[Xfce4-commits] [xfce/xfconf] 03/10: Implement some GSettings interface methods
noreply at xfce.org
noreply at xfce.org
Sun Oct 21 12:05:10 CEST 2018
This is an automated email from the git hooks/post-receive script.
a l i p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository xfce/xfconf.
commit 4864bed3de435a1bc87c2f9b263476465c406e19
Author: Ali Abdallah <ali at xfce.org>
Date: Fri Jul 13 22:35:42 2018 +0200
Implement some GSettings interface methods
Interface method implemented are reset, write and read.
---
gsettings-backend/Makefile.am | 1 +
gsettings-backend/xfconf-gsettings-backend.c | 114 ++++++++++++++++++++++++---
2 files changed, 104 insertions(+), 11 deletions(-)
diff --git a/gsettings-backend/Makefile.am b/gsettings-backend/Makefile.am
index cafee4a..bee1484 100644
--- a/gsettings-backend/Makefile.am
+++ b/gsettings-backend/Makefile.am
@@ -21,6 +21,7 @@ libxfconfgsettingsbackend_la_LDFLAGS = \
libxfconfgsettingsbackend_la_LIBADD = \
$(top_builddir)/xfconf/libxfconf-0.la \
+ $(top_builddir)/common/libxfconf-gvaluefuncs.la\
$(GIO_LDFLAGS) \
$(GMODULE_LDFLAGS)
diff --git a/gsettings-backend/xfconf-gsettings-backend.c b/gsettings-backend/xfconf-gsettings-backend.c
index f6e63c1..deba52a 100644
--- a/gsettings-backend/xfconf-gsettings-backend.c
+++ b/gsettings-backend/xfconf-gsettings-backend.c
@@ -25,26 +25,78 @@
#include <glib.h>
#include "xfconf/xfconf.h"
+#include "common/xfconf-gvaluefuncs.h"
#include "xfconf-gsettings-backend.h"
-
struct _XfconfGsettingsBackend
{
GSettingsBackend __parent__;
XfconfChannel *channel;
+
+ GHashTable *changed_prop;
};
G_DEFINE_TYPE (XfconfGsettingsBackend, xfconf_gsettings_backend, G_TYPE_SETTINGS_BACKEND);
+static void
+xfconf_gsettings_backend_property_changed_cb (XfconfGsettingsBackend *self,
+ const gchar *property,
+ const GValue *value)
+{
+ gpointer origin_tag;
+ gboolean found;
+
+ found = g_hash_table_lookup_extended (self->changed_prop, property, NULL, &origin_tag);
+
+ if (found) {
+ /* Emit the changed signal */
+ g_debug ("Emitting property changed signal '%s'\n", property);
+ g_settings_backend_changed ((GSettingsBackend*)self, property, origin_tag);
+ } else {
+ g_warning ("Changed property '%s' not expected!", property);
+ }
+
+ g_hash_table_remove (self->changed_prop, property);
+}
+
static GVariant *
xfconf_gsettings_backend_read (GSettingsBackend *backend,
const gchar *key,
const GVariantType *expected_type,
gboolean default_value)
{
- return NULL;
+ XfconfGsettingsBackend *self = XFCONF_GSETTINGS_BACKEND(backend);
+ GValue value = G_VALUE_INIT;
+ GVariant *variant;
+ gboolean found;
+
+ /* The GSettings will take care of handling the default value */
+ if (default_value)
+ return NULL;
+
+ found = xfconf_channel_get_property (self->channel,
+ key,
+ &value);
+ if (!found)
+ return NULL;
+
+ variant = xfconf_gvalue_to_gvariant (&value);
+ g_value_unset (&value);
+
+ if (!g_variant_is_of_type (variant, expected_type)) {
+ gchar *type_str;
+
+ type_str = g_variant_type_dup_string (expected_type);
+ g_critical ("Property '%s' expected type is '%s' => '%s' found!",
+ key, type_str, g_variant_get_type_string(variant) );
+ g_free(type_str);
+ g_variant_unref(variant);
+ return NULL;
+ }
+
+ return variant;
}
static void
@@ -52,36 +104,70 @@ xfconf_gsettings_backend_reset (GSettingsBackend *backend,
const gchar *key,
gpointer origin_tag)
{
+ XfconfGsettingsBackend *self;
+
+ self = XFCONF_GSETTINGS_BACKEND(backend);
+
+ g_hash_table_replace (self->changed_prop, g_strdup(key), origin_tag);
+
+ xfconf_channel_reset_property (self->channel, key, TRUE);
}
static gboolean
xfconf_gsettings_backend_get_writable (GSettingsBackend *backend,
const gchar *key)
{
- return FALSE;
-}
+ XfconfGsettingsBackend *self;
-static gboolean
-xfconf_gsettings_backend_write_tree (GSettingsBackend *backend,
- GTree *tree,
- gpointer origin_tag)
-{
- return FALSE;
+ self = XFCONF_GSETTINGS_BACKEND(backend);
+
+ return !xfconf_channel_is_property_locked(self->channel, key);
}
static gboolean
xfconf_gsettings_backend_write (GSettingsBackend *backend,
const gchar *key,
- GVariant *value,
+ GVariant *variant,
gpointer origin_tag)
{
+ XfconfGsettingsBackend *self;
+ GValue *value;
+ gboolean ret_val;
+
+ self = XFCONF_GSETTINGS_BACKEND(backend);
+
+ value = xfconf_gvariant_to_gvalue (variant);
+
+ if (value) {
+ g_hash_table_replace (self->changed_prop, g_strdup(key), origin_tag);
+ ret_val = xfconf_channel_set_property (self->channel, key, value);
+ if (ret_val == FALSE)
+ g_hash_table_remove (self->changed_prop, key);
+
+ g_value_unset (value);
+ g_free (value);
+ }
return FALSE;
}
+static gboolean
+xfconf_gsettings_backend_write_tree (GSettingsBackend *backend,
+ GTree *tree,
+ gpointer origin_tag)
+{
+ return TRUE;
+}
+
+
static void
xfconf_gsettings_backend_finalize (XfconfGsettingsBackend *self)
{
+ g_object_unref (self->channel);
+
+ g_hash_table_destroy (self->changed_prop);
+
+ G_OBJECT_CLASS(xfconf_gsettings_backend_parent_class)->finalize((GObject*)self);
}
static void
@@ -92,6 +178,12 @@ xfconf_gsettings_backend_init (XfconfGsettingsBackend *self)
prg_name = g_get_prgname();
self->channel = xfconf_channel_new (prg_name);
+
+ self->changed_prop = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, NULL);
+
+ g_signal_connect_swapped (self->channel, "property-changed",
+ G_CALLBACK (xfconf_gsettings_backend_property_changed_cb), self);
}
static void
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list