From 6456cb1beb898be3f669025988975e782e394995 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 2 Jun 2010 19:31:22 +0100 Subject: [PATCH] Port to GSettings Instead of GConf. --- configure.ac | 4 +- src/Makefile.am | 10 +++- src/geoclue | 3 + src/main.c | 99 +++++++++++++++---------------- src/org.freedesktop.Geoclue.gschema.xml | 15 +++++ 5 files changed, 77 insertions(+), 54 deletions(-) create mode 100644 src/geoclue create mode 100644 src/org.freedesktop.Geoclue.gschema.xml diff --git a/configure.ac b/configure.ac index 999f7d9..438894c 100644 --- a/configure.ac +++ b/configure.ac @@ -14,6 +14,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) @@ -41,7 +42,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 4a8b331..d9d3dc1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -59,8 +59,16 @@ service_DATA = $(service_in_files:.service.in=.service) $(service_DATA): $(service_in_files) Makefile @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 --- /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 - -#include +#include #include #include @@ -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 --- /dev/null +++ b/src/org.freedesktop.Geoclue.gschema.xml @@ -0,0 +1,15 @@ + + + + + 0 + The baud rate for the attached GPS device + The baud rate for the attached GPS device. + + + '' + The device node or Bluetooth address for the attached GPS device + The device node or Bluetooth address for the attached GPS device. + + + -- 1.7.0.1