start to implement join and share activities

This commit is contained in:
Guillaume Desmottes 2007-03-06 17:15:55 +01:00
parent 195e18d7b0
commit f716f20191
3 changed files with 67 additions and 12 deletions

View File

@ -21,7 +21,7 @@ _ACTIVITY_PATH = "/org/laptop/Sugar/Presence/Activities/"
_ACTIVITY_INTERFACE = "org.laptop.Sugar.Presence.Activity"
class Activity(dbus.service.Object):
def __init__(self, bus_name, object_id, activity_id):
def __init__(self, bus_name, object_id, activity_id, tp):
self._buddies = []
self._color = None
self._valid = False
@ -30,6 +30,12 @@ class Activity(dbus.service.Object):
self._object_id = object_id
self._object_path = "/org/laptop/Presence/Activities/%d" % self._object_id
# the telepathy client
self._tp = tp
self._activity_text_channel = None
self._joined = False
dbus.service.Object.__init__(self, bus_name, self._object_path)
@ -63,7 +69,7 @@ class Activity(dbus.service.Object):
@dbus.service.method(_ACTIVITY_INTERFACE,
in_signature="", out_signature="")
def Join(self):
raise NotImplementedError("not implemented yet")
self.join()
@dbus.service.method(_ACTIVITY_INTERFACE,
in_signature="", out_signature="ao")
@ -103,3 +109,8 @@ class Activity(dbus.service.Object):
if buddy in self._buddies:
self._buddies.remove(buddy)
self.BuddyLeft(buddy.object_path())
def join(self):
if not self._joined:
self._activity_text_channel = self._tp.join_activity(self._activity_id)
self._joined = True

View File

@ -76,6 +76,7 @@ class PresenceService(dbus.service.Object):
dbus.service.Object.__init__(self, self._bus_name, _PRESENCE_PATH)
def _server_status_cb(self, plugin, status, reason):
if status == CONNECTION_STATUS_CONNECTED:
pass
def _contact_online(self, tp, handle, props):
@ -133,9 +134,9 @@ class PresenceService(dbus.service.Object):
buddy.set_properties(prop)
print "Buddy %s properties updated" % buddy.props.key
def _new_activity(self, activity_id):
def _new_activity(self, activity_id, tp):
objid = self._get_next_object_id()
activity = Activity(self._bus_name, objid, activity_id)
activity = Activity(self._bus_name, objid, activity_id, tp)
# FIXME : don't do that shit !
activity._valid = True
self._activities[activity_id] = activity
@ -175,7 +176,7 @@ class PresenceService(dbus.service.Object):
activity = self._activities.get(act)
if not activity:
# new activity
activity = self._new_activity(act)
activity = self._new_activity(act, tp)
activity.buddy_joined(buddy)
buddy.add_activity(activity)
@ -248,12 +249,29 @@ class PresenceService(dbus.service.Object):
@dbus.service.method(_PRESENCE_INTERFACE, in_signature="sssa{sv}", out_signature="o")
def ShareActivity(self, actid, atype, name, properties):
raise NotImplementedError("not implemented yet")
activity = self._share_activity(actid, atype, name, properties)
return activity.object_path()
def cleanup(self):
for tp in self._handles_buddies:
tp.cleanup()
def _share_activity(self, actid, atype, name, properties):
objid = self._get_next_object_id()
# FIXME check which tp client we should use to share the activity
activity = Activity(self._bus_name, objid, actid, self._server_plugin)
# FIXME : don't do that shit !
activity._valid = True
self._activities[actid] = activity
# FIXME set the type, name, properties...
print "new activity", actid
activity.join()
self.ActivityAppeared(activity.object_path())
return activity
def main():
loop = gobject.MainLoop()
ps = PresenceService()

View File

@ -29,7 +29,7 @@ import hashlib
from telepathy.client import ConnectionManager, ManagerRegistry, Connection, Channel
from telepathy.interfaces import (
CONN_MGR_INTERFACE, CONN_INTERFACE, CHANNEL_TYPE_CONTACT_LIST, CHANNEL_INTERFACE_GROUP, CONN_INTERFACE_ALIASING,
CONN_INTERFACE_AVATARS, CONN_INTERFACE_PRESENCE)
CONN_INTERFACE_AVATARS, CONN_INTERFACE_PRESENCE, CHANNEL_TYPE_TEXT)
from telepathy.constants import (
CONNECTION_HANDLE_TYPE_NONE, CONNECTION_HANDLE_TYPE_CONTACT,
CONNECTION_STATUS_CONNECTED, CONNECTION_STATUS_DISCONNECTED, CONNECTION_STATUS_CONNECTING,
@ -93,7 +93,9 @@ class ServerPlugin(gobject.GObject):
self._gabble_mgr = registry.GetManager('gabble')
self._online_contacts = {} # handle -> jid
self._activities = {} # activity id -> handle
self._joined_activities = [] # (activity_id, handle of the activity channel)
self._account = self._get_account_info()
self._conn = self._init_connection()
@ -138,6 +140,9 @@ class ServerPlugin(gobject.GObject):
return item
return None
def get_connection(self):
return self._conn
def _init_connection(self):
conn = self._find_existing_connection()
if not conn:
@ -249,6 +254,27 @@ class ServerPlugin(gobject.GObject):
except RuntimeError, e:
pass
def join_activity(self, act):
handle = self._activities.get(act)
if not handle:
handle = self._conn[CONN_INTERFACE].RequestHandles(CONNECTION_HANDLE_TYPE_ROOM, [act])[0]
self._activities[act] = handle
if (act, handle) in self._joined_activities:
print "%s already joined" % act
return
chan_path = self._conn[CONN_INTERFACE].RequestChannel(
CHANNEL_TYPE_TEXT, CONNECTION_HANDLE_TYPE_ROOM,
handle, True)
channel = Channel(self._conn._dbus_object._named_service, chan_path)
self._joined_activities.append((act, handle))
self._conn[CONN_INTERFACE_BUDDY_INFO].SetActivities(self._joined_activities)
return channel
def _set_self_buddy_info(self):
# Set our OLPC buddy properties
props = {}
@ -264,7 +290,7 @@ class ServerPlugin(gobject.GObject):
self_handle = self._conn[CONN_INTERFACE].GetSelfHandle()
self._conn[CONN_INTERFACE_ALIASING].SetAliases( {self_handle : name} )
self._conn[CONN_INTERFACE_BUDDY_INFO].SetActivities([])
self._conn[CONN_INTERFACE_BUDDY_INFO].SetActivities(self._joined_activities)
self._upload_avatar()
@ -273,8 +299,8 @@ class ServerPlugin(gobject.GObject):
print 'connecting: %r' % reason
elif state == CONNECTION_STATUS_CONNECTED:
print 'connected: %r' % reason
self.emit('status', state, int(reason))
self._connected_cb()
self.emit('status', state, int(reason))
elif state == CONNECTION_STATUS_DISCONNECTED:
print 'disconnected: %r' % reason
self.emit('status', state, int(reason))