-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
42 lines (38 loc) · 1.51 KB
/
MainWindow.cpp
File metadata and controls
42 lines (38 loc) · 1.51 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
#include "MainWindow.hpp"
#include "ui_MainWindow.h"
#include <QLineEdit>
#include <QCheckBox>
#include <QCryptographicHash>
#include <QComboBox>
#include "CRC32.hpp"
#include "CRC64.hpp"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),
m_ui(new Ui::MainWindow()) {
m_ui->setupUi(this);
}
MainWindow::~MainWindow() {
delete m_ui;
}
void MainWindow::onTextChanged(QString str) {
if (!str.isEmpty()) {
std::string val = (m_ui->addPrefixCheckbox->isChecked() ? "$/" : "") +
(m_ui->toLowerCheckbox->isChecked() ? str.toLower() : str).toStdString();
QString result;
if (m_ui->comboBox->currentText().toLower() == "crc32") {
result = tr("%1").arg(CRC32::Calculate(val.c_str(), val.length()), 8, 16, QLatin1Char('0'));
} else if (m_ui->comboBox->currentText().toLower() == "crc64") {
uint64_t sum = CRC64::Calculate(val.c_str(), val.length());
result = tr("%1 (%2)").arg(sum, 16, 16, QLatin1Char('0')).arg(sum);
} else if (m_ui->comboBox->currentText().toLower() == "md5") {
QByteArray tmp = QCryptographicHash::hash(QByteArray::fromStdString(val),
QCryptographicHash::Algorithm::Md5);
result = tmp.mid(8).toHex();
}
m_ui->resultLineEdit->setText(result.toUpper());
} else
m_ui->resultLineEdit->clear();
}
void MainWindow::onCheckStateChanged() {
onTextChanged(m_ui->pathLineEdit->text());
}