From: Philip Chimento Date: Sun, 6 Mar 2011 21:43:51 +0000 (+0100) Subject: Add preference for graphics file directory X-Git-Tag: v0.9~128 X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=5e4bfcdc9f0082dc12b770868087680bb0fb7626;p=projects%2Fchimara%2Fchimara.git Add preference for graphics file directory You can now set a preference for the default directory in which to look for graphics resource files for older Infocom games. Unfortnately, these resource files still mysteriously don't work, but it's a start. --- diff --git a/player/callbacks.c b/player/callbacks.c index 229ff0c..a4cc173 100644 --- a/player/callbacks.c +++ b/player/callbacks.c @@ -70,7 +70,35 @@ confirm_open_new_game(ChimaraGlk *glk) return TRUE; } -void +/* Internal function: See if there is a corresponding graphics file */ +static void +search_for_graphics_file(const char *filename, ChimaraIF *glk) +{ + + extern GSettings *prefs_settings; + + /* First get the name of the story file */ + char *scratch = g_path_get_basename(filename); + *(strrchr(scratch, '.')) = '\0'; + + /* Check in the stored resource path, if set */ + char *resource_path; + g_settings_get(prefs_settings, "resource-path", "ms", &resource_path); + + /* Otherwise check in the current directory */ + if(!resource_path) + resource_path = g_path_get_dirname(filename); + + char *blorbfile = g_strconcat(resource_path, "/", scratch, ".blb", NULL); + if(g_file_test(blorbfile, G_FILE_TEST_EXISTS)) + g_object_set(glk, "graphics-file", blorbfile, NULL); + + g_free(blorbfile); + g_free(scratch); + g_free(resource_path); +} + +void on_open_activate(GtkAction *action, ChimaraGlk *glk) { GtkWindow *window = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(glk))); @@ -96,27 +124,10 @@ on_open_activate(GtkAction *action, ChimaraGlk *glk) if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { GError *error = NULL; - gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - - /* See if there is a corresponding graphics file */ - /* FIXME: hardcoded path */ - gchar *path = g_path_get_dirname(filename); - gchar *scratch = g_path_get_basename(filename); - *(strrchr(scratch, '.')) = '\0'; - gchar *blorbfile = g_strconcat(path, "/../Resources/", scratch, ".blb", NULL); - if(g_file_test(blorbfile, G_FILE_TEST_EXISTS)) { - g_object_set(glk, "graphics-file", blorbfile, NULL); - g_printerr("Setting graphics file to %s\n", blorbfile); - } - g_free(blorbfile); - g_free(path); - g_free(scratch); + extern GSettings *prefs_settings; + char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - path = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(dialog)); - if(path) { - g_settings_set(state_settings, "last-open-path", "ms", path); - g_free(path); - } + search_for_graphics_file(filename, CHIMARA_IF(glk)); if(!chimara_if_run_game(CHIMARA_IF(glk), filename, &error)) { error_dialog(window, error, _("Could not open game file '%s': "), filename); g_free(filename); @@ -124,6 +135,12 @@ on_open_activate(GtkAction *action, ChimaraGlk *glk) return; } + path = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(dialog)); + if(path) { + g_settings_set(state_settings, "last-open-path", "ms", path); + g_free(path); + } + /* Add file to recent files list */ GtkRecentManager *manager = gtk_recent_manager_get_default(); gchar *uri; @@ -149,29 +166,26 @@ on_recent_item_activated(GtkRecentChooser *chooser, ChimaraGlk *glk) gchar *filename; if(!(filename = g_filename_from_uri(uri, NULL, &error))) { error_dialog(window, error, _("Could not open game file '%s': "), uri); - g_free(uri); - return; + goto finally; } - if(!confirm_open_new_game(glk)) { - g_free(filename); - g_free(uri); - return; - } + if(!confirm_open_new_game(glk)) + goto finally2; + search_for_graphics_file(filename, CHIMARA_IF(glk)); if(!chimara_if_run_game(CHIMARA_IF(glk), filename, &error)) { error_dialog(window, error, _("Could not open game file '%s': "), filename); - g_free(filename); - g_free(uri); - return; + goto finally2; } - g_free(filename); /* Add file to recent files list again, this updates it to most recently used */ GtkRecentManager *manager = gtk_recent_manager_get_default(); if(!gtk_recent_manager_add_item(manager, uri)) g_warning(_("Could not add URI '%s' to recent files list."), uri); - + +finally2: + g_free(filename); +finally: g_free(uri); } diff --git a/player/chimara.ui b/player/chimara.ui index 7a60d05..44fca73 100644 --- a/player/chimara.ui +++ b/player/chimara.ui @@ -842,6 +842,7 @@ Philip Chimento False Where to look for Blorb resource files containing graphics and sound; normally, these are part of the story file itself, but they are provided as separate files in some older games. select-folder + True diff --git a/player/preferences.c b/player/preferences.c index 157a784..f2cbaf0 100644 --- a/player/preferences.c +++ b/player/preferences.c @@ -91,6 +91,13 @@ preferences_create(ChimaraGlk *glk) 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") ); + char *filename; + g_settings_get(prefs_settings, "resource-path", "ms", &filename); + if(filename) { + gtk_file_chooser_set_filename(blorb_chooser, filename); + g_free(filename); + } } static void @@ -240,3 +247,12 @@ on_font_set(GtkFontButton *button, ChimaraGlk *glk) g_object_set(current_tag, "font-desc", font_description, NULL); chimara_glk_update_style(glk); } + +void +on_resource_file_set(GtkFileChooserButton *button, ChimaraGlk *glk) +{ + extern GSettings *prefs_settings; + char *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(button) ); + g_settings_set(prefs_settings, "resource-path", "ms", filename); + g_free(filename); +}