def share_activity(self, activity, properties=None, private=True): if properties is None: properties = {} if "id" not in properties: properties["id"] = activity.get_id() if "type" not in properties: properties["type"] = activity.get_bundle_id() if "name" not in properties: properties["name"] = activity.metadata.get("title", None) if "color" not in properties: properties["color"] = activity.metadata.get("icon-color", None) properties["private"] = private if self._activity_cache is not None: raise ValueError("Activity %s is already tracked" % activity.get_id()) connection_manager = get_connection_manager() account_path, connection = connection_manager.get_preferred_connection() if connection is None: self.emit("activity-shared", False, None, "No active connection available") return shared_activity = Activity(account_path, connection, properties=properties) self._activity_cache = shared_activity if shared_activity.props.joined: raise RuntimeError("Activity %s is already shared." % activity.props.id) shared_activity.share(self.__share_activity_cb, self.__share_activity_error_cb)
def share_activity(self, activity, properties=None, private=True): if properties is None: properties = {} if 'id' not in properties: properties['id'] = activity.get_id() if 'type' not in properties: properties['type'] = activity.get_bundle_id() if 'name' not in properties: properties['name'] = activity.metadata.get('title', None) if 'color' not in properties: properties['color'] = activity.metadata.get('icon-color', None) properties['private'] = private if self._activity_cache is not None: raise ValueError('Activity %s is already tracked' % (activity.get_id())) connection_manager = get_connection_manager() account_path, connection = \ connection_manager.get_preferred_connection() if connection is None: self.emit('activity-shared', False, None, 'No active connection available') return shared_activity = Activity(account_path, connection, properties=properties) self._activity_cache = shared_activity if shared_activity.props.joined: raise RuntimeError('Activity %s is already shared.' % (activity.props.id)) shared_activity.share(self.__share_activity_cb, self.__share_activity_error_cb)
def share_activity(self, activity, properties=None, private=True): if properties is None: properties = {} if 'id' not in properties: properties['id'] = activity.get_id() if 'type' not in properties: properties['type'] = activity.get_bundle_id() if 'name' not in properties: properties['name'] = activity.metadata.get('title', None) if 'color' not in properties: properties['color'] = activity.metadata.get('icon-color', None) properties['private'] = private if self._activity_cache is not None: raise ValueError('Activity %s is already tracked' % activity.get_id()) connection_manager = get_connection_manager() account_path, connection = \ connection_manager.get_preferred_connection() if connection is None: self.emit('activity-shared', False, None, 'No active connection available') return shared_activity = Activity(account_path, connection, properties=properties) self._activity_cache = shared_activity if shared_activity.props.joined: raise RuntimeError('Activity %s is already shared.' % activity.props.id) shared_activity.share(self.__share_activity_cb, self.__share_activity_error_cb)
def get_activity(self, activity_id, warn_if_none=True): """Retrieve single Activity object for the given unique id activity_id -- unique ID for the activity returns single Activity object or None if the activity is not found using GetActivityById on the service """ if self._activity_cache is not None: if self._activity_cache.props.id != activity_id: raise RuntimeError('Activities can only access their own' ' shared instance') return self._activity_cache else: connection_manager = get_connection_manager() connections_per_account = \ connection_manager.get_connections_per_account() for account_path, connection in list( connections_per_account.items()): if not connection.connected: continue logging.debug('Calling GetActivity on %s' % account_path) try: room_handle = connection.connection.GetActivity( activity_id, dbus_interface=CONN_INTERFACE_ACTIVITY_PROPERTIES) except dbus.exceptions.DBusException as e: name = 'org.freedesktop.Telepathy.Error.NotAvailable' if e.get_dbus_name() == name: logging.debug("There's no shared activity with the id " "%s" % activity_id) elif e.get_dbus_name() == \ 'org.freedesktop.DBus.Error.UnknownMethod': logging.warning( 'Telepathy Account %r does not support ' 'Sugar collaboration', account_path) else: raise else: activity = Activity(account_path, connection.connection, room_handle=room_handle) self._activity_cache = activity return activity return None
def get_activity_by_handle(self, connection_path, room_handle): if self._activity_cache is not None: if self._activity_cache.room_handle != room_handle: raise RuntimeError('Activities can only access their own' ' shared instance') return self._activity_cache else: connection_manager = get_connection_manager() account_path = \ connection_manager.get_account_for_connection(connection_path) connection_name = connection_path.replace('/', '.')[1:] bus = dbus.SessionBus() connection = bus.get_object(connection_name, connection_path) activity = Activity(account_path, connection, room_handle=room_handle) self._activity_cache = activity return activity