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

This commit is contained in:
Marco Pesenti Gritti 2007-03-15 11:11:57 +01:00
commit 705466a2d2
3 changed files with 88 additions and 24 deletions

View File

@ -69,6 +69,7 @@ class Activity(DBusGObject):
self._valid = False
self._id = None
self._color = None
self._local = False
self._type = None
@ -225,3 +226,33 @@ class Activity(DBusGObject):
def _activity_text_channel_closed_cb(self):
self._joined = False
self._activity_text_channel = None
def send_properties(self):
props = {}
props['name'] = self._name
props['color'] = self._color
props['type'] = self._type
self._tp.set_activity_properties(self.props.id, props)
def set_properties(self, properties):
changed = False
if "name" in properties.keys():
name = properties["name"]
if name != self._name:
self._name = name
changed = True
if "color" in properties.keys():
color = properties["color"]
if color != self._color:
self._color = color
changed = True
if "type" in properties.keys():
type = properties["type"]
if type != self._type:
self._type = type
changed = True
if changed:
self._update_validity()

View File

@ -23,6 +23,7 @@ from telepathy.constants import (CONNECTION_STATUS_CONNECTING, CONNECTION_STATUS
from server_plugin import ServerPlugin
from linklocal_plugin import LinkLocalPlugin
from sugar import util
from buddy import Buddy, Owner
from activity import Activity
@ -65,10 +66,11 @@ class PresenceService(dbus.service.Object):
self._server_plugin.connect('contact-online', self._contact_online)
self._server_plugin.connect('contact-offline', self._contact_offline)
self._server_plugin.connect('avatar-updated', self._avatar_updated)
self._server_plugin.connect('properties-changed', self._properties_changed)
self._server_plugin.connect('contact-activities-changed', self._contact_activities_changed)
self._server_plugin.connect('buddy-properties-changed', self._buddy_properties_changed)
self._server_plugin.connect('buddy-activities-changed', self._buddy_activities_changed)
self._server_plugin.connect('activity-invitation', self._activity_invitation)
self._server_plugin.connect('private-invitation', self._private_invitation)
self._server_plugin.connect('activity-properties-changed', self._activity_properties_changed)
self._server_plugin.start()
# Set up the link local connection
@ -80,6 +82,10 @@ 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.lapin",
"Chat of %s" % self._owner.props.nick, [])
def _contact_online(self, tp, handle, props):
new_buddy = False
@ -130,7 +136,7 @@ class PresenceService(dbus.service.Object):
print "Buddy %s icon updated" % buddy.props.key
buddy.props.icon = avatar
def _properties_changed(self, tp, handle, prop):
def _buddy_properties_changed(self, tp, handle, prop):
buddy = self._handles_buddies[tp].get(handle)
if buddy:
buddy.set_properties(prop)
@ -150,14 +156,14 @@ class PresenceService(dbus.service.Object):
# FIXME
# Use values from the network
import random
names = ["Tommy", "Susie", "Jill", "Bryan", "Nathan", "Sophia", "Haley", "Jimmy"]
name = names[random.randint(0, len(names) - 1)]
activity.props.name = "Chat with %s" % name
activity.props.type = "org.laptop.Sugar.Chat"
from sugar.graphics import xocolor
color = xocolor.XoColor().to_string()
activity.props.color = color
#import random
#names = ["Tommy", "Susie", "Jill", "Bryan", "Nathan", "Sophia", "Haley", "Jimmy"]
#name = names[random.randint(0, len(names) - 1)]
#activity.props.name = "Chat with %s" % name
#activity.props.type = "org.laptop.Sugar.Chat"
#from sugar.graphics import xocolor
#color = xocolor.XoColor().to_string()
#activity.props.color = color
return activity
@ -167,7 +173,7 @@ class PresenceService(dbus.service.Object):
self.ActivityDisappeared(activity.object_path())
del self._activities[activity.props.id]
def _contact_activities_changed(self, tp, contact_handle, activities):
def _buddy_activities_changed(self, tp, contact_handle, activities):
print "------------activities changed-------------"
buddies = self._handles_buddies[tp]
buddy = buddies.get(contact_handle)
@ -299,6 +305,7 @@ class PresenceService(dbus.service.Object):
self._activities[actid] = activity
activity.join()
activity.send_properties()
return activity
@ -310,6 +317,11 @@ class PresenceService(dbus.service.Object):
self.ActivityDisappeared(activity.object_path())
print "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)
if activity:
activity.set_properties(props)
def main():
loop = gobject.MainLoop()

View File

