PyMaemo/Accessing APIs without Python bindings/More examples

(New page: = 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 c...)
(Searching contacts by phone number)
Line 5: Line 5:
== Searching contacts by phone number ==
== Searching contacts by phone number ==
-
TODO
+
Searching contacts by phone number can be done using the [http://maemo.org/api_refs/5.0/5.0-final/libosso-abook/libosso-abook-osso-abook-util.html#osso-abook-query-phone-number osso_abook_query_phone_number()] and [http://maemo.org/api_refs/5.0/5.0-final/libebook/EBook.html#e-book-get-contacts 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)
 +
c_query = osso_abook.osso_abook_query_phone_number("12345678", 0)
 +
 +
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)

Revision as of 17:56, 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)
c_query = osso_abook.osso_abook_query_phone_number("12345678", 0)

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)