Use search for showing expired entries on unlock

* Fix #8036 - use search interface to display expiring entries on first unlock.
This commit is contained in:
Jonathan White 2022-09-05 12:55:57 -04:00
parent ee55143c4a
commit de168959a5
3 changed files with 14 additions and 7 deletions

View File

@ -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();
@ -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"));
@ -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();

View File

@ -302,6 +302,7 @@ private:
// Search state
QScopedPointer<EntrySearcher> m_entrySearcher;
QString m_lastSearchText;
QString m_nextSearchLabelText;
bool m_searchLimitGroup;
// Autoreload

View File

@ -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");