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

Conflicts:

	services/presence/server_plugin.py
This commit is contained in:
Simon McVittie 2007-05-16 12:30:49 +01:00
commit 531321740c
6 changed files with 93 additions and 35 deletions

View File

@ -622,7 +622,10 @@ class ServerPlugin(gobject.GObject):
def cleanup(self): def cleanup(self):
"""If we still have a connection, disconnect it""" """If we still have a connection, disconnect it"""
if self._conn: if self._conn:
self._conn[CONN_INTERFACE].Disconnect() try:
self._conn[CONN_INTERFACE].Disconnect()
except:
pass
self._conn = None self._conn = None
self._conn_status = CONNECTION_STATUS_DISCONNECTED self._conn_status = CONNECTION_STATUS_DISCONNECTED
@ -670,10 +673,16 @@ class ServerPlugin(gobject.GObject):
reply_handler=lambda *args: self._contact_online_activities_cb(handle, *args), reply_handler=lambda *args: self._contact_online_activities_cb(handle, *args),
error_handler=lambda *args: self._contact_online_activities_error_cb(handle, *args)) error_handler=lambda *args: self._contact_online_activities_error_cb(handle, *args))
def _contact_online_aliases_error_cb(self, handle, err): def _contact_online_aliases_error_cb(self, handle, props, retry, err):
"""Handle failure to retrieve given user's alias/information""" """Handle failure to retrieve given user's alias/information"""
_logger.debug("Handle %s - Error getting nickname: %s" % (handle, err)) if retry:
self._contact_offline(handle) _logger.debug("Handle %s - Error getting nickname (will retry): %s" % (handle, err))
self._conn[CONN_INTERFACE_ALIASING].RequestAliases([handle],
reply_handler=lambda *args: self._contact_online_aliases_cb(handle, props, *args),
error_handler=lambda *args: self._contact_online_aliases_error_cb(handle, props, False, *args))
else:
_logger.debug("Handle %s - Error getting nickname: %s" % (handle, err))
self._contact_offline(handle)
def _contact_online_properties_cb(self, handle, props): def _contact_online_properties_cb(self, handle, props):
"""Handle failure to retrieve given user's alias/information""" """Handle failure to retrieve given user's alias/information"""
@ -691,12 +700,23 @@ class ServerPlugin(gobject.GObject):
self._conn[CONN_INTERFACE_ALIASING].RequestAliases([handle], self._conn[CONN_INTERFACE_ALIASING].RequestAliases([handle],
reply_handler=lambda *args: self._contact_online_aliases_cb(handle, props, *args), reply_handler=lambda *args: self._contact_online_aliases_cb(handle, props, *args),
error_handler=lambda *args: self._contact_online_aliases_error_cb(handle, *args)) error_handler=lambda *args: self._contact_online_aliases_error_cb(handle, props, True, *args))
def _contact_online_properties_error_cb(self, handle, err): def _contact_online_request_properties(self, handle, tries):
"""Handle error retrieving property-set for a user (handle)""" self._conn[CONN_INTERFACE_BUDDY_INFO].GetProperties(handle,
_logger.debug("Handle %s - Error getting properties: %s" % (handle, err)) reply_handler=lambda *args: self._contact_online_properties_cb(handle, *args),
self._contact_offline(handle) error_handler=lambda *args: self._contact_online_properties_error_cb(handle, tries, *args))
return False
def _contact_online_properties_error_cb(self, handle, tries, err):
"""Handle error retrieving property-set for a user (handle)"""
if tries <= 3:
_logger.debug("Handle %s - Error getting properties (will retry): %s" % (handle, err))
tries += 1
gobject.timeout_add(1000, self._contact_online_request_properties, handle, tries)
else:
_logger.debug("Handle %s - Error getting properties: %s" % (handle, err))
self._contact_offline(handle)
def _contact_online(self, handle): def _contact_online(self, handle):
"""Handle a contact coming online""" """Handle a contact coming online"""
@ -715,9 +735,7 @@ class ServerPlugin(gobject.GObject):
# are handled locally # are handled locally
return return
self._conn[CONN_INTERFACE_BUDDY_INFO].GetProperties(handle, self._contact_online_request_properties(handle, 1)
reply_handler=lambda *args: self._contact_online_properties_cb(handle, *args),
error_handler=lambda *args: self._contact_online_properties_error_cb(handle, *args))
def _subscribe_members_changed_cb(self, added, removed, local_pending, def _subscribe_members_changed_cb(self, added, removed, local_pending,
remote_pending, actor, reason): remote_pending, actor, reason):
@ -765,6 +783,15 @@ class ServerPlugin(gobject.GObject):
elif status in ["offline", "invisible"]: elif status in ["offline", "invisible"]:
self._contact_offline(handle) self._contact_offline(handle)
def _request_avatar_cb(self, handle, new_avatar_token, avatar, mime_type):
jid = self._online_contacts[handle]
if not jid:
logging.debug("Handle %s not valid yet..." % handle)
return
icon = ''.join(map(chr, avatar))
self._icon_cache.store_icon(jid, new_avatar_token, icon)
self.emit("avatar-updated", handle, icon)
def _avatar_updated_cb(self, handle, new_avatar_token): def _avatar_updated_cb(self, handle, new_avatar_token):
"""Handle update of given user (handle)'s avatar""" """Handle update of given user (handle)'s avatar"""
if handle == self._conn[CONN_INTERFACE].GetSelfHandle(): if handle == self._conn[CONN_INTERFACE].GetSelfHandle():
@ -784,11 +811,11 @@ class ServerPlugin(gobject.GObject):
icon = self._icon_cache.get_icon(jid, new_avatar_token) icon = self._icon_cache.get_icon(jid, new_avatar_token)
if not icon: if not icon:
# cache miss # cache miss
avatar, mime_type = self._conn[CONN_INTERFACE_AVATARS].RequestAvatar(handle) self._conn[CONN_INTERFACE_AVATARS].RequestAvatar(handle,
icon = ''.join(map(chr, avatar)) reply_handler=lambda *args: self._request_avatar_cb(handle, new_avatar_token, *args),
self._icon_cache.store_icon(jid, new_avatar_token, icon) error_handler=lambda *args: self._log_error_cb("getting avatar", *args))
else:
self.emit("avatar-updated", handle, icon) self.emit("avatar-updated", handle, icon)
def _alias_changed_cb(self, aliases): def _alias_changed_cb(self, aliases):
"""Handle update of aliases for all users""" """Handle update of aliases for all users"""

