[simple-scan/gnome-3-4: 10/25] Fix crash when starting a new document during a scan



commit 1cd85a4ff4c668cb96616ac1fe0c0893845d1d70
Author: Robert Ancell <robert ancell canonical com>
Date:   Fri Mar 22 09:37:21 2013 +1300

    Fix crash when starting a new document during a scan

 src/scanner.vala |   40 ++++++++++++++++++++++++++++++----------
 src/ui.vala      |    2 ++
 2 files changed, 32 insertions(+), 10 deletions(-)
---
diff --git a/src/scanner.vala b/src/scanner.vala
index 7af1269..722f308 100644
--- a/src/scanner.vala
+++ b/src/scanner.vala
@@ -84,6 +84,7 @@ public class ScanOptions
 
 private class ScanJob
 {
+    public int id;
     public string device;
     public double dpi;
     public ScanMode scan_mode;
@@ -167,23 +168,36 @@ private class NotifyExpectPage : Notify
 
 private class NotifyGotPageInfo : Notify
 {
-    public NotifyGotPageInfo (ScanPageInfo info) { this.info = info; }
+    public NotifyGotPageInfo (int job_id, ScanPageInfo info) { this.job_id = job_id; this.info = info; }
+    private int job_id;
     private ScanPageInfo info;
-    public override void run (Scanner scanner) { scanner.got_page_info (info); }
+    public override void run (Scanner scanner)
+    {
+        if (job_id >= scanner.first_job_id && job_id < scanner.job_id)
+            scanner.got_page_info (info);
+    }
 }
 
 private class NotifyPageDone : Notify
 {
-    public override void run (Scanner scanner) { scanner.page_done (); }
+    public NotifyPageDone (int job_id) { this.job_id = job_id; }
+    private int job_id;
+    public override void run (Scanner scanner)
+    {
+        if (job_id >= scanner.first_job_id && job_id < scanner.job_id)
+            scanner.page_done ();
+    }
 }
 
 private class NotifyGotLine : Notify
 {
-    public NotifyGotLine (ScanLine line) { this.line = line; }
+    public NotifyGotLine (int job_id, ScanLine line) { this.job_id = job_id; this.line = line; }
+    private int job_id;
     private ScanLine line;
     public override void run (Scanner scanner)
     {
-        scanner.got_line (line);
+        if (job_id >= scanner.first_job_id && job_id < scanner.job_id)
+            scanner.got_line (line);
     }
 }
 
@@ -204,6 +218,10 @@ public class Scanner
     /* Queue of responses to authorization requests */
     private AsyncQueue<Credentials> authorize_queue;
 
+    /* ID for the current job */
+    public int first_job_id;
+    public int job_id;
+
     private string? default_device;
 
     private ScanState state;
@@ -1174,7 +1192,7 @@ public class Scanner
 
         if (page_number != notified_page)
         {
-            notify (new NotifyGotPageInfo (info));
+            notify (new NotifyGotPageInfo (job.id, info));
             notified_page = page_number;
         }
 
@@ -1189,10 +1207,10 @@ public class Scanner
 
     private void do_complete_page ()
     {
-        notify (new NotifyPageDone ());
-
         var job = (ScanJob) job_queue.data;
 
+        notify (new NotifyPageDone (job.id));
+
         /* If multi-pass then scan another page */
         if (!parameters.last_frame)
         {
@@ -1206,7 +1224,7 @@ public class Scanner
         {
             page_number++;
             pass_number = 0;
-            notify (new NotifyPageDone ());
+            notify (new NotifyPageDone (job.id));
             state = ScanState.START;
             return;
         }
@@ -1347,7 +1365,7 @@ public class Scanner
                 line.data_length = (line.width * 2 + 7) / 8;
             }
 
-            notify (new NotifyGotLine (line));
+            notify (new NotifyGotLine (job.id, line));
         }
     }
 
@@ -1475,6 +1493,7 @@ public class Scanner
                get_scan_type_string (options.type), options.paper_width, options.paper_height);
         var request = new RequestStartScan ();
         request.job = new ScanJob ();
+        request.job.id = job_id++;
         request.job.device = device;
         request.job.dpi = options.dpi;
         request.job.scan_mode = options.scan_mode;
@@ -1487,6 +1506,7 @@ public class Scanner
 
     public void cancel ()
     {
+        first_job_id = job_id;
         request_queue.push (new RequestCancel ());
     }
 
diff --git a/src/ui.vala b/src/ui.vala
index 5443aa9..79c46b6 100644
--- a/src/ui.vala
+++ b/src/ui.vala
@@ -534,6 +534,8 @@ public class SimpleScan
                              _("Discard Changes")))
             return;
 
+        if (scanning)
+            stop_scan ();
         clear_document ();
     }
 


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