diff --git a/aptss-installer.pro b/aptss-installer.pro index 035c4a9..8a1cb81 100644 --- a/aptss-installer.pro +++ b/aptss-installer.pro @@ -9,10 +9,12 @@ CONFIG += c++17 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ + installdeb.cpp \ main.cpp \ mainwindow.cpp HEADERS += \ + installdeb.h \ mainwindow.h FORMS += \ @@ -27,3 +29,4 @@ CONFIG += embed_translations qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target +unix:!macx: LIBS += -lqtermwidget5 # 这一行让我查了好久 diff --git a/installdeb.cpp b/installdeb.cpp new file mode 100644 index 0000000..eaccbfe --- /dev/null +++ b/installdeb.cpp @@ -0,0 +1,44 @@ +#include "installdeb.h" +#include +#include +#include +#include + +InstallDEB::InstallDEB(QTermWidget *terminal, QMainWindow *mainWindow) +{ + this->terminal = terminal; + this->mainWindow = mainWindow; +} + +void InstallDEB::AddCommand(QString command){ + this->commandList.append(command); +} + +void InstallDEB::RunCommand(){ + this->terminal->setEnabled(true); + this->runStatus = true; + // 写入为 Bash 文件,方便执行 + QString commandCode = "#!/bin/bash\n"; + QString bashPath = "/tmp/deepin-wine-runner-aptss-installer-" + QString::number(QDateTime::currentMSecsSinceEpoch()) + ".sh"; + for(int i = 0; i < this->commandList.size(); i++){ + commandCode += this->commandList.at(i) + "\n"; + } + commandCode += "rm -rfv '" + bashPath + "'"; + QFile file(bashPath); + file.open(QFile::WriteOnly); + if(!file.isWritable()){ + throw "Can't write the file!"; + } + file.write(commandCode.toUtf8()); + file.close(); + system(("chmod +x '" + bashPath + "'").toUtf8()); // 赋予运行权限 + this->terminal->setColorScheme("DarkPastels"); + this->terminal->setShellProgram("/usr/bin/bash"); + this->terminal->setArgs(QStringList() << bashPath); + //this->terminal->setAutoClose(1); + this->terminal->setAutoFillBackground(1); + this->terminal->startShellProgram(); + QObject::connect(this->terminal, &QTermWidget::finished, this->mainWindow, [this](){ + QMessageBox::information(this->mainWindow, "A", "B"); + }); +} diff --git a/installdeb.h b/installdeb.h new file mode 100644 index 0000000..48831c3 --- /dev/null +++ b/installdeb.h @@ -0,0 +1,21 @@ +#ifndef INSTALLDEB_H +#define INSTALLDEB_H + +#include +#include +#include + +class InstallDEB +{ +public: + InstallDEB(QTermWidget *terminal, QMainWindow *mainWindow = NULL); + void AddCommand(QString command); + void RunCommand(); + QStringList commandList; +private: + QTermWidget *terminal; + QMainWindow *mainWindow = NULL; + bool runStatus; +}; + +#endif // INSTALLDEB_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 41a26bd..a63aec5 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,11 +1,15 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include "installdeb.h" +#include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); + } MainWindow::~MainWindow() @@ -13,3 +17,17 @@ MainWindow::~MainWindow() delete ui; } + +void MainWindow::on_installPath_clicked() +{ + QTermWidget *terminal = new QTermWidget(0); + terminal->setColorScheme("DarkPastels"); + terminal->setShellProgram("/usr/bin/bash"); + terminal->setArgs(QStringList() << "-c" << "gedit"); + connect(terminal, &QTermWidget::finished, this, [&, this](){QMessageBox::information(NULL, "提示", "系统安装完成"); }); + terminal->startShellProgram(); + + + ui->gridLayout->addWidget(terminal, 1, 0); +} + diff --git a/mainwindow.h b/mainwindow.h index 4643e32..57cd5cb 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -15,6 +15,9 @@ public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); +private slots: + void on_installPath_clicked(); + private: Ui::MainWindow *ui; }; diff --git a/mainwindow.ui b/mainwindow.ui index b232854..8ad743a 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -13,9 +13,24 @@ MainWindow - - - + + + + + + + + + + + 安装 + + + + + + +