diff options
-rw-r--r-- | addressbook/ChangeLog | 30 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-card-compare.c | 4 | ||||
-rw-r--r-- | addressbook/gui/component/e-address-popup.c | 181 | ||||
-rw-r--r-- | addressbook/gui/component/e-address-popup.h | 3 | ||||
-rw-r--r-- | addressbook/gui/component/select-names/e-select-names-popup.c | 4 |
5 files changed, 170 insertions, 52 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index 687d6570db..b5cdb76d65 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,33 @@ +2001-06-21 Jon Trowbridge <trow@ximian.com> + + * gui/component/select-names/e-select-names-popup.c + (make_contact_editor_cb): Renamed. (The old name, + edit_contact_info_have_book_cb was a hold-over from before, when + we weren't using e_book_use_local_address_book.) + + * gui/component/e-address-popup.c + (e_address_popup_schedule_refresh): A Added. We now do the name + refreshes in an idle function, rather than in the setters. + (e_address_popup_set_free_form): Added. Properly handle inputs of + the form "Foo <bar@zar.com>", extracting the name and e-mail + address. + (e_address_popup_set_name): Check to make sure that the free-form + handler shouldn't be used to handle the input. Schedule a refresh + after making any changes. + (e_address_popup_set_email): Check to make sure that the free-form + handler shouldn't be used to handle the input. Schedule a refresh + after making any changes. + (e_address_popup_name_only_matches): Temporary place-holder for + handling name-only matches. + (query_cb): If our initial query fails (and included e-mail + information), do a name-only query. This is to handle the case of + adding new e-mail addresses to existing contacts. + (e_address_popup_query): Eliminated the "common_book" crap; using + e_book_use_local_address_book instead. + + * backend/ebook/e-card-compare.c (match_search_info_free): Make + sure that the ->avoid list gets properly freed. + 2001-06-20 Chris Toshok <toshok@ximian.com> * backend/pas/pas-backend-file.c diff --git a/addressbook/backend/ebook/e-card-compare.c b/addressbook/backend/ebook/e-card-compare.c index 136535409b..6f5cf86de9 100644 --- a/addressbook/backend/ebook/e-card-compare.c +++ b/addressbook/backend/ebook/e-card-compare.c @@ -337,6 +337,10 @@ match_search_info_free (MatchSearchInfo *info) if (info) { gtk_object_unref (GTK_OBJECT (info->card)); g_free (info); + + /* This should already have been deallocated, but just in case... */ + g_list_foreach (info->avoid, (GFunc) gtk_object_unref, NULL); + g_list_free (info->avoid); } } diff --git a/addressbook/gui/component/e-address-popup.c b/addressbook/gui/component/e-address-popup.c index 81add0e243..0d01e3f162 100644 --- a/addressbook/gui/component/e-address-popup.c +++ b/addressbook/gui/component/e-address-popup.c @@ -37,12 +37,11 @@ #include <addressbook/contact-editor/e-contact-editor.h> #include <addressbook/contact-editor/e-contact-quick-add.h> #include <addressbook/gui/widgets/e-minicard-widget.h> - +#include <addressbook/gui/widgets/e-addressbook-util.h> static GtkObjectClass *parent_class; -static EBook *common_book = NULL; /* still sort of lame */ -static void e_address_popup_destroy (GtkObject *); -static void e_address_popup_query (EAddressPopup *); +static void e_address_popup_destroy (GtkObject *); +static void e_address_popup_query (EAddressPopup *); static void @@ -69,6 +68,9 @@ e_address_popup_destroy (GtkObject *obj) if (pop->card) gtk_object_unref (GTK_OBJECT (pop->card)); + if (pop->scheduled_refresh) + gtk_idle_remove (pop->scheduled_refresh); + if (pop->leave_timeout_tag) gtk_timeout_remove (pop->leave_timeout_tag); @@ -129,17 +131,66 @@ e_address_popup_refresh_names (EAddressPopup *pop) e_address_popup_query (pop); } +static gint +refresh_idle_cb (gpointer ptr) +{ + EAddressPopup *pop = E_ADDRESS_POPUP (ptr); + e_address_popup_refresh_names (pop); + pop->scheduled_refresh = 0; + return 0; +} + +static void +e_address_popup_schedule_refresh (EAddressPopup *pop) +{ + if (pop->scheduled_refresh == 0) + pop->scheduled_refresh = gtk_idle_add (refresh_idle_cb, pop); +} + +/* If we are handed something of the form "Foo <bar@bar.com>", + do the right thing. */ +static gboolean +e_address_popup_set_free_form (EAddressPopup *pop, const gchar *txt) +{ + gchar *lt, *gt = NULL; + + g_return_val_if_fail (pop && E_IS_ADDRESS_POPUP (pop), FALSE); + + if (txt == NULL) + return FALSE; + + lt = strchr (txt, '<'); + if (lt) + gt = strchr (txt, '>'); + + if (lt && gt && lt+1 < gt) { + gchar *name = g_strndup (txt, lt-txt); + gchar *email = g_strndup (lt+1, gt-lt-1); + e_address_popup_set_name (pop, name); + e_address_popup_set_email (pop, email); + + return TRUE; + } + + return FALSE; +} + void e_address_popup_set_name (EAddressPopup *pop, const gchar *name) { g_return_if_fail (pop && E_IS_ADDRESS_POPUP (pop)); - g_free (pop->name); - pop->name = g_strdup (name); - g_strstrip (pop->name); + /* We only allow the name to be set once. */ + if (pop->name) + return; - if (pop->name && pop->email) - e_address_popup_refresh_names (pop); + if (!e_address_popup_set_free_form (pop, name)) { + pop->name = g_strdup (name); + if (pop->name) + g_strstrip (pop->name); + } + + e_address_popup_schedule_refresh (pop); } void @@ -147,12 +198,17 @@ e_address_popup_set_email (EAddressPopup *pop, const gchar *email) { g_return_if_fail (pop && E_IS_ADDRESS_POPUP (pop)); - g_free (pop->email); - pop->email = g_strdup (email); - g_strstrip (pop->email); + /* We only allow the e-mail to be set once. */ + if (pop->email) + return; + + if (!e_address_popup_set_free_form (pop, email)) { + pop->email = g_strdup (email); + if (pop->email) + g_strstrip (pop->email); + } - if (pop->name && pop->email) - e_address_popup_refresh_names (pop); + e_address_popup_schedule_refresh (pop); } void @@ -214,10 +270,17 @@ e_address_popup_new (void) } static void +contact_editor_cb (EBook *book, gpointer closure) +{ + EAddressPopup *pop = E_ADDRESS_POPUP (closure); + EContactEditor *ce = e_addressbook_show_contact_editor (book, pop->card, FALSE, TRUE); + e_contact_editor_raise (ce); +} + +static void edit_contact_info_cb (EAddressPopup *pop) { - EContactEditor *ce = e_addressbook_show_contact_editor (common_book, pop->card, FALSE, TRUE); - e_contact_editor_raise (ce); + e_book_use_local_address_book (contact_editor_cb, pop); gtk_widget_destroy (GTK_WIDGET (pop)); } @@ -250,7 +313,6 @@ static void add_contacts_cb (EAddressPopup *pop) { if (pop->email && *pop->email) { - if (pop->name && *pop->name) e_contact_quick_add (pop->name, pop->email, NULL, NULL); else @@ -280,7 +342,23 @@ e_address_popup_no_matches (EAddressPopup *pop) static void e_address_popup_multiple_matches (EAddressPopup *pop) { - + pop->multiple_matches = TRUE; +} + +static void +e_address_popup_name_only_matches (EAddressPopup *pop, const GList *cards) +{ + const GList *iter; + for (iter = cards; iter != NULL; iter = g_list_next (iter)) { + const ECard *card = E_CARD (iter->data); + gchar *name = e_card_name_to_string (card->name); + gchar *s = g_strdup_printf ("Matched %s", name); + GtkWidget *w = gtk_label_new (s); + gtk_widget_show (w); + g_free (name); + g_free (s); + gtk_box_pack_start (GTK_BOX (pop->main_vbox), w, TRUE, TRUE, 0); + } } @@ -291,7 +369,7 @@ e_address_popup_multiple_matches (EAddressPopup *pop) */ static void -query_cb (EBook *book, EBookSimpleQueryStatus status, const GList *cards, gpointer closure) +name_only_query_cb (EBook *book, EBookSimpleQueryStatus status, const GList *cards, gpointer closure) { EAddressPopup *pop; @@ -300,47 +378,57 @@ query_cb (EBook *book, EBookSimpleQueryStatus status, const GList *cards, gpoint pop = E_ADDRESS_POPUP (closure); - pop->have_queried = TRUE; - gtk_widget_hide (pop->query_msg); + pop->query_tag = 0; if (cards == NULL) { - e_address_popup_no_matches (pop); + } else { + e_address_popup_name_only_matches (pop, cards); + } +} + +static void +query_cb (EBook *book, EBookSimpleQueryStatus status, const GList *cards, gpointer closure) +{ + EAddressPopup *pop; + + if (status != E_BOOK_SIMPLE_QUERY_STATUS_SUCCESS) + return; + + pop = E_ADDRESS_POPUP (closure); + pop->query_tag = 0; + gtk_widget_hide (pop->query_msg); + + if (cards == NULL) { + + /* Do a name-only query if: + (1) The name is non-empty. + (2) The e-mail is also non-empty (so that the query we just did wasn't actually a name-only query. + */ + if (pop->name && *pop->name && pop->email && *pop->email) { + pop->query_tag = e_book_name_and_email_query (book, pop->name, NULL, name_only_query_cb, pop); + } else { + e_address_popup_no_matches (pop); + } + } else { if (g_list_length ((GList *) cards) == 1) e_address_popup_cardify (pop, E_CARD (cards->data)); else e_address_popup_multiple_matches (pop); } - - pop->query_tag = 0; } static void -start_query (EAddressPopup *pop) +start_query (EBook *book, gpointer closure) { - g_assert (common_book != NULL); - g_return_if_fail (pop && E_IS_ADDRESS_POPUP (pop)); + EAddressPopup *pop = E_ADDRESS_POPUP (closure); if (pop->query_tag) - e_book_simple_query_cancel (common_book, pop->query_tag); + e_book_simple_query_cancel (book, pop->query_tag); - pop->query_tag = e_book_name_and_email_query (common_book, pop->name, pop->email, query_cb, pop); -} - -static void -loaded_book_cb (EBook *book, EBookStatus status, gpointer closure) -{ - g_return_if_fail (status == E_BOOK_STATUS_SUCCESS); - g_return_if_fail (book != NULL); - - if (common_book == NULL) { - common_book = book; - gtk_object_ref (GTK_OBJECT (common_book)); - } - - start_query (E_ADDRESS_POPUP (closure)); + pop->query_tag = e_book_name_and_email_query (book, pop->name, pop->email, query_cb, pop); } static void @@ -348,12 +436,7 @@ e_address_popup_query (EAddressPopup *pop) { g_return_if_fail (pop && E_IS_ADDRESS_POPUP (pop)); - if (common_book == NULL) { - EBook *book = e_book_new (); - e_book_load_local_address_book (book, loaded_book_cb, pop); - } else { - start_query (pop); - } + e_book_use_local_address_book (start_query, pop); } /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/ diff --git a/addressbook/gui/component/e-address-popup.h b/addressbook/gui/component/e-address-popup.h index 1ecfc773c7..26b1c49219 100644 --- a/addressbook/gui/component/e-address-popup.h +++ b/addressbook/gui/component/e-address-popup.h @@ -60,8 +60,9 @@ struct _EAddressPopup { GtkWidget *generic_view; GtkWidget *minicard_view; + guint scheduled_refresh; guint query_tag; - gboolean have_queried, multiple_matches; + gboolean multiple_matches; ECard *card; }; diff --git a/addressbook/gui/component/select-names/e-select-names-popup.c b/addressbook/gui/component/select-names/e-select-names-popup.c index 4cea4dfb86..03dadf2d80 100644 --- a/addressbook/gui/component/select-names/e-select-names-popup.c +++ b/addressbook/gui/component/select-names/e-select-names-popup.c @@ -94,7 +94,7 @@ popup_info_cleanup (GtkWidget *w, gpointer info) /* You are in a maze of twisty little callbacks, all alike... */ static void -edit_contact_info_have_book_cb (EBook *book, gpointer user_data) +make_contact_editor_cb (EBook *book, gpointer user_data) { if (book) { EDestination *dest = E_DESTINATION (user_data); @@ -116,7 +116,7 @@ edit_contact_info_cb (GtkWidget *w, gpointer user_data) return; gtk_object_ref (GTK_OBJECT (info->dest)); - e_book_use_local_address_book (edit_contact_info_have_book_cb, (gpointer) info->dest); + e_book_use_local_address_book (make_contact_editor_cb, (gpointer) info->dest); } static void |