[baobab/wip/vala: 27/53] Add a "completed" signal to the scanner



commit 66c0d7d19e11eac11db234666ae4fe5170a19c4f
Author: Paolo Borelli <pborelli gnome org>
Date:   Sun Jan 8 22:48:52 2012 +0100

    Add a "completed" signal to the scanner
    
    Use the new signal to update the window state when the scan is
    completed.

 src/baobab-scanner.vala          |    4 +++-
 src/baobab-threaded-scanner.vala |    4 ++++
 src/baobab-window.vala           |   10 ++++++----
 3 files changed, 13 insertions(+), 5 deletions(-)
---
diff --git a/src/baobab-scanner.vala b/src/baobab-scanner.vala
index 0de1ac6..5871cef 100644
--- a/src/baobab-scanner.vala
+++ b/src/baobab-scanner.vala
@@ -47,9 +47,11 @@ namespace Baobab {
 
 		public int max_depth { get; protected set; }
 
+		public signal void completed();
+
 		public abstract void scan ();
 
-		public virtual void stop () {
+		public virtual void cancel () {
 			cancellable.cancel ();
 		}
 
diff --git a/src/baobab-threaded-scanner.vala b/src/baobab-threaded-scanner.vala
index 56fdeb2..a17bf24 100644
--- a/src/baobab-threaded-scanner.vala
+++ b/src/baobab-threaded-scanner.vala
@@ -207,6 +207,10 @@ namespace Baobab {
 					if (results.max_depth > max_depth) {
 						max_depth = results.max_depth;
 					}
+
+					if (results.parent == null) {
+						completed ();
+					}
 				}
 			}
 
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index 0db1852..55ac367 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -103,7 +103,7 @@ namespace Baobab {
 
 		void on_stop_activate () {
 			if (scanner != null) {
-				scanner.stop ();
+				scanner.cancel ();
 			}
 		}
 
@@ -224,6 +224,11 @@ namespace Baobab {
 			                                    Scanner.Columns.PARSE_NAME,
 			                                    Scanner.Columns.PERCENT,
 			                                    Scanner.Columns.ELEMENTS, null);
+
+			set_busy (true);
+			scanner.completed.connect(() => {
+				set_busy (false);
+			});
 		}
 
 		public void scan_directory (File directory) {
@@ -231,13 +236,10 @@ namespace Baobab {
 				return;
 			}
 
-			set_busy (true);
-
 			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]