Skip to content

Commit e9202a5

Browse files
committed
Added option to stop and resume download
1 parent b0d0317 commit e9202a5

File tree

6 files changed

+61
-11
lines changed

6 files changed

+61
-11
lines changed

src/app/downloadmanager.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ void DownloadManager::cancel()
137137
}
138138
}
139139

140+
void DownloadManager::stopDownload()
141+
{
142+
if (m_current) {
143+
m_current->deleteLater();
144+
mDebug() << this->metaObject()->className() << "Stopping";
145+
}
146+
}
147+
140148
bool DownloadManager::isDownloaded(const QUrl &url) const
141149
{
142150
const QString filePath = QString("%1/%2").arg(DownloadManager::dir()).arg(url.fileName());

src/app/downloadmanager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ class DownloadManager : public QObject, public DownloadReceiver
163163
QNetworkReply *tryAnotherMirror();
164164

165165
Q_INVOKABLE void cancel();
166+
Q_INVOKABLE void stopDownload();
166167
Q_INVOKABLE bool isDownloaded(const QUrl &url) const;
167168

168169
// DownloadReceiver interface

src/app/qml/DownloadPage.qml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ Page {
6262
qsTr("Preparing %1").arg(file)
6363
else if (currentStatus === Units.DownloadStatus.Ready)
6464
qsTr("Ready to write %1").arg(file)
65+
else if (currentStatus === Units.DownloadStatus.Stopped)
66+
qsTr("%1 has been stopped").arg(file)
6567
else if (currentStatus == Units.DownloadStatus.Failed_Download)
6668
qsTr("Failed to download %1").arg(file)
6769
else
@@ -110,12 +112,12 @@ Page {
110112
}
111113

112114
Label {
113-
visible: currentStatus == Units.DownloadStatus.Downloading
115+
visible: currentStatus == Units.DownloadStatus.Downloading || currentStatus == Units.DownloadStatus.Stopped
114116
text: progressColumn.leftStr
115117
}
116118

117119
Label {
118-
visible: currentStatus == Units.DownloadStatus.Downloading
120+
visible: currentStatus == Units.DownloadStatus.Downloading || currentStatus == Units.DownloadStatus.Stopped
119121
text: progressColumn.rightStr
120122
}
121123
}
@@ -156,6 +158,14 @@ Page {
156158
width: mainColumn.width
157159
}
158160

161+
Label {
162+
id: messageContinueDownload
163+
visible: false
164+
text: qsTr("Download has been stopped.")
165+
wrapMode: Label.Wrap
166+
width: mainColumn.width
167+
}
168+
159169
Label {
160170
id: messageRestore
161171
visible: false
@@ -321,6 +331,18 @@ Page {
321331
target: messageLoseData;
322332
visible: true
323333
}
334+
},
335+
State {
336+
name: "stopped"
337+
when: currentStatus === Units.DownloadStatus.Stopped
338+
PropertyChanges {
339+
target: progressBar;
340+
value: releases.variant.progress.ratio
341+
}
342+
PropertyChanges {
343+
target: messageContinueDownload;
344+
visible: true
345+
}
324346
}
325347
// Unhandled states:
326348
// preparing. writing_not_possible, failed_verification_no_drives,failed_download, failed_no_drives
@@ -349,7 +371,7 @@ Page {
349371

350372
function getNextButtonState() {
351373
// This will be [Finish] button to successfully go to the main page
352-
if (currentStatus == Units.DownloadStatus.Finished)
374+
if (currentStatus == Units.DownloadStatus.Finished || currentStatus == Units.DownloadStatus.Stopped)
353375
return true
354376
// This will be [Retry] button to start the process again if there is a drive plugged in
355377
else if (currentStatus == Units.DownloadStatus.Ready ||

src/app/qml/Units.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ QtObject {
5959
Downloading,
6060
Download_Verifying,
6161
Ready,
62+
Stopped,
6263
Writing_Not_Possible,
6364
Writing,
6465
Write_Verifying,

src/app/qml/main.qml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ ApplicationWindow {
101101

102102
Button {
103103
id: nextButton
104-
visible: mainLayout.state != "downloadPage"
105104
enabled: mainLayout.state != "drivePage"
106105
text: getNextButtonText()
107106
}
@@ -215,8 +214,11 @@ ApplicationWindow {
215214
target: prevButton
216215
visible: true
217216
onClicked: {
218-
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) {
217+
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) {
219218
cancelDialog.show()
219+
} else if (releases.variant.status === Units.DownloadStatus.Downloading) {
220+
downloadManager.stopDownload()
221+
releases.variant.setStatus(Units.DownloadStatus.Stopped)
220222
} else {
221223
releases.variant.resetStatus()
222224
downloadManager.cancel()
@@ -237,7 +239,16 @@ ApplicationWindow {
237239
if (selectedOption != Units.MainSelect.Write)
238240
releases.variant.download()
239241
drives.selected.setImage(releases.variant)
240-
drives.selected.write(releases.variant)
242+
drives.selected.write(releases.variant)
243+
} else if (releases.variant.status === Units.DownloadStatus.Preparing) {
244+
releases.variant.download()
245+
} else if (releases.variant.status === Units.DownloadStatus.Stopped) {
246+
if (selectedOption != Units.MainSelect.Write)
247+
releases.variant.download()
248+
if (drives.length) {
249+
drives.selected.setImage(releases.variant)
250+
drives.selected.write(releases.variant)
251+
}
241252
}
242253
}
243254
}
@@ -296,12 +307,14 @@ ApplicationWindow {
296307
return qsTr("Download && Write")
297308
return qsTr("Download & Write")
298309
} else if (mainLayout.state == "downloadPage") {
299-
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)
310+
if (releases.variant.status === Units.DownloadStatus.Write_Verifying || releases.variant.status === Units.DownloadStatus.Writing || releases.variant.status === Units.DownloadStatus.Download_Verifying)
300311
return qsTr("Cancel")
301312
else if (releases.variant.status == Units.DownloadStatus.Ready)
302313
return qsTr("Write")
303314
else if (releases.variant.status === Units.DownloadStatus.Finished)
304315
return qsTr("Finish")
316+
else if (releases.variant.status === Units.DownloadStatus.Stopped)
317+
return qsTr("Resume")
305318
else
306319
return qsTr("Retry")
307320
}
@@ -311,8 +324,12 @@ ApplicationWindow {
311324
function getPrevButtonText() {
312325
if (mainLayout.state == "mainPage")
313326
return qsTr("About")
314-
else if (mainLayout.state == "downloadPage")
315-
return qsTr("Cancel")
327+
else if (mainLayout.state == "downloadPage") {
328+
if (releases.variant.status === Units.DownloadStatus.Downloading)
329+
return qsTr("Pause")
330+
else
331+
return qsTr("Cancel")
332+
}
316333
return qsTr("Previous")
317334
}
318335
}

src/app/releasemanager.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,13 @@ class ReleaseVariant : public QObject, public DownloadReceiver
373373
public:
374374
enum Type { LIVE = 0, NETINSTALL, FULL, ATOMIC };
375375
Q_ENUMS(Type)
376-
enum Status { PREPARING = 0, DOWNLOADING, DOWNLOAD_VERIFYING, READY, WRITING_NOT_POSSIBLE, WRITING, WRITE_VERIFYING, FINISHED, FAILED_VERIFICATION, FAILED_DOWNLOAD, FAILED };
376+
enum Status { PREPARING = 0, DOWNLOADING, DOWNLOAD_VERIFYING, READY, STOPPED, WRITING_NOT_POSSIBLE, WRITING, WRITE_VERIFYING, FINISHED, FAILED_VERIFICATION, FAILED_DOWNLOAD, FAILED };
377377
Q_ENUMS(Status)
378378
const QStringList m_statusStrings{tr("Preparing"),
379379
tr("Downloading"),
380380
tr("Checking the download"),
381381
tr("Ready to write"),
382+
tr("Download has been stopped"),
382383
tr("Image file was saved to your downloads folder. Writing is not possible"),
383384
tr("Writing"),
384385
tr("Checking the written data"),
@@ -414,7 +415,6 @@ class ReleaseVariant : public QObject, public DownloadReceiver
414415

415416
Status status() const;
416417
QString statusString() const;
417-
void setStatus(Status s);
418418
QString errorString() const;
419419
void setErrorString(const QString &o);
420420

@@ -439,6 +439,7 @@ class ReleaseVariant : public QObject, public DownloadReceiver
439439
public slots:
440440
void download();
441441
void resetStatus();
442+
void setStatus(Status s);
442443

443444
private:
444445
QString m_temporaryIso{};

0 commit comments

Comments
 (0)