Exemple #1
0
static void save_cwidget_geometry (GtkWidget *clist, struct clist_def *cldef) {
	char buf[256];
	int i;

	g_snprintf (buf, 256, "/" CONFIG_FILE "/%s Geometry/", cldef->name);
	config_push_prefix (buf);

	for (i = 0; i < cldef->columns; i++)
		config_set_int (cldef->cols[i].name, GTK_CLIST (clist)->column[i].width);

	config_pop_prefix ();
}
Exemple #2
0
static void statistics_restore_geometry (GtkWidget *window) {
	int height, width;

	config_push_prefix ("/" CONFIG_FILE "/Statistics Window Geometry/");

	height = config_get_int ("height");
	width = config_get_int ("width");
	if (!width || !height)
		return;

	gtk_window_set_default_size (GTK_WINDOW (window), width, height);

	config_pop_prefix ();
}
Exemple #3
0
void ui_done (void) {
	GtkCTreeNode *node;
	char cfgkey[128];
	int expanded;
	GSList *list;
	struct master *m;

	save_cwidget_geometry (GTK_WIDGET (server_clist), &server_clist_def);
	save_cwidget_geometry (GTK_WIDGET (player_clist), &player_clist_def);
	save_cwidget_geometry (GTK_WIDGET (srvinf_ctree), &srvinf_clist_def);

	config_push_prefix ("/" CONFIG_FILE "/Main Window Geometry/");

	config_set_int ("height", main_window->allocation.height);
	config_set_int ("width", main_window->allocation.width);
	config_set_int ("pane1", GTK_PANED (pane1_widget)->child1->allocation.width);
	config_set_int ("pane2", GTK_PANED (pane2_widget)->child1->allocation.height);
	config_set_int ("pane3", GTK_PANED (pane3_widget)->child1->allocation.width);

	config_pop_prefix ();

	config_clean_section ("/" CONFIG_FILE "/Source Tree");

	for (list = master_groups; list; list = list->next) {
		m = (struct master *) list->data;
		if (m->isgroup) {
			node = gtk_ctree_find_by_row_data (GTK_CTREE (source_ctree), NULL, m);
			if (node) {
				gtk_ctree_get_node_info (GTK_CTREE (source_ctree), node,
						NULL, NULL, NULL, NULL, NULL, NULL, NULL, &expanded);
				if (!expanded) {
					g_snprintf (cfgkey, 128, "/" CONFIG_FILE "/Source Tree/%s node collapsed=false", m->name);
					config_set_bool (cfgkey, TRUE - expanded);
				}
			}
		}
	}
}
Exemple #4
0
void restore_main_window_geometry (void) {
	int height, width;
	int pane1, pane2, pane3;

	config_push_prefix ("/" CONFIG_FILE "/Main Window Geometry/");

	height = config_get_int ("height=480");
	width  = config_get_int ("width=640");
	pane1  = config_get_int ("pane1");
	pane2  = config_get_int ("pane2");
	pane3  = config_get_int ("pane3");

	config_pop_prefix ();

	if (height && width) {
		/* gtk_widget_set_usize (GTK_WIDGET (main_window), width, height); */
		gtk_window_set_default_size (GTK_WINDOW (main_window), width, height);
	}

	gtk_paned_set_position (GTK_PANED (pane1_widget), (pane1)? pane1 : 120);
	gtk_paned_set_position (GTK_PANED (pane2_widget), (pane2)? pane2 : server_clist_def.height +4);
	gtk_paned_set_position (GTK_PANED (pane3_widget), (pane3)? pane3 : player_clist_def.height + 4);
}
Exemple #5
0
static void statistics_save_geometry (GtkWidget *window, gpointer data) {
	config_push_prefix ("/" CONFIG_FILE "/Statistics Window Geometry/");
	config_set_int ("height", window->allocation.height);
	config_set_int ("width", window->allocation.width);
	config_pop_prefix ();
}
Exemple #6
0
void save_script_prefs() {
	GList* s;
	char path[PATH_MAX];

	for (s = scripts; s; s = g_list_next(s)) {
		Script* script;
		GSList* optlist;

		script = g_datalist_get_data(&scriptdata, s->data);

		if (!script) {
			xqf_error("no data for script %s", s->data);
			continue;
		}

		snprintf(path, sizeof(path), "/" CONFIG_FILE "/scripts/%s", (char*)s->data);
		config_push_prefix(path);

		for (optlist = script->options; optlist; optlist = g_slist_next(optlist)) {
			ScriptOption* opt = optlist->data;
			const char* val = NULL;
			int enable = 0;

			switch(opt->type) {
				case SCRIPT_OPTION_TYPE_STRING:
				case SCRIPT_OPTION_TYPE_INT:
				case SCRIPT_OPTION_TYPE_LIST:
					val = gtk_entry_get_text(GTK_ENTRY(opt->widget));

					if (!strlen(val)) {
						val = NULL;
					}

					if ((!val && opt->defval) || (val && !opt->defval) || (val && opt->defval && strcmp(opt->defval, val))) {
						g_free(opt->defval);
						debug(4, "set %s/%s=%s (before: %s)", s->data, opt->section, val, opt->defval);
						if (opt->type == SCRIPT_OPTION_TYPE_INT) {
							int tmp = val?atoi(val):0;
							config_set_int(opt->section, tmp);
							opt->defval = g_strdup_printf("%d", tmp);
						}
						else {
							config_set_string(opt->section, val?val:"");
							opt->defval = val?strdup(val):NULL;
						}
					}
					break;
				case SCRIPT_OPTION_TYPE_BOOL:
					enable = GTK_TOGGLE_BUTTON(opt->widget)->active;
					if (enable != opt->enable) {
						config_set_bool(opt->section, enable);
						debug(4, "set %s/%s=%d", s->data, opt->section, enable);
						opt->enable = enable;
					}
					break;
				case SCRIPT_OPTION_TYPE_INVALID:
					break;
			}
		}

		config_pop_prefix();
	}
}
Exemple #7
0
void scripts_load() {
	GSList* dir;
	GList* s;
	unsigned i;
	char path[PATH_MAX];

	if (!scriptdata) {
		g_datalist_init(&scriptdata);
	}

	/*
	   g_datalist_get_data(&scriptdata, "foo");
	   g_datalist_set_data_full(&scriptdata,"foo",value,g_free);
	*/

	for (dir = scriptdirs; dir; dir = g_slist_next(dir)) {
		GList* s = dir_to_list(dir->data, script_filter);
		scripts = merge_sorted_string_lists(scripts, s);
	}

	for (s = scripts; s; s = g_list_next(s)) {
		unsigned version;
		config_section_iterator* sit;
		Script* script;
		const char* filename = s->data;
		char* errtitle = _("Script error");

		// already known?
		if (g_datalist_get_data(&scriptdata, filename)) {
			continue;
		}

		script = script_new();

		snprintf(path, sizeof(path), "/scripts/%s/General", filename);
		config_push_prefix(path);

		version = config_get_int("xqf version");
		script->summary = config_get_string("summary");
		script->author = config_get_string("author");
		script->license = config_get_string("license");

		config_pop_prefix();

		if (version > MAX_SCRIPT_VERSION) {
			dialog_ok(errtitle, _("Script %s has version %d, xqf only supports version %d."),
					filename, version, MAX_SCRIPT_VERSION);
			script_free(script);
			continue;
		}

		if (!script->summary) {
			dialog_ok(errtitle, _("Script %s missing summary."), filename);
			script_free(script);
			continue;
		}
		if (!script->author) {
			dialog_ok(errtitle, _("Script %s missing author."), filename);
			script_free(script);
			continue;
		}
		if (!script->license) {
			dialog_ok(errtitle, _("Script %s missing license."), filename);
			script_free(script);
			continue;
		}

		script->name = g_strdup(filename);

		snprintf(path, sizeof(path), "/scripts/%s/Action", filename);
		config_push_prefix(path);

		for (i = 0; i < NUM_ACTIONS; ++i) {
			gboolean on = config_get_bool(action_key[i]);
			if (on) {
				action[i] = g_slist_prepend(action[i], script);
			}
		}

		config_pop_prefix();

		// treat script property 'enabled' as option as it has a widget
		// so it's easier to handle later
		{
			ScriptOption* opt;
			snprintf(path, sizeof(path), "/" CONFIG_FILE "/scripts/%s/enabled=false", filename);

			opt = scriptoption_new("bool");
			opt->enable = config_get_bool(path);
			// Translator: whether this plugin script is enabled
			opt->name = _("Enabled");
			opt->section = g_strdup("enabled");
			script->options = g_slist_prepend(script->options, opt);
		}

		snprintf(path, sizeof(path), "/scripts/%s", filename);
		sit = config_init_section_iterator(path);

		while (sit) {
			char* sname = NULL;

			sit = config_section_iterator_next(sit, &sname);

			if (strlen(sname) > 7 && !strncmp(sname, "option ", 7)) {
				char* typestr;
				char* name;
				ScriptOption* opt;
				char settings_path[PATH_MAX];

				snprintf(settings_path, sizeof(settings_path), "/" CONFIG_FILE "/scripts/%s/%s", filename, sname);

				snprintf(path, sizeof(path), "/scripts/%s/%s", filename, sname);
				config_push_prefix(path);

				typestr = config_get_string("type");
				name = config_get_string("name");

				opt = scriptoption_new(typestr);

				g_free(typestr);

				if (!opt || !name) {
					xqf_warning("script %s: invalid option %s", filename, sname+7);
					goto next;
				}

				opt->name = name;
				opt->section = sname;

				switch(opt->type) {
					case SCRIPT_OPTION_TYPE_LIST:
						{
							config_key_iterator* it;

							it = config_init_iterator(path);

							if (!opt->list) {
								opt->list = g_ptr_array_new();
							}

							while (it) {
								char* key = NULL;
								char* val = NULL;

								it = config_iterator_next(it, &key, &val);

								if (!strncmp(key, "value",5)) {
									g_ptr_array_add(opt->list, val);
								}
								else {
									g_free(val);
								}

								g_free(key);
							}
						}
					// fall through
					case SCRIPT_OPTION_TYPE_STRING:
					case SCRIPT_OPTION_TYPE_INT:
						{
							char* defval = NULL;
							char* curval = NULL;

							defval = config_get_string("default");
							curval = config_get_string(settings_path);

							if (curval) {
								opt->defval = g_strdup(curval);
							}
							else if (defval) {
								opt->defval = g_strdup(defval);
							}

							g_free(defval);
							g_free(curval);
						}
						break;
					case SCRIPT_OPTION_TYPE_BOOL:
						{
							gboolean defval;
							gboolean curval;
							int is_deflt = 0;

							defval = config_get_bool("default=false");
							curval = config_get_bool_with_default(settings_path, &is_deflt);

							if (is_deflt) {
								opt->enable = defval;
							}
							else {
								opt->enable = curval;
							}
						}
						break;

					case SCRIPT_OPTION_TYPE_INVALID:
						xqf_error("unreachable code");
						break;
				}

				script->options = g_slist_prepend(script->options, opt);

next:
				config_pop_prefix();
			}
		}

		script->options = g_slist_reverse(script->options);

		g_datalist_set_data_full(&scriptdata, filename, script, (GDestroyNotify)script_free);

		snprintf(path, sizeof(path), "/scripts/%s", filename);
		config_drop_file(path);
	}
}