-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselectingaction.cpp
More file actions
executable file
·97 lines (88 loc) · 3.13 KB
/
Copy pathselectingaction.cpp
File metadata and controls
executable file
·97 lines (88 loc) · 3.13 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 "selectingaction.h"
#include "crc32.h"
#include <QFileSystemModel>
#include <QtGui>
#include <QBoxLayout>
#include <QHeaderView>
#include <QLabel>
#include <enumTypes.h>
SelectingAction::SelectingAction(QWidget *parent) :
QWidget(parent)
{
QLabel *label1 = new QLabel("Select algorithm:");
QLabel *label2 = new QLabel("Select files for creating/checking hash:");
getHashButton = new QPushButton("Get hash");
checkHashButton = new QPushButton("Check hash");
comboBox = new QComboBox();
QStringList stringList;
stringList << "md5" << "crc32" << "sha1";
comboBox->addItems(stringList);
fileSystemModel = new QFileSystemModel(this);
fileSystemModel->setRootPath("");
treeView = new QTreeView();
treeView->setModel(fileSystemModel);
treeView->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
treeView->header()->setStretchLastSection(true);
treeView->setAnimated(false);
treeView->setIndentation(20);
treeView->setSortingEnabled(true);
treeView->sortByColumn(0, Qt::AscendingOrder);
treeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
QVBoxLayout *vbox = new QVBoxLayout;
QHBoxLayout *hbox = new QHBoxLayout;
vbox->addWidget(label1);
vbox->addWidget(comboBox);
vbox->addWidget(label2);
vbox->addWidget(treeView);
hbox->addWidget(getHashButton);
hbox->addWidget(checkHashButton);
vbox->addLayout(hbox);
vbox->setAlignment(Qt::AlignTop);
setLayout(vbox);
setWindowTitle("Hashcount");
connect(getHashButton, SIGNAL(clicked()), this, SLOT(getHash()));
connect(checkHashButton, SIGNAL(clicked()), this, SLOT(checkHash()));
}
void SelectingAction::getHash()
{
QFileInfoList list = getSelectedFiles();
if(!list.empty())
emit createHashReady(list, WidgetType::hashView);
}
void SelectingAction::checkHash()
{
QFileInfoList list = getSelectedFiles();
if(list.count() == 1)
emit createHashReady(list, WidgetType::checkHashFile);
else if(list.count() > 1)
emit createHashReady(list, WidgetType::checkHashFiles);
}
QFileInfoList SelectingAction::getSelectedFiles()
{
algorithmType = comboBox->currentIndex();
QFileInfoList filesInfoList;
if(treeView->selectionModel()->hasSelection())
{
QModelIndexList indexList = treeView->selectionModel()->selectedRows();
foreach (QModelIndex index, indexList)
{
QFileInfo fileInfo = fileSystemModel->fileInfo(index);
if(fileInfo.isDir())
{
QDirIterator dirIIterator(fileInfo.absoluteFilePath(),QDirIterator::Subdirectories);
while (dirIIterator.hasNext())
{
dirIIterator.next();
if (QFileInfo(dirIIterator.filePath()).isFile())
filesInfoList.append(dirIIterator.fileInfo());
}
}
else filesInfoList.append(fileInfo);
}
}
return filesInfoList;
}
int SelectingAction::getAlgorithmType()
{
return algorithmType;
}