}
void
-modest_address_book_select_addresses (ModestRecptEditor *recpt_editor)
+modest_address_book_select_addresses (ModestRecptEditor *recpt_editor,
+ GtkWindow *parent_window)
{
#if MODEST_ABOOK_API < 4
GtkWidget *contact_view = NULL;
}
#else /* MODEST_ABOOK_API < 4 */
/* TODO: figure out how to make the contact chooser modal */
- contact_chooser = osso_abook_contact_chooser_new_with_capabilities (NULL,
+ contact_chooser = osso_abook_contact_chooser_new_with_capabilities (parent_window,
_AB("addr_ti_dia_select_contacts"),
OSSO_ABOOK_CAPS_EMAIL,
OSSO_ABOOK_CONTACT_ORDER_NAME);
return selected_email_addr_list;
}
+/* Assumes that the second argument (the user provided one) is a pure
+ email address without name */
+static gint
+compare_addresses (const gchar *address1,
+ const gchar *mail2)
+{
+ gint retval;
+ gchar *mail1;
+
+ mail1 = modest_text_utils_get_email_address (address1);
+ retval = g_strcmp0 (mail1, mail2);
+ g_free (mail1);
+
+ return retval;
+}
+
static EContact *
get_contact_for_address (GList *contacts,
const gchar *address)
{
EContact *retval = NULL, *contact;
GList *iter;
+ gchar *email;
+ email = modest_text_utils_get_email_address (address);
iter = contacts;
while (iter && !retval) {
GList *emails = NULL;
emails = e_contact_get (contact, E_CONTACT_EMAIL);
if (emails) {
/* Look for the email address */
- if (g_list_find_custom (emails, address, (GCompareFunc) g_strcmp0))
+ if (g_list_find_custom (emails, email, (GCompareFunc) compare_addresses))
retval = contact;
/* Free the list */
}
iter = g_list_next (iter);
}
+ g_free (email);
+
return retval;
}
{
GSList *addresses, *iter;
GList *to_commit_contacts, *to_add_contacts;
+ EContact *self_contact;
addresses = (GSList *) closure;
if (status != E_BOOK_ERROR_OK)
goto frees;
+ self_contact = (EContact *) osso_abook_self_contact_get_default ();
+ if (self_contact) {
+ contacts = g_list_prepend (contacts, self_contact);
+ }
+
iter = addresses;
to_commit_contacts = NULL;
to_add_contacts = NULL;
/* Add new or commit existing contact */
if (contact) {
to_commit_contacts = g_list_prepend (to_commit_contacts, contact);
- g_debug ("Preparing to commit contact %s", address);
+ g_debug ("----Preparing to commit contact %s", address);
} else {
+ gchar *email_address, *display_address;
+
+ /* Create new contact and add it to the list */
+ contact = e_contact_new ();
+ email_address = modest_text_utils_get_email_address (address);
+ e_contact_set (contact, E_CONTACT_EMAIL_1, email_address);
+ g_free (email_address);
+
+ display_address = g_strdup (address);
+ if (display_address) {
+ modest_text_utils_get_display_address (display_address);
+ if ((display_address[0] != '\0') && (strlen (display_address) != strlen (address)))
+ e_contact_set (contact, E_CONTACT_FULL_NAME, (const gpointer)display_address);
+ g_free (display_address);
+ }
+
to_add_contacts = g_list_prepend (to_add_contacts, contact);
- g_debug ("Preparing to add contact %s", address);
+ g_debug ("----Preparing to add contact %s", address);
}
iter = g_slist_next (iter);
g_list_foreach (contacts, (GFunc) g_object_unref, NULL);
g_list_free (contacts);
}
-
}
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, NULL);
+ e_book_async_get_contacts (book, composite_query, async_get_contacts_cb, addresses);
/* Frees. This will unref the subqueries as well */
e_book_query_unref (composite_query);
return result;
}
+
+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)
+ if (OSSO_ABOOK_IS_CONTACT (self_contact))
+ return osso_abook_contact_get_name ((OssoABookContact*)self_contact);
+ else
+ return e_contact_get ((EContact *) self_contact, E_CONTACT_NAME);
+ else
+ return NULL;
+}