PyMaemo/Accessing APIs without Python bindings/More examples: Difference between revisions

From Maemo Wiki
Jump to navigationJump to search
imported>lizardo
No edit summary
imported>lizardo
Line 14: Line 14:
     print >>sys.stderr, "Couldn't load addressbook."
     print >>sys.stderr, "Couldn't load addressbook."
     sys.exit(1)
     sys.exit(1)
  c_query = osso_abook.osso_abook_query_phone_number("12345678", 0)
# fuzzy search enabled to allow partial matches (refer to documentation)
  c_query = osso_abook.osso_abook_query_phone_number("12345678", 1)
   
   
  contacts = ctypes.c_void_p()
  contacts = ctypes.c_void_p()

Revision as of 18:07, 10 April 2010

More examples

This page contains some other example code using ctypes. Note that they are not complete, and assume some code already shown on the [[../|main article]].

Searching contacts by phone number

Searching contacts by phone number can be done using the osso_abook_query_phone_number() and e_book_get_contacts() functions:

ebook = ctypes.CDLL('libebook-1.2.so.5')

err = ctypes.c_void_p()
c_book = ebook.e_book_new_default_addressbook(ctypes.byref(err)) 
if not ebook.e_book_open(c_book, 1, 0):
    print >>sys.stderr, "Couldn't load addressbook."
    sys.exit(1)
# fuzzy search enabled to allow partial matches (refer to documentation)
c_query = osso_abook.osso_abook_query_phone_number("12345678", 1)

contacts = ctypes.c_void_p()
if not ebook.e_book_get_contacts(c_book, c_query, ctypes.byref(contacts), err):
    print >>sys.stderr, "Couldn't get query results."
    sys.exit(1)

The "contacts" is a GList which can be iterated over as explained [[../#Accessing Items in a GList|here]].