[evolution] I#1876 - Contacts: Add a way to create a contact copy
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] I#1876 - Contacts: Add a way to create a contact copy
- Date: Tue, 26 Apr 2022 14:07:46 +0000 (UTC)
commit ec872984ce46a6371809bf4948ea763658445b8f
Author: Milan Crha <mcrha redhat com>
Date: Tue Apr 26 16:06:19 2022 +0200
I#1876 - Contacts: Add a way to create a contact copy
Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/1876
src/addressbook/addressbook.error.xml | 7 +++
.../gui/contact-editor/e-contact-editor.c | 4 +-
.../gui/contact-editor/e-contact-quick-add.c | 2 +-
.../contact-list-editor/e-contact-list-editor.c | 2 +-
.../gui/widgets/e-addressbook-selector.c | 4 +-
.../gui/widgets/e-addressbook-table-adapter.c | 2 +-
src/addressbook/gui/widgets/e-addressbook-view.c | 2 +-
src/addressbook/gui/widgets/eab-contact-merging.c | 52 ++++++++++++++++++++--
src/addressbook/gui/widgets/eab-contact-merging.h | 3 +-
src/addressbook/gui/widgets/eab-gui-util.c | 2 +-
src/modules/vcard-inline/e-mail-part-vcard.c | 2 +-
11 files changed, 68 insertions(+), 14 deletions(-)
---
diff --git a/src/addressbook/addressbook.error.xml b/src/addressbook/addressbook.error.xml
index d9416932ee..4811907483 100644
--- a/src/addressbook/addressbook.error.xml
+++ b/src/addressbook/addressbook.error.xml
@@ -152,4 +152,11 @@
<button _label="Do _Not Unset" response="GTK_RESPONSE_CANCEL"/>
<button _label="_Unset" response="GTK_RESPONSE_ACCEPT"/>
</error>
+
+ <error id="ask-add-existing" type="question" default="GTK_RESPONSE_CANCEL">
+ <_primary>Contact already exists in the address book.</_primary>
+ <_secondary>Contact “{0}” already exists in the address book “{1}”. Do you want to add a copy of it
instead?</_secondary>
+ <button _label="_Cancel" response="GTK_RESPONSE_CANCEL"/>
+ <button _label="_Add Copy" response="GTK_RESPONSE_ACCEPT"/>
+ </error>
</error-list>
diff --git a/src/addressbook/gui/contact-editor/e-contact-editor.c
b/src/addressbook/gui/contact-editor/e-contact-editor.c
index bb6dc4f202..7bda5826da 100644
--- a/src/addressbook/gui/contact-editor/e-contact-editor.c
+++ b/src/addressbook/gui/contact-editor/e-contact-editor.c
@@ -4551,12 +4551,12 @@ real_save_contact (EContactEditor *ce,
/* Two-step move; add to target, then remove from source */
eab_merging_book_add_contact (
registry, ce->priv->target_client,
- ce->priv->contact, contact_added_cb, ecs);
+ ce->priv->contact, contact_added_cb, ecs, FALSE);
} else {
if (ce->priv->is_new_contact)
eab_merging_book_add_contact (
registry, ce->priv->target_client,
- ce->priv->contact, contact_added_cb, ecs);
+ ce->priv->contact, contact_added_cb, ecs, FALSE);
else if (ce->priv->check_merge)
eab_merging_book_modify_contact (
registry, ce->priv->target_client,
diff --git a/src/addressbook/gui/contact-editor/e-contact-quick-add.c
b/src/addressbook/gui/contact-editor/e-contact-quick-add.c
index 33d521200a..d5a3d617a5 100644
--- a/src/addressbook/gui/contact-editor/e-contact-quick-add.c
+++ b/src/addressbook/gui/contact-editor/e-contact-quick-add.c
@@ -155,7 +155,7 @@ merge_cb (GObject *source_object,
eab_merging_book_add_contact (
registry, E_BOOK_CLIENT (client),
- qa->contact, NULL, NULL);
+ qa->contact, NULL, NULL, FALSE);
g_object_unref (registry);
} else {
diff --git a/src/addressbook/gui/contact-list-editor/e-contact-list-editor.c
b/src/addressbook/gui/contact-list-editor/e-contact-list-editor.c
index b8b6808634..9e961e3c96 100644
--- a/src/addressbook/gui/contact-list-editor/e-contact-list-editor.c
+++ b/src/addressbook/gui/contact-list-editor/e-contact-list-editor.c
@@ -1588,7 +1588,7 @@ contact_list_editor_save_contact (EABEditor *eab_editor,
if (priv->is_new_list)
eab_merging_book_add_contact (
registry, priv->book_client, contact,
- contact_list_editor_list_added_cb, ecs);
+ contact_list_editor_list_added_cb, ecs, FALSE);
else
eab_merging_book_modify_contact (
registry, priv->book_client, contact,
diff --git a/src/addressbook/gui/widgets/e-addressbook-selector.c
b/src/addressbook/gui/widgets/e-addressbook-selector.c
index 8879fa01df..425e0fb07c 100644
--- a/src/addressbook/gui/widgets/e-addressbook-selector.c
+++ b/src/addressbook/gui/widgets/e-addressbook-selector.c
@@ -166,7 +166,7 @@ addressbook_selector_merge_next_cb (EBookClient *book_client,
merge_context->registry,
merge_context->target_client,
merge_context->current_contact,
- addressbook_selector_merge_next_cb, merge_context);
+ addressbook_selector_merge_next_cb, merge_context, FALSE);
} else if (merge_context->pending_removals == 0) {
merge_context_free (merge_context);
@@ -278,7 +278,7 @@ target_client_connect_cb (GObject *source_object,
merge_context->registry,
merge_context->target_client,
merge_context->current_contact,
- addressbook_selector_merge_next_cb, merge_context);
+ addressbook_selector_merge_next_cb, merge_context, FALSE);
}
static gboolean
diff --git a/src/addressbook/gui/widgets/e-addressbook-table-adapter.c
b/src/addressbook/gui/widgets/e-addressbook-table-adapter.c
index 3a953fa101..d7b94a620e 100644
--- a/src/addressbook/gui/widgets/e-addressbook-table-adapter.c
+++ b/src/addressbook/gui/widgets/e-addressbook-table-adapter.c
@@ -137,7 +137,7 @@ addressbook_append_row (ETableModel *etm,
registry = e_client_cache_ref_registry (client_cache);
eab_merging_book_add_contact (
- registry, book_client, contact, NULL, NULL);
+ registry, book_client, contact, NULL, NULL, FALSE);
g_object_unref (registry);
diff --git a/src/addressbook/gui/widgets/e-addressbook-view.c
b/src/addressbook/gui/widgets/e-addressbook-view.c
index dbf69ce0b6..c02d057132 100644
--- a/src/addressbook/gui/widgets/e-addressbook-view.c
+++ b/src/addressbook/gui/widgets/e-addressbook-view.c
@@ -856,7 +856,7 @@ addressbook_view_paste_clipboard (ESelectable *selectable)
EContact *contact = iter->data;
eab_merging_book_add_contact (
- registry, book_client, contact, NULL, NULL);
+ registry, book_client, contact, NULL, NULL, TRUE);
}
g_object_unref (registry);
diff --git a/src/addressbook/gui/widgets/eab-contact-merging.c
b/src/addressbook/gui/widgets/eab-contact-merging.c
index 49ee00382b..5b72067125 100644
--- a/src/addressbook/gui/widgets/eab-contact-merging.c
+++ b/src/addressbook/gui/widgets/eab-contact-merging.c
@@ -83,6 +83,8 @@ typedef struct {
gpointer closure;
MergeDialogData *merge_dialog_data;
+
+ gboolean can_add_copy;
} EContactMergingLookup;
typedef struct _dropdown_data {
@@ -239,6 +241,31 @@ final_cb (EBookClient *book_client,
finished_lookup ();
}
+static gboolean
+ask_should_add (EContactMergingLookup *lookup)
+{
+ ESource *source;
+ gchar *contact_info;
+ gint response;
+
+ source = e_client_get_source (E_CLIENT (lookup->book_client));
+
+ contact_info = e_contact_get (lookup->contact, E_CONTACT_FILE_AS);
+ if (!contact_info || !*contact_info) {
+ g_free (contact_info);
+ contact_info = e_contact_get (lookup->contact, E_CONTACT_FULL_NAME);
+ }
+
+ response = e_alert_run_dialog_for_args (NULL,
+ "addressbook:ask-add-existing",
+ contact_info && *contact_info ? contact_info : _("Unnamed"),
+ e_source_get_display_name (source), NULL);
+
+ g_free (contact_info);
+
+ return response == GTK_RESPONSE_ACCEPT;
+}
+
static void
modify_contact_ready_cb (GObject *source_object,
GAsyncResult *result,
@@ -277,7 +304,24 @@ add_contact_ready_cb (GObject *source_object,
e_book_client_add_contact_finish (book_client, result, &uid, &error);
- final_id_cb (book_client, error, uid, lookup);
+ if (lookup->can_add_copy && g_error_matches (error, E_BOOK_CLIENT_ERROR,
E_BOOK_CLIENT_ERROR_CONTACT_ID_ALREADY_EXISTS)) {
+ lookup->can_add_copy = FALSE;
+
+ if (ask_should_add (lookup)) {
+ gchar *new_uid;
+
+ new_uid = e_util_generate_uid ();
+ e_contact_set (lookup->contact, E_CONTACT_UID, new_uid);
+ g_free (new_uid);
+
+ e_book_client_add_contact (lookup->book_client, lookup->contact,
E_BOOK_OPERATION_FLAG_NONE, NULL, add_contact_ready_cb, lookup);
+ } else {
+ g_clear_error (&error);
+ final_id_cb (book_client, error, uid, lookup);
+ }
+ } else {
+ final_id_cb (book_client, error, uid, lookup);
+ }
if (error != NULL)
g_error_free (error);
@@ -972,7 +1016,7 @@ match_query_callback (EContact *contact,
&& 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 || same_uids) {
- doit (lookup, same_uids);
+ doit (lookup, same_uids && !lookup->can_add_copy);
} else {
GtkWidget *dialog;
@@ -1001,7 +1045,8 @@ eab_merging_book_add_contact (ESourceRegistry *registry,
EBookClient *book_client,
EContact *contact,
EABMergingIdAsyncCallback cb,
- gpointer closure)
+ gpointer closure,
+ gboolean can_add_copy)
{
EContactMergingLookup *lookup;
@@ -1017,6 +1062,7 @@ eab_merging_book_add_contact (ESourceRegistry *registry,
lookup->closure = closure;
lookup->avoid = NULL;
lookup->match = NULL;
+ lookup->can_add_copy = TRUE;
add_lookup (lookup);
diff --git a/src/addressbook/gui/widgets/eab-contact-merging.h
b/src/addressbook/gui/widgets/eab-contact-merging.h
index 4dcf14bf14..103e84b96d 100644
--- a/src/addressbook/gui/widgets/eab-contact-merging.h
+++ b/src/addressbook/gui/widgets/eab-contact-merging.h
@@ -46,7 +46,8 @@ gboolean eab_merging_book_add_contact (ESourceRegistry *registry,
EBookClient *book_client,
EContact *contact,
EABMergingIdAsyncCallback cb,
- gpointer closure);
+ gpointer closure,
+ gboolean can_add_copy);
gboolean eab_merging_book_modify_contact (ESourceRegistry *registry,
EBookClient *book_client,
diff --git a/src/addressbook/gui/widgets/eab-gui-util.c b/src/addressbook/gui/widgets/eab-gui-util.c
index 11397a9915..f92bcf0c36 100644
--- a/src/addressbook/gui/widgets/eab-gui-util.c
+++ b/src/addressbook/gui/widgets/eab-gui-util.c
@@ -524,7 +524,7 @@ do_copy (gpointer data,
process->count++;
eab_merging_book_add_contact (
process->registry, book_client,
- contact, contact_added_cb, process);
+ contact, contact_added_cb, process, TRUE);
}
static void
diff --git a/src/modules/vcard-inline/e-mail-part-vcard.c b/src/modules/vcard-inline/e-mail-part-vcard.c
index cf3ad36f1b..5fea20451a 100644
--- a/src/modules/vcard-inline/e-mail-part-vcard.c
+++ b/src/modules/vcard-inline/e-mail-part-vcard.c
@@ -76,7 +76,7 @@ client_connect_cb (GObject *source_object,
contact = E_CONTACT (iter->data);
eab_merging_book_add_contact (
- registry, book_client, contact, NULL, NULL);
+ registry, book_client, contact, NULL, NULL, FALSE);
}
g_object_unref (client);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]