mirror of
https://gitee.com/gfdgd-xi/deep-wine-runner
synced 2025-12-14 02:52:03 +08:00
初步可以运行命令
This commit is contained in:
@@ -9,10 +9,12 @@ CONFIG += c++17
|
|||||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
installdeb.cpp \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
mainwindow.cpp
|
mainwindow.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
installdeb.h \
|
||||||
mainwindow.h
|
mainwindow.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
@@ -27,3 +29,4 @@ CONFIG += embed_translations
|
|||||||
qnx: target.path = /tmp/$${TARGET}/bin
|
qnx: target.path = /tmp/$${TARGET}/bin
|
||||||
else: unix:!android: target.path = /opt/$${TARGET}/bin
|
else: unix:!android: target.path = /opt/$${TARGET}/bin
|
||||||
!isEmpty(target.path): INSTALLS += target
|
!isEmpty(target.path): INSTALLS += target
|
||||||
|
unix:!macx: LIBS += -lqtermwidget5 # 这一行让我查了好久
|
||||||
|
|||||||
44
installdeb.cpp
Normal file
44
installdeb.cpp
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
#include "installdeb.h"
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QMainWindow>
|
||||||
|
|
||||||
|
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");
|
||||||
|
});
|
||||||
|
}
|
||||||
21
installdeb.h
Normal file
21
installdeb.h
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#ifndef INSTALLDEB_H
|
||||||
|
#define INSTALLDEB_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <qtermwidget5/qtermwidget.h>
|
||||||
|
#include <QMainWindow>
|
||||||
|
|
||||||
|
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
|
||||||
@@ -1,11 +1,15 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
#include "installdeb.h"
|
||||||
|
#include <qtermwidget5/qtermwidget.h>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@@ -13,3 +17,17 @@ MainWindow::~MainWindow()
|
|||||||
delete ui;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ public:
|
|||||||
MainWindow(QWidget *parent = nullptr);
|
MainWindow(QWidget *parent = nullptr);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void on_installPath_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,9 +13,24 @@
|
|||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>MainWindow</string>
|
<string>MainWindow</string>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="centralwidget"/>
|
<widget class="QWidget" name="centralwidget">
|
||||||
<widget class="QMenuBar" name="menubar"/>
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<widget class="QStatusBar" name="statusbar"/>
|
<item row="0" column="0">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="debPath"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="installPath">
|
||||||
|
<property name="text">
|
||||||
|
<string>安装</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|||||||
Reference in New Issue
Block a user