예제 #1
0
void
on_interpreter_cell_changed(GtkCellRendererCombo *combo, char *path_string, GtkTreeIter *new_iter, ChimaraGlk *glk)
{
	unsigned int format, interpreter;
	format = (unsigned int)strtol(path_string, NULL, 10);
	GtkTreeModel *combo_model;
	g_object_get(combo, "model", &combo_model, NULL);
	char *combo_string = gtk_tree_model_get_string_from_iter(combo_model, new_iter);
	interpreter = (unsigned int)strtol(combo_string, NULL, 10);
	g_free(combo_string);

	chimara_if_set_preferred_interpreter(CHIMARA_IF(glk), format, interpreter);

	/* Display the new setting in the list */
	GtkTreeIter iter;
	GtkTreePath *path = gtk_tree_path_new_from_string(path_string);
	gtk_tree_model_get_iter(GTK_TREE_MODEL(preferred_list), &iter, path);
	gtk_tree_path_free(path);
	gtk_list_store_set(preferred_list, &iter,
		1, interpreter_to_display_string(interpreter),
		-1);

	/* Save the new settings in the preferences file */
	extern GSettings *prefs_settings;
	GVariantBuilder *builder = g_variant_builder_new( G_VARIANT_TYPE("a{ss}") );
	unsigned int count;
	for(count = 0; count < CHIMARA_IF_NUM_FORMATS; count++) {
		g_variant_builder_add(builder, "{ss}",
			format_to_string(count),
			interpreter_to_string(chimara_if_get_preferred_interpreter(CHIMARA_IF(glk), count)));
	}
	g_settings_set(prefs_settings, "preferred-interpreters", "a{ss}", builder);
	g_variant_builder_unref(builder);
}
예제 #2
0
파일: main.c 프로젝트: chimara/Chimara
static void
on_open(GApplication *gapp, GFile **files, int n_files, char *hint)
{
	GError *error = NULL;

	if(n_files == 2) {
		char *graphics_file_path = g_file_get_path(files[1]);
		g_object_set(glk, "graphics-file", graphics_file_path, NULL);
		g_free(graphics_file_path);
	}
	if(n_files >= 1) {
		if( !chimara_if_run_game_file(CHIMARA_IF(glk), files[0], &error) ) {
			error_dialog(GTK_WINDOW(window), error, "Error starting Glk library: ");
			g_application_quit(gapp);
		}
	}
	on_activate(gapp);
}
예제 #3
0
파일: main.c 프로젝트: imclab/Chimara
int
main(int argc, char *argv[])
{
	GError *error = NULL;

#ifdef ENABLE_NLS
	bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
	textdomain(GETTEXT_PACKAGE);
#endif

	gdk_threads_init();
	gtk_init(&argc, &argv);

	/* Create configuration dir ~/.chimara */
	gchar *configdir = g_build_filename(g_get_home_dir(), ".chimara", NULL);
	if(!g_file_test(configdir, G_FILE_TEST_IS_DIR)
		&& g_mkdir(configdir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
		g_error(_("Cannot create configuration directory ~/.chimara"));
	g_free(configdir);

	/* Initialize settings file; it can be overridden by a "chimara-config" file
	 in the current directory */
	gchar *keyfile;
	if(g_file_test("chimara-config", G_FILE_TEST_IS_REGULAR))
		keyfile = g_strdup("chimara-config");
	else
		keyfile = g_build_filename(g_get_home_dir(), ".chimara", "config", NULL);
	GSettingsBackend *backend = g_keyfile_settings_backend_new(keyfile, "/org/chimara-if/player/", NULL);
	prefs_settings = g_settings_new_with_backend("org.chimara-if.player.preferences", backend);
	state_settings = g_settings_new_with_backend("org.chimara-if.player.state", backend);
	g_free(keyfile);

	if( !create_window() ) {
		error_dialog(NULL, NULL, "Error while building interface.");
		return 1;
	}
	gtk_widget_show_all(window);

	g_object_unref( G_OBJECT(uimanager) );

	if(argc == 3) {
		g_object_set(glk, "graphics-file", argv[2], NULL);
	}
	if(argc >= 2) {
		if( !chimara_if_run_game(CHIMARA_IF(glk), argv[1], &error) ) {
	   		error_dialog(GTK_WINDOW(window), error, "Error starting Glk library: ");
			return 1;
		}
	}

    gdk_threads_enter();
	gtk_main();
	gdk_threads_leave();

	chimara_glk_stop(CHIMARA_GLK(glk));
	chimara_glk_wait(CHIMARA_GLK(glk));

	g_object_unref( G_OBJECT(builder) );

	return 0;
}
예제 #4
0
/* Create the preferences dialog. */
void
preferences_create(ChimaraGlk *glk)
{
	/* Initialize the tree of style names */
	GtkTreeStore *style_list = GTK_TREE_STORE( load_object("style-list") );
	GtkTreeIter buffer, grid, buffer_child, grid_child;

	gtk_tree_store_append(style_list, &buffer, NULL);
	gtk_tree_store_append(style_list, &grid, NULL);
	gtk_tree_store_set(style_list, &buffer, 0, "Text buffer", -1);
	gtk_tree_store_set(style_list, &grid, 0, "Text grid", -1);

	unsigned i, num_tags;
	const char * const *tag_names = chimara_glk_get_tag_names(glk, &num_tags);
	for(i=0; i<num_tags; i++) {
		gtk_tree_store_append(style_list, &buffer_child, &buffer);
		gtk_tree_store_append(style_list, &grid_child, &grid);
		gtk_tree_store_set(style_list, &buffer_child, 0, tag_names[i], -1);
		gtk_tree_store_set(style_list, &grid_child, 0, tag_names[i], -1);
	}

	/* Set selection mode to single select */
	GtkTreeView *view = GTK_TREE_VIEW( load_object("style-treeview") );
	GtkTreeSelection *selection = gtk_tree_view_get_selection(view);
	gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
	g_signal_connect(selection, "changed", G_CALLBACK(style_tree_select_callback), glk);

	/* Bind the preferences to the entries in the preferences file */
	extern GSettings *prefs_settings;
	GObject *flep = G_OBJECT( load_object("flep") );
	g_settings_bind(prefs_settings, "flep", flep, "active", G_SETTINGS_BIND_DEFAULT);
	GtkFileChooser *blorb_chooser = GTK_FILE_CHOOSER( load_object("blorb_file_chooser") );
	GtkFileChooser *css_chooser = GTK_FILE_CHOOSER( load_object("css-filechooser") );
	char *filename;
	g_settings_get(prefs_settings, "resource-path", "ms", &filename);
	if(filename) {
		gtk_file_chooser_set_filename(blorb_chooser, filename);
		g_free(filename);
	}
	g_settings_get(prefs_settings, "css-file", "ms", &filename);
	if(filename) {
		if(!chimara_glk_set_css_from_file(glk, filename, NULL)) {
			/* If the setting didn't point to a CSS file, fail silently and
			 null the setting */
			g_settings_set(prefs_settings, "css-file", "ms", NULL);
		} else {
			gtk_file_chooser_set_filename(css_chooser, filename);
		}
		g_free(filename);
	}

	/* Populate the list of available interpreters */
	GtkListStore *interp_list = GTK_LIST_STORE( load_object("available_interpreters") );
	unsigned int count;
	GtkTreeIter tree_iter;
	for(count = 0; count < CHIMARA_IF_NUM_INTERPRETERS; count++) {
		gtk_list_store_append(interp_list, &tree_iter);
		gtk_list_store_set(interp_list, &tree_iter,
			0, interpreter_to_display_string(count),
			-1);
	}

	/* Get the list of preferred interpreters from the preferences */
	GVariantIter *iter;
	char *format, *plugin;
	g_settings_get(prefs_settings, "preferred-interpreters", "a{ss}", &iter);
	while(g_variant_iter_loop(iter, "{ss}", &format, &plugin)) {
		ChimaraIFFormat format_num = parse_format(format);
		if(format_num == CHIMARA_IF_FORMAT_NONE)
			continue;
		ChimaraIFInterpreter interp_num = parse_interpreter(plugin);
		if(interp_num == CHIMARA_IF_INTERPRETER_NONE)
			continue;
		chimara_if_set_preferred_interpreter(CHIMARA_IF(glk), format_num, interp_num);
	}
	g_variant_iter_free(iter);

	/* Display it all in the list */
	preferred_list = GTK_LIST_STORE( load_object("interpreters") );
	for(count = 0; count < CHIMARA_IF_NUM_FORMATS; count++) {
		gtk_list_store_append(preferred_list, &tree_iter);
		gtk_list_store_set(preferred_list, &tree_iter,
			0, format_to_display_string(count),
			1, interpreter_to_display_string(chimara_if_get_preferred_interpreter(CHIMARA_IF(glk), count)),
			-1);
	}
}