diff options
Diffstat (limited to 'src/jarabe/model/neighborhood.py')
-rw-r--r-- | src/jarabe/model/neighborhood.py | 112 |
1 files changed, 62 insertions, 50 deletions
diff --git a/src/jarabe/model/neighborhood.py b/src/jarabe/model/neighborhood.py index 91dd059..ca4c5bf 100644 --- a/src/jarabe/model/neighborhood.py +++ b/src/jarabe/model/neighborhood.py @@ -48,6 +48,7 @@ from sugar.profile import get_profile from jarabe.model.buddy import BuddyModel, get_owner_instance from jarabe.model import bundleregistry + ACCOUNT_MANAGER_SERVICE = 'org.freedesktop.Telepathy.AccountManager' ACCOUNT_MANAGER_PATH = '/org/freedesktop/Telepathy/AccountManager' CHANNEL_DISPATCHER_SERVICE = 'org.freedesktop.Telepathy.ChannelDispatcher' @@ -65,17 +66,21 @@ Time in seconds to wait when querying contact properties. Some jabber servers will be very slow in returning these queries, so just be patient. """ +_model = None + + class ActivityModel(gobject.GObject): __gsignals__ = { - 'current-buddy-added': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([object])), - 'current-buddy-removed': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([object])), - 'buddy-added': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([object])), - 'buddy-removed': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([object])), + 'current-buddy-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ([object])), + 'current-buddy-removed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ([object])), + 'buddy-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ([object])), + 'buddy-removed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ([object])), } + def __init__(self, activity_id, room_handle): gobject.GObject.__init__(self) @@ -102,7 +107,8 @@ class ActivityModel(gobject.GObject): def set_bundle(self, bundle): self._bundle = bundle - bundle = gobject.property(type=object, getter=get_bundle, setter=set_bundle) + bundle = gobject.property(type=object, getter=get_bundle, + setter=set_bundle) def get_name(self): return self._name @@ -151,30 +157,29 @@ class ActivityModel(gobject.GObject): current_buddies = gobject.property(type=object, getter=get_current_buddies) + class _Account(gobject.GObject): __gsignals__ = { - 'activity-added': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([object, object])), - 'activity-updated': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([object, object])), - 'activity-removed': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([object])), - 'buddy-added': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([object, object, object])), - 'buddy-updated': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([object, object])), - 'buddy-removed': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([object])), - 'buddy-joined-activity': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([object, object])), - 'buddy-left-activity': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([object, object])), + 'activity-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ([object, object])), + 'activity-updated': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ([object, object])), + 'activity-removed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ([object])), + 'buddy-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ([object, object, object])), + 'buddy-updated': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ([object, object])), + 'buddy-removed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ([object])), + 'buddy-joined-activity': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ([object, object])), + 'buddy-left-activity': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ([object, object])), 'current-activity-updated': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([object, object])), - 'connected': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([])), - 'disconnected': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([])), + 'connected': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), + 'disconnected': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), } def __init__(self, account_path): @@ -203,7 +208,8 @@ class _Account(gobject.GObject): 'AccountPropertyChanged', self.__account_property_changed_cb) def __error_handler_cb(self, function_name, error): - raise RuntimeError('Error when calling %s: %s' % (function_name, error)) + raise RuntimeError('Error when calling %s: %s' % (function_name, + error)) def __got_connection_cb(self, connection_path): logging.debug('_Account.__got_connection_cb %r', connection_path) @@ -379,7 +385,8 @@ class _Account(gobject.GObject): logging.debug('Got handle %r with nick %r, going to update', handle, alias) properties = {CONNECTION_INTERFACE_ALIASING + '/alias': alias} - self.emit('buddy-updated', self._buddy_handles[handle], properties) + self.emit('buddy-updated', self._buddy_handles[handle], + properties) def __presences_changed_cb(self, presences): logging.debug('_Account.__presences_changed_cb %r', presences) @@ -573,7 +580,8 @@ class _Account(gobject.GObject): connection.GetActivities( handle, - reply_handler=partial(self.__got_activities_cb, handle), + reply_handler=partial(self.__got_activities_cb, + handle), error_handler=partial(self.__error_handler_cb, 'BuddyInfo.GetActivities'), timeout=_QUERY_DBUS_TIMEOUT) @@ -609,21 +617,22 @@ class _Account(gobject.GObject): reply_handler=self.__set_enabled_cb, error_handler=partial(self.__error_handler_cb, 'Account.SetEnabled'), - dbus_interface='org.freedesktop.DBus.Properties') + dbus_interface=dbus.PROPERTIES_IFACE) def __set_enabled_cb(self): logging.debug('_Account.__set_enabled_cb success') + class Neighborhood(gobject.GObject): __gsignals__ = { - 'activity-added': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([object])), - 'activity-removed': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([object])), - 'buddy-added': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([object])), - 'buddy-removed': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([object])) + 'activity-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ([object])), + 'activity-removed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ([object])), + 'buddy-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ([object])), + 'buddy-removed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ([object])), } def __init__(self): @@ -635,7 +644,8 @@ class Neighborhood(gobject.GObject): self._server_account = None client = gconf.client_get_default() - client.add_dir('/desktop/sugar/collaboration', gconf.CLIENT_PRELOAD_NONE) + client.add_dir('/desktop/sugar/collaboration', + gconf.CLIENT_PRELOAD_NONE) client.notify_add('/desktop/sugar/collaboration/jabber_server', self.__jabber_server_changed_cb) client.add_dir('/desktop/sugar/user/nick', gconf.CLIENT_PRELOAD_NONE) @@ -732,7 +742,8 @@ class Neighborhood(gobject.GObject): client = gconf.client_get_default() nick = client.get_string('/desktop/sugar/user/nick') - server = client.get_string('/desktop/sugar/collaboration/jabber_server') + server = client.get_string('/desktop/sugar/collaboration' + '/jabber_server') key_hash = get_profile().privkey_hash params = { @@ -764,7 +775,8 @@ class Neighborhood(gobject.GObject): def _get_jabber_account_id(self): public_key_hash = sha1(get_profile().pubkey).hexdigest() client = gconf.client_get_default() - server = client.get_string('/desktop/sugar/collaboration/jabber_server') + server = client.get_string('/desktop/sugar/collaboration' + '/jabber_server') return '%s@%s' % (public_key_hash, server) def __jabber_server_changed_cb(self, client, timestamp, entry, *extra): @@ -774,7 +786,8 @@ class Neighborhood(gobject.GObject): account = bus.get_object(ACCOUNT_MANAGER_SERVICE, self._server_account.object_path) - server = client.get_string('/desktop/sugar/collaboration/jabber_server') + server = client.get_string( + '/desktop/sugar/collaboration/jabber_server') account_id = self._get_jabber_account_id() needs_reconnect = account.UpdateParameters({'server': server, 'account': account_id, @@ -830,8 +843,8 @@ class Neighborhood(gobject.GObject): return if contact_id not in self._buddies: - logging.debug('__buddy_updated_cb Unknown buddy with contact_id %r', - contact_id) + logging.debug('__buddy_updated_cb Unknown buddy with contact_id' + ' %r', contact_id) return buddy = self._buddies[contact_id] @@ -917,8 +930,8 @@ class Neighborhood(gobject.GObject): 'contact_id %r', contact_id) return if activity_id and activity_id not in self._activities: - logging.debug('__current_activity_updated_cb Unknown activity with ' - 'id %s', activity_id) + logging.debug('__current_activity_updated_cb Unknown activity with' + ' id %s', activity_id) activity_id = '' buddy = self._buddies[contact_id] @@ -987,7 +1000,6 @@ class Neighborhood(gobject.GObject): def get_activities(self): return self._activities.values() -_model = None def get_model(): global _model |