[gnome-screensaver] Prepare preferences move to gsettings-desktop-schemas



commit c5df3be7e2c78ef6d684d3e5fbe090c0bc8a40f2
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Feb 7 17:58:17 2011 +0000

    Prepare preferences move to gsettings-desktop-schemas
    
    Use uint for timeouts as they don't support negative values anyway,
    use enum from gsettings-desktop-schemas for operation mode.

 configure.ac                                 |    7 ++-
 data/org.gnome.screensaver.gschema.xml.in.in |   17 ++----
 src/gs-prefs.c                               |   75 ++++++++++++++------------
 3 files changed, 51 insertions(+), 48 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 6edc290..6f72f96 100644
--- a/configure.ac
+++ b/configure.ac
@@ -44,6 +44,7 @@ GTK_REQUIRED_VERSION=2.99.3
 X11_REQUIRED_VERSION=1.0
 LIBGNOME_MENU_REQUIRED_VERSION=2.11.1
 GNOME_DESKTOP_REQUIRED_VERSION=2.91.5
+GSETTINGS_DESKTOP_SCHEMAS_REQUIRED_VERSION=0.1.7
 
 LIBGNOMEKBDUI_REQUIRED_VERSION=0.1
 
@@ -60,7 +61,8 @@ PKG_CHECK_MODULES(GNOME_SCREENSAVER,
         gtk+-3.0 >= $GTK_REQUIRED_VERSION
         dbus-glib-1 >= $DBUS_REQUIRED_VERSION
         gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION
-        libgnome-menu >= $LIBGNOME_MENU_REQUIRED_VERSION)
+        libgnome-menu >= $LIBGNOME_MENU_REQUIRED_VERSION
+        gsettings-desktop-schemas >= $GSETTINGS_DESKTOP_SCHEMAS_REQUIRED_VERSION)
 AC_SUBST(GNOME_SCREENSAVER_CFLAGS)
 AC_SUBST(GNOME_SCREENSAVER_LIBS)
 
@@ -73,7 +75,8 @@ AC_SUBST(GNOME_SCREENSAVER_DIALOG_LIBS)
 PKG_CHECK_MODULES(GNOME_SCREENSAVER_CAPPLET,
         gio-2.0 >= $GLIB_REQUIRED_VERSION
         gtk+-3.0 >= $GTK_REQUIRED_VERSION
-        libgnome-menu >= $LIBGNOME_MENU_REQUIRED_VERSION)
+        libgnome-menu >= $LIBGNOME_MENU_REQUIRED_VERSION
+        gsettings-desktop-schemas >= $GSETTINGS_DESKTOP_SCHEMAS_REQUIRED_VERSION)
 AC_SUBST(GNOME_SCREENSAVER_CAPPLET_CFLAGS)
 AC_SUBST(GNOME_SCREENSAVER_CAPPLET_LIBS)
 
diff --git a/data/org.gnome.screensaver.gschema.xml.in.in b/data/org.gnome.screensaver.gschema.xml.in.in
index 3d1eef3..d3a33ea 100644
--- a/data/org.gnome.screensaver.gschema.xml.in.in
+++ b/data/org.gnome.screensaver.gschema.xml.in.in
@@ -1,9 +1,4 @@
 <schemalist>
-  <enum id="org.gnome.screensaver.Mode">
-    <value nick="blank-only" value="0"/>
-    <value nick="random" value="1"/>
-    <value nick="single" value="2"/>
-  </enum>
   <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.screensaver" path="/org/gnome/screensaver/">
     <key name="idle-activation-enabled" type="b">
       <default>true</default>
@@ -15,7 +10,7 @@
       <summary>Lock on activation</summary>
       <description>Set this to TRUE to lock the screen when the screensaver goes active.</description>
     </key>
-    <key name="mode" enum="org.gnome.screensaver.Mode">
+    <key name="mode" enum="org.gnome.desktop.GDesktopScreensaverMode">
       <default>'blank-only'</default>
       <summary>Screensaver theme selection mode</summary>
       <description>The selection mode used by screensaver.  May be "blank-only" to enable the screensaver without using any theme on activation, "single" to enable screensaver using only one theme on activation (specified in "themes" key), and "random" to enable the screensaver using a random theme on activation.</description>
@@ -25,22 +20,22 @@
       <summary>Screensaver themes</summary>
       <description>This key specifies the list of themes to be used by the screensaver. It's ignored when "mode" key is  "blank-only", should provide the theme name when "mode" is "single", and should provide a list of themes when "mode" is "random".</description>
     </key>
