diff --git a/src/widgets/common/downloaditem.cpp b/src/widgets/common/downloaditem.cpp index 8142790..ac5bbf6 100644 --- a/src/widgets/common/downloaditem.cpp +++ b/src/widgets/common/downloaditem.cpp @@ -64,9 +64,9 @@ QString DownloadItem::getName() /*************************************************************** * @brief 告知界面,准备安装 - * @param + * @param * @note 如果正在安装,返回-1 - * @Sample usage: DownloadItem::install(0); + * @Sample usage: DownloadItem::install(0); **************************************************************/ int DownloadItem::readyInstall() { @@ -110,9 +110,9 @@ void DownloadItem::setSpeed(QString s) /*************************************************************** * @brief 安装当前应用 - * @param int t, t为安装方式,可以为 0,1,2 + * @param int t, t为安装方式,可以为 0,1,2 * @note 执行这个函数时,需要已经检查是否可以安装,但该函数仍然会再检测一次! - * @Sample usage: DownloadItem::install(0); + * @Sample usage: DownloadItem::install(0); **************************************************************/ void DownloadItem::install(int t) { @@ -165,9 +165,9 @@ void DownloadItem::on_pushButton_3_clicked() /*************************************************************** * @brief 实际安装应用 - * @param int t, t为安装方式,可以为 0,1,2 + * @param int t, t为安装方式,可以为 0,1,2 * @note 备注 - * @Sample usage: slotAsyncInstall(0); + * @Sample usage: slotAsyncInstall(0); **************************************************************/ void DownloadItem::slotAsyncInstall(int t) { @@ -238,5 +238,5 @@ void DownloadItem::slotAsyncInstall(int t) ui->widget_spinner->hide(); DownloadItem::isInstall = false; - emit finished(); + emit finished(error == 0 && !haveError && !notRoot); } diff --git a/src/widgets/common/downloaditem.h b/src/widgets/common/downloaditem.h index b00c3ee..13c2d2b 100644 --- a/src/widgets/common/downloaditem.h +++ b/src/widgets/common/downloaditem.h @@ -62,7 +62,7 @@ private slots: void slotAsyncInstall(int t); signals: - void finished(); + void finished(bool success); }; #endif // DOWNLOADITEM_H diff --git a/src/widgets/downloadlistwidget.cpp b/src/widgets/downloadlistwidget.cpp index 8cd666c..89fa8ba 100644 --- a/src/widgets/downloadlistwidget.cpp +++ b/src/widgets/downloadlistwidget.cpp @@ -91,10 +91,14 @@ DownloadItem* DownloadListWidget::addItem(QString name, QString fileName, QStrin { return nullptr; } + urList.append(downloadurl); allDownload += 1; toDownload += 1; + DownloadItem *di = new DownloadItem; + connect(di, &DownloadItem::finished, this, &DownloadListWidget::slotInstallFinished, Qt::QueuedConnection); + dlist << downloadurl; downloaditemlist << di; di->setName(name); @@ -167,22 +171,9 @@ void DownloadListWidget::httpFinished() // 完成下载 { continue; } - toDownload -= 1; // 安装完以后减少待安装数目 - qDebug() << "Download: 还没有下载的数目:" << toDownload; - - if (toDownload == 0) - { - Application *app = qobject_cast(qApp); - MainWindow *mainWindow = app->mainWindow(); - if (mainWindow->isCloseWindowAnimation() == true) - { - qDebug() << "Download: 后台安装结束,退出程序"; - qApp->quit(); - } - } - downloaditemlist[nowDownload - 1]->free = true; emit downloadFinished(); + if (nowDownload < allDownload) { // 如果有排队则下载下一个 @@ -241,3 +232,23 @@ void DownloadListWidget::on_pushButton_clicked() { QDesktopServices::openUrl(QUrl("file:///tmp/spark-store", QUrl::TolerantMode)); } + +void DownloadListWidget::slotInstallFinished(bool success) +{ + // NOTE: 仅在安装成功后判断是否需要退出后台 + if (success) { + toDownload -= 1; // 安装完以后减少待安装数目 + qDebug() << "Download: 还没有下载的数目:" << toDownload; + + if (toDownload == 0) + { + Application *app = qobject_cast(qApp); + MainWindow *mainWindow = app->mainWindow(); + if (mainWindow->isCloseWindowAnimation() == true) + { + qDebug() << "Download: 后台安装结束,退出程序"; + qApp->quit(); + } + } + } +} diff --git a/src/widgets/downloadlistwidget.h b/src/widgets/downloadlistwidget.h index 09517f5..6faebc0 100644 --- a/src/widgets/downloadlistwidget.h +++ b/src/widgets/downloadlistwidget.h @@ -60,6 +60,7 @@ signals: private slots: void on_pushButton_clicked(); + void slotInstallFinished(bool success); }; #endif // DOWNLOADLISTWIDGET_H