I#1876 - Contacts: Add a way to create a contact copy

Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/1876
This commit is contained in:
Milan Crha
2022-04-26 16:06:19 +02:00
parent ac987d7c47
commit ec872984ce
11 changed files with 68 additions and 14 deletions

View File

@ -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>

View File

@ -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,

View File

@ -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 {

View File

@ -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,

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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,

View File

@ -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

View File

@ -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);