[Xfce4-commits] <thunar:master> Add free space tooltip for devices.

Nick Schermer noreply at xfce.org
Sat Nov 10 17:04:03 CET 2012


Updating branch refs/heads/master
         to 0017d6b40610a3562ecd2379dddb869be7e28124 (commit)
       from 115da6b521dbc30b844d57d5fad6b647bbaa6888 (commit)

commit 0017d6b40610a3562ecd2379dddb869be7e28124
Author: Nick Schermer <nick at xfce.org>
Date:   Fri Nov 9 22:55:20 2012 +0100

    Add free space tooltip for devices.

 thunar/thunar-file.c              |   50 -------------------
 thunar/thunar-file.h              |    3 -
 thunar/thunar-gio-extensions.c    |   98 +++++++++++++++++++++++++++++++++----
 thunar/thunar-gio-extensions.h    |   24 ++++++---
 thunar/thunar-list-model.c        |    3 +-
 thunar/thunar-properties-dialog.c |   30 +++++-------
 thunar/thunar-shortcuts-model.c   |   31 ++++++++---
 7 files changed, 139 insertions(+), 100 deletions(-)

diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index 7a18e83..4a4f853 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -2322,56 +2322,6 @@ thunar_file_get_mode (const ThunarFile *file)
 
 
 
