summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Little <arealityfarbetween@googlemail.com>2013-02-16 23:16:10 +0000
committerAndres G. Aragoneses <knocte@gmail.com>2013-02-16 23:20:36 +0000
commitefd3c38d356fdb4dc0abe3658f618b2a25dcbe20 (patch)
treef5ad56590c3e967e40eadd4f895d369a777a2bd3
parentbda9217292517a7fe6d0eb52329cc693754ca00b (diff)
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>
-rw-r--r--src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs21
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 d79d5a6fd..3653c6db0 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 ();
}
}