Skip to content

Commit

Permalink
Use search for showing expired entries on unlock
Browse files Browse the repository at this point in the history
* Fix keepassxreboot#8036 - use search interface to display expiring entries on first unlock.
  • Loading branch information
droidmonkey committed Sep 8, 2022
1 parent dfee597 commit e5bd5f3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,13 +1128,13 @@ void DatabaseWidget::loadDatabase(bool accepted)
// Only show expired entries if first unlock and option is enabled
if (m_groupBeforeLock.isNull() && config()->get(Config::GUI_ShowExpiredEntriesOnDatabaseUnlock).toBool()) {
int expirationOffset = config()->get(Config::GUI_ShowExpiredEntriesOnDatabaseUnlockOffsetDays).toInt();
if (expirationOffset <= 0) {
m_nextSearchLabelText = tr("Expired entries");
} else {
m_nextSearchLabelText =
tr("Entries expiring within %1 day(s)", "", expirationOffset).arg(expirationOffset);
}
requestSearch(QString("is:expired-%1").arg(expirationOffset));
QTimer::singleShot(150, this, [=] {
m_searchingLabel->setText(
expirationOffset == 0
? tr("Expired entries")
: tr("Entries expiring within %1 day(s)", "", expirationOffset).arg(expirationOffset));
});
}

m_groupBeforeLock = QUuid();
Expand Down Expand Up @@ -1426,7 +1426,10 @@ void DatabaseWidget::search(const QString& searchtext)
m_lastSearchText = searchtext;

// Display a label detailing our search results
if (!searchResult.isEmpty()) {
if (!m_nextSearchLabelText.isEmpty()) {
m_searchingLabel->setText(m_nextSearchLabelText);
m_nextSearchLabelText.clear();
} else if (!searchResult.isEmpty()) {
m_searchingLabel->setText(tr("Search Results (%1)").arg(searchResult.size()));
} else {
m_searchingLabel->setText(tr("No Results"));
Expand Down Expand Up @@ -1545,6 +1548,7 @@ void DatabaseWidget::endSearch()
m_searchingLabel->setText(tr("Searching…"));

m_lastSearchText.clear();
m_nextSearchLabelText.clear();

// Tell the search widget to clear
emit clearSearch();
Expand Down
1 change: 1 addition & 0 deletions src/gui/DatabaseWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ private slots:
// Search state
QScopedPointer<EntrySearcher> m_entrySearcher;
QString m_lastSearchText;
QString m_nextSearchLabelText;
bool m_searchLimitGroup;

// Autoreload
Expand Down
2 changes: 2 additions & 0 deletions tests/gui/TestGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ void TestGui::init()
config()->set(Config::Security_QuickUnlock, false);
// Disable atomic saves to prevent transient errors on some platforms
config()->set(Config::UseAtomicSaves, false);
// Disable showing expired entries on unlock
config()->set(Config::GUI_ShowExpiredEntriesOnDatabaseUnlock, false);

// Copy the test database file to the temporary file
auto origFilePath = QDir(KEEPASSX_TEST_DATA_DIR).absoluteFilePath("NewDatabase.kdbx");
Expand Down

0 comments on commit e5bd5f3

Please sign in to comment.