[gnome-settings-daemon/wip/xsettings-manager] xsettings: add GVariant 'overrides' to the manager



commit 045697958bd0e70f630754c5560c3b8af5d0e50f
Author: Ryan Lortie <desrt desrt ca>
Date:   Thu Mar 8 10:18:20 2012 -0500

    xsettings: add GVariant 'overrides' to the manager
    
    Increase the tier count and put it in tier 1 (normal settings are in
    tier 0).

 plugins/xsettings/xsettings-common.h  |    2 +-
 plugins/xsettings/xsettings-manager.c |   42 +++++++++++++++++++++++++++++++++
 plugins/xsettings/xsettings-manager.h |    2 +
 3 files changed, 45 insertions(+), 1 deletions(-)
---
diff --git a/plugins/xsettings/xsettings-common.h b/plugins/xsettings/xsettings-common.h
index 0a0d840..2062f47 100644
--- a/plugins/xsettings/xsettings-common.h
+++ b/plugins/xsettings/xsettings-common.h
@@ -25,7 +25,7 @@
 
 #include <glib.h>
 
-#define XSETTINGS_N_TIERS 1
+#define XSETTINGS_N_TIERS 2
 
 typedef struct _XSettingsColor   XSettingsColor;
 typedef struct _XSettingsSetting XSettingsSetting;
diff --git a/plugins/xsettings/xsettings-manager.c b/plugins/xsettings/xsettings-manager.c
index d5afbff..231a6e4 100644
--- a/plugins/xsettings/xsettings-manager.c
+++ b/plugins/xsettings/xsettings-manager.c
@@ -44,6 +44,8 @@ struct _XSettingsManager
 
   GHashTable *settings;
   unsigned long serial;
+
+  GVariant *overrides;
 };
 
 typedef struct 
@@ -142,6 +144,7 @@ xsettings_manager_new (Display                *display,
 
   manager->settings = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) xsettings_setting_free);
   manager->serial = 0;
+  manager->overrides = NULL;
 
   manager->window = XCreateSimpleWindow (display,
 					 RootWindow (display, screen),
@@ -339,3 +342,42 @@ xsettings_manager_notify (XSettingsManager *manager)
   g_string_free (buffer, TRUE);
   manager->serial++;
 }
+
+void
+xsettings_manager_set_overrides (XSettingsManager *manager,
+                                 GVariant         *overrides)
+{
+  GVariantIter iter;
+  const gchar *key;
+  GVariant *value;
+
+  g_return_if_fail (overrides != NULL && g_variant_is_of_type (overrides, G_VARIANT_TYPE_VARDICT));
+
+  if (manager->overrides)
+    {
+      /* unset the existing overrides */
+
+      g_variant_iter_init (&iter, manager->overrides);
+      while (g_variant_iter_next (&iter, "{&sv}", &key, NULL))
+        /* only unset it at this point if it's not in the new list */
+        if (!g_variant_lookup (overrides, key, "*", NULL))
+          xsettings_manager_set_setting (manager, key, 1, NULL);
+      g_variant_unref (manager->overrides);
+    }
+
+  /* save this so we can do the unsets next time */
+  manager->overrides = g_variant_ref_sink (overrides);
+
+  /* set the new values */
+  g_variant_iter_init (&iter, overrides);
+  while (g_variant_iter_loop (&iter, "{&sv}", &key, &value))
+    {
+      /* only accept recognised types... */
+      if (!g_variant_is_of_type (value, G_VARIANT_TYPE_STRING) &&
+          !g_variant_is_of_type (value, G_VARIANT_TYPE_INT32) &&
+          !g_variant_is_of_type (value, G_VARIANT_TYPE ("(qqqq)")))
+        continue;
+
+      xsettings_manager_set_setting (manager, key, 1, value);
+    }
+}
diff --git a/plugins/xsettings/xsettings-manager.h b/plugins/xsettings/xsettings-manager.h
index 85f4833..a8cf151 100644
--- a/plugins/xsettings/xsettings-manager.h
+++ b/plugins/xsettings/xsettings-manager.h
@@ -52,5 +52,7 @@ void   xsettings_manager_set_color      (XSettingsManager *manager,
                                          const char       *name,
                                          XSettingsColor   *value);
 void   xsettings_manager_notify         (XSettingsManager *manager);
+void   xsettings_manager_set_overrides  (XSettingsManager *manager,
+                                         GVariant         *overrides);
 
 #endif /* XSETTINGS_MANAGER_H */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]