From: Philip Chimento Date: Sat, 26 Feb 2011 16:15:35 +0000 (+0100) Subject: Introduce preferences file X-Git-Tag: v0.9~136 X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=06f2cc3823e21032a016dfdfd3e53ba558cea69f;p=projects%2Fchimara%2Fchimara.git Introduce preferences file We now use a GSettings object with a custom backend that writes to a configuration file, ~/.chimara. Right now there is only one example setting, "flep". It's easy to bind the setting to a property of another GObject, like the "active" property of a checkbox. Still need to check how other GLib applications install the settings file properly in their Makefile.am, and how to work with a default configuration file such as /etc/chimara if the one in the home directory is not present. --- diff --git a/player/Makefile.am b/player/Makefile.am index ebc4c93..b548e64 100644 --- a/player/Makefile.am +++ b/player/Makefile.am @@ -24,4 +24,10 @@ chimara_CPPFLAGS = $(AM_CPPFLAGS) \ chimara_CFLAGS = @TEST_CFLAGS@ $(AM_CFLAGS) chimara_LDADD = @TEST_LIBS@ $(top_builddir)/libchimara/libchimara.la +schemasdir = $(datadir)/glib-2.0/schemas +dist_schemas_DATA = org.chimara-if.gschema.xml + +install-data-hook: + glib-compile-schemas $(datadir)/glib-2.0/schemas + endif diff --git a/player/chimara.ui b/player/chimara.ui index d9d219c..be9651b 100644 --- a/player/chimara.ui +++ b/player/chimara.ui @@ -381,9 +381,16 @@ Philip Chimento True True - + True - False + True + + + True + False + Turn on flepping + + diff --git a/player/main.c b/player/main.c index ff5c681..01de398 100644 --- a/player/main.c +++ b/player/main.c @@ -40,6 +40,10 @@ #include #include +/* Use a custom GSettings backend for our preferences file */ +#define G_SETTINGS_ENABLE_BACKEND +#include + #include "error.h" #include #include @@ -56,6 +60,7 @@ GtkBuilder *builder = NULL; GtkWidget *aboutwindow = NULL; GtkWidget *prefswindow = NULL; GtkWidget *toolbar = NULL; +GSettings *settings = NULL; GObject * load_object(const gchar *name) @@ -206,7 +211,7 @@ create_window(void) g_signal_connect(glk, "notify::story-name", G_CALLBACK(change_window_title), window); /* Create preferences window */ - //preferences_create(CHIMARA_GLK(glk)); + preferences_create(CHIMARA_GLK(glk)); } int @@ -225,6 +230,11 @@ main(int argc, char *argv[]) gdk_threads_init(); gtk_init(&argc, &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); + create_window(); gtk_widget_show_all(window); diff --git a/player/org.chimara-if.gschema.xml b/player/org.chimara-if.gschema.xml new file mode 100644 index 0000000..be81e95 --- /dev/null +++ b/player/org.chimara-if.gschema.xml @@ -0,0 +1,17 @@ + + + + + + + + false + Flepping + + Whether to flep or not while gronking a bloop. + + + + + \ No newline at end of file diff --git a/player/preferences.c b/player/preferences.c index b7cc3ad..504cbd6 100644 --- a/player/preferences.c +++ b/player/preferences.c @@ -86,6 +86,11 @@ preferences_create(ChimaraGlk *glk) 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 *settings; + GObject *flep = G_OBJECT( load_object("flep") ); + g_settings_bind(settings, "flep", flep, "active", G_SETTINGS_BIND_DEFAULT); } static void