Merge branch 'master' of git+ssh://dev.laptop.org/git/sugar

This commit is contained in:
Marco Pesenti Gritti 2007-04-13 02:02:46 +02:00
commit 17cb94faa1
3 changed files with 94 additions and 62 deletions

View File

@ -16,6 +16,8 @@
import gobject
import dbus, dbus.service, dbus.glib
import logging
from telepathy.client import ManagerRegistry, Connection
from telepathy.interfaces import (CONN_MGR_INTERFACE, CONN_INTERFACE)
from telepathy.constants import (CONNECTION_STATUS_CONNECTING, CONNECTION_STATUS_CONNECTED,
@ -85,10 +87,6 @@ class PresenceService(dbus.service.Object):
def _server_status_cb(self, plugin, status, reason):
if status == CONNECTION_STATUS_CONNECTED:
pass
# TEST
id = util.unique_id()
self._share_activity(id, "org.laptop.Sugar.Test",
"Chat of %s" % self._owner.props.nick, [])
def _contact_online(self, tp, handle, props):
new_buddy = False
@ -111,10 +109,10 @@ class PresenceService(dbus.service.Object):
def _buddy_validity_changed_cb(self, buddy, valid):
if valid:
self.BuddyAppeared(buddy.object_path())
print "New Buddy: %s (%s)" % (buddy.props.nick, buddy.props.color)
logging.debug("New Buddy: %s (%s)" % (buddy.props.nick, buddy.props.color))
else:
self.BuddyDisappeared(buddy.object_path())
print "Buddy left: %s (%s)" % (buddy.props.nick, buddy.props.color)
logging.debug("Buddy left: %s (%s)" % (buddy.props.nick, buddy.props.color))
def _contact_offline(self, tp, handle):
buddy = self._handles_buddies[tp].pop(handle)
@ -125,7 +123,7 @@ class PresenceService(dbus.service.Object):
if not buddy.handles:
if buddy.props.valid:
self.BuddyDisappeared(buddy.object_path())
print "Buddy left: %s (%s)" % (buddy.props.nick, buddy.props.color)
logging.debug("Buddy left: %s (%s)" % (buddy.props.nick, buddy.props.color))
self._buddies.pop(key)
def _get_next_object_id(self):
@ -136,21 +134,21 @@ class PresenceService(dbus.service.Object):
def _avatar_updated(self, tp, handle, avatar):
buddy = self._handles_buddies[tp].get(handle)
if buddy and not buddy.props.owner:
print "Buddy %s icon updated" % buddy.props.key
logging.debug("Buddy %s icon updated" % buddy.props.nick)
buddy.props.icon = avatar
def _buddy_properties_changed(self, tp, handle, prop):
buddy = self._handles_buddies[tp].get(handle)
if buddy:
buddy.set_properties(prop)
#print "Buddy %s properties updated" % buddy.props.key
logging.debug("Buddy %s properties updated" % buddy.props.nick)
def _new_activity(self, activity_id, tp):
try:
objid = self._get_next_object_id()
activity = Activity(self._bus_name, objid, tp, id=activity_id)
except Exception, e:
print "Invalid activity: %s" % e
logging.debug("Invalid activity: %s" % e)
return None
activity.connect("validity-changed", self._activity_validity_changed_cb)
@ -171,13 +169,13 @@ class PresenceService(dbus.service.Object):
return activity
def _remove_activity(self, activity):
print "remove activity", activity.props.id
logging.debug("remove activity", activity.props.id)
self.ActivityDisappeared(activity.object_path())
del self._activities[activity.props.id]
def _buddy_activities_changed(self, tp, contact_handle, activities):
print "------------activities changed-------------"
logging.debug("------------activities changed-------------")
buddies = self._handles_buddies[tp]
buddy = buddies.get(contact_handle)
@ -185,7 +183,7 @@ class PresenceService(dbus.service.Object):
# We don't know this buddy
# FIXME: What should we do here?
# FIXME: Do we need to check if the buddy is valid or something?
print "contact_activities_changed: buddy unknow"
logging.debug("contact_activities_changed: buddy unknown")
return
old_activities = set()
@ -196,7 +194,7 @@ class PresenceService(dbus.service.Object):
activities_joined = new_activities - old_activities
for act in activities_joined:
print "buddy", contact_handle, "joined", act
logging.debug("Buddy", contact_handle, "joined", act)
activity = self._activities.get(act)
if not activity:
# new activity, can fail
@ -208,7 +206,7 @@ class PresenceService(dbus.service.Object):
activities_left = old_activities - new_activities
for act in activities_left:
print "buddy", contact_handle, "left", act
logging.debug("Buddy", contact_handle, "left", act)
activity = self._activities.get(act)
if not activity:
continue
@ -304,6 +302,9 @@ class PresenceService(dbus.service.Object):
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
import time
start = time.time()
logging.debug("Start share of %s (%s)" % (actid, atype))
color = self._owner.props.color
activity = Activity(self._bus_name, objid, self._server_plugin,
id=actid, type=atype, name=name, color=color, local=True)
@ -312,16 +313,17 @@ class PresenceService(dbus.service.Object):
activity.join()
activity.send_properties()
logging.debug("End share of %s (%s). Time: %f" % (actid, atype, (float)(time.time() - start)))
return activity
def _activity_validity_changed_cb(self, activity, valid):
if valid:
self.ActivityAppeared(activity.object_path())
print "New Activity: %s (%s)" % (activity.props.name, activity.props.id)
logging.debug("New Activity: %s (%s)" % (activity.props.name, activity.props.id))
else:
self.ActivityDisappeared(activity.object_path())
print "Activity disappeared: %s (%s)" % (activity.props.name, activity.props.id)
logging.debug("Activity disappeared: %s (%s)" % (activity.props.name, activity.props.id))
def _activity_properties_changed(self, tp, act_id, props):
activity = self._activities.get(act_id)
@ -336,7 +338,7 @@ def main(test=False):
loop.run()
except KeyboardInterrupt:
ps.cleanup()
print 'Ctrl+C pressed, exiting...'
logging.debug('Ctrl+C pressed, exiting...')
if __name__ == "__main__":
main()

View File

@ -120,11 +120,19 @@ class ServerPlugin(gobject.GObject):
def _owner_property_changed_cb(self, owner, properties):
logging.debug("Owner properties changed: %s" % properties)
self._set_self_buddy_info()
if properties.has_key("current-activity"):
self._set_self_current_activity()
if properties.has_key("nick"):
self._set_self_alias()
if properties.has_key("color"):
self._set_self._olpc_properties()
def _owner_icon_changed_cb(self, owner, icon):
logging.debug("Owner icon changed to size %d" % len(str(icon)))
self._upload_avatar()
self._set_self_avatar(icon)
def _get_account_info(self):
account_info = {}
@ -228,28 +236,37 @@ class ServerPlugin(gobject.GObject):
self.cleanup()
return
self._conn[CONN_INTERFACE_BUDDY_INFO].connect_to_signal('PropertiesChanged', self._buddy_properties_changed_cb)
self._conn[CONN_INTERFACE_BUDDY_INFO].connect_to_signal('ActivitiesChanged', self._buddy_activities_changed_cb)
self._conn[CONN_INTERFACE_BUDDY_INFO].connect_to_signal('CurrentActivityChanged', self._buddy_current_activity_changed_cb)
self._conn[CONN_INTERFACE_BUDDY_INFO].connect_to_signal('PropertiesChanged',
self._buddy_properties_changed_cb)
self._conn[CONN_INTERFACE_BUDDY_INFO].connect_to_signal('ActivitiesChanged',
self._buddy_activities_changed_cb)
self._conn[CONN_INTERFACE_BUDDY_INFO].connect_to_signal('CurrentActivityChanged',
self._buddy_current_activity_changed_cb)
self._conn[CONN_INTERFACE_AVATARS].connect_to_signal('AvatarUpdated', self._avatar_updated_cb)
self._conn[CONN_INTERFACE_AVATARS].connect_to_signal('AvatarUpdated',
self._avatar_updated_cb)
self._conn[CONN_INTERFACE_ALIASING].connect_to_signal('AliasesChanged',
self._alias_changed_cb)
self._conn[CONN_INTERFACE_ACTIVITY_PROPERTIES].connect_to_signal('ActivityPropertiesChanged',
self._activity_properties_changed_cb)
self._conn[CONN_INTERFACE_ALIASING].connect_to_signal('AliasesChanged', self._alias_changed_cb)
self._conn[CONN_INTERFACE_ACTIVITY_PROPERTIES].connect_to_signal('ActivityPropertiesChanged', self._activity_properties_changed_cb)
try:
self._set_self_buddy_info()
except RuntimeError, e:
logging.debug("Could not set owner properties: %s" % e)
self.cleanup()
return
# Set initial buddy properties, avatar, and activities
self._set_self_olpc_properties(True)
self._set_self_alias()
self._set_self_activities()
self._set_self_current_activity()
self._set_self_avatar()
# Request presence for everyone on the channel
self._conn[CONN_INTERFACE_PRESENCE].GetPresence(subscribe_handles)
self._conn[CONN_INTERFACE_PRESENCE].GetPresence(subscribe_handles,
ignore_reply=True)
def _upload_avatar(self):
icon_data = self._owner.props.icon
def _set_self_avatar_cb(self, token):
self._icon_cache.set_avatar(hash, token)
def _set_self_avatar(self, icon_data=None):
if not icon_data:
icon_data = self._owner.props.icon
md5 = hashlib.md5()
md5.update(icon_data)
@ -268,8 +285,9 @@ class ServerPlugin(gobject.GObject):
return
img_data = _get_buddy_icon_at_size(icon_data, min(maxw, 96), min(maxh, 96), maxsize)
token = self._conn[CONN_INTERFACE_AVATARS].SetAvatar(img_data, "image/jpeg")
self._icon_cache.set_avatar(hash, token)
self._conn[CONN_INTERFACE_AVATARS].SetAvatar(img_data, "image/jpeg",
reply_handler=self._set_self_avatar_cb,
error_handler=lambda *args: self._log_error_cb("avatar", *args))
def join_activity(self, act):
handle = self._activities.get(act)
@ -292,23 +310,34 @@ class ServerPlugin(gobject.GObject):
return channel
def _set_self_buddy_info(self):
# Set our OLPC buddy properties
def _ignore_success_cb(self):
pass
def _log_error_cb(self, msg, err):
logging.debug("Error setting %s: %s" % (msg, err))
def _set_self_olpc_properties(self, set_key=False):
props = {}
props['color'] = self._owner.props.color
props['key'] = dbus.ByteArray(self._owner.props.key)
try:
self._conn[CONN_INTERFACE_BUDDY_INFO].SetProperties(props)
except dbus.DBusException, e:
if str(e).find("Server does not support PEP") >= 0:
raise RuntimeError("Server does not support PEP")
if set_key:
props['key'] = dbus.ByteArray(self._owner.props.key)
self._conn[CONN_INTERFACE_BUDDY_INFO].SetProperties(props,
reply_handler=self._ignore_success_cb,
error_handler=lambda *args: self._log_error_cb("properties", *args))
name = self._owner.props.nick
def _set_self_alias(self):
alias = self._owner.props.nick
self_handle = self._conn[CONN_INTERFACE].GetSelfHandle()
self._conn[CONN_INTERFACE_ALIASING].SetAliases( {self_handle : name} )
self._conn[CONN_INTERFACE_ALIASING].SetAliases({self_handle : alias},
reply_handler=self._ignore_success_cb,
error_handler=lambda *args: self._log_error_cb("alias", *args))
self._conn[CONN_INTERFACE_BUDDY_INFO].SetActivities(self._joined_activities)
def _set_self_activities(self):
self._conn[CONN_INTERFACE_BUDDY_INFO].SetActivities(self._joined_activities,
reply_handler=self._ignore_success_cb,
error_handler=lambda *args: self._log_error_cb("activities", *args))
def _set_self_current_activity(self):
cur_activity = self._owner.props.current_activity
cur_activity_handle = 0
if not cur_activity:
@ -318,10 +347,12 @@ class ServerPlugin(gobject.GObject):
if not cur_activity_handle:
# dont advertise a current activity that's not shared
cur_activity = ""
logging.debug("cur_activity is '%s', handle is %s" % (cur_activity, cur_activity_handle))
self._conn[CONN_INTERFACE_BUDDY_INFO].SetCurrentActivity(cur_activity, cur_activity_handle)
self._upload_avatar()
logging.debug("Setting current activity to '%s' (handle %s)" % (cur_activity, cur_activity_handle))
self._conn[CONN_INTERFACE_BUDDY_INFO].SetCurrentActivity(cur_activity,
cur_activity_handle,
reply_handler=self._ignore_success_cb,
error_handler=lambda *args: self._log_error_cb("current activity", *args))
def _get_handle_for_activity(self, activity_id):
for (act, handle) in self._joined_activities:
@ -543,12 +574,12 @@ class ServerPlugin(gobject.GObject):
def set_activity_properties(self, act_id, props):
handle = self._activities.get(act_id)
if not handle:
logging.debug("set_activity_properties: handle unkown")
logging.debug("set_activity_properties: handle unknown")
return
self._conn[CONN_INTERFACE_ACTIVITY_PROPERTIES].SetProperties(handle, props)
self._conn[CONN_INTERFACE_ACTIVITY_PROPERTIES].SetProperties(handle, props,
reply_handler=self._ignore_success_cb,
error_handler=lambda *args: self._log_error_cb("activity properties", *args))
def _activity_properties_changed_cb(self, room, properties):
for act_id, act_handle in self._activities.items():

View File

@ -31,11 +31,10 @@ class ActivityMenu(Menu):
def __init__(self, activity_model):
Menu.__init__(self, activity_model.get_title())
# FIXME: re-enable after trial1
# if not activity_model.get_shared():
# self.add_item(MenuItem(ActivityMenu.ACTION_SHARE,
# _('Share'),
# 'theme:stock-share-mesh'))
if not activity_model.get_shared():
self.add_item(MenuItem(ActivityMenu.ACTION_SHARE,
_('Share'),
'theme:stock-share-mesh'))
self.add_item(MenuItem(ActivityMenu.ACTION_CLOSE,
_('Close'),