summaryrefslogtreecommitdiff
authorBastien Nocera <hadess@hadess.net>2010-06-02 18:31:22 (GMT)
committer Bastien Nocera <hadess@hadess.net>2010-12-03 14:53:47 (GMT)
commit59f49112b023310487142d48891f1d86b43b1e42 (patch) (side-by-side diff)
tree5099bf4a635886b502c5d26b4c0749599c3bb87d
parent2a257e15d6f00f4ab34d585f137de88019f00f90 (diff)
downloadgeoclue-59f49112b023310487142d48891f1d86b43b1e42.zip
geoclue-59f49112b023310487142d48891f1d86b43b1e42.tar.gz
Port to GSettings
Instead of GConf.
Diffstat (more/less context) (ignore whitespace changes)
-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
@@ -17,6 +17,7 @@ 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)
@@ -44,7 +45,8 @@ 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)
diff --git a/src/Makefile.am b/src/Makefile.am
index ec54d61..ebb5f22 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -70,8 +70,16 @@ 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) \
diff --git a/src/geoclue b/src/geoclue
new file mode 100644
index 0000000..03bde7f
--- a/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
@@ -27,8 +27,7 @@
#endif
#include <glib.h>
-
-#include <gconf/gconf-client.h>
+#include <gio/gsettings.h>
#include <dbus/dbus-protocol.h>
#include <dbus/dbus-glib.h>
@@ -38,26 +37,27 @@
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')
@@ -65,13 +65,16 @@ gconf_value_to_value (GConfValue *value)
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;
@@ -86,9 +89,9 @@ debug_print_key (gboolean init,
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);
@@ -103,24 +106,23 @@ debug_print_key (gboolean init,
}
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);
}
@@ -138,46 +140,38 @@ 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;
}
@@ -224,6 +218,7 @@ main (int argc,
}
/* Load options */
+ settings = g_settings_new (GEOCLUE_SCHEMA_NAME);
options = load_options ();
master = g_object_new (GC_TYPE_MASTER, NULL);
diff --git a/src/org.freedesktop.Geoclue.gschema.xml b/src/org.freedesktop.Geoclue.gschema.xml
new file mode 100644
index 0000000..94ff65d
--- a/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>