[gnome-games] iagno: port to GSettings



commit 0327105aa114ba479054e2b9e1beff57e27f7d64
Author: Thomas Hindoe Paaboel Andersen <phomes gmail com>
Date:   Sat Jul 30 00:27:49 2011 +0200

    iagno: port to GSettings

 iagno/Makefile.am                    |   19 ++----
 iagno/gnothello.c                    |    9 ++-
 iagno/iagno.schemas.in               |  114 ----------------------------------
 iagno/org.gnome.iagno.gschema.xml.in |   36 +++++++++++
 iagno/properties.c                   |   77 +++++++++--------------
 po/POTFILES.in                       |    2 +-
 6 files changed, 77 insertions(+), 180 deletions(-)
---
diff --git a/iagno/Makefile.am b/iagno/Makefile.am
index b6574de..4027382 100644
--- a/iagno/Makefile.am
+++ b/iagno/Makefile.am
@@ -55,32 +55,25 @@ Gamesdir = $(datadir)/applications
 Games_in_files = iagno.desktop.in.in
 Games_DATA = $(Games_in_files:.desktop.in.in=.desktop)
 
-schema_in_files = iagno.schemas.in
-if HAVE_GNOME
-schemadir = $(GCONF_SCHEMA_FILE_DIR)
-schema_DATA = $(schema_in_files:.schemas.in=.schemas)
-endif
+gsettings_in_file = org.gnome.iagno.gschema.xml.in
+gsettings_SCHEMAS = $(gsettings_in_file:.xml.in=.xml)
+ INTLTOOL_XML_NOMERGE_RULE@
+ GSETTINGS_RULES@
 
 man_MANS = iagno.6
 
 EXTRA_DIST = \
 	AUTHORS \
 	$(pixmap_DATA)	\
-	$(schema_in_files) \
+	$(gsettings_in_file) \
 	$(man_MANS)
 
 CLEANFILES = \
 	$(NULL)
 
-DISTCLEANFILES = $(Games_DATA) $(schema_DATA)
-
-install-data-local:
-if GCONF_SCHEMAS_INSTALL
-	GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-install-rule $(top_builddir)/iagno/$(schema_DATA)
-endif
+DISTCLEANFILES = $(Games_DATA) $(gsettings_in_file)
 
 @INTLTOOL_DESKTOP_RULE@
- INTLTOOL_SCHEMAS_RULE@
 @INTLTOOL_SOUNDLIST_RULE@
 
 -include $(top_srcdir)/git.mk
diff --git a/iagno/gnothello.c b/iagno/gnothello.c
index 83ce31c..ee153c4 100644
--- a/iagno/gnothello.c
+++ b/iagno/gnothello.c
@@ -31,9 +31,9 @@
 #include <gdk/gdkkeysyms.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 
-#include <libgames-support/games-conf.h>
 #include <libgames-support/games-help.h>
 #include <libgames-support/games-runtime.h>
+#include <libgames-support/games-settings.h>
 #include <libgames-support/games-stock.h>
 
 #ifdef WITH_SMCLIENT
@@ -54,6 +54,7 @@
 #define APP_NAME "iagno"
 #define APP_NAME_LONG N_("Iagno")
 
+GSettings *settings;
 GtkWidget *window;
 GtkWidget *statusbar;
 GtkWidget *notebook;
@@ -933,7 +934,7 @@ create_window (void)
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title (GTK_WINDOW (window), _(APP_NAME_LONG));
 
-  games_conf_add_window (GTK_WINDOW (window), NULL);
+  games_settings_bind_window_state ("/org/gnome/iagno/", GTK_WINDOW (window));
 
   vbox = gtk_vbox_new (FALSE, 0);
   gtk_container_add (GTK_CONTAINER (window), vbox);
@@ -1041,7 +1042,7 @@ main (int argc, char **argv)
 
   g_set_application_name (_(APP_NAME_LONG));
 
-  games_conf_initialise (APP_NAME);
+  settings = g_settings_new ("org.gnome.iagno");
 
   games_stock_init ();
 
@@ -1075,7 +1076,7 @@ main (int argc, char **argv)
 
   gtk_main ();
 
-  games_conf_shutdown ();
+  g_settings_sync ();
 
   games_runtime_shutdown ();
 
