[baobab] Store GFile in the Location class



commit 4b1e7392dbf7b3e3478457ac0f5131e7fbc60e90
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Jul 28 14:35:58 2012 +0200

    Store GFile in the Location class
    
    Use GFile instead of a plain "mount_point" string

 src/baobab-location-list.vala   |    6 ++----
 src/baobab-location-widget.vala |    4 ++--
 src/baobab-location.vala        |   26 ++++++++++++--------------
 src/baobab-window.vala          |    4 ++--
 4 files changed, 18 insertions(+), 22 deletions(-)
---
diff --git a/src/baobab-location-list.vala b/src/baobab-location-list.vala
index 79e1f5e..5e760c2 100644
--- a/src/baobab-location-list.vala
+++ b/src/baobab-location-list.vala
@@ -128,12 +128,10 @@ namespace Baobab {
                     break;
                 }
                 if (info.has_group ("baobab") && info.exists ()) {
-                    // FIXME: I do not like this hack to avoid duplucates
-                    // and beside locations should have a proper uri field
-                    // to be uniquely identified
+                    // FIXME: I do not like this hack to avoid duplucates...
                     bool dup = false;
                     foreach (var l in locations) {
-                        if (l.mount_point == info.get_uri_display ()) {
+                        if (l.file != null && l.file.equal (File.new_for_uri (info.get_uri ()))) {
                             dup = true;
                         }
                     }
diff --git a/src/baobab-location-widget.vala b/src/baobab-location-widget.vala
index f181337..09535a4 100644
--- a/src/baobab-location-widget.vala
+++ b/src/baobab-location-widget.vala
@@ -63,7 +63,7 @@ namespace Baobab {
             label.xalign = 0;
             attach (label, 1, 0, 1, 1);
 
-            label = new Gtk.Label ("<small>%s</small>".printf (location.mount_point != null ? location.mount_point : ""));
+            label = new Gtk.Label ("<small>%s</small>".printf (location.file != null ? location.file.get_parse_name () : ""));
             name_size_group.add_widget (label);
             label.use_markup = true;
             label.hexpand = true;
@@ -93,7 +93,7 @@ namespace Baobab {
                 attach (usagebar, 2, 1, 1, 1);
             }
 
-            var button = new Gtk.Button.with_label (location.mount_point != null ? _("Scan") : _("Mount and Scan"));
+            var button = new Gtk.Button.with_label (location.file != null ? _("Scan") : _("Mount and Scan"));
             button_size_group.add_widget (button);
             button.valign = Gtk.Align.CENTER;
             attach (button, 3, 0, 1, 2);
diff --git a/src/baobab-location.vala b/src/baobab-location.vala
index db126c6..9352717 100644
--- a/src/baobab-location.vala
+++ b/src/baobab-location.vala
@@ -23,7 +23,7 @@ namespace Baobab {
 
     public class Location {
         public string name { get; private set; }
-        public string? mount_point { get; private set; }
+        public File? file { get; private set; }
         public bool is_volume { get; private set; default = true; }
 
         public uint64? size { get; private set; }
@@ -42,10 +42,10 @@ namespace Baobab {
 
         Location.for_home_folder () {
             is_volume = false;
-            mount_point = Environment.get_home_dir ();
+            file = File.new_for_path (GLib.Environment.get_home_dir ());
             make_this_home_location ();
 
-            get_fs_usage (File.new_for_path (mount_point));
+            get_fs_usage ();
         }
 
         public static Location get_home_location () {
@@ -71,20 +71,20 @@ namespace Baobab {
 
         public Location.for_main_volume () {
             name = _("Main volume");
-            mount_point = "/";
+            file = File.new_for_path ("/");
             icon = new ThemedIcon ("drive-harddisk-system");
 
-            get_fs_usage (File.new_for_path (mount_point));
+            get_fs_usage ();
         }
 
         public Location.for_recent_info (Gtk.RecentInfo info) {
             is_volume = false; // we assume recent locations are just folders
             name = info.get_display_name ();
-            mount_point = info.get_uri_display ();
+            file = File.new_for_uri (info.get_uri ());
             icon = info.get_gicon ();
 
             if (info.is_local ()) {
-                get_fs_usage (File.new_for_uri (info.get_uri ()));
+                get_fs_usage ();
             }
         }
 
@@ -107,7 +107,7 @@ namespace Baobab {
             } else {
                 name = volume.get_name ();
                 icon = volume.get_icon ();
-                mount_point = null;
+                file = null;
                 size = null;
                 used = null;
             }
@@ -116,18 +116,16 @@ namespace Baobab {
         void fill_from_mount () {
             name = mount.get_name ();
             icon = mount.get_icon ();
+            file = mount.get_root ();
 
-            var file = mount.get_root ();
-            mount_point = file.get_path ();
-
-            if (mount_point == Environment.get_home_dir ()) {
+            if (file != null && file.equal (File.new_for_path (Environment.get_home_dir ()))) {
                 make_this_home_location ();
             }
 
-            get_fs_usage (file);
+            get_fs_usage ();
         }
 
-        private void get_fs_usage (File file) {
+        private void get_fs_usage () {
             size = null;
             used = null;
             reserved = null;
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index d01af47..b5ff4c8 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -230,13 +230,13 @@ namespace Baobab {
                 location.mount_volume.begin ((location_, res) => {
                     try {
                         location.mount_volume.end (res);
-                        scan_directory (File.new_for_path (location.mount_point), ScanFlags.EXCLUDE_MOUNTS);
+                        scan_directory (location.file, ScanFlags.EXCLUDE_MOUNTS);
                     } catch (Error e) {
                         message (_("Could not analyze volume."), e.message, Gtk.MessageType.ERROR);
                     }
                 });
             } else {
-                scan_directory (File.new_for_path (location.mount_point));
+                scan_directory (location.file);
             }
         }
 



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