[Xfce4-commits] <thunar:master> Port settings to xfconf.

Nick Schermer noreply at xfce.org
Mon Oct 1 21:32:01 CEST 2012


Updating branch refs/heads/master
         to af2fcaebf673d730b1297929978ff74d7ca71346 (commit)
       from 6b99127271a999cfb94364f4035cf9d0f96f4ac5 (commit)

commit af2fcaebf673d730b1297929978ff74d7ca71346
Author: Nick Schermer <nick at xfce.org>
Date:   Mon Oct 1 21:24:08 2012 +0200

    Port settings to xfconf.
    
    Loading over DBus is a tiny bit slower, but makes
    it a lot easier to change values and also saves a
    lot of hassle with modified properties.

 configure.in.in             |    1 +
 thunar/Makefile.am          |    4 +-
 thunar/main.c               |   10 +
 thunar/thunar-preferences.c |  503 +++++++++++++------------------------------
 4 files changed, 163 insertions(+), 355 deletions(-)

diff --git a/configure.in.in b/configure.in.in
index 91f9e46..b7c33a1 100644
--- a/configure.in.in
+++ b/configure.in.in
@@ -147,6 +147,7 @@ XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [2.24.0])
 XDT_CHECK_PACKAGE([GDK_PIXBUF], [gdk-pixbuf-2.0], [2.14.0])
 XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.9.0])
 XDT_CHECK_PACKAGE([LIBXFCE4UI], [libxfce4ui-1], [4.9.0])
+XDT_CHECK_PACKAGE([XFCONF], [libxfconf-0], [4.10.0])
 
 dnl ********************************************
 dnl *** Check for session management support ***
diff --git a/thunar/Makefile.am b/thunar/Makefile.am
index a487f64..3bafe9d 100644
--- a/thunar/Makefile.am
+++ b/thunar/Makefile.am
@@ -226,6 +226,7 @@ thunar_CFLAGS =								\
 	$(LIBSM_CFLAGS)							\
 	$(LIBSTARTUP_NOTIFICATION_CFLAGS)				\
 	$(LIBXFCE4UI_CFLAGS)						\
+	$(XFCONF_CFLAGS)						\
 	$(PLATFORM_CFLAGS)
 
 thunar_LDFLAGS =							\
@@ -242,7 +243,8 @@ thunar_LDADD =								\
 	$(LIBNOTIFY_LIBS)						\
 	$(LIBSM_LIBS)							\
 	$(LIBSTARTUP_NOTIFICATION_LIBS)					\
-	$(LIBXFCE4UI_LIBS)
+	$(LIBXFCE4UI_LIBS)						\
+	$(XFCONF_LIBS)
 
 thunar_DEPENDENCIES =							\
 	$(top_builddir)/thunarx/libthunarx-$(THUNARX_VERSION_API).la
diff --git a/thunar/main.c b/thunar/main.c
index b65c8e5..f3d9219 100644
--- a/thunar/main.c
+++ b/thunar/main.c
@@ -33,6 +33,8 @@
 #include <gio/gdesktopappinfo.h>
 #endif
 
+#include <xfconf/xfconf.h>
+
 #ifdef HAVE_LIBNOTIFY
 #include <thunar/thunar-notify.h>
 #endif
@@ -172,6 +174,14 @@ main (int argc, char **argv)
       return EXIT_SUCCESS;
     }
 
+  /* initialize xfconf */
+  if (!xfconf_init (&error))
+    {
+      g_critical ("Failed to initialize Xfconf: %s", error->message);
+      g_error_free (error);
+      return EXIT_FAILURE;
+    }
+
 #ifdef HAVE_GIO_UNIX
   /* set desktop environment for app infos */
   g_desktop_app_info_set_desktop_env ("XFCE");
diff --git a/thunar/thunar-preferences.c b/thunar/thunar-preferences.c
index d558221..ea5bdc8 100644
--- a/thunar/thunar-preferences.c
+++ b/thunar/thunar-preferences.c
@@ -42,7 +42,7 @@
 #include <thunar/thunar-gobject-extensions.h>
 #include <thunar/thunar-preferences.h>
 #include <thunar/thunar-private.h>
-
+#include <xfconf/xfconf.h>
 
 
 /* Property identifiers */
@@ -100,19 +100,11 @@ static void     thunar_preferences_set_property       (GObject                *o
                                                        guint                   prop_id,
                                                        const GValue           *value,
                                                        GParamSpec             *pspec);
