Ejemplo n.º 1
0
Archivo: scripts.c Proyecto: IR4T4/xqf
void install_file_dialog_ok_callback (GtkWidget *widget, gpointer data) {
	const char *filename = NULL;
	char dest[PATH_MAX];
	GtkWidget* filesel = topmost_parent(widget);
	const char* msg;

	filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));

	if (!filename) {
		return;
	}

	mkdir((const char*)scriptdirs->data, 0777);

	snprintf(dest, sizeof(dest), "%s/%s", (const char*)scriptdirs->data, g_path_get_basename(filename));

	if (!access(dest, F_OK)) {
		if (!dialog_yesno(NULL, 0, NULL, NULL, _("Script %s already exists, overwrite?"), dest)) {
			return;
		}
	}

	if ((msg = copy_file(filename, dest))) {
		dialog_ok(NULL, "%s", msg);
		return;
	}

	g_datalist_remove_data(&scriptdata, g_path_get_basename(filename));
	scripts_load();

	dialog_ok(NULL, _("Script saved as\n%s\nPlease close and reopen the preferences dialog"), dest);
}
Ejemplo n.º 2
0
static void master_okbutton_callback (GtkWidget *widget, GtkWidget* window) {
	master_check_master_addr_prefix();

	master_addr_result = strdup_strip (gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (master_addr_combo)->entry)));
	master_name_result = strdup_strip (gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (master_name_combo)->entry)));

	config_set_string ("/" CONFIG_FILE "/Add Master/game", type2id (master_type));

	if (!master_addr_result || !master_name_result) {
		dialog_ok (NULL, _("You have to specify a name and an address."));
		return;
	}

	master_to_add = add_master (master_addr_result, master_name_result, master_type, NULL, TRUE, FALSE);
	if (!master_to_add) {
		dialog_ok (NULL, _("Master address \"%s\" is not valid."),
				master_addr_result);
	}
	else {

		if (master_addr_result)
			history_add (master_history_addr, master_addr_result);
		if (master_name_result)
			history_add (master_history_name, master_name_result);

		gtk_widget_destroy(window);
	}
}
Ejemplo n.º 3
0
static void show_pattern_error (int row) {
  GSList *list;
  struct player_pattern *pp;

  list = g_slist_nth (curplrs, row);
  pp = (struct player_pattern *) list->data;

  if (pp->error) {
    dialog_ok (_("XQF: Error"), _("Regular Expression Error!\n\n%s\n\n%s."), 
                                                      pp->pattern, pp->error);
  }
}
Ejemplo n.º 4
0
Archivo: launch.c Proyecto: aufau/xqf
static void client_input_callback (struct running_client *cl, int fd, GdkInputCondition condition) {
	int res;
	int pid;
	char *tmp;

	if (!cl->buffer)
		cl->buffer = g_malloc (CLIENT_ERROR_BUFFER);

	res = read (fd, cl->buffer + cl->pos, CLIENT_ERROR_BUFFER - 1 - cl->pos);

	if (res < 0) {  /* read error or EOF */
		if (errno == EAGAIN || errno == EWOULDBLOCK)
			return;

		client_detach (cl);
		return;
	} else if (res == 0) {
		client_detach (cl);
		return;
	}

	if (cl->pos + res == CLIENT_ERROR_BUFFER - 1) {
		tmp = &cl->buffer[CLIENT_ERROR_BUFFER - 1];
		*tmp = '\0';
	}
	else {
		tmp = memchr (cl->buffer + cl->pos, '\0', res);
		cl->pos += res;
	}

	if (tmp) {
		gdk_input_remove (cl->tag);
		close (cl->fd);
		cl->fd = -1;

		if (!strncmp (cl->buffer, 
					CLIENT_ERROR_MSG_HEAD, strlen (CLIENT_ERROR_MSG_HEAD))) {
			dialog_ok (_("XQF: ERROR!"), _("ERROR!\n\n%s"), 
					cl->buffer + strlen (CLIENT_ERROR_MSG_HEAD));

			pid = cl->pid;                  /* save PID value */
			client_detach (cl);
			if (pid) kill (pid, SIGTERM);    // kill(0) would kill this process too!
		}
		else {
			client_detach (cl);
		}
	}
}
Ejemplo n.º 5
0
Archivo: launch.c Proyecto: aufau/xqf
static void dialog_failed (char *func, char *arg) {
	dialog_ok (_("XQF: ERROR!"), _("ERROR!\n\n%s(%s) failed: %s"), 
			func, (arg)? arg : "", g_strerror (errno));
}
Ejemplo n.º 6
0
Archivo: scripts.c Proyecto: IR4T4/xqf
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);
	}
}