From 2d5567b2f6ae6223c8865547704797a5c785ec1f Mon Sep 17 00:00:00 2001 From: Harald Judt <h.judt@gmx.at> Date: Thu, 14 May 2015 20:19:24 +0200 Subject: [PATCH] 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 e2eff3eda..fc0c91b01 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 44c12132c..4ab921fbf 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -3951,6 +3951,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 9a3de1782..1704aca50 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); -- GitLab