From ace00efd348b1ded0307e798925539f886d9e833 Mon Sep 17 00:00:00 2001 From: Harald Judt Date: Thu, 14 May 2015 20:19:24 +0200 Subject: Fix loading the trash bin status at startup (bug #9513) When the gvfsd-trash daemon has not spawned and thunar accesses the trash bin "trash:///" the first time, then the trash bin does not have 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 again after 2 and 3 seconds. By that time the gvfs trash daemon should have spawned hopefully. This is only necessary when first loading the file. --- thunar/thunar-file.c | 37 +++++++++++++++++++++++++++++++++++++ thunar/thunar-file.h | 2 ++ 2 files changed, 39 insertions(+) diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index 44c1213..e67bfd4 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -1243,6 +1243,22 @@ thunar_file_get (GFile *gfile, /* done inserting in the cache */ G_UNLOCK (file_cache_mutex); + + /* if we are loading the trash bin for the first time (which + * means it is not cached), then reload it in idle later, + * when it is very likely the gvfsd-trash backend daemon has + * spawned already (bug #9513) */ + if (g_file_has_uri_scheme (file->gfile, "trash")) + { + gchar *uri = thunar_file_info_get_uri (THUNARX_FILE_INFO (file)); + if (g_strcmp0 (uri, "trash:///") == 0) + { + thunar_file_reload_idle (file); + thunar_file_reload_idle_timeout (file, 2000); + thunar_file_reload_idle_timeout (file, 3000); + } + g_free (uri); + } } else { @@ -3952,6 +3968,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); -- 2.4.0