!188 fix: 多个应用安装可能会出现某一个应用没有安装

Merge pull request !188 from Pluto/auto-5304420-dev-f9438ba2
This commit is contained in:
2023-02-18 12:21:51 +00:00
committed by Gitee
3 changed files with 65 additions and 33 deletions

View File

@@ -61,8 +61,21 @@ QString DownloadItem::getName()
return ui->label_filename->text();
}
void DownloadItem::readyInstall()
/***************************************************************
* @brief 告知界面,准备安装
* @param
* @note 如果正在安装,返回-1
* @Sample usage: DownloadItem::install(0);
**************************************************************/
int DownloadItem::readyInstall()
{
// 检查是否正在安装,如果是返回错误 -1
if (isInstall)
{
return -1;
}
if (!close)
{
ui->progressBar->hide();
@@ -70,7 +83,9 @@ void DownloadItem::readyInstall()
ui->pushButton_install->show();
DownloadItem::install(0);
ui->pushButton_2->hide();
return 1;
}
return 0;
}
void DownloadItem::setFileName(QString fileName)
@@ -93,6 +108,12 @@ void DownloadItem::setSpeed(QString s)
speed = s;
}
/***************************************************************
* @brief 安装当前应用
* @param int t, t为安装方式可以为 0,1,2
* @note 备注
* @Sample usage: DownloadItem::install(0);
**************************************************************/
void DownloadItem::install(int t)
{
if (!isInstall)
@@ -142,6 +163,12 @@ void DownloadItem::on_pushButton_3_clicked()
output_w->show();
}
/***************************************************************
* @brief 实际安装应用
* @param int t, t为安装方式可以为 0,1,2
* @note 备注
* @Sample usage: slotAsyncInstall(0);
**************************************************************/
void DownloadItem::slotAsyncInstall(int t)
{
QProcess installer;

View File

@@ -34,7 +34,7 @@ public:
void setMax(qint64);
void setName(QString);
QString getName();
void readyInstall();
int readyInstall();
void setFileName(QString);
void seticon(const QPixmap);

View File

@@ -3,6 +3,8 @@
#include <QGraphicsOpacityEffect>
#include <QPropertyAnimation>
#include <QDebug>
#include <QtConcurrent>
DownloadListWidget::DownloadListWidget(QWidget *parent) : DBlurEffectWidget(parent),
ui(new Ui::DownloadListWidget)
{
@@ -65,20 +67,6 @@ DownloadListWidget::~DownloadListWidget()
void DownloadListWidget::clearItem()
{
// QListWidgetItem *item = nullptr;
// while ((item = ui->listWidget->takeItem(0)) != nullptr)
// {
// QWidget *card = ui->listWidget->itemWidget(item);
// if (card)
// {
// card->deleteLater();
// card = nullptr;
// }
// delete item;
// item = nullptr;
// }
// ui->listWidget->vScrollBar->scrollTop();
ui->listWidget->clear();
}
@@ -142,30 +130,47 @@ void DownloadListWidget::startRequest(QUrl url, QString fileName)
downloadController->startDownload(url.toString());
}
/***************************************************************
* @brief 下载列表完成下载的回调函数
* @param
* @note 如果正在安装,则在新开的线程空间中等待上一个安装完
* @Sample usage:
**************************************************************/
void DownloadListWidget::httpFinished() // 完成下载
{
isdownload = false;
isBusy = false;
downloaditemlist[nowDownload - 1]->readyInstall();
downloaditemlist[nowDownload - 1]->free = true;
emit downloadFinished();
if (nowDownload < allDownload)
QtConcurrent::run([=]()
{
// 如果有排队则下载下一个
qDebug() << "切换下一个下载...";
nowDownload += 1;
while (downloaditemlist[nowDownload - 1]->close)
while (downloaditemlist[nowDownload - 1]->readyInstall() == -1)
{
nowDownload += 1;
if (nowDownload >= allDownload)
{
nowDownload = allDownload;
return;
}
continue;
}
QString fileName = downloaditemlist[nowDownload - 1]->getName();
startRequest(urList.at(nowDownload - 1), fileName);
}
downloaditemlist[nowDownload - 1]->free = true;
emit downloadFinished();
if (nowDownload < allDownload)
{
// 如果有排队则下载下一个
qDebug() << "切换下一个下载...";
nowDownload += 1;
while (downloaditemlist[nowDownload - 1]->close)
{
nowDownload += 1;
if (nowDownload >= allDownload)
{
nowDownload = allDownload;
return;
}
}
QString fileName = downloaditemlist[nowDownload - 1]->getName();
startRequest(urList.at(nowDownload - 1), fileName);
}
});
}
void DownloadListWidget::updateDataReadProgress(QString speedInfo, qint64 bytesRead, qint64 totalBytes)