diff options
Diffstat (limited to 'addressbook/gui/component/select-names/e-select-names-model.c')
-rw-r--r-- | addressbook/gui/component/select-names/e-select-names-model.c | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/addressbook/gui/component/select-names/e-select-names-model.c b/addressbook/gui/component/select-names/e-select-names-model.c index 506eb40124..877f03a01a 100644 --- a/addressbook/gui/component/select-names/e-select-names-model.c +++ b/addressbook/gui/component/select-names/e-select-names-model.c @@ -16,9 +16,11 @@ #include <gtk/gtksignal.h> #include <gal/util/e-util.h> +#include <libebook/e-book-async.h> #include <libebook/e-contact.h> #include "e-select-names-model.h" #include "e-select-names-marshal.h" +#include "eab-book-util.h" #define MAX_LENGTH 2047 @@ -587,6 +589,102 @@ e_select_names_model_merge (ESelectNamesModel *dest, ESelectNamesModel *src) } } +typedef struct { + EDestination *dest; + ESelectNamesModel *model; +} ModelDestClosure; + +static void +name_and_email_simple_query_cb (EBook *book, EBookStatus status, GList *contacts, gpointer closure) +{ + ModelDestClosure *c = closure; + EDestination *dest = c->dest; + ESelectNamesModel *model = c->model; + + g_free (c); + + if (status == E_BOOK_ERROR_OK && g_list_length (contacts) == 1) { + EContact *contact = E_CONTACT (contacts->data); + const char *email = e_destination_get_email (dest); + int email_num = 0; + + if (email && *email) { + GList *email_list = e_contact_get (contact, E_CONTACT_EMAIL); + GList *l; + + for (l = email_list; l; l = l->next) { + if (!g_ascii_strcasecmp (email, l->data)) + break; + email_num++; + } + if (l == NULL) + email_num = -1; + } + + if (email_num >= 0) { + e_destination_set_contact (dest, contact, email_num); + e_select_names_model_changed (model); + } + } + + + g_object_unref (dest); + g_object_unref (model); + g_object_unref (book); +} + +static void +book_opened (EBook *book, EBookStatus status, gpointer closure) +{ + ESelectNamesModel *model = closure; + GList *iter; + + for (iter = model->priv->data; iter != NULL; iter = g_list_next (iter)) { + ModelDestClosure *c = g_new (ModelDestClosure, 1); + + c->dest = g_object_ref (E_DESTINATION (iter->data)); + c->model = g_object_ref (model); + + if (e_destination_is_evolution_list (c->dest)) + continue; + + if (e_destination_get_contact (c->dest)) + continue; + + g_object_ref (book); + + eab_name_and_email_query (book, + e_destination_get_name (c->dest), + e_destination_get_email (c->dest), + name_and_email_simple_query_cb, + c); + } + + + g_object_unref (model); + g_object_unref (book); +} + +void +e_select_names_model_load_contacts (ESelectNamesModel *model) +{ + EBook *book; + + g_return_if_fail (E_IS_SELECT_NAMES_MODEL (model)); + + g_object_ref (model); + + book = e_book_new_default_addressbook (NULL); + + e_book_async_open (book, TRUE, book_opened, model); +} + +void +e_select_names_cancel_contacts_load (ESelectNamesModel *model) +{ +} + + void e_select_names_model_name_pos (ESelectNamesModel *model, gint seplen, gint index, gint *pos, gint *length) { |