vaccinewars

be a doctor and try to vaccinate the world
git clone git://src.adamsgaard.dk/vaccinewars # fast
git clone https://src.adamsgaard.dk/vaccinewars.git # slow
Log | Files | Refs | README | LICENSE Back to index

commit dca625d6b5ee3b6b60fdb8a266a60279be66d913
parent fdfb74e2a12fcd210e0de6787e7ec1efb4e29f46
Author: Ben Webb <ben@salilab.org>
Date:   Mon,  2 Sep 2002 13:41:40 +0000

Add option to force the GUI client to write out the configuration file
in UTF-8 encoding; moved Win32 "minimize server to System Tray" option
from General tab to Server.


Diffstat:
Mdoc/help/general.html | 12+++++++-----
Adoc/help/server.html | 25+++++++++++++++++++++++++
Msrc/configfile.c | 18+++++++++++++++---
Msrc/configfile.h | 3++-
Msrc/gui_client/optdialog.c | 21++++++++++++++++-----
Msrc/serverside.c | 2+-
6 files changed, 66 insertions(+), 15 deletions(-)

diff --git a/doc/help/general.html b/doc/help/general.html @@ -19,11 +19,13 @@ Obviously, if you really want to remove drug references completely, you also need to change all the drug names in the <a href="drugs.html">Drugs tab</a>.<p /></li> -<li><b>Put server in System Tray</b>: (Windows only) When running the -graphical server, and it is minimized, do not show the window in the normal -window list, but in the System Tray (the collection of small icons in the -bottom right of the screen). Clicking on the dopewars icon in the Tray will -restore the window to its normal state.<p /></li> +<li><b>Unicode config file</b>: Write out the configuration file in UTF-8 +(Unicode) encoding, rather than the default locale encoding. You should turn +this option on if you are using unusual characters (e.g. Hebrew or Cyrillic +in the English version) as these will be otherwise lost when you save the file. +Note that this is the default under Unix when running in UTF-8 locales. Note +also that versions of dopewars prior to 1.5.8, or Unix versions linked against +GTK+1.x will not be able to read UTF-8 configuration files.<p /></li> <li><b>Game length (turns)</b>: The number of days over which the game runs. If this is set to 0 (zero) then the game will only end if you are killed. diff --git a/doc/help/server.html b/doc/help/server.html @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> + +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> + +<head> +<title>dopewars: Server Options</title> +</head> + +<body> +<h1>dopewars: Server Options</h1> + +<ul> +<li><b>Minimize to System Tray</b>: (Windows only) When running the +graphical server, and it is minimized, do not show the window in the normal +window list, but in the System Tray (the collection of small icons in the +bottom right of the screen). Clicking on the dopewars icon in the Tray will +restore the window to its normal state.<p /></li> + +</ul> + +</body> +</html> diff --git a/src/configfile.c b/src/configfile.c @@ -31,6 +31,7 @@ #include <ctype.h> /* For isprint */ #include <glib.h> +#include "configfile.h" #include "convert.h" /* For Converter */ #include "dopewars.h" /* For struct GLOBALS etc. */ #include "nls.h" /* For _ function */ @@ -191,11 +192,17 @@ static void ReadFileToString(FILE *fp, gchar *str, int matchlen) * Writes all of the configuration file variables that have changed * (together with their values) to the given file. */ -static void WriteConfigFile(FILE *fp) +static void WriteConfigFile(FILE *fp, gboolean ForceUTF8) { int i, j; Converter *conv = Conv_New(); + if (ForceUTF8 && !IsConfigFileUTF8()) { + g_free(LocalCfgEncoding); + LocalCfgEncoding = g_strdup("UTF-8"); + fprintf(fp, "encoding \"UTF-8\"\n"); + } + if (LocalCfgEncoding && LocalCfgEncoding[0]) { Conv_SetCodeset(conv, LocalCfgEncoding); } @@ -214,7 +221,7 @@ static void WriteConfigFile(FILE *fp) Conv_Free(conv); } -gboolean UpdateConfigFile(const gchar *cfgfile) +gboolean UpdateConfigFile(const gchar *cfgfile, gboolean ForceUTF8) { FILE *fp; gchar *defaultfile; @@ -246,9 +253,14 @@ gboolean UpdateConfigFile(const gchar *cfgfile) } ReadFileToString(fp, header, 50); - WriteConfigFile(fp); + WriteConfigFile(fp, ForceUTF8); fclose(fp); g_free(defaultfile); return TRUE; } + +gboolean IsConfigFileUTF8(void) +{ + return (LocalCfgEncoding && strcmp(LocalCfgEncoding, "UTF-8") == 0); +} diff --git a/src/configfile.h b/src/configfile.h @@ -26,6 +26,7 @@ #include <glib.h> extern gchar *LocalCfgEncoding; -gboolean UpdateConfigFile(const gchar *cfgfile); +gboolean UpdateConfigFile(const gchar *cfgfile, gboolean ForceUTF8); +gboolean IsConfigFileUTF8(void); #endif /* __DP_CONFIGFILE_H__ */ diff --git a/src/gui_client/optdialog.c b/src/gui_client/optdialog.c @@ -556,8 +556,12 @@ static void TestPlaySound(GtkWidget *entry) static void OKCallback(GtkWidget *widget, GtkWidget *dialog) { + GtkToggleButton *unicode_check; + SaveConfigWidgets(); - UpdateConfigFile(NULL); + unicode_check = GTK_TOGGLE_BUTTON(gtk_object_get_data(GTK_OBJECT(dialog), + "unicode_check")); + UpdateConfigFile(NULL, gtk_toggle_button_get_active(unicode_check)); gtk_widget_destroy(dialog); } @@ -772,9 +776,11 @@ void OptDialog(GtkWidget *widget, gpointer data) check = NewConfigCheck("Sanitized", _("Remove drug references")); gtk_table_attach_defaults(GTK_TABLE(table), check, 0, 1, 0, 1); -#ifdef CYGWIN - check = NewConfigCheck("MinToSysTray", _("Put server in System Tray")); - gtk_table_attach_defaults(GTK_TABLE(table), check, 1, 2, 0, 1); +#ifdef HAVE_GLIB2 + check = gtk_check_button_new_with_label(_("Unicode config file")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), IsConfigFileUTF8()); + gtk_table_attach_defaults(GTK_TABLE(table), check, 1, 3, 0, 1); + gtk_object_set_data(GTK_OBJECT(dialog), "unicode_check", check); #endif label = gtk_label_new(_("Game length (turns)")); @@ -877,7 +883,12 @@ void OptDialog(GtkWidget *widget, gpointer data) check = NewConfigCheck("MetaServer.Active", _("Server reports to metaserver")); - gtk_table_attach_defaults(GTK_TABLE(table), check, 0, 4, 0, 1); + gtk_table_attach_defaults(GTK_TABLE(table), check, 0, 2, 0, 1); + +#ifdef CYGWIN + check = NewConfigCheck("MinToSysTray", _("Minimize to System Tray")); + gtk_table_attach_defaults(GTK_TABLE(table), check, 2, 4, 0, 1); +#endif label = gtk_label_new(_("Metaserver hostname")); gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, diff --git a/src/serverside.c b/src/serverside.c @@ -971,7 +971,7 @@ static void ServerSaveConfigFile(const char *string) file = GetLocalConfigFile(); string = file; } - if (UpdateConfigFile(file)) { + if (UpdateConfigFile(file, FALSE)) { g_print(_("Configuration file saved OK as %s\n"), string); } g_free(file);