[hitori] Store board size in gsettings
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [hitori] Store board size in gsettings
- Date: Mon, 7 Jul 2014 12:55:27 +0000 (UTC)
commit e82fe40dcd1755d1196de5a0c83d2f133706891e
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Sat Jul 5 18:54:52 2014 -0500
Store board size in gsettings
Remember the user's preferred board size
* Bump GLib dependency to 2.32, for g_settings_get_action()
* Bump intltool dependency to 0.50.2, for automatic gsettings support
https://bugzilla.gnome.org/show_bug.cgi?id=732504
Makefile.am | 5 +++++
configure.ac | 7 +++++--
data/org.gnome.hitori.gschema.xml | 10 ++++++++++
src/interface.c | 27 +++++++++++----------------
src/main.c | 8 +++++++-
src/main.h | 2 ++
6 files changed, 40 insertions(+), 19 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 37fd25a..9be7a14 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -78,6 +78,10 @@ css_DATA = data/hitori.css
uidir = $(datadir)/hitori
ui_DATA = data/hitori.ui
+# GSettings
+gsettings_SCHEMAS = data/org.gnome.hitori.gschema.xml
+ GSETTINGS_RULES@
+
# Desktop file
# We can't use INTLTOOL_DESKTOP_RULE here due to lp#605826
%.desktop: %.desktop.in
@@ -89,6 +93,7 @@ desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
EXTRA_DIST += \
$(css_DATA) \
+ $(gsettings_SCHEMAS) \
$(ui_DATA) \
$(desktop_in_files) \
$(NULL)
diff --git a/configure.ac b/configure.ac
index 8905693..300c55c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,7 +22,10 @@ AM_CONDITIONAL([DEBUG],[test "$debug" = "yes"])
GETTEXT_PACKAGE=hitori
AC_SUBST([GETTEXT_PACKAGE])
AC_DEFINE_UNQUOTED([GETTEXT_PACKAGE],["$GETTEXT_PACKAGE"],[gettext package name])
-IT_PROG_INTLTOOL([0.35.0])
+IT_PROG_INTLTOOL([0.50.2])
+
+# GSettings
+GLIB_GSETTINGS
# Documentation
YELP_HELP_INIT
@@ -31,7 +34,7 @@ YELP_HELP_INIT
APPDATA_XML
# Dependencies
-PKG_CHECK_MODULES([GENERAL],[glib-2.0 gtk+-3.0 >= 3.13.2 gmodule-2.0 cairo >= 1.4])
+PKG_CHECK_MODULES([GENERAL],[glib-2.0 gio-2.0 >= 2.32 gtk+-3.0 >= 3.13.2 gmodule-2.0 cairo >= 1.4])
# Output!
AC_CONFIG_FILES([
diff --git a/data/org.gnome.hitori.gschema.xml b/data/org.gnome.hitori.gschema.xml
new file mode 100644
index 0000000..206bf87
--- /dev/null
+++ b/data/org.gnome.hitori.gschema.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schemalist>
+ <schema id="org.gnome.hitori" path="/org/gnome/hitori/" gettext-domain="hitori">
+ <key name="board-size" type="s">
+ <default>"5"</default>
+ <summary>Board size</summary>
+ <description>The size of the board, in cells.</description>
+ </key>
+ </schema>
+</schemalist>
diff --git a/src/interface.c b/src/interface.c
index fe7d7cc..aaf18c3 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -49,12 +49,10 @@ static void redo_cb (GSimpleAction *action, GVariant *parameter, gpointer user_d
static void quit_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
static void help_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
static void about_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
-static void board_size_activate_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
-static void board_size_change_cb (GSimpleAction *action, GVariant *state, gpointer user_data);
+static void board_size_change_cb (GObject *object, GParamSpec *pspec, gpointer user_data);
static GActionEntry app_entries[] = {
{ "new-game", new_game_cb, NULL, NULL, NULL },
- { "board-size", board_size_activate_cb, "s", "'5'", board_size_change_cb },
{ "about", about_cb, NULL, NULL, NULL },
{ "help", help_cb, NULL, NULL, NULL },
{ "quit", quit_cb, NULL, NULL, NULL },
@@ -75,6 +73,7 @@ hitori_create_interface (Hitori *hitori)
GtkCssProvider *css_provider;
const PangoFontDescription *font;
GMenuModel *app_menu; /* owned */
+ GAction *action;
builder = gtk_builder_new ();
@@ -116,6 +115,11 @@ hitori_create_interface (Hitori *hitori)
g_action_map_add_action_entries (G_ACTION_MAP (hitori), app_entries, G_N_ELEMENTS (app_entries),
hitori);
g_action_map_add_action_entries (G_ACTION_MAP (hitori->window), win_entries, G_N_ELEMENTS
(win_entries), hitori);
+ action = g_settings_create_action (hitori->settings, "board-size");
+ g_action_map_add_action (G_ACTION_MAP (hitori), action);
+ g_signal_connect (G_OBJECT (action), "notify::state", (GCallback) board_size_change_cb, hitori);
+ g_object_unref (action);
+
hitori->undo_action = G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (hitori->window),
"undo"));
hitori->redo_action = G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (hitori->window),
"redo"));
hitori->hint_action = G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (hitori->window),
"hint"));
@@ -145,9 +149,6 @@ hitori_create_interface (Hitori *hitori)
g_simple_action_set_enabled (hitori->undo_action, FALSE);
g_simple_action_set_enabled (hitori->redo_action, FALSE);
- /* Set the initial board size. */
- g_simple_action_set_state (G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (hitori),
"board-size")), g_variant_new_string ("5"));
-
return hitori->window;
}
@@ -694,21 +695,15 @@ about_cb (GSimpleAction *action, GVariant *parameters, gpointer user_data)
}
static void
-board_size_activate_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data)
-{
- g_action_change_state (G_ACTION (action), parameter);
-}
-
-static void
-board_size_change_cb (GSimpleAction *action, GVariant *state, gpointer user_data)
+board_size_change_cb (GObject *object, GParamSpec *pspec, gpointer user_data)
{
HitoriApplication *self = HITORI_APPLICATION (user_data);
- const gchar *size_str;
+ gchar *size_str;
guint64 size;
- size_str = g_variant_get_string (state, NULL);
+ size_str = g_settings_get_string (self->settings, "board-size");
size = g_ascii_strtoull (size_str, NULL, 10);
hitori_set_board_size (self, size);
- g_simple_action_set_state (action, state);
+ g_free (size_str);
}
diff --git a/src/main.c b/src/main.c
index b59835a..b67befa 100644
--- a/src/main.c
+++ b/src/main.c
@@ -171,10 +171,14 @@ activate (GApplication *application)
/* Create the interface. */
if (self->window == NULL) {
HitoriUndo *undo;
+ gchar *size_str;
/* Setup */
self->debug = priv->debug;
- self->board_size = DEFAULT_BOARD_SIZE;
+ self->settings = g_settings_new ("org.gnome.hitori");
+ size_str = g_settings_get_string (self->settings, "board-size");
+ self->board_size = g_ascii_strtoull (size_str, NULL, 10);
+ g_free (size_str);
undo = g_new0 (HitoriUndo, 1);
undo->type = UNDO_NEW_GAME;
@@ -436,6 +440,8 @@ hitori_quit (Hitori *hitori)
if (hitori->painted_font_desc != NULL)
pango_font_description_free (hitori->painted_font_desc);
+ g_object_unref (hitori->settings);
+
g_application_quit (G_APPLICATION (hitori));
}
diff --git a/src/main.h b/src/main.h
index 95357a6..ad62752 100644
--- a/src/main.h
+++ b/src/main.h
@@ -105,6 +105,8 @@ typedef struct {
guint timer_value; /* seconds into the game */
GtkLabel *timer_label;
guint timeout_id;
+
+ GSettings *settings;
} HitoriApplication;
typedef struct {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]