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

This commit is contained in:
uniartisan 2023-02-18 20:06:36 +08:00
parent d742e85332
commit 33ea9ee065
3 changed files with 65 additions and 33 deletions

View File

@ -61,8 +61,21 @@ QString DownloadItem::getName()
return ui->label_filename->text(); 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) if (!close)
{ {
ui->progressBar->hide(); ui->progressBar->hide();
@ -70,7 +83,9 @@ void DownloadItem::readyInstall()
ui->pushButton_install->show(); ui->pushButton_install->show();
DownloadItem::install(0); DownloadItem::install(0);
ui->pushButton_2->hide(); ui->pushButton_2->hide();
return 1;
} }
return 0;
} }
void DownloadItem::setFileName(QString fileName) void DownloadItem::setFileName(QString fileName)
@ -93,6 +108,12 @@ void DownloadItem::setSpeed(QString s)
speed = s; speed = s;
} }
/***************************************************************
* @brief
* @param int t, t为安装方式 0,1,2
* @note
* @Sample usage: DownloadItem::install(0);
**************************************************************/
void DownloadItem::install(int t) void DownloadItem::install(int t)
{ {
if (!isInstall) if (!isInstall)
@ -142,6 +163,12 @@ void DownloadItem::on_pushButton_3_clicked()
output_w->show(); output_w->show();
} }
/***************************************************************
* @brief
* @param int t, t为安装方式 0,1,2
* @note
* @Sample usage: slotAsyncInstall(0);
**************************************************************/
void DownloadItem::slotAsyncInstall(int t) void DownloadItem::slotAsyncInstall(int t)
{ {
QProcess installer; QProcess installer;

View File

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

View File

@ -3,6 +3,8 @@
#include <QGraphicsOpacityEffect> #include <QGraphicsOpacityEffect>
#include <QPropertyAnimation> #include <QPropertyAnimation>
#include <QDebug> #include <QDebug>
#include <QtConcurrent>
DownloadListWidget::DownloadListWidget(QWidget *parent) : DBlurEffectWidget(parent), DownloadListWidget::DownloadListWidget(QWidget *parent) : DBlurEffectWidget(parent),
ui(new Ui::DownloadListWidget) ui(new Ui::DownloadListWidget)
{ {
@ -65,20 +67,6 @@ DownloadListWidget::~DownloadListWidget()
void DownloadListWidget::clearItem() 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(); ui->listWidget->clear();
} }
@ -142,30 +130,47 @@ void DownloadListWidget::startRequest(QUrl url, QString fileName)
downloadController->startDownload(url.toString()); downloadController->startDownload(url.toString());
} }
/***************************************************************
* @brief
* @param
* @note 线
* @Sample usage:
**************************************************************/
void DownloadListWidget::httpFinished() // 完成下载 void DownloadListWidget::httpFinished() // 完成下载
{ {
isdownload = false; isdownload = false;
isBusy = false; isBusy = false;
downloaditemlist[nowDownload - 1]->readyInstall();
downloaditemlist[nowDownload - 1]->free = true; QtConcurrent::run([=]()
emit downloadFinished();
if (nowDownload < allDownload)
{ {
// 如果有排队则下载下一个 while (downloaditemlist[nowDownload - 1]->readyInstall() == -1)
qDebug() << "切换下一个下载...";
nowDownload += 1;
while (downloaditemlist[nowDownload - 1]->close)
{ {
nowDownload += 1; continue;
if (nowDownload >= allDownload)
{
nowDownload = allDownload;
return;
}
} }
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) void DownloadListWidget::updateDataReadProgress(QString speedInfo, qint64 bytesRead, qint64 totalBytes)