| 33 | } |
| 34 | |
| 35 | void FileInfoWidget::addHashField( |
| 36 | const QString& hashName, const QCryptographicHash::Algorithm& algorithm, const QByteArray& data) |
| 37 | { |
| 38 | auto& [row, column] = this->m_fieldPosition; |
| 39 | |
| 40 | const auto hashFieldColor = getThemeColor(AlphanumericHighlightColor); |
| 41 | auto hashLabel = new CopyableLabel("Calculating...", hashFieldColor); |
| 42 | hashLabel->setFont(getMonospaceFont(this)); |
| 43 | |
| 44 | this->m_layout->addWidget(new QLabel(hashName), row, column); |
| 45 | this->m_layout->addWidget(hashLabel, row++, column + 1); |
| 46 | |
| 47 | // Process the hash calculations in a separate thread and update the label when done |
| 48 | QPointer<QFutureWatcher<QByteArray>> watcher = new QFutureWatcher<QByteArray>(this); |
| 49 | connect(watcher, &QFutureWatcher<QByteArray>::finished, this, [watcher, hashLabel]() { |
| 50 | if (watcher) |
| 51 | { |
| 52 | hashLabel->setText(watcher->result().toHex()); |
| 53 | watcher->deleteLater(); |
| 54 | } |
| 55 | }); |
| 56 | QFuture<QByteArray> future = QtConcurrent::run([data, algorithm]() { |
| 57 | return QCryptographicHash::hash(data, algorithm); |
| 58 | }); |
| 59 | watcher->setFuture(future); |
| 60 | connect(this, &QObject::destroyed, this, [watcher]() { |
| 61 | if (watcher && watcher->isRunning()) { |
| 62 | watcher->cancel(); |
| 63 | watcher->waitForFinished(); |
| 64 | } |
| 65 | }); |
| 66 | } |
| 67 | |
| 68 | FileInfoWidget::FileInfoWidget(QWidget* parent, BinaryViewRef bv) |
| 69 | { |
no test coverage detected