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

Here's a variant that shows a confirmation dialog when the tileset wants
to change the theme, similar to and applying on top of PR#37988.
diff -urN -X trunk/diff_ignore trunk.orig/client/gui-gtk-2.0/gui_main.c trunk/client/gui-gtk-2.0/gui_main.c
--- trunk.orig/client/gui-gtk-2.0/gui_main.c	2007-03-12 06:11:49.000000000 +0100
+++ trunk/client/gui-gtk-2.0/gui_main.c	2007-03-09 20:01:32.000000000 +0100
@@ -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",
diff -urN -X trunk/diff_ignore trunk.orig/client/gui-gtk-2.0/Makefile.am trunk/client/gui-gtk-2.0/Makefile.am
--- trunk.orig/client/gui-gtk-2.0/Makefile.am	2007-03-12 06:12:11.000000000 +0100
+++ trunk/client/gui-gtk-2.0/Makefile.am	2007-03-12 06:13:13.000000000 +0100
@@ -91,6 +91,7 @@
 	spaceshipdlg.h  \
 	sprite.c	\
 	sprite.h	\
+	theme_dlg.c	\
 	themes.c	\
 	tileset_dlg.c	\
 	wldlg.c		\
diff -urN -X trunk/diff_ignore trunk.orig/client/gui-gtk-2.0/theme_dlg.c trunk/client/gui-gtk-2.0/theme_dlg.c
--- trunk.orig/client/gui-gtk-2.0/theme_dlg.c	1970-01-01 01:00:00.000000000 +0100
+++ trunk/client/gui-gtk-2.0/theme_dlg.c	2007-03-12 07:17:10.000000000 +0100
@@ -0,0 +1,76 @@
+/********************************************************************** 
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gtk/gtk.h>
+
+#include "fcintl.h"
+
+#include "options.h"
+
+#include "dialogs_g.h"
+
+static bool load_theme = FALSE;
+
+static void theme_suggestion_callback(GtkWidget *dlg, gint arg);
+
+/****************************************************************
+  Callback deciding if the theme may be loaded or not
+*****************************************************************/
+static void theme_suggestion_callback(GtkWidget *dlg, gint arg)
+{
+  load_theme = (arg == GTK_RESPONSE_YES);
+}
+
+/****************************************************************
+  Popup dialog asking if tileset suggested theme should be
+  used.
+*****************************************************************/
+bool popup_theme_suggestion_dialog(const char *theme_name)
+{
+  GtkWidget *dialog, *label;
+  char buf[1024];
+
+  dialog = gtk_dialog_new_with_buttons(_("Theme suggested"),
+                                       NULL,
+                                       0,
+                                       _("Load theme"),
+                                       GTK_RESPONSE_YES,
+                                       _("Keep current theme"),
+                                       GTK_RESPONSE_NO,
+                                       NULL);
+  gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_YES);
+  gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE);
+
+  my_snprintf(buf, sizeof(buf),
+              _("Tileset suggests using %s theme.\n"
+              "You are currently using %s."),
+              theme_name, default_theme_name);
+
+  label = gtk_label_new(buf);
+  gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label);
+  gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
+  gtk_widget_show(label);
+
+  g_signal_connect(dialog, "response",
+                   G_CALLBACK(theme_suggestion_callback), NULL);
+
+  gtk_dialog_run(GTK_DIALOG(dialog));
+
+  gtk_widget_destroy(dialog);
+  
+  return load_theme;
+}
diff -urN -X trunk/diff_ignore trunk.orig/client/gui-gtk-2.0/themes.c trunk/client/gui-gtk-2.0/themes.c
--- trunk.orig/client/gui-gtk-2.0/themes.c	2007-03-12 06:11:49.000000000 +0100
+++ trunk/client/gui-gtk-2.0/themes.c	2007-03-09 20:01:49.000000000 +0100
@@ -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));
+  }
 }
 
 /*****************************************************************************
diff -urN -X trunk/diff_ignore trunk.orig/client/include/dialogs_g.h trunk/client/include/dialogs_g.h
--- trunk.orig/client/include/dialogs_g.h	2007-03-12 06:12:11.000000000 +0100
+++ trunk/client/include/dialogs_g.h	2007-03-12 06:32:46.000000000 +0100
@@ -18,6 +18,7 @@
 #include "fc_types.h"
 #include "nation.h"		/* Nation_type_id */
 #include "terrain.h"		/* enum tile_special_type */
+#include "unitlist.h"           /* struct unit_list */
 
 struct packet_nations_selected_info;
 
@@ -46,6 +47,7 @@
 void popup_sabotage_dialog(struct city *pcity);
 void popup_pillage_dialog(struct unit *punit, bv_special may_pillage);
 void popup_upgrade_dialog(struct unit_list *punits);
+bool popup_theme_suggestion_dialog(const char *theme_name);
 void popup_tileset_suggestion_dialog(void);
 
 void popdown_all_game_dialogs(void);
diff -urN -X trunk/diff_ignore trunk.orig/client/options.c trunk/client/options.c
--- trunk.orig/client/options.c	2007-03-12 06:11:49.000000000 +0100
+++ trunk/client/options.c	2007-03-12 07:04:46.000000000 +0100
@@ -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,7 @@
 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";
 char default_tileset_name[512] = "\0";
 char default_sound_set_name[512] = "stdsounds";
 char default_sound_plugin_name[512] = "\0";
@@ -132,6 +134,10 @@
 		    "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_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 "
diff -urN -X trunk/diff_ignore trunk.orig/client/options.h trunk/client/options.h
--- trunk.orig/client/options.h	2007-03-12 06:11:48.000000000 +0100
+++ trunk/client/options.h	2007-03-12 07:04:15.000000000 +0100
@@ -20,6 +20,7 @@
 extern char default_server_host[512];
 extern int default_server_port; 
 extern char default_metaserver[512];
+extern char default_theme_name[512];
 extern char default_tileset_name[512];
 extern char default_sound_set_name[512];
 extern char default_sound_plugin_name[512];
@@ -199,4 +200,3 @@
 void mapview_redraw_callback(struct client_option *option);
 
 #endif  /* FC__OPTIONS_H */
-
diff -urN -X trunk/diff_ignore trunk.orig/client/themes_common.c trunk/client/themes_common.c
--- trunk.orig/client/themes_common.c	2007-03-12 06:11:49.000000000 +0100
+++ trunk/client/themes_common.c	2007-03-09 20:10:55.000000000 +0100
@@ -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);
+}
diff -urN -X trunk/diff_ignore trunk.orig/client/themes_common.h trunk/client/themes_common.h
--- trunk.orig/client/themes_common.h	2007-03-12 06:11:49.000000000 +0100
+++ trunk/client/themes_common.h	2007-03-09 18:02:48.000000000 +0100
@@ -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
diff -urN -X trunk/diff_ignore trunk.orig/client/tilespec.c trunk/client/tilespec.c
--- trunk.orig/client/tilespec.c	2007-03-12 06:11:49.000000000 +0100
+++ trunk/client/tilespec.c	2007-03-12 06:35:08.000000000 +0100
@@ -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 (popup_theme_suggestion_dialog(t->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");
+                       "default");
+  
   gui_clear_theme();
 }
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to