Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMorgan Collett <morgan.collett@gmail.com>2008-05-13 14:59:34 (GMT)
committer Morgan Collett <morgan.collett@gmail.com>2008-05-15 11:20:48 (GMT)
commit4db051f4020a6b5373fd95c02cb21280fa58edb3 (patch)
tree23f6aba5fca9e0f09335008b71e8451cb3169457 /src
parentc7a92b5d5a432079d9a9b4aa19842638329e76d0 (diff)
6473: Better method for resolving handles to buddies
Diffstat (limited to 'src')
-rw-r--r--src/sugar/presence/Makefile.am1
-rw-r--r--src/sugar/presence/sugartubeconn.py60
2 files changed, 61 insertions, 0 deletions
diff --git a/src/sugar/presence/Makefile.am b/src/sugar/presence/Makefile.am
index cb52a41..0c4368b 100644
--- a/src/sugar/presence/Makefile.am
+++ b/src/sugar/presence/Makefile.am
@@ -3,6 +3,7 @@ sugar_PYTHON = \
__init__.py \
activity.py \
buddy.py \
+ sugartubeconn.py \
tubeconn.py \
presenceservice.py
diff --git a/src/sugar/presence/sugartubeconn.py b/src/sugar/presence/sugartubeconn.py
new file mode 100644
index 0000000..3477611
--- /dev/null
+++ b/src/sugar/presence/sugartubeconn.py
@@ -0,0 +1,60 @@
+"""Subclass of TubeConnection that converts handles to Sugar Buddies"""
+# Copyright (C) 2008 One Laptop Per Child
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published
+# by the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# This program 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 program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+from telepathy.constants import (
+ CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES)
+
+from tubeconn import TubeConnection
+import presenceservice
+
+
+class SugarTubeConnection(TubeConnection):
+ """Subclass of TubeConnection that converts handles to Sugar Buddies"""
+
+ def __new__(cls, conn, tubes_iface, tube_id, address=None,
+ group_iface=None, mainloop=None):
+ self = super(SugarTubeConnection, cls).__new__(
+ cls, conn, tubes_iface, tube_id, address=address,
+ group_iface=group_iface, mainloop=mainloop)
+ self._conn = conn
+ self._group_iface = group_iface
+ return self
+
+ def get_buddy(self, cs_handle):
+ """Retrieve a Buddy object given a telepathy handle.
+
+ cs_handle: A channel-specific CONTACT type handle.
+ returns: sugar.presence Buddy object or None
+ """
+ pservice = presenceservice.get_instance()
+ if self.self_handle == cs_handle:
+ # It's me, just get my global handle
+ handle = self._conn.GetSelfHandle()
+ elif self._group_iface.GetGroupFlags() & \
+ CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES:
+ # The group (channel) has channel specific handles
+ handle = self._group_iface.GetHandleOwners([cs_handle])[0]
+ else:
+ # The group does not have channel specific handles
+ handle = cs_handle
+
+ # deal with failure to get the handle owner
+ if handle == 0:
+ return None
+ return pservice.get_buddy_by_telepathy_handle(
+ self._conn.service_name, self._conn.object_path, handle)