[Xfce4-commits] <thunar:master> Make emptying the trash work again.

Jannis Pohlmann jannis at xfce.org
Thu Sep 3 14:26:01 CEST 2009


Updating branch refs/heads/master
         to 93817ae8bd6337648e3b2dd71f7f48a5e70320b6 (commit)
       from dd385ea8b70a87d281e4be6e07fbf698c0f05cce (commit)

commit 93817ae8bd6337648e3b2dd71f7f48a5e70320b6
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Thu Sep 3 14:20:52 2009 +0200

    Make emptying the trash work again.
    
    With GIO, the size of the trash:/// directory no longer corresponds to
    whether the trash is empty or not. Instead, we have to use the
    G_FILE_ATTRIBUTE_TRASH_ITEM_COUNT attribute. This commit adds a new
    method thunar_file_get_item_count() which is used the shortcuts pane and
    the tree view to make the empty trash action sensitive or insensitive.
    
    Also remove a few redundant g_file_info_has_attribute() checks.

 thunar/thunar-file.c           |   27 ++++++++++++++++++++++++---
 thunar/thunar-file.h           |    1 +
 thunar/thunar-shortcuts-view.c |    2 +-
 thunar/thunar-tree-view.c      |    2 +-
 4 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index 5149d4f..f0ac95a 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -2280,10 +2280,31 @@ thunar_file_get_original_path (const ThunarFile *file)
   if (file->info == NULL)
     return NULL;
 
-  if (g_file_info_has_attribute (file->info, "trash::orig-path"))
-    return g_file_info_get_attribute_byte_string (file->info, "trash::orig-path");
-  else
+  g_file_info_get_attribute_byte_string (file->info, "trash::orig-path");
+}
+
+
+
+/**
+ * thunar_file_get_item_count:
+ * @file : a #ThunarFile instance.
+ *
+ * Returns the number of items in the trash, if @file refers to the
+ * trash root directory. Otherwise returns 0.
+ *
+ * Return value: number of files in the trash if @file is the trash 
+ *               root dir, 0 otherwise.
+ **/
+const gchar *
+thunar_file_get_item_count (const ThunarFile *file)
+{
+  _thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
+
+  if (file->info == NULL)
     return NULL;
+
+  return g_file_info_get_attribute_uint32 (file->info, 
+                                           G_FILE_ATTRIBUTE_TRASH_ITEM_COUNT);
 }
 
 
diff --git a/thunar/thunar-file.h b/thunar/thunar-file.h
index 1a760e0..3a98b57 100644
--- a/thunar/thunar-file.h
+++ b/thunar/thunar-file.h
@@ -204,6 +204,7 @@ const gchar      *thunar_file_get_display_name     (const ThunarFile       *file
 gchar            *thunar_file_get_deletion_date    (const ThunarFile       *file,
                                                     ThunarDateStyle         date_style) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
 const gchar      *thunar_file_get_original_path    (const ThunarFile       *file);
+guint64           thunar_file_get_trash_item_count (const ThunarFile       *file);
 
 gboolean          thunar_file_is_chmodable         (const ThunarFile       *file);
 gboolean          thunar_file_is_renameable        (const ThunarFile       *file);
diff --git a/thunar/thunar-shortcuts-view.c b/thunar/thunar-shortcuts-view.c
index a7da72a..2ba4b61 100644
--- a/thunar/thunar-shortcuts-view.c
+++ b/thunar/thunar-shortcuts-view.c
@@ -832,7 +832,7 @@ thunar_shortcuts_view_context_menu (ThunarShortcutsView *view,
     {
       /* append the "Empty Trash" menu action */
       item = gtk_image_menu_item_new_with_mnemonic (_("_Empty Trash"));
-      gtk_widget_set_sensitive (item, (thunar_file_get_size (file) > 0));
+      gtk_widget_set_sensitive (item, (thunar_file_get_item_count (file) > 0));
       g_signal_connect_swapped (G_OBJECT (item), "activate", G_CALLBACK (thunar_shortcuts_view_empty_trash), view);
       gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
       gtk_widget_show (item);
diff --git a/thunar/thunar-tree-view.c b/thunar/thunar-tree-view.c
index cdbaa9d..3836a32 100644
--- a/thunar/thunar-tree-view.c
+++ b/thunar/thunar-tree-view.c
@@ -1102,7 +1102,7 @@ thunar_tree_view_context_menu (ThunarTreeView *view,
     {
       /* append the "Empty Trash" menu action */
       item = gtk_image_menu_item_new_with_mnemonic (_("_Empty Trash"));
-      gtk_widget_set_sensitive (item, (thunar_file_get_size (file) > 0));
+      gtk_widget_set_sensitive (item, (thunar_file_get_item_count (file) > 0));
       g_signal_connect_swapped (G_OBJECT (item), "activate", G_CALLBACK (thunar_tree_view_action_empty_trash), view);
       gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
       gtk_widget_show (item);



More information about the Xfce4-commits mailing list