--- a/thunar/main.c +++ b/thunar/main.c @@ -53,7 +53,7 @@ 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 @@ } 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 @@ +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) { @@ -249,6 +288,14 @@ /* 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 (); @@ -314,6 +361,13 @@ 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)); --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -3756,6 +3756,45 @@ /** + * thunar_file_reload_idle: + * @file : a #ThunarFile instance. + * + * Schedules a reload of the @file by calling thunar_file_reload + * when idle. + * + **/ +void +thunar_file_reload_idle (ThunarFile *file) +{ + _thunar_return_if_fail (THUNAR_IS_FILE (file)); + + g_idle_add ((GSourceFunc) thunar_file_reload, 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. * --- a/thunar/thunar-file.h +++ b/thunar/thunar-file.h @@ -237,6 +237,9 @@ void thunar_file_unwatch (ThunarFile *file); 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_destroy (ThunarFile *file);