def _get_buddy(self, cs_handle): '''Get a Buddy from a (possibly channel-specific) handle.''' # XXX This will be made redundant once Presence Service # provides buddy resolution # Get the Presence Service pservice = presenceservice.get_instance() # Get the Telepathy Connection tp_name, tp_path = pservice.get_preferred_connection() conn = Connection(tp_name, tp_path) group = self._text_chan[CHANNEL_INTERFACE_GROUP] my_csh = group.GetSelfHandle() if my_csh == cs_handle: handle = conn.GetSelfHandle() elif (group.GetGroupFlags() & CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES): handle = group.GetHandleOwners([cs_handle])[0] else: handle = cs_handle # XXX: deal with failure to get the handle owner assert handle != 0 return pservice.get_buddy_by_telepathy_handle(tp_name, tp_path, handle)
def __init__(self): BaseBuddyModel.__init__(self) self.props.nick = "rgs" self.props.color = XoColor(None) # self.props.key = get_profile().pubkey self.props.key = "foobar" self.connect('notify::nick', self.__property_changed_cb) self.connect('notify::color', self.__property_changed_cb) self.connect('notify::current-activity', self.__current_activity_changed_cb) bus = dbus.SessionBus() bus.add_signal_receiver(self.__name_owner_changed_cb, signal_name='NameOwnerChanged', dbus_interface='org.freedesktop.DBus') bus_object = bus.get_object(dbus.BUS_DAEMON_NAME, dbus.BUS_DAEMON_PATH) for service in bus_object.ListNames( dbus_interface=dbus.BUS_DAEMON_IFACE): if service.startswith(CONNECTION + '.'): path = '/%s' % service.replace('.', '/') Connection(service, path, bus, ready_handler=self.__connection_ready_cb)
def findConnections(): cons = Connection.get_connections() for con in cons: watch_connection(con) status = statuses[con[CONNECTION].GetStatus()] print("Connection: %s with status %s" % (con.service_name, status))
def __init__(self): BaseBuddyModel.__init__(self) client = gconf.client_get_default() self.props.nick = client.get_string('/desktop/sugar/user/nick') color = client.get_string('/desktop/sugar/user/color') self.props.color = XoColor(color) self.props.key = get_profile().pubkey self.connect('notify::nick', self.__property_changed_cb) self.connect('notify::color', self.__property_changed_cb) bus = dbus.SessionBus() bus.add_signal_receiver( self.__name_owner_changed_cb, signal_name='NameOwnerChanged', dbus_interface='org.freedesktop.DBus') bus_object = bus.get_object(dbus.BUS_DAEMON_NAME, dbus.BUS_DAEMON_PATH) for service in bus_object.ListNames( dbus_interface=dbus.BUS_DAEMON_IFACE): if service.startswith(CONNECTION + '.'): path = '/%s' % service.replace('.', '/') Connection(service, path, bus, ready_handler=self.__connection_ready_cb)
def _add_connection(self, service_name, path): if path in self._connections: return try: Connection(service_name, path, ready_handler=self._conn_ready_cb) except dbus.exceptions.DBusException: logging.debug('%s is propably already gone.', service_name)
def _one_to_one_connection(self, tp_channel): '''Handle a private invite from a non-sugar3 XMPP client.''' if self.shared_activity or self.text_channel: return bus_name, connection, channel = json.loads(tp_channel) logger.debug('GOT XMPP: %s %s %s', bus_name, connection, channel) Connection(bus_name, connection, ready_handler=lambda conn: self._one_to_one_connection_ready_cb( bus_name, channel, conn))
def _one_to_one_connection(self, tp_channel): """Handle a private invite from a non-Sugar XMPP client.""" if self.shared_activity or self.text_channel: return bus_name, connection, channel = cjson.decode(tp_channel) logger.debug('GOT XMPP: %s %s %s', bus_name, connection, channel) Connection( bus_name, connection, ready_handler=lambda conn: \ self._one_to_one_connection_ready_cb(bus_name, channel, conn))
def _name_owner_changed_cb(self, service, old, new): if service.startswith(conn_prefix): name = service[len(conn_prefix):] if old == '': conn = Connection(service) self._watch_conn(conn) status = connection_status[conn[CONN_INTERFACE].GetStatus()] print 'new connection: %s (%s)' % (name, status) elif new == '': print 'connection gone: %s' % name
def __init__(self, bus): self.bus = bus connections = Connection.get_connections() for conn in connections: self._watch_conn(conn) status = connection_status[conn[CONN_INTERFACE].GetStatus()] print 'found connection: %s (%s)' % (conn.service_name, status) dbus = bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus') dbus.connect_to_signal('NameOwnerChanged', self._name_owner_changed_cb)
def __init__(self, bus): self.bus = bus connections = Connection.get_connections() for conn in connections: self._watch_conn(conn) status = connection_status[conn[CONN_INTERFACE].GetStatus()] print "found connection: %s (%s)" % (conn.service_name, status) dbus = bus.get_object("org.freedesktop.DBus", "/org/freedesktop/DBus") dbus.connect_to_signal("NameOwnerChanged", self._name_owner_changed_cb)
def __init__(self): self.loop = gobject.MainLoop() self.con_monitors = con_monitors = set() for con in Connection.get_connections(): con_monitors.add(ConnectionMonitor(con)) bus = dbus.Bus() dbus_object = bus.get_object("org.freedesktop.DBus", "/org/freedesktop/DBus") dbus_object.connect_to_signal("NameOwnerChanged", self.change_owner_handler)
def __init__(self, bus=None): gobject.GObject.__init__(self) if bus is None: self.bus = dbus.Bus() else: self.bus = bus # D-Bus path -> Connection self._connections = {} self.bus.add_signal_receiver(self._status_changed_cb, dbus_interface=CONN_INTERFACE, signal_name='StatusChanged', path_keyword='path') for conn in Connection.get_connections(bus): conn.call_when_ready(self._conn_ready_cb)
def __init__(self, bus=None): GObject.GObject.__init__(self) if bus is None: self.bus = dbus.Bus() else: self.bus = bus # D-Bus path -> Connection self._connections = {} self.bus.add_signal_receiver(self._status_changed_cb, dbus_interface=CONN_INTERFACE, signal_name='StatusChanged', path_keyword='path') for conn in Connection.get_connections(bus): conn.call_when_ready(self._conn_ready_cb)
def _find_existing_connection(self): """Try to find an existing Telepathy connection to this server filters the set of connections from telepathy.client.Connection.get_connections to find a connection using our protocol with the "self handle" of that connection being a handle which matches our account (see _get_account_info) returns connection or None """ # Search existing connections, if any, that we might be able to use connections = Connection.get_connections() for item in connections: if not item.object_path.startswith(self._OBJ_PATH_PREFIX): continue if item[CONN_INTERFACE].GetProtocol() != self._PROTOCOL: continue # Any Salut instance will do return item return None
def __init__(self, buddy, file_name, title, description, mime_type): presence_service = presenceservice.get_instance() name, path = presence_service.get_preferred_connection() connection = Connection(name, path, ready_handler=self.__connection_ready_cb) BaseFileTransfer.__init__(self, connection) self.connect('notify::state', self.__notify_state_cb) self._file_name = file_name self._socket_address = None self._socket = None self._splicer = None self._output_stream = None self.buddy = buddy self.title = title self.file_size = os.stat(file_name).st_size self.description = description self.mime_type = mime_type
def __name_owner_changed_cb(self, name, old, new): if name.startswith(CONNECTION + '.') and not old and new: path = '/' + name.replace('.', '/') Connection(name, path, ready_handler=self.__connection_ready_cb)
class Account(InterfaceFactory): def __init__(self, object_path, bus=None): if not bus: bus = dbus.Bus() service_name = 'org.freedesktop.Telepathy.AccountManager' #service_name = object_path.replace('/', '.')[1:] object = bus.get_object(service_name, object_path) InterfaceFactory.__init__(self, object, ACCOUNT) # FIXME: make this async self.get_valid_interfaces().update(self[DBUS_PROPERTIES].Get(ACCOUNT, 'Interfaces')) if __name__ == '__main__': from accountmgr import AccountManager from telepathy.client import Connection import gobject import dbus.glib # sets up a main loop (!!!); somewhat deprecated am = AccountManager() def show_conn(conn): print repr(conn) for acct_path in am[DBUS_PROPERTIES].Get(ACCOUNT_MANAGER, 'ValidAccounts'): acct = Account(acct_path) conn = acct[DBUS_PROPERTIES].Get(ACCOUNT, 'Connection') print conn conn = Connection(conn.replace('/', '.')[1:], conn) conn.call_when_ready(show_conn) gobject.MainLoop().run()
def _prepare_connection(self, connection_path): connection_name = connection_path.replace('/', '.')[1:] self._connection = Connection(connection_name, connection_path, ready_handler=self.__connection_ready_cb)
return CHANNEL_TYPE_TEXT def GetHandle(self): return (1, 1) def GetInterfaces(self): return [CHANNEL, CHANNEL_TYPE_TEXT, CHANNEL_INTERFACE_MESSAGES] def publish_channel(name): bus_name = '.'.join([CHANNEL, name]) object_path = '/' + bus_name.replace('.', '/') bus_name = dbus.service.BusName(bus_name, bus=dbus.SessionBus()) global channel channel = FakeChannel(bus_name, object_path) return False if __name__ == "__main__": loop = gobject.MainLoop() con = Connection.get_connections()[0] con.create_channel gobject.timeout_add(0, publish_channel, "MyFakeChannel") try: loop.run() except KeyboardInterrupt: loop.quit()