[baobab/wip/new-design: 53/59] baobab-scanner: replace boolean argument with a bit flag



commit 922054ffad04a61a1091e9161448f1d72123e2cb
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Thu Mar 15 15:41:31 2012 +0100

    baobab-scanner: replace boolean argument with a bit flag

 src/baobab-scanner.vala          |   32 +++++++++++++++++++-------------
 src/baobab-sync-scanner.vala     |    4 ++--
 src/baobab-threaded-scanner.vala |    4 ++--
 src/baobab-window.vala           |   10 +++++-----
 4 files changed, 28 insertions(+), 22 deletions(-)
---
diff --git a/src/baobab-scanner.vala b/src/baobab-scanner.vala
index 0fe42e7..3a20e74 100644
--- a/src/baobab-scanner.vala
+++ b/src/baobab-scanner.vala
@@ -1,4 +1,10 @@
 namespace Baobab {
+	[Flags]
+	public enum ScanFlags {
+		NONE,
+		EXCLUDE_MOUNTS
+	}
+
 	abstract class Scanner : Gtk.TreeStore {
 		public enum Columns {
 			DISPLAY_NAME,
@@ -40,7 +46,7 @@ namespace Baobab {
 			FileAttribute.STANDARD_DISPLAY_NAME + "," +
 			FileAttribute.STANDARD_TYPE + "," +
 			FileAttribute.STANDARD_SIZE +  "," +
-			FileAttribute.STANDARD_ALLOCATED_SIZE +  "," +
+			FileAttribute.STANDARD_ALLOCATED_SIZE +	 "," +
 			FileAttribute.UNIX_NLINK + "," +
 			FileAttribute.UNIX_INODE + "," +
 			FileAttribute.UNIX_DEVICE + "," +
@@ -48,7 +54,7 @@ namespace Baobab {
 
 		public File directory { get; private set; }
 
-		public bool exclude_mounts { get; private set; }
+		public ScanFlags scan_flags { get; private set; }
 
 		public int max_depth { get; protected set; }
 
@@ -117,25 +123,25 @@ namespace Baobab {
 			     Columns.ERROR, null);
 		}
 
-		public Scanner (File directory, bool exclude_mounts) {
+		public Scanner (File directory, ScanFlags flags) {
 			this.directory = directory;
-			this.exclude_mounts = exclude_mounts;
+			this.scan_flags = flags;
 			cancellable = new Cancellable();
 			scan_error = null;
 			set_column_types (new Type[] {
-			                  typeof (string),  // DIR_NAME
-			                  typeof (string),  // PARSE_NAME
-			                  typeof (double),  // PERCENT
-			                  typeof (uint64),  // SIZE
-			                  typeof (uint64),  // ALLOC_SIZE
-			                  typeof (int),     // ELEMENTS
-			                  typeof (State),   // STATE
-			                  typeof (Error)}); // ERROR (if STATE is ERROR)
+					  typeof (string),  // DIR_NAME
+					  typeof (string),  // PARSE_NAME
+					  typeof (double),  // PERCENT
+					  typeof (uint64),  // SIZE
+					  typeof (uint64),  // ALLOC_SIZE
+					  typeof (int),	    // ELEMENTS
+					  typeof (State),   // STATE
+					  typeof (Error)}); // ERROR (if STATE is ERROR)
 			set_sort_column_id (Columns.SIZE, Gtk.SortType.DESCENDING);
 
 			excluded_locations = Application.get_excluded_locations ();
 
-			if (exclude_mounts) {
+			if (ScanFlags.EXCLUDE_MOUNTS in flags) {
 				foreach (unowned UnixMountEntry mount in UnixMountEntry.get (null))
 					excluded_locations.add (File.new_for_path (mount.get_mount_path ()));
 			}
diff --git a/src/baobab-sync-scanner.vala b/src/baobab-sync-scanner.vala
index 3344ab8..d04385e 100644
--- a/src/baobab-sync-scanner.vala
+++ b/src/baobab-sync-scanner.vala
@@ -118,8 +118,8 @@ namespace Baobab {
 			} catch { }
 		}
 
-		public SyncScanner (File directory, bool exclude_mounts) {
-			base (directory, exclude_mounts);
+		public SyncScanner (File directory, ScanFlags flags) {
+			base (directory, flags);
 		}
 	}
 }
diff --git a/src/baobab-threaded-scanner.vala b/src/baobab-threaded-scanner.vala
index 6fb920e..55a9c57 100644
--- a/src/baobab-threaded-scanner.vala
+++ b/src/baobab-threaded-scanner.vala
@@ -235,8 +235,8 @@ namespace Baobab {
 			Timeout.add (100, process_results);
 		}
 
-		public ThreadedScanner (File directory, bool exclude_mounts) {
-			base (directory, exclude_mounts);
+		public ThreadedScanner (File directory, ScanFlags flags) {
+			base (directory, flags);
 
 			results_queue = new AsyncQueue<ResultsArray> ();
 
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index 8716ebc..2c576dd 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -171,7 +171,7 @@ namespace Baobab {
 							fs.call_mount_sync (new GLib.Variant ("a{sv}", null), out mount_point, null);
 						}
 
-						scan_directory (File.new_for_path (mount_point), true);
+						scan_directory (File.new_for_path (mount_point), ScanFlags.EXCLUDE_MOUNTS);
 					} catch (Error e) {
 						message (_("Could not analyze volume."), e.message, Gtk.MessageType.ERROR);
 					}
@@ -223,7 +223,7 @@ namespace Baobab {
 
 		void on_reload_activate () {
 			if (scanner != null) {
-				scan_directory (scanner.directory, scanner.exclude_mounts);
+				scan_directory (scanner.directory, scanner.scan_flags);
 			}
 		}
 
@@ -486,7 +486,7 @@ namespace Baobab {
 		public void show_filesystem_usage () {
 			var dir = File.new_for_uri ("file:///");
 
-			scanner = new ThreadedScanner (dir, false);
+			scanner = new ThreadedScanner (dir, ScanFlags.NONE);
 			set_model (scanner);
 
 			try {
@@ -498,12 +498,12 @@ namespace Baobab {
 			treeview.set_headers_visible (false);
 		}
 
-		public void scan_directory (File directory, bool exclude_mounts = false) {
+		public void scan_directory (File directory, ScanFlags flags = ScanFlags.NONE) {
 			if (!check_dir (directory)) {
 				return;
 			}
 
-			scanner = new ThreadedScanner (directory, exclude_mounts);
+			scanner = new ThreadedScanner (directory, flags);
 			set_model (scanner);
 
 			scanner.completed.connect(() => {



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