예제 #1
0
파일: client.py 프로젝트: 0-wiz-0/Coherence
 def new_channels_cb(self, channels):
     self._channels.extend(channels)
     for path, props in channels:
         self.debug("new channel with path %r and props %r", path, props)
         if props[CHANNEL_INTERFACE + ".ChannelType"] == CHANNEL_TYPE_DBUS_TUBE:
             tube = Channel(self.conn.dbus_proxy.bus_name, path)
             self.connect_tube_signals(tube)
             tube.props = props
             self._tubes[path] = tube
             self.got_tube(tube)
예제 #2
0
 def new_channels_cb(self, channels):
     self._channels.extend(channels)
     for path, props in channels:
         self.debug("new channel with path %r and props %r", path, props)
         if props[CHANNEL_INTERFACE +
                  ".ChannelType"] == CHANNEL_TYPE_DBUS_TUBE:
             tube = Channel(self.conn.dbus_proxy.bus_name, path)
             self.connect_tube_signals(tube)
             tube.props = props
             self._tubes[path] = tube
             self.got_tube(tube)
예제 #3
0
파일: activity.py 프로젝트: dsd/turtleart
 def __create_tubes_channel_cb(self, channel_path):
     print("Creating tubes channel with bus name %s" %
           (self._connection.requested_bus_name))
     print("Creating tubes channel with channel path %s" % (channel_path))
     Channel(self._connection.requested_bus_name,
             channel_path,
             ready_handler=self.__tubes_channel_ready_cb)
예제 #4
0
    def __connection_ready_cb(self, connection):
        requests = connection[CONNECTION_INTERFACE_REQUESTS]
        object_path, properties_ = requests.CreateChannel({
            CHANNEL + '.ChannelType':
            CHANNEL_TYPE_FILE_TRANSFER,
            CHANNEL + '.TargetHandleType':
            CONNECTION_HANDLE_TYPE_CONTACT,
            CHANNEL + '.TargetHandle':
            self.buddy.handle,
            CHANNEL_TYPE_FILE_TRANSFER + '.ContentType':
            self.mime_type,
            CHANNEL_TYPE_FILE_TRANSFER + '.Filename':
            self.title,
            CHANNEL_TYPE_FILE_TRANSFER + '.Size':
            self.file_size,
            CHANNEL_TYPE_FILE_TRANSFER + '.Description':
            self.description,
            CHANNEL_TYPE_FILE_TRANSFER + '.InitialOffset':
            0
        })

        self.set_channel(Channel(connection.service_name, object_path))

        channel_file_transfer = self.channel[CHANNEL_TYPE_FILE_TRANSFER]
        self._socket_address = channel_file_transfer.ProvideFile(
            SOCKET_ADDRESS_TYPE_UNIX,
            SOCKET_ACCESS_CONTROL_LOCALHOST,
            '',
            byte_arrays=True)
예제 #5
0
    def join_muc(self):
        # workaround to be sure that the muc service is fully resolved in
        # Salut.
        time.sleep(2)

        print "join muc", self.muc_id
        chan_path, props = self.conn[
            CONNECTION_INTERFACE_REQUESTS].CreateChannel({
                CHANNEL_INTERFACE + ".ChannelType":
                CHANNEL_TYPE_TEXT,
                CHANNEL_INTERFACE + ".TargetHandleType":
                CONNECTION_HANDLE_TYPE_ROOM,
                CHANNEL_INTERFACE + ".TargetID":
                self.muc_id
            })

        self.channel_text = Channel(self.conn.dbus_proxy.bus_name, chan_path)

        self.self_handle = self.channel_text[
            CHANNEL_INTERFACE_GROUP].GetSelfHandle()
        self.channel_text[CHANNEL_INTERFACE_GROUP].connect_to_signal(
            "MembersChanged", self.text_channel_members_changed_cb)

        if self.self_handle in self.channel_text[
                CHANNEL_INTERFACE_GROUP].GetMembers():
            self.joined = True
            self.muc_joined()
예제 #6
0
 def _request_list_channel(self, name):
     handle = self.conn[CONN_INTERFACE].RequestHandles(
         CONNECTION_HANDLE_TYPE_LIST, [name])[0]
     chan_path = self.conn[CONN_INTERFACE].RequestChannel(
         CHANNEL_TYPE_CONTACT_LIST, CONNECTION_HANDLE_TYPE_LIST, handle,
         True)
     channel = Channel(self.conn.service_name, chan_path)
     return channel
예제 #7
0
    def __init__(self, connection, object_path, props):
        BaseFileTransfer.__init__(self, connection)

        channel = Channel(connection.service_name, object_path)
        self.set_channel(channel)

        self.connect('notify::state', self.__notify_state_cb)

        self.destination_path = None
        self._socket_address = None
        self._socket = None
        self._splicer = None
