×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    6

    Question How to print all contact names in N900 addressbook - Please Help

    I have been trying to access the contacts in the N900 using Qt mobility and osso-addressbook for a long time now with no luck. All I want to do is to print out the names of all the contacts in the addressbook as a list on the console but am not able to do so. I do not mind whether I use Qt Mobility or the standard libebook or libosso-abook methods. Please help.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    6

    Re: How to print all contact names in N900 addressbook - Please Help

    I know this is a Qt forum but I was at a loss as to where else to ask. Also since the code is being implemented as part of a Qt program (I cant get Qt Mobility to work) I thought I would ask my question here.

    Could someone please tell me why the following code wont work on a N900? It simply quits without ever entering the for loop to print out the contacts.

    #include <libosso-abook/osso-abook.h>
    #include <libebook/e-book.h>
    #include <QDebug>

    int main(int argc, char** argv)
    {
    GList *contacts2, *c;
    GtkWidget *view;
    osso_context_t *osso_cxt; //libosso initialization
    OssoABookContactModel *default_model;

    osso_cxt = osso_initialize (argv[0], "1.0", FALSE, NULL); //libossoinit
    osso_abook_init (&argc, &argv, osso_cxt); //pass ossocontext
    default_model = osso_abook_contact_model_get_default ();

    view = osso_abook_contact_view_new_basic (HILDON_UI_MODE_NORMAL, default_model);
    contacts2 = osso_abook_contact_view_get_selection (OSSO_ABOOK_CONTACT_VIEW (view));


    //now print out the contacts in contacts2 using a for loop

    int count;
    count = 1;
    qDebug() << "ok so far..";
    for (c = contacts2; c; c = c->next) {
    qDebug() << "entered loop..";
    EContact *contact = E_CONTACT (c->data);
    EVCard *vcard = E_VCARD (contact);
    char *v;
    v = e_vcard_to_string (vcard, EVC_FORMAT_VCARD_30);
    g_print ("Card %d\n", count);
    g_print ("%s", v);
    g_print ("-------\n");
    g_free (v);
    count++;
    }

    return 0;
    }


    Any help would be highly appreciated. Been trying to work this out for over a week now.

    Thanks!
    Last edited by sarsh1910; 2010-05-17 at 01:25. Reason: Corrrection in code + additional information

  3. #3
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to print all contact names in N900 addressbook - Please Help

    The reason it doesn't work is because you are trying to print selected contacts from view widget. However, you do not show your widget anywhere and thus do not give yourself a chance to select anything. If your goal is to print all contacts, you don't need view and its selection.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    6

    Re: How to print all contact names in N900 addressbook - Please Help

    thanks for the reply Danill.

    yes i'm simply trying to print out all contact names.

    could you please tell me how i could do this without using view and its selection like you mentioned?

    thanks in advance.
    Sarshad

  5. #5
    Super Contributor
    Join Date
    Mar 2009
    Posts
    1,024

    Re: How to print all contact names in N900 addressbook - Please Help

    Hi,
    You should:
    1) get the list of the master contacts:
    GList *contacts = osso_abook_aggregator_list_master_contacts(m_abookAgregator);

    2) Then you can get the display labels from any contact:
    acontact = (OssoABookContact*)contacts->data;
    const char* displayName = osso_abook_contact_get_display_name(acontact);

    Note:
    The contact display name is created in Maemo5 in according to some "internal" rules...
    Internal since user should not be able to change those...

    However the contact display name is created using First and Last name. If those are missing
    then email is used. If contacts doesn't have any email address then the account name (eg: Skype, GTalk and so on)
    associated to the contact is used.

    If you don't want to get the Display name but just a contact attribute like First/Last name, email...
    then instead of casting contacts->data to (OssoABookContact*) you have to cast it to EContact:
    econtact = E_CONTACT(contacts->data)
    so that you can use the EBook API to retrieve values and parameters from the contact attributes.

  6. #6
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to print all contact names in N900 addressbook - Please Help

    You can use this example to achieve the same with Qt Mobility (note that QContactManager::contacts is deprecated method)
    http://wiki.forum.nokia.com/index.ph...t_Mobility_API
    However, I faced the problem that Qt Mobility from extras-devel:
    http://repository.maemo.org/extras-d...q/qt-mobility/
    Conflicts with the latest Qt from Fremantle repository.

  7. #7
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to print all contact names in N900 addressbook - Please Help

    Quote Originally Posted by divanov View Post
    You can use this example to achieve the same with Qt Mobility (note that QContactManager::contacts is deprecated method)
    http://wiki.forum.nokia.com/index.ph...t_Mobility_API
    However, I faced the problem that Qt Mobility from extras-devel:
    http://repository.maemo.org/extras-d...q/qt-mobility/
    Conflicts with the latest Qt from Fremantle repository.
    The latter was fixed. However 1.0.0-beta1-maemo6 doesn't contain contacts backend.
    Last edited by divanov; 2010-05-17 at 15:22.

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    6

    Re: How to print all contact names in N900 addressbook - Please Help

    Thanks a lot Danil and Gnuton for you help.

    Will try the Qt Mobility API but would like to get this working first. This is what my code looks like now after following Gnutons's guidelines:


    int main(int argc, char** argv)
    {
    OssoABookAggregator *m_abookAggregator;
    OssoABookRoster *roster;
    OssoABookContact *acontact;
    GList *contacts2, *c;
    GError *error;
    osso_context_t *osso_cxt; //libosso initialization
    osso_cxt = osso_initialize (argv[0], "1.0", FALSE, NULL); //libossoinit
    osso_abook_init (&argc, &argv, osso_cxt); //pass ossocontext

    roster = osso_abook_aggregator_get_default(&error);
    m_abookAggregator = OSSO_ABOOK_AGGREGATOR(roster);
    contacts2 = osso_abook_aggregator_list_master_contacts(m_abookAggregator);

    printf("count = %d\n", g_list_length(contacts2));
    for (c = contacts2; c; c = c->next) {
    acontact = (OssoABookContact*)c->data;
    const char* displayName = osso_abook_contact_get_display_name(acontact);
    printf("Display Name: %s", displayName);
    }
    return 0;
    }


    The problem is that it is only returning one contact.... and that is the Telus Voicemail number it grabbed automatically from my SIM (The sim had no other contacts on it).

    It is not returning the contents of either the phone memory or the "availability" (skype, gmail etc.) contacts. I'd like to mention that what i'm primarily interested is is the phone memory... ie in accessing the contacts i store manually on the phone. Isn't the osso_abook_aggregator_get_default supposed to return that?

    any suggestions on how to correct this???

    thanks again,
    sarshad

  9. #9
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to print all contact names in N900 addressbook - Please Help

    You have to wait before aggregator is ready.

    Code:
    /* gcc -Wall --std=gnu99 contacts.c -o contacts $(pkg-config --cflags --libs libosso-abook-1.0) */
    #include <libosso-abook/osso-abook.h>
    
    void listContacts(OssoABookAggregator *aggregator)
    {
        for (GList *contacts = osso_abook_aggregator_list_master_contacts(aggregator);
             contacts;
             contacts = g_list_delete_link(contacts, contacts)) {
            OssoABookContact *contact = OSSO_ABOOK_CONTACT(contacts->data);
            const char* displayName = osso_abook_contact_get_display_name(contact);
            printf("Display Name: %s\n", displayName);
        }
    }
    
    int main(int argc, char** argv)
    {
        osso_context_t *osso_cxt = osso_initialize (argv[0], "1.0", FALSE, NULL);
        osso_abook_init (&argc, &argv, osso_cxt);
    
        GError *error = NULL;
        OssoABookRoster *roster = osso_abook_aggregator_get_default (&error);
        if (error) {
            printf("error %s\n", error->message);
            g_error_free(error);
        }
        OssoABookAggregator *aggregator = OSSO_ABOOK_AGGREGATOR(roster);
        osso_abook_waitable_run(OSSO_ABOOK_WAITABLE(aggregator),
                                g_main_context_default(), &error);
        if (error) {
            printf("error %s\n", error->message);
            g_error_free(error);
        }
        listContacts(aggregator);
    
        osso_deinitialize (osso_cxt);
    
        exit(0);
    }

  10. #10
    Registered User
    Join Date
    Jun 2003
    Posts
    11

    Re: How to print all contact names in N900 addressbook - Please Help

    Hi,

    there are code that i had modification on maemo-example if you want some simple UI. that code could add/delete contact also.

    Code:
    /**
     * This file is part of maemo-examples package
     *
     * Copyright (c) 2007 Nokia Corporation
     *
     * Permission is hereby granted, free of charge, to any person obtaining a copy
     * of this software and associated documentation files (the "Software"), to deal
     * in the Software without restriction, including without limitation the rights
     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     * copies of the Software, and to permit persons to whom the Software is
     * furnished to do so, subject to the following conditions:
     *
     * The above copyright notice and this permission notice shall be included in
     * all copies or substantial portions of the Software.
     *
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     * THE SOFTWARE. */
    
    
    #include <libosso.h>
    #include <libebook/e-book.h>
    #include <libosso-abook/osso-abook.h>
    #include <gtk/gtk.h>
    
    #include "example_common.h"
    
    /* Define structure for data that's passed around
     * the application */
    typedef struct
    {
            HildonProgram *program;
            HildonWindow *window;
    
            osso_context_t *osso_context;
    
            EBookView *book_view;
            OssoABookRoster *roster;
            OssoABookContactModel *contact_model;
            GtkWidget *contact_view;
    } AppData;
    
    /* Callback to be called when user activates (double clicks) a contact
     * in the contact view */
    static void contact_activated(OssoABookContactView *view, EContact *contact,
                    AppData *appdata)
    {
            GtkWidget *starter;
    
            /* Create new contact starter dialog */
            starter = osso_abook_touch_contact_starter_new_with_contact(GTK_WINDOW(appdata->window), contact);
    
            /* Run dialog and destroy it afterwards. The dialog works "independently", ie
             * no action or response value checking is needed by the client side code */
            gtk_dialog_run(GTK_DIALOG(starter));
    
            gtk_widget_destroy(GTK_WIDGET(starter));
    }
    
    /* Initialize the contact list connections and widgets */
    static void create_contact_list(AppData *appdata)
    {
            EBook *book;
            GError *error = NULL;
            EBookQuery *query;
    
            appdata->roster = osso_abook_aggregator_get_default (&error);
            if (error) {
                printf("error %s\n", error->message);
                g_error_free(error);
            }
            osso_abook_roster_start(appdata->roster);
    
            /* Request a handle to the system-wide addressbook
             * The book isn't opened yet. */
            book = e_book_new_system_addressbook(&error);
            if(!book)
            {
                    g_critical("Couldn't open addressbook: %s", error->message);
                    g_error_free(error);
                    return;
            }
    
            /* Open connection to the address book */
            if(!e_book_open(book, FALSE, &error))
            {
                    g_critical("Couldn't open addressbook: %s", error->message);
                    g_error_free(error);
                    return;
            }
    
            /* Create a query. This query matches any
             * records in the book. */
            query = e_book_query_any_field_contains("");
    
            /* Create new book view with the book and the query */
            if(!e_book_get_book_view(book, query, NULL, -1, &appdata->book_view, &error))
            {
                    g_critical("Couldn't create book view: %s", error->message);
                    g_error_free(error);
                    return;
            }
            e_book_query_unref(query);
    
            /* Start the EBookView, this runs the query and
             * starts to exchange signals with the EBook */
            e_book_view_start(appdata->book_view);
    
            /* Create a new data model for the abook contact widget */
            appdata->contact_model = osso_abook_contact_model_new();
            /* Set the model to use the book view as a data source */
            osso_abook_list_store_set_book_view(appdata->contact_model,
                            appdata->book_view);
    
            /* Create new basic contact view using the model */
            appdata->contact_view = osso_abook_contact_view_new_basic(HILDON_UI_MODE_NORMAL, appdata->contact_model);
            g_object_unref(appdata->contact_model);
    
            /* Connect contact-activated signal to a callback */
            g_signal_connect(G_OBJECT(appdata->contact_view), "contact-activated",
                            G_CALLBACK(contact_activated), appdata);
    
    }
    
    /* Callback to be called when user clicks the "Add Contact" button */
    static void add_contact(GtkWidget *button, AppData *appdata)
    {
            /* This is all that's needed to use the contact adding dialog,
             * the new users created will be shown automatically in the
             * contact_view widget */
            osso_abook_add_contact_dialog_run(GTK_WINDOW(appdata->window));
    }
    
    /* Callback to be called when user clicks the "Delete Contact" button */
    static void delete_contacts(GtkWidget *button, AppData *appdata)
    {
            GList *selection;
    
            /* Get selected items from the contact view */
            selection = osso_abook_contact_view_get_selection(
                            OSSO_ABOOK_CONTACT_VIEW(appdata->contact_view));
            /* Pass the selection to delete contacts dialog */
            osso_abook_delete_contacts_dialog_run(GTK_WINDOW(appdata->window),
                            appdata->roster, appdata->contact_model);
    
            g_list_free(selection);
    }
    
    #define APP_NAME "maemo-abook-example"
    
    int main(int argc, char **argv)
    {
            AppData appdata;
            GtkWidget *add_button;
            GtkWidget *delete_button;
            GtkWidget *contact_box;
            GtkWidget *button_box;
    
            /* Initialize the osso context */
            appdata.osso_context = osso_initialize(
                            APP_NAME, "1.0", TRUE, NULL);
            if(!appdata.osso_context)
            {
                    g_error("Couldn't initialize osso context");
                    return 1;
            }
    
            /* Initialize abook, which also initializes all the
             * libraries it needs (GTK+, Galago, Gnome-VFS) */
            osso_abook_init(&argc, &argv, appdata.osso_context);
    
            /* Create and initialize the HildonProgram and HildonWindow */
            example_gui_initialize(&appdata.program, &appdata.window,
                            &argc, &argv, APP_NAME);
    
            /* Create the contact list widget and rest of the GUI */
            create_contact_list(&appdata);
            add_button = gtk_button_new_with_label("Add contact");
            delete_button = gtk_button_new_with_label("Delete contact");
            contact_box = gtk_vbox_new(FALSE, 8);
            button_box = gtk_hbox_new(FALSE, 8);
            gtk_box_pack_start_defaults(GTK_BOX(contact_box),
                            GTK_WIDGET(appdata.contact_view));
            gtk_box_pack_start_defaults(GTK_BOX(button_box),
                            GTK_WIDGET(add_button));
            gtk_box_pack_start_defaults(GTK_BOX(button_box),
                            GTK_WIDGET(delete_button));
    
            gtk_box_pack_start_defaults(GTK_BOX(contact_box),
                            GTK_WIDGET(button_box));
    
            gtk_container_add(GTK_CONTAINER(appdata.window),
                            GTK_WIDGET(contact_box));
    
            g_signal_connect(G_OBJECT(add_button), "clicked",
                            G_CALLBACK(add_contact), &appdata);
            g_signal_connect(G_OBJECT(delete_button), "clicked",
                            G_CALLBACK(delete_contacts), &appdata);
    
    
            /* Run the application */
            example_gui_run(appdata.program, appdata.window);
    
            /* Deinitialize and free allocated resources */
            osso_abook_roster_stop(appdata.roster);
            g_object_unref(appdata.roster);
            e_book_view_stop(appdata.book_view);
            g_object_unref(appdata.book_view);
    
            osso_deinitialize(appdata.osso_context);
            return 0;
    }

  11. #11
    Registered User
    Join Date
    May 2010
    Posts
    6

    Re: How to print all contact names in N900 addressbook - Please Help

    Thank you so much for your help guys. You have no idea how long I've been stuck on this!! You rock!!

    Danill one quick question just to get my concepts clear:

    The code you gave works flawlessly if I compile and ssh it across to the device and then run it from the device using run-standalone.sh. However, if I either:

    a) try to run it from the pc terminal (using run-standalone.sh) after ssh'ing to the device or
    b) try to run it from the device after gaining root using 'sudo gainroot'

    I get a 'Permission Denied' error.

    Why is that? The above seems to suggest that I cant access the addressbook as root either if I use sudo gainroot or ssh to the device. (the n900 is connected to the pc via usb).

    A bit confused about this.

    Thanks again for the help.
    Sarshad

  12. #12
    Registered User
    Join Date
    Jun 2003
    Posts
    11

    Re: How to print all contact names in N900 addressbook - Please Help

    hi,
    what's difference between following 2 situation? it looks you use .sh to run it both.

    1)The code you gave works flawlessly if I compile and ssh it across to the device and then run it from the device using run-standalone.sh. However, if I either:
    2) try to run it from the pc terminal (using run-standalone.sh) after ssh'ing to the device or

  13. #13
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to print all contact names in N900 addressbook - Please Help

    First of all you run all applications as user, never as root. Environments are different and running applications as root is simply unsafe.
    If you are running application as user you don't need run-standalone.sh on the device. It's enough to use
    Code:
    ./binary_name
    . When you are running as root
    run-standalone.sh makes sense as it switch user and setting environment.
    You always can switch user with a command:
    Code:
    su - user

  14. #14
    Registered User
    Join Date
    May 2010
    Posts
    6

    Re: How to print all contact names in N900 addressbook - Please Help

    Hi Funpig.... in the first case I'm running the app locally on the tablet... but i'm not logged in as root. In the second case I'm ssh'ing to the tablet from my pc using ssh root@192..... (hence logging on as root on the tablet) and then trying to run the application remotely.

    Hi Danill...... thanks for the clarification. I was not aware that it is unsafe to run an application as root. Will learn more about it. Thank you for all your help.

    Sarshad

  15. #15
    Registered User
    Join Date
    Sep 2010
    Posts
    22

    Re: How to print all contact names in N900 addressbook - Please Help

    Quote Originally Posted by divanov View Post
    You have to wait before aggregator is ready.
    Thank you. This helped me a lot on my own application.

    Quote Originally Posted by divanov View Post
    Code:
    ...
        OssoABookAggregator *aggregator = OSSO_ABOOK_AGGREGATOR(roster);
        osso_abook_waitable_run(OSSO_ABOOK_WAITABLE(aggregator),
                                g_main_context_default(), &error);
    ...

Similar Threads

  1. Guitar Tuner in Python
    By cassioli in forum Symbian
    Replies: 44
    Last Post: 2009-11-30, 20:03
  2. Random RingTone within Contact List for 3rd
    By cckfranky in forum Symbian
    Replies: 5
    Last Post: 2007-12-29, 18:33
  3. How to send an image with attachment in email
    By krtrivdi in forum Symbian
    Replies: 1
    Last Post: 2007-01-09, 12:07
  4. Sending an image over email
    By jeclarim in forum Symbian
    Replies: 3
    Last Post: 2006-12-15, 20:25
  5. contact number and contact names doesn't match.
    By ninidotnet in forum Symbian User Interface
    Replies: 0
    Last Post: 2006-10-09, 09:25

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×