[PATCH xoo 7/8] Port to GSettings

Yaakov (Cygwin/X) yselkowitz at users.sourceforge.net
Wed Oct 10 16:07:02 PDT 2012


From: Yaakov Selkowitz <yselkowitz at users.sourceforge.net>

Signed-off-by: Yaakov Selkowitz <yselkowitz at users.sourceforge.net>
---
 configure.ac               |   29 ++---------------------------
 data/Makefile.am           |    9 +++++++++
 data/org.x.Xoo.gschema.xml |   30 ++++++++++++++++++++++++++++++
 data/xoo.convert           |    5 +++++
 src/Makefile.am            |    5 +----
 src/main.c                 |   14 ++------------
 src/prefs.c                |   28 ++++++++++++++--------------
 src/prefs.h                |    7 +------
 8 files changed, 64 insertions(+), 63 deletions(-)
 create mode 100644 data/org.x.Xoo.gschema.xml
 create mode 100644 data/xoo.convert

diff --git a/configure.ac b/configure.ac
index df20e1f..d8b77dc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -21,33 +21,8 @@ AC_ARG_WITH(expat-lib,
 AC_GNU_SOURCE
 AC_PROG_CC
 AC_PATH_XTRA
-AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
-
-AC_ARG_ENABLE(gconf,
-        AC_HELP_STRING([--enable-gconf], [Use GConf for preferences @<:@default=auto@:>@]),
-        ,enable_gconf=auto)
-GCONF_REQ=
-if test "x$enable_gconf" = "xyes"; then
-  GCONF_REQ="gconf-2.0"
-else
-  if test "x$enable_gconf" != "xno"; then
-    AC_MSG_CHECKING(for GConf)
-    if $PKG_CONFIG --exists gconf-2.0; then
-       AC_MSG_RESULT(yes)
-        GCONF_REQ="gconf-2.0"
-    else
-       AC_MSG_RESULT(no)
-    fi
-  fi
-fi
-if test -n "$GCONF_REQ"; then
-        AC_DEFINE([HAVE_GCONF], 1, [Defined when GConf is detected])
-fi
-AM_CONDITIONAL(HAVE_GCONF, test -n "$GCONF_REQ")
-
-
-dnl TODO: make gconf optional
-PKG_CHECK_MODULES(APP, [gtk+-3.0 $GCONF_REQ])
+GLIB_GSETTINGS
+PKG_CHECK_MODULES(APP, [gtk+-3.0])
 
 dnl ------ XTest ------------------------------------------------------------
 
diff --git a/data/Makefile.am b/data/Makefile.am
index ccd41d4..d38cf00 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -12,3 +12,12 @@ dist_desktop_DATA = xoo.desktop
 
 pixmapdir = $(datadir)/pixmaps
 dist_pixmap_DATA = xoo.png
+
+convertdir = $(datadir)/GConf/gsettings
+dist_convert_DATA = xoo.convert
+
+gsettings_SCHEMAS = org.x.Xoo.gschema.xml
+
+ at GSETTINGS_RULES@
+
+EXTRA_DIST = $(gsettings_SCHEMAS)
diff --git a/data/org.x.Xoo.gschema.xml b/data/org.x.Xoo.gschema.xml
new file mode 100644
index 0000000..17c56f7
--- /dev/null
+++ b/data/org.x.Xoo.gschema.xml
@@ -0,0 +1,30 @@
+<?xml version='1.0' encoding='utf-8'?>
+<schemalist>
+  <schema id="org.x.Xoo" path="/org/x/Xoo/">
+
+    <key name="display" type="s">
+      <default>':1'</default>
+      <summary>X Display</summary>
+      <description>Display string to be passed to the embedded X server</description>
+    </key>
+
+    <key name="xserver" type="s">
+      <default>'/usr/bin/Xephyr'</default>
+      <summary>X Server</summary>
+      <description>Fully-qualified path to the embedded X server (Xephyr or Xnest)</description>
+    </key>
+
+    <key name="xserver-options" type="s">
+      <default>'-ac'</default>
+      <summary>X Server Options</summary>
+      <description>Options to be passed to the embedded X server</description>
+    </key>
+
+    <key name="startup-command" type="s">
+      <default>''</default>
+      <summary>Startup Command</summary>
+      <description>Command to be launched within the embedded X server</description>
+    </key>
+
+  </schema>
+</schemalist>
diff --git a/data/xoo.convert b/data/xoo.convert
new file mode 100644
index 0000000..8faab64
--- /dev/null
+++ b/data/xoo.convert
@@ -0,0 +1,5 @@
+[org.x.Xoo]
+display = /apps/Xoo/display
+xserver = /apps/Xoo/xserver
+xserver-options = /apps/Xoo/xserver-options
+startup-command = /apps/Xoo/startup-command
diff --git a/src/Makefile.am b/src/Makefile.am
index ed8b5bd..900f70f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,9 +1,6 @@
 INCLUDES = -DPKGDATADIR=\"$(pkgdatadir)\" @APP_CFLAGS@ @EXPAT_CFLAGS@ @X_CFLAGS@ -Wall
 bin_PROGRAMS = xoo
 
-if HAVE_GCONF
-GCONF_SOURCES = prefs.c prefs.h
-endif
-xoo_SOURCES =  main.c button.c callbacks.h callbacks.c config.c keys.c fakedev.h $(GCONF_SOURCES)
+xoo_SOURCES =  main.c button.c callbacks.h callbacks.c config.c keys.c fakedev.h prefs.c prefs.h
 
 xoo_LDADD = @APP_LIBS@ @EXPAT_LIBS@ @X_LIBS@ @XTEST_LIBS@
diff --git a/src/main.c b/src/main.c
index 83a0e31..d5806cb 100644
--- a/src/main.c
+++ b/src/main.c
@@ -114,7 +114,6 @@ fakeapp_new (void)
   g_signal_connect (G_OBJECT (widget), "activate",
   G_CALLBACK (on_select_device), app);
 
-#if HAVE_GCONF
   widget = GTK_WIDGET (gtk_builder_get_object (builder, "preferences"));
   g_signal_connect (G_OBJECT (widget), "activate",
   G_CALLBACK (on_preferences_activate), app);
@@ -126,11 +125,7 @@ fakeapp_new (void)
   widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_close"));
   g_signal_connect (G_OBJECT (widget), "clicked",
   G_CALLBACK (on_prefs_cancel_clicked), app);
-#else
-  widget = GTK_WIDGET (gtk_builder_get_object (builder, "preferences"));
-  gtk_widget_hide (widget);
 
-#endif
   widget = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
   app->window = widget;
   widget = GTK_WIDGET (gtk_builder_get_object (builder, "menubar"));
@@ -167,9 +162,6 @@ fakeapp_new (void)
   widget = GTK_WIDGET (gtk_builder_get_object (builder, "popupmenu_menu"));
   app->popupmenu = widget;
 
-  widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_about_close"));
-  g_signal_connect_swapped (widget, "clicked",
-			    G_CALLBACK (gtk_widget_hide), app->about_window);
   return app;
 }
 
