+
+const gchar *
+modest_address_book_get_my_name ()
+{
+ OssoABookSelfContact *self_contact = osso_abook_self_contact_get_default ();
+
+ /* We are not using osso_abook_contact_get_display_name
+ because that method fallbacks to another fields if the name
+ is not defined */
+ if (self_contact)
+ return e_contact_get ((EContact *) self_contact, E_CONTACT_FULL_NAME);
+ else
+ return NULL;
+}
+
+void
+modest_address_book_init (void)
+{
+ open_addressbook ();
+}
+
+void
+modest_address_book_add_address_list (GSList *address_list)
+{
+ EBookQuery **queries, *composite_query;
+ gint num_add, i;
+
+ g_return_if_fail (address_list);
+
+ if (!book)
+ if (!open_addressbook ())
+ g_return_if_reached ();
+
+ /* Create the list of queries */
+ num_add = g_slist_length (address_list);
+ queries = g_malloc0 (sizeof (EBookQuery *) * num_add);
+ for (i = 0; i < num_add; i++) {
+ gchar *email;
+
+ email = modest_text_utils_get_email_address (g_slist_nth_data (address_list, i));
+ queries[i] = e_book_query_field_test (E_CONTACT_EMAIL, E_BOOK_QUERY_IS, email);
+ g_free (email);
+ }
+
+ /* Create the query */
+ composite_query = e_book_query_or (num_add, queries, TRUE);
+
+ /* Asynchronously retrieve contacts */
+ e_book_async_get_contacts (book, composite_query, async_get_contacts_cb, address_list);
+
+ /* Frees. This will unref the subqueries as well */
+ e_book_query_unref (composite_query);
+}
+
+void
+modest_address_book_add_address_list_with_selector (GSList *address_list, GtkWindow *parent)
+{
+ GtkWidget *picker_dialog;
+ GtkWidget *selector;
+ GSList *node;
+ gchar *selected = NULL;
+ gboolean contacts_to_add = FALSE;
+
+ selector = hildon_touch_selector_new_text ();
+ g_object_ref (selector);
+
+ for (node = address_list; node != NULL; node = g_slist_next (node)) {
+ if (!modest_address_book_has_address ((const gchar *) node->data)) {
+ hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
+ (const gchar *) node->data);
+ contacts_to_add = TRUE;
+ }
+ }
+
+ if (contacts_to_add) {
+ gint picker_result;
+
+ picker_dialog = hildon_picker_dialog_new (parent);
+ gtk_window_set_title (GTK_WINDOW (picker_dialog), _("mcen_me_viewer_addtocontacts"));
+
+ hildon_picker_dialog_set_selector (HILDON_PICKER_DIALOG (picker_dialog),
+ HILDON_TOUCH_SELECTOR (selector));
+
+ picker_result = gtk_dialog_run (GTK_DIALOG (picker_dialog));
+
+ if (picker_result == GTK_RESPONSE_OK) {
+ selected = hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector));
+ }
+ gtk_widget_destroy (picker_dialog);
+
+ if (selected)
+ modest_address_book_add_address (selected, parent);
+ g_free (selected);
+
+ } else {
+ g_object_unref (selector);
+ }
+}