-    <key name="idle-delay" type="i">
+    <key name="idle-delay" type="u">
       <default>10</default>
       <summary>Time before session is considered idle</summary>
       <description>The number of minutes of inactivity before the session is considered idle.</description>
     </key>
-    <key name="power-management-delay" type="i">
+    <key name="power-management-delay" type="u">
       <default>30</default>
       <summary>Time before power management baseline</summary>
       <description>The number of seconds of inactivity before signalling to power management.  This key is set and maintained by the session power management agent.</description>
     </key>
-    <key name="cycle-delay" type="i">
+    <key name="cycle-delay" type="u">
       <default>10</default>
       <summary>Time before theme change</summary>
       <description>The number of minutes to run before changing the screensaver theme.</description>
     </key>
-    <key name="lock-delay" type="i">
+    <key name="lock-delay" type="u">
       <default>0</default>
       <summary>Time before locking</summary>
       <description>The number of minutes after screensaver activation before locking the screen.</description>
@@ -60,7 +55,7 @@
       <summary>Allow logout</summary>
       <description>Set this to TRUE to offer an option in the unlock dialog to allow logging out after a delay.  The delay is specified in the "logout_delay" key.</description>
     </key>
-    <key name="logout-delay" type="i">
+    <key name="logout-delay" type="u">
       <default>120</default>
       <summary>Time before logout option</summary>
       <description>The number of minutes after the screensaver activation before a logout option will appear in the unlock dialog. This key has effect only if the "logout_enable" key is set to TRUE.</description>
diff --git a/src/gs-prefs.c b/src/gs-prefs.c
index f937606..a98af1a 100644
--- a/src/gs-prefs.c
+++ b/src/gs-prefs.c
@@ -27,6 +27,7 @@
 #include <glib.h>
 #include <glib-object.h>
 #include <gio/gio.h>
+#include <gdesktop-enums.h>
 
 #include "gs-prefs.h"
 
