-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainWindow.cpp
More file actions
97 lines (84 loc) · 3.05 KB
/
mainWindow.cpp
File metadata and controls
97 lines (84 loc) · 3.05 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
#include <mainWindow.h>
#include <Utils.h>
MainWindow::MainWindow() : QWidget()
{
setFixedSize(640, 480);
m_SelectPathText = new QLabel("Select folder path :");
m_SelectPathText->setGeometry(0, 0, 100, 20);
m_SelectedPath = new QLineEdit();
m_SelectedPath->setGeometry(100, 0, 400, 20);
m_button = new QPushButton("MyButton");
m_button->setCursor(Qt::PointingHandCursor);
m_button->setIcon(QIcon(":/icons/add_folder"));
m_checkSub = new QCheckBox("Include Sub-Folders?");
m_fileList = new QListWidget;
m_validate = new QPushButton("Generate hashes!");
//Layouts
m_gridLayout = new QGridLayout;
m_gridLayout->addWidget(m_SelectPathText, 0, 0);
m_gridLayout->addWidget(m_SelectedPath, 0, 1);
m_gridLayout->addWidget(m_button, 0, 2);
m_gridLayout->addWidget(m_checkSub, 1, 2);
m_confirm = new QHBoxLayout;
m_confirm->addWidget(m_validate);
m_vboxLayout = new QVBoxLayout;
m_vboxLayout->addLayout(m_gridLayout);
m_vboxLayout->addWidget(m_fileList);
m_vboxLayout->addLayout(m_confirm);
this->setLayout(m_vboxLayout);
// Result Window
m_formattedResult = new QTextBrowser;
m_windowResult = new QDialog(this);
m_windowResult->setFixedSize(800, 600);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(m_formattedResult);
m_windowResult->setLayout(layout);
//File loading test. Working now!
/*QDomDocument input;
Utils::loadFile("BuildDir.xml", input);
QMap<QString, QString> map;
Utils::generateMap(map, input);
QMapIterator<QString, QString> i(map);
while (i.hasNext()) {
i.next();
qDebug() << i.key() << ": " << i.value() << endl;
}*/
//SLOTS & SIGNALS
QObject::connect(m_button, SIGNAL(clicked()), this, SLOT(openFolderDialog()));
QObject::connect(m_validate, SIGNAL(clicked()), this, SLOT(generateHash()));
QObject::connect(m_checkSub, SIGNAL(clicked()), this, SLOT(updateList()));
}
void MainWindow::updateList()
{
if(m_lastSelectedDirectory != "")
{
fileList.clear();
m_fileList->clear();
(m_checkSub->isChecked() ? fileList << Utils::scanFolder(m_lastSelectedDirectory, true) : fileList << Utils::scanFolder(m_lastSelectedDirectory, false));
m_fileList->addItems(fileList);
}
}
void MainWindow::openFolderDialog()
{
//Update Last Selected Directory
m_lastSelectedDirectory = "";
QString result = QFileDialog::getExistingDirectory(this);
if(result != m_lastSelectedDirectory && result != "")
{
m_lastSelectedDirectory = result;
m_SelectedPath->setText(m_lastSelectedDirectory);
}
updateList();
};
void MainWindow::generateHash()
{
if(m_lastSelectedDirectory == "")
QMessageBox::warning(this, "Warning", "No folder selected");
else
{
QDomDocument output = Utils::generateXML(m_lastSelectedDirectory, m_checkSub->isChecked());
m_formattedResult->setText(output.toString());
m_windowResult->exec();
Utils::saveFile(m_lastSelectedDirectory.split("\\").last() + ".xml", output);
}
}