<URL: http://bugs.freeciv.org/Ticket/Display.html?id=28301 >

This patch adds a common client option for GUI theme selection (for use
in the GTK+ client, but the SDL client could use it, too). It's based on
a patch by Mateusz Stefek in PR#13589, but with an additional boolean
option to allow or disallow tilesets to override the manually selected
theme.

A command line switch would be nice, too, but I'm not sure if it should
be a common client switch or a switch to be passed to the GUI. On the
one hand the patch defines the option as a common option to make it
integrate easily with the other client options in the GTK+ client's
local option dialog, and the "prefered_themes" tag in a tilespec file
doesn't distinguish between GUIs either, but on the other hand one might
argue that it still is a GUI-specific option and thus the parameter
should be passed to the GUI. What's your opinion on this?

Index: client/options.h
===================================================================
--- client/options.h	(Revision 12419)
+++ client/options.h	(Arbeitskopie)
@@ -20,6 +20,8 @@
 extern char default_server_host[512];
 extern int default_server_port; 
 extern char default_metaserver[512];
+extern char default_theme_name[512];
+extern bool allow_theme_override;
 extern char default_tileset_name[512];
 extern char default_sound_set_name[512];
 extern char default_sound_plugin_name[512];
@@ -199,4 +201,3 @@
 void mapview_redraw_callback(struct client_option *option);
 
 #endif  /* FC__OPTIONS_H */
-
Index: client/gui-gtk-2.0/themes.c
===================================================================
--- client/gui-gtk-2.0/themes.c	(Revision 12419)
+++ client/gui-gtk-2.0/themes.c	(Arbeitskopie)
@@ -85,10 +85,18 @@
 *****************************************************************************/
 void gui_clear_theme(void)
 {
-  load_default_files();
-  default_files[num_default_files] = NULL;
-  gtk_rc_set_default_files(default_files);
-  gtk_rc_reparse_all_for_settings(gtk_settings_get_default(), TRUE);
+  bool theme_loaded;
+
+  /* try to load user defined theme */
+  theme_loaded = load_theme(default_theme_name);
+  
+  /* no user defined theme loaded -> load system default theme */
+  if (!theme_loaded) {
+    load_default_files();
+    default_files[num_default_files] = NULL;
+    gtk_rc_set_default_files(default_files);
+    gtk_rc_reparse_all_for_settings(gtk_settings_get_default(), TRUE);
+  }
 }
 
 /*****************************************************************************
Index: client/themes_common.c
===================================================================
--- client/themes_common.c	(Revision 12419)
+++ client/themes_common.c	(Arbeitskopie)
@@ -190,3 +190,12 @@
   }
   return FALSE;
 }
+
+/****************************************************************************
+  Wrapper for load_theme. It's is used by local options dialog
+****************************************************************************/
+void theme_reread_callback(struct client_option *option)
+{
+  assert(option->p_string_value && *option->p_string_value != '\0');
+  load_theme(option->p_string_value);
+}
Index: client/themes_common.h
===================================================================
--- client/themes_common.h	(Revision 12419)
+++ client/themes_common.h	(Arbeitskopie)
@@ -17,4 +17,5 @@
 void init_themes(void);
 const char** get_themes_list(void);
 bool load_theme(const char* theme_name);
+void theme_reread_callback(struct client_option *option);
 #endif
Index: client/tilespec.c
===================================================================
--- client/tilespec.c	(Revision 12419)
+++ client/tilespec.c	(Arbeitskopie)
@@ -4682,14 +4682,19 @@
 void tileset_use_prefered_theme(const struct tileset *t)
 {
   int i;
-  for (i = 0; i < t->num_prefered_themes; i++) {
-    freelog(LOG_DEBUG, "trying theme %s", t->prefered_themes[i]);
-    if (load_theme(t->prefered_themes[i])) {
-      return;
+  
+  if (allow_theme_override) {
+    for (i = 0; i < t->num_prefered_themes; i++) {
+      freelog(LOG_DEBUG, "trying theme %s", t->prefered_themes[i]);
+      if (load_theme(t->prefered_themes[i])) {
+        sz_strlcpy(default_theme_name, t->prefered_themes[i]);
+        return;
+      }
     }
+    freelog(LOG_VERBOSE, "The tileset doesn't specify prefered themes or "
+                         "none of prefered themes can be used. Using system "
+                         "default");
   }
-  freelog(LOG_VERBOSE, "The tileset doesn't specify prefered themes or "
-                       "none of prefered themes can be used. Using system "
-		       "default");
+  
   gui_clear_theme();
 }
Index: client/options.c
===================================================================
--- client/options.c	(Revision 12419)
+++ client/options.c	(Arbeitskopie)
@@ -40,6 +40,7 @@
 #include "overview_common.h"
 #include "plrdlg_common.h"
 #include "servers.h"
+#include "themes_common.h"
 #include "tilespec.h"
 
 /** Defaults for options normally on command line **/
@@ -48,6 +49,8 @@
 char default_server_host[512] = "localhost";
 int  default_server_port = DEFAULT_SOCK_PORT;
 char default_metaserver[512] = METALIST_ADDR;
+char default_theme_name[512] = "\0";
+bool allow_theme_override = TRUE;
 char default_tileset_name[512] = "\0";
 char default_sound_set_name[512] = "stdsounds";
 char default_sound_plugin_name[512] = "\0";
@@ -131,6 +134,15 @@
 		    "you restart Freeciv.  Changing this is the same as "
 		    "using the -P command-line option."),
 		 COC_SOUND, get_soundplugin_list, NULL),
+  GEN_STR_OPTION(default_theme_name, N_("Theme"),
+		 N_("By changing this option you change the active theme."),
+		 COC_GRAPHICS,
+		 get_themes_list, theme_reread_callback),
+  GEN_BOOL_OPTION(allow_theme_override, N_("Allow tilesets to change the theme"),
+		  N_("Tilesets may define a set of themes they prefer. "
+		     "Disable this option if you don't want them to change the "
+                     "theme."),
+		  COC_GRAPHICS),
   GEN_STR_OPTION(default_tileset_name, N_("Tileset"),
 		 N_("By changing this option you change the active tileset. "
 		    "This is the same as using the -t command-line "
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to