@@ -129,7 +130,7 @@ gs_prefs_class_init (GSPrefsClass *klass)
 
 static void
 _gs_prefs_set_timeout (GSPrefs *prefs,
-                       int      value)
+                       guint    value)
 {
         if (value < 1)
                 value = 10;
@@ -144,7 +145,7 @@ _gs_prefs_set_timeout (GSPrefs *prefs,
 
 static void
 _gs_prefs_set_power_timeout (GSPrefs *prefs,
-                             int      value)
+                             guint    value)
 {
         if (value < 1)
                 value = 60;
@@ -160,11 +161,8 @@ _gs_prefs_set_power_timeout (GSPrefs *prefs,
 
 static void
 _gs_prefs_set_lock_timeout (GSPrefs *prefs,
-                            int      value)
+                            guint    value)
 {
-        if (value < 0)
-                value = 0;
-
         /* pick a reasonable large number for the
            upper bound */
         if (value > 480)
@@ -175,7 +173,7 @@ _gs_prefs_set_lock_timeout (GSPrefs *prefs,
 
 static void
 _gs_prefs_set_cycle_timeout (GSPrefs *prefs,
-                             int      value)
+                             guint    value)
 {
         if (value < 1)
                 value = 1;
@@ -189,8 +187,8 @@ _gs_prefs_set_cycle_timeout (GSPrefs *prefs,
 }
 
 static void
-_gs_prefs_set_mode (GSPrefs    *prefs,
-                    gint        mode)
+_gs_prefs_set_mode (GSPrefs                 *prefs,
+                    GDesktopScreensaverMode  mode)
 {
         prefs->mode = mode;
 }
@@ -291,11 +289,8 @@ _gs_prefs_set_logout_command (GSPrefs    *prefs,
 
 static void
 _gs_prefs_set_logout_timeout (GSPrefs *prefs,
-                              int      value)
+                              guint    value)
 {
-        if (value < 0)
-                value = 0;
-
         /* pick a reasonable large number for the
            upper bound */
         if (value > 480)
@@ -311,14 +306,24 @@ _gs_prefs_set_user_switch_enabled (GSPrefs *prefs,
         prefs->user_switch_enabled = value;
 }
 
+static guint
+_gs_settings_get_uint (GSettings  *settings,
+		       const char *key)
+{
+  guint value;
+
+  g_settings_get (settings, key, "u", &value);
+  return value;
+}
+
 static void
 gs_prefs_load_from_settings (GSPrefs *prefs)
 {
-        glong    value;
+        guint    uvalue;
         gboolean bvalue;
         char    *string;
         gchar  **strv;
-        gint     mode;
+        GDesktopScreensaverMode mode;
 
         bvalue = g_settings_get_boolean (prefs->priv->settings, KEY_IDLE_ACTIVATION_ENABLED);
         _gs_prefs_set_idle_activation_enabled (prefs, bvalue);
@@ -332,17 +337,17 @@ gs_prefs_load_from_settings (GSPrefs *prefs)
         bvalue = g_settings_get_boolean (prefs->priv->lockdown, KEY_USER_SWITCH_DISABLE);
         _gs_prefs_set_user_switch_disabled (prefs, bvalue);
 
-        value = g_settings_get_int (prefs->priv->settings, KEY_ACTIVATE_DELAY);
-        _gs_prefs_set_timeout (prefs, value);
+        uvalue = _gs_settings_get_uint (prefs->priv->settings, KEY_ACTIVATE_DELAY);
+        _gs_prefs_set_timeout (prefs, uvalue);
 
-        value = g_settings_get_int (prefs->priv->settings, KEY_POWER_DELAY);
-        _gs_prefs_set_power_timeout (prefs, value);
+        uvalue = _gs_settings_get_uint (prefs->priv->settings, KEY_POWER_DELAY);
+        _gs_prefs_set_power_timeout (prefs, uvalue);
 
-        value = g_settings_get_int (prefs->priv->settings, KEY_LOCK_DELAY);
-        _gs_prefs_set_lock_timeout (prefs, value);
+        uvalue = _gs_settings_get_uint (prefs->priv->settings, KEY_LOCK_DELAY);
+        _gs_prefs_set_lock_timeout (prefs, uvalue);
 
-        value = g_settings_get_int (prefs->priv->settings, KEY_CYCLE_DELAY);
-        _gs_prefs_set_cycle_timeout (prefs, value);
+        uvalue = _gs_settings_get_uint (prefs->priv->settings, KEY_CYCLE_DELAY);
+        _gs_prefs_set_cycle_timeout (prefs, uvalue);
 
         mode = g_settings_get_enum (prefs->priv->settings, KEY_MODE);
         _gs_prefs_set_mode (prefs, mode);
@@ -372,8 +377,8 @@ gs_prefs_load_from_settings (GSPrefs *prefs)
         _gs_prefs_set_logout_command (prefs, string);
         g_free (string);
 
-        value = g_settings_get_int (prefs->priv->settings, KEY_LOGOUT_DELAY);
-        _gs_prefs_set_logout_timeout (prefs, value);
+        uvalue = g_settings_get_int (prefs->priv->settings, KEY_LOGOUT_DELAY);
+        _gs_prefs_set_logout_timeout (prefs, uvalue);
 
         /* User switching options */
 
@@ -402,23 +407,23 @@ key_changed_cb (GSettings   *settings,
 
         } else if (strcmp (key, KEY_ACTIVATE_DELAY) == 0) {
 
-		int delay;
+		guint delay;
 
-		delay = g_settings_get_int (settings, key);
+		delay = _gs_settings_get_uint (settings, key);
 		_gs_prefs_set_timeout (prefs, delay);
 
         } else if (strcmp (key, KEY_POWER_DELAY) == 0) {
 
-		int delay;
+		guint delay;
 
-		delay = g_settings_get_int (settings, key);
+		delay = _gs_settings_get_uint (settings, key);
 		_gs_prefs_set_power_timeout (prefs, delay);
 
         } else if (strcmp (key, KEY_LOCK_DELAY) == 0) {
 
-		int delay;
+		guint delay;
 
-		delay = g_settings_get_int (settings, key);
+		delay = _gs_settings_get_uint (settings, key);
 		_gs_prefs_set_lock_timeout (prefs, delay);
 
         } else if (strcmp (key, KEY_IDLE_ACTIVATION_ENABLED) == 0) {
@@ -451,9 +456,9 @@ key_changed_cb (GSettings   *settings,
 
         } else if (strcmp (key, KEY_CYCLE_DELAY) == 0) {
 
-		int delay;
+		guint delay;
 
-		delay = g_settings_get_int (settings, key);
+		delay = _gs_settings_get_uint (settings, key);
 		_gs_prefs_set_cycle_timeout (prefs, delay);
 
         } else if (strcmp (key, KEY_KEYBOARD_ENABLED) == 0) {
@@ -486,9 +491,9 @@ key_changed_cb (GSettings   *settings,
 
         } else if (strcmp (key, KEY_LOGOUT_DELAY) == 0) {
 
-		int delay;
+		guint delay;
 
-		delay = g_settings_get_int (settings, key);
+		delay = _gs_settings_get_uint (settings, key);
 		_gs_prefs_set_logout_timeout (prefs, delay);
 
         } else if (strcmp (key, KEY_LOGOUT_COMMAND) == 0) {



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