rename some signals to avoid confusions
use activity properties API
This commit is contained in:
parent
eae978346d
commit
a16484bc7b
@ -69,6 +69,7 @@ class Activity(DBusGObject):
|
|||||||
|
|
||||||
self._valid = False
|
self._valid = False
|
||||||
self._id = None
|
self._id = None
|
||||||
|
self._color = None
|
||||||
self._local = False
|
self._local = False
|
||||||
self._type = None
|
self._type = None
|
||||||
|
|
||||||
@ -225,3 +226,33 @@ class Activity(DBusGObject):
|
|||||||
def _activity_text_channel_closed_cb(self):
|
def _activity_text_channel_closed_cb(self):
|
||||||
self._joined = False
|
self._joined = False
|
||||||
self._activity_text_channel = None
|
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()
|
||||||
|
@ -23,6 +23,7 @@ from telepathy.constants import (CONNECTION_STATUS_CONNECTING, CONNECTION_STATUS
|
|||||||
|
|
||||||
from server_plugin import ServerPlugin
|
from server_plugin import ServerPlugin
|
||||||
from linklocal_plugin import LinkLocalPlugin
|
from linklocal_plugin import LinkLocalPlugin
|
||||||
|
from sugar import util
|
||||||
|
|
||||||
from buddy import Buddy, Owner
|
from buddy import Buddy, Owner
|
||||||
from activity import Activity
|
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-online', self._contact_online)
|
||||||
self._server_plugin.connect('contact-offline', self._contact_offline)
|
self._server_plugin.connect('contact-offline', self._contact_offline)
|
||||||
self._server_plugin.connect('avatar-updated', self._avatar_updated)
|
self._server_plugin.connect('avatar-updated', self._avatar_updated)
|
||||||
self._server_plugin.connect('properties-changed', self._properties_changed)
|
self._server_plugin.connect('buddy-properties-changed', self._buddy_properties_changed)
|
||||||
self._server_plugin.connect('contact-activities-changed', self._contact_activities_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('activity-invitation', self._activity_invitation)
|
||||||
self._server_plugin.connect('private-invitation', self._private_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()
|
self._server_plugin.start()
|
||||||
|
|
||||||
# Set up the link local connection
|
# Set up the link local connection
|
||||||
@ -80,6 +82,10 @@ class PresenceService(dbus.service.Object):
|
|||||||
def _server_status_cb(self, plugin, status, reason):
|
def _server_status_cb(self, plugin, status, reason):
|
||||||
if status == CONNECTION_STATUS_CONNECTED:
|
if status == CONNECTION_STATUS_CONNECTED:
|
||||||
pass
|
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):
|
def _contact_online(self, tp, handle, props):
|
||||||
new_buddy = False
|
new_buddy = False
|
||||||
@ -130,7 +136,7 @@ class PresenceService(dbus.service.Object):
|
|||||||
print "Buddy %s icon updated" % buddy.props.key
|
print "Buddy %s icon updated" % buddy.props.key
|
||||||
buddy.props.icon = avatar
|
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)
|
buddy = self._handles_buddies[tp].get(handle)
|
||||||
if buddy:
|
if buddy:
|
||||||
buddy.set_properties(prop)
|
buddy.set_properties(prop)
|
||||||
@ -150,14 +156,14 @@ class PresenceService(dbus.service.Object):
|
|||||||
|
|
||||||
# FIXME
|
# FIXME
|
||||||
# Use values from the network
|
# Use values from the network
|
||||||
import random
|
#import random
|
||||||
names = ["Tommy", "Susie", "Jill", "Bryan", "Nathan", "Sophia", "Haley", "Jimmy"]
|
#names = ["Tommy", "Susie", "Jill", "Bryan", "Nathan", "Sophia", "Haley", "Jimmy"]
|
||||||
name = names[random.randint(0, len(names) - 1)]
|
#name = names[random.randint(0, len(names) - 1)]
|
||||||
activity.props.name = "Chat with %s" % name
|
#activity.props.name = "Chat with %s" % name
|
||||||
activity.props.type = "org.laptop.Sugar.Chat"
|
#activity.props.type = "org.laptop.Sugar.Chat"
|
||||||
from sugar.graphics import xocolor
|
#from sugar.graphics import xocolor
|
||||||
color = xocolor.XoColor().to_string()
|
#color = xocolor.XoColor().to_string()
|
||||||
activity.props.color = color
|
#activity.props.color = color
|
||||||
|
|
||||||
return activity
|
return activity
|
||||||
|
|
||||||
@ -167,7 +173,7 @@ class PresenceService(dbus.service.Object):
|
|||||||
self.ActivityDisappeared(activity.object_path())
|
self.ActivityDisappeared(activity.object_path())
|
||||||
del self._activities[activity.props.id]
|
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-------------"
|
print "------------activities changed-------------"
|
||||||
buddies = self._handles_buddies[tp]
|
buddies = self._handles_buddies[tp]
|
||||||
buddy = buddies.get(contact_handle)
|
buddy = buddies.get(contact_handle)
|
||||||
@ -299,6 +305,7 @@ class PresenceService(dbus.service.Object):
|
|||||||
self._activities[actid] = activity
|
self._activities[actid] = activity
|
||||||
|
|
||||||
activity.join()
|
activity.join()
|
||||||
|
activity.send_properties()
|
||||||
|
|
||||||
return activity
|
return activity
|
||||||
|
|
||||||
@ -310,6 +317,11 @@ class PresenceService(dbus.service.Object):
|
|||||||
self.ActivityDisappeared(activity.object_path())
|
self.ActivityDisappeared(activity.object_path())
|
||||||
print "Activity disappeared: %s (%s)" % (activity.props.name, activity.props.id)
|
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():
|
def main():
|
||||||
loop = gobject.MainLoop()
|
loop = gobject.MainLoop()
|
||||||
|
@ -37,6 +37,7 @@ from telepathy.constants import (
|
|||||||
CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED)
|
CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED)
|
||||||
|
|
||||||
CONN_INTERFACE_BUDDY_INFO = 'org.laptop.Telepathy.BuddyInfo'
|
CONN_INTERFACE_BUDDY_INFO = 'org.laptop.Telepathy.BuddyInfo'
|
||||||
|
CONN_INTERFACE_ACTIVITY_PROPERTIES = 'org.laptop.Telepathy.ActivityProperties'
|
||||||
|
|
||||||
_PROTOCOL = "jabber"
|
_PROTOCOL = "jabber"
|
||||||
|
|
||||||
@ -85,14 +86,16 @@ class ServerPlugin(gobject.GObject):
|
|||||||
([gobject.TYPE_INT, gobject.TYPE_INT])),
|
([gobject.TYPE_INT, gobject.TYPE_INT])),
|
||||||
'avatar-updated': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
'avatar-updated': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
||||||
([gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT])),
|
([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])),
|
([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])),
|
([gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT])),
|
||||||
'activity-invitation': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
'activity-invitation': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
||||||
([gobject.TYPE_PYOBJECT])),
|
([gobject.TYPE_PYOBJECT])),
|
||||||
'private-invitation': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
'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):
|
def __init__(self, registry, owner):
|
||||||
@ -142,6 +145,7 @@ class ServerPlugin(gobject.GObject):
|
|||||||
account_info['account'] = "%s@%s" % (khash, account_info['server'])
|
account_info['account'] = "%s@%s" % (khash, account_info['server'])
|
||||||
|
|
||||||
account_info['password'] = profile.get_private_key_hash()
|
account_info['password'] = profile.get_private_key_hash()
|
||||||
|
print account_info
|
||||||
return account_info
|
return account_info
|
||||||
|
|
||||||
def _find_existing_connection(self):
|
def _find_existing_connection(self):
|
||||||
@ -181,6 +185,7 @@ class ServerPlugin(gobject.GObject):
|
|||||||
# hack
|
# hack
|
||||||
conn._valid_interfaces.add(CONN_INTERFACE_PRESENCE)
|
conn._valid_interfaces.add(CONN_INTERFACE_PRESENCE)
|
||||||
conn._valid_interfaces.add(CONN_INTERFACE_BUDDY_INFO)
|
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_AVATARS)
|
||||||
conn._valid_interfaces.add(CONN_INTERFACE_ALIASING)
|
conn._valid_interfaces.add(CONN_INTERFACE_ALIASING)
|
||||||
|
|
||||||
@ -231,13 +236,15 @@ class ServerPlugin(gobject.GObject):
|
|||||||
self.cleanup()
|
self.cleanup()
|
||||||
return
|
return
|
||||||
|
|
||||||
self._conn[CONN_INTERFACE_BUDDY_INFO].connect_to_signal('PropertiesChanged', self._properties_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._activities_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_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_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:
|
try:
|
||||||
self._set_self_buddy_info()
|
self._set_self_buddy_info()
|
||||||
except RuntimeError, e:
|
except RuntimeError, e:
|
||||||
@ -289,7 +296,7 @@ class ServerPlugin(gobject.GObject):
|
|||||||
|
|
||||||
self._joined_activities.append((act, handle))
|
self._joined_activities.append((act, handle))
|
||||||
self._conn[CONN_INTERFACE_BUDDY_INFO].SetActivities(self._joined_activities)
|
self._conn[CONN_INTERFACE_BUDDY_INFO].SetActivities(self._joined_activities)
|
||||||
|
|
||||||
return channel
|
return channel
|
||||||
|
|
||||||
def _set_self_buddy_info(self):
|
def _set_self_buddy_info(self):
|
||||||
@ -387,7 +394,7 @@ class ServerPlugin(gobject.GObject):
|
|||||||
self.emit("contact-online", handle, props)
|
self.emit("contact-online", handle, props)
|
||||||
|
|
||||||
activities = self._conn[CONN_INTERFACE_BUDDY_INFO].GetActivities(handle)
|
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):
|
def _presence_update_cb(self, presence):
|
||||||
for handle in presence:
|
for handle in presence:
|
||||||
@ -419,16 +426,16 @@ class ServerPlugin(gobject.GObject):
|
|||||||
for handle, alias in aliases:
|
for handle, alias in aliases:
|
||||||
prop = {'nick': alias}
|
prop = {'nick': alias}
|
||||||
#print "Buddy %s alias changed to %s" % (handle, 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):
|
def _buddy_properties_changed_cb(self, contact, properties):
|
||||||
self.emit("properties-changed", 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:
|
for act_id, act_handle in activities:
|
||||||
self._activities[act_id] = act_handle
|
self._activities[act_id] = act_handle
|
||||||
activities_id = map(lambda x: x[0], activities)
|
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):
|
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:
|
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 \
|
elif handle_type == CONNECTION_HANDLE_TYPE_CONTACT and \
|
||||||
channel_type in [CHANNEL_TYPE_TEXT, CHANNEL_TYPE_STREAMED_MEDIA]:
|
channel_type in [CHANNEL_TYPE_TEXT, CHANNEL_TYPE_STREAMED_MEDIA]:
|
||||||
self.emit("private-invitation", object_path)
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user