diff --git a/iagno/org.gnome.iagno.gschema.xml.in b/iagno/org.gnome.iagno.gschema.xml.in
new file mode 100644
index 0000000..7ab3f2f
--- /dev/null
+++ b/iagno/org.gnome.iagno.gschema.xml.in
@@ -0,0 +1,36 @@
+<schemalist>
+  <schema id="org.gnome.iagno" path="/org/gnome/iagno/" gettext-domain="gnome-games">
+    <key name="black-level" type="i">
+      <default>0</default>
+      <range min="0" max="3" />
+    </key>
+    <key name="white-level" type="i">
+      <default>1</default>
+      <range min="0" max="3" />
+    </key>
+    <key name="quick-moves" type="b">
+      <default>false</default>
+    </key>
+    <key name="tileset" type="s">
+      <default>'classic.png'</default>
+    </key>
+    <key name="animate" type="i">
+      <default>2</default>
+      <range min="0" max="2" />
+    </key>
+    <key name="animate-stagger" type="b">
+      <default>false</default>
+    </key>
+    <key name="show-grid" type="b">
+      <default>false</default>
+    </key>
+    <key name="flip-final-results" type="b">
+      <default>true</default>
+    </key>
+    <key name="sound" type="b">
+      <default>true</default>
+      <_summary>Sound</_summary>
+      <_description>Whether or not to play event sounds.</_description>
+    </key>
+  </schema>
+</schemalist>
diff --git a/iagno/properties.c b/iagno/properties.c
index 0469104..4a23a97 100644
--- a/iagno/properties.c
+++ b/iagno/properties.c
@@ -27,7 +27,6 @@
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
-#include <libgames-support/games-conf.h>
 #include <libgames-support/games-frame.h>
 #include <libgames-support/games-files.h>
 #include <libgames-support/games-sound.h>
@@ -38,18 +37,16 @@
 #include "othello.h"
 
 #define KEY_TILESET             "tileset"
-#define KEY_BLACK_LEVEL         "black_level"
-#define KEY_WHITE_LEVEL         "white_level"
-#define KEY_QUICK_MOVES         "quick_moves"
+#define KEY_BLACK_LEVEL         "black-level"
+#define KEY_WHITE_LEVEL         "white-level"
+#define KEY_QUICK_MOVES         "quick-moves"
 #define KEY_ANIMATE             "animate"
-#define KEY_ANIMATE_STAGGER     "animate_stagger"
-#define KEY_SHOW_GRID           "show_grid"
-#define KEY_FLIP_FINAL_RESULTS "flip_final_results"
+#define KEY_ANIMATE_STAGGER     "animate-stagger"
+#define KEY_SHOW_GRID           "show-grid"
+#define KEY_FLIP_FINAL_RESULTS "flip-final-results"
 #define KEY_SOUND               "sound"
 
-#define DEFAULT_TILESET "classic.png"
-
-
+extern GSettings *settings;
 extern GtkWidget *window;
 extern guint black_computer_level;
 extern guint white_computer_level;
@@ -82,27 +79,14 @@ static void apply_changes (void);
  *	It doesn't abide by the HIG.
  */
 
