File: contact-list.py

package info (click to toggle)
telepathy-glib 0.24.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 31,756 kB
  • sloc: ansic: 124,638; xml: 34,410; sh: 4,531; python: 3,528; makefile: 1,722; javascript: 211; cpp: 16
file content (38 lines) | stat: -rwxr-xr-x 1,425 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python

import os
import gi
from gi.repository import GObject
GObject.threads_init()

gi.require_version('TelepathyGLib', '0.12')
from gi.repository import TelepathyGLib as Tp

def manager_prepared_cb(manager, result, loop):
    manager.prepare_finish(result)

    for account in manager.get_valid_accounts():
        connection = account.get_connection()

        # Verify account is online and received its contact list. If state is not
        # SUCCESS this means we didn't received the roster from server yet and
        # we would have to wait for the "notify:contact-list-state" signal. */
        if connection is not None and \
           connection.get_contact_list_state() == Tp.ContactListState.SUCCESS:
            contacts = connection.dup_contact_list()
            for contact in contacts:
                print("%s (%s)" % (contact.get_identifier(), contact.get_contact_groups()))
    loop.quit()

if __name__ == '__main__':
    Tp.debug_set_flags(os.getenv('EXAMPLE_DEBUG', ''))

    loop = GObject.MainLoop()
    manager = Tp.AccountManager.dup()
    factory = manager.get_factory()
    factory.add_account_features([Tp.Account.get_feature_quark_connection()])
    factory.add_connection_features([Tp.Connection.get_feature_quark_contact_list()])
    factory.add_contact_features([Tp.ContactFeature.CONTACT_GROUPS])

    manager.prepare_async(None, manager_prepared_cb, loop)
    loop.run()