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

> [EMAIL PROTECTED] - Fr 09. Mär 2007, 15:54:17]:
> 
>  It being common client option, does this mean that I cannot have
> different theme name for gtk and sdl clients? They hardly ship with
> similar themes.
> 

It means that only one theme name is saved in the .civclientrc file and
that this name might change when switching clients. But using a GUI
option instead of a common option won't help here, because all GUI
options get lost when switching to another client. I updated the patch a
bit to make sure the GTK+ client loads its default theme ("Freeciv")
when it can't find a theme with the name read from the options file.

The main reason why I made the options common options is that the "allow
tilesets to change the theme" option must be evaluated before the
"choose tileset" option (because when changing the tileset it must
already be known if the theme may be changed), but the GTK+ client shows
and evaluates the common options in the local options dialog first and
the GUI options only afterwards.

Index: client/options.h
===================================================================
--- client/options.h	(Revision 12776)
+++ 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 12776)
+++ client/gui-gtk-2.0/themes.c	(Arbeitskopie)
@@ -24,9 +24,13 @@
 #include "mem.h"
 #include "support.h"
 
+#include "gui_main.h"
+
 #include "themes_common.h"
 #include "themes_g.h"
 
+#define FC_GTK_DEFAULT_THEME_NAME "Freeciv"
+
 /* Array of default files. First num_default_files positions
  * are files returned by gtk_rc_get_default_files() on client startup.
  * There are two extra postions allocated in the array - one for
@@ -65,6 +69,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 +83,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 +97,34 @@
 *****************************************************************************/
 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 -> try to load Freeciv default theme */
+  if (!theme_loaded) {
+    theme_loaded = load_theme(FC_GTK_DEFAULT_THEME_NAME);
+    if (theme_loaded) {
+      sz_strlcpy(default_theme_name, FC_GTK_DEFAULT_THEME_NAME);
+    }
+  }
+    
+  /* still no 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 12776)
+++ 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",
Index: client/themes_common.c
===================================================================
--- client/themes_common.c	(Revision 12776)
+++ 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 12776)
+++ 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 12776)
+++ client/tilespec.c	(Arbeitskopie)
@@ -4769,14 +4769,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 12776)
+++ 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