2 "$Id: config.c 11627 2009-04-04 16:55:25Z lalo $";
35 #include <glade/glade.h>
47 int alphasort(
const struct dirent **a,
const struct dirent **b)
49 return strcoll((*a)->d_name, (*b)->d_name);
52 int scandir(
const char *dir,
struct dirent ***namelist,
53 int (*select)(
const struct dirent *),
54 int (*compar)(
const struct dirent **,
const struct dirent **)) {
60 if((d = opendir(dir)) == NULL)
64 while ((entry = readdir(d)) != NULL)
66 if (select == NULL || (select != NULL && (*select)(entry)))
68 *namelist = (
struct dirent **)realloc((
void *)(*namelist),
69 (size_t)((i + 1) *
sizeof(
struct dirent *)));
70 if (*namelist == NULL)
return -1;
71 entrysize =
sizeof(
struct dirent) - sizeof(entry->d_name) + strlen(entry->d_name) + 1;
72 (*namelist)[i] = (
struct dirent *)malloc(entrysize);
73 if ((*namelist)[i] == NULL)
return -1;
74 memcpy((*namelist)[i], entry, entrysize);
78 if (closedir(d))
return -1;
79 if (i == 0)
return -1;
81 qsort((
void *)(*namelist), (
size_t)i,
sizeof(
struct dirent *),
82 (
int(*)(
const void*,
const void*))compar);
99 static char *
theme =
"Standard";
120 static char **default_files=NULL;
133 tmp = gtk_rc_get_default_files();
138 default_files = malloc(
sizeof(
char*) * (i+1));
141 default_files[i] = strdup(tmp[i]);
144 default_files[i] = NULL;
147 if (!strcmp(theme,
"None")) {
153 gtk_rc_set_default_files(default_files);
156 snprintf(path,
MAX_BUF,
"%s/%s/%s", CF_DATADIR, themedir, theme);
162 if (access(path, R_OK) == -1) {
164 "Unable to find theme file %s", path);
173 gtk_rc_set_default_files(default_files);
174 gtk_rc_add_default_file(path);
183 gtk_rc_reparse_all_for_settings(gtk_settings_get_for_screen(gdk_screen_get_default()),
TRUE);
184 gtk_rc_reset_styles(gtk_settings_get_for_screen(gdk_screen_get_default()));
218 snprintf(path,
sizeof(path),
"%s/.crossfire/gdefaults2", getenv(
"HOME"));
219 if ((fp=fopen(path,
"r"))==NULL)
return;
220 while (fgets(inbuf,
MAX_BUF-1, fp)) {
222 inbuf[strlen(inbuf)-1]=
'\0';
224 if (inbuf[0]==
'#')
continue;
226 if (!(cp=strchr(inbuf,
':')))
continue;
231 if (isdigit(*cp)) val=atoi(cp);
232 else if (!strcmp(cp,
"True")) val =
TRUE;
233 else if (!strcmp(cp,
"False")) val =
FALSE;
239 "Invalid value/line: %s: %s", inbuf, cp);
247 if (i < CONFIG_NUMS)
continue;
253 if (!strcmp(inbuf,
"mapsize")) {
256 "Malformed mapsize option in gdefaults2. Ignoring");
259 else if (!strcmp(inbuf,
"server")) {
263 else if (!strcmp(inbuf,
"theme")) {
267 else if (!strcmp(inbuf,
"window_layout")) {
271 else if (!strcmp(inbuf,
"nopopups")) {
276 else if (!strcmp(inbuf,
"nosplash")) {
280 else if (!strcmp(inbuf,
"splash")) {
284 else if (!strcmp(inbuf,
"faceset")) {
289 else if (!strcmp(inbuf,
"per_tile_lighting")) {
292 else if (!strcmp(inbuf,
"per_pixel_lighting")) {
295 else if (!strcmp(inbuf,
"resists")) {
298 else if (!strcmp(inbuf,
"sdl")) {
302 "Unknown line in gdefaults2: %s %s", inbuf, cp);
311 "Ignoring iconscale value read from gdefaults2 file.\n"
312 "Invalid iconscale range (%d), valid range for -iconscale "
318 "ignoring mapscale value read for gdefaults2 file.\n"
319 "Invalid mapscale range (%d), valid range for -iconscale "
325 "No lighting mechanism selected - will not use darkness code");
330 "ignoring resists display value read for gdafaults file.\n"
331 "Invalid value (%d), must be one value of 0, 1 or 2.",
338 LOG(
LOG_WARNING,
"config.c::load_defaults",
"Invalid map width (%d) "
339 "option in gdefaults2. Valid range is 9 to %d",
344 LOG(
LOG_WARNING,
"config.c::load_defaults",
"Invalid map height (%d) "
345 "option in gdefaults2. Valid range is 9 to %d",
371 snprintf(path,
sizeof(path),
"%s/.crossfire/gdefaults2", getenv(
"HOME"));
373 LOG(
LOG_ERROR,
"config.c::save_defaults",
"Could not create %s", path);
376 if ((fp=fopen(path,
"w"))==NULL) {
377 LOG(
LOG_ERROR,
"config.c::save_defaults",
"Could not open %s", path);
380 fprintf(fp,
"# crossfire-client-gtk2 automatically generates this file.\n");
381 fprintf(fp,
"# Manual editing is allowed, but the client may be a bit\n");
382 fprintf(fp,
"# finicky about the keys and values. Comparisons are case\n");
383 fprintf(fp,
"# sensitive. 'True' and 'False' are the proper case, but\n");
384 fprintf(fp,
"# have been replaced with 1 and 0 respectively.\n#\n");
385 fprintf(fp,
"server: %s\n",
server);
386 fprintf(fp,
"theme: %s\n", theme);
399 snprintf(buf,
sizeof(buf),
"Defaults saved to %s",path);
416 config_window = glade_xml_get_widget(
dialog_xml,
"config_window");
417 xml_tree = glade_get_widget_tree(GTK_WIDGET(config_window));
419 config_spinbutton_cwindow =
420 glade_xml_get_widget(xml_tree,
"config_spinbutton_cwindow");
422 glade_xml_get_widget(xml_tree,
"config_button_echo");
423 config_button_fasttcp =
424 glade_xml_get_widget(xml_tree,
"config_button_fasttcp");
425 config_button_grad_color =
426 glade_xml_get_widget(xml_tree,
"config_button_grad_color");
427 config_button_foodbeep =
428 glade_xml_get_widget(xml_tree,
"config_button_foodbeep");
429 config_button_sound =
430 glade_xml_get_widget(xml_tree,
"config_button_sound");
431 config_button_cache =
432 glade_xml_get_widget(xml_tree,
"config_button_cache");
433 config_button_download =
434 glade_xml_get_widget(xml_tree,
"config_button_download");
436 glade_xml_get_widget(xml_tree,
"config_button_fog");
437 config_button_smoothing =
438 glade_xml_get_widget(xml_tree,
"config_button_smoothing");
439 config_spinbutton_iconscale =
440 glade_xml_get_widget(xml_tree,
"config_spinbutton_iconscale");
441 config_spinbutton_mapscale =
442 glade_xml_get_widget(xml_tree,
"config_spinbutton_mapscale");
443 config_spinbutton_mapwidth =
444 glade_xml_get_widget(xml_tree,
"config_spinbutton_mapwidth");
445 config_spinbutton_mapheight =
446 glade_xml_get_widget(xml_tree,
"config_spinbutton_mapheight");
447 config_combobox_displaymode =
448 glade_xml_get_widget(xml_tree,
"config_combobox_displaymode");
449 config_combobox_faceset =
450 glade_xml_get_widget(xml_tree,
"config_combobox_faceset");
451 config_combobox_lighting =
452 glade_xml_get_widget(xml_tree,
"config_combobox_lighting");
453 config_combobox_theme =
454 glade_xml_get_widget(xml_tree,
"config_combobox_theme");
455 config_combobox_glade =
456 glade_xml_get_widget(xml_tree,
"config_combobox_glade");
458 widget = glade_xml_get_widget(xml_tree,
"config_button_save");
459 g_signal_connect ((gpointer) widget,
"clicked",
462 widget = glade_xml_get_widget(xml_tree,
"config_button_apply");
463 g_signal_connect ((gpointer) widget,
"clicked",
466 widget = glade_xml_get_widget(xml_tree,
"config_button_close");
467 g_signal_connect ((gpointer) widget,
"clicked",
474 count = gtk_tree_model_iter_n_children(
475 gtk_combo_box_get_model(GTK_COMBO_BOX(config_combobox_displaymode)), NULL);
476 for (i=0; i < count; i++)
477 gtk_combo_box_remove_text(GTK_COMBO_BOX(config_combobox_displaymode), 0);
480 gtk_combo_box_append_text(GTK_COMBO_BOX(config_combobox_displaymode),
"OpenGL");
484 gtk_combo_box_append_text(GTK_COMBO_BOX(config_combobox_displaymode),
"SDL");
486 gtk_combo_box_append_text(GTK_COMBO_BOX(config_combobox_displaymode),
"Pixmap");
502 if (d->d_name[0] ==
'.')
return 0;
522 char exten[] =
"glade";
525 strncpy(parse, d->d_name,
MAX_BUF);
526 token = strtok(parse, delim);
529 token = strtok(NULL, delim);
531 if (extok && strncmp(exten, extok, strlen(exten)) == 0) {
566 uint64 want_none,
char *subdir,
int (*scandir_filter) ())
573 model = gtk_combo_box_get_model(GTK_COMBO_BOX(combobox));
574 count = gtk_tree_model_iter_n_children(model, NULL);
581 struct dirent **files;
584 snprintf(path,
MAX_BUF,
"%s/%s", CF_DATADIR, subdir);
586 count = scandir(path, &files, *scandir_filter, alphasort);
588 "found %d files in %s\n", count, path);
590 for (i=0; i<count; i++) {
596 if (!done_none && want_none &&
597 strcmp(files[i]->d_name,
"None") > 0) {
598 gtk_combo_box_append_text(GTK_COMBO_BOX(combobox),
"None");
602 gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), files[i]->d_name);
605 count = gtk_tree_model_iter_n_children(model, NULL);
611 for (i=0; i < count; i++) {
612 if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, i)) {
614 "Unable to get combo box iter\n");
617 gtk_tree_model_get(model, &iter, 0, &buf, -1);
618 if (!strcasecmp(active, buf)) {
619 gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), i);
638 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(config_button_echo),
641 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(config_button_fasttcp),
644 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(config_button_grad_color),
647 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(config_button_foodbeep),
650 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(config_button_sound),
653 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(config_button_cache),
656 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(config_button_download),
659 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(config_button_fog),
662 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(config_button_smoothing),
665 gtk_spin_button_set_value(GTK_SPIN_BUTTON(config_spinbutton_cwindow),
668 gtk_spin_button_set_value(GTK_SPIN_BUTTON(config_spinbutton_iconscale),
671 gtk_spin_button_set_value(GTK_SPIN_BUTTON(config_spinbutton_mapscale),
674 gtk_spin_button_set_value(GTK_SPIN_BUTTON(config_spinbutton_mapwidth),
677 gtk_spin_button_set_value(GTK_SPIN_BUTTON(config_spinbutton_mapheight),
683 model = gtk_combo_box_get_model(GTK_COMBO_BOX(config_combobox_faceset));
684 count = gtk_tree_model_iter_n_children(model, NULL);
686 for (i=0; i < count; i++)
687 gtk_combo_box_remove_text(GTK_COMBO_BOX(config_combobox_faceset), 0);
693 gtk_combo_box_append_text(GTK_COMBO_BOX(config_combobox_faceset),
696 gtk_combo_box_append_text(GTK_COMBO_BOX(config_combobox_faceset),
"Standard");
697 gtk_combo_box_append_text(GTK_COMBO_BOX(config_combobox_faceset),
"Classic");
699 count = gtk_tree_model_iter_n_children(model, NULL);
701 for (i=0; i < count; i++) {
702 if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, i)) {
704 "Unable to get faceset iter\n");
707 gtk_tree_model_get(model, &iter, 0, &buf, -1);
710 gtk_combo_box_set_active(GTK_COMBO_BOX(config_combobox_faceset), i);
719 "Player display mode not in display_modes range\n");
725 model = gtk_combo_box_get_model(GTK_COMBO_BOX(config_combobox_displaymode));
726 count = gtk_tree_model_iter_n_children(model, NULL);
727 for (i=0; i < count; i++) {
728 if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, i)) {
730 "Unable to get faceset iter\n");
733 gtk_tree_model_get(model, &iter, 0, &buf, -1);
734 if (!strcasecmp(display_modes[
want_config[CONFIG_DISPLAYMODE]], buf)) {
735 gtk_combo_box_set_active(GTK_COMBO_BOX(config_combobox_displaymode), i);
747 model = gtk_combo_box_get_model(GTK_COMBO_BOX(config_combobox_lighting));
748 count = gtk_tree_model_iter_n_children(model, NULL);
749 for (i=0; i < count; i++) {
750 if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, i)) {
752 "Unable to get lighting iter\n");
755 gtk_tree_model_get(model, &iter, 0, &buf, -1);
760 gtk_combo_box_set_active(GTK_COMBO_BOX(config_combobox_lighting), i);
784 #define IS_DIFFERENT(TYPE) (want_config[TYPE] != use_config[TYPE])
810 buf = gtk_combo_box_get_active_text(GTK_COMBO_BOX(config_combobox_faceset));
823 buf = gtk_combo_box_get_active_text(GTK_COMBO_BOX(config_combobox_displaymode));
831 buf = gtk_combo_box_get_active_text(GTK_COMBO_BOX(config_combobox_lighting));
849 buf = gtk_combo_box_get_active_text(GTK_COMBO_BOX(config_combobox_theme));
851 if (strcmp(buf, theme)) {
864 buf = gtk_combo_box_get_active_text(GTK_COMBO_BOX(config_combobox_glade));
890 perror(
"TCP_NODELAY");
895 perror(
"TCP_NODELAY");
958 gtk_widget_hide(config_window);
971 gtk_widget_show(config_window);
989 GList *pane_list, *list_loop;
999 cp = strrchr(buf,
'.');
1003 snprintf(savename,
sizeof(savename),
"%s/.crossfire/%s.pos", getenv(
"HOME"), buf);
1004 if (!(save = fopen(savename,
"w"))) {
1005 snprintf(buf,
sizeof(buf),
"Cannot open %s - window positions not saved!", savename);
1010 fprintf(save,
"window_root: +%d+%dx%dx%d\n", wx, wy, w, h);
1012 xml_tree = glade_get_widget_tree(GTK_WIDGET(window_root));
1019 pane_list = glade_xml_get_widget_prefix(xml_tree,
"hpaned_");
1020 for (list_loop = pane_list; list_loop; list_loop = g_list_next(list_loop)) {
1021 widget = list_loop->data;
1022 fprintf(save,
"%s: %d\n", glade_get_widget_name(widget),
1023 gtk_paned_get_position(GTK_PANED(widget)));
1025 g_list_free(pane_list);
1027 pane_list = glade_xml_get_widget_prefix(xml_tree,
"vpaned_");
1028 for (list_loop = pane_list; list_loop; list_loop = g_list_next(list_loop)) {
1029 widget = list_loop->data;
1030 fprintf(save,
"%s: %d\n", glade_get_widget_name(widget),
1031 gtk_paned_get_position(GTK_PANED(widget)));
1033 g_list_free(pane_list);
1036 snprintf(buf,
sizeof(buf),
"Window positions saved to %s", savename);
1055 g_signal_stop_emission_by_name(GTK_OBJECT(menuitem),
"activate");
1079 cp = strrchr(buf,
'.');
1083 snprintf(loadname,
sizeof(loadname),
"%s/.crossfire/%s.pos", getenv(
"HOME"), buf);
1084 if (!(load = fopen(loadname,
"r"))) {
1085 snprintf(buf,
sizeof(buf),
1086 "Cannot open %s: Using default window positions.", loadname);
1091 snprintf(buf,
sizeof(buf),
"Loading window positions from %s", loadname);
1095 xml_tree = glade_get_widget_tree(GTK_WIDGET (window_root));
1097 while(fgets(buf,
MAX_BUF-1, load)!=NULL) {
1098 if ((cp=strchr(buf,
':'))!=NULL) {
1101 while(isspace(*cp)) cp++;
1103 if (!strcmp(buf,
"window_root")) {
1106 if (sscanf(cp,
"+%d+%dx%dx%d", &x, &y, &w, &h) == 4) {
1107 gtk_window_set_default_size (GTK_WINDOW(window_root), w, h);
1108 gtk_window_move(GTK_WINDOW(window_root), x, y);
1112 "Window size %s corrupt\n", cp);
1114 }
else if (strstr(buf,
"paned_")) {
1121 widget = glade_xml_get_widget(xml_tree, buf);
1123 gtk_paned_set_position(GTK_PANED(widget), atoi(cp));
1125 LOG(
LOG_INFO,
"config.c::load_window_positions",
"%s in "
1126 "%s not found in this UI layout.\n", buf, loadname);
1130 "Found unknown line %s in %s\n", buf, loadname);
GtkWidget * config_button_cache
void update_spell_information(void)
void info_get_styles(void)
void load_window_positions(GtkWidget *window_root)
void init_SDL(GtkWidget *sdl_window, int just_lightmap)
void spell_get_styles(void)
#define DEFAULT_IMAGE_SIZE
GtkWidget * config_spinbutton_cwindow
GtkWidget * config_button_sound
GtkWidget * config_button_fasttcp
GtkWidget * config_combobox_lighting
GtkWidget * config_button_smoothing
char window_xml_file[MAX_BUF]
#define IS_DIFFERENT(TYPE)
void config_init(GtkWidget *window_root)
GtkWidget * config_spinbutton_mapwidth
static void fill_combobox_from_datadir(GtkWidget *combobox, char *active, uint64 want_none, char *subdir, int(*scandir_filter)())
GtkWidget * config_button_download
int make_path_to_file(char *filename)
Face_Information face_info
void get_window_coord(GtkWidget *win, int *x, int *y, int *wx, int *wy, int *w, int *h)
sint16 want_config[CONFIG_NUMS]
GtkWidget * config_spinbutton_mapscale
#define CFG_LT_PIXEL_BEST
void on_configure_activate(GtkMenuItem *menuitem, gpointer user_data)
void draw_stats(int redraw)
void LOG(LogLevel level, const char *origin, const char *format,...)
int cs_print_string(int fd, const char *str,...)
void draw_message_window(int redraw)
sint16 use_config[CONFIG_NUMS]
void on_config_button_close_clicked(GtkButton *button, gpointer user_data)
GtkWidget * config_button_grad_color
GtkWidget * config_combobox_theme
#define CONFIG_GRAD_COLOR
GtkWidget * config_combobox_glade
#define DIALOG_XML_FILENAME
GtkWidget * config_window
GtkWidget * config_spinbutton_mapheight
GtkWidget * config_combobox_faceset
void stats_get_styles(void)
GtkWidget * config_combobox_displaymode
GtkWidget * config_button_foodbeep
const char *const rcsid_gtk2_config_c
char * strdup_local(const char *str)
static void setup_config_window(void)
void load_theme(int reload)
GtkWidget * config_button_echo
void draw_info(const char *str, int color)
static int scandir_theme_filter(const struct dirent *d)
GtkWidget * config_spinbutton_iconscale
void inventory_get_styles(void)
#define CONFIG_DISPLAYMODE
void on_save_window_position_activate(GtkMenuItem *menuitem, gpointer user_data)
static const char *const display_modes[]
static void read_config_window(void)
void on_config_button_save_clicked(GtkButton *button, gpointer user_data)
const char *const config_names[CONFIG_NUMS]
void on_config_button_apply_clicked(GtkButton *button, gpointer user_data)
static int scandir_glade_filter(const struct dirent *d)
GtkWidget * config_button_fog