[empathy: 14/35] Add a confirmation dialog when you block a contact from the Contact menu



commit 8e95ee8c1455390b18126d2280bcd218777379a8
Author: Danielle Madeley <danielle madeley collabora co uk>
Date:   Thu Feb 10 13:19:35 2011 +1100

    Add a confirmation dialog when you block a contact from the Contact menu

 libempathy-gtk/empathy-contact-menu.c |   43 ++++++++++++++++++++++++++++++++-
 src/empathy-chat-window.c             |    7 ++++-
 2 files changed, 47 insertions(+), 3 deletions(-)
---
diff --git a/libempathy-gtk/empathy-contact-menu.c b/libempathy-gtk/empathy-contact-menu.c
index 03e0db3..e03444a 100644
--- a/libempathy-gtk/empathy-contact-menu.c
+++ b/libempathy-gtk/empathy-contact-menu.c
@@ -232,15 +232,57 @@ static void
 empathy_contact_block_menu_item_toggled (GtkCheckMenuItem *item,
 					 EmpathyContact   *contact)
 {
+	static guint block_signal = 0;
 	EmpathyContactManager *manager;
 	gboolean blocked;
 
+	if (block_signal > 0)
+		return;
+
 	manager = empathy_contact_manager_dup_singleton ();
 	blocked = gtk_check_menu_item_get_active (item);
 
+	if (blocked) {
+		/* confirm the user really wishes to block the contact */
+		int res;
+		GtkWidget *parent, *dialog;
+
+		/* gtk_menu_get_attach_widget() doesn't behave properly here
+		 * for some reason */
+		parent = g_object_get_data (
+			G_OBJECT (gtk_widget_get_parent (GTK_WIDGET (item))),
+			"window");
+		dialog = gtk_message_dialog_new (GTK_WINDOW (parent),
+				GTK_DIALOG_MODAL,
+				GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
+				_("Block %s?"),
+				empathy_contact_get_id (contact));
+
+		gtk_message_dialog_format_secondary_text (
+			GTK_MESSAGE_DIALOG (dialog),
+			_("Are you sure you want to block the contact %s?"),
+			empathy_contact_get_id (contact));
+		gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+				GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+				_("Block"), GTK_RESPONSE_REJECT,
+				NULL);
+
+		res = gtk_dialog_run (GTK_DIALOG (dialog));
+		gtk_widget_destroy (dialog);
+
+		if (res != GTK_RESPONSE_REJECT)
+			goto finally;
+	}
+
 	empathy_contact_list_set_blocked (EMPATHY_CONTACT_LIST (manager),
 					  contact, blocked);
 
+	/* update the toggle with the blocked status */
+	block_signal++;
+	gtk_check_menu_item_set_active (item, blocked);
+	block_signal--;
+
+finally:
 	g_object_unref (manager);
 }
 
@@ -270,7 +312,6 @@ empathy_contact_block_menu_item_new (EmpathyContact *contact)
 	}
 
 	item = gtk_check_menu_item_new_with_mnemonic (_("_Block Contact"));
-	/* FIXME: this doesn't always get updated immediately */
 	blocked = empathy_contact_list_get_blocked (
 			EMPATHY_CONTACT_LIST (manager),
 			contact);
diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c
index 799a825..73856ad 100644
--- a/src/empathy-chat-window.c
+++ b/src/empathy-chat-window.c
@@ -417,12 +417,15 @@ chat_window_contact_menu_update (EmpathyChatWindowPriv *priv,
 
 	if (orig_submenu == NULL || !gtk_widget_get_visible (orig_submenu)) {
 		submenu = empathy_chat_get_contact_menu (priv->current_chat);
+
+		/* gtk_menu_attach_to_widget() doesn't behave nicely here */
+		g_object_set_data (G_OBJECT (submenu), "window", priv->dialog);
+
 		if (submenu != NULL) {
 			gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu), submenu);
 			gtk_widget_show (menu);
 			gtk_widget_set_sensitive (menu, TRUE);
-		}
-		else {
+		} else {
 			gtk_widget_set_sensitive (menu, FALSE);
 		}
 	} else {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]