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

Here's an updated patch that further sets the "Freeciv" theme as default
in the GTK+ client (until the user chooses another theme either in the
local options dialog or in the tileset).

Index: client/options.h
===================================================================
--- client/options.h	(Revision 12647)
+++ 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 12647)
+++ client/gui-gtk-2.0/themes.c	(Arbeitskopie)
@@ -24,6 +24,8 @@
 #include "mem.h"
 #include "support.h"
 
+#include "gui_main.h"
+
 #include "themes_common.h"
 #include "themes_g.h"
 
@@ -65,6 +67,7 @@
 *****************************************************************************/
 void gui_load_theme(const char *directory, const char *theme_name)
 {
+  GtkStyle *style;
   char buf[strlen(directory) + strlen(theme_name) + 32];
   
   load_default_files();
@@ -78,6 +81,13 @@
   gtk_rc_set_default_files(default_files);
 
   gtk_rc_reparse_all_for_settings(gtk_settings_get_default(), TRUE);
+    
+  /* the turn done button must have its own style. otherwise when we flash
+     the turn done button other widgets may flash too. */
+  if (!(style = gtk_rc_get_style(turn_done_button))) {
+    style = turn_done_button->style;
+  }
+  gtk_widget_set_style(turn_done_button, gtk_style_copy(style));
 }
 
 /*****************************************************************************
@@ -85,10 +95,26 @@
 *****************************************************************************/
 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);
+  GtkStyle *style;
+  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);
+      
+    /* the turn done button must have its own style. otherwise when we flash
+       the turn done button other widgets may flash too. */
+    if (!(style = gtk_rc_get_style(turn_done_button))) {
+      style = turn_done_button->style;
+    }
+    gtk_widget_set_style(turn_done_button, gtk_style_copy(style));
+  }
 }
 
 /*****************************************************************************
Index: client/gui-gtk-2.0/gui_main.c
===================================================================
--- client/gui-gtk-2.0/gui_main.c	(Revision 12647)
+++ client/gui-gtk-2.0/gui_main.c	(Arbeitskopie)
@@ -862,7 +862,6 @@
 {
   GtkWidget *box, *ebox, *hbox, *sbox, *align, *label;
   GtkWidget *frame, *table, *table2, *paned, *sw, *text;
-  GtkStyle *style;
   int i;
   char buf[256];
   struct sprite *sprite;
@@ -1065,13 +1064,6 @@
   /* turn done */
   turn_done_button = gtk_button_new_with_label(_("Turn Done"));
 
-  /* the turn done button must have its own style. otherwise when we flash
-     the turn done button other widgets may flash too. */
-  if (!(style = gtk_rc_get_style(turn_done_button))) {
-    style = turn_done_button->style;
-  }
-  gtk_widget_set_style(turn_done_button, gtk_style_copy(style));
-
   gtk_table_attach_defaults(GTK_TABLE(table), turn_done_button, 0, 10, 2, 3);
 
   g_signal_connect(turn_done_button, "clicked",
@@ -1291,6 +1283,10 @@
 
   parse_options(argc, argv);
 
+  if (default_theme_name[0] == '\0') {
+    sz_strlcpy(default_theme_name, "Freeciv");
+  }
+
   /* GTK withdraw gtk options. Process GTK arguments */
   gtk_init(&argc, &argv);
 
Index: client/themes_common.c
===================================================================
--- client/themes_common.c	(Revision 12647)
+++ 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 12647)
+++ 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 12647)
+++ client/tilespec.c	(Arbeitskopie)
@@ -4688,14 +4688,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 12647)
+++ client/options.c	(Arbeitskopie)
@@ -41,6 +41,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 **/
@@ -49,6 +50,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";
@@ -132,6 +135,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