[baobab/wip/vala: 26/53] Pass the directory in the scanner constructor.



commit cd79a8f4bc52ff0477e2dab6320278a65dc500ec
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 702345e..1ffefcd 100644
--- a/src/baobab-scanner.vala
+++ b/src/baobab-scanner.vala
@@ -63,26 +63,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 47b540b..66d8ae7 100644
--- a/src/baobab-sync-scanner.vala
+++ b/src/baobab-sync-scanner.vala
@@ -129,8 +129,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);
@@ -138,5 +137,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 7267d92..80c39d2 100644
--- a/src/baobab-threaded-scanner.vala
+++ b/src/baobab-threaded-scanner.vala
@@ -228,26 +228,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 95581fa..1b7ea4f 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -253,11 +253,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]