From: Sergio Villar Senin Date: Fri, 5 Jun 2009 09:29:27 +0000 (+0200) Subject: Use a filter function to show only desired contacts X-Git-Tag: 3.0.17-rc13~9 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=05a39554f335d35fb85361c40475e3c1dda9679f Use a filter function to show only desired contacts --- diff --git a/src/hildon2/modest-address-book.c b/src/hildon2/modest-address-book.c index 0af7d5a..19d314d 100644 --- a/src/hildon2/modest-address-book.c +++ b/src/hildon2/modest-address-book.c @@ -1046,42 +1046,49 @@ get_contacts_for_name (const gchar *name) return result; } +static gboolean +filter_by_name (OssoABookContactChooser *chooser, + OssoABookContact *contact, + gpointer user_data) +{ + const gchar *contact_name; + const gchar *name = (const gchar *) user_data; + + contact_name = osso_abook_contact_get_name (contact); + /* contact_name includes both name and surname */ + if (contact_name && name && strstr (contact_name, name)) + return TRUE; + else + return FALSE; +} + static GList * select_contacts_for_name_dialog (const gchar *name) { - EBookQuery *full_name_book_query = NULL; - EBookView *book_view = NULL; + GtkWidget *contact_view; + OssoABookContactChooser *contact_dialog; GList *result = NULL; gchar *unquoted; + contact_dialog = (OssoABookContactChooser *) + osso_abook_contact_chooser_new_with_capabilities (NULL, + _AB("addr_ti_dia_select_contacts"), + OSSO_ABOOK_CAPS_EMAIL, + OSSO_ABOOK_CONTACT_ORDER_NAME); + + /* Enable multiselection */ + osso_abook_contact_chooser_set_maximum_selection (contact_dialog, G_MAXUINT); + + /* Set up the filtering */ unquoted = unquote_string (name); - full_name_book_query = e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_CONTAINS, unquoted); - g_free (unquoted); - e_book_get_book_view (book, full_name_book_query, NULL, -1, &book_view, NULL); - e_book_query_unref (full_name_book_query); + contact_view = osso_abook_contact_chooser_get_contact_view (contact_dialog); + osso_abook_contact_chooser_set_model (contact_dialog, contact_model); + osso_abook_contact_chooser_set_visible_func (contact_dialog, filter_by_name, unquoted, NULL); - if (book_view) { - GtkWidget *contact_dialog = NULL; - osso_abook_list_store_set_book_view (OSSO_ABOOK_LIST_STORE (contact_model), book_view); - e_book_view_start (book_view); - - /* TODO: figure out how to make the contact chooser modal */ - contact_dialog = osso_abook_contact_chooser_new_with_capabilities (NULL, - _AB("addr_ti_dia_select_contacts"), - OSSO_ABOOK_CAPS_EMAIL, - OSSO_ABOOK_CONTACT_ORDER_NAME); - /* Enable multiselection */ - osso_abook_contact_chooser_set_maximum_selection (OSSO_ABOOK_CONTACT_CHOOSER (contact_dialog), - G_MAXUINT); - osso_abook_contact_chooser_set_model (OSSO_ABOOK_CONTACT_CHOOSER (contact_dialog), - contact_model); - - if (gtk_dialog_run (GTK_DIALOG (contact_dialog)) == GTK_RESPONSE_OK) - result = osso_abook_contact_chooser_get_selection (OSSO_ABOOK_CONTACT_CHOOSER (contact_dialog)); - e_book_view_stop (book_view); - g_object_unref (book_view); - gtk_widget_destroy (contact_dialog); - } + if (gtk_dialog_run (GTK_DIALOG (contact_dialog)) == GTK_RESPONSE_OK) + result = osso_abook_contact_chooser_get_selection (contact_dialog); + + g_free (unquoted); return result; }