-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
198 lines (144 loc) · 6.11 KB
/
mainwindow.cpp
File metadata and controls
198 lines (144 loc) · 6.11 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include <QtWidgets>
#include <QtDebug>
#include "droparea.h"
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
QWidget *widget = new QWidget;
configLabel = NULL;
dropArea = new DropArea(this);
configLabel = new QLabel("<b>Config file : </b>" + configFile);
configLabel->setTextFormat(Qt::RichText);
configLabel->setWordWrap(true);
configLabel->adjustSize();
launchButton = new QPushButton(tr("Launch"));
clearButton = new QPushButton(tr("Clear"));
// quitButton = new QPushButton(tr("Quit"));
buttonBox = new QDialogButtonBox;
buttonBox->addButton(launchButton, QDialogButtonBox::ActionRole);
buttonBox->addButton(clearButton, QDialogButtonBox::ActionRole);
//buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
//connect(quitButton, &QAbstractButton::pressed, this, &exit);
connect(clearButton, &QAbstractButton::pressed, dropArea, &DropArea::clear);
connect(launchButton, &QAbstractButton::pressed, dropArea, &DropArea::launch);
QVBoxLayout *mainLayout = new QVBoxLayout(widget);
mainLayout->addWidget(configLabel);
mainLayout->addWidget(dropArea);
mainLayout->addWidget(buttonBox);
// widget->setLayout(mainLayout);
createActions();
createMenus();
setLaunch(false);
setWindowTitle(tr("BatchGUI"));
resize(480, 480);
setCentralWidget(widget);
}
void MainWindow::clearConfigLabel() {
configFile = "";
if(configLabel != NULL) {
configLabel->setText("<b>Config file : </b>" + configFile);
}
}
void MainWindow::contextMenuEvent(QContextMenuEvent *event) {
QMenu menu(this);
menu.exec(event->globalPos());
}
void MainWindow::setLaunch(bool value){
launchButton->setEnabled(value);
}
void MainWindow::open() {
QString filename = QFileDialog::getOpenFileName(this, tr("Open File"), "./", tr("XML Files (*.xml)"));
if(filename == "")
return;
QFile file(filename);
bool errorFound = false;
//qWarning() << "Open" << endl;
if(file.open(QIODevice::ReadOnly)) {
qWarning() << "Reading the file" << endl;
QXmlStreamReader xml(&file);
configFile = file.fileName();
configLabel->setText("<b>Config file : </b> " + configFile);
xml.readNextStartElement(); // Go to the root element
QString name = xml.name().toString();
if (name == "root") { // Find the root
while (xml.readNextStartElement()) {
QString name2 = xml.name().toString();
if(name2 == "prog") {
QString out, exe, arg;
QXmlStreamAttributes attr = xml.attributes();
if(attr.hasAttribute("out")) {
out = attr.value("out").toString();
}
if(attr.hasAttribute("exe")) {
exe = attr.value("exe").toString();
}
if(attr.hasAttribute("arg")) {
arg = attr.value("arg").toString();
}
qWarning() << "parent :" << out << endl;
// Base program
Program *prog = NULL;
if(exe != "") {
prog = new Program(out, exe, arg);
}
int i = 1;
while(xml.readNextStartElement()) {
QString out2, exe2, arg2;
QString name3 = xml.name().toString();
if(name3 == "prog") {
QXmlStreamAttributes attr2 = xml.attributes();
if(attr2.hasAttribute("out")) {
out2 = attr2.value("out").toString();
}
if(attr2.hasAttribute("exe")) {
exe2 = attr2.value("exe").toString();
}
if(attr2.hasAttribute("arg")) {
arg2 = attr2.value("arg").toString();
}
//qWarning() << "child :" << out2 << endl;
if(exe2 != "") {
Program* lastProg = prog;
while(lastProg->getProgram() != NULL) {
lastProg = lastProg->getProgram();
}
qWarning() << "set next program " << i << " : " << out2 << ", " << exe2 << ", " << arg2 << endl;
lastProg->setProg(new Program(out2, exe2, arg2));
i++;
}
}
}
dropArea->addProgram(prog);
}
}
}
} else {
errorFound = true;
QMessageBox::warning(this, tr("BatchGUI"),tr("An error has occured when parsing the config file."));
//qWarning() << "Error reading file" << endl;
}
qWarning() << "end of the parsing XML" << endl;
setLaunch(!errorFound);
}
void MainWindow::about() {
QMessageBox::about(this, tr("About BatchGUI"),
tr("<div align=\"center\">The application <b>BatchGUI</b> is created by Glusoft.<br/>"
"<a href=\"http://glusoft.com/tuto/BatchGUI.php\">Official page</a></div>"));
}
void MainWindow::createActions()
{
openAct = new QAction(tr("&Open..."), this);
openAct->setShortcuts(QKeySequence::Open);
openAct->setStatusTip(tr("Open an existing file"));
connect(openAct, &QAction::triggered, this, &MainWindow::open);
aboutAct = new QAction(tr("&About"), this);
aboutAct->setStatusTip(tr("Show the application's About box"));
connect(aboutAct, &QAction::triggered, this, &MainWindow::about);
}
void MainWindow::createMenus() {
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(openAct);
helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(aboutAct);
}
MainWindow::~MainWindow() {
}