[Xfce4-commits] <thunar:master> Fallback to only default values if xfconf failed.

Nick Schermer noreply at xfce.org
Tue Nov 6 19:10:01 CET 2012


Updating branch refs/heads/master
         to 48f01622ea50d0275bd165114e8e3d09fc70b7fe (commit)
       from bddf31b2cd54b2bbd589ec6a4c395a3aa88f9c50 (commit)

commit 48f01622ea50d0275bd165114e8e3d09fc70b7fe
Author: Nick Schermer <nick at xfce.org>
Date:   Tue Nov 6 18:40:04 2012 +0100

    Fallback to only default values if xfconf failed.
    
    This can happen when running as root. Fallback to only loading
    default values and no saving.

 thunar/main.c               |    9 ++++++---
 thunar/thunar-preferences.c |   28 +++++++++++++++++++++++++++-
 thunar/thunar-preferences.h |    6 ++++--
 3 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/thunar/main.c b/thunar/main.c
index 218f90f..bb42f68 100644
--- a/thunar/main.c
+++ b/thunar/main.c
@@ -43,6 +43,7 @@
 #include <thunar/thunar-notify.h>
 #include <thunar/thunar-session-client.h>
 #include <thunar/thunar-stock.h>
+#include <thunar/thunar-preferences.h>
 
 
 
@@ -176,9 +177,11 @@ main (int argc, char **argv)
   /* initialize xfconf */
   if (!xfconf_init (&error))
     {
-      g_critical ("Failed to initialize Xfconf: %s", error->message);
-      g_error_free (error);
-      return EXIT_FAILURE;
+      g_printerr (PACKAGE_NAME ": Failed to initialize Xfconf: %s\n\n", error->message);
+      g_clear_error (&error);
+
+      /* disable get/set properties */
+      thunar_preferences_xfconf_init_failed ();
     }
 
 #ifdef HAVE_GIO_UNIX
diff --git a/thunar/thunar-preferences.c b/thunar/thunar-preferences.c
index ef4c06b..8d6b8cd 100644
--- a/thunar/thunar-preferences.c
+++ b/thunar/thunar-preferences.c
@@ -130,6 +130,11 @@ struct _ThunarPreferences
 
 
 
+/* don't do anything in case xfconf_init() failed */
+static gboolean no_xfconf = FALSE;
+
+
+
 G_DEFINE_TYPE (ThunarPreferences, thunar_preferences, G_TYPE_OBJECT)
 
 
@@ -755,6 +760,10 @@ thunar_preferences_init (ThunarPreferences *preferences)
 {
   const gchar check_prop[] = "/last-view";
 
+  /* don't set a channel if xfconf init failed */
+  if (no_xfconf)
+    return;
+
   /* load the channel */
   preferences->channel = xfconf_channel_get ("thunar");
 
@@ -800,6 +809,13 @@ thunar_preferences_get_property (GObject    *object,
   gchar               prop_name[64];
   gchar             **array;
 
+  /* only set defaults if channel is not set */
+  if (G_UNLIKELY (preferences->channel == NULL))
+    {
+      g_param_value_set_default (pspec, value);
+      return;
+    }
+
   /* build property name */
   g_snprintf (prop_name, sizeof (prop_name), "/%s", g_param_spec_get_name (pspec));
 
@@ -809,7 +825,7 @@ thunar_preferences_get_property (GObject    *object,
       array = xfconf_channel_get_string_list (preferences->channel, prop_name);
       g_value_take_boxed (value, array);
     }
-  else if (xfconf_channel_get_property (preferences->channel, prop_name, &src))
+  else if (0&&xfconf_channel_get_property (preferences->channel, prop_name, &src))
     {
       if (G_VALUE_TYPE (value) == G_VALUE_TYPE (&src))
         g_value_copy (&src, value);
@@ -837,6 +853,10 @@ thunar_preferences_set_property (GObject      *object,
   gchar               prop_name[64];
   gchar             **array;
 
+  /* leave if the channel is not set */
+  if (G_UNLIKELY (preferences->channel == NULL))
+    return;
+
   /* build property name */
   g_snprintf (prop_name, sizeof (prop_name), "/%s", g_param_spec_get_name (pspec));
 
@@ -1001,3 +1021,9 @@ thunar_preferences_get (void)
 }
 
 
+
+void
+thunar_preferences_xfconf_init_failed (void)
+{
+  no_xfconf = TRUE;
+}
diff --git a/thunar/thunar-preferences.h b/thunar/thunar-preferences.h
index 32eb20c..8f45eb2 100644
--- a/thunar/thunar-preferences.h
+++ b/thunar/thunar-preferences.h
@@ -34,9 +34,11 @@ typedef struct _ThunarPreferences      ThunarPreferences;
 #define THUNAR_IS_PREFERENCES_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), THUNAR_TYPE_PREFERENCES))
 #define THUNAR_PREFERENCES_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), THUNAR_TYPE_PREFERENCES, ThunarPreferencesClass))
 
-GType              thunar_preferences_get_type (void) G_GNUC_CONST;
+GType              thunar_preferences_get_type           (void) G_GNUC_CONST;
 
-ThunarPreferences *thunar_preferences_get      (void);
+ThunarPreferences *thunar_preferences_get                (void);
+
+void               thunar_preferences_xfconf_init_failed (void);
 
 G_END_DECLS;
 


More information about the Xfce4-commits mailing list