[banshee] PrimarySource: Allow cancelling track delete job (bgo#691971)



commit efd3c38d356fdb4dc0abe3658f618b2a25dcbe20
Author: Nicholas Little <arealityfarbetween googlemail com>
Date:   Sat Feb 16 23:16:10 2013 +0000

    PrimarySource: Allow cancelling track delete job (bgo#691971)
    
    In the same way the job to add tracks can be cancelled, the
    delete one should be as well (this might especially be useful
    for device management/sync; although deletion of tracks is
    much faster than addition so the user will still have a very
    small window to react...).
    
    Signed-off-by: Andres G. Aragoneses <knocte gmail com>

 .../Banshee.Sources/PrimarySource.cs               |   21 ++++++++++---------
 1 files changed, 11 insertions(+), 10 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs 
b/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
index d79d5a6..3653c6d 100644
--- a/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
+++ b/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
@@ -511,7 +511,7 @@ namespace Banshee.Sources
         {
             is_deleting = true;
             DeleteTrackJob.Total += list.Count;
-            List<DatabaseTrackInfo> skip_deletion = null;
+            var skip_deletion = new List<DatabaseTrackInfo> ();
 
             // Remove from file system
             foreach (DatabaseTrackInfo track in list) {
@@ -520,12 +520,14 @@ namespace Banshee.Sources
                     continue;
                 }
 
+                if (DeleteTrackJob.IsCancelRequested) {
+                    skip_deletion.Add (track);
+                    continue;
+                }
+
                 try {
                     DeleteTrackJob.Status = String.Format ("{0} - {1}", track.ArtistName, track.TrackTitle);
                     if (!DeleteTrack (track)) {
-                        if (skip_deletion == null) {
-                            skip_deletion = new List<DatabaseTrackInfo> ();
-                        }
                         skip_deletion.Add (track);
                     }
                 } catch (Exception e) {
@@ -539,17 +541,15 @@ namespace Banshee.Sources
                 }
             }
 
-            is_deleting = false;
-
-            if (DeleteTrackJob.Total == DeleteTrackJob.Completed) {
+            if (!DeleteTrackJob.IsFinished || DeleteTrackJob.IsCancelRequested) {
                 delete_track_job.Finish ();
-                delete_track_job = null;
             }
+            delete_track_job = null;
+            is_deleting = false;
 
-            if (skip_deletion != null) {
+            if (skip_deletion.Count > 0) {
                 list.Remove (skip_deletion);
                 skip_deletion.Clear ();
-                skip_deletion = null;
             }
 
             // Remove from database
@@ -727,6 +727,7 @@ namespace Banshee.Sources
                         delete_track_job.SetResources (Resource.Cpu, Resource.Database);
                         delete_track_job.PriorityHints = PriorityHints.SpeedSensitive | 
PriorityHints.DataLossIfStopped;
                         delete_track_job.DelayShow = DelayDeleteJob;
+                        delete_track_job.CanCancel = true;
                         delete_track_job.Register ();
                     }
                 }


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