-static void     thunar_preferences_resume_monitor     (ThunarPreferences      *preferences);
-static void     thunar_preferences_suspend_monitor    (ThunarPreferences      *preferences);
-static void     thunar_preferences_monitor            (GFileMonitor           *monitor,
-                                                       GFile                  *file,
-                                                       GFile                  *other_file,
-                                                       GFileMonitorEvent       event_type,
-                                                       gpointer                user_data);
-static void     thunar_preferences_queue_load         (ThunarPreferences      *preferences);
-static void     thunar_preferences_queue_store        (ThunarPreferences      *preferences);
-static gboolean thunar_preferences_load_idle          (gpointer                user_data);
-static void     thunar_preferences_load_idle_destroy  (gpointer                user_data);
-static gboolean thunar_preferences_store_idle         (gpointer                user_data);
-static void     thunar_preferences_store_idle_destroy (gpointer                user_data);
+static void     thunar_preferences_prop_changed       (XfconfChannel          *channel,
+                                                       const gchar            *prop_name,
+                                                       const GValue           *value,
+                                                       ThunarPreferences      *preferences);
+static void     thunar_preferences_load_rc_file       (ThunarPreferences      *preferences);
 
 
 
@@ -125,14 +117,7 @@ struct _ThunarPreferences
 {
   GObject __parent__;
 
-  GFileMonitor *monitor;
-
-  GValue        values[N_PROPERTIES];
-
-  gboolean      loading_in_progress;
-
-  gint          load_idle_id;
-  gint          store_idle_id;
+  XfconfChannel *channel;
 };
 
 
@@ -162,7 +147,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_DEFAULT_VIEW,
                                    g_param_spec_string ("default-view",
                                                         "DefaultView",
-                                                        "default-view",
+                                                        NULL,
                                                         "void",
                                                         EXO_PARAM_READWRITE));
 
@@ -175,7 +160,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_LAST_COMPACT_VIEW_ZOOM_LEVEL,
                                    g_param_spec_enum ("last-compact-view-zoom-level",
                                                       "LastCompactViewZoomLevel",
-                                                      "last-compact-view-zoom-level",
+                                                      NULL,
                                                       THUNAR_TYPE_ZOOM_LEVEL,
                                                       THUNAR_ZOOM_LEVEL_SMALLEST,
                                                       EXO_PARAM_READWRITE));
@@ -191,7 +176,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_LAST_DETAILS_VIEW_COLUMN_ORDER,
                                    g_param_spec_string ("last-details-view-column-order",
                                                         "LastDetailsViewColumnOrder",
-                                                        "last-details-view-column-order",
+                                                        NULL,
                                                         "THUNAR_COLUMN_NAME,THUNAR_COLUMN_SIZE,THUNAR_COLUMN_TYPE,THUNAR_COLUMN_DATE_MODIFIED",
                                                         EXO_PARAM_READWRITE));
 
@@ -205,7 +190,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_LAST_DETAILS_VIEW_COLUMN_WIDTHS,
                                    g_param_spec_string ("last-details-view-column-widths",
                                                         "LastDetailsViewColumnWidths",
-                                                        "last-details-view-column-widths",
+                                                        NULL,
                                                         "",
                                                         EXO_PARAM_READWRITE));
 
@@ -219,7 +204,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_LAST_DETAILS_VIEW_FIXED_COLUMNS,
                                    g_param_spec_boolean ("last-details-view-fixed-columns",
                                                          "LastDetailsViewFixedColumns",
-                                                         "last-details-view-fixed-columns",
+                                                         NULL,
                                                          FALSE,
                                                          EXO_PARAM_READWRITE));
 
@@ -232,7 +217,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_LAST_DETAILS_VIEW_VISIBLE_COLUMNS,
                                    g_param_spec_string ("last-details-view-visible-columns",
                                                         "LastDetailsViewVisibleColumns",
-                                                        "last-details-view-visible-columns",
+                                                        NULL,
                                                         "THUNAR_COLUMN_DATE_MODIFIED,THUNAR_COLUMN_NAME,THUNAR_COLUMN_SIZE,THUNAR_COLUMN_TYPE",
                                                         EXO_PARAM_READWRITE));
 
@@ -245,7 +230,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_LAST_DETAILS_VIEW_ZOOM_LEVEL,
                                    g_param_spec_enum ("last-details-view-zoom-level",
                                                       "LastDetailsViewZoomLevel",
-                                                      "last-details-view-zoom-level",
+                                                      NULL,
                                                       THUNAR_TYPE_ZOOM_LEVEL,
                                                       THUNAR_ZOOM_LEVEL_SMALLER,
                                                       EXO_PARAM_READWRITE));
