Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2004:
[Freeciv-Dev] (PR#10899) quit confirmation
Home

[Freeciv-Dev] (PR#10899) quit confirmation

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: chrisk@xxxxxxxxx
Subject: [Freeciv-Dev] (PR#10899) quit confirmation
From: "Vasco Alexandre da Silva Costa" <vasc@xxxxxxxxxxxxxx>
Date: Sun, 7 Nov 2004 15:54:40 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=10899 >

> [vasc - Sun Nov 07 23:50:34 2004]:
> 
> > [chrisk - Fri Nov 05 21:12:27 2004]:
> > 
> > 
> > CVS 05 NOV 2004 S2 GTK2
> > 
> > On leaving or quitting civclient via menu you are presented a
confirmation
> > dialog. On leaving it with the window close button (the X) you are not.
> > 
> > It may be debatable whether there should be such a thing or not. At
> least it
> > cost me half an hour of game 'work' today.
> 
> Here's the patch. I'm a sucker for consistency.

Oops, the last patch had some noise. Here's a brand spanking new one.

Index: client/gui-gtk-2.0/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gui_main.c,v
retrieving revision 1.88
diff -u -r1.88 gui_main.c
--- client/gui-gtk-2.0/gui_main.c       7 Nov 2004 06:30:29 -0000       1.88
+++ client/gui-gtk-2.0/gui_main.c       7 Nov 2004 23:53:27 -0000
@@ -181,6 +181,7 @@
                                            gpointer data);
 static gint timer_callback(gpointer data);
 gboolean show_conn_popup(GtkWidget *view, GdkEventButton *ev, gpointer data);
+static gboolean quit_dialog_callback(void);
 
 /**************************************************************************
 ...
@@ -1052,7 +1053,8 @@
   
   gtk_window_set_title(GTK_WINDOW (toplevel), _("Freeciv"));
 
-  g_signal_connect(toplevel, "delete_event", G_CALLBACK(gtk_main_quit), NULL);
+  g_signal_connect(toplevel, "delete_event",
+      G_CALLBACK(quit_dialog_callback), NULL);
 
   /* Disable GTK+ cursor key focus movement */
   sig = g_signal_lookup("focus", GTK_TYPE_WIDGET);
@@ -1443,3 +1445,53 @@
   gtk_input_remove(input_id);
   gdk_window_set_cursor(root_window, NULL);
 }
+
+/****************************************************************
+  This is the response callback for the dialog with the message:
+  Are you sure you want to quit?
+****************************************************************/
+static void quit_dialog_response(GtkWidget *dialog, gint response)
+{
+  gtk_widget_destroy(dialog);
+  if (response == GTK_RESPONSE_YES) {
+    exit(EXIT_SUCCESS);
+  }
+}
+
+/****************************************************************
+  Popups the dialog with the message:
+  Are you sure you want to quit?
+****************************************************************/
+void popup_quit_dialog(void)
+{
+  static GtkWidget *dialog;
+
+  if (!dialog) {
+    dialog = gtk_message_dialog_new(NULL,
+       0,
+       GTK_MESSAGE_WARNING,
+       GTK_BUTTONS_YES_NO,
+       _("Are you sure you want to quit?"));
+    setup_dialog(dialog, toplevel);
+
+    gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_MOUSE);
+
+    g_signal_connect(dialog, "response", 
+       G_CALLBACK(quit_dialog_response), NULL);
+    g_signal_connect(dialog, "destroy",
+       G_CALLBACK(gtk_widget_destroyed), &dialog);
+  }
+
+  gtk_window_present(GTK_WINDOW(dialog));
+}
+
+/****************************************************************
+  Popups the quit dialog.
+****************************************************************/
+static gboolean quit_dialog_callback(void)
+{
+  popup_quit_dialog();
+  /* Stop emission of event. */
+  return TRUE;
+}
+
Index: client/gui-gtk-2.0/gui_main.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gui_main.h,v
retrieving revision 1.16
diff -u -r1.16 gui_main.h
--- client/gui-gtk-2.0/gui_main.h       31 Oct 2004 20:45:54 -0000      1.16
+++ client/gui-gtk-2.0/gui_main.h       7 Nov 2004 23:53:28 -0000
@@ -95,5 +95,6 @@
 gboolean show_conn_popup(GtkWidget *view, GdkEventButton *ev, gpointer data);
 
 void reset_unit_table(void);
+void popup_quit_dialog(void);
 
 #endif  /* FC__GUI_MAIN_H */
Index: client/gui-gtk-2.0/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/menu.c,v
retrieving revision 1.49
diff -u -r1.49 menu.c
--- client/gui-gtk-2.0/menu.c   31 Oct 2004 20:45:54 -0000      1.49
+++ client/gui-gtk-2.0/menu.c   7 Nov 2004 23:53:31 -0000
@@ -41,6 +41,7 @@
 #include "finddlg.h"
 #include "gotodlg.h"
 #include "graphics.h"
+#include "gui_main.h"
 #include "gui_stuff.h"
 #include "helpdlg.h"
 #include "mapctrl.h"   /* center_on_unit */
@@ -188,22 +189,10 @@
 }
 
 /****************************************************************
-  This is the response callback for the dialog with the message:
-  Are you sure you want to quit?
-****************************************************************/
-static void quit_client_response(GtkWidget* dialog, gint response)
-{
-  gtk_widget_destroy(dialog);
-  if (response == GTK_RESPONSE_OK) {
-    exit(EXIT_SUCCESS);
-  }
-}
-
-/****************************************************************
-...
-*****************************************************************/
+  ...
+ *****************************************************************/
 static void game_menu_callback(gpointer callback_data,
-                              guint callback_action, GtkWidget *widget)
+    guint callback_action, GtkWidget *widget)
 {
   switch(callback_action) {
   case MENU_GAME_OPTIONS:
@@ -236,30 +225,20 @@
   case MENU_GAME_LEAVE:
     if (is_server_running()) {
       GtkWidget* dialog = gtk_message_dialog_new(NULL,
-                             0,
-                            GTK_MESSAGE_WARNING,
-                            GTK_BUTTONS_OK_CANCEL,
-                            _("Leaving a local game will end it!"));
+         0,
+         GTK_MESSAGE_WARNING,
+         GTK_BUTTONS_OK_CANCEL,
+         _("Leaving a local game will end it!"));
       gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_MOUSE);
       g_signal_connect(dialog, "response", 
-                        G_CALLBACK(leave_local_game_response), NULL);
+         G_CALLBACK(leave_local_game_response), NULL);
       gtk_widget_show_all(dialog);
     } else {
       disconnect_from_server();
     }
     break;
   case MENU_GAME_QUIT:
-    {
-      GtkWidget* dialog = gtk_message_dialog_new(NULL,
-         0,
-         GTK_MESSAGE_WARNING,
-         GTK_BUTTONS_OK_CANCEL,
-         _("Are you sure you want to quit?"));
-      gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_MOUSE);
-      g_signal_connect(dialog, "response", 
-         G_CALLBACK(quit_client_response), NULL);
-      gtk_widget_show_all(dialog);
-    }
+    popup_quit_dialog();
     break;
   }
 }

[Prev in Thread] Current Thread [Next in Thread]