下载完成后自动更改按钮文案

This commit is contained in:
柚子 2022-12-09 11:33:48 +08:00 committed by uniartisan
parent f0604afcfc
commit 3fecd41c4f
3 changed files with 20 additions and 4 deletions

View File

@ -43,6 +43,9 @@ void AppIntoPage::clear()
void AppIntoPage::setDownloadWidget(DownloadListWidget *w) void AppIntoPage::setDownloadWidget(DownloadListWidget *w)
{ {
dw=w; dw=w;
connect(w, &DownloadListWidget::downloadFinished, [=]() {
isDownloading();
});
} }
void AppIntoPage::openUrl(QUrl url) void AppIntoPage::openUrl(QUrl url)
{ {
@ -126,7 +129,7 @@ void AppIntoPage::openUrl(QUrl url)
} }
else else
{ {
ui->downloadButton->setText(tr("Install")); ui->downloadButton->setText(tr("Download"));
ui->downloadButton->setEnabled(true); ui->downloadButton->setEnabled(true);
ui->downloadButton->show(); ui->downloadButton->show();
} }
@ -180,7 +183,7 @@ void AppIntoPage::isDownloading()
switch (dw->isDownloading(SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString())) { switch (dw->isDownloading(SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString())) {
case 3:{ case 3:{
ui->downloadButton->setEnabled(true); ui->downloadButton->setEnabled(true);
ui->downloadButton->setText(tr("Install")); ui->downloadButton->setText(tr("Download"));
break; break;
} }
case 1:{ case 1:{
@ -262,6 +265,10 @@ AppIntoPage::~AppIntoPage()
void AppIntoPage::on_downloadButton_clicked() void AppIntoPage::on_downloadButton_clicked()
{ {
dw->addItem(info["Name"].toString(),info["Filename"].toString(),info["Pkgname"].toString(),iconpixmap,SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString()); dw->addItem(info["Name"].toString(),info["Filename"].toString(),info["Pkgname"].toString(),iconpixmap,SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString());
if(ui->downloadButton->text() == tr("Reinstall"))
{
dw->getDIList()[dw->allDownload - 1]->reinstall = true;
}
isDownloading(); isDownloading();
} }

View File

@ -96,6 +96,11 @@ void DownloadListWidget::addItem(QString name,QString fileName,QString pkgName,c
} }
} }
QList<DownloadItem *> DownloadListWidget::getDIList()
{
return downloaditemlist;
}
void DownloadListWidget::startRequest(QUrl url, QString fileName) void DownloadListWidget::startRequest(QUrl url, QString fileName)
{ {
ui->listWidget->show(); ui->listWidget->show();
@ -117,6 +122,7 @@ void DownloadListWidget::httpFinished() // 完成下载
isBusy = false; isBusy = false;
downloaditemlist[nowDownload - 1]->readyInstall(); downloaditemlist[nowDownload - 1]->readyInstall();
downloaditemlist[nowDownload - 1]->free = true; downloaditemlist[nowDownload - 1]->free = true;
emit downloadFinished();
if(nowDownload < allDownload) if(nowDownload < allDownload)
{ {

View File

@ -22,13 +22,14 @@ class DownloadListWidget : public DBlurEffectWidget
public: public:
void addItem(QString name, QString fileName, QString pkgName, const QPixmap icon, QString downloadurl); void addItem(QString name, QString fileName, QString pkgName, const QPixmap icon, QString downloadurl);
int isDownloading(QString url); int isDownloading(QString url);
int nowDownload = 0;
int allDownload = 0;
QList<DownloadItem *> getDIList();
void m_move(int x, int y); void m_move(int x, int y);
explicit DownloadListWidget(QWidget *parent = nullptr); explicit DownloadListWidget(QWidget *parent = nullptr);
~DownloadListWidget(); ~DownloadListWidget();
private: private:
int nowDownload = 0;
int allDownload = 0;
int isdownload = false; int isdownload = false;
bool isBusy = false; bool isBusy = false;
QStringList dlist; QStringList dlist;
@ -51,6 +52,8 @@ private slots:
bool eventFilter(QObject *, QEvent *); bool eventFilter(QObject *, QEvent *);
void mouseMoveEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event);
void on_pushButton_clicked(); void on_pushButton_clicked();
signals:
void downloadFinished();
}; };
#endif // DOWNLOADLISTWIDGET_H #endif // DOWNLOADLISTWIDGET_H