From d6034ed7fe206a9f98155305415d66b4f5f92dde Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Thu, 15 Oct 2009 20:34:29 +0200 Subject: Bug #565306 - "Edit Full" in "Add to address book" searches first --- .../gui/contact-editor/e-contact-quick-add.c | 28 ++++++++- addressbook/gui/merging/eab-contact-merging.c | 72 +++++++++++++++++++--- addressbook/gui/merging/eab-contact-merging.h | 4 ++ 3 files changed, 92 insertions(+), 12 deletions(-) (limited to 'addressbook/gui') diff --git a/addressbook/gui/contact-editor/e-contact-quick-add.c b/addressbook/gui/contact-editor/e-contact-quick-add.c index 5288ab009d..6c134192cd 100644 --- a/addressbook/gui/contact-editor/e-contact-quick-add.c +++ b/addressbook/gui/contact-editor/e-contact-quick-add.c @@ -183,26 +183,33 @@ editor_closed_cb (GtkWidget *w, gpointer closure) } static void -ce_have_book (EBook *book, EBookStatus status, gpointer closure) +ce_have_contact (EBook *book, EBookStatus status, EContact *contact, gpointer closure) { QuickAdd *qa = (QuickAdd *) closure; if (status != E_BOOK_ERROR_OK) { if (book) g_object_unref (book); - g_warning ("Couldn't open local address book."); + g_warning ("Failed to find contact, status %d.", status); quick_add_unref (qa); } else { EShell *shell; EABEditor *contact_editor; + if (contact) { + /* use found contact */ + if (qa->contact) + g_object_unref (qa->contact); + qa->contact = g_object_ref (contact); + } + shell = e_shell_get_default (); contact_editor = e_contact_editor_new ( shell, book, qa->contact, TRUE, TRUE /* XXX */); /* mark it as changed so the Save buttons are enabled when we bring up the dialog. */ g_object_set (contact_editor, - "changed", TRUE, + "changed", contact != NULL, NULL); /* We pass this via object data, so that we don't get a dangling pointer referenced if both @@ -224,6 +231,21 @@ ce_have_book (EBook *book, EBookStatus status, gpointer closure) } } +static void +ce_have_book (EBook *book, EBookStatus status, gpointer closure) +{ + QuickAdd *qa = (QuickAdd *) closure; + + if (status != E_BOOK_ERROR_OK) { + if (book) + g_object_unref (book); + g_warning ("Couldn't open local address book."); + quick_add_unref (qa); + } else { + eab_merging_book_find_contact (book, qa->contact, ce_have_contact, qa); + } +} + static void edit_contact (QuickAdd *qa) { diff --git a/addressbook/gui/merging/eab-contact-merging.c b/addressbook/gui/merging/eab-contact-merging.c index 0b280a93ed..6cb1ea99f9 100644 --- a/addressbook/gui/merging/eab-contact-merging.c +++ b/addressbook/gui/merging/eab-contact-merging.c @@ -37,7 +37,8 @@ typedef struct dropdown_data dropdown_data; typedef enum { E_CONTACT_MERGING_ADD, - E_CONTACT_MERGING_COMMIT + E_CONTACT_MERGING_COMMIT, + E_CONTACT_MERGING_FIND } EContactMergingOpType; typedef struct { @@ -50,6 +51,7 @@ typedef struct { GList *avoid; EBookIdCallback id_cb; EBookCallback cb; + EBookContactCallback c_cb; gpointer closure; } EContactMergingLookup; @@ -120,6 +122,19 @@ final_id_cb (EBook *book, EBookStatus status, const gchar *id, gpointer closure) finished_lookup (); } +static void +final_cb_as_id (EBook *book, EBookStatus status, gpointer closure) +{ + EContactMergingLookup *lookup = closure; + + if (lookup->id_cb) + lookup->id_cb (lookup->book, status, lookup->contact ? e_contact_get_const (lookup->contact, E_CONTACT_UID) : NULL, lookup->closure); + + free_lookup (lookup); + + finished_lookup (); +} + static void final_cb (EBook *book, EBookStatus status, gpointer closure) { @@ -134,11 +149,14 @@ final_cb (EBook *book, EBookStatus status, gpointer closure) } static void -doit (EContactMergingLookup *lookup) +doit (EContactMergingLookup *lookup, gboolean force_commit) { - if (lookup->op == E_CONTACT_MERGING_ADD) - e_book_async_add_contact (lookup->book, lookup->contact, final_id_cb, lookup); - else if (lookup->op == E_CONTACT_MERGING_COMMIT) + if (lookup->op == E_CONTACT_MERGING_ADD) { + if (force_commit) + e_book_async_commit_contact (lookup->book, lookup->contact, final_cb_as_id, lookup); + else + e_book_async_add_contact (lookup->book, lookup->contact, final_id_cb, lookup); + } else if (lookup->op == E_CONTACT_MERGING_COMMIT) e_book_async_commit_contact (lookup->book, lookup->contact, final_cb, lookup); } @@ -415,7 +433,7 @@ response (GtkWidget *dialog, gint response, EContactMergingLookup *lookup) switch (response) { case 0: - doit (lookup); + doit (lookup, FALSE); break; case 1: cancelit (lookup); @@ -439,9 +457,22 @@ match_query_callback (EContact *contact, EContact *match, EABContactMatchType ty EContactMergingLookup *lookup = closure; gchar *gladefile; gint flag; + gboolean same_uids; + + if (lookup->op == E_CONTACT_MERGING_FIND) { + if (lookup->c_cb) + lookup->c_cb (lookup->book, E_BOOK_ERROR_OK, (gint) type <= (gint) EAB_CONTACT_MATCH_VAGUE ? NULL : match, lookup->closure); + + free_lookup (lookup); + finished_lookup (); + return; + } + + /* if had same UID, then we are editing old contact, thus force commit change to it */ + same_uids = contact && match && g_str_equal (e_contact_get_const (contact, E_CONTACT_UID), e_contact_get_const (match, E_CONTACT_UID)); - if ((gint) type <= (gint) EAB_CONTACT_MATCH_VAGUE) { - doit (lookup); + if ((gint) type <= (gint) EAB_CONTACT_MATCH_VAGUE || same_uids) { + doit (lookup, same_uids); } else { GladeXML *ui; @@ -467,7 +498,7 @@ match_query_callback (EContact *contact, EContact *match, EABContactMatchType ty ui = glade_xml_new (gladefile, NULL, NULL); g_free (gladefile); } else { - doit (lookup); + doit (lookup, FALSE); return; } @@ -544,6 +575,29 @@ eab_merging_book_commit_contact (EBook *book, return TRUE; } +gboolean +eab_merging_book_find_contact (EBook *book, + EContact *contact, + EBookContactCallback cb, + gpointer closure) +{ + EContactMergingLookup *lookup; + + lookup = g_new (EContactMergingLookup, 1); + + lookup->op = E_CONTACT_MERGING_FIND; + lookup->book = g_object_ref (book); + lookup->contact = g_object_ref (contact); + lookup->c_cb = cb; + lookup->closure = closure; + lookup->avoid = g_list_append (NULL, contact); + lookup->match = NULL; + + add_lookup (lookup); + + return TRUE; +} + GtkWidget * _eab_contact_merging_create_contact_display(gchar *name, gchar *string1, gchar *string2, diff --git a/addressbook/gui/merging/eab-contact-merging.h b/addressbook/gui/merging/eab-contact-merging.h index 81528c6325..70cd825626 100644 --- a/addressbook/gui/merging/eab-contact-merging.h +++ b/addressbook/gui/merging/eab-contact-merging.h @@ -38,6 +38,10 @@ gboolean eab_merging_book_commit_contact (EBook *book, EContact *contact, EBookCallback cb, gpointer closure); +gboolean eab_merging_book_find_contact (EBook *book, + EContact *contact, + EBookContactCallback cb, + gpointer closure); G_END_DECLS -- cgit v1.2.3