diff --git a/src/app/downloadmanager.cpp b/src/app/downloadmanager.cpp index c79ed368..e1f393c8 100644 --- a/src/app/downloadmanager.cpp +++ b/src/app/downloadmanager.cpp @@ -137,6 +137,14 @@ void DownloadManager::cancel() } } +void DownloadManager::stopDownload() +{ + if (m_current) { + m_current->deleteLater(); + mDebug() << this->metaObject()->className() << "Stopping"; + } +} + bool DownloadManager::isDownloaded(const QUrl &url) const { const QString filePath = QString("%1/%2").arg(DownloadManager::dir()).arg(url.fileName()); diff --git a/src/app/downloadmanager.h b/src/app/downloadmanager.h index 7f475159..fa2b223f 100644 --- a/src/app/downloadmanager.h +++ b/src/app/downloadmanager.h @@ -163,6 +163,7 @@ class DownloadManager : public QObject, public DownloadReceiver QNetworkReply *tryAnotherMirror(); Q_INVOKABLE void cancel(); + Q_INVOKABLE void stopDownload(); Q_INVOKABLE bool isDownloaded(const QUrl &url) const; // DownloadReceiver interface diff --git a/src/app/qml/DownloadPage.qml b/src/app/qml/DownloadPage.qml index bb2831d1..24b5bb83 100644 --- a/src/app/qml/DownloadPage.qml +++ b/src/app/qml/DownloadPage.qml @@ -42,6 +42,8 @@ Page { qsTr("Preparing %1").arg(file) else if (currentStatus === Units.DownloadStatus.Ready) qsTr("Ready to write %1").arg(file) + else if (currentStatus === Units.DownloadStatus.Stopped) + qsTr("%1 has been stopped").arg(file) else if (currentStatus == Units.DownloadStatus.Failed_Download) qsTr("Failed to download %1").arg(file) else @@ -78,12 +80,12 @@ Page { } QQC2.Label { - visible: currentStatus == Units.DownloadStatus.Downloading + visible: currentStatus == Units.DownloadStatus.Downloading || currentStatus == Units.DownloadStatus.Stopped text: downloadPage.leftStr } QQC2.Label { - visible: currentStatus == Units.DownloadStatus.Downloading + visible: currentStatus == Units.DownloadStatus.Downloading || currentStatus == Units.DownloadStatus.Stopped text: downloadPage.rightStr } } @@ -135,6 +137,14 @@ Page { wrapMode: QQC2.Label.Wrap } + QQC2.Label { + id: messageContinueDownload + visible: currentStatus === Units.DownloadStatus.Stopped + text: qsTr("Download has been stopped.") + wrapMode: Label.Wrap + width: mainColumn.width + } + QQC2.Label { id: messageSelectedImage visible: releases.selected.isLocal @@ -228,19 +238,37 @@ Page { releases.variant } } + }, + State { + name: "stopped" + when: currentStatus === Units.DownloadStatus.Stopped + PropertyChanges { + target: progressBar; + value: releases.variant.progress.ratio + } + PropertyChanges { + target: messageContinueDownload; + visible: true + } } ] - // There will be only [Finish] button on the right side so [Cancel] button - // is not necessary previousButtonVisible: currentStatus != Units.DownloadStatus.Finished - previousButtonText: qsTr("Cancel") + previousButtonText: { + if (releases.variant.status === Units.DownloadStatus.Downloading) + return qsTr("Pause") + else + return qsTr("Cancel") + } onPreviousButtonClicked: { if (releases.variant.status === Units.DownloadStatus.Write_Verifying || releases.variant.status === Units.DownloadStatus.Writing || - releases.variant.status === Units.DownloadStatus.Downloading || + releases.variant.status === Units.DownloadStatus.Stopped || releases.variant.status === Units.DownloadStatus.Download_Verifying) { cancelDialog.show() + } else if (releases.variant.status === Units.DownloadStatus.Downloading) { + downloadManager.stopDownload() + releases.variant.setStatus(Units.DownloadStatus.Stopped) } else { releases.variant.resetStatus() downloadManager.cancel() @@ -249,7 +277,9 @@ Page { } nextButtonVisible: { - if (currentStatus == Units.DownloadStatus.Finished) + // This will be [Finish] or [Resume] button to finish download or resume download + if (currentStatus == Units.DownloadStatus.Finished || + currentStatus == Units.DownloadStatus.Stopped) return true // This will be [Retry] button to start the process again if there is a drive plugged in else if (currentStatus == Units.DownloadStatus.Ready || @@ -260,7 +290,6 @@ Page { return false } nextButtonText: { - if (releases.variant.status === Units.DownloadStatus.Write_Verifying || releases.variant.status === Units.DownloadStatus.Writing || releases.variant.status === Units.DownloadStatus.Downloading || @@ -268,6 +297,8 @@ Page { return qsTr("Cancel") else if (releases.variant.status == Units.DownloadStatus.Ready) return qsTr("Write") + else if (releases.variant.status === Units.DownloadStatus.Stopped) + return qsTr("Resume") else if (releases.variant.status === Units.DownloadStatus.Finished) return qsTr("Finish") else @@ -288,6 +319,13 @@ Page { releases.variant.download() drives.selected.setImage(releases.variant) drives.selected.write(releases.variant) + } else if (releases.variant.status === Units.DownloadStatus.Stopped) { + if (selectedOption != Units.MainSelect.Write) + releases.variant.download() + if (drives.length) { + drives.selected.setImage(releases.variant) + drives.selected.write(releases.variant) + } } } } diff --git a/src/app/qml/Units.qml b/src/app/qml/Units.qml index 512fd1f9..4cc474b8 100644 --- a/src/app/qml/Units.qml +++ b/src/app/qml/Units.qml @@ -58,6 +58,7 @@ QtObject { Downloading, Download_Verifying, Ready, + Stopped, Writing_Not_Possible, Writing, Write_Verifying, diff --git a/src/app/releasemanager.h b/src/app/releasemanager.h index e85bfd40..100daeec 100644 --- a/src/app/releasemanager.h +++ b/src/app/releasemanager.h @@ -373,12 +373,13 @@ class ReleaseVariant : public QObject, public DownloadReceiver public: enum Type { LIVE = 0, NETINSTALL, FULL, ATOMIC }; Q_ENUMS(Type) - enum Status { PREPARING = 0, DOWNLOADING, DOWNLOAD_VERIFYING, READY, WRITING_NOT_POSSIBLE, WRITING, WRITE_VERIFYING, FINISHED, FAILED_VERIFICATION, FAILED_DOWNLOAD, FAILED }; + enum Status { PREPARING = 0, DOWNLOADING, DOWNLOAD_VERIFYING, READY, STOPPED, WRITING_NOT_POSSIBLE, WRITING, WRITE_VERIFYING, FINISHED, FAILED_VERIFICATION, FAILED_DOWNLOAD, FAILED }; Q_ENUMS(Status) const QStringList m_statusStrings{tr("Preparing"), tr("Downloading"), tr("Checking the download"), tr("Ready to write"), + tr("Download has been stopped"), tr("Image file was saved to your downloads folder. Writing is not possible"), tr("Writing"), tr("Checking the written data"), @@ -414,7 +415,6 @@ class ReleaseVariant : public QObject, public DownloadReceiver Status status() const; QString statusString() const; - void setStatus(Status s); QString errorString() const; void setErrorString(const QString &o); @@ -439,6 +439,7 @@ class ReleaseVariant : public QObject, public DownloadReceiver public slots: void download(); void resetStatus(); + void setStatus(Status s); private: QString m_temporaryIso{};