Author: cazfi
Date: Mon Nov  2 20:02:11 2015
New Revision: 30375

URL: http://svn.gna.org/viewcvs/freeciv?rev=30375&view=rev
Log:
When client options are saved when it exits, write message about it to a log 
instead of the
already closed or immediately closing output window.

Reported by Jacob Nevins <jtn>

See bug #23969

Modified:
    branches/S2_6/client/client_main.c
    branches/S2_6/client/clinet.c
    branches/S2_6/client/gui-gtk-2.0/menu.c
    branches/S2_6/client/gui-gtk-2.0/optiondlg.c
    branches/S2_6/client/gui-gtk-3.0/menu.c
    branches/S2_6/client/gui-gtk-3.0/optiondlg.c
    branches/S2_6/client/gui-qt/menu.cpp
    branches/S2_6/client/gui-qt/optiondlg.cpp
    branches/S2_6/client/gui-sdl/optiondlg.c
    branches/S2_6/client/gui-sdl2/optiondlg.c
    branches/S2_6/client/gui-xaw/menu.c
    branches/S2_6/client/options.c
    branches/S2_6/client/options.h
    branches/S2_6/utility/log.h

Modified: branches/S2_6/client/client_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/client_main.c?rev=30375&r1=30374&r2=30375&view=diff
==============================================================================
--- branches/S2_6/client/client_main.c  (original)
+++ branches/S2_6/client/client_main.c  Mon Nov  2 20:02:11 2015
@@ -674,6 +674,18 @@
 }
 
 /**************************************************************************
+  Write messages from option saving to the log.
+**************************************************************************/
+static void log_option_save_msg(enum log_level lvl, const char *msg, ...)
+{
+  va_list args;
+
+  va_start(args, msg);
+  log_va_list(lvl, msg, args);
+  va_end(args);
+}
+
+/**************************************************************************
   Main client execution stop function. This calls ui_exit() and not the
   other way around.
 **************************************************************************/
@@ -685,7 +697,7 @@
   }
 
   if (gui_options.save_options_on_exit) {
-    options_save();
+    options_save(log_option_save_msg);
   }
 
   overview_free();

Modified: branches/S2_6/client/clinet.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/clinet.c?rev=30375&r1=30374&r2=30375&view=diff
==============================================================================
--- branches/S2_6/client/clinet.c       (original)
+++ branches/S2_6/client/clinet.c       Mon Nov  2 20:02:11 2015
@@ -321,7 +321,7 @@
   output_window_append(ftc_client, _("Disconnected from server."));
 
   if (gui_options.save_options_on_exit) {
-    options_save();
+    options_save(NULL);
   }
 }
 

Modified: branches/S2_6/client/gui-gtk-2.0/menu.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-2.0/menu.c?rev=30375&r1=30374&r2=30375&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-2.0/menu.c     (original)
+++ branches/S2_6/client/gui-gtk-2.0/menu.c     Mon Nov  2 20:02:11 2015
@@ -137,7 +137,7 @@
 *****************************************************************/
 static void save_options_callback(GtkAction *action, gpointer data)
 {
-  options_save();
+  options_save(NULL);
 }
 
 /****************************************************************

Modified: branches/S2_6/client/gui-gtk-2.0/optiondlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-2.0/optiondlg.c?rev=30375&r1=30374&r2=30375&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-2.0/optiondlg.c        (original)
+++ branches/S2_6/client/gui-gtk-2.0/optiondlg.c        Mon Nov  2 20:02:11 2015
@@ -118,7 +118,7 @@
     break;
   case RESPONSE_SAVE:
     desired_settable_options_update();
-    options_save();
+    options_save(NULL);
     break;
   }
 }

Modified: branches/S2_6/client/gui-gtk-3.0/menu.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-3.0/menu.c?rev=30375&r1=30374&r2=30375&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-3.0/menu.c     (original)
+++ branches/S2_6/client/gui-gtk-3.0/menu.c     Mon Nov  2 20:02:11 2015
@@ -139,7 +139,7 @@
 *****************************************************************/
 static void save_options_callback(GtkAction *action, gpointer data)
 {
-  options_save();
+  options_save(NULL);
 }
 
 /****************************************************************

Modified: branches/S2_6/client/gui-gtk-3.0/optiondlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-3.0/optiondlg.c?rev=30375&r1=30374&r2=30375&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-3.0/optiondlg.c        (original)
+++ branches/S2_6/client/gui-gtk-3.0/optiondlg.c        Mon Nov  2 20:02:11 2015
@@ -118,7 +118,7 @@
     break;
   case RESPONSE_SAVE:
     desired_settable_options_update();
-    options_save();
+    options_save(NULL);
     break;
   }
 }

Modified: branches/S2_6/client/gui-qt/menu.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/menu.cpp?rev=30375&r1=30374&r2=30375&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/menu.cpp        (original)
+++ branches/S2_6/client/gui-qt/menu.cpp        Mon Nov  2 20:02:11 2015
@@ -2046,7 +2046,7 @@
 *****************************************************************/
 void mr_menu::save_options_now()
 {
-  options_save();
+  options_save(NULL);
 }
 
 /***************************************************************************

Modified: branches/S2_6/client/gui-qt/optiondlg.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/optiondlg.cpp?rev=30375&r1=30374&r2=30375&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/optiondlg.cpp   (original)
+++ branches/S2_6/client/gui-qt/optiondlg.cpp   Mon Nov  2 20:02:11 2015
@@ -174,7 +174,7 @@
     break;
   case RESPONSE_SAVE:
     desired_settable_options_update();
-    options_save();
+    options_save(NULL);
     break;
   case RESPONSE_RESET:
     full_reset();

Modified: branches/S2_6/client/gui-sdl/optiondlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-sdl/optiondlg.c?rev=30375&r1=30374&r2=30375&view=diff
==============================================================================
--- branches/S2_6/client/gui-sdl/optiondlg.c    (original)
+++ branches/S2_6/client/gui-sdl/optiondlg.c    Mon Nov  2 20:02:11 2015
@@ -344,7 +344,7 @@
 static int save_client_options_callback(struct widget *pWidget)
 {
   if (Main.event.button.button == SDL_BUTTON_LEFT) {
-    options_save();
+    options_save(NULL);
   }
   return -1;
 }

Modified: branches/S2_6/client/gui-sdl2/optiondlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-sdl2/optiondlg.c?rev=30375&r1=30374&r2=30375&view=diff
==============================================================================
--- branches/S2_6/client/gui-sdl2/optiondlg.c   (original)
+++ branches/S2_6/client/gui-sdl2/optiondlg.c   Mon Nov  2 20:02:11 2015
@@ -347,7 +347,7 @@
 static int save_client_options_callback(struct widget *pWidget)
 {
   if (Main.event.button.button == SDL_BUTTON_LEFT) {
-    options_save();
+    options_save(NULL);
   }
 
   return -1;

Modified: branches/S2_6/client/gui-xaw/menu.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-xaw/menu.c?rev=30375&r1=30374&r2=30375&view=diff
==============================================================================
--- branches/S2_6/client/gui-xaw/menu.c (original)
+++ branches/S2_6/client/gui-xaw/menu.c Mon Nov  2 20:02:11 2015
@@ -616,7 +616,7 @@
     popup_messageopt_dialog();
     break;
   case MENU_GAME_SAVE_SETTINGS:
-    options_save();
+    options_save(NULL);
     break;
   case MENU_GAME_SERVER_OPTIONS:
     option_dialog_popup(_("Game Settings"), server_optset);

Modified: branches/S2_6/client/options.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/options.c?rev=30375&r1=30374&r2=30375&view=diff
==============================================================================
--- branches/S2_6/client/options.c      (original)
+++ branches/S2_6/client/options.c      Mon Nov  2 20:02:11 2015
@@ -5432,18 +5432,35 @@
 }
 
 /**************************************************************************
+  Write messages from option saving to the output window.
+**************************************************************************/
+static void option_save_output_window_callback(enum log_level lvl,
+                                               const char *msg, ...)
+{
+  va_list args;
+
+  va_start(args, msg);
+  output_window_vprintf(ftc_client, msg, args);
+  va_end(args);
+}
+
+/**************************************************************************
   Save all options.
 **************************************************************************/