-/**
- * thunar_file_get_free_space:
- * @file           : a #ThunarFile instance.
- * @fs_free_return : return location for the amount of
- *                   free space or %NULL.
- * @fs_size_return : return location for the total volume size.
- *
- * Determines the amount of free space of the volume on
- * which @file resides. Returns %TRUE if the amount of
- * free space was determined successfully and placed into
- * @free_space_return, else %FALSE will be returned.
- *
- * Return value: %TRUE if successfull, else %FALSE.
- **/
-gboolean
-thunar_file_get_free_space (const ThunarFile *file, 
-                            guint64          *fs_free_return,
-                            guint64          *fs_size_return)
-{
-  GFileInfo *filesystem_info;
-  gboolean   success = FALSE;
-
-  _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE);
-
-  filesystem_info = g_file_query_filesystem_info (file->gfile, 
-                                                  THUNARX_FILESYSTEM_INFO_NAMESPACE,
-                                                  NULL, NULL);
-
-  if (filesystem_info != NULL)
-    {
-      if (fs_free_return != NULL)
-        {
-          *fs_free_return = g_file_info_get_attribute_uint64 (filesystem_info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
-          success = g_file_info_has_attribute (filesystem_info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
-        }
-
-      if (fs_size_return != NULL)
-        {
-          *fs_size_return = g_file_info_get_attribute_uint64 (filesystem_info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE);
-          success = g_file_info_has_attribute (filesystem_info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE);
-        }
-
-      g_object_unref (filesystem_info);
-    }
-
-  return success;
-}
-
-
-
 gboolean
 thunar_file_is_mounted (const ThunarFile *file)
 {
diff --git a/thunar/thunar-file.h b/thunar/thunar-file.h
index 586b18a..7d04b60 100644
--- a/thunar/thunar-file.h
+++ b/thunar/thunar-file.h
@@ -179,9 +179,6 @@ GAppInfo         *thunar_file_get_default_handler  (const ThunarFile       *file
 GFileType         thunar_file_get_kind             (const ThunarFile       *file) G_GNUC_PURE;
 GFile            *thunar_file_get_target_location  (const ThunarFile       *file);
 ThunarFileMode    thunar_file_get_mode             (const ThunarFile       *file);
-gboolean          thunar_file_get_free_space       (const ThunarFile       *file, 
-                                                    guint64                *fs_free_return,
-                                                    guint64                *fs_size_return);
 gboolean          thunar_file_is_mounted           (const ThunarFile       *file);
 gboolean          thunar_file_exists               (const ThunarFile       *file);
 gboolean          thunar_file_is_directory         (const ThunarFile       *file) G_GNUC_PURE;
diff --git a/thunar/thunar-gio-extensions.c b/thunar/thunar-gio-extensions.c
index 8700d58..c7d37fc 100644
--- a/thunar/thunar-gio-extensions.c
+++ b/thunar/thunar-gio-extensions.c
@@ -2,18 +2,18 @@
 /*-
  * Copyright (c) 2009-2010 Jannis Pohlmann <jannis at xfce.org>
  *
- * This program is free software; you can redistribute it and/or 
+ * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of 
+ * published by the Free Software Foundation; either version 2 of
  * the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public 
- * License along with this program; if not, write to the Free 
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  * Boston, MA 02110-1301, USA.
  */
@@ -104,7 +104,7 @@ thunar_g_file_is_root (GFile *file)
 
 
 
-gboolean 
+gboolean
 thunar_g_file_is_trashed (GFile *file)
 {
   _thunar_return_val_if_fail (G_IS_FILE (file), FALSE);
@@ -191,10 +191,10 @@ thunar_g_file_write_key_file (GFile        *file,
   /* try to replace the file contents with the key file data */
   if (contents != NULL)
     {
-      result = g_file_replace_contents (file, contents, length, NULL, FALSE, 
+      result = g_file_replace_contents (file, contents, length, NULL, FALSE,
                                         G_FILE_CREATE_NONE,
                                         NULL, cancellable, error);
-      
+
       /* cleanup */
       g_free (contents);
     }
@@ -210,7 +210,7 @@ thunar_g_file_get_location (GFile *file)
   gchar *location;
 
   _thunar_return_val_if_fail (G_IS_FILE (file), NULL);
-  
+
   location = g_file_get_path (file);
   if (location == NULL)
     location = g_file_get_uri (file);
@@ -348,7 +348,7 @@ thunar_g_vfs_is_uri_scheme_supported (const gchar *scheme)
   if (supported_schemes == NULL)
     return FALSE;
 
-  for (n = 0; !supported && supported_schemes[n] != NULL; ++n) 
+  for (n = 0; !supported && supported_schemes[n] != NULL; ++n)
     if (g_strcmp0 (supported_schemes[n], scheme) == 0)
       supported = TRUE;
 
@@ -357,6 +357,84 @@ thunar_g_vfs_is_uri_scheme_supported (const gchar *scheme)
 
 
 
+/**
+ * thunar_g_file_get_free_space:
+ * @file           : a #GFile instance.
+ * @fs_free_return : return location for the amount of
+ *                   free space or %NULL.
+ * @fs_size_return : return location for the total volume size.
+ *
+ * Determines the amount of free space of the volume on
+ * which @file resides. Returns %TRUE if the amount of
+ * free space was determined successfully and placed into
+ * @free_space_return, else %FALSE will be returned.
+ *
+ * Return value: %TRUE if successfull, else %FALSE.
+ **/
+gboolean
+thunar_g_file_get_free_space (GFile   *file,
+                              guint64 *fs_free_return,
+                              guint64 *fs_size_return)
+{
+  GFileInfo *filesystem_info;
+  gboolean   success = FALSE;
+
+  _thunar_return_val_if_fail (G_IS_FILE (file), FALSE);
+
+  filesystem_info = g_file_query_filesystem_info (file,
+                                                  THUNARX_FILESYSTEM_INFO_NAMESPACE,
+                                                  NULL, NULL);
+
+  if (filesystem_info != NULL)
+    {
+      if (fs_free_return != NULL)
+        {
+          *fs_free_return = g_file_info_get_attribute_uint64 (filesystem_info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
+          success = g_file_info_has_attribute (filesystem_info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
+        }
+
+      if (fs_size_return != NULL)
+        {
+          *fs_size_return = g_file_info_get_attribute_uint64 (filesystem_info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE);
+          success = g_file_info_has_attribute (filesystem_info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE);
+        }
+
+      g_object_unref (filesystem_info);
+    }
+
+  return success;
+}
+
+
+gchar *
+thunar_g_file_get_free_space_string (GFile *file)
+{
+  gchar   *fs_free_str;
+  gchar   *fs_size_str;
+  guint64  fs_free;
+  guint64  fs_size;
+  gchar   *fs_string = NULL;
+
+  _thunar_return_val_if_fail (G_IS_FILE (file), NULL);
+
+  if (thunar_g_file_get_free_space (file, &fs_free, &fs_size)
+      && fs_size > 0)
+    {
+      fs_free_str = g_format_size (fs_free);
+      fs_size_str = g_format_size (fs_size);
+      /* free disk space string */
+      fs_string = g_strdup_printf (_("%s of %s (%d%% used)"),
+                                   fs_free_str, fs_size_str,
+                                   (gint) ((fs_size - fs_free) * 100 / fs_size));
+      g_free (fs_free_str);
+      g_free (fs_size_str);
+    }
+
+  return fs_string;
+}
+
+
+
 GType
 thunar_g_file_list_get_type (void)
 {
diff --git a/thunar/thunar-gio-extensions.h b/thunar/thunar-gio-extensions.h
index 4758710..c19101e 100644
--- a/thunar/thunar-gio-extensions.h
+++ b/thunar/thunar-gio-extensions.h
@@ -2,18 +2,18 @@
 /*-
  * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
  *
- * This program is free software; you can redistribute it and/or 
+ * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of 
+ * published by the Free Software Foundation; either version 2 of
  * the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public 
- * License along with this program; if not, write to the Free 
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  * Boston, MA 02110-1301, USA.
  */
@@ -34,7 +34,7 @@ GFile    *thunar_g_file_new_for_bookmarks        (void);
 gboolean  thunar_g_file_is_root                  (GFile                *file);
 gboolean  thunar_g_file_is_trashed               (GFile                *file);
 gboolean  thunar_g_file_is_home                  (GFile                *file);
-                                                                      
+
 GKeyFile *thunar_g_file_query_key_file           (GFile                *file,
                                                   GCancellable         *cancellable,
                                                   GError              **error);
@@ -42,19 +42,25 @@ gboolean  thunar_g_file_write_key_file           (GFile                *file,
                                                   GKeyFile             *key_file,
                                                   GCancellable         *cancellable,
                                                   GError              **error);
-                                                                      
+
 gchar    *thunar_g_file_get_location             (GFile                *file);
 
 gchar    *thunar_g_file_get_display_name         (GFile                *file);
 
 gchar    *thunar_g_file_get_display_name_remote  (GFile                *file);
-                                                                      
+
 gboolean  thunar_g_vfs_is_uri_scheme_supported   (const gchar          *scheme);
 
+gboolean  thunar_g_file_get_free_space           (GFile                *file,
+                                                  guint64              *fs_free_return,
+                                                  guint64              *fs_size_return);
+
+gchar    *thunar_g_file_get_free_space_string    (GFile                *file);
+
 /**
  * THUNAR_TYPE_G_FILE_LIST:
  *
- * Returns the type ID for #GList<!---->s of #GFile<!---->s which is a 
+ * Returns the type ID for #GList<!---->s of #GFile<!---->s which is a
  * boxed type.
  **/
 #define THUNAR_TYPE_G_FILE_LIST (thunar_g_file_list_get_type ())
diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c
index 92f7867..3be891c 100644
--- a/thunar/thunar-list-model.c
+++ b/thunar/thunar-list-model.c
@@ -2260,7 +2260,8 @@ thunar_list_model_get_statusbar_text (ThunarListModel *store,
       file = (store->folder != NULL) ? thunar_folder_get_corresponding_file (store->folder) : NULL;
 
       /* check if we can determine the amount of free space for the volume */
-      if (G_LIKELY (file != NULL && thunar_file_get_free_space (file, &size, NULL)))
+      if (G_LIKELY (file != NULL
+          && thunar_g_file_get_free_space (thunar_file_get_file (file), &size, NULL)))
         {
           /* humanize the free space */
           fspace_string = g_format_size (size);
diff --git a/thunar/thunar-properties-dialog.c b/thunar/thunar-properties-dialog.c
index 34cf2e6..7b20030 100644
--- a/thunar/thunar-properties-dialog.c
+++ b/thunar/thunar-properties-dialog.c
@@ -855,14 +855,10 @@ thunar_properties_dialog_update_single (ThunarPropertiesDialog *dialog)
   const gchar       *name;
   const gchar       *path;
   GVolume           *volume;
-  guint64            fs_free;
-  guint64            fs_size;
   GIcon             *gicon;
   glong              offset;
   gchar             *date;
   gchar             *display_name;
-  gchar             *fs_free_str;
-  gchar             *fs_size_str;
   gchar             *fs_string;
   gchar             *str;
   gchar             *volume_name;
@@ -1045,21 +1041,19 @@ thunar_properties_dialog_update_single (ThunarPropertiesDialog *dialog)
     }
 
   /* update the free space (only for folders) */
-  if (thunar_file_is_directory (file)
-      && thunar_file_get_free_space (file, &fs_free, &fs_size)
-      && fs_size > 0)
+  if (thunar_file_is_directory (file))
     {
-      fs_free_str = g_format_size (fs_free);
-      fs_size_str = g_format_size (fs_size);
-      fs_string = g_strdup_printf (_("%s of %s (%d%% used)"),
-                                   fs_free_str, fs_size_str,
-                                   (gint) ((fs_size - fs_free) * 100 / fs_size));
-      g_free (fs_free_str);
-      g_free (fs_size_str);
-
-      gtk_label_set_text (GTK_LABEL (dialog->freespace_label), fs_string);
-      gtk_widget_show (dialog->freespace_label);
-      g_free (fs_string);
+      fs_string = thunar_g_file_get_free_space_string (thunar_file_get_file (file));
+      if (fs_string != NULL)
+        {
+          gtk_label_set_text (GTK_LABEL (dialog->freespace_label), fs_string);
+          gtk_widget_show (dialog->freespace_label);
+          g_free (fs_string);
+        }
+      else
+        {
+          gtk_widget_hide (dialog->freespace_label);
+        }
     }
   else
     {
diff --git a/thunar/thunar-shortcuts-model.c b/thunar/thunar-shortcuts-model.c
index 8da1b45..49ed7a7 100644
--- a/thunar/thunar-shortcuts-model.c
+++ b/thunar/thunar-shortcuts-model.c
@@ -527,6 +527,7 @@ thunar_shortcuts_model_get_value (GtkTreeModel *tree_model,
   ThunarShortcut *shortcut;
   gboolean        can_eject;
   GFile          *file;
+  gchar          *disk_usage;
 
   _thunar_return_if_fail (iter->stamp == THUNAR_SHORTCUTS_MODEL (tree_model)->stamp);
   _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_MODEL (tree_model));
@@ -571,25 +572,37 @@ thunar_shortcuts_model_get_value (GtkTreeModel *tree_model,
       break;
 
     case THUNAR_SHORTCUTS_MODEL_COLUMN_TOOLTIP:
-      if (shortcut->tooltip == NULL)
+      g_value_init (value, G_TYPE_STRING);
+      if ((shortcut->group & THUNAR_SHORTCUT_GROUP_DEVICES) != 0)
         {
-          if (shortcut->file != NULL)
-            file = g_object_ref (thunar_file_get_file (shortcut->file));
-          else if (shortcut->location != NULL)
-            file = g_object_ref (shortcut->location);
-          else if (shortcut->device != NULL)
+          if (shortcut->device != NULL)
             file = thunar_device_get_root (shortcut->device);
+          else if (shortcut->file != NULL)
+            file = g_object_ref (thunar_file_get_file (shortcut->file));
           else
             file = NULL;
 
-          if (G_LIKELY (file != NULL))
+          if (file != NULL)
             {
-              shortcut->tooltip = g_file_get_parse_name (file);;
+              disk_usage = thunar_g_file_get_free_space_string (file);
               g_object_unref (file);
+              g_value_take_string (value, disk_usage);
             }
+          break;
+        }
+      else if (shortcut->tooltip == NULL)
+        {
+          if (shortcut->file != NULL)
+            file = thunar_file_get_file (shortcut->file);
+          else if (shortcut->location != NULL)
+            file = shortcut->location;
+          else
+            file = NULL;
+
+          if (G_LIKELY (file != NULL))
+            shortcut->tooltip = g_file_get_parse_name (file);
         }
 
-      g_value_init (value, G_TYPE_STRING);
       g_value_set_static_string (value, shortcut->tooltip);
       break;
 


More information about the Xfce4-commits mailing list