summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2010-06-02 19:31:22 +0100
committerBastien Nocera <hadess@hadess.net>2010-12-03 14:53:47 +0000
commit59f49112b023310487142d48891f1d86b43b1e42 (patch)
tree5099bf4a635886b502c5d26b4c0749599c3bb87d
parent2a257e15d6f00f4ab34d585f137de88019f00f90 (diff)
Port to GSettings
Instead of GConf.
-rw-r--r--configure.ac4
-rw-r--r--src/Makefile.am10
-rw-r--r--src/geoclue3
-rw-r--r--src/main.c99
-rw-r--r--src/org.freedesktop.Geoclue.gschema.xml15
5 files changed, 77 insertions, 54 deletions
diff --git a/configure.ac b/configure.ac
index b06529c..ec24938 100644
--- a/configure.ac
+++ b/configure.ac
@@ -14,12 +14,13 @@ AC_ISC_POSIX
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_GCC_TRADITIONAL
AM_PROG_LIBTOOL
+GLIB_GSETTINGS
GTK_DOC_CHECK(1.0)
AC_CHECK_PROGS(XSLT, xsltproc)
AC_ARG_ENABLE(system-bus,
[AC_HELP_STRING([--enable-system-bus],
@@ -41,13 +42,14 @@ PKG_CHECK_MODULES(GEOCLUE, [
libxml-2.0
])
AC_SUBST(GEOCLUE_LIBS)
AC_SUBST(GEOCLUE_CFLAGS)
PKG_CHECK_MODULES(MASTER, [
- gconf-2.0
+ gio-2.0 >= 2.25.7
+ glib-2.0
])
AC_SUBST(MASTER_LIBS)
AC_SUBST(MASTER_CFLAGS)
AC_PATH_PROG(DBUS_BINDING_TOOL, dbus-binding-tool)
AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal)
diff --git a/src/Makefile.am b/src/Makefile.am
index ec54d61..ebb5f22 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -67,14 +67,22 @@ servicedir = $(DBUS_SERVICES_DIR)
service_in_files = org.freedesktop.Geoclue.Master.service.in
service_DATA = $(service_in_files:.service.in=.service)
$(service_DATA): $(service_in_files) Makefile
$(AM_V_GEN) sed -e "s|\@libexecdir\@|$(libexecdir)|" $< > $@
+convertdir = $(datadir)/GConf/gsettings
+convert_DATA = geoclue
+
+gsettings_SCHEMAS = org.freedesktop.Geoclue.gschema.xml
+@GSETTINGS_RULES@
+
EXTRA_DIST = \
- $(service_in_files)
+ $(service_in_files) \
+ $(gsettings_SCHEMAS) \
+ $(convert_DATA)
CLEANFILES = \
$(BUILT_SOURCES) \
stamp-gc-iface-master-glue.h \
stamp-gc-iface-master-client-glue.h
diff --git a/src/geoclue b/src/geoclue
new file mode 100644
index 0000000..03bde7f
--- /dev/null
+++ b/src/geoclue
@@ -0,0 +1,3 @@
+[org.freedesktop.Geoclue]
+gps-baudrate = /apps/geoclue/master/org.freedesktop.Geoclue.GPSBaudRate
+gps-device = /apps/geoclue/master/org.freedesktop.Geoclue.GPSDevice
diff --git a/src/main.c b/src/main.c
index adbe8a8..96d7f3d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -24,57 +24,60 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <glib.h>
-
-#include <gconf/gconf-client.h>
+#include <gio/gsettings.h>
#include <dbus/dbus-protocol.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-bindings.h>
#include "master.h"
static GMainLoop *mainloop;
static GHashTable *options;
+static GSettings *settings;
static GcMaster *master;
-#define GEOCLUE_GCONF_TOP "/apps/geoclue/master"
+#define GEOCLUE_SCHEMA_NAME "org.freedesktop.Geoclue"
#define GEOCLUE_MASTER_NAME "org.freedesktop.Geoclue.Master"
static GValue *
-gconf_value_to_value (GConfValue *value)
+gvariant_value_to_value (GVariant *value)
{
GValue *gvalue;
+ const GVariantType *type;
g_return_val_if_fail (value != NULL, NULL);
- g_return_val_if_fail (value->type == GCONF_VALUE_STRING ||
- value->type == GCONF_VALUE_INT, NULL);
+ type = g_variant_get_type (value);
- if (value->type == GCONF_VALUE_STRING) {
+ if (g_variant_type_is_subtype_of (type, G_VARIANT_TYPE_STRING)) {
const char *str;
gvalue = g_new0 (GValue, 1);
- str = gconf_value_get_string (value);
+ str = g_variant_get_string (value, NULL);
/* Don't add empty strings in the hashtable */
if (str != NULL && str[0] == '\0')
str = NULL;
g_value_init (gvalue, G_TYPE_STRING);
g_value_set_string (gvalue, str);
- } else if (value->type == GCONF_VALUE_INT) {
+ } else if (g_variant_type_is_subtype_of (type, G_VARIANT_TYPE_UINT32)) {
int i;
gvalue = g_new0 (GValue, 1);
- i = gconf_value_get_int (value);
+ i = g_variant_get_uint32 (value);
g_value_init (gvalue, G_TYPE_INT);
g_value_set_int (gvalue, i);
+ } else {
+ gvalue = NULL;
+ g_warning ("Value is of unknown type");
}
return gvalue;
}
static void
@@ -83,15 +86,15 @@ debug_print_key (gboolean init,
GValue *gvalue)
{
const char *message;
char *string;
if (init)
- message = "GConf key '%s' initialised to '%s'";
+ message = "GSettings key '%s' initialised to '%s'";
else
- message = "GConf key '%s' changed to '%s'";
+ message = "GSettings key '%s' changed to '%s'";
if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING) {
string = g_value_dup_string (gvalue);
} else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT) {
string = g_strdup_printf ("%d", g_value_get_int (gvalue));
} else {
@@ -100,30 +103,29 @@ debug_print_key (gboolean init,
g_message (message, key, string);
g_free (string);
}
static void
-gconf_key_changed (GConfClient *client,
- guint cnxn_id,
- GConfEntry *entry,
- gpointer user_data)
+gsettings_key_changed (GSettings *settings,
+ char *key,
+ gpointer user_data)
{
- const char *key;
- GConfValue *v;
+ GVariant *v;
GValue *gvalue;
- key = gconf_entry_get_key (entry);
- v = gconf_entry_get_value (entry);
- gvalue = gconf_value_to_value (v);
- if (gvalue == NULL)
+ v = g_settings_get_value (settings, key);
+ gvalue = gvariant_value_to_value (v);
+ if (gvalue == NULL) {
+ g_variant_unref (v);
return;
+ }
debug_print_key (FALSE, key, gvalue);
- g_hash_table_insert (options, g_path_get_basename (key), gvalue);
+ g_hash_table_insert (options, g_strdup (key), gvalue);
g_signal_emit_by_name (G_OBJECT (master), "options-changed", options);
}
static void
free_gvalue (GValue *value)
@@ -135,52 +137,44 @@ free_gvalue (GValue *value)
}
static GHashTable *
load_options (void)
{
GHashTable *ht = NULL;
- GConfClient *client = gconf_client_get_default ();
- GSList *entries, *e;
- GError *error = NULL;
-
- gconf_client_add_dir (client, GEOCLUE_GCONF_TOP,
- GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
-
- entries = gconf_client_all_entries (client, GEOCLUE_GCONF_TOP, &error);
- if (error != NULL) {
- g_warning ("Error loading master options: %s", error->message);
- g_error_free (error);
- return NULL;
- }
+ guint i;
+ const char const * keys[] = {
+ "gps-baudrate",
+ "gps-device"
+ };
/* Setup keys monitoring */
- gconf_client_notify_add (client, GEOCLUE_GCONF_TOP,
- (GConfClientNotifyFunc) gconf_key_changed,
- NULL, NULL, NULL);
+ g_signal_connect (G_OBJECT (settings), "changed",
+ G_CALLBACK (gsettings_key_changed), NULL);
ht = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, (GDestroyNotify) free_gvalue);
+
g_print ("Master options:\n");
- for (e = entries; e; e = e->next) {
- GConfEntry *entry = e->data;
- const char *key;
- GConfValue *v;
- GValue *gvalue;
-
- key = gconf_entry_get_key (entry);
- v = gconf_entry_get_value (entry);
- gvalue = gconf_value_to_value (v);
- if (gvalue == NULL)
+ for (i = 0; i < G_N_ELEMENTS (keys); i++) {
+ GVariant *v;
+ GValue *gvalue;
+ const char *key = keys[i];
+
+ v = g_settings_get_value (settings, key);
+ gvalue = gvariant_value_to_value (v);
+
+ if (gvalue == NULL) {
+ g_variant_unref (v);
continue;
+ }
debug_print_key (TRUE, key, gvalue);
- g_hash_table_insert (ht, g_path_get_basename (key), gvalue);
- gconf_entry_free (entry);
+ g_hash_table_insert (ht, g_strdup (key), gvalue);
+ g_variant_unref (v);
}
- g_slist_free (entries);
return ht;
}
GHashTable *
geoclue_get_main_options (void)
@@ -221,12 +215,13 @@ main (int argc,
/* Just quit if master is already running */
if (request_name_ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
return 1;
}
/* Load options */
+ settings = g_settings_new (GEOCLUE_SCHEMA_NAME);
options = load_options ();
master = g_object_new (GC_TYPE_MASTER, NULL);
dbus_g_connection_register_g_object (conn,
"/org/freedesktop/Geoclue/Master",
G_OBJECT (master));
diff --git a/src/org.freedesktop.Geoclue.gschema.xml b/src/org.freedesktop.Geoclue.gschema.xml
new file mode 100644
index 0000000..94ff65d
--- /dev/null
+++ b/src/org.freedesktop.Geoclue.gschema.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schemalist>
+ <schema path="/apps/geoclue/" id="org.freedesktop.Geoclue">
+ <key type="u" name="gps-baudrate">
+ <default>0</default>
+ <summary>The baud rate for the attached GPS device</summary>
+ <description>The baud rate for the attached GPS device.</description>
+ </key>
+ <key type="s" name="gps-device">
+ <default>''</default>
+ <summary>The device node or Bluetooth address for the attached GPS device</summary>
+ <description>The device node or Bluetooth address for the attached GPS device.</description>
+ </key>
+ </schema>
+</schemalist>