-static gint
-clamp_int (gint input, gint low, gint high)
-{
-  if (input < low)
-    input = low;
-  if (input > high)
-    input = high;
-
-  return input;
-}
-
 void
 load_properties (void)
 {
-  black_computer_level = games_conf_get_integer (NULL, KEY_BLACK_LEVEL, NULL);
-  black_computer_level = clamp_int (black_computer_level, 0, 3);
+  black_computer_level = g_settings_get_int (settings, KEY_BLACK_LEVEL);
 
-  white_computer_level = games_conf_get_integer (NULL, KEY_WHITE_LEVEL, NULL);
-  white_computer_level = clamp_int (white_computer_level, 0, 3);
+  white_computer_level = g_settings_get_int (settings, KEY_WHITE_LEVEL);
 
-  if (games_conf_get_boolean (NULL, KEY_QUICK_MOVES, NULL))
+  if (g_settings_get_boolean (settings, KEY_QUICK_MOVES))
     computer_speed = COMPUTER_MOVE_DELAY / 2;
   else
     computer_speed = COMPUTER_MOVE_DELAY;
@@ -110,19 +94,18 @@ load_properties (void)
   if (tile_set)
     g_free (tile_set);
 
-  tile_set = games_conf_get_string_with_default (NULL, KEY_TILESET, DEFAULT_TILESET);
+  tile_set = g_settings_get_string (settings, KEY_TILESET);
 
-  animate = games_conf_get_integer (NULL, KEY_ANIMATE, NULL);
-  animate = clamp_int (animate, 0, 2);
+  animate = g_settings_get_int (settings, KEY_ANIMATE);
 
-  animate_stagger = games_conf_get_boolean (NULL, KEY_ANIMATE_STAGGER, NULL);
+  animate_stagger = g_settings_get_boolean (settings, KEY_ANIMATE_STAGGER);
 
-  sound = games_conf_get_boolean (NULL, KEY_SOUND, NULL);
+  sound = g_settings_get_boolean (settings, KEY_SOUND);
   games_sound_enable (sound);
 
-  show_grid = games_conf_get_boolean (NULL, KEY_SHOW_GRID, NULL);
+  show_grid = g_settings_get_boolean (settings, KEY_SHOW_GRID);
 
-  flip_final = games_conf_get_boolean (NULL, KEY_FLIP_FINAL_RESULTS, NULL);
+  flip_final = g_settings_get_boolean (settings, KEY_FLIP_FINAL_RESULTS);
 
   switch (animate) {
   case 0:
@@ -141,21 +124,19 @@ load_properties (void)
 static void
 reset_properties (void)
 {
-  black_computer_level = games_conf_get_integer (NULL, KEY_BLACK_LEVEL, NULL);
-  black_computer_level = clamp_int (black_computer_level, 0, 3);
+  black_computer_level = g_settings_get_int (settings, KEY_BLACK_LEVEL);
 
-  white_computer_level = games_conf_get_integer (NULL, KEY_WHITE_LEVEL, NULL);
-  white_computer_level = clamp_int (white_computer_level, 0, 3);
+  white_computer_level = g_settings_get_int (settings, KEY_WHITE_LEVEL);
       
   t_black_computer_level = black_computer_level;
   t_white_computer_level = white_computer_level;
 
-  t_quick_moves = games_conf_get_boolean (NULL, KEY_QUICK_MOVES, NULL);
+  t_quick_moves = g_settings_get_boolean (settings, KEY_QUICK_MOVES);
 
   if (tile_set_tmp)
     g_free (tile_set_tmp);
 
-  tile_set_tmp = games_conf_get_string_with_default (NULL, KEY_TILESET, DEFAULT_TILESET);
+  tile_set_tmp = g_settings_get_string (settings, KEY_TILESET);
 
   t_animate = animate;
   t_animate_stagger = animate_stagger;
@@ -242,19 +223,19 @@ animate_select (GtkWidget * widget, gpointer data)
 static void
 save_properties (void)
 {
-  games_conf_set_integer (NULL, KEY_BLACK_LEVEL, black_computer_level);
-  games_conf_set_integer (NULL, KEY_WHITE_LEVEL, white_computer_level);
+  g_settings_set_int (settings, KEY_BLACK_LEVEL, black_computer_level);
+  g_settings_set_int (settings, KEY_WHITE_LEVEL, white_computer_level);
 
-  games_conf_set_boolean (NULL, KEY_QUICK_MOVES, t_quick_moves);
+  g_settings_set_boolean (settings, KEY_QUICK_MOVES, t_quick_moves);
 
-  games_conf_set_string (NULL, KEY_TILESET, tile_set_tmp);
+  g_settings_set_string (settings, KEY_TILESET, tile_set_tmp);
 
-  games_conf_set_integer (NULL, KEY_ANIMATE, animate);
+  g_settings_set_int (settings, KEY_ANIMATE, animate);
 
-  games_conf_set_boolean (NULL, KEY_ANIMATE_STAGGER, animate_stagger);
-  games_conf_set_boolean (NULL, KEY_SHOW_GRID, show_grid);
-  games_conf_set_boolean (NULL, KEY_FLIP_FINAL_RESULTS, flip_final);
-  games_conf_set_boolean (NULL, KEY_SOUND, sound);
+  g_settings_set_boolean (settings, KEY_ANIMATE_STAGGER, animate_stagger);
+  g_settings_set_boolean (settings, KEY_SHOW_GRID, show_grid);
+  g_settings_set_boolean (settings, KEY_FLIP_FINAL_RESULTS, flip_final);
+  g_settings_set_boolean (settings, KEY_SOUND, sound);
 }
 
 static void
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c613615..fffc82c 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -96,7 +96,7 @@ gtali/setup.c
 gtali/yahtzee.c
 iagno/gnothello.c
 iagno/iagno.desktop.in.in
-iagno/iagno.schemas.in
+iagno/org.gnome.iagno.gschema.xml.in
 iagno/othello.c
 iagno/properties.c
 libgames-support/eggdesktopfile.c



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]