/
mainwindow.cpp
219 lines (182 loc) · 4.15 KB
/
mainwindow.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
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#include "mainwindow.h"
#include "ui_mainwindow.h"
// global declarations
QString path;
QString type = "-hd";
QString format = "-mode=flat";
QString Size;
Ui_MainWindow mainWindow;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
// setup ui
ui->setupUi(this);
// set window name
setWindowTitle("bxui (A bximage GUI)");
}
MainWindow::~MainWindow()
{
delete ui;
}
// when exit is pressed
void MainWindow::on_Exit_clicked()
{
// exit
exit(0);
}
// when about is pressed
void MainWindow::on_About_clicked()
{
// declarations
QMessageBox About;
// set About properties and execute messagebox
About.setWindowTitle("About");
About.setText("bxUI\nv1.0\n(c)2012 @ioshomebrew (Beecher Adams)");
About.setStandardButtons(QMessageBox::Ok);
About.setDefaultButton(QMessageBox::Ok);
About.exec();
}
// when browse is pressed
void MainWindow::on_Browse_clicked()
{
// open file dialog
path = QFileDialog::getSaveFileName(this, "Save File", "", "Disk Image (*.img);;VMware Disk Image (*.vmdk);;Virtual Hard Disk(*.vhd)");
// print path
qDebug() << path;
// set path
ui->path->setText(path);
}
// when create is pressed
void MainWindow::on_Create_clicked()
{
// declarations
QMessageBox Finished;
QString Message;
QProcess bximage;
QStringList arguments;
int size2;
bool ok;
size_t BufSize = 1024;
char buf[BufSize];
QString currentPath;
// make size argument
size2 = Size.toInt(&ok, 10);
snprintf(buf, BufSize, "-size=%i", size2);
Size = QString::fromAscii(buf);
// put bximage arugments in arguments
arguments << type << format;
arguments << Size << "-q";
arguments << path;
// print arguments
for(int count = 0; count < 5; count++)
qDebug() << arguments[count];
// print current path
currentPath = QDir::currentPath();
qDebug() << currentPath;
// start bximage
bximage.setReadChannel(QProcess::StandardOutput);
bximage.setWorkingDirectory(QString(QDir::currentPath()));
bximage.start("bximage", arguments);
bximage.waitForStarted(-1);
// make messagebox
Message = path + QString(" has been created");
Finished.setWindowTitle("Finished");
Finished.setText(Message);
Finished.setIcon(QMessageBox::Information);
Finished.exec();
}
// when Type changed
void MainWindow::on_Type_currentIndexChanged(int index)
{
// change type
if(index == 0)
{
// change type to hd
type = "-hd";
// change format back to flat
ui->Format->setCurrentIndex(0);
// set format to flat
format = "-mode=flat";
// enable format box
ui->Format->setEnabled(true);
}
else
{
// change type to fd
type = "-fd";
// null out format
format = "";
// grey out format box
ui->Format->setEnabled(false);
}
// print type
qDebug() << type;
}
void MainWindow::on_Format_currentIndexChanged(int index)
{
// change type
switch(index)
{
case 0:
{
format = "-mode=flat";
}
break;
case 1:
{
format = "-mode=concat";
}
break;
case 2:
{
format = "-mode=sparse";
}
break;
case 3:
{
format = "-mode=vmware3";
}
break;
case 4:
{
format = "-mode=vmware4";
}
break;
case 5:
{
format = "-mode=undoable";
}
break;
case 6:
{
format = "-mode=growing";
}
break;
case 7:
{
format = "-mode=volatile";
}
break;
case 8:
{
format = "-mode=virtualpc";
}
break;
case 9:
{
format = "-mode=vvat";
}
break;
}
// print format
qDebug() << format;
}
// when text is changed
void MainWindow::on_size_textChanged(const QString &arg1)
{
// set size
Size = arg1;
// print size
qDebug() << Size;
}