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
|
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFile>
#include <QFileDialog>
#include <QDateTime>
#include <QDebug>
#include <QScreen>
#include <QTimer>
#include "ThreadCalcHash.h"
#include "version.h"
MainWindow::MainWindow(QWidget *parent, int gostSupport) :
QMainWindow(parent),
ui(new Ui::MainWindow),
_gostSupport(gostSupport)
{
ui->setupUi(this);
this->setWindowTitle("QCalcFileHash v"+QString(VERSION)+" ("+QString(DATE_BUILD)+")");
changeShowCompareForm();
ui->label_6->setText("");
connect(ui->pushButton,SIGNAL(clicked(bool)),this,SLOT(close()));
connect(ui->pushButton_2,SIGNAL(clicked(bool)),this,SLOT(openfile()));
connect(ui->pushButton_3,SIGNAL(clicked(bool)),this,SLOT(calcHash()));
connect(ui->pushButton_4,SIGNAL(clicked(bool)),this,SLOT(changeShowCompareForm()));
connect(ui->lineEdit,SIGNAL(textChanged(QString)),this,SLOT(resultCompare()));
ui->comboBox->addItem("CRC-8",static_cast<int>(HASH_ALGORITHM::Crc8));
ui->comboBox->addItem("CRC-32",static_cast<int>(HASH_ALGORITHM::Crc32));
ui->comboBox->addItem("MD4",static_cast<int>(HASH_ALGORITHM::Md4));
ui->comboBox->addItem("MD5",static_cast<int>(HASH_ALGORITHM::Md5));
ui->comboBox->addItem("SHA-1",static_cast<int>(HASH_ALGORITHM::Sha1));
ui->comboBox->addItem("SHA-224",static_cast<int>(HASH_ALGORITHM::Sha224));
ui->comboBox->addItem("SHA-256",static_cast<int>(HASH_ALGORITHM::Sha256));
ui->comboBox->addItem("SHA-384",static_cast<int>(HASH_ALGORITHM::Sha384));
ui->comboBox->addItem("SHA-512",static_cast<int>(HASH_ALGORITHM::Sha512));
if (gostSupport){
ui->comboBox->addItem(tr("GOST R 34.11-94"),static_cast<int>(HASH_ALGORITHM::md_gost94));
ui->comboBox->addItem(tr("GOST R 34.11-2012 (256 bit)"),static_cast<int>(HASH_ALGORITHM::md_gost12_256));
ui->comboBox->addItem(tr("GOST R 34.11-2012 (512 bit)"),static_cast<int>(HASH_ALGORITHM::md_gost12_512));
}
ui->comboBox->setCurrentIndex(0);
ui->label->setText("");
ui->progressBar->setValue(0);
ui->progressBar->setEnabled(false);
QTimer::singleShot(100,[&](){
// move to center
this->move((qApp->primaryScreen()->size().width()-this->width())/2,(qApp->primaryScreen()->size().height()-this->height())/2);
});
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::setFilename(QString filename){
ui->label->setText(filename);
_filename=filename;
}
void MainWindow::setHash(QString hashName){
for (int i=0;i<ui->comboBox->count();i++){
if (ui->comboBox->itemText(i).toLower()==hashName.toLower()){
ui->comboBox->setCurrentIndex(i);
return;
}
}
}
void MainWindow::startCalc(){
emit calcHash();
}
void MainWindow::openfile(){
QString fileName = QFileDialog::getOpenFileName(this,tr("Open file"), "", tr("All Files (*)"));
if (fileName.size() <= 0) return;
ui->label->setText(fileName);
_filename=fileName;
ui->textEdit->setText("");
resultCompare();
}
void MainWindow::calcHashChangeValue(int value) {
ui->progressBar->setValue(value);
}
void MainWindow::calcHashResult(QString hash) {
ui->textEdit->setText(hash);
ui->progressBar->setValue(0);
ui->progressBar->setEnabled(false);
ui->pushButton_3->setEnabled(true);
resultCompare();
}
void MainWindow::changeShowCompareForm(){
if (ui->pushButton_4->isChecked()){
ui->label_6->setVisible(true);
ui->label_5->setVisible(true);
ui->lineEdit->setVisible(true);
}else{
ui->label_6->setVisible(false);
ui->label_5->setVisible(false);
ui->lineEdit->setVisible(false);
}
}
void MainWindow::calcHash(){
if (_filename.isEmpty()) return;
ui->progressBar->setValue(0);
ui->progressBar->setEnabled(true);
ui->textEdit->setText("");
ui->pushButton_3->setEnabled(false);
ThreadCalcHash *thCaclHash = new ThreadCalcHash();
thCaclHash->setFilename(_filename);
thCaclHash->setHashAlgorithm(HASH_ALGORITHM(ui->comboBox->currentData().toInt()));
connect(thCaclHash,SIGNAL(changeValue(int)),this,SLOT(calcHashChangeValue(int)));
connect(thCaclHash,SIGNAL(result(QString)),this,SLOT(calcHashResult(QString)));
thCaclHash->start();
}
void MainWindow::resultCompare(){
QString ourhash = ui->textEdit->toPlainText();
QString userhash = ui->lineEdit->text();
// if there is nothing to compare
if ( QString::compare(ourhash, "", Qt::CaseInsensitive) == 0 ||
QString::compare(userhash, "", Qt::CaseInsensitive) == 0 ) {
ui->label_6->setText("");
return;
}
if (QString::compare(ourhash, userhash, Qt::CaseInsensitive) == 0) {
ui->label_6->setText("<font color=\"#005500\">"+tr("equally")+"</font>");
}else{
ui->label_6->setText("<font color=\"#ff0000\">"+tr("different")+"</font>");
}
}
|