[gnome-games] libgames-support: Add games-settings.[ch]



commit c2a35aec02fada8a8b04e8e237b96e4a41a195d0
Author: Christian Persch <chpe gnome org>
Date:   Tue Sep 7 15:26:58 2010 +0200

    libgames-support: Add games-settings.[ch]
    
    Port them to the final GSettings API, and add them to the build again.

 configure.in                                       |    2 +-
 libgames-support/Makefile.am                       |   14 ++--
 libgames-support/games-settings.c                  |   71 +++++++++-----------
 libgames-support/games-settings.h                  |    7 +--
 .../org.gnome.Games.WindowState.gschema.xml.in     |   17 +++++
 5 files changed, 58 insertions(+), 53 deletions(-)
---
diff --git a/configure.in b/configure.in
index 431432a..09da829 100644
--- a/configure.in
+++ b/configure.in
@@ -576,7 +576,7 @@ PKG_CHECK_MODULES([GIO],[gio-2.0 >= $GIO_REQUIRED],[have_gio_2_26=yes],[have_gio
 
 AM_CONDITIONAL([HAVE_GIO_2_26],[test "$have_gio_2_26" = "yes"])
 
-# GLIB_GSETTINGS([],[:])
+GLIB_GSETTINGS([],[:])
 
 # Check for GNOME modules
 
diff --git a/libgames-support/Makefile.am b/libgames-support/Makefile.am
index c834dd9..ca37a9a 100644
--- a/libgames-support/Makefile.am
+++ b/libgames-support/Makefile.am
@@ -50,12 +50,12 @@ libgames_support_la_SOURCES +=		\
 	$(NULL)
 endif # !HAVE_HILDON
 
-# if HAVE_GIO_2_26
-# libgames_support_la_SOURCES += \
-# 	games-settings.c \
-# 	games-settings.h \
-# 	$(NULL)
-# endif
+if HAVE_GIO_2_26
+libgames_support_la_SOURCES += \
+	games-settings.c \
+	games-settings.h \
+	$(NULL)
+endif
 
 if LIBGAMES_SUPPORT_FULL
 libgames_support_la_SOURCES +=		\
@@ -239,6 +239,6 @@ CLEANFILES += GnomeGamesSupport-1.0.gir $(typelibs_DATA)
 endif # HAVE_INTROSPECTION
 
 @INTLTOOL_XML_NOMERGE_RULE@
-# @GSETTINGS_RULES@
+ GSETTINGS_RULES@
 
 -include $(top_srcdir)/git.mk
diff --git a/libgames-support/games-settings.c b/libgames-support/games-settings.c
index aa1ae6e..183b8cc 100644
--- a/libgames-support/games-settings.c
+++ b/libgames-support/games-settings.c
@@ -3,7 +3,7 @@
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU Lesser General Public License as published by
- *  the Free Software Foundation; either version 2.1, or (at your option)
+ *  the Free Software Foundation; either version 3, or (at your option)
  *  any later version.
  *
  *  This program is distributed in the hope conf it will be useful,
@@ -227,29 +227,28 @@ games_conf_save_accel_map (GamesConf *conf)
 
 #endif /* !HAVE_HILDON */
 
-/**
- * games_settings_new_for_state:
- * @path:
- *
- * Creates a #GSettings object to store window state.
- *
- * Returns: a new #GSettings
- */
-GSettings *
-games_settings_new_for_state (const char *game_name,
-                              const char *path)
+typedef struct {
+  guint keyval;
+  GdkModifierType modifiers;
+} KeyEntry;
+
+static gboolean
+variant_to_keyval (GVariant *value,
+                   gpointer *result,
+                   KeyEntry *entry)
 {
-  char *filename;
+  if (value == NULL) {
+    entry->keyval = GDK_VoidSymbol;
+    entry->modifiers = 0;
+    return TRUE;
+  }
 
-  filename = g_build_filename (g_get_tmp_dir (),
-                               /* FIXME: use g_get_user_cache_dir (),
-                               game_name, */
-                               "gsettings-state.ini",
-                               NULL);
-  g_settings_backend_setup_keyfile ("state", filename);
-  g_free (filename);
+  gtk_accelerator_parse (g_variant_get_string (value, NULL),
+                         &entry->keyval, &entry->modifiers);
+  if (entry->keyval == 0 && entry->modifiers == 0)
+    return FALSE;
 
-  return g_settings_new_with_context_and_path (SCHEMA_NAME, "state", path);
+  return TRUE;
 }
 
 /**
@@ -270,24 +269,16 @@ games_settings_get_keyval (GSettings *settings,
                            guint *keyval,
                            GdkModifierType *modifiers)
 {
-  char *value;
-  guint kv;
-  GdkModifierType km;
+  KeyEntry entry;
 
   g_return_if_fail (G_IS_SETTINGS (settings));
   g_return_if_fail (key != NULL && key[0] != '\0');
 
-  value = g_settings_get_string (settings, key);
-  gtk_accelerator_parse (value, &kv, &km);
-  g_free (value);
-
-  if (kv == 0 && km == 0)
-    kv = GDK_VoidSymbol;
-
+  g_settings_get_mapped (settings, key, (GSettingsGetMapping) variant_to_keyval, &entry);
   if (keyval)
-    *keyval = kv;
+    *keyval = entry.keyval;
   if (modifiers)
-    *modifiers = km;
+    *modifiers = entry.modifiers;
 }
 
 /**
@@ -323,7 +314,7 @@ games_settings_set_keyval (GSettings *settings,
 
 /**
  * games_settings_bind_window_state:
- * @settings: a #GSettings with schema org.gnome.Games.WindowState
+ * @path: a valid #GSettings path
  * @window: a #GtkWindow
  *
  * Restore the window configuration, and persist changes to the window configuration:
@@ -331,7 +322,7 @@ games_settings_set_keyval (GSettings *settings,
  * @window must not be realised yet.
  */
 void
-games_settings_bind_window_state (GSettings *settings,
+games_settings_bind_window_state (const char *path,
                                   GtkWindow *window)
 {
   WindowState *state;
@@ -344,7 +335,7 @@ games_settings_bind_window_state (GSettings *settings,
   state = g_slice_new0 (WindowState);
 
   state->window = window;
-  state->settings = g_object_ref (settings);
+  state->settings = g_settings_new_with_path (SCHEMA_NAME, path);
   g_object_set_data_full (G_OBJECT (window), "GamesSettings::WindowState",
                           state, (GDestroyNotify) free_window_state);
 
@@ -353,10 +344,10 @@ games_settings_bind_window_state (GSettings *settings,
   g_signal_connect (window, "window-state-event",
                     G_CALLBACK (window_state_event_cb), state);
 
-  maximised = g_settings_get_boolean (settings, STATE_KEY_MAXIMIZED);
-  fullscreen = g_settings_get_boolean (settings, STATE_KEY_FULLSCREEN);
-  width = g_settings_get_int (settings, STATE_KEY_WIDTH);
-  height = g_settings_get_int (settings, STATE_KEY_HEIGHT);
+  maximised = g_settings_get_boolean (state->settings, STATE_KEY_MAXIMIZED);
+  fullscreen = g_settings_get_boolean (state->settings, STATE_KEY_FULLSCREEN);
+  width = g_settings_get_int (state->settings, STATE_KEY_WIDTH);
+  height = g_settings_get_int (state->settings, STATE_KEY_HEIGHT);
 
   if (width > 0 && height > 0) {
     _games_debug_print (GAMES_DEBUG_WINDOW_STATE,
diff --git a/libgames-support/games-settings.h b/libgames-support/games-settings.h
index 9523f8b..152d001 100644
--- a/libgames-support/games-settings.h
+++ b/libgames-support/games-settings.h
@@ -3,7 +3,7 @@
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU Lesser General Public License as published by
- *  the Free Software Foundation; either version 2.1, or (at your option)
+ *  the Free Software Foundation; either version 3, or (at your option)
  *  any later version.
  *
  *  This program is distributed in the hope conf it will be useful,
@@ -24,9 +24,6 @@
 
 G_BEGIN_DECLS
 
-GSettings *games_settings_new_for_state (const char *game_name,
-                                         const char *path);
-
 void     games_settings_get_keyval (GSettings *settings,
                                     const char *key,
                                     guint *keyval,
@@ -36,7 +33,7 @@ gboolean games_settings_set_keyval (GSettings *settings,
                                     guint keyval,
                                     GdkModifierType modifiers);
 
-void games_settings_bind_window_state (GSettings *settings,
+void games_settings_bind_window_state (const char *path,
                                        GtkWindow *window);
 
 G_END_DECLS
diff --git a/libgames-support/org.gnome.Games.WindowState.gschema.xml.in b/libgames-support/org.gnome.Games.WindowState.gschema.xml.in
index 9ecb9ca..d643f87 100644
--- a/libgames-support/org.gnome.Games.WindowState.gschema.xml.in
+++ b/libgames-support/org.gnome.Games.WindowState.gschema.xml.in
@@ -1,4 +1,21 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Copyright © 2010 Christian Persch
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 3, or (at your option)
+  any later version.
+
+  This program is distributed in the hope conf it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+-->
 <schemalist>
   <!-- This schema is relocatable -->
   <schema id="org.gnome.Games.WindowState" gettext-domain="gnome-games">



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