-
Notifications
You must be signed in to change notification settings - Fork 1
/
SimpleHasher.h
278 lines (233 loc) · 8.14 KB
/
SimpleHasher.h
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/*
File: SimpleHasher.h
Created on: 05/06/2016
Author: Felix de las Pozas Alvarez
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SIMPLEHASHER_H_
#define SIMPLEHASHER_H_
// Qt
#include "ui_SimpleHasher.h"
#include <QMainWindow>
#include <QtWinExtras/QWinTaskbarButton>
#include <QStyledItemDelegate>
#include <QTableWidgetItem>
// C++
#include <memory>
// Project
#include <Hash.h>
class ComputerThread;
class QPoint;
class QPainter;
class QStyleOptionViewItem;
class QModelItem;
/** \class SimpleHasher
* \brief Application main window class.
*
*/
class SimpleHasher
: public QMainWindow
, private Ui::SimpleHasherMainWindow
{
Q_OBJECT
public:
/** \brief SimpleHasher class constructor.
* \param[in] files list of files passed to the application as parameters.
* \param[in] parent pointer of the class parent of this one.
* \param[in] flags window flags.
*
*/
SimpleHasher(const QStringList &files, QWidget *parent = nullptr, Qt::WindowFlags flags = 0);
/** \brief SimpleHasher class virtual destructor.
*
*/
virtual ~SimpleHasher();
protected:
virtual void showEvent(QShowEvent *event) override;
virtual void closeEvent(QCloseEvent *event) override;
private slots:
/** \brief Shows the about dialog.
*
*/
void onAboutPressed();
/** \brief Launches the add files dialog and adds the files specified by the user to the table.
*
*/
void onAddFilesPressed();
/** \brief Removes the currently selected files from the table.
*
*/
void onRemoveFilePressed();
/** \brief Launches the computation thread.
*
*/
void onComputePressed();
/** \brief Cancels the computation thread.
*
*
*/
void onCancelPressed();
/** \brief Launches the select directory dialog and saves the computed hashes to the selected directory.
*
*/
void onSavePressed();
/** \brief Updates the GUI when a hash checkbox changes state.
*
*/
void onCheckBoxStateChanged();
/** \brief Updates the UI when the computation thread finishes.
*
*/
void onComputationFinished();
/** \brief Updates the UI with the value of the computed hash.
* \param[in] filename filename of the computed hash.
* \param[in] hash hash object pointer.
*
*/
void onHashComputed(const QString &filename, const Hash *hash);
/** \brief Updates the correspondent item in the table with the progress value.
* \param[in] filename filename of the computed hash.
* \param[in] hash hash object pointer.
* \param[in] value Progress value in [0,100]
*
*/
void onHashUpdated(const QString &filename, const Hash *hash, const int value);
/** \brief Copies the values of the selected hashes to the clipboard.
*
*/
void copyHashesToClipboard();
/** \brief Saves the values of the selected hashes to disk.
*
*/
void saveSelectedHashes();
/** \brief Shows the context menu if activated over a hash cell.
*
*/
void onContextMenuActivated(const QPoint &pos);
/** \brief Shows the configuration dialog.
*
*/
void onOptionsPressed();
private:
/** \class Mode
* \brief Enumeration of application operation mode.
*
*/
enum class Mode: char { GENERATE = 0, CHECK };
/** Settings strings. */
static QString STATE_MD5;
static QString STATE_SHA1;
static QString STATE_SHA224;
static QString STATE_SHA256;
static QString STATE_SHA384;
static QString STATE_SHA512;
static QString STATE_TIGER;
static QString GEOMETRY;
static QString OPTIONS_ONELINE;
static QString OPTIONS_UPPERCASE;
static QString OPTIONS_SPACES;
static QString THREADS_NUMBER;
/** \brief Helper method to load the application settings from the ini file.
*
*/
void loadSettings();
/** \brief Helper method to save the application settings to the ini file.
*
*/
void saveSettings();
/** \brief Helper method to create the contextual menu on application initialization.
*
*/
void createContextMenu();
/** \brief Helper method to connect GUI signals on application initialization.
*
*/
void connectSignals();
/** \brief Hides the progress bar and the cancel button. Disables the hash group.
*
*/
void hideProgress();
/** \brief Shows the progress bar and the cancel button. Enables the hash group.
*
*/
void showProgress();
/** \brief Helper method to load the information contained in the files passed as arguments to the application.
*
*/
void loadInformation();
/** \brief Returns a string that describes the type of hash detected in the file passed as argument.
* \param[in] file opened file object.
*
*/
const QString guessHash(QFile &file);
/** \brief Helper method to add a list of files to the table.
*
*/
void addFilesToTable(const QStringList &files);
Mode m_mode; /** operation mode. */
QStringList m_files; /** files in the table. */
std::shared_ptr<ComputerThread> m_thread; /** computer thread. */
bool m_spaces; /** true to divide the hashes with spaces. */
bool m_oneline; /** true to show the long hashes in one line. */
bool m_uppercase; /** true to show the hashes in uppercase. */
int m_threadsNum; /** number of simultaneous threads to compute hashes. */
QMap<QString, QMap<QString, HashSPtr>> m_results; /** maps files -> computed hashes. */
QStringList m_headers; /** list of column strings, just to avoid computing over and over.. */
std::shared_ptr<QMenu> m_menu; /** contextual menu for the table. */
QWinTaskbarButton *m_taskBarButton; /** task bar button widget. */
};
/** \class HashCellItem
* \brief Custom item for the hash table.
*
*/
class HashCellItem
: public QTableWidgetItem
{
public:
explicit HashCellItem(int type = Type)
: QTableWidgetItem(type)
{};
explicit HashCellItem(const QString &text, int type = Type)
: QTableWidgetItem(text, type)
{};
explicit HashCellItem(const QIcon &icon, const QString &text, int type = Type)
: QTableWidgetItem(icon, text, type)
{};
inline void setProgress(int value)
{
this->setData(Qt::UserRole, value);
}
};
/** \class HashCellDelegate
* \brief Custom item delegate to draw the progress of the hash computation over the item.
*
*/
class HashCellDelegate
: public QStyledItemDelegate
{
Q_OBJECT
public:
/** \brief HashCellDelegate class constructor.
* \param[in] parent Raw pointer of the widget parent of this delegate.
*
*/
explicit HashCellDelegate(QWidget *parent = nullptr)
: QStyledItemDelegate{parent}
{};
/** \brief HashCellDelegate class virtual destructor.
*
*/
virtual ~HashCellDelegate()
{};
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
};
#endif // SIMPLEHASHER_H_