commit a06853cd1a46bdcbf7d49da7fba5023bba353a71 Author: Harald Judt Date: Mon May 18 19:07:33 2015 +0200 Revert "Revert changes for restoring the trash in the session client (bug #9513)" This reverts commit 61e52c7d53bf612b532dd1b8d7d49352cee1597e. diff --git a/thunar/thunar-session-client.c b/thunar/thunar-session-client.c index de8db1f..303e484 100644 --- a/thunar/thunar-session-client.c +++ b/thunar/thunar-session-client.c @@ -79,6 +79,9 @@ struct _ThunarSessionClient gchar *path; gchar *id; + guint trash_load_idle; + guint trash_checks; + #ifdef HAVE_LIBSM SmcConn connection; #endif @@ -115,6 +118,9 @@ thunar_session_client_finalize (GObject *object) { ThunarSessionClient *session_client = THUNAR_SESSION_CLIENT (object); + if (session_client->trash_load_idle != 0) + g_source_remove (session_client->trash_load_idle); + #ifdef HAVE_LIBSM /* disconnect from the session manager */ if (G_LIKELY (session_client->connection != NULL)) @@ -269,6 +275,43 @@ thunar_session_client_connect (ThunarSessionClient *session_client, +static gboolean +thunar_session_client_restore_trash (gpointer data) +{ + ThunarSessionClient *session_client = THUNAR_SESSION_CLIENT (data); + GFile *trash; + ThunarFile *directory; + guint32 item_count = 0; + + /* make sure the trash is loaded */ + trash = thunar_g_file_new_for_trash (); + directory = thunar_file_cache_lookup (trash); + g_object_unref (trash); + + if (G_LIKELY (directory != NULL)) + { + thunar_file_reload (directory); + item_count = thunar_file_get_item_count (directory); + g_object_unref (directory); + } + + /* continue checking for 15 seconds or files are found */ + return (session_client->trash_checks++ < 5 && item_count == 0); +} + + + +static void +thunar_session_client_restore_finised (gpointer data) +{ + ThunarSessionClient *session_client = THUNAR_SESSION_CLIENT (data); + + session_client->trash_load_idle = 0; + session_client->trash_checks = 0; +} + + + static void thunar_session_client_restore (ThunarSessionClient *session_client) { @@ -313,7 +356,17 @@ thunar_session_client_restore (ThunarSessionClient *session_client) gtk_widget_show (window); /* open tabs */ - if (!thunar_window_set_directories (THUNAR_WINDOW (window), uris, active_tab)) + if (thunar_window_set_directories (THUNAR_WINDOW (window), uris, active_tab)) + { + /* add idle to make sure the trash status is up2date (bug #9513) */ + if (session_client->trash_load_idle == 0) + { + session_client->trash_load_idle = + g_timeout_add_seconds_full (G_PRIORITY_DEFAULT_IDLE, 3, thunar_session_client_restore_trash, + session_client, thunar_session_client_restore_finised); + } + } + else { /* no tabs were opened */ gtk_widget_destroy (window);