]> git.0d.be Git - empathy.git/commitdiff
Confirm closing chat room tabs
authorWill Thompson <will.thompson@collabora.co.uk>
Thu, 13 Aug 2009 23:00:21 +0000 (00:00 +0100)
committerWill Thompson <will.thompson@collabora.co.uk>
Mon, 30 Jan 2012 13:28:00 +0000 (13:28 +0000)
I often accidentally close tabs with Control-W, and more occasionally by
clicking the [X] by mistake. This is okay for 1-1 conversations (I can
just reopen them) but is destructive for chat rooms. So let's make the
user confirm.

https://bugzilla.gnome.org/show_bug.cgi?id=591756

src/empathy-chat-window.c

index 3e197796d9c55e0facbc602929cb1fbc56ffedbb..979139078d0ed7c1f53a8cc8f3ccfec6cf5f5909 100644 (file)
@@ -212,6 +212,63 @@ chat_window_find_chat (EmpathyChat *chat)
        return NULL;
 }
 
+static void
+confirm_close_response_cb (GtkWidget *dialog,
+                           int response,
+                           EmpathyChatWindow *window)
+{
+       EmpathyChat *chat;
+
+       chat = g_object_get_data (G_OBJECT (dialog), "chat");
+
+       gtk_widget_destroy (dialog);
+
+       if (response == GTK_RESPONSE_ACCEPT)
+               empathy_chat_window_remove_chat (window, chat);
+}
+
+static void
+maybe_close_chat (EmpathyChatWindow *window,
+                  EmpathyChat *chat)
+{
+       EmpathyChatWindowPriv *priv;
+
+       priv = GET_PRIV (window);
+
+       if (empathy_chat_is_room (chat)) {
+               gchar *chat_name = empathy_chat_dup_name (chat);
+               GtkWidget *dialog = gtk_message_dialog_new (
+                       GTK_WINDOW (priv->dialog),
+                       GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+                       GTK_MESSAGE_WARNING,
+                       GTK_BUTTONS_CANCEL,
+                       _("Leave %s?"),
+                       chat_name);
+
+               gtk_window_set_title (GTK_WINDOW (dialog), "");
+
+               gtk_message_dialog_format_secondary_text (
+                       GTK_MESSAGE_DIALOG (dialog),
+                       _("You will not receive any further messages from "
+                         "this chat room unless you rejoin."));
+
+               gtk_dialog_add_button (GTK_DIALOG (dialog),
+                       _("Leave chat room"), GTK_RESPONSE_ACCEPT);
+               gtk_dialog_set_default_response (GTK_DIALOG (dialog),
+                       GTK_RESPONSE_ACCEPT);
+
+               g_object_set_data (G_OBJECT (dialog), "chat", chat);
+
+               g_signal_connect (dialog, "response",
+                       G_CALLBACK (confirm_close_response_cb), window);
+
+               gtk_window_present (GTK_WINDOW (dialog));
+               g_free (chat_name);
+       } else {
+               empathy_chat_window_remove_chat (window, chat);
+       }
+}
+
 static void
 chat_window_close_clicked_cb (GtkAction   *action,
                              EmpathyChat *chat)
@@ -219,7 +276,7 @@ chat_window_close_clicked_cb (GtkAction   *action,
        EmpathyChatWindow *window;
 
        window = chat_window_find_chat (chat);
-       empathy_chat_window_remove_chat (window, chat);
+       maybe_close_chat (window, chat);
 }
 
 static void
@@ -1027,7 +1084,7 @@ chat_window_close_activate_cb (GtkAction         *action,
 
        g_return_if_fail (priv->current_chat != NULL);
 
-       empathy_chat_window_remove_chat (window, priv->current_chat);
+       maybe_close_chat (window, priv->current_chat);
 }
 
 static void