maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   libabook Contact from number (https://talk.maemo.org/showthread.php?t=44929)

tgalal 2010-02-18 02:03

libabook Contact from number
 
So I've been struggling for 3 days now trying to do only one thing! Given a phone number, I want to fetch the contact name associated with that number! 3 days switching back and forth between osso abook and ebook libraries. Not to mention that I'm developing in python and have to use ctypes as there are no bindings yet.

However, forget about python, can someone just point me out to the correct steps get a contact from his/her number? Thanks a lot

lizardo 2010-02-19 17:56

Re: libabook Contact from number
 
Quote:

Originally Posted by tgalal (Post 533471)
So I've been struggling for 3 days now trying to do only one thing! Given a phone number, I want to fetch the contact name associated with that number! 3 days switching back and forth between osso abook and ebook libraries. Not to mention that I'm developing in python and have to use ctypes as there are no bindings yet.

However, forget about python, can someone just point me out to the correct steps get a contact from his/her number? Thanks a lot

I did not try, but take a look at these functions:

http://maemo.org/api_refs/5.0/5.0-fi...r-phone-number

http://maemo.org/api_refs/5.0/5.0-fi...y-phone-number

Hope that helps.

lizardo 2010-04-12 00:11

Re: libabook Contact from number
 
I recently added this new wiki page:

http://wiki.maemo.org/PyMaemo/Access.../More_examples

It contains sample source code (using ctypes) to do what you want.

Hope that helps.

tgalal 2010-04-12 10:43

Re: libabook Contact from number
 
Quote:

Originally Posted by lizardo (Post 606142)
I recently added this new wiki page:

http://wiki.maemo.org/PyMaemo/Access.../More_examples

It contains sample source code (using ctypes) to do what you want.

Hope that helps.

Thanks a lot! I'm your sure your wiki article would be helpful for a lot of people too :)

barisione 2010-04-12 10:55

Re: libabook Contact from number
 
The example uses directly libebook, you should not do that.
You have to get the default aggregator (osso_abook_aggregator_get_default), wait for it until it's ready (osso_abook_waitable_call_when_ready) and then search for the matching contacts (osso_abook_aggregator_find_contacts_for_phone_num ber).

tgalal 2010-04-12 10:58

Re: libabook Contact from number
 
Quote:

Originally Posted by barisione (Post 606729)
The example uses directly libebook, you should not do that.
You have to get the default aggregator (osso_abook_aggregator_get_default), wait for it until it's ready (osso_abook_waitable_call_when_ready) and then search for the matching contacts (osso_abook_aggregator_find_contacts_for_phone_num ber).

Could you post an example that does that ?

lizardo 2010-04-12 11:07

Re: libabook Contact from number
 
Quote:

Originally Posted by barisione (Post 606729)
The example uses directly libebook, you should not do that.
You have to get the default aggregator (osso_abook_aggregator_get_default), wait for it until it's ready (osso_abook_waitable_call_when_ready) and then search for the matching contacts (osso_abook_aggregator_find_contacts_for_phone_num ber).

While I know it is not the recommended way, the example is still useful for simple cases... you lack some additional information or even contacts, but for some use cases that's enough.

I'll see if I can add another example using the recommended API, but if you can provide one (even in C) that will be great! :D

barisione 2010-04-12 11:19

Re: libabook Contact from number
 
Something like this should work (in C):

Code:

#include <libosso-abook/osso-abook.h>

static gchar *phone_number = NULL;

static void
aggregator_ready_cb (OssoABookWaitable *aggregator,
                    const GError      *error,
                    gpointer          user_data)
{
    GList *contacts;
    GList *l;
    OssoABookContact *contact;

    contacts = osso_abook_aggregator_find_contacts_for_phone_number (
            OSSO_ABOOK_AGGREGATOR (aggregator), phone_number, TRUE);


    if (contacts) {
        g_print ("Contacts with phone number %s:\n", phone_number);
        for (l = contacts; l; l = l->next) {
            contact = l->data;
            g_print ("    %s\n",
                    osso_abook_contact_get_display_name (contact));
        }
    }
    else {
        g_print ("No contacts found with phone number %s.\n",
                phone_number);
    }

    g_list_free (contacts);

    gtk_main_quit ();
}

int
main (int argc, char **argv)
{
    osso_context_t *osso_cxt;

    osso_cxt = osso_initialize (argv[0], "0.1", FALSE, NULL);
    osso_abook_init (&argc, &argv, osso_cxt);

    if (argc > 1)
        phone_number = argv[1];
    else
        phone_number = "1234567";

    osso_abook_waitable_call_when_ready (
            OSSO_ABOOK_WAITABLE (osso_abook_aggregator_get_default (NULL)),
            aggregator_ready_cb, NULL, NULL);

    gtk_main ();

    return 0;
}


twaelti 2010-04-12 12:33

Re: libabook Contact from number
 
A quick tip to find a library.

lizardo 2010-04-12 14:22

Re: libabook Contact from number
 
Quote:

Originally Posted by barisione (Post 606757)
Something like this should work (in C):
...

I updated the wiki pages based on your example code. Thanks!

JohnLF 2010-04-12 14:29

Re: libabook Contact from number
 
Can someone make a working app from this? Even if it is command line, that's fine for me.

Can someone also clarify if it requires whole numbers or if it will list partial matches?


All times are GMT. The time now is 05:22.

vBulletin® Version 3.8.8