-void options_save(void)
+void options_save(option_save_log_callback log_cb)
 {
   struct section_file *sf;
   const char *name = get_current_option_file_name();
   char dir_name[2048];
   int i;
 
+  if (log_cb == NULL) {
+    /* Default callback */
+    log_cb = option_save_output_window_callback;
+  }
+
   if (!name) {
-    output_window_append(ftc_client,
-                         _("Save failed, cannot find a filename."));
+    log_cb(LOG_ERROR, _("Save failed, cannot find a filename."));
     return;
   }
 
@@ -5493,10 +5510,9 @@
 
   /* save to disk */
   if (!secfile_save(sf, name, 0, FZ_PLAIN)) {
-    output_window_printf(ftc_client,
-                         _("Save failed, cannot write to file %s"), name);
+    log_cb(LOG_ERROR, _("Save failed, cannot write to file %s"), name);
   } else {
-    output_window_printf(ftc_client, _("Saved settings to file %s"), name);
+    log_cb(LOG_VERBOSE, _("Saved settings to file %s"), name);
   }
   secfile_destroy(sf);
 }

Modified: branches/S2_6/client/options.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/options.h?rev=30375&r1=30374&r2=30375&view=diff
==============================================================================
--- branches/S2_6/client/options.h      (original)
+++ branches/S2_6/client/options.h      Mon Nov  2 20:02:11 2015
@@ -314,6 +314,7 @@
 struct option;                  /* Opaque type. */
 struct option_set;              /* Opaque type. */
 
+typedef void (*option_save_log_callback)(enum log_level lvl, const char *msg, 
...);
 
 /* Main functions. */
 void options_init(void);
@@ -321,7 +322,7 @@
 void server_options_init(void);
 void server_options_free(void);
 void options_load(void);
-void options_save(void);
+void options_save(option_save_log_callback log_cb);
 
 
 /* Option sets. */

Modified: branches/S2_6/utility/log.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/utility/log.h?rev=30375&r1=30374&r2=30375&view=diff
==============================================================================
--- branches/S2_6/utility/log.h (original)
+++ branches/S2_6/utility/log.h Mon Nov  2 20:02:11 2015
@@ -118,6 +118,12 @@
   log_base(altlvl, message, ## __VA_ARGS__)
 #endif /* TESTMATIC_ENABLED */
 
+#define log_va_list(level, msg, args)                                       \
+  if (log_do_output_for_level(level)) {                                     \
+    vdo_log(__FILE__, __FUNCTION__, __FC_LINE__, FALSE,                     \
+            level, msg, args);                                              \
+  }
+
 /* Used by game debug command */
 #define log_test log_normal
 #define log_packet log_verbose


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to