@@ -259,7 +244,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_LAST_ICON_VIEW_ZOOM_LEVEL,
                                    g_param_spec_enum ("last-icon-view-zoom-level",
                                                       "LastIconViewZoomLevel",
-                                                      "last-icon-view-zoom-level",
+                                                      NULL,
                                                       THUNAR_TYPE_ZOOM_LEVEL,
                                                       THUNAR_ZOOM_LEVEL_NORMAL,
                                                       EXO_PARAM_READWRITE));
@@ -275,7 +260,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_LAST_LOCATION_BAR,
                                    g_param_spec_string ("last-location-bar",
                                                         "LastLocationBar",
-                                                        "last-location-bar",
+                                                        NULL,
                                                         "ThunarLocationButtons",
                                                         EXO_PARAM_READWRITE));
 
@@ -288,7 +273,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_LAST_MENUBAR_VISIBLE,
                                    g_param_spec_boolean ("last-menubar-visible",
                                                          "LastMenubarVisible",
-                                                         "last-menubar-visible",
+                                                         NULL,
                                                          TRUE,
                                                          EXO_PARAM_READWRITE));
 
@@ -302,7 +287,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_LAST_SEPARATOR_POSITION,
                                    g_param_spec_int ("last-separator-position",
                                                      "LastSeparatorPosition",
-                                                     "last-separator-position",
+                                                     NULL,
                                                      0, G_MAXINT, 170,
                                                      EXO_PARAM_READWRITE));
 
@@ -315,7 +300,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_LAST_SHOW_HIDDEN,
                                    g_param_spec_boolean ("last-show-hidden",
                                                          "LastShowHidden",
-                                                         "last-show-hidden",
+                                                         NULL,
                                                          FALSE,
                                                          EXO_PARAM_READWRITE));
 
@@ -330,7 +315,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_LAST_SIDE_PANE,
                                    g_param_spec_string ("last-side-pane",
                                                         "LastSidePane",
-                                                        "last-side-pane",
+                                                        NULL,
                                                         "ThunarShortcutsPane",
                                                         EXO_PARAM_READWRITE));
 
@@ -343,7 +328,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_LAST_SORT_COLUMN,
                                    g_param_spec_enum ("last-sort-column",
                                                       "LastSortColumn",
-                                                      "last-sort-column",
+                                                      NULL,
                                                       THUNAR_TYPE_COLUMN,
                                                       THUNAR_COLUMN_NAME,
                                                       EXO_PARAM_READWRITE));
@@ -357,7 +342,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_LAST_SORT_ORDER,
                                    g_param_spec_enum ("last-sort-order",
                                                       "LastSortOrder",
-                                                      "last-sort-order",
+                                                      NULL,
                                                       GTK_TYPE_SORT_TYPE,
                                                       GTK_SORT_ASCENDING,
                                                       EXO_PARAM_READWRITE));
@@ -370,7 +355,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_LAST_STATUSBAR_VISIBLE,
                                    g_param_spec_boolean ("last-statusbar-visible",
                                                          "LastStatusbarVisible",
-                                                         "last-statusbar-visible",
+                                                         NULL,
                                                          TRUE,
                                                          EXO_PARAM_READWRITE));
 
@@ -384,7 +369,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_LAST_VIEW,
                                    g_param_spec_string ("last-view",
                                                         "LastView",
-                                                        "last-view",
+                                                        NULL,
                                                         "ThunarIconView",
                                                         EXO_PARAM_READWRITE));
 
@@ -398,7 +383,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_LAST_WINDOW_HEIGHT,
                                    g_param_spec_int ("last-window-height",
                                                      "LastWindowHeight",
-                                                     "last-window-height",
+                                                     NULL,
                                                      1, G_MAXINT, 480,
                                                      EXO_PARAM_READWRITE));
 
@@ -412,10 +397,10 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_LAST_WINDOW_WIDTH,
                                    g_param_spec_int ("last-window-width",
                                                      "LastWindowWidth",
-                                                     "last-window-width",
+                                                     NULL,
                                                      1, G_MAXINT, 640,
                                                      EXO_PARAM_READWRITE));
