-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialog.cpp
74 lines (59 loc) · 1.61 KB
/
dialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "dialog.h"
#include "ui_dialog.h"
#include <QString>
#include <QProcess>
Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog)
{
// setup ui
ui->setupUi(this);
// connect signal/slots
connect(ui->makeButton, SIGNAL(pressed()), this, SLOT(make()));
connect(ui->insmodButton, SIGNAL(pressed()), this, SLOT(insmod()));
connect(ui->rmmodButton, SIGNAL(pressed()), this, SLOT(rmmod()));
connect(ui->readButton, SIGNAL(pressed()), this, SLOT(read()));
connect(ui->clearButton, SIGNAL(pressed()), this, SLOT(clear()));
}
void Dialog::run(const QString &command)
{
QProcess *process;
QTextEdit *outputText;
process = new QProcess();
outputText = ui->outputText;
outputText->insertPlainText("$ " + command + "\n");
connect(process, &QProcess::readyReadStandardOutput, [process,outputText]() {
outputText->insertPlainText(process->readAllStandardOutput());
});
connect(process, &QProcess::readyReadStandardError, [process,outputText]() {
outputText->insertPlainText(process->readAllStandardError());
});
connect(process, static_cast<void (QProcess::*)(int)>(&QProcess::finished), [process, outputText](int) {
outputText->insertPlainText(process->readAllStandardOutput());
outputText->insertPlainText(process->readAllStandardError());
delete process;
});
process->start(command);
}
void Dialog::make()
{
run("make all");
}
void Dialog::insmod()
{
run("insmod falcon.ko");
}
void Dialog::rmmod()
{
run("rmmod falcon");
}
void Dialog::read()
{
run("cat /dev/falcon1");
}
void Dialog::clear()
{
ui->outputText->clear();
}
Dialog::~Dialog()
{
delete ui;
}