예제 #8
0
    def _one_to_one_connection_ready_cb(self, bus_name, channel, conn):
        """Callback for Connection for one to one connection"""
        text_channel = Channel(bus_name, channel)
        self.text_channel = TextChannelWrapper(text_channel, conn)
        self.text_channel.set_received_callback(self._received_cb)
        self.text_channel.handle_pending_messages()
        self.text_channel.set_closed_callback(
            self._one_to_one_connection_closed_cb)
        self._chat_is_room = False
        self._alert(_('On-line'), _('Private Chat'))

        # XXX How do we detect the sender going offline?
        self.entry.set_sensitive(True)
        self.entry.grab_focus()
예제 #9
0
    def new_channels_cb(self, channels):
        if self.tube is not None:
            return

        for path, props in channels:
            if props[CHANNEL_INTERFACE +
                     ".ChannelType"] == CHANNEL_TYPE_DBUS_TUBE:
                self.tube = Channel(self.conn.dbus_proxy.bus_name, path)

                self.tube[CHANNEL_INTERFACE_TUBE].connect_to_signal(
                    "TubeChannelStateChanged",
                    self.tube_channel_state_changed_cb)
                self.tube[CHANNEL_INTERFACE].connect_to_signal(
                    "Closed", self.tube_closed_cb)

                self.got_tube(props)
예제 #10
0
    def _create_channel(self, file_size):
        object_path, properties_ = self._conn.CreateChannel(dbus.Dictionary({
            CHANNEL + '.ChannelType': CHANNEL_TYPE_FILE_TRANSFER,
            CHANNEL + '.TargetHandleType': CONNECTION_HANDLE_TYPE_CONTACT,
            CHANNEL + '.TargetHandle': self.buddy.contact_handle,
            CHANNEL_TYPE_FILE_TRANSFER + '.Filename': self._filename,
            CHANNEL_TYPE_FILE_TRANSFER + '.Description': self._description,
            CHANNEL_TYPE_FILE_TRANSFER + '.Size': file_size,
            CHANNEL_TYPE_FILE_TRANSFER + '.ContentType': self._mime,
            CHANNEL_TYPE_FILE_TRANSFER + '.InitialOffset': 0}, signature='sv'))
        self.set_channel(Channel(self._conn.bus_name, object_path))

        channel_file_transfer = self.channel[CHANNEL_TYPE_FILE_TRANSFER]
        self._socket_address = channel_file_transfer.ProvideFile(
            SOCKET_ADDRESS_TYPE_UNIX, SOCKET_ACCESS_CONTROL_LOCALHOST, '',
            byte_arrays=True)
예제 #11
0
    def new_channels_cb(self, channels):
        for path, props in channels:
            if props[CHANNEL + '.ChannelType'] == CHANNEL_TYPE_FILE_TRANSFER:
                print "new FileTransfer channel"
                self.ft_channel = Channel(self.conn.service_name, path)

                self.ft_channel[CHANNEL_TYPE_FILE_TRANSFER].connect_to_signal(
                    'FileTransferStateChanged', self.ft_state_changed_cb)
                self.ft_channel[CHANNEL_TYPE_FILE_TRANSFER].connect_to_signal(
                    'TransferredBytesChanged',
                    self.ft_transferred_bytes_changed_cb)
                self.ft_channel[CHANNEL_TYPE_FILE_TRANSFER].connect_to_signal(
                    'InitialOffsetDefined', self.ft_initial_offset_defined_cb)
                self.got_ft_channel()

                self.file_name = props[CHANNEL_TYPE_FILE_TRANSFER +
                                       '.Filename']
                self.file_size = props[CHANNEL_TYPE_FILE_TRANSFER + '.Size']
