Reply
Thread Tools
Posts: 51 | Thanked: 15 times | Joined on Apr 2009 @ ChengDu, SiChuan, P.R.C
#1
hi,

i had a question for API osso_abook_touch_contact_starter_new_with_contact. if i used following code come from http://wiki.maemo.org/Documentation/...ContactStarter. it's working fine.
Code:
#include <libosso-abook/osso-abook.h>

int main (int argc, char** argv)
{
        osso_context_t *osso_cxt;
        //OssoABookTouchContactStarter *starter;
        GtkWidget *starter, *window, *chooser;
        GList *contacts = NULL;

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

        chooser = osso_abook_contact_chooser_new (NULL, "Pick a Contact");
        gtk_dialog_run (GTK_DIALOG (chooser));
        gtk_widget_hide (chooser);

        contacts = osso_abook_contact_chooser_get_selection
                (OSSO_ABOOK_CONTACT_CHOOSER (chooser));

        if (contacts) {
                starter = osso_abook_touch_contact_starter_new_with_contact
                        (NULL, contacts->data);
                window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
                gtk_container_add (GTK_CONTAINER (window), starter);

                gtk_widget_show (starter);
                gtk_widget_show (window);
                g_signal_connect (window, "destroy", gtk_main_quit, NULL);
                gtk_main ();

                g_list_free (contacts);
        }

        return 0;
}
But, if i use following code. it had some problem
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;
        OssoABookAggregator *aggregator;
        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, OssoABookContact *master_contact,
                AppData *appdata)
{
        GtkWidget *starter;
        GtkWidget *dlg;

        /* Create new contact starter dialog */
        starter = osso_abook_touch_contact_starter_new_with_contact(NULL, master_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 */
        dlg = osso_abook_touch_contact_starter_dialog_new(GTK_WINDOW(appdata->window), starter);
        gtk_dialog_run(GTK_DIALOG(dlg));

        gtk_widget_destroy(GTK_WIDGET(starter));
}

/* Callback to be called when user activates (double clicks) a contact
 * in the contact view */
static void print_contact_info(OssoABookContactView *view, EContact *contact,
                AppData *appdata)
{
        printf("contact info E_CONTACT_UID :%s\n",       e_contact_get(contact, E_CONTACT_UID));
        printf("contact info E_CONTACT_FILE_AS :%s\n",   e_contact_get(contact, E_CONTACT_FILE_AS));
        printf("contact info E_CONTACT_BOOK_URI :%s\n",  e_contact_get(contact, E_CONTACT_BOOK_URI));

        printf("contact info E_CONTACT_FULL_NAME :%s\n",    e_contact_get(contact, E_CONTACT_FULL_NAME));
        printf("contact info E_CONTACT_GIVEN_NAME :%s\n",   e_contact_get(contact, E_CONTACT_GIVEN_NAME));
        printf("contact info E_CONTACT_FAMILY_NAME :%s\n",  e_contact_get(contact, E_CONTACT_FAMILY_NAME));
        printf("contact info E_CONTACT_NICKNAME :%s\n",     e_contact_get(contact, E_CONTACT_NICKNAME));

        printf("contact info E_CONTACT_CATEGORIES :%s\n",   e_contact_get(contact, E_CONTACT_CATEGORIES));

        printf("contact info E_CONTACT_PHONE_ASSISTANT :%s\n",   e_contact_get(contact, E_CONTACT_PHONE_ASSISTANT));
        printf("contact info E_CONTACT_PHONE_BUSINESS :%s\n",   e_contact_get(contact, E_CONTACT_PHONE_BUSINESS));
        printf("contact info E_CONTACT_PHONE_HOME :%s\n",   e_contact_get(contact, E_CONTACT_PHONE_HOME));
        printf("contact info E_CONTACT_PHONE_MOBILE :%s\n",   e_contact_get(contact, E_CONTACT_PHONE_MOBILE));
}

/* 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) {
            g_critical("Couldn't open roster: %s\n", error->message);
            g_error_free(error);
        }
        osso_abook_roster_start(appdata->roster);

        appdata->aggregator = osso_abook_aggregator_get_default( &error );
        if (error) {
            g_critical("Couldn't open aggregator: %s\n", error->message);
            g_error_free(error);
        }

        /* 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);

        g_signal_connect(G_OBJECT(appdata->contact_view), "contact-activated",
                        G_CALLBACK(print_contact_info), 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;
}
the contact come from OssoABookContactChooser has difference with contact come from osso_abook_contact_view with signal "contact-activated" ??

screenshot please see the attachment. thank.
Attached Files
File Type: tar pic.tar (80.0 KB, 64 views)
 
Reply


 
Forum Jump


All times are GMT. The time now is 14:15.