Repository navigation
Expand file tree
/
Copy pathhashlistmanager.cpp
More file actions
108 lines (97 loc) · 3.43 KB
/
Copy pathhashlistmanager.cpp
File metadata and controls
108 lines (97 loc) · 3.43 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
#include "hashlistmanager.h"
// Copyright 2013-2020 Pasquale J. Rinaldi, Jr.
// Distrubted under the terms of the GNU General Public License version 2
HashListManager::HashListManager(QWidget* parent) : QDialog(parent), ui(new Ui::HashListManager)
{
ui->setupUi(this);
this->hide();
connect(ui->closebutton, SIGNAL(clicked()), this, SLOT(HideClicked()));
connect(ui->importbutton, SIGNAL(clicked()), this, SLOT(ImportHashList()));
connect(ui->createbutton, SIGNAL(clicked()), this, SLOT(CreateHashList()));
connect(ui->deletebutton, SIGNAL(clicked()), this, SLOT(DeleteSelectedList()));
connect(ui->hashlistwidget, SIGNAL(itemSelectionChanged()), this, SLOT(SelectionChanged()));
ui->deletebutton->setEnabled(false);
UpdateList();
}
HashListManager::~HashListManager()
{
delete ui;
this->close();
}
void HashListManager::HideClicked()
{
emit HideHashListManager();
this->close();
}
void HashListManager::closeEvent(QCloseEvent* e)
{
emit HideHashListManager();
e->accept();
}
void HashListManager::ImportHashList()
{
//qDebug() << "import hash list here.";
QStringList files = QFileDialog::getOpenFileNames(this, "Select one or more files to import", QDir::homePath(), "Wombat Hash Lists (*.whl)");
for(int i=0; i < files.count(); i++)
{
QFile tmpfile(files.at(i));
tmpfile.copy(wombatvariable.tmpmntpath + "hashlists/" + files.at(i).split("/").last());
}
UpdateList();
emit ReadHashLists();
}
void HashListManager::CreateHashList()
{
QString emptyfilename = "";
QInputDialog* newdialog = new QInputDialog(this);
newdialog->setCancelButtonText("Cancel");
newdialog->setInputMode(QInputDialog::TextInput);
newdialog->setLabelText("Enter Hash List Name");
newdialog->setOkButtonText("Create Empty List");
newdialog->setTextEchoMode(QLineEdit::Normal);
newdialog->setWindowTitle("Create Empty Wombat Hash List");
if(newdialog->exec())
emptyfilename = newdialog->textValue();
if(!emptyfilename.isEmpty())
{
//qDebug() << "Create Empty Hash List.";
if(!emptyfilename.endsWith(".whl"))
emptyfilename = emptyfilename + ".whl";
QFile tmpfile(wombatvariable.tmpmntpath + "hashlists/" + emptyfilename);
tmpfile.open(QIODevice::WriteOnly | QIODevice::Text);
tmpfile.close();
ui->hashlistwidget->addItem(emptyfilename);
}
emit ReadHashLists();
}
void HashListManager::DeleteSelectedList()
{
QListWidgetItem* curitem = ui->hashlistwidget->takeItem(ui->hashlistwidget->currentRow());
QFile tmphashlistfile(wombatvariable.tmpmntpath + "hashlists/" + curitem->text());
tmphashlistfile.remove();
delete curitem;
emit ReadHashLists();
}
/*
void HashListManager::ShowBrowser()
{
fileviewerpath = QFileDialog::getOpenFileName(this, tr("Select Viewer Executable"), QDir::homePath(), "", NULL, QFileDialog::DontUseNativeDialog);
if(!fileviewerpath.isNull())
{
ui->lineEdit->setText(fileviewerpath);
ui->addbutton->setEnabled(true);
}
}
*/
void HashListManager::SelectionChanged()
{
ui->deletebutton->setEnabled(true);
}
void HashListManager::UpdateList()
{
ui->hashlistwidget->clear();
QDir hashdir(wombatvariable.tmpmntpath + "hashlists/");
QFileInfoList whllist = hashdir.entryInfoList(QStringList() << "*.whl", QDir::Files);
for(int i=0; i < whllist.count(); i++)
ui->hashlistwidget->addItem(whllist.at(i).fileName());
}