[telepathy-pinocchio/master] Implement the basic functionalities of SimplePresence

Marco Barisione marco at barisione.org
Mon Aug 10 14:08:09 PDT 2009


---
 pinocchio/connection/__init__.py        |    5 ++-
 pinocchio/connection/simple_presence.py |   60 +++++++++++++++++++++++++++++++
 pinocchio/server/__init__.py            |   19 ++++++++++
 3 files changed, 83 insertions(+), 1 deletions(-)
 create mode 100644 pinocchio/connection/simple_presence.py

diff --git a/pinocchio/connection/__init__.py b/pinocchio/connection/__init__.py
index d234367..2d3d03b 100644
--- a/pinocchio/connection/__init__.py
+++ b/pinocchio/connection/__init__.py
@@ -27,12 +27,14 @@ from aliasing import *
 from avatars import *
 from capabilities import *
 from presence import *
+from simple_presence import *
 
 class Connection(tp.server.Connection,
                  aliasing.Aliasing,
                  avatars.Avatars,
                  capabilities.Capabilities,
-                 presence.Presence):
+                 presence.Presence,
+                 simple_presence.SimplePresence):
     """Representation of a virtual connection."""
 
     _CONTACT_LIST_NAMES = ('subscribe', 'publish', 'hide', 'allow', 'deny')
@@ -51,6 +53,7 @@ class Connection(tp.server.Connection,
         avatars.Avatars.__init__(self)
         capabilities.Capabilities.__init__(self)
         presence.Presence.__init__(self)
+        simple_presence.SimplePresence.__init__(self)
 
         # accept the default alias, etc. (including the required, though empty,
         # avatar)
diff --git a/pinocchio/connection/simple_presence.py b/pinocchio/connection/simple_presence.py
new file mode 100644
index 0000000..30be881
--- /dev/null
+++ b/pinocchio/connection/simple_presence.py
@@ -0,0 +1,60 @@
+# telepathy-pinocchio - dummy Telepathy connection manager for instrumentation
+#
+# Copyright (C) 2008 Nokia Corporation
+# Copyright (C) 2008 Collabora Ltd.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public License
+# version 2.1 as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA
+
+import dbus.service
+
+import telepathy as tp
+
+import pinocchio as pin
+
+class SimplePresence(tp.server.ConnectionInterfaceSimplePresence):
+    """Presence interface for a Telepathy Connection."""
+
+    def __init__(self):
+        tp.server.ConnectionInterfaceSimplePresence.__init__(self)
+
+    def GetPresences(self, contacts):
+        """Returns the presence of the given contacts.
+
+        Arguments:
+        contacts -- iterable of contacts whose presence is requested
+        
+        Returns:
+        presences -- complex list of structs containing the presences
+
+        Exceptions:
+        org.freedesktop.Telepathy.Error.Disconnected
+        org.freedesktop.Telepathy.Error.InvalidArgument
+        org.freedesktop.Telepathy.Error.InvalidHandle
+        org.freedesktop.Telepathy.Error.NetworkError
+        org.freedesktop.Telepathy.Error.NotAvailable
+        """
+        presences = {}
+        for handle_id in contacts:
+            self.check_handle (tp.constants.HANDLE_TYPE_CONTACT, handle_id)
+
+            handle_obj = self._handles[tp.constants.HANDLE_TYPE_CONTACT,
+                                       handle_id]
+
+            presences[handle_id] = (0,
+                                    handle_obj.get_status(),
+                                    handle_obj.get_status_message())
+
+        return presences
+
diff --git a/pinocchio/server/__init__.py b/pinocchio/server/__init__.py
index 1489ec3..88771f9 100644
--- a/pinocchio/server/__init__.py
+++ b/pinocchio/server/__init__.py
@@ -114,6 +114,25 @@ class HandleContact(tp.server.Handle):
     def get_connection(self):
         return self._connection
 
+    def get_status_type(self):
+        # TODO do this in a proper way, for instance Presence.set_presences
+        # should also get the status type in the contact_presences argument
+        types = \
+        {
+            'available': tp.CONNECTION_PRESENCE_TYPE_AVAILABLE,
+            'away': tp.CONNECTION_PRESENCE_TYPE_AWAY,
+            'brb': tp.CONNECTION_PRESENCE_TYPE_AWAY,
+            'busy': tp.CONNECTION_PRESENCE_TYPE_AWAY,
+            'dnd': tp.CONNECTION_PRESENCE_TYPE_AWAY,
+            'xa': tp.CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY,
+            'offline': tp.CONNECTION_PRESENCE_TYPE_OFFLINE,
+            'hidden': tp.CONNECTION_PRESENCE_TYPE_HIDDEN
+        }
+        try:
+            return types[self.get_status()]
+        except KeyError:
+            return tp.CONNECTION_PRESENCE_TYPE_AVAILABLE
+
     def get_status(self):
         return self._extended_attrs['status']
 
-- 
1.5.6.5




More information about the telepathy-commits mailing list