From 90f956ad4a0d7622bc9798893d53dbff8bb942bd Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Fri, 24 Jan 2014 14:13:09 +0100 Subject: Bug #707121 - Merge contacts dialogs indefinitely expands by itself --- addressbook/gui/widgets/Makefile.am | 7 +- .../eab-contact-commit-duplicate-detected.ui | 185 ---------------- .../gui/widgets/eab-contact-duplicate-detected.ui | 219 ------------------ addressbook/gui/widgets/eab-contact-merging.c | 246 ++++++++++++++++----- 4 files changed, 196 insertions(+), 461 deletions(-) delete mode 100644 addressbook/gui/widgets/eab-contact-commit-duplicate-detected.ui delete mode 100644 addressbook/gui/widgets/eab-contact-duplicate-detected.ui (limited to 'addressbook/gui') diff --git a/addressbook/gui/widgets/Makefile.am b/addressbook/gui/widgets/Makefile.am index 79ab1fb2f4..bfebe2125c 100644 --- a/addressbook/gui/widgets/Makefile.am +++ b/addressbook/gui/widgets/Makefile.am @@ -87,13 +87,8 @@ dist-hook: etspec_DATA= e-addressbook-view.etspec -ui_DATA = \ - eab-contact-duplicate-detected.ui \ - eab-contact-commit-duplicate-detected.ui - EXTRA_DIST = \ $(etspec_DATA) \ - $(rule_DATA) \ - $(ui_DATA) + $(rule_DATA) -include $(top_srcdir)/git.mk diff --git a/addressbook/gui/widgets/eab-contact-commit-duplicate-detected.ui b/addressbook/gui/widgets/eab-contact-commit-duplicate-detected.ui deleted file mode 100644 index 04ed728a56..0000000000 --- a/addressbook/gui/widgets/eab-contact-commit-duplicate-detected.ui +++ /dev/null @@ -1,185 +0,0 @@ - - - - - 6 - True - Duplicate Contact Detected - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_CENTER_ON_PARENT - False - True - False - - - True - False - 6 - - - True - GTK_BUTTONBOX_END - - - True - True - True - gtk-cancel - True - GTK_RELIEF_NORMAL - - - - - True - True - True - gtk-save - True - GTK_RELIEF_NORMAL - - - - - 0 - False - True - GTK_PACK_END - - - - - 6 - True - 5 - 2 - False - 6 - 6 - - - True - - - 1 - 2 - 4 - 5 - - - - - True - The name or email of this contact already exists in this folder. Would you like to save the changes anyway? - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - - - 1 - 2 - 0 - 1 - fill - - - - - True - Conflicting Contact: - False - False - GTK_JUSTIFY_CENTER - False - False - 0 - 0.5 - 0 - 0 - - - 1 - 2 - 3 - 4 - fill - - - - - True - Changed Contact: - False - False - GTK_JUSTIFY_CENTER - False - False - 0 - 0.5 - 0 - 0 - - - 1 - 2 - 1 - 2 - fill - - - - - - True - - - 1 - 2 - 2 - 3 - - - - - True - 0.5 - 0 - 1 - 0 - - - True - avatar-default - - - - - 0 - 1 - 0 - 5 - fill - fill - - - - - 0 - True - True - - - - - - button3 - button4 - - - diff --git a/addressbook/gui/widgets/eab-contact-duplicate-detected.ui b/addressbook/gui/widgets/eab-contact-duplicate-detected.ui deleted file mode 100644 index 124b9c2787..0000000000 --- a/addressbook/gui/widgets/eab-contact-duplicate-detected.ui +++ /dev/null @@ -1,219 +0,0 @@ - - - - - True - Duplicate Contact Detected - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - True - False - True - False - False - GDK_WINDOW_TYPE_HINT_DIALOG - GDK_GRAVITY_NORTH_WEST - 400 - 500 - - - True - False - 0 - - - True - GTK_BUTTONBOX_END - - - True - True - True - gtk-cancel - True - GTK_RELIEF_NORMAL - True - - - - - True - True - True - gtk-add - True - GTK_RELIEF_NORMAL - True - - - - - True - True - True - _Merge - True - GTK_RELIEF_NORMAL - True - - - - - 0 - False - True - GTK_PACK_END - - - - - True - True - GTK_POLICY_NEVER - GTK_POLICY_AUTOMATIC - GTK_SHADOW_IN - GTK_CORNER_TOP_LEFT - - - - - 12 - True - 5 - 2 - False - 6 - 12 - - - True - - - 1 - 2 - 4 - 5 - - - - - True - The name or email address of this contact already exists -in this folder. Would you like to add it anyway? - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - - - 1 - 2 - 0 - 1 - fill - - - - - True - Original Contact: - False - False - GTK_JUSTIFY_CENTER - False - False - 0 - 0.5 - 0 - 0 - - - 1 - 2 - 3 - 4 - fill - - - - - True - New Contact: - False - False - GTK_JUSTIFY_CENTER - False - False - 0 - 0.5 - 0 - 0 - - - 1 - 2 - 1 - 2 - fill - - - - - - True - - - 1 - 2 - 2 - 3 - - - - - True - 0.5 - 0 - 1 - 0 - 0 - 0 - 0 - 0 - - - True - avatar-default - - - - - 0 - 1 - 0 - 5 - fill - fill - - - - - - - - - - - - button4 - button3 - button5 - - - diff --git a/addressbook/gui/widgets/eab-contact-merging.c b/addressbook/gui/widgets/eab-contact-merging.c index 0a0903d5b3..05bc69665f 100644 --- a/addressbook/gui/widgets/eab-contact-merging.c +++ b/addressbook/gui/widgets/eab-contact-merging.c @@ -597,28 +597,210 @@ check_if_same (EContact *contact, return res; } +static GtkWidget * +create_iconic_button (const gchar *label, + const gchar *icon_name) +{ + GtkWidget *button, *image; + + button = gtk_button_new_with_mnemonic (label); + + if (icon_name) { + image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON); + gtk_button_set_image (GTK_BUTTON (button), image); + } + + return button; +} + +static GtkWidget * +create_duplicate_contact_detected_dialog (EContact *old_contact, + EContact *new_contact, + gboolean disable_merge, + gboolean is_for_commit) +{ + GtkWidget *widget, *scrolled; + GtkContainer *container; + GtkDialog *dialog; + const gchar *text; + + widget = gtk_dialog_new (); + dialog = GTK_DIALOG (widget); + + g_object_set (G_OBJECT (dialog), + "title", _("Duplicate Contact Detected"), + "default-width", 500, + "default-height", 400, + NULL); + + gtk_dialog_add_action_widget (dialog, create_iconic_button (_("_Cancel"), GTK_STOCK_CANCEL), GTK_RESPONSE_CANCEL); + + if (is_for_commit) { + gtk_dialog_add_action_widget (dialog, create_iconic_button (_("_Save"), "document-save"), GTK_RESPONSE_OK); + } else { + gtk_dialog_add_action_widget (dialog, create_iconic_button (_("_Add"), "list-add"), GTK_RESPONSE_OK); + gtk_dialog_add_action_widget (dialog, create_iconic_button (_("_Merge"), NULL), GTK_RESPONSE_APPLY); + } + + if (disable_merge) + gtk_dialog_set_response_sensitive (dialog, GTK_RESPONSE_APPLY, FALSE); + + container = GTK_CONTAINER (gtk_dialog_get_content_area (dialog)); + + widget = gtk_grid_new (); + g_object_set (G_OBJECT (widget), + "orientation", GTK_ORIENTATION_HORIZONTAL, + "hexpand", TRUE, + "halign", GTK_ALIGN_FILL, + "vexpand", TRUE, + "valign", GTK_ALIGN_FILL, + "margin", 12, + NULL); + + gtk_container_add (container, widget); + container = GTK_CONTAINER (widget); + + widget = gtk_image_new_from_icon_name ("avatar-default", GTK_ICON_SIZE_BUTTON); + g_object_set (G_OBJECT (widget), + "hexpand", FALSE, + "halign", GTK_ALIGN_START, + "vexpand", FALSE, + "valign", GTK_ALIGN_START, + "margin-right", 12, + NULL); + gtk_container_add (container, widget); + + widget = gtk_grid_new (); + g_object_set (G_OBJECT (widget), + "orientation", GTK_ORIENTATION_VERTICAL, + "hexpand", TRUE, + "halign", GTK_ALIGN_FILL, + "vexpand", TRUE, + "valign", GTK_ALIGN_FILL, + NULL); + + gtk_container_add (container, widget); + container = GTK_CONTAINER (widget); + + if (is_for_commit) + text = _("The name or email address of this contact already exists\n" + "in this folder. Would you like to save the changes anyway?"); + else + text = _("The name or email address of this contact already exists\n" + "in this folder. Would you like to add it anyway?"); + + widget = gtk_label_new (text); + g_object_set (G_OBJECT (widget), + "hexpand", FALSE, + "halign", GTK_ALIGN_START, + "vexpand", FALSE, + "valign", GTK_ALIGN_START, + "margin-bottom", 6, + NULL); + gtk_container_add (container, widget); + + if (is_for_commit) + text = _("Changed Contact:"); + else + text = _("New Contact:"); + + widget = gtk_label_new (text); + g_object_set (G_OBJECT (widget), + "hexpand", FALSE, + "halign", GTK_ALIGN_START, + "vexpand", FALSE, + "valign", GTK_ALIGN_START, + "margin-bottom", 6, + NULL); + gtk_container_add (container, widget); + + scrolled = gtk_scrolled_window_new (NULL, NULL); + g_object_set (G_OBJECT (scrolled), + "hexpand", TRUE, + "halign", GTK_ALIGN_FILL, + "hscrollbar-policy", GTK_POLICY_AUTOMATIC, + "vexpand", TRUE, + "valign", GTK_ALIGN_FILL, + "vscrollbar-policy", GTK_POLICY_AUTOMATIC, + "margin-bottom", 6, + NULL); + gtk_container_add (container, scrolled); + + widget = eab_contact_display_new (); + g_object_set (G_OBJECT (widget), + "hexpand", TRUE, + "halign", GTK_ALIGN_FILL, + "vexpand", TRUE, + "valign", GTK_ALIGN_FILL, + "contact", new_contact, + "mode", EAB_CONTACT_DISPLAY_RENDER_COMPACT, + NULL); + gtk_container_add (GTK_CONTAINER (scrolled), widget); + + if (is_for_commit) + text = _("Conflicting Contact:"); + else + text = _("Old Contact:"); + + widget = gtk_label_new (text); + g_object_set (G_OBJECT (widget), + "hexpand", FALSE, + "halign", GTK_ALIGN_START, + "vexpand", FALSE, + "valign", GTK_ALIGN_START, + "margin-bottom", 6, + NULL); + gtk_container_add (container, widget); + + scrolled = gtk_scrolled_window_new (NULL, NULL); + g_object_set (G_OBJECT (scrolled), + "hexpand", TRUE, + "halign", GTK_ALIGN_FILL, + "hscrollbar-policy", GTK_POLICY_AUTOMATIC, + "vexpand", TRUE, + "valign", GTK_ALIGN_FILL, + "vscrollbar-policy", GTK_POLICY_AUTOMATIC, + NULL); + gtk_container_add (container, scrolled); + + widget = eab_contact_display_new (); + g_object_set (G_OBJECT (widget), + "hexpand", TRUE, + "halign", GTK_ALIGN_FILL, + "vexpand", TRUE, + "valign", GTK_ALIGN_FILL, + "contact", old_contact, + "mode", EAB_CONTACT_DISPLAY_RENDER_COMPACT, + NULL); + gtk_container_add (GTK_CONTAINER (scrolled), widget); + + gtk_widget_show_all (gtk_dialog_get_content_area (dialog)); + + return GTK_WIDGET (dialog); +} + static void response (GtkWidget *dialog, gint response, EContactMergingLookup *lookup) { - static gint merge_response; - switch (response) { - case 0: + case GTK_RESPONSE_OK: doit (lookup, FALSE); break; - case 1: + case GTK_RESPONSE_CANCEL: cancelit (lookup); break; - case 2: - merge_response = mergeit (lookup); - if (merge_response) + case GTK_RESPONSE_APPLY: + if (mergeit (lookup)) break; return; case GTK_RESPONSE_DELETE_EVENT: cancelit (lookup); break; + default: + g_warn_if_reached (); + break; } gtk_widget_destroy (dialog); @@ -631,7 +813,7 @@ match_query_callback (EContact *contact, gpointer closure) { EContactMergingLookup *lookup = closure; - gint flag; + gboolean flag; gboolean same_uids; if (lookup->op == E_CONTACT_MERGING_FIND) { @@ -656,63 +838,25 @@ match_query_callback (EContact *contact, if ((gint) type <= (gint) EAB_CONTACT_MATCH_VAGUE || same_uids) { doit (lookup, same_uids); } else { - GtkBuilder *builder; - GtkWidget *container; - GtkWidget *merge_button; - GtkWidget *widget; - - builder = gtk_builder_new (); + GtkWidget *dialog; lookup->match = g_object_ref (match); if (lookup->op == E_CONTACT_MERGING_ADD) { /* Compares all the values of contacts and return true, if they match */ flag = check_if_same (contact, match); - e_load_ui_builder_definition ( - builder, "eab-contact-duplicate-detected.ui"); - merge_button = e_builder_get_widget (builder, "button5"); - /* Merge Button not sensitive when all values are same */ - if (flag) - gtk_widget_set_sensitive (GTK_WIDGET (merge_button), FALSE); + dialog = create_duplicate_contact_detected_dialog (match, contact, flag, FALSE); } else if (lookup->op == E_CONTACT_MERGING_COMMIT) { - e_load_ui_builder_definition ( - builder, "eab-contact-commit-duplicate-detected.ui"); + dialog = create_duplicate_contact_detected_dialog (match, contact, FALSE, TRUE); } else { doit (lookup, FALSE); - g_object_unref (builder); return; } - widget = e_builder_get_widget (builder, "custom-old-contact"); - eab_contact_display_set_mode ( - EAB_CONTACT_DISPLAY (widget), - EAB_CONTACT_DISPLAY_RENDER_COMPACT); - eab_contact_display_set_contact ( - EAB_CONTACT_DISPLAY (widget), match); - - widget = e_builder_get_widget (builder, "custom-new-contact"); - eab_contact_display_set_mode ( - EAB_CONTACT_DISPLAY (widget), - EAB_CONTACT_DISPLAY_RENDER_COMPACT); - eab_contact_display_set_contact ( - EAB_CONTACT_DISPLAY (widget), contact); - - widget = e_builder_get_widget (builder, "dialog-duplicate-contact"); - - gtk_widget_ensure_style (widget); - - container = gtk_dialog_get_action_area (GTK_DIALOG (widget)); - gtk_container_set_border_width (GTK_CONTAINER (container), 12); - - container = gtk_dialog_get_content_area (GTK_DIALOG (widget)); - gtk_container_set_border_width (GTK_CONTAINER (container), 0); - g_signal_connect ( - widget, "response", + dialog, "response", G_CALLBACK (response), lookup); - gtk_widget_show_all (widget); - - g_object_unref (builder); + gtk_widget_show_all (dialog); } } -- cgit v1.2.3