From: Philip Chimento Date: Sun, 27 Feb 2011 11:49:48 +0000 (+0100) Subject: Add 'state' settings; add last opened path setting X-Git-Tag: v0.9~134 X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=39b9e14c0e3c11a4b6df8c22ac4a554e2aae9720;p=projects%2Fchimara%2Fchimara.git Add 'state' settings; add last opened path setting The settings file now discriminates between 'preferences' settings, which the user sets from the preferences dialog, and 'state' settings, which are things remembered by the program. As an example state setting, the program now remembers the last path a game was opened from, and automatically starts the file chooser in that path when opening a game. --- diff --git a/player/callbacks.c b/player/callbacks.c index 3013800..229ff0c 100644 --- a/player/callbacks.c +++ b/player/callbacks.c @@ -84,6 +84,16 @@ on_open_activate(GtkAction *action, ChimaraGlk *glk) GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); + + /* Get last opened path */ + extern GSettings *state_settings; + gchar *path; + g_settings_get(state_settings, "last-open-path", "ms", &path); + if(path) { + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path); + g_free(path); + } + if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { GError *error = NULL; gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); @@ -102,6 +112,11 @@ on_open_activate(GtkAction *action, ChimaraGlk *glk) g_free(path); g_free(scratch); + 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); + } if(!chimara_if_run_game(CHIMARA_IF(glk), filename, &error)) { error_dialog(window, error, _("Could not open game file '%s': "), filename); g_free(filename); diff --git a/player/main.c b/player/main.c index 01de398..70bad3b 100644 --- a/player/main.c +++ b/player/main.c @@ -60,7 +60,8 @@ GtkBuilder *builder = NULL; GtkWidget *aboutwindow = NULL; GtkWidget *prefswindow = NULL; GtkWidget *toolbar = NULL; -GSettings *settings = NULL; +GSettings *prefs_settings = NULL; +GSettings *state_settings = NULL; GObject * load_object(const gchar *name) @@ -232,8 +233,9 @@ main(int argc, char *argv[]) /* Initialize settings file */ gchar *keyfile = g_build_filename(g_get_home_dir(), ".chimara", NULL); - GSettingsBackend *backend = g_keyfile_settings_backend_new(keyfile, "/", "player"); - settings = g_settings_new_with_backend("org.chimara-if.chimara-player", backend); + 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); create_window(); gtk_widget_show_all(window); diff --git a/player/org.chimara-if.gschema.xml b/player/org.chimara-if.gschema.xml index be81e95..4e2fc56 100644 --- a/player/org.chimara-if.gschema.xml +++ b/player/org.chimara-if.gschema.xml @@ -1,10 +1,15 @@ - - - - - + + + + + + + + + + false Flepping @@ -12,6 +17,19 @@ Whether to flep or not while gronking a bloop. - + + + + + + + nothing + Last open path + + The path in which a game was last opened. The next Open dialog will + start in this path. + + + \ No newline at end of file diff --git a/player/preferences.c b/player/preferences.c index 504cbd6..afb34a4 100644 --- a/player/preferences.c +++ b/player/preferences.c @@ -88,9 +88,9 @@ preferences_create(ChimaraGlk *glk) g_signal_connect(selection, "changed", G_CALLBACK(style_tree_select_callback), glk); /* Bind the preferences to the entries in the preferences file */ - extern GSettings *settings; + extern GSettings *prefs_settings; GObject *flep = G_OBJECT( load_object("flep") ); - g_settings_bind(settings, "flep", flep, "active", G_SETTINGS_BIND_DEFAULT); + g_settings_bind(prefs_settings, "flep", flep, "active", G_SETTINGS_BIND_DEFAULT); } static void