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):
"""If we still have a connection, disconnect it"""
if self._conn:
try:
self._conn[CONN_INTERFACE].Disconnect()
except:
pass
self._conn = None
self._conn_status = CONNECTION_STATUS_DISCONNECTED
@ -670,8 +673,14 @@ class ServerPlugin(gobject.GObject):
reply_handler=lambda *args: self._contact_online_activities_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"""
if retry:
_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)
@ -691,10 +700,21 @@ class ServerPlugin(gobject.GObject):
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, *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):
self._conn[CONN_INTERFACE_BUDDY_INFO].GetProperties(handle,
reply_handler=lambda *args: self._contact_online_properties_cb(handle, *args),
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)
@ -715,9 +735,7 @@ class ServerPlugin(gobject.GObject):
# are handled locally
return
self._conn[CONN_INTERFACE_BUDDY_INFO].GetProperties(handle,
reply_handler=lambda *args: self._contact_online_properties_cb(handle, *args),
error_handler=lambda *args: self._contact_online_properties_error_cb(handle, *args))
self._contact_online_request_properties(handle, 1)
def _subscribe_members_changed_cb(self, added, removed, local_pending,
remote_pending, actor, reason):
@ -765,6 +783,15 @@ class ServerPlugin(gobject.GObject):
elif status in ["offline", "invisible"]:
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):
"""Handle update of given user (handle)'s avatar"""
if handle == self._conn[CONN_INTERFACE].GetSelfHandle():
@ -784,10 +811,10 @@ class ServerPlugin(gobject.GObject):
icon = self._icon_cache.get_icon(jid, new_avatar_token)
if not icon:
# cache miss
avatar, mime_type = self._conn[CONN_INTERFACE_AVATARS].RequestAvatar(handle)
icon = ''.join(map(chr, avatar))
self._icon_cache.store_icon(jid, new_avatar_token, icon)
self._conn[CONN_INTERFACE_AVATARS].RequestAvatar(handle,
reply_handler=lambda *args: self._request_avatar_cb(handle, new_avatar_token, *args),
error_handler=lambda *args: self._log_error_cb("getting avatar", *args))
else:
self.emit("avatar-updated", handle, icon)
def _alias_changed_cb(self, aliases):

View File

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

View File

@ -170,11 +170,15 @@ class ActivityView(SnowflakeBox):
self._model = model
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)
icon.connect('activated', self._clicked_cb)
self.append(icon, hippo.PACK_FIXED)
self.set_root(icon)
self._icon.connect('activated', self._clicked_cb)
self._update_name()
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):
return self._icons.has_key(key)

View File

@ -207,15 +207,20 @@ class Activity(Window, gtk.Container):
self.jobject['preview'] = ''
self.jobject['icon-color'] = profile.get_color().to_string()
self.jobject.file_path = ''
try:
datastore.write(self.jobject)
except Exception, e:
logging.error(e)
datastore.write(self.jobject,
reply_handler=self._internal_jobject_create_cb,
error_handler=self._internal_jobject_error_cb)
else:
self.jobject = None
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):
if self.jobject:
self.save()
@ -234,6 +239,12 @@ class Activity(Window, gtk.Container):
"""
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):
"""Request that the activity is saved to the Journal."""
try:
@ -241,7 +252,9 @@ class Activity(Window, gtk.Container):
self.write_file()
except NotImplementedError:
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):
"""Callback when join has finished"""

View File

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

View File

@ -54,12 +54,17 @@ def create(properties, filename):
logging.debug('dbus_helpers.create: ' + 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))
try:
logging.debug(get_contents(filename))
except UnicodeDecodeError:
pass
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):
@ -76,7 +81,11 @@ def get_filename(uid):
pass
return filename
def find(query):
def find(query, reply_handler, error_handler):
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)
"""