diff options
author | Chris Toshok <toshok@ximian.com> | 2004-05-29 12:43:04 +0800 |
---|---|---|
committer | Chris Toshok <toshok@src.gnome.org> | 2004-05-29 12:43:04 +0800 |
commit | 3feccd8c20fdd464521369678195af32ac067125 (patch) | |
tree | cb72748c475c9528f689a6c88ad27137b67064f6 /addressbook | |
parent | 9e6feeb9fb6bf39d4809850f0833bed8a8a8387b (diff) | |
download | gsoc2013-evolution-3feccd8c20fdd464521369678195af32ac067125.tar.gz gsoc2013-evolution-3feccd8c20fdd464521369678195af32ac067125.tar.zst gsoc2013-evolution-3feccd8c20fdd464521369678195af32ac067125.zip |
call e_select_names_model_load_contacts after setting
2004-05-28 Chris Toshok <toshok@ximian.com>
* gui/component/select-names/e-select-names-bonobo.c
(entry_set_property_fn): call e_select_names_model_load_contacts
after setting text/addresses/destinations.
* gui/component/select-names/e-select-names-model.c
(name_and_email_simple_query_cb): new function, ripped from the
1.4 e-destination stuff.
(book_opened): new function, fire off eab_name_and_email_query for
each item in our model (that doesn't represent a contact already).
(e_select_names_model_load_contacts): new function, open the
default addressbook (yeah yeah, i know we should open something
different/more.)
(e_select_names_cancel_contacts_load): new (unimplemented, and how
do we implement it?) function.
* gui/component/select-names/e-select-names-model.h: add
prototypes for e_select_names_model_load_contacts and
e_select_names_cancel_contacts_load.
* gui/component/select-names/e-select-names.c (set_book): call
get_query_string and set the book and query in a single call to
g_object_set, just because we can/should.
(update_query): reimplement in terms of get_query_string.
(get_query_string): new function, build up the query string.
* gui/component/select-names/Makefile.am (INCLUDES): add
$(top_srcdir)/addressbook/util to INCLUDES.
svn path=/trunk/; revision=26129
Diffstat (limited to 'addressbook')
6 files changed, 153 insertions, 8 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index 6727dfd5a8..e184545e0f 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,33 @@ +2004-05-28 Chris Toshok <toshok@ximian.com> + + * gui/component/select-names/e-select-names-bonobo.c + (entry_set_property_fn): call e_select_names_model_load_contacts + after setting text/addresses/destinations. + + * gui/component/select-names/e-select-names-model.c + (name_and_email_simple_query_cb): new function, ripped from the + 1.4 e-destination stuff. + (book_opened): new function, fire off eab_name_and_email_query for + each item in our model (that doesn't represent a contact already). + (e_select_names_model_load_contacts): new function, open the + default addressbook (yeah yeah, i know we should open something + different/more.) + (e_select_names_cancel_contacts_load): new (unimplemented, and how + do we implement it?) function. + + * gui/component/select-names/e-select-names-model.h: add + prototypes for e_select_names_model_load_contacts and + e_select_names_cancel_contacts_load. + + * gui/component/select-names/e-select-names.c (set_book): call + get_query_string and set the book and query in a single call to + g_object_set, just because we can/should. + (update_query): reimplement in terms of get_query_string. + (get_query_string): new function, build up the query string. + + * gui/component/select-names/Makefile.am (INCLUDES): add + $(top_srcdir)/addressbook/util to INCLUDES. + 2004-05-28 Hans Petter Jansson <hpj@ximian.com> * gui/contact-editor/contact-editor.glade: Add back office, spouse, diff --git a/addressbook/gui/component/select-names/Makefile.am b/addressbook/gui/component/select-names/Makefile.am index 8cd1235be2..c8d0b83052 100644 --- a/addressbook/gui/component/select-names/Makefile.am +++ b/addressbook/gui/component/select-names/Makefile.am @@ -33,6 +33,7 @@ INCLUDES = \ -I$(top_srcdir)/addressbook/contact-editor \ -I$(top_srcdir)/addressbook/backend \ -I$(top_builddir)/addressbook/backend \ + -I$(top_srcdir)/addressbook/util \ -DEVOLUTION_IMAGESDIR=\""$(imagesdir)"\" \ -DEVOLUTION_DATADIR=\""$(datadir)"\" \ -DEVOLUTION_GLADEDIR=\""$(gladedir)"\" \ diff --git a/addressbook/gui/component/select-names/e-select-names-bonobo.c b/addressbook/gui/component/select-names/e-select-names-bonobo.c index 871bb8b3f6..9c0245ff46 100644 --- a/addressbook/gui/component/select-names/e-select-names-bonobo.c +++ b/addressbook/gui/component/select-names/e-select-names-bonobo.c @@ -159,6 +159,7 @@ entry_set_property_fn (BonoboPropertyBag *bag, g_assert (model != NULL); e_entry_set_text (E_ENTRY (w), BONOBO_ARG_GET_STRING (arg)); + e_select_names_model_load_contacts (model); break; } @@ -169,6 +170,7 @@ entry_set_property_fn (BonoboPropertyBag *bag, g_assert (model != NULL); e_select_names_model_import_destinationv (model, BONOBO_ARG_GET_STRING (arg)); + e_select_names_model_load_contacts (model); break; } 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) { diff --git a/addressbook/gui/component/select-names/e-select-names-model.h b/addressbook/gui/component/select-names/e-select-names-model.h index 8bb8e3778b..10bede3f85 100644 --- a/addressbook/gui/component/select-names/e-select-names-model.h +++ b/addressbook/gui/component/select-names/e-select-names-model.h @@ -76,6 +76,9 @@ void e_select_names_model_clean (ESelectNamesModel *model, gboolea void e_select_names_model_name_pos (ESelectNamesModel *model, gint seplen, gint index, gint *pos, gint *length); void e_select_names_model_text_pos (ESelectNamesModel *model, gint seplen, gint pos, gint *index, gint *start_pos, gint *length); +void e_select_names_model_load_contacts (ESelectNamesModel *model); +void e_select_names_cancel_contacts_load (ESelectNamesModel *model); + /* This is a mildly annoying freeze/thaw pair, in that it only applies to the 'changed' signal and not to 'resized'. This could cause unexpected results in some cases. */ void e_select_names_model_freeze (ESelectNamesModel *model); diff --git a/addressbook/gui/component/select-names/e-select-names.c b/addressbook/gui/component/select-names/e-select-names.c index cdf5628caa..158abd0755 100644 --- a/addressbook/gui/component/select-names/e-select-names.c +++ b/addressbook/gui/component/select-names/e-select-names.c @@ -47,10 +47,11 @@ #include <e-util/e-categories-master-list-wombat.h> #include "e-util/e-sexp.h" -static void e_select_names_init (ESelectNames *names); -static void e_select_names_class_init (ESelectNamesClass *klass); -static void e_select_names_dispose (GObject *object); -static void update_query (GtkWidget *widget, ESelectNames *e_select_names); +static void e_select_names_init (ESelectNames *names); +static void e_select_names_class_init (ESelectNamesClass *klass); +static void e_select_names_dispose (GObject *object); +static void update_query (GtkWidget *widget, ESelectNames *e_select_names); +static char *get_query_string (ESelectNames *e_select_names); static void sync_table_and_models (ESelectNamesModel *triggering_model, ESelectNames *esl); @@ -120,10 +121,12 @@ search_result (EABModel *model, EBookViewStatus status, ESelectNames *esn) static void set_book(EBook *book, EBookStatus status, ESelectNames *esn) { + char *query_str = get_query_string (esn); g_object_set(esn->model, "book", book, + "query", query_str, NULL); - update_query (NULL, esn); + g_free (query_str); g_object_unref(book); g_object_unref(esn->model); g_object_unref(esn); @@ -342,8 +345,8 @@ source_selected (ESourceOptionMenu *menu, ESource *source, ESelectNames *e_selec e_select_names_config_set_last_completion_book (e_source_peek_uid (source)); } -static void -update_query (GtkWidget *widget, ESelectNames *e_select_names) +static char * +get_query_string (ESelectNames *e_select_names) { char *category = ""; const char *search = ""; @@ -376,12 +379,20 @@ update_query (GtkWidget *widget, ESelectNames *e_select_names) query = q_array[0]; } query_str = e_book_query_to_string (query); + e_book_query_unref (query); + return query_str; +} + + +static void +update_query (GtkWidget *widget, ESelectNames *e_select_names) +{ + char *query_str = get_query_string (e_select_names); printf ("query_str = %s\n", query_str); g_object_set (e_select_names->model, "query", query_str, NULL); g_free (query_str); - e_book_query_unref (query); } static void |