[baobab/wip/vala: 25/39] Pass the directory in the scanner constructor.



commit 3102c0d14097049781a15805b8513b441e2fb3ff
Author: Paolo Borelli <pborelli gnome org>
Date:   Sun Jan 8 19:59:38 2012 +0100

    Pass the directory in the scanner constructor.
    
    We decided that scanner is a single use object that is reinstanciated
    every time a new dir is scanned, so passing the directory in the
    constructor makes it more clear.

 src/baobab-scanner.vala          |   23 ++++++++++++-----------
 src/baobab-sync-scanner.vala     |    7 +++++--
 src/baobab-threaded-scanner.vala |   17 +++++++----------
 src/baobab-window.vala           |    5 ++---
 4 files changed, 26 insertions(+), 26 deletions(-)
---
diff --git a/src/baobab-scanner.vala b/src/baobab-scanner.vala
index 41d3cb6..0de1ac6 100644
--- a/src/baobab-scanner.vala
+++ b/src/baobab-scanner.vala
@@ -43,26 +43,27 @@ namespace Baobab {
 			FileAttribute.UNIX_DEVICE + "," +
 			FileAttribute.ACCESS_CAN_READ;
 
-		public File directory { get; protected set; }
-
-		public abstract void scan (File directory);
+		public File directory { get; private set; }
 
 		public int max_depth { get; protected set; }
 
+		public abstract void scan ();
+
 		public virtual void stop () {
 			cancellable.cancel ();
 		}
 
-		public Scanner () {
+		public Scanner (File directory) {
+			this.directory = directory;
 			cancellable = new Cancellable();
 			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 (string),  // DIR_NAME
+			                  typeof (string),  // PARSE_NAME
+			                  typeof (double),  // PERCENT
+			                  typeof (uint64),  // SIZE
+			                  typeof (uint64),  // ALLOC_SIZE
+			                  typeof (int),     // ELEMENTS
+			                  typeof (State)}); // STATE
 			set_sort_column_id (Columns.SIZE, Gtk.SortType.DESCENDING);
 			excluded_locations = Application.get_excluded_locations ();
 		}
diff --git a/src/baobab-sync-scanner.vala b/src/baobab-sync-scanner.vala
index 2083a8e..f5b4e8c 100644
--- a/src/baobab-sync-scanner.vala
+++ b/src/baobab-sync-scanner.vala
@@ -109,8 +109,7 @@ namespace Baobab {
 			}
 		}
 
-		protected override void scan (File directory) {
-			this.directory = directory;
+		public override void scan () {
 			try {
 				var info = directory.query_info (ATTRIBUTES, 0, cancellable);
 				var results = add_directory (directory, info);
@@ -118,5 +117,9 @@ namespace Baobab {
 				max_depth = results.max_depth;
 			} catch { }
 		}
+
+		public SyncScanner (File directory) {
+			base (directory);
+		}
 	}
 }
diff --git a/src/baobab-threaded-scanner.vala b/src/baobab-threaded-scanner.vala
index ac7174d..56fdeb2 100644
--- a/src/baobab-threaded-scanner.vala
+++ b/src/baobab-threaded-scanner.vala
@@ -208,26 +208,23 @@ namespace Baobab {
 						max_depth = results.max_depth;
 					}
 				}
-
 			}
 
 			return this.self != null;
 		}
 
-		protected override void scan (File directory) {
-			this.directory = directory;
-			this.excluded_locations = Application.get_excluded_locations ();
-
-			// the thread owns a reference on the Scanner object
-			this.self = this;
-
+		public override void scan () {
 			new GLib2.Thread ("scanner", scan_in_thread);
-
 			Timeout.add (100, process_results);
 		}
 
-		public ThreadedScanner () {
+		public ThreadedScanner (File directory) {
+			base (directory);
+
 			results_queue = new AsyncQueue<ResultsArray> ();
+
+			// the thread owns a reference on the Scanner object
+			this.self = this;
 		}
 	}
 }
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index d02899b..0db1852 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -233,11 +233,10 @@ namespace Baobab {
 
 			set_busy (true);
 
-			scanner = new ThreadedScanner ();
-			scanner.scan (directory);
-
+			scanner = new ThreadedScanner (directory);
 			set_model (scanner);
 
+			scanner.scan ();
 			set_busy (false);
 		}
 	}



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