[gnome-settings-daemon/wip/xsettings-manager: 11/16] xsettings: split xsettings_setting_copy to new/set



commit 47e751c040d0da5eb11a142097f6430e4508ec60
Author: Ryan Lortie <desrt desrt ca>
Date:   Wed Mar 7 23:38:48 2012 -0500

    xsettings: split xsettings_setting_copy to new/set

 plugins/xsettings/xsettings-common.c  |   30 +++++++++++++++++++-----------
 plugins/xsettings/xsettings-common.h  |    4 +++-
 plugins/xsettings/xsettings-manager.c |   26 ++++++++++++--------------
 3 files changed, 34 insertions(+), 26 deletions(-)
---
diff --git a/plugins/xsettings/xsettings-common.c b/plugins/xsettings/xsettings-common.c
index fefb00f..d74cd14 100644
--- a/plugins/xsettings/xsettings-common.c
+++ b/plugins/xsettings/xsettings-common.c
@@ -32,31 +32,39 @@
 #include "xsettings-common.h"
 
 XSettingsSetting *
-xsettings_setting_copy (XSettingsSetting *setting)
+xsettings_setting_new (const gchar *name)
 {
   XSettingsSetting *result;
 
   result = g_slice_new (XSettingsSetting);
-  result->name = g_strdup (setting->name);
+  result->name = g_strdup (name);
+  result->type = XSETTINGS_TYPE_INT;
+  result->last_change_serial = 0;
 
-  result->type = setting->type;
+  return result;
+}
 
-  switch (setting->type)
+void
+xsettings_setting_set (XSettingsSetting *setting,
+                       XSettingsSetting *value)
+{
+  if (setting->type == XSETTINGS_TYPE_STRING)
+    g_free (setting->data.v_string);
+
+  setting->type = value->type;
+
+  switch (value->type)
     {
     case XSETTINGS_TYPE_INT:
-      result->data.v_int = setting->data.v_int;
+      setting->data.v_int = value->data.v_int;
       break;
     case XSETTINGS_TYPE_COLOR:
-      result->data.v_color = setting->data.v_color;
+      setting->data.v_color = value->data.v_color;
       break;
     case XSETTINGS_TYPE_STRING:
-      result->data.v_string = g_strdup (setting->data.v_string);
+      setting->data.v_string = g_strdup (value->data.v_string);
       break;
     }
-
-  result->last_change_serial = setting->last_change_serial;
-
-  return result;
 }
 
 int
diff --git a/plugins/xsettings/xsettings-common.h b/plugins/xsettings/xsettings-common.h
index 5c88ee6..8f60e93 100644
--- a/plugins/xsettings/xsettings-common.h
+++ b/plugins/xsettings/xsettings-common.h
@@ -55,7 +55,9 @@ struct _XSettingsSetting
   unsigned long last_change_serial;
 };
 
-XSettingsSetting *xsettings_setting_copy  (XSettingsSetting *setting);
+XSettingsSetting *xsettings_setting_new   (const gchar      *name);
+void              xsettings_setting_set   (XSettingsSetting *setting,
+                                           XSettingsSetting *value);
 void              xsettings_setting_free  (XSettingsSetting *setting);
 int               xsettings_setting_equal (XSettingsSetting *setting_a,
 					   XSettingsSetting *setting_b);
diff --git a/plugins/xsettings/xsettings-manager.c b/plugins/xsettings/xsettings-manager.c
index 4cc3818..e216335 100644
--- a/plugins/xsettings/xsettings-manager.c
+++ b/plugins/xsettings/xsettings-manager.c
@@ -202,26 +202,24 @@ xsettings_manager_delete_setting (XSettingsManager *manager,
 
 static void
 xsettings_manager_set_setting (XSettingsManager *manager,
-			       XSettingsSetting *setting)
+                               XSettingsSetting *value)
 {
-  XSettingsSetting *old_setting = g_hash_table_lookup (manager->settings, setting->name);
-  XSettingsSetting *new_setting;
+  XSettingsSetting *setting;
 
-  if (old_setting)
-    {
-      if (xsettings_setting_equal (old_setting, setting))
-        return;
+  setting = g_hash_table_lookup (manager->settings, value->name);
 
-      g_hash_table_remove (manager->settings, setting->name);
+  if (setting == NULL)
+    {
+      setting = xsettings_setting_new (value->name);
+      setting->last_change_serial = manager->serial;
+      g_hash_table_insert (manager->settings, setting->name, setting);
     }
 
-  new_setting = xsettings_setting_copy (setting);
-  if (!new_setting)
+  if (xsettings_setting_equal (setting, value))
     return;
-  
-  new_setting->last_change_serial = manager->serial;
-  
-  g_hash_table_insert (manager->settings, new_setting->name, new_setting);
+
+  xsettings_setting_set (setting, value);
+  setting->last_change_serial = manager->serial;
 }
 
 void



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