[baobab] Remove the get_filesyste_usage method from the scanner



commit f8501c44c89cae1fe40228de2ca24ec9efe4822d
Author: Paolo Borelli <pborelli gnome org>
Date:   Fri Apr 6 19:02:36 2012 +0200

    Remove the get_filesyste_usage method from the scanner
    
    In the new design we do not need the fs state stored as a tree model
    anymore. Move the logic to calculate the reserved space to the location
    class even if it is not used yet.

 src/baobab-location.vala |   32 ++++++++++++++--------------
 src/baobab-scanner.vala  |   51 ----------------------------------------------
 2 files changed, 16 insertions(+), 67 deletions(-)
---
diff --git a/src/baobab-location.vala b/src/baobab-location.vala
index 1cf399a..e1e9cd5 100644
--- a/src/baobab-location.vala
+++ b/src/baobab-location.vala
@@ -26,12 +26,13 @@ namespace Baobab {
 
         public uint64? size { get; private set; }
         public uint64? used { get; private set; }
+        public uint64? reserved { get; private set; }
         public Icon? icon { get; private set; }
 
         public Volume? volume { get; private set; }
         public Mount? mount { get; private set; }
 
-        protected static const string FS_ATTRIBUTES =
+        private static const string FS_ATTRIBUTES =
             FileAttribute.FILESYSTEM_SIZE + "," +
             FileAttribute.FILESYSTEM_USED;
 
@@ -65,12 +66,7 @@ namespace Baobab {
             mount_point = "/";
             icon = new ThemedIcon ("drive-harddisk-system");
 
-            uint64? size_ = null;
-            uint64? used_ = null;
-            get_fs_size (File.new_for_path ("/"), out size_, out used_);
-
-            size = size_;
-            used = used_;
+            get_fs_usage (File.new_for_path ("/"));
         }
 
         public Location.for_home_folder () {
@@ -110,21 +106,25 @@ namespace Baobab {
                 make_this_home_location ();
             }
 
-            uint64? size_ = null;
-            uint64? used_ = null;
-            get_fs_size (file, out size_, out used_);
-
-            size = size_;
-            used = used_;
+            get_fs_usage (file);
         }
 
-        static void get_fs_size (File file, out uint64? size, out uint64? used) {
+        private void get_fs_usage (File file) {
+            size = null;
+            used = null;
+            reserved = null;
             try {
                 var info = file.query_filesystem_info (FS_ATTRIBUTES, null);
-                if (info.has_attribute (FileAttribute.FILESYSTEM_SIZE))
+                if (info.has_attribute (FileAttribute.FILESYSTEM_SIZE)) {
                     size = info.get_attribute_uint64 (FileAttribute.FILESYSTEM_SIZE);
-                if (info.has_attribute (FileAttribute.FILESYSTEM_USED))
+                }
+                if (info.has_attribute (FileAttribute.FILESYSTEM_USED)) {
                     used = info.get_attribute_uint64 (FileAttribute.FILESYSTEM_USED);
+                }
+                if (size != null && used != null && info.has_attribute (FileAttribute.FILESYSTEM_FREE)) {
+                    var free = info.get_attribute_uint64 (FileAttribute.FILESYSTEM_FREE);
+                    reserved = size - free - used;
+                }
             } catch (Error e) {
             }
         }
diff --git a/src/baobab-scanner.vala b/src/baobab-scanner.vala
index 429b1e4..db3c146 100644
--- a/src/baobab-scanner.vala
+++ b/src/baobab-scanner.vala
@@ -95,57 +95,6 @@ namespace Baobab {
             }
         }
 
-        protected static const string FS_ATTRIBUTES =
-            FileAttribute.FILESYSTEM_SIZE + "," +
-            FileAttribute.FILESYSTEM_USED + "," +
-            FileAttribute.FILESYSTEM_FREE;
-
-        public void get_filesystem_usage () throws Error {
-            var info = directory.query_filesystem_info (FS_ATTRIBUTES, cancellable);
-
-            var size = info.get_attribute_uint64 (FileAttribute.FILESYSTEM_SIZE);
-            var used = info.get_attribute_uint64 (FileAttribute.FILESYSTEM_USED);
-            var free = info.get_attribute_uint64 (FileAttribute.FILESYSTEM_FREE);
-            var reserved = size - free - used;
-
-            var used_perc = 100 * ((double) used) / ((double) size);
-            var reserved_perc = 100 * ((double) reserved) / ((double) size);
-
-            Gtk.TreeIter? root_iter, iter;
-            append (out root_iter, null);
-            set (root_iter,
-                 Columns.STATE, State.DONE,
-                 Columns.DISPLAY_NAME, _("Total filesystem capacity"),
-                 Columns.PARSE_NAME, "",
-                 Columns.SIZE, size,
-                 Columns.ALLOC_SIZE, size,
-                 Columns.PERCENT, 100.0,
-                 Columns.ELEMENTS, -1,
-                 Columns.ERROR, null);
-
-            append (out iter, root_iter);
-            set (iter,
-                 Columns.STATE, State.DONE,
-                 Columns.DISPLAY_NAME, _("Used"),
-                 Columns.PARSE_NAME, "",
-                 Columns.SIZE, used,
-                 Columns.ALLOC_SIZE, used,
-                 Columns.PERCENT, used_perc,
-                 Columns.ELEMENTS, -1,
-                 Columns.ERROR, null);
-
-            append (out iter, root_iter);
-            set (iter,
-                 Columns.STATE, State.DONE,
-                 Columns.DISPLAY_NAME, _("Reserved"),
-                 Columns.PARSE_NAME, "",
-                 Columns.SIZE, reserved,
-                 Columns.ALLOC_SIZE, reserved,
-                 Columns.PERCENT, reserved_perc,
-                 Columns.ELEMENTS, -1,
-                 Columns.ERROR, null);
-        }
-
         public Scanner (File directory, ScanFlags flags) {
             this.directory = directory;
             this.scan_flags = flags;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]