예제 #12
0
    def join_muc(self):
        conn_obj = self.conn[CONN_INTERFACE]

        # workaround to be sure that the muc service is fully resolved in
        # Salut.
        if conn_obj.GetProtocol() == "local-xmpp":
            time.sleep(2)

        muc_id = self.muc_id
        self.info("joining MUC %r", muc_id)

        if self.existing_client:
            self.channel_text = self.existing_client.channel_text
            #self.new_channels_cb(self.existing_client._channels)
            self._tubes = self.existing_client._pending_tubes
            for path, tube in self._tubes.iteritems():
                self.connect_tube_signals(tube)
                self.got_tube(tube)
        else:
            conn_iface = self.conn[CONNECTION_INTERFACE_REQUESTS]
            params = {
                CHANNEL_INTERFACE + ".ChannelType": CHANNEL_TYPE_TEXT,
                CHANNEL_INTERFACE + ".TargetHandleType":
                CONNECTION_HANDLE_TYPE_ROOM,
                CHANNEL_INTERFACE + ".TargetID": muc_id
            }
            chan_path, props = conn_iface.CreateChannel(params)

            self.channel_text = Channel(self.conn.dbus_proxy.bus_name,
                                        chan_path)

        room_iface = self.channel_text[CHANNEL_INTERFACE_GROUP]
        self.self_handle = room_iface.GetSelfHandle()
        room_iface.connect_to_signal("MembersChanged",
                                     self.text_channel_members_changed_cb)

        if self.self_handle in room_iface.GetMembers():
            self.joined = True
            self.muc_joined()
    def new_channels_cb(self, channels):
        if self.tube is not None:
            return

        for path, props in channels:
            if props[CHANNEL_INTERFACE + ".ChannelType"] == CHANNEL_TYPE_STREAM_TUBE:
                self.tube = Channel(self.conn.dbus_proxy.bus_name, path)

                self.tube[CHANNEL_INTERFACE_TUBE].connect_to_signal(
                        "TubeChannelStateChanged", self.tube_channel_state_changed_cb)
                self.tube[CHANNEL_INTERFACE].connect_to_signal(
                        "Closed", self.tube_closed_cb)
                self.tube[CHANNEL_TYPE_STREAM_TUBE].connect_to_signal(
                       "NewRemoteConnection",
                       self.stream_tube_new_remote_connection_cb)
                self.tube[CHANNEL_TYPE_STREAM_TUBE].connect_to_signal(
                       "NewLocalConnection",
                       self.stream_tube_new_local_connection_cb)
                self.tube[CHANNEL_TYPE_STREAM_TUBE].connect_to_signal(
                       "ConnectionClosed",
                       self.stream_tube_connection_closed_cb)

                self.got_tube(props)
 def __create_text_channel_cb(self, channel_path):
     Channel(self._connection.requested_bus_name, channel_path,
             ready_handler=self.__text_channel_ready_cb)
예제 #15
0
    def __get_self_handle_cb(self, self_handle):
        self._self_handle = self_handle

        if CONNECTION_INTERFACE_CONTACT_CAPABILITIES in self._connection:
            interface = CONNECTION_INTERFACE_CONTACT_CAPABILITIES
            connection = self._connection[interface]
            client_name = CLIENT + '.Sugar.FileTransfer'
            file_transfer_channel_class = {
                CHANNEL + '.ChannelType': CHANNEL_TYPE_FILE_TRANSFER,
                CHANNEL + '.TargetHandleType': HANDLE_TYPE_CONTACT
            }
            capabilities = []
            connection.UpdateCapabilities(
                [(client_name, [file_transfer_channel_class], capabilities)],
                reply_handler=self.__update_capabilities_cb,
                error_handler=partial(self.__error_handler_cb,
                                      'Connection.UpdateCapabilities'))

        connection = self._connection[CONNECTION_INTERFACE_ALIASING]
        connection.connect_to_signal('AliasesChanged',
                                     self.__aliases_changed_cb)

        connection = self._connection[CONNECTION_INTERFACE_SIMPLE_PRESENCE]
        connection.connect_to_signal('PresencesChanged',
                                     self.__presences_changed_cb)

        if CONNECTION_INTERFACE_BUDDY_INFO in self._connection:
            connection = self._connection[CONNECTION_INTERFACE_BUDDY_INFO]
            connection.connect_to_signal('PropertiesChanged',
                                         self.__buddy_info_updated_cb,
                                         byte_arrays=True)

            connection.connect_to_signal('ActivitiesChanged',
                                         self.__buddy_activities_changed_cb)

            connection.connect_to_signal('CurrentActivityChanged',
                                         self.__current_activity_changed_cb)
            home_model = shell.get_model()
            home_model.connect('active-activity-changed',
                               self.__active_activity_changed_cb)
        else:
            logging.warning(
                'Connection %s does not support OLPC buddy '
                'properties', self._connection.object_path)

        if CONNECTION_INTERFACE_ACTIVITY_PROPERTIES in self._connection:
            connection = self._connection[
                CONNECTION_INTERFACE_ACTIVITY_PROPERTIES]
            connection.connect_to_signal('ActivityPropertiesChanged',
                                         self.__activity_properties_changed_cb)
        else:
            logging.warning(
                'Connection %s does not support OLPC activity '
                'properties', self._connection.object_path)

        properties = {
            CHANNEL + '.ChannelType': CHANNEL_TYPE_CONTACT_LIST,
            CHANNEL + '.TargetHandleType': HANDLE_TYPE_LIST,
            CHANNEL + '.TargetID': 'subscribe',
        }
        properties = dbus.Dictionary(properties, signature='sv')
        connection = self._connection[CONNECTION_INTERFACE_REQUESTS]
        is_ours, channel_path, properties = \
                connection.EnsureChannel(properties)

        channel = Channel(self._connection.service_name, channel_path)
        channel[CHANNEL_INTERFACE_GROUP].connect_to_signal(
            'MembersChanged', self.__members_changed_cb)

        channel[PROPERTIES_IFACE].Get(
            CHANNEL_INTERFACE_GROUP,
            'Members',
            reply_handler=self.__get_members_ready_cb,
            error_handler=partial(self.__error_handler_cb,
                                  'Connection.GetMembers'))