aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2009-10-16 02:34:29 +0800
committerMilan Crha <mcrha@redhat.com>2009-10-16 02:34:29 +0800
commitd6034ed7fe206a9f98155305415d66b4f5f92dde (patch)
tree69c24e54e60cf48ffcdc365a092b71207723cfb9 /addressbook
parent75887d8cde2c3d372fc402623fd7b1ee14526c5a (diff)
downloadgsoc2013-evolution-d6034ed7fe206a9f98155305415d66b4f5f92dde.tar
gsoc2013-evolution-d6034ed7fe206a9f98155305415d66b4f5f92dde.tar.gz
gsoc2013-evolution-d6034ed7fe206a9f98155305415d66b4f5f92dde.tar.bz2
gsoc2013-evolution-d6034ed7fe206a9f98155305415d66b4f5f92dde.tar.lz
gsoc2013-evolution-d6034ed7fe206a9f98155305415d66b4f5f92dde.tar.xz
gsoc2013-evolution-d6034ed7fe206a9f98155305415d66b4f5f92dde.tar.zst
gsoc2013-evolution-d6034ed7fe206a9f98155305415d66b4f5f92dde.zip
Bug #565306 - "Edit Full" in "Add to address book" searches first
Diffstat (limited to 'addressbook')
-rw-r--r--addressbook/gui/contact-editor/e-contact-quick-add.c28
-rw-r--r--addressbook/gui/merging/eab-contact-merging.c72
-rw-r--r--addressbook/gui/merging/eab-contact-merging.h4
3 files changed, 92 insertions, 12 deletions
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
@@ -225,6 +232,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)
{
addressbook_load (qa->book, ce_have_book, 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;
@@ -121,6 +123,19 @@ final_id_cb (EBook *book, EBookStatus status, const gchar *id, gpointer closure)
}
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)
{
EContactMergingLookup *lookup = 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