diff --git a/kerfuffle/propertiesdialog.h b/kerfuffle/propertiesdialog.h --- a/kerfuffle/propertiesdialog.h +++ b/kerfuffle/propertiesdialog.h @@ -30,7 +30,9 @@ #include "kerfuffle/archive_kerfuffle.h" +#include #include +#include namespace Kerfuffle { @@ -40,8 +42,18 @@ public: explicit PropertiesDialog(QWidget *parent, Archive *archive); + +private slots: + void slotShowSha1(); + void slotShowSha256(); + private: + QString calcHash(QCryptographicHash::Algorithm algorithm); + class PropertiesDialogUI *m_ui; + QByteArray m_byteArray; + QFuture m_futureCalcSha1; + QFuture m_futureCalcSha256; }; } diff --git a/kerfuffle/propertiesdialog.cpp b/kerfuffle/propertiesdialog.cpp --- a/kerfuffle/propertiesdialog.cpp +++ b/kerfuffle/propertiesdialog.cpp @@ -29,8 +29,10 @@ #include "ark_debug.h" #include "ui_propertiesdialog.h" +#include #include #include +#include #include #include @@ -80,6 +82,27 @@ break; } + QFile file(archive->fileName()); + + if (file.open(QIODevice::ReadOnly)) { + m_byteArray = file.readAll(); + file.close(); + + QCryptographicHash hashMD5(QCryptographicHash::Md5); + hashMD5.addData(m_byteArray); + m_ui->lblMD5->setText(QLatin1String(hashMD5.result().toHex())); + + QFutureWatcher *watchCalcSha1 = new QFutureWatcher; + connect(watchCalcSha1, SIGNAL(finished()), this, SLOT(slotShowSha1())); + m_futureCalcSha1 = QtConcurrent::run(this, &PropertiesDialog::calcHash, QCryptographicHash::Sha1); + watchCalcSha1->setFuture(m_futureCalcSha1); + + QFutureWatcher *watchCalcSha256 = new QFutureWatcher; + connect(watchCalcSha256, SIGNAL(finished()), this, SLOT(slotShowSha256())); + m_futureCalcSha256 = QtConcurrent::run(this, &PropertiesDialog::calcHash, QCryptographicHash::Sha256); + watchCalcSha256->setFuture(m_futureCalcSha256); + } + // Show an icon representing the mimetype of the archive. QIcon icon = QIcon::fromTheme(archive->mimeType().iconName()); m_ui->lblIcon->setPixmap(icon.pixmap(IconSize(KIconLoader::Desktop), IconSize(KIconLoader::Desktop))); @@ -90,5 +113,28 @@ setFixedSize(m_ui->size()); } +QString PropertiesDialog::calcHash(QCryptographicHash::Algorithm algorithm) { + + QCryptographicHash hash(algorithm); + hash.addData(m_byteArray); + + return QLatin1String(hash.result().toHex()); +} + +void PropertiesDialog::slotShowSha1() { + + m_ui->lblSHA1->setText(m_futureCalcSha1.result()); + m_ui->groupBox->adjustSize(); + m_ui->adjustSize(); + setFixedSize(m_ui->size()); +} + +void PropertiesDialog::slotShowSha256() { + + m_ui->lblSHA256->setText(m_futureCalcSha256.result()); + m_ui->groupBox->adjustSize(); + m_ui->adjustSize(); + setFixedSize(m_ui->size()); +} } diff --git a/kerfuffle/propertiesdialog.ui b/kerfuffle/propertiesdialog.ui --- a/kerfuffle/propertiesdialog.ui +++ b/kerfuffle/propertiesdialog.ui @@ -66,6 +66,13 @@ + + + + lblMimetype + + + @@ -178,10 +185,54 @@ - - + + - lblMimetype + MD5 hash: + + + + + + + + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + + + + + SHA-1 hash: + + + + + + + Calculating... + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + + + + + SHA-256 hash: + + + + + + + Calculating... + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse