修复在第一次下载进度报告前取消下载导致崩溃的问题

This commit is contained in:
RigoLigoRLC 2022-02-21 18:01:26 +08:00
parent b0a2d64b71
commit 904cc3cb1c
4 changed files with 27 additions and 11 deletions

@ -13,11 +13,11 @@ SpkUi::SpkPageDownloads::SpkPageDownloads(QWidget *parent) :
mScrollWidget = new QWidget;
mScrollArea = new QScrollArea(this);
mLayEntries->setAlignment(Qt::AlignTop);
mScrollWidget->setLayout(mLayEntries);
mScrollArea->setWidget(mScrollWidget);
mScrollArea->setWidgetResizable(true);
mMainLay->addWidget(mScrollArea);
mMainLay->addStretch();
setLayout(mMainLay);
mDownloadMgr = new SpkDownloadMgr(this);
@ -118,6 +118,8 @@ void SpkUi::SpkPageDownloads::DownloadStopped(SpkDownloadMgr::TaskResult status,
if(!mWaitingDownloads.isEmpty())
{
auto nextTask = mWaitingDownloads.dequeue();
auto nextEntry = mEntries[nextTask.first];
nextEntry->SetStatus(SpkDownloadEntry::Starting);
mDownloadMgr->StartNewDownload(nextTask.second, nextTask.first);
mCurrentStatus = Waiting;
}
@ -199,6 +201,8 @@ void SpkUi::SpkPageDownloads::NewDownloadTask(int id, QString downloadPath)
mWaitingDownloads.enqueue({ id, downloadPath }); // Queue download task for future
else
{
auto nextEntry = mEntries[id];
nextEntry->SetStatus(SpkDownloadEntry::Starting);
mCurrentStatus = Waiting;
if(!mDownloadMgr->StartNewDownload(downloadPath, id)) // Initiate a download task when idle
{

@ -81,10 +81,16 @@ void SpkDownloadEntry::SetStatus(DownloadEntryStatus status, QString msg)
mBtnDelete->setText(tr("Cancel"));
break;
case Starting:
mMessage->setText(tr("Starting download"));
mBtnDelete->setVisible(false);
break;
case Downloading:
mMessage->setText(tr(""));
mProgress->setVisible(true);
mBtnActions->setVisible(false);
mBtnDelete->setVisible(true);
break;
case DownloadFailed:

@ -25,6 +25,7 @@ class SpkDownloadEntry : public QWidget
{
Invalid = -1,
Waiting,
Starting,
Downloading,
DownloadFailed,
ToBeInstalled,

@ -201,38 +201,43 @@ Right now we are not just a Chinese group. We are discovering our way into more
</message>
<message>
<location filename="../gui/spkdownloadentry.cpp" line="81"/>
<location filename="../gui/spkdownloadentry.cpp" line="130"/>
<location filename="../gui/spkdownloadentry.cpp" line="136"/>
<source>Cancel</source>
<translation></translation>
</message>
<message>
<location filename="../gui/spkdownloadentry.cpp" line="94"/>
<location filename="../gui/spkdownloadentry.cpp" line="85"/>
<source>Starting download</source>
<translation></translation>
</message>
<message>
<location filename="../gui/spkdownloadentry.cpp" line="100"/>
<source>Retry</source>
<translation></translation>
</message>
<message>
<location filename="../gui/spkdownloadentry.cpp" line="99"/>
<location filename="../gui/spkdownloadentry.cpp" line="105"/>
<source>Download Finished</source>
<translation></translation>
</message>
<message>
<location filename="../gui/spkdownloadentry.cpp" line="103"/>
<location filename="../gui/spkdownloadentry.cpp" line="128"/>
<location filename="../gui/spkdownloadentry.cpp" line="109"/>
<location filename="../gui/spkdownloadentry.cpp" line="134"/>
<source>Install</source>
<translation></translation>
</message>
<message>
<location filename="../gui/spkdownloadentry.cpp" line="116"/>
<location filename="../gui/spkdownloadentry.cpp" line="122"/>
<source>Installed</source>
<translation></translation>
</message>
<message>
<location filename="../gui/spkdownloadentry.cpp" line="120"/>
<location filename="../gui/spkdownloadentry.cpp" line="126"/>
<source>Delete</source>
<translation></translation>
</message>
<message>
<location filename="../gui/spkdownloadentry.cpp" line="124"/>
<location filename="../gui/spkdownloadentry.cpp" line="130"/>
<source>Install Failed</source>
<translation></translation>
</message>
@ -772,12 +777,12 @@ to use terminal for program output.</source>
<translation>%1</translation>
</message>
<message>
<location filename="../gui/page/spkpagedownloads.cpp" line="156"/>
<location filename="../gui/page/spkpagedownloads.cpp" line="158"/>
<source>Failed to start installation.</source>
<translation></translation>
</message>
<message>
<location filename="../gui/page/spkpagedownloads.cpp" line="192"/>
<location filename="../gui/page/spkpagedownloads.cpp" line="194"/>
<source>Install failed, exit code: %1.</source>
<translation>退%1</translation>
</message>