Skip to content

Commit

Permalink
Statistics panel: Show warning icon for problematic values (keepassxr…
Browse files Browse the repository at this point in the history
  • Loading branch information
wolframroesler committed Sep 20, 2019
1 parent 823fbf2 commit cebdc43
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions src/gui/dbsettings/DatabaseSettingsWidgetStatistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "ui_DatabaseSettingsWidgetStatistics.h"

#include "core/Database.h"
#include "core/FilePath.h"
#include "core/Group.h"
#include "core/Metadata.h"

Expand Down Expand Up @@ -66,6 +67,28 @@ namespace
return ret;
}

// A warning sign is displayed if one of the
// following returns true.
bool expiredBad() const
{
return nExpired > 0;
}

bool reuseBad() const
{
return nPwdsReused > nPwdsUnique / 10;
}

bool maxReuseBad() const
{
return maxPwdReuse() > 3;
}

bool avgLenBad() const
{
return pwdAvgLen() < 10;
}

private:
std::map<QString, int> pwds_;

Expand Down Expand Up @@ -128,26 +151,32 @@ void DatabaseSettingsWidgetStatistics::loadSettings(QSharedPointer<Database> db)
m_referencesModel.reset(new QStandardItemModel());
m_referencesModel->setHorizontalHeaderLabels(QStringList() << tr("Name") << tr("Value"));

const auto show = [this](QString name, QString value) {
auto errIcon = FilePath::instance()->icon("status", "dialog-error");

const auto show = [this, &errIcon](QString name, QString value, bool bad = false) {
auto row = QList<QStandardItem*>();
row << new QStandardItem(name);
row << new QStandardItem(value);
m_referencesModel->appendRow(row);

if (bad) {
m_referencesModel->item(m_referencesModel->rowCount() - 1, 1)->setIcon(errIcon);
}
};

const auto stats = Stats(*db);
show(tr("Database name"), db->metadata()->name());
show(tr("Description"), db->metadata()->description());
show(tr("Location"), db->filePath());
show(tr("Last saved"), stats.modified.toString(Qt::DefaultLocaleShortDate));
show(tr("Unsaved changes"), db->isModified() ? tr("YES") : tr("no"));
show(tr("Unsaved changes"), db->isModified() ? tr("yes") : tr("no"), db->isModified());
show(tr("Number of groups"), QString("%L1").arg(stats.nGroups));
show(tr("Number of entries"), QString("%L1").arg(stats.nEntries));
show(tr("Number of expired entries"), QString("%L1").arg(stats.nExpired));
show(tr("Number of expired entries"), QString("%L1").arg(stats.nExpired), stats.expiredBad());
show(tr("Unique passwords"), QString("%L1").arg(stats.nPwdsUnique));
show(tr("Non-unique passwords"), QString("%L1").arg(stats.nPwdsReused));
show(tr("Maximum password reuse"), QString("%L1").arg(stats.maxPwdReuse()));
show(tr("Average password length"), QString("%L1").arg(stats.pwdAvgLen()));
show(tr("Non-unique passwords"), QString("%L1").arg(stats.nPwdsReused), stats.reuseBad());
show(tr("Maximum password reuse"), QString("%L1").arg(stats.maxPwdReuse()), stats.maxReuseBad());
show(tr("Average password length"), QString("%L1").arg(stats.pwdAvgLen()), stats.avgLenBad());

m_ui->sharedGroupsView->setModel(m_referencesModel.data());
m_ui->sharedGroupsView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
Expand Down

0 comments on commit cebdc43

Please sign in to comment.