@@ -451,10 +443,8 @@ main (int argc, char **argv)
   app->argv = argv;
   app->argc = argc;
 
-#ifdef HAVE_GCONF
-  /* Do this here so that command line argument override the GConf prefs */
-  gconf_prefs_init (app);
-#endif
+  /* Do this here so that command line argument override the GSettings prefs */
+  gsettings_prefs_init (app);
 
   if (xnest_display)
     app->xnest_dpy_name = xnest_display;
diff --git a/src/prefs.c b/src/prefs.c
index a2f2411..e6727ee 100644
--- a/src/prefs.c
+++ b/src/prefs.c
@@ -16,40 +16,40 @@
 #include "config.h"
 
 #include <string.h>
-#include <gconf/gconf-client.h>
+#include <gio/gio.h>
 #include <gtk/gtk.h>
 #include "prefs.h"
 
 gboolean fakeapp_restart_server (FakeApp * app);  /* TODO: move to a header */
 
-static GConfClient *gconf = NULL;
+static GSettings *gsettings = NULL;
 
 void
-gconf_prefs_init (FakeApp * app)
+gsettings_prefs_init (FakeApp * app)
 {
   char *s;
-  gconf = gconf_client_get_default ();
-  g_return_if_fail (gconf != NULL);
+  gsettings = g_settings_new ("org.x.Xoo");
+  g_return_if_fail (gsettings != NULL);
 
-  s = gconf_client_get_string (gconf, GCONF_DISPLAY, NULL);
+  s = g_settings_get_string (gsettings, "display");
   if (s != NULL && *s != '\0')
     {
       app->xnest_dpy_name = s;
     }
 
-  s = gconf_client_get_string (gconf, GCONF_SERVER, NULL);
+  s = g_settings_get_string (gsettings, "xserver");
   if (s != NULL && *s != '\0')
     {
       app->xnest_bin_path = s;
     }
 
-  s = gconf_client_get_string (gconf, GCONF_SERVER_OPTIONS, NULL);
+  s = g_settings_get_string (gsettings, "xserver-options");
   if (s != NULL && *s != '\0')
     {
       app->xnest_bin_options = s;
     }
 
-  s = gconf_client_get_string (gconf, GCONF_START_CMD, NULL);
+  s = g_settings_get_string (gsettings, "startup-command");
   if (s != NULL && *s != '\0')
     {
       app->start_cmd = s;
@@ -77,18 +77,18 @@ on_prefs_apply_clicked (GtkWidget * widget, FakeApp * app)
   const char *s = NULL;
 
   s = gtk_entry_get_text (GTK_ENTRY (app->entry_display));
-  gconf_client_set_string (gconf, GCONF_DISPLAY, s, NULL);
+  g_settings_set_string (gsettings, "display", s);
 
   s = gtk_entry_get_text (GTK_ENTRY (app->entry_server));
-  gconf_client_set_string (gconf, GCONF_SERVER, s, NULL);
+  g_settings_set_string (gsettings, "xserver", s);
 
   s = gtk_entry_get_text (GTK_ENTRY (app->entry_options));
-  gconf_client_set_string (gconf, GCONF_SERVER_OPTIONS, s, NULL);
+  g_settings_set_string (gsettings, "xserver-options", s);
 
   s = gtk_entry_get_text (GTK_ENTRY (app->entry_start));
-  gconf_client_set_string (gconf, GCONF_START_CMD, s, NULL);
+  g_settings_set_string (gsettings, "startup-command", s);
 
-  gconf_prefs_init (app);
+  gsettings_prefs_init (app);
   fakeapp_restart_server (app);
 
   gtk_widget_hide (app->prefs_window);
diff --git a/src/prefs.h b/src/prefs.h
index 5fe62a0..d83370b 100644
--- a/src/prefs.h
+++ b/src/prefs.h
@@ -1,13 +1,8 @@
 #include <gtk/gtk.h>
 #include "fakedev.h"
 
-#define GCONF_DISPLAY "/apps/Xoo/display"
-#define GCONF_SERVER "/apps/Xoo/xserver"
-#define GCONF_SERVER_OPTIONS "/apps/Xoo/xserver-options"
-#define GCONF_START_CMD "/apps/Xoo/startup-command"
-
 void 
-gconf_prefs_init (FakeApp * app);
+gsettings_prefs_init (FakeApp * app);
 
 void 
 on_preferences_activate (GtkMenuItem * menuitem, FakeApp * app);
-- 
1.7.9



More information about the xorg-devel mailing list