[f-spot] Correctly clean up when cancelling.
- From: Ruben Vermeersch <rubenv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [f-spot] Correctly clean up when cancelling.
- Date: Sat, 5 Jun 2010 20:54:52 +0000 (UTC)
commit 0548bf773bc7a23c2e4b877281d42fe46d008133
Author: Ruben Vermeersch <ruben savanne be>
Date: Sat Jun 5 20:50:28 2010 +0200
Correctly clean up when cancelling.
src/Import/ImportController.cs | 35 ++++++++++++++++++++++++-----------
1 files changed, 24 insertions(+), 11 deletions(-)
---
diff --git a/src/Import/ImportController.cs b/src/Import/ImportController.cs
index c2717c8..969b9ee 100644
--- a/src/Import/ImportController.cs
+++ b/src/Import/ImportController.cs
@@ -187,8 +187,10 @@ namespace FSpot.Import
public void CancelImport ()
{
- // FIXME
- DeactivateSource (ActiveSource);
+ import_cancelled = true;
+ if (ImportThread != null)
+ ImportThread.Join ();
+ Cleanup ();
}
Stack<SafeUri> created_directories;
@@ -198,6 +200,7 @@ namespace FSpot.Import
RollStore rolls = App.Instance.Database.Rolls;
volatile bool photo_scan_running;
XmpTagsImporter xmp_importer;
+ volatile bool import_cancelled = false;
void DoImport ()
{
@@ -219,6 +222,11 @@ namespace FSpot.Import
int i = 0;
int total = Photos.Count;
foreach (var info in Photos.Items) {
+ if (import_cancelled) {
+ RollbackImport ();
+ return;
+ }
+
ThreadAssist.ProxyToMain (() => ReportProgress (i++, total));
ImportPhoto (info, CreatedRoll);
}
@@ -229,18 +237,23 @@ namespace FSpot.Import
RollbackImport ();
throw e;
} finally {
- if (imported_photos.Count == 0)
- rolls.Remove (CreatedRoll);
- imported_photos = null;
- created_directories = null;
- Photo.ResetMD5Cache ();
- DeactivateSource (ActiveSource);
- Photos.Clear ();
- System.GC.Collect ();
- App.Instance.Database.Sync = true;
+ Cleanup ();
}
}
+ void Cleanup ()
+ {
+ if (imported_photos != null && imported_photos.Count == 0)
+ rolls.Remove (CreatedRoll);
+ imported_photos = null;
+ created_directories = null;
+ Photo.ResetMD5Cache ();
+ DeactivateSource (ActiveSource);
+ Photos.Clear ();
+ System.GC.Collect ();
+ App.Instance.Database.Sync = true;
+ }
+
void FinishImport ()
{
ThreadAssist.SpawnFromMain (() => {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]