@ -37,6 +37,7 @@ from telepathy.constants import (
CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED)
CONN_INTERFACE_BUDDY_INFO = 'org.laptop.Telepathy.BuddyInfo'
CONN_INTERFACE_ACTIVITY_PROPERTIES = 'org.laptop.Telepathy.ActivityProperties'
_PROTOCOL = "jabber"
@ -85,14 +86,16 @@ class ServerPlugin(gobject.GObject):
([gobject.TYPE_INT, gobject.TYPE_INT])),
'avatar-updated': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT])),
'properties-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
'buddy-properties-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT])),
'contact-activities-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
'buddy-activities-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT])),
'activity-invitation': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'private-invitation': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT]))
([gobject.TYPE_PYOBJECT])),
'activity-properties-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT])),
}
def __init__(self, registry, owner):
@ -142,6 +145,7 @@ class ServerPlugin(gobject.GObject):
account_info['account'] = "%s@%s" % (khash, account_info['server'])
account_info['password'] = profile.get_private_key_hash()
print account_info
return account_info
def _find_existing_connection(self):
@ -181,6 +185,7 @@ class ServerPlugin(gobject.GObject):
# hack
conn._valid_interfaces.add(CONN_INTERFACE_PRESENCE)
conn._valid_interfaces.add(CONN_INTERFACE_BUDDY_INFO)
conn._valid_interfaces.add(CONN_INTERFACE_ACTIVITY_PROPERTIES)
conn._valid_interfaces.add(CONN_INTERFACE_AVATARS)
conn._valid_interfaces.add(CONN_INTERFACE_ALIASING)
@ -231,13 +236,15 @@ class ServerPlugin(gobject.GObject):
self.cleanup()
return
self._conn[CONN_INTERFACE_BUDDY_INFO].connect_to_signal('PropertiesChanged', self._properties_changed_cb)
self._conn[CONN_INTERFACE_BUDDY_INFO].connect_to_signal('ActivitiesChanged', self._activities_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_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('PropertiesChanged', self._activity_properties_changed_cb)
try:
self._set_self_buddy_info()
except RuntimeError, e:
@ -289,7 +296,7 @@ class ServerPlugin(gobject.GObject):
self._joined_activities.append((act, handle))
self._conn[CONN_INTERFACE_BUDDY_INFO].SetActivities(self._joined_activities)
return channel
def _set_self_buddy_info(self):
@ -387,7 +394,7 @@ class ServerPlugin(gobject.GObject):
self.emit("contact-online", handle, props)
activities = self._conn[CONN_INTERFACE_BUDDY_INFO].GetActivities(handle)
self._activities_changed_cb(handle, activities)
self._buddy_activities_changed_cb(handle, activities)
def _presence_update_cb(self, presence):
for handle in presence:
@ -419,16 +426,16 @@ class ServerPlugin(gobject.GObject):
for handle, alias in aliases:
prop = {'nick': alias}
#print "Buddy %s alias changed to %s" % (handle, alias)
self._properties_changed_cb(handle, prop)
self._buddy_properties_changed_cb(handle, prop)
def _properties_changed_cb(self, contact, properties):
self.emit("properties-changed", contact, properties)
def _buddy_properties_changed_cb(self, contact, properties):
self.emit("buddy-properties-changed", contact, properties)
def _activities_changed_cb(self, contact, activities):
def _buddy_activities_changed_cb(self, contact, activities):
for act_id, act_handle in activities:
self._activities[act_id] = act_handle
activities_id = map(lambda x: x[0], activities)
self.emit("contact-activities-changed", contact, activities_id)
self.emit("buddy-activities-changed", contact, activities_id)
def _new_channel_cb(self, object_path, channel_type, handle_type, handle, suppress_handler):
if handle_type == CONNECTION_HANDLE_TYPE_ROOM and channel_type == CHANNEL_TYPE_TEXT:
@ -447,3 +454,17 @@ class ServerPlugin(gobject.GObject):
elif handle_type == CONNECTION_HANDLE_TYPE_CONTACT and \
channel_type in [CHANNEL_TYPE_TEXT, CHANNEL_TYPE_STREAMED_MEDIA]:
self.emit("private-invitation", object_path)
def set_activity_properties(self, act_id, props):
handle = self._activities.get(act_id)
if not handle:
print "set_activity_properties: handle unkown"
return
self._conn[CONN_INTERFACE_ACTIVITY_PROPERTIES].SetProperties(handle, props)
def _activity_properties_changed_cb(self, room, properties):
for act_id, act_handle in self._activities.items():
if room == act_handle:
self.emit("activity-properties-changed", act_id, properties)