1 Title: Querying N900 address book
2 Tags: en, python, maemo, n900, osso, addressbook, libebook, evolution, mobile, hacking, c, binding
4 Since there is not a lot of information on how to hack Maemo's address book
5 to find some contacts with a mobile phone number, I'll share my findings.
7 Since setting up an environment to cross-compile for ARM is a big hassle,
8 I decided to write this small test program in Python, (ab)using the wonderful
9 ctypes module to avoid compiling at all.
11 Here is a very small script to use the (sadly proprietary) OSSO Addressbook
14 # This function get all the names in the address book with mobile phone numbers
15 # and print them. The code is Python but is as similar as C as possible.
16 def get_all_mobiles():
18 osso_ctx = osso_initialize("test_abook", "0.1", FALSE)
19 osso_abook_init(argc, argv, hash(osso_ctx))
21 roster = osso_abook_aggregator_get_default(NULL)
22 osso_abook_waitable_run(roster, g_main_context_default(), NULL)
23 contacts = osso_abook_aggregator_list_master_contacts(roster)
25 for contact in glist(contacts):
26 name = osso_abook_contact_get_display_name(contact)
27 # Somehow hackish way to get the EVC_TEL attributes
28 field = e_contact_field_id("mobile-phone")
29 attrs = e_contact_get_attributes(contact, field)
31 for attr in glist(attrs):
32 types = e_vcard_attribute_get_param(attr, "TYPE")
33 for t in glist(types):
34 type = ctypes.c_char_p(t).value
35 # Remove this condition to get all phone numbers
36 # (not just mobile phones)
38 mobiles.append(e_vcard_attribute_get_value(attr))
47 # be sure to import gtk before calling osso_abook_init()
51 osso_initialize = osso.Context
53 # Dynamic libraries bindings
54 glib = ctypes.CDLL('libglib-2.0.so.0')
55 g_main_context_default = glib.g_main_context_default
57 class _GList(ctypes.Structure):
58 _fields_ = [('data', ctypes.c_void_p),
59 ('next', ctypes.c_void_p)]
62 l = _GList.from_address(l)
66 osso_abook = ctypes.CDLL('libosso-abook-1.0.so.0')
67 osso_abook_init = osso_abook.osso_abook_init
68 osso_abook_aggregator_get_default = osso_abook.osso_abook_aggregator_get_default
69 osso_abook_waitable_run = osso_abook.osso_abook_waitable_run
70 osso_abook_aggregator_list_master_contacts = osso_abook.osso_abook_aggregator_list_master_contacts
71 osso_abook_contact_get_display_name = osso_abook.osso_abook_contact_get_display_name
72 osso_abook_contact_get_display_name.restype = ctypes.c_char_p
74 ebook = ctypes.CDLL('libebook-1.2.so.5')
75 e_contact_field_id = ebook.e_contact_field_id
76 e_contact_get_attributes = ebook.e_contact_get_attributes
77 e_vcard_attribute_get_value = ebook.e_vcard_attribute_get_value
78 e_vcard_attribute_get_value.restype = ctypes.c_char_p
79 e_vcard_attribute_get_param = ebook.e_vcard_attribute_get_param
82 argv_type = ctypes.c_char_p * len(sys.argv)
83 argv = ctypes.byref(argv_type(*sys.argv))
84 argc = ctypes.byref(ctypes.c_int(len(sys.argv)))
94 Here are some useful links I used as reference:
96 * http://wiki.maemo.org/PyMaemo/Accessing_APIs_without_Python_bindings
97 * http://wiki.maemo.org/Documentation/Maemo_5_Developer_Guide/Using_Generic_Platform_Components/Using_Address_Book_API
98 * http://maemo.org/api_refs/5.0/5.0-final/libebook/
99 * http://maemo.org/api_refs/5.0/5.0-final/libosso-abook/
100 * https://garage.maemo.org/plugins/scmsvn/viewcvs.php/releases/evolution-data-server/1.4.2.1-20091104/addressbook/libebook-dbus/?root=eds
101 * http://www.developer.nokia.com/Community/Discussion/showthread.php?200914-How-to-print-all-contact-names-in-N900-addressbook-Please-Help
104 .. vim: set et sw=3 sts=3 :