View File

@ -41,6 +41,9 @@ class ActivityModel:
def get_service_name(self): def get_service_name(self):
return self._bundle.get_service_name() return self._bundle.get_service_name()
def get_title(self):
return self._activity.props.name
class MeshModel(gobject.GObject): class MeshModel(gobject.GObject):
__gsignals__ = { __gsignals__ = {
'activity-added': (gobject.SIGNAL_RUN_FIRST, 'activity-added': (gobject.SIGNAL_RUN_FIRST,

View File

@ -170,11 +170,15 @@ class ActivityView(SnowflakeBox):
self._model = model self._model = model
self._icons = {} self._icons = {}
icon = CanvasIcon(icon_name=model.get_icon_name(), self._icon = CanvasIcon(icon_name=model.get_icon_name(),
xo_color=model.get_color(), box_width=80) xo_color=model.get_color(), box_width=80)
icon.connect('activated', self._clicked_cb) self._icon.connect('activated', self._clicked_cb)
self.append(icon, hippo.PACK_FIXED) self._update_name()
self.set_root(icon) self.append(self._icon, hippo.PACK_FIXED)
self.set_root(self._icon)
def _update_name(self):
self._icon.props.tooltip = self._model.get_title()
def has_buddy_icon(self, key): def has_buddy_icon(self, key):
return self._icons.has_key(key) return self._icons.has_key(key)

View File

@ -207,15 +207,20 @@ class Activity(Window, gtk.Container):
self.jobject['preview'] = '' self.jobject['preview'] = ''
self.jobject['icon-color'] = profile.get_color().to_string() self.jobject['icon-color'] = profile.get_color().to_string()
self.jobject.file_path = '' self.jobject.file_path = ''
try: datastore.write(self.jobject,
datastore.write(self.jobject) reply_handler=self._internal_jobject_create_cb,
except Exception, e: error_handler=self._internal_jobject_error_cb)
logging.error(e)
else: else:
self.jobject = None self.jobject = None
self.connect('focus-out-event', self._focus_out_event_cb) self.connect('focus-out-event', self._focus_out_event_cb)
def _internal_jobject_create_cb(self):
pass
def _internal_jobject_error_cb(self, err):
logging.debug("Error creating activity datastore object: %s" % err)
def _focus_out_event_cb(self, widget, event): def _focus_out_event_cb(self, widget, event):
if self.jobject: if self.jobject:
self.save() self.save()
@ -234,6 +239,12 @@ class Activity(Window, gtk.Container):
""" """
raise NotImplementedError raise NotImplementedError
def _internal_save_cb(self):
pass
def _internal_save_error_cb(self, err):
logging.debug("Error saving activity object to datastore: %s" % err)
def save(self): def save(self):
"""Request that the activity is saved to the Journal.""" """Request that the activity is saved to the Journal."""
try: try:
@ -241,7 +252,9 @@ class Activity(Window, gtk.Container):
self.write_file() self.write_file()
except NotImplementedError: except NotImplementedError:
self.jobject.file_path = '' self.jobject.file_path = ''
datastore.write(self.jobject) datastore.write(self.jobject,
reply_handler=self._internal_save_cb,
error_handler=self._internal_save_error_cb)
def _internal_joined_cb(self, activity, success, err): def _internal_joined_cb(self, activity, success, err):
"""Callback when join has finished""" """Callback when join has finished"""

View File

@ -71,20 +71,22 @@ def get(object_id):
def create(): def create():
return DSObject(object_id=None, metadata={}, file_path=None) return DSObject(object_id=None, metadata={}, file_path=None)
def write(ds_object): def write(ds_object, reply_handler=None, error_handler=None):
logging.debug('datastore.write') logging.debug('datastore.write')
if ds_object.object_id: if ds_object.object_id:
dbus_helpers.update(ds_object.object_id, dbus_helpers.update(ds_object.object_id,
ds_object.metadata, ds_object.metadata,
ds_object.file_path) ds_object.file_path,
reply_handler=reply_handler,
error_handler=error_handler)
else: else:
ds_object.object_id = dbus_helpers.create(ds_object.metadata, ds_object.object_id = dbus_helpers.create(ds_object.metadata,
ds_object.file_path) ds_object.file_path)
# TODO: register the object for updates # TODO: register the object for updates
logging.debug('Written object %s to the datastore.' % ds_object.object_id) logging.debug('Written object %s to the datastore.' % ds_object.object_id)
def find(query): def find(query, reply_handler=None, error_handler=None):
object_ids = dbus_helpers.find({}) object_ids = dbus_helpers.find(query, reply_handler, error_handler)
objects = [] objects = []
for object_id in object_ids: for object_id in object_ids:
objects.append(get(object_id)) objects.append(get(object_id))

View File

@ -54,13 +54,18 @@ def create(properties, filename):
logging.debug('dbus_helpers.create: ' + object_id) logging.debug('dbus_helpers.create: ' + object_id)
return object_id return object_id
def update(uid, properties, filename): def update(uid, properties, filename, reply_handler=None, error_handler=None):
logging.debug('dbus_helpers.update: %s, %s, %s' % (uid, properties, filename)) logging.debug('dbus_helpers.update: %s, %s, %s' % (uid, properties, filename))
try: try:
logging.debug(get_contents(filename)) logging.debug(get_contents(filename))
except UnicodeDecodeError: except UnicodeDecodeError:
pass pass
_data_store.update(uid, dbus.Dictionary(properties), filename) if reply_handler and error_handler:
_data_store.update(uid, dbus.Dictionary(properties), filename,
reply_handler=reply_handler,
error_handler=error_handler)
else:
_data_store.update(uid, dbus.Dictionary(properties), filename)
def get_properties(uid): def get_properties(uid):
props = _data_store.get_properties(uid) props = _data_store.get_properties(uid)
@ -76,8 +81,12 @@ def get_filename(uid):
pass pass
return filename return filename
def find(query): def find(query, reply_handler, error_handler):
return _data_store.find(query) if reply_handler and error_handler:
return _data_store.find(query, reply_handler=reply_handler,
error_handler=error_handler)
else:
return _data_store.find(query)
""" """