-                                                     
+
   /**
    * ThunarPreferences:last-window-maximized:
    *
@@ -426,7 +411,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_LAST_WINDOW_FULLSCREEN,
                                    g_param_spec_boolean ("last-window-maximized",
                                                          "LastWindowMaximized",
-                                                         "last-window-maximized",
+                                                         NULL,
                                                          FALSE,
                                                          EXO_PARAM_READWRITE));
 
@@ -440,7 +425,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_MISC_VOLUME_MANAGEMENT,
                                    g_param_spec_boolean ("misc-volume-management",
                                                          "MiscVolumeManagement",
-                                                         "misc-volume-management",
+                                                         NULL,
                                                          TRUE,
                                                          EXO_PARAM_READWRITE));
 
@@ -453,7 +438,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_MISC_CASE_SENSITIVE,
                                    g_param_spec_boolean ("misc-case-sensitive",
                                                          "MiscCaseSensitive",
-                                                         "misc-case-sensitive",
+                                                         NULL,
                                                          FALSE,
                                                          EXO_PARAM_READWRITE));
 
@@ -466,7 +451,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_MISC_DATE_STYLE,
                                    g_param_spec_enum ("misc-date-style",
                                                       "MiscDateStyle",
-                                                      "misc-date-style",
+                                                      NULL,
                                                       THUNAR_TYPE_DATE_STYLE,
                                                       THUNAR_DATE_STYLE_SIMPLE,
                                                       EXO_PARAM_READWRITE));
@@ -480,7 +465,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_MISC_FOLDERS_FIRST,
                                    g_param_spec_boolean ("misc-folders-first",
                                                          "MiscFoldersFirst",
-                                                         "misc-folders-first",
+                                                         NULL,
                                                          TRUE,
                                                          EXO_PARAM_READWRITE));
 
@@ -494,7 +479,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_MISC_FULL_PATH_IN_TITLE,
                                    g_param_spec_boolean ("misc-full-path-in-title",
                                                          "MiscFullPathInTitle",
-                                                         "misc-full-path-in-title",
+                                                         NULL,
                                                          FALSE,
                                                          EXO_PARAM_READWRITE));
 
@@ -508,7 +493,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_MISC_HORIZONTAL_WHEEL_NAVIGATES,
                                    g_param_spec_boolean ("misc-horizontal-wheel-navigates",
                                                          "MiscHorizontalWheelNavigates",
-                                                         "misc-horizontal-wheel-navigates",
+                                                         NULL,
                                                          FALSE,
                                                          EXO_PARAM_READWRITE));
 
@@ -522,7 +507,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_MISC_RECURSIVE_PERMISSIONS,
                                    g_param_spec_enum ("misc-recursive-permissions",
                                                       "MiscRecursivePermissions",
-                                                      "misc-recursive-permissions",
+                                                      NULL,
                                                       THUNAR_TYPE_RECURSIVE_PERMISSIONS,
                                                       THUNAR_RECURSIVE_PERMISSIONS_ASK,
                                                       EXO_PARAM_READWRITE));
@@ -540,7 +525,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_MISC_REMEMBER_GEOMETRY,
                                    g_param_spec_boolean ("misc-remember-geometry",
                                                          "MiscRememberGeometry",
-                                                         "misc-remember-geometry",
+                                                         NULL,
                                                          TRUE,
                                                          EXO_PARAM_READWRITE));
 
@@ -554,7 +539,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_MISC_SHOW_ABOUT_TEMPLATES,
                                    g_param_spec_boolean ("misc-show-about-templates",
                                                          "MiscShowAboutTemplates",
-                                                         "misc-show-about-templates",
+                                                         NULL,
                                                          TRUE,
                                                          EXO_PARAM_READWRITE));
 
@@ -567,7 +552,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_MISC_SHOW_THUMBNAILS,
                                    g_param_spec_boolean ("misc-show-thumbnails",
                                                          "MiscShowThumbnails",
-                                                         "misc-show-thumbnails",
+                                                         NULL,
                                                          TRUE,
                                                          EXO_PARAM_READWRITE));
 
@@ -580,7 +565,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_MISC_SINGLE_CLICK,
                                    g_param_spec_boolean ("misc-single-click",
                                                          "MiscSingleClick",
-                                                         "misc-single-click",
+                                                         NULL,
                                                          FALSE,
                                                          EXO_PARAM_READWRITE));
 
@@ -596,7 +581,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_MISC_SINGLE_CLICK_TIMEOUT,
                                    g_param_spec_uint ("misc-single-click-timeout",
                                                       "MiscSingleClickTimeout",
-                                                      "misc-single-click-timeout",
+                                                      NULL,
                                                       0u, G_MAXUINT, 500u,
                                                       EXO_PARAM_READWRITE));
 
@@ -610,7 +595,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_MISC_TEXT_BESIDE_ICONS,
                                    g_param_spec_boolean ("misc-text-beside-icons",
                                                          "MiscTextBesideIcons",
-                                                         "misc-text-beside-icons",
+                                                         NULL,
                                                          FALSE,
                                                          EXO_PARAM_READWRITE));
 
@@ -624,7 +609,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_SHORTCUTS_ICON_EMBLEMS,
                                    g_param_spec_boolean ("shortcuts-icon-emblems",
                                                          "ShortcutsIconEmblems",
-                                                         "shortcuts-icon-emblems",
+                                                         NULL,
                                                          TRUE,
                                                          EXO_PARAM_READWRITE));
 
@@ -638,7 +623,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_SHORTCUTS_ICON_SIZE,
                                    g_param_spec_enum ("shortcuts-icon-size",
                                                       "ShortcutsIconSize",
-                                                      "shortcuts-icon-size",
+                                                      NULL,
                                                       THUNAR_TYPE_ICON_SIZE,
                                                       THUNAR_ICON_SIZE_SMALLER,
                                                       EXO_PARAM_READWRITE));
@@ -653,7 +638,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_TREE_ICON_EMBLEMS,
                                    g_param_spec_boolean ("tree-icon-emblems",
                                                          "TreeIconEmblems",
-                                                         "tree-icon-emblems",
+                                                         NULL,
                                                          TRUE,
                                                          EXO_PARAM_READWRITE));
 
@@ -667,7 +652,7 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                                    PROP_TREE_ICON_SIZE,
                                    g_param_spec_enum ("tree-icon-size",
                                                       "TreeIconSize",
-                                                      "tree-icon-size",
+                                                      NULL,
                                                       THUNAR_TYPE_ICON_SIZE,
                                                       THUNAR_ICON_SIZE_SMALLEST,
                                                       EXO_PARAM_READWRITE));
@@ -678,13 +663,24 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
 static void
 thunar_preferences_init (ThunarPreferences *preferences)
 {
-  preferences->monitor = NULL;
+  const gchar check_prop[] = "/last-view";
+
+  /* load the channel */
+  preferences->channel = xfconf_channel_new ("thunar");
+
+  /* check one of the property to see if there are values */
+  if (!xfconf_channel_has_property (preferences->channel, check_prop))
+    {
+      /* try to load the old config file */
+      thunar_preferences_load_rc_file (preferences);
 
-  /* load the settings */
-  thunar_preferences_load_idle (preferences);
+      /* set the string we check */
+      if (!xfconf_channel_has_property (preferences->channel, check_prop))
+        xfconf_channel_set_string (preferences->channel, check_prop, "ThunarIconView");
+    }
 
