Пример #1
0
    def get_preferred_connection(self):
        """Gets the preferred telepathy connection object that an activity
        should use when talking directly to telepathy

        returns the bus name and the object path of the Telepathy connection
        """
        manager = get_connection_manager()
        account_path, connection = manager.get_preferred_connection()
        if connection is None:
            return None
        else:
            return connection.requested_bus_name, connection.object_path
Пример #2
0
    def get_preferred_connection(self):
        """Gets the preferred telepathy connection object that an activity
        should use when talking directly to telepathy

        returns the bus name and the object path of the Telepathy connection
        """
        manager = get_connection_manager()
        account_path, connection = manager.get_preferred_connection()
        if connection is None:
            return None
        else:
            return connection.requested_bus_name, connection.object_path
Пример #3
0
    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
    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 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, 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
Пример #5
0
    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
Пример #6
0
    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 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, 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
Пример #8
0
    def __init__(self, account_path, contact_id):
        _logger.debug('Buddy.__init__')
        BaseBuddy.__init__(self)

        self._account_path = account_path
        self.contact_id = contact_id
        self.contact_handle = None

        connection_manager = get_connection_manager()
        connection = connection_manager.get_connection(account_path)

        connection_name = connection.object_path.replace('/', '.')[1:]

        bus = dbus.SessionBus()
        obj = bus.get_object(connection_name, connection.object_path)
        handles = obj.RequestHandles(HANDLE_TYPE_CONTACT, [self.contact_id],
                                     dbus_interface=CONNECTION)
        self.contact_handle = handles[0]

        self._get_properties_call = bus.call_async(
                connection_name,
                connection.object_path,
                CONN_INTERFACE_BUDDY_INFO,
                'GetProperties',
                'u',
                (self.contact_handle,),
                reply_handler=self.__got_properties_cb,
                error_handler=self.__error_handler_cb,
                utf8_strings=True,
                byte_arrays=True)

        self._get_attributes_call = bus.call_async(
                connection_name,
                connection.object_path,
                CONNECTION_INTERFACE_CONTACTS,
                'GetContactAttributes',
                'auasb',
                ([self.contact_handle], [CONNECTION_INTERFACE_ALIASING],
                 False),
                reply_handler=self.__got_attributes_cb,
                error_handler=self.__error_handler_cb)
Пример #9
0
    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)
Пример #10
0
    def __init__(self, account_path, contact_id):
        _logger.debug('Buddy.__init__')
        BaseBuddy.__init__(self)

        self._account_path = account_path
        self.contact_id = contact_id
        self.contact_handle = None

        connection_manager = get_connection_manager()
        connection = connection_manager.get_connection(account_path)

        connection_name = connection.object_path.replace('/', '.')[1:]

        bus = dbus.SessionBus()
        obj = bus.get_object(connection_name, connection.object_path)
        handles = obj.RequestHandles(HANDLE_TYPE_CONTACT, [self.contact_id],
                                     dbus_interface=CONNECTION)
        self.contact_handle = handles[0]

        self._get_properties_call = bus.call_async(
            connection_name,
            connection.object_path,
            CONN_INTERFACE_BUDDY_INFO,
            'GetProperties',
            'u', (self.contact_handle, ),
            reply_handler=self.__got_properties_cb,
            error_handler=self.__error_handler_cb,
            utf8_strings=True,
            byte_arrays=True)

        self._get_attributes_call = bus.call_async(
            connection_name,
            connection.object_path,
            CONNECTION_INTERFACE_CONTACTS,
            'GetContactAttributes',
            'auasb',
            ([self.contact_handle], [CONNECTION_INTERFACE_ALIASING], False),
            reply_handler=self.__got_attributes_cb,
            error_handler=self.__error_handler_cb)