[Xfce4-commits] [xfce/thunar] 03/06: Fix loading the trash bin status at startup (bug #9513)

noreply at xfce.org noreply at xfce.org
Fri May 15 18:37:07 CEST 2015


This is an automated email from the git hooks/post-receive script.

hjudt pushed a commit to branch master
in repository xfce/thunar.

commit 2d5567b2f6ae6223c8865547704797a5c785ec1f
Author: Harald Judt <h.judt at gmx.at>
Date:   Thu May 14 20:19:24 2015 +0200

    Fix loading the trash bin status at startup (bug #9513)
    
    If the gvfsd-trash daemon has not spawned and thunar accesses the trash bin
    "trash:///" the first time, then the trash bin does not report the correct
    state. This is probably because the daemon needs some time to spawn and get
    ready.
    
    As a solution, lets reload the trash file in idle when it is first created,
    and then again a bit later after a few seconds have passed. By that time
    the gvfs trash daemon should have spawned and the state is properly set.
    This is only necessary when first loading the file, not when getting it
    from the cache, so we put this into main to be run at startup.
---
 thunar/main.c        |   56 +++++++++++++++++++++++++++++++++++++++++++++++++-
 thunar/thunar-file.c |   21 +++++++++++++++++++
 thunar/thunar-file.h |    2 ++
 3 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/thunar/main.c b/thunar/main.c
index e2eff3e..fc0c91b 100644
--- a/thunar/main.c
+++ b/thunar/main.c
@@ -53,7 +53,7 @@ static gboolean opt_daemon = FALSE;
 static gchar   *opt_sm_client_id = NULL;
 static gboolean opt_quit = FALSE;
 static gboolean opt_version = FALSE;
-
+static ThunarFile *thunar_trash_file = NULL;
 
 
 /* --- command line options --- */
@@ -97,6 +97,13 @@ thunar_delayed_exit_check (gpointer user_data)
     }
   else
     {
+      /* unref the trash bin */
+      if (thunar_trash_file != NULL)
+        {
+          g_object_unref (thunar_trash_file);
+          thunar_trash_file = NULL;
+        }
+
       /* no command line arguments opened in Thunar, exit now */
       gtk_main_quit ();
 
@@ -108,6 +115,38 @@ thunar_delayed_exit_check (gpointer user_data)
 
 
 
+static void
+thunar_force_spawn_trash (void)
+{
+  GFile      *trash;
+
+  /* check that this has not happened yet */
+  if (thunar_trash_file != NULL)
+    return;
+
+  /* gvfs has no trash support */
+  if (!thunar_g_vfs_is_uri_scheme_supported ("trash"))
+    return;
+
+  trash = thunar_g_file_new_for_trash ();
+  thunar_trash_file = thunar_file_cache_lookup (trash);
+  if (thunar_trash_file == NULL)
+    {
+      thunar_trash_file = thunar_file_get (trash, NULL);
+      if (thunar_trash_file)
+        {
+          /* schedule a few reloads */
+          thunar_file_reload_idle (thunar_trash_file);
+          thunar_file_reload_idle_timeout (thunar_trash_file, 2000);
+          thunar_file_reload_idle_timeout (thunar_trash_file, 3000);
+          thunar_file_reload_idle_timeout (thunar_trash_file, 5000);
+        }
+    }
+  g_object_unref (trash);
+}
+
+
+
 int
 main (int argc, char **argv)
 {
@@ -251,6 +290,14 @@ main (int argc, char **argv)
   /* initialize the thunar stock items/icons */
   thunar_stock_init ();
 
+  /* For the trash state to be correct, gvfsd-trash needs to have been
+   * spawned. If the trash file is not in cache, this means we could
+   * access it the first time and the daemon might not have been
+   * spawned yet. So let's reload the trash later in idle, so that
+   * the state gets updated correctly (bug #9513).
+   */
+  thunar_force_spawn_trash ();
+
   /* acquire a reference on the global application */
   application = thunar_application_get ();
 
@@ -316,6 +363,13 @@ error0:
     g_object_unref (G_OBJECT (dbus_service));
 #endif
 
+  /* unreference the trash file */
+  if (thunar_trash_file != NULL)
+    {
+      g_object_unref (thunar_trash_file);
+      thunar_trash_file = NULL;
+    }
+
   /* disconnect from the session manager */
   g_object_unref (G_OBJECT (session_client));
 
diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index 44c1213..4ab921f 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -3952,6 +3952,27 @@ thunar_file_reload_idle (ThunarFile *file)
 
 
 /**
+ * thunar_file_reload_idle_timeout:
+ * @file    : a #ThunarFile instance.
+ * @timeout : the timeout in ms after which the reload should happen
+ *
+ * Schedules a reload of the @file by calling thunar_file_reload in
+ * idle after @timeout milliseconds have passed.
+ *
+ **/
+void
+thunar_file_reload_idle_timeout (ThunarFile *file,
+                                 guint timeout)
+{
+  _thunar_return_if_fail (THUNAR_IS_FILE (file));
+
+  g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE, timeout,
+                      (GSourceFunc) thunar_file_reload, file, NULL);
+}
+
+
+
+/**
  * thunar_file_destroy:
  * @file : a #ThunarFile instance.
  *
diff --git a/thunar/thunar-file.h b/thunar/thunar-file.h
index 9a3de17..1704aca 100644
--- a/thunar/thunar-file.h
+++ b/thunar/thunar-file.h
@@ -241,6 +241,8 @@ void              thunar_file_unwatch                    (ThunarFile
 
 void              thunar_file_reload                     (ThunarFile              *file);
 void              thunar_file_reload_idle                (ThunarFile              *file);
+void              thunar_file_reload_idle_timeout        (ThunarFile              *file,
+                                                          guint                    timeout);
 void              thunar_file_reload_parent              (ThunarFile              *file);
 
 void              thunar_file_destroy                    (ThunarFile              *file);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list