Skip to content

Commit

Permalink
Added option to stop and resume download
Browse files Browse the repository at this point in the history
  • Loading branch information
gastoner committed Sep 23, 2024
1 parent b0d0317 commit e9202a5
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 11 deletions.
8 changes: 8 additions & 0 deletions src/app/downloadmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions src/app/downloadmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 25 additions & 3 deletions src/app/qml/DownloadPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,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
Expand Down Expand Up @@ -110,12 +112,12 @@ Page {
}

Label {
visible: currentStatus == Units.DownloadStatus.Downloading
visible: currentStatus == Units.DownloadStatus.Downloading || currentStatus == Units.DownloadStatus.Stopped
text: progressColumn.leftStr
}

Label {
visible: currentStatus == Units.DownloadStatus.Downloading
visible: currentStatus == Units.DownloadStatus.Downloading || currentStatus == Units.DownloadStatus.Stopped
text: progressColumn.rightStr
}
}
Expand Down Expand Up @@ -156,6 +158,14 @@ Page {
width: mainColumn.width
}

Label {
id: messageContinueDownload
visible: false
text: qsTr("Download has been stopped.")
wrapMode: Label.Wrap
width: mainColumn.width
}

Label {
id: messageRestore
visible: false
Expand Down Expand Up @@ -321,6 +331,18 @@ Page {
target: messageLoseData;
visible: true
}
},
State {
name: "stopped"
when: currentStatus === Units.DownloadStatus.Stopped
PropertyChanges {
target: progressBar;
value: releases.variant.progress.ratio
}
PropertyChanges {
target: messageContinueDownload;
visible: true
}
}
// Unhandled states:
// preparing. writing_not_possible, failed_verification_no_drives,failed_download, failed_no_drives
Expand Down Expand Up @@ -349,7 +371,7 @@ Page {

function getNextButtonState() {
// This will be [Finish] button to successfully go to the main page
if (currentStatus == Units.DownloadStatus.Finished)
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 ||
Expand Down
1 change: 1 addition & 0 deletions src/app/qml/Units.qml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ QtObject {
Downloading,
Download_Verifying,
Ready,
Stopped,
Writing_Not_Possible,
Writing,
Write_Verifying,
Expand Down
29 changes: 23 additions & 6 deletions src/app/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ ApplicationWindow {

Button {
id: nextButton
visible: mainLayout.state != "downloadPage"
enabled: mainLayout.state != "drivePage"
text: getNextButtonText()
}
Expand Down Expand Up @@ -215,8 +214,11 @@ ApplicationWindow {
target: prevButton
visible: true
onClicked: {
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.Download_Verifying) {
if (releases.variant.status === Units.DownloadStatus.Write_Verifying || releases.variant.status === Units.DownloadStatus.Writing || 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()
Expand All @@ -237,7 +239,16 @@ ApplicationWindow {
if (selectedOption != Units.MainSelect.Write)
releases.variant.download()
drives.selected.setImage(releases.variant)
drives.selected.write(releases.variant)
drives.selected.write(releases.variant)
} else if (releases.variant.status === Units.DownloadStatus.Preparing) {
releases.variant.download()
} 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)
}
}
}
}
Expand Down Expand Up @@ -296,12 +307,14 @@ ApplicationWindow {
return qsTr("Download && Write")
return qsTr("Download & Write")
} else if (mainLayout.state == "downloadPage") {
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.Download_Verifying)
if (releases.variant.status === Units.DownloadStatus.Write_Verifying || releases.variant.status === Units.DownloadStatus.Writing || releases.variant.status === Units.DownloadStatus.Download_Verifying)
return qsTr("Cancel")
else if (releases.variant.status == Units.DownloadStatus.Ready)
return qsTr("Write")
else if (releases.variant.status === Units.DownloadStatus.Finished)
return qsTr("Finish")
else if (releases.variant.status === Units.DownloadStatus.Stopped)
return qsTr("Resume")
else
return qsTr("Retry")
}
Expand All @@ -311,8 +324,12 @@ ApplicationWindow {
function getPrevButtonText() {
if (mainLayout.state == "mainPage")
return qsTr("About")
else if (mainLayout.state == "downloadPage")
return qsTr("Cancel")
else if (mainLayout.state == "downloadPage") {
if (releases.variant.status === Units.DownloadStatus.Downloading)
return qsTr("Pause")
else
return qsTr("Cancel")
}
return qsTr("Previous")
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/app/releasemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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);

Expand All @@ -439,6 +439,7 @@ class ReleaseVariant : public QObject, public DownloadReceiver
public slots:
void download();
void resetStatus();
void setStatus(Status s);

private:
QString m_temporaryIso{};
Expand Down

0 comments on commit e9202a5

Please sign in to comment.