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

@ -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;

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

@ -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)