From 25456a413c95475f1060540e8fbafd1f8e6fde89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=A4=A9=E6=80=BF?= Date: Mon, 3 Aug 2020 18:25:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E2=80=9C=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E5=AE=89=E8=A3=85=E2=80=9D=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加手动安装按钮来处理部分 gdebi 无法正确安装的应用(主要是 wine 应用)。 --- downloadlist.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++++--- downloadlist.h | 4 +-- downloadlist.ui | 35 +++++++++++++++++---- 3 files changed, 108 insertions(+), 13 deletions(-) diff --git a/downloadlist.cpp b/downloadlist.cpp index da74bb7..3cfb976 100644 --- a/downloadlist.cpp +++ b/downloadlist.cpp @@ -17,6 +17,7 @@ downloadlist::downloadlist(QWidget *parent) : ui->progressBar->setValue(0); ui->label_filename->hide(); ui->pushButton_install->hide(); + ui->pushButton_maninst->hide(); ui->pushButton_3->hide(); ui->widget_spinner->start(); ui->widget_spinner->hide(); @@ -133,15 +134,16 @@ void downloadlist::on_pushButton_install_clicked() ui->pushButton_3->show(); }else { ui->pushButton_install->show(); - ui->pushButton_install->show(); + ui->pushButton_maninst->show(); ui->pushButton_install->setText("重装"); + ui->pushButton_maninst->setText("手动重装"); ui->label_2->setText("安装出现错误,可重新安装"); ui->pushButton_3->show(); } if(notRoot){ ui->label_2->setText("安装被终止,可重新安装"); ui->pushButton_install->show(); - ui->pushButton_install->show(); + ui->pushButton_maninst->show(); ui->pushButton_3->hide(); } ui->widget_spinner->hide(); @@ -154,6 +156,80 @@ void downloadlist::on_pushButton_install_clicked() } +void downloadlist::on_pushButton_maninst_clicked() +{ + if(!isInstall) + { + isInstall = true; + ui->pushButton_install->hide(); + ui->pushButton_maninst->hide(); + ui->widget_spinner->show(); + qDebug() << "/tmp/spark-store/" + ui->label_filename->text().toUtf8(); + ui->label_2->setText("正在安装,请稍候"); + QtConcurrent::run([=]() + { + QProcess installer; + if(reinstall) + { + installer.start("pkexec apt reinstall /tmp/spark-store/" + ui->label_filename->text().toUtf8()); + } + else + { + installer.start("pkexec apt install /tmp/spark-store/" + ui->label_filename->text().toUtf8()); + } + installer.waitForFinished(); + out = installer.readAllStandardOutput(); + installer.close(); + QStringList everyOut = out.split("\n"); + bool haveError = false; + bool notRoot = false; + for (int i = 0; i < everyOut.size(); i++) + { + qDebug() << everyOut[i].left(2); + if(everyOut[i].left(2) == "E:") + { + haveError = true; + } + if(everyOut[i].right(14) == "Not authorized") + { + notRoot = true; + } + } + QProcess isInstall; + isInstall.start("dpkg -s " + pkgName); + isInstall.waitForFinished(); + int error = QString::fromStdString(isInstall.readAllStandardError().toStdString()).length(); + isInstall.close(); + if(error == 0) + { + ui->pushButton_install->hide(); + ui->pushButton_maninst->hide(); + ui->label_2->setText("安装完成"); + ui->pushButton_3->show(); + } + else + { + ui->pushButton_install->show(); + ui->pushButton_maninst->show(); + ui->pushButton_install->setText("重装"); + ui->pushButton_maninst->setText("手动重装"); + ui->label_2->setText("安装出现错误,可重新安装"); + ui->pushButton_3->show(); + } + if(notRoot) + { + ui->label_2->setText("安装被终止,可重新安装"); + ui->pushButton_install->show(); + ui->pushButton_maninst->show(); + ui->pushButton_3->hide(); + } + ui->widget_spinner->hide(); + downloadlist::isInstall = false; + }); + qDebug() << ui->label_filename->text().toUtf8(); + } +} + void downloadlist::on_pushButton_2_clicked() { ui->label_2->setText("已取消下载"); @@ -164,8 +240,6 @@ void downloadlist::on_pushButton_2_clicked() void downloadlist::on_pushButton_3_clicked() { - - output_w.layout()->addWidget(textbrowser); textbrowser->setLineWidth(0); textbrowser->setText(out); diff --git a/downloadlist.h b/downloadlist.h index f085044..c119aa1 100644 --- a/downloadlist.h +++ b/downloadlist.h @@ -35,10 +35,8 @@ public: QString pkgName; private slots: void on_pushButton_install_clicked(); - + void on_pushButton_maninst_clicked(); void on_pushButton_2_clicked(); - - void on_pushButton_3_clicked(); private: diff --git a/downloadlist.ui b/downloadlist.ui index 75a7dca..dce9186 100644 --- a/downloadlist.ui +++ b/downloadlist.ui @@ -6,7 +6,7 @@ 0 0 - 729 + 776 54 @@ -54,6 +54,22 @@ + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + @@ -71,7 +87,7 @@ - 100 + 80 0 @@ -92,7 +108,7 @@ - + Qt::Horizontal @@ -101,7 +117,7 @@ - 40 + 20 20 @@ -181,7 +197,7 @@ - + Qt::Horizontal @@ -200,12 +216,19 @@ - 60 + 30 0 + + + + 手动安转 + + +