changeset 981:c6f2b93a7d52

Respond tidily to user cancellation during download, instead of going on to attempt to load the nonexistent file as a non-audio format
author Chris Cannam
date Tue, 09 Sep 2014 16:52:24 +0100
parents c598b1d880f2
children f161ca450050
files data/fileio/FileSource.cpp data/fileio/FileSource.h
diffstat 2 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/FileSource.cpp	Wed Sep 03 13:10:19 2014 +0100
+++ b/data/fileio/FileSource.cpp	Tue Sep 09 16:52:24 2014 +0100
@@ -78,6 +78,7 @@
     m_reply(0),
     m_preferredContentType(preferredContentType),
     m_ok(false),
+    m_cancelled(false),
     m_lastStatus(0),
     m_resource(fileOrUrl.startsWith(':')),
     m_remote(isRemote(fileOrUrl)),
@@ -167,6 +168,7 @@
     m_localFile(0),
     m_reply(0),
     m_ok(false),
+    m_cancelled(false),
     m_lastStatus(0),
     m_resource(false),
     m_remote(isRemote(url.toString())),
@@ -199,6 +201,7 @@
     m_localFile(0),
     m_reply(0),
     m_ok(rf.m_ok),
+    m_cancelled(rf.m_cancelled),
     m_lastStatus(rf.m_lastStatus),
     m_resource(rf.m_resource),
     m_remote(rf.m_remote),
@@ -571,6 +574,12 @@
 }
 
 bool
+FileSource::wasCancelled() const
+{
+    return m_cancelled;
+}
+
+bool
 FileSource::isResource() const
 {
     return m_resource;
@@ -710,6 +719,7 @@
     cleanup();
 
     m_ok = false;
+    m_cancelled = true;
     m_errorString = tr("Download cancelled");
 }
 
--- a/data/fileio/FileSource.h	Wed Sep 03 13:10:19 2014 +0100
+++ b/data/fileio/FileSource.h	Tue Sep 09 16:52:24 2014 +0100
@@ -101,10 +101,10 @@
     void waitForData();
 
     /**
-     * Return true if the FileSource object is valid and no error
-     * occurred in looking up the file or remote URL.  Non-existence
-     * of the file or URL is not an error -- call isAvailable() to
-     * test for that.
+     * Return true if the FileSource object is valid and neither error
+     * nor cancellation occurred while retrieving the file or remote
+     * URL.  Non-existence of the file or URL is not an error -- call
+     * isAvailable() to test for that.
      */
     bool isOK() const;
 
@@ -122,6 +122,14 @@
     bool isDone() const;
 
     /**
+     * Return true if the operation was cancelled by the user through
+     * the ProgressReporter interface. Note that the cancelled()
+     * signal will have been emitted, and isOK() will also return
+     * false in this case.
+     */
+    bool wasCancelled() const;
+
+    /**
      * Return true if this FileSource is referring to a QRC resource.
      */
     bool isResource() const;
@@ -227,6 +235,7 @@
     QString m_contentType;
     QString m_preferredContentType;
     bool m_ok;
+    bool m_cancelled;
     int m_lastStatus;
     bool m_resource;
     bool m_remote;