Add 'state' settings; add last opened path setting
authorPhilip Chimento <philip.chimento@gmail.com>
Sun, 27 Feb 2011 11:49:48 +0000 (12:49 +0100)
committerPhilip Chimento <philip.chimento@gmail.com>
Sun, 27 Feb 2011 11:49:48 +0000 (12:49 +0100)
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.

player/callbacks.c
player/main.c
player/org.chimara-if.gschema.xml
player/preferences.c

index 3013800baafaca0471649e3efb8c065a0bda678b..229ff0cbcfe9b92f651aa4421220e108954f7fea 100644 (file)
@@ -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);
index 01de3982e1b8199815c8483dd43f776e1612f25d..70bad3b3941ae4062058548fec4631e0a942cccc 100644 (file)
@@ -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);
index be81e951a12ef006c45048950dfe8fd1200b6c5d..4e2fc56de251d97dd79d6fde05731569d73016a6 100644 (file)
@@ -1,10 +1,15 @@
 <schemalist>
-  <schema id="org.chimara-if.chimara-player" path="/">
-    
-    <!-- Keys and key names are subject to change without notice, until we have
-     a spec-->
-    <!-- "b" = boolean; see documentation of GVariantType -->
-    
+  <!-- Keys and key names are subject to change without notice, until we have
+  a spec-->
+  <!-- "b" = boolean; see documentation of GVariantType -->
+
+  <schema id="org.chimara-if.player" path="/org/chimara-if/player/">
+    <child name="preferences" schema="org.chimara-if.player.preferences"/>
+    <child name="state" schema="org.chimara-if.player.state"/>
+  </schema>
+
+  <schema id="org.chimara-if.player.preferences" path="/org/chimara-if/player/preferences/">
+
     <key name="flep" type="b"> 
       <default>false</default>
       <summary>Flepping</summary>
         Whether to flep or not while gronking a bloop.
       </description>
     </key>
-  
+
+  </schema>
+
+  <schema id="org.chimara-if.player.state" path="/org/chimara-if/player/state/">
+
+    <key name="last-open-path" type="ms">
+      <default>nothing</default>
+      <summary>Last open path</summary>
+      <description>
+        The path in which a game was last opened. The next Open dialog will
+        start in this path.
+      </description>
+    </key>
+
   </schema>
 </schemalist>
\ No newline at end of file
index 504cbd6227e31fb5ad70089c35f82fd49beb76ee..afb34a476c30a0961f4385e29a9e722ddb87489c 100644 (file)
@@ -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