Merge branch 'dev' of gitee.com:deepin-community-store/spark-store into Reason

This commit is contained in:
uniartisan 2023-03-05 22:57:18 +08:00
commit efba72002a
4 changed files with 34 additions and 22 deletions

View File

@ -64,9 +64,9 @@ QString DownloadItem::getName()
/*************************************************************** /***************************************************************
* @brief * @brief
* @param * @param
* @note -1 * @note -1
* @Sample usage: DownloadItem::install(0); * @Sample usage: DownloadItem::install(0);
**************************************************************/ **************************************************************/
int DownloadItem::readyInstall() int DownloadItem::readyInstall()
{ {
@ -110,9 +110,9 @@ void DownloadItem::setSpeed(QString s)
/*************************************************************** /***************************************************************
* @brief * @brief
* @param int t, t为安装方式 0,1,2 * @param int t, t为安装方式 0,1,2
* @note * @note
* @Sample usage: DownloadItem::install(0); * @Sample usage: DownloadItem::install(0);
**************************************************************/ **************************************************************/
void DownloadItem::install(int t) void DownloadItem::install(int t)
{ {
@ -165,9 +165,9 @@ void DownloadItem::on_pushButton_3_clicked()
/*************************************************************** /***************************************************************
* @brief * @brief
* @param int t, t为安装方式 0,1,2 * @param int t, t为安装方式 0,1,2
* @note * @note
* @Sample usage: slotAsyncInstall(0); * @Sample usage: slotAsyncInstall(0);
**************************************************************/ **************************************************************/
void DownloadItem::slotAsyncInstall(int t) void DownloadItem::slotAsyncInstall(int t)
{ {
@ -238,5 +238,5 @@ void DownloadItem::slotAsyncInstall(int t)
ui->widget_spinner->hide(); ui->widget_spinner->hide();
DownloadItem::isInstall = false; DownloadItem::isInstall = false;
emit finished(); emit finished(error == 0 && !haveError && !notRoot);
} }

View File

@ -62,7 +62,7 @@ private slots:
void slotAsyncInstall(int t); void slotAsyncInstall(int t);
signals: signals:
void finished(); void finished(bool success);
}; };
#endif // DOWNLOADITEM_H #endif // DOWNLOADITEM_H

View File

@ -91,10 +91,14 @@ DownloadItem* DownloadListWidget::addItem(QString name, QString fileName, QStrin
{ {
return nullptr; return nullptr;
} }
urList.append(downloadurl); urList.append(downloadurl);
allDownload += 1; allDownload += 1;
toDownload += 1; toDownload += 1;
DownloadItem *di = new DownloadItem; DownloadItem *di = new DownloadItem;
connect(di, &DownloadItem::finished, this, &DownloadListWidget::slotInstallFinished, Qt::QueuedConnection);
dlist << downloadurl; dlist << downloadurl;
downloaditemlist << di; downloaditemlist << di;
di->setName(name); di->setName(name);
@ -167,22 +171,9 @@ void DownloadListWidget::httpFinished() // 完成下载
{ {
continue; continue;
} }
toDownload -= 1; // 安装完以后减少待安装数目
qDebug() << "Download: 还没有下载的数目:" << toDownload;
if (toDownload == 0)
{
Application *app = qobject_cast<Application *>(qApp);
MainWindow *mainWindow = app->mainWindow();
if (mainWindow->isCloseWindowAnimation() == true)
{
qDebug() << "Download: 后台安装结束,退出程序";
qApp->quit();
}
}
downloaditemlist[nowDownload - 1]->free = true; downloaditemlist[nowDownload - 1]->free = true;
emit downloadFinished(); emit downloadFinished();
if (nowDownload < allDownload) if (nowDownload < allDownload)
{ {
// 如果有排队则下载下一个 // 如果有排队则下载下一个
@ -241,3 +232,23 @@ void DownloadListWidget::on_pushButton_clicked()
{ {
QDesktopServices::openUrl(QUrl("file:///tmp/spark-store", QUrl::TolerantMode)); 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<Application *>(qApp);
MainWindow *mainWindow = app->mainWindow();
if (mainWindow->isCloseWindowAnimation() == true)
{
qDebug() << "Download: 后台安装结束,退出程序";
qApp->quit();
}
}
}
}

View File

@ -60,6 +60,7 @@ signals:
private slots: private slots:
void on_pushButton_clicked(); void on_pushButton_clicked();
void slotInstallFinished(bool success);
}; };
#endif // DOWNLOADLISTWIDGET_H #endif // DOWNLOADLISTWIDGET_H