-  /* launch the file monitor */
-  thunar_preferences_resume_monitor (preferences);
+  g_signal_connect (G_OBJECT (preferences->channel), "property-changed",
+                    G_CALLBACK (thunar_preferences_prop_changed), preferences);
 }
 
 
@@ -693,30 +689,9 @@ static void
 thunar_preferences_finalize (GObject *object)
 {
   ThunarPreferences *preferences = THUNAR_PREFERENCES (object);
-  guint              n;
 
-  /* flush preferences */
-  if (G_UNLIKELY (preferences->store_idle_id != 0))
-    {
-      thunar_preferences_store_idle (preferences);
-      g_source_remove (preferences->store_idle_id);
-    }
-
-  /* stop any pending load idle source */
-  if (G_UNLIKELY (preferences->load_idle_id != 0))
-    g_source_remove (preferences->load_idle_id);
-
-  /* stop the file monitor */
-  if (G_LIKELY (preferences->monitor != NULL))
-    {
-      thunar_preferences_suspend_monitor (preferences);
-      g_object_unref (G_OBJECT (preferences->monitor));
-    }
-
-  /* release the property values */
-  for (n = 1; n < N_PROPERTIES; ++n)
-    if (G_IS_VALUE (preferences->values + n))
-      g_value_unset (preferences->values + n);
+  /* release the channel */
+  g_object_unref (G_OBJECT (preferences->channel));
 
   (*G_OBJECT_CLASS (thunar_preferences_parent_class)->finalize) (object);
 }
@@ -730,13 +705,25 @@ thunar_preferences_get_property (GObject    *object,
                                  GParamSpec *pspec)
 {
   ThunarPreferences *preferences = THUNAR_PREFERENCES (object);
-  GValue            *src;
+  GValue             src = { 0, };
+  gchar              prop_name[64];
 
-  src = preferences->values + prop_id;
-  if (G_IS_VALUE (src))
-    g_value_copy (src, value);
+  /* build property name */
+  g_snprintf (prop_name, sizeof (prop_name), "/%s", g_param_spec_get_name (pspec));
+
+  if (xfconf_channel_get_property (preferences->channel, prop_name, &src))
+    {
+      if (G_VALUE_TYPE (value) == G_VALUE_TYPE (&src))
+        g_value_copy (&src, value);
+      else if (!g_value_transform (&src, value))
+        g_printerr ("Thunar: Failed to transform property %s", prop_name);
+      g_value_unset (&src);
+    }
   else
-    g_param_value_set_default (pspec, value);
+    {
+      /* value is not found, return default */
+      g_param_value_set_default (pspec, value);
+    }
 }
 
 
@@ -748,316 +735,124 @@ thunar_preferences_set_property (GObject      *object,
                                  GParamSpec   *pspec)
 {
   ThunarPreferences *preferences = THUNAR_PREFERENCES (object);
-  GValue            *dst;
-
-  dst = preferences->values + prop_id;
-  if (G_UNLIKELY (!G_IS_VALUE (dst)))
-    {
-      g_value_init (dst, pspec->value_type);
-      g_param_value_set_default (pspec, dst);
-    }
-
-  if (g_param_values_cmp (pspec, value, dst) != 0)
-    {
-      g_value_copy (value, dst);
-      thunar_preferences_queue_store (preferences);
-    }
-}
-
-
+  GValue             dst = { 0, };
+  gchar              prop_name[64];
 
-static void
-thunar_preferences_resume_monitor (ThunarPreferences *preferences)
-{
-  GFile *file;
-  gchar *filename;
+  /* build property name */
+  g_snprintf (prop_name, sizeof (prop_name), "/%s", g_param_spec_get_name (pspec));
 
-  /* verify that the monitor is suspended */
-  if (G_LIKELY (preferences->monitor == NULL))
+  if (G_VALUE_HOLDS_ENUM (value))
     {
-      /* determine the save location for thunarrc to monitor */
-      filename = xfce_resource_save_location (XFCE_RESOURCE_CONFIG, "Thunar/thunarrc", TRUE);
-      if (G_LIKELY (filename != NULL))
-        {
-          /* monitor this file */
-          file = g_file_new_for_path (filename);
-          preferences->monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL);
-          if (G_LIKELY (preferences->monitor != NULL))
-            g_signal_connect (preferences->monitor, "changed", G_CALLBACK (thunar_preferences_monitor), preferences);
-          g_object_unref (file);
-
-          /* release the filename */
-          g_free (filename);
-        }
+      /* convert into a string */
+      g_value_init (&dst, G_TYPE_STRING);
+      if (g_value_transform (value, &dst))
+        xfconf_channel_set_property (preferences->channel, prop_name, &dst);
+      g_value_unset (&dst);
     }
-}
-
-
-
-static void
-thunar_preferences_suspend_monitor (ThunarPreferences *preferences)
-{
-  /* verify that the monitor is active */
-  if (G_LIKELY (preferences->monitor != NULL 
-                && !g_file_monitor_is_cancelled (preferences->monitor)))
+  else
     {
-      /* disconnect the handle from the monitor */
-      g_file_monitor_cancel (preferences->monitor);
+      /* other types we support directly */
+      xfconf_channel_set_property (preferences->channel, prop_name, value);
     }
 }
 
 
 
 static void
-thunar_preferences_monitor (GFileMonitor           *monitor,
-                            GFile                  *file,
-                            GFile                  *other_file,
-                            GFileMonitorEvent       event_type,
-                            gpointer                user_data)
+thunar_preferences_prop_changed (XfconfChannel     *channel,
+                                 const gchar       *prop_name,
+                                 const GValue      *value,
+                                 ThunarPreferences *preferences)
 {
-  ThunarPreferences *preferences = THUNAR_PREFERENCES (user_data);
-
-  _thunar_return_if_fail (THUNAR_IS_PREFERENCES (preferences));
-  _thunar_return_if_fail (G_IS_FILE_MONITOR (monitor));
-  _thunar_return_if_fail (preferences->monitor == monitor);
-
-  /* schedule a reload whenever the file is created/changed */
-  if (event_type == G_FILE_MONITOR_EVENT_CHANGED 
-      || event_type == G_FILE_MONITOR_EVENT_CREATED)
-    {
-      thunar_preferences_queue_load (preferences);
-    }
-}
-
-
+  GParamSpec *pspec;
 
-static void
-thunar_preferences_queue_load (ThunarPreferences *preferences)
-{
-  if (preferences->load_idle_id == 0 && preferences->store_idle_id == 0)
-    {
-      preferences->load_idle_id = g_idle_add_full (G_PRIORITY_LOW, thunar_preferences_load_idle,
-                                                   preferences, thunar_preferences_load_idle_destroy);
-    }
+  /* check if the property exists and emit change */
+  pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (preferences), prop_name + 1);
+  if (G_LIKELY (pspec != NULL))
+    g_object_notify_by_pspec (G_OBJECT (preferences), pspec);
 }
 
 
 
 static void
-thunar_preferences_queue_store (ThunarPreferences *preferences)
-{
-  if (preferences->store_idle_id == 0 && !preferences->loading_in_progress)
-    {
-      preferences->store_idle_id = g_idle_add_full (G_PRIORITY_LOW, thunar_preferences_store_idle,
-                                                    preferences, thunar_preferences_store_idle_destroy);
-    }
-}
-
-
-
-#ifndef NDEBUG
-static gchar*
-property_name_to_option_name (const gchar *property_name)
+thunar_preferences_load_rc_file (ThunarPreferences *preferences)
 {
-  const gchar *s;
-  gboolean     upper = TRUE;
-  gchar       *option;
-  gchar       *t;
-
-  option = g_new (gchar, strlen (property_name) + 1);
-  for (s = property_name, t = option; *s != '\0'; ++s)
-    {
-      if (*s == '-')
-        {
-          upper = TRUE;
-        }
-      else if (upper)
-        {
-          *t++ = g_ascii_toupper (*s);
-          upper = FALSE;
-        }
-      else
-        {
-          *t++ = *s;
-        }
-    }
-  *t = '\0';
-
-  return option;
-}
-#endif
-
-
-
-static gboolean
-thunar_preferences_load_idle (gpointer user_data)
-{
-  ThunarPreferences *preferences = THUNAR_PREFERENCES (user_data);
-  const gchar       *string;
-  GParamSpec       **specs;
-  GParamSpec        *spec;
-  XfceRc            *rc;
-  GValue             dst = { 0, };
-  GValue             src = { 0, };
-#ifndef NDEBUG
-  gchar             *option;
-#endif
-  guint              nspecs;
-  guint              n;
-
-  rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, "Thunar/thunarrc", TRUE);
+  GParamSpec  **pspecs;
+  GParamSpec   *pspec;
+  XfceRc       *rc;
+  guint         nspecs, n;
+  const gchar  *string;
+  GValue        dst = { 0, };
+  GValue        src = { 0, };
+  gchar         prop_name[64];
+  const gchar  *nick;
+  gchar        *filename;
+
+  /* find file */
+  filename = xfce_resource_lookup (XFCE_RESOURCE_CONFIG, "Thunar/thunarrc");
+  if (G_UNLIKELY (filename == NULL))
+    return;
+
+  /* look for preferences */
+  rc = xfce_rc_simple_open (filename, TRUE);
   if (G_UNLIKELY (rc == NULL))
-    {
-      g_warning ("Failed to load thunar preferences.");
-      return FALSE;
-    }
-
-  g_object_freeze_notify (G_OBJECT (preferences));
+    return;
 
   xfce_rc_set_group (rc, "Configuration");
 
-  preferences->loading_in_progress = TRUE;
-
-  specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (preferences), &nspecs);
+  pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (preferences), &nspecs);
   for (n = 0; n < nspecs; ++n)
     {
-      spec = specs[n];
-
-#ifndef NDEBUG
-      /* when debugging is enabled, check if the generated option name
-       * is equal to the nickname, to prevent typos */
-      option = property_name_to_option_name (spec->name);
-      g_assert (exo_str_is_equal (option, g_param_spec_get_nick (spec)));
-      g_free (option);
-#endif
+      pspec = pspecs[n];
 
-      string = xfce_rc_read_entry (rc, g_param_spec_get_nick (spec), NULL);
+      /* continue if the nick is null */
+      nick = g_param_spec_get_nick (pspec);
+      if (G_UNLIKELY (nick == NULL))
+        continue;
 
+      /* read the value from the rc file */
+      string = xfce_rc_read_entry (rc, nick, NULL);
       if (G_UNLIKELY (string == NULL))
         continue;
 
+      /* xfconf property name, continue if exists */
+      g_snprintf (prop_name, sizeof (prop_name), "/%s", g_param_spec_get_name (pspec));
+      if (xfconf_channel_has_property (preferences->channel, prop_name))
+        continue;
+
+      /* source property */
       g_value_init (&src, G_TYPE_STRING);
       g_value_set_static_string (&src, string);
 
-      if (spec->value_type == G_TYPE_STRING)
+      /* store string and enums directly */
+      if (G_IS_PARAM_SPEC_STRING (pspec) || G_IS_PARAM_SPEC_ENUM (pspec))
         {
-          g_object_set_property (G_OBJECT (preferences), spec->name, &src);
+          xfconf_channel_set_property (preferences->channel, prop_name, &src);
         }
-      else if (g_value_type_transformable (G_TYPE_STRING, spec->value_type))
+      else if (g_value_type_transformable (G_TYPE_STRING, G_PARAM_SPEC_VALUE_TYPE (pspec)))
         {
-          g_value_init (&dst, spec->value_type);
+          g_value_init (&dst, G_PARAM_SPEC_VALUE_TYPE (pspec));
           if (g_value_transform (&src, &dst))
-            g_object_set_property (G_OBJECT (preferences), spec->name, &dst);
+            xfconf_channel_set_property (preferences->channel, prop_name, &dst);
           g_value_unset (&dst);
         }
       else
         {
-          g_warning ("Failed to load property \"%s\"", spec->name);
+          g_warning ("Failed to migrate property \"%s\"", g_param_spec_get_name (pspec));
         }
 
       g_value_unset (&src);
     }
-  g_free (specs);
-
-  preferences->loading_in_progress = FALSE;
 
+  g_free (pspecs);
   xfce_rc_close (rc);
 
-  g_object_thaw_notify (G_OBJECT (preferences));
-
-  return FALSE;
-}
-
-
+  g_print ("\n\n"
+           "Your Thunar settings have been migrated to Xfconf.\n"
+           "The config file \"%s\"\n"
+           "is not used anymore.\n\n", filename);
 
-static void
-thunar_preferences_load_idle_destroy (gpointer user_data)
-{
-  THUNAR_PREFERENCES (user_data)->load_idle_id = 0;
-}
-
-
-
-static gboolean
-thunar_preferences_store_idle (gpointer user_data)
-{
-  ThunarPreferences *preferences = THUNAR_PREFERENCES (user_data);
-  const gchar       *string;
-  GParamSpec       **specs;
-  GParamSpec        *spec;
-  XfceRc            *rc;
-  GValue             dst = { 0, };
-  GValue             src = { 0, };
-#ifndef NDEBUG
-  gchar             *option;
-#endif
-  guint              nspecs;
-  guint              n;
-
-  rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, "Thunar/thunarrc", FALSE);
-  if (G_UNLIKELY (rc == NULL))
-    {
-      g_warning ("Failed to store thunar preferences.");
-      return FALSE;
-    }
-
-  /* suspend the monitor (hopefully tricking FAM to avoid unnecessary reloads) */
-  thunar_preferences_suspend_monitor (preferences);
-
-  xfce_rc_set_group (rc, "Configuration");
-
-  specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (preferences), &nspecs);
-  for (n = 0; n < nspecs; ++n)
-    {
-      spec = specs[n];
-
-      g_value_init (&dst, G_TYPE_STRING);
-
-      if (spec->value_type == G_TYPE_STRING)
-        {
-          g_object_get_property (G_OBJECT (preferences), spec->name, &dst);
-        }
-      else
-        {
-          g_value_init (&src, spec->value_type);
-          g_object_get_property (G_OBJECT (preferences), spec->name, &src);
-          g_value_transform (&src, &dst);
-          g_value_unset (&src);
-        }
-
-#ifndef NDEBUG
-      /* when debugging is enabled, check if the generated option name
-       * is equal to the nickname, to prevent typos */
-      option = property_name_to_option_name (spec->name);
-      g_assert (exo_str_is_equal (option, g_param_spec_get_nick (spec)));
-      g_free (option);
-#endif
-
-      /* store the setting */
-      string = g_value_get_string (&dst);
-      if (G_LIKELY (string != NULL))
-        xfce_rc_write_entry (rc, g_param_spec_get_nick (spec), string);
-
-      /* cleanup */
-      g_value_unset (&dst);
-    }
-
-  /* cleanup */
-  xfce_rc_close (rc);
-  g_free (specs);
-
-  /* restart the monitor */
-  thunar_preferences_resume_monitor (preferences);
-
-  return FALSE;
-}
-
-
-
-static void
-thunar_preferences_store_idle_destroy (gpointer user_data)
-{
-  THUNAR_PREFERENCES (user_data)->store_idle_id = 0;
+  g_free (filename);
 }
 
 


More information about the Xfce4-commits mailing list