Fix issues with HIBP report

* Show horizontal header in results table
* Correctly handle the case when there are no entries to analyze
* Make countToText static
This commit is contained in:
Jonathan White 2020-03-31 20:52:55 -04:00
parent f0709d187d
commit ab9856ee88
3 changed files with 17 additions and 13 deletions

View File

@ -76,9 +76,18 @@ void ReportsWidgetHibp::makeHibpTable()
{
// Reset the table
m_referencesModel->clear();
m_referencesModel->setHorizontalHeaderLabels(QStringList() << tr("Title") << tr("Path") << tr("Password exposed…"));
m_rowToEntry.clear();
// If there were no findings, display a motivational message
if (m_pwndPasswords.isEmpty() && m_error.isEmpty()) {
m_referencesModel->setHorizontalHeaderLabels(QStringList() << tr("Congratulations, no exposed passwords!"));
m_ui->stackedWidget->setCurrentIndex(1);
return;
}
// Standard header labels for found issues
m_referencesModel->setHorizontalHeaderLabels(QStringList() << tr("Title") << tr("Path") << tr("Password exposed…"));
// Search database for passwords that we've found so far
QList<QPair<const Entry*, int>> items;
for (const auto* entry : m_db->rootGroup()->entriesRecursive()) {
@ -120,14 +129,6 @@ void ReportsWidgetHibp::makeHibpTable()
row[0]->setForeground(QBrush(QColor("red")));
}
// If we're done and everything is good, display a motivational message
#ifdef WITH_XC_NETWORKING
if (m_downloader.passwordsRemaining() == 0 && m_pwndPasswords.isEmpty() && m_error.isEmpty()) {
m_referencesModel->clear();
m_referencesModel->setHorizontalHeaderLabels(QStringList() << tr("Congratulations, no exposed passwords!"));
}
#endif
m_ui->hibpTableView->resizeRowsToContents();
m_ui->stackedWidget->setCurrentIndex(1);
@ -182,6 +183,12 @@ void ReportsWidgetHibp::startValidation()
}
}
// Short circuit if we didn't actually add any passwords
if (m_downloader.passwordsToValidate() == 0) {
makeHibpTable();
return;
}
// Store the number of passwords we need to check for the progress bar
m_ui->progressBar->show();
m_ui->progressBar->setMaximum(m_downloader.passwordsToValidate());

View File

@ -62,7 +62,7 @@ public slots:
private:
void makeHibpTable();
void startValidation();
QString countToText(int count);
static QString countToText(int count);
QScopedPointer<Ui::ReportsWidgetHibp> m_ui;
QScopedPointer<QStandardItemModel> m_referencesModel;

View File

@ -135,9 +135,6 @@
<property name="sortingEnabled">
<bool>false</bool>
</property>
<attribute name="horizontalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>