#!/usr/bin/env python import gobject gobject.threads_init() from gi.repository import TelepathyGLib def handle_channels_cb(handler, account, connection, channels, requests, user_action_time, context, user_data): for channel in channels: if not isinstance(channel, TelepathyGLib.TextChannel): continue print "Yes, we got a TpTextChannel subclass!" context.accept() def manager_prepared_cb(manager, result, loop): manager.prepare_full_finish(result) accounts = manager.get_valid_accounts() for account in accounts: connection = account.get_connection() if connection != None: contacts = connection.get_contact_list() for contact in contacts: print "%s (%s)" % (contact.get_identifier(), contact.get_contact_groups()) loop.quit() if __name__ == '__main__': #TelepathyGLib.debug_set_flags("all") loop = gobject.MainLoop() factory = TelepathyGLib.AutomaticFactory.new() factory.add_account_manager_features([TelepathyGLib.AccountManager.get_feature_quark_account()]) factory.add_account_features([TelepathyGLib.Account.get_feature_quark_connection()]) factory.add_connection_features([TelepathyGLib.Connection.get_feature_quark_contact_list()]) factory.add_contact_features([TelepathyGLib.ContactFeature.CONTACT_GROUPS]) # no args needed to get an AM, internally factory would do a # factory.dup_dbus_daemon() though, or should we do it outself and pass it # to dup_account_manager() ? manager = factory.dup_account_manager() features = factory.dup_account_manager_features() manager.prepare_async(features, manager_prepared_cb, loop) # Internally, when a channel arrives, SimpleHandler does # # factory = dbus.get_factory() # if factory != None: # connection = factory.dup_connection(connectionPath) # channel = factory.dup_channel(connection, channelPath) # else: # fallback doing as it does atm # # so the connection object will be shared with those we prepared above! dbus = factory.dup_dbus_daemon() handler = TelepathyGLib.SimpleHandler.new(dbus, False, False, 'ExampleHandler', False, handle_channels_cb, None) handler.add_handler_filter({ TelepathyGLib.PROP_CHANNEL_CHANNEL_TYPE: TelepathyGLib.IFACE_CHANNEL_TYPE_TEXT, # bgo #637466 TelepathyGLib.PROP_CHANNEL_TARGET_HANDLE_TYPE: int(TelepathyGLib.HandleType.CONTACT), TelepathyGLib.PROP_CHANNEL_REQUESTED: False, }) handler.register() loop.run()