From 43915ec670e4fad9aa1253a69ab9c212fb16d5a5 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Sat, 11 Jan 2025 23:42:14 -0500 Subject: [PATCH] Code cleanup --- share/translations/keepassxc_en.ts | 8 +++---- src/core/Entry.cpp | 6 +++++ src/core/Entry.h | 1 + src/gui/DatabaseWidget.cpp | 24 ++++--------------- src/gui/DatabaseWidget.h | 1 - src/gui/GuiTools.cpp | 14 ----------- src/gui/GuiTools.h | 1 - src/gui/MainWindow.ui | 3 +-- .../ReportsWidgetBrowserStatistics.cpp | 6 ++--- src/gui/reports/ReportsWidgetHealthcheck.cpp | 6 ++--- src/gui/reports/ReportsWidgetHibp.cpp | 5 ++-- 11 files changed, 24 insertions(+), 51 deletions(-) diff --git a/share/translations/keepassxc_en.ts b/share/translations/keepassxc_en.ts index 11612309d9..ed4effabc9 100644 --- a/share/translations/keepassxc_en.ts +++ b/share/translations/keepassxc_en.ts @@ -5950,10 +5950,6 @@ Expect some bugs and minor issues, this version is meant for testing purposes.Import Passkey - - &Expire Entry… - - Remote S&ync… @@ -6226,6 +6222,10 @@ Expect some bugs and minor issues, this version is meant for testing purposes.Password Generator + + E&xpire Entry… + + ManageDatabase diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index 9587e8d67e..1acf663818 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -460,6 +460,12 @@ bool Entry::willExpireInDays(int days) const return m_data.timeInfo.expires() && m_data.timeInfo.expiryTime() < Clock::currentDateTime().addDays(days); } +void Entry::expireNow() +{ + setExpiryTime(Clock::currentDateTimeUtc()); + setExpires(true); +} + bool Entry::isRecycled() const { const Database* db = database(); diff --git a/src/core/Entry.h b/src/core/Entry.h index 749a9fe542..3fb3fbcbbc 100644 --- a/src/core/Entry.h +++ b/src/core/Entry.h @@ -126,6 +126,7 @@ class Entry : public ModifiableObject bool hasTotp() const; bool isExpired() const; bool willExpireInDays(int days) const; + void expireNow(); bool isRecycled() const; bool isAttributeReference(const QString& key) const; bool isAttributeReferenceOf(const QString& key, const QUuid& uuid) const; diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index ed9d5a8981..2b4266c907 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -572,17 +572,12 @@ void DatabaseWidget::setupTotp() void DatabaseWidget::expireSelectedEntries() { const QModelIndexList selected = m_entryView->selectionModel()->selectedRows(); - if (selected.isEmpty()) { - return; - } - - // Resolve entries from the selection model - QList selectedEntries; - for (const QModelIndex& index : selected) { - selectedEntries.append(m_entryView->entryFromIndex(index)); + for (const auto& index : selected) { + auto entry = m_entryView->entryFromIndex(index); + if (entry) { + entry->expireNow(); + } } - - expireEntries(std::move(selectedEntries)); } void DatabaseWidget::deleteSelectedEntries() @@ -621,15 +616,6 @@ void DatabaseWidget::restoreSelectedEntries() } } -void DatabaseWidget::expireEntries(QList selectedEntries) -{ - if (selectedEntries.isEmpty()) { - return; - } - - GuiTools::expireEntries(this, selectedEntries); -} - void DatabaseWidget::deleteEntries(QList selectedEntries, bool confirm) { if (selectedEntries.isEmpty()) { diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index 7b6a267b81..1e85dd312c 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -183,7 +183,6 @@ public slots: void expireSelectedEntries(); void deleteSelectedEntries(); void restoreSelectedEntries(); - void expireEntries(QList entries); void deleteEntries(QList entries, bool confirm = true); void focusOnEntries(bool editIfFocused = false); void focusOnGroups(bool editIfFocused = false); diff --git a/src/gui/GuiTools.cpp b/src/gui/GuiTools.cpp index 1c6437b595..b2dfa63f3a 100644 --- a/src/gui/GuiTools.cpp +++ b/src/gui/GuiTools.cpp @@ -17,7 +17,6 @@ #include "GuiTools.h" -#include "core/Clock.h" #include "core/Config.h" #include "core/Group.h" #include "gui/MessageBox.h" @@ -82,19 +81,6 @@ namespace GuiTools return answer == MessageBox::Delete; } - size_t expireEntries(QWidget* parent, const QList& entries) - { - if (!parent || entries.isEmpty()) { - return 0; - } - - for (auto entry : asConst(entries)) { - entry->setExpiryTime(Clock::currentDateTimeUtc()); - entry->setExpires(true); - } - return entries.size(); - } - size_t deleteEntriesResolveReferences(QWidget* parent, const QList& entries, bool permanent) { if (!parent || entries.isEmpty()) { diff --git a/src/gui/GuiTools.h b/src/gui/GuiTools.h index 133f6a0370..c5e7108964 100644 --- a/src/gui/GuiTools.h +++ b/src/gui/GuiTools.h @@ -27,7 +27,6 @@ namespace GuiTools { bool confirmDeleteEntries(QWidget* parent, const QList& entries, bool permanent); bool confirmDeletePluginData(QWidget* parent, const QList& entries); - size_t expireEntries(QWidget* parent, const QList& entries); size_t deleteEntriesResolveReferences(QWidget* parent, const QList& entries, bool permanent); } // namespace GuiTools #endif // KEEPASSXC_GUITOOLS_H diff --git a/src/gui/MainWindow.ui b/src/gui/MainWindow.ui index 292ab3aa0b..c84727c3e8 100644 --- a/src/gui/MainWindow.ui +++ b/src/gui/MainWindow.ui @@ -430,7 +430,6 @@ - @@ -551,7 +550,7 @@ false - &Expire Entry… + E&xpire Entry… diff --git a/src/gui/reports/ReportsWidgetBrowserStatistics.cpp b/src/gui/reports/ReportsWidgetBrowserStatistics.cpp index 6d00ac769d..63267d77fd 100644 --- a/src/gui/reports/ReportsWidgetBrowserStatistics.cpp +++ b/src/gui/reports/ReportsWidgetBrowserStatistics.cpp @@ -347,11 +347,9 @@ QList ReportsWidgetBrowserStatistics::getSelectedEntries() void ReportsWidgetBrowserStatistics::expireSelectedEntries() { - QList selectedEntries = getSelectedEntries(); - if (selectedEntries.isEmpty()) { - return; + for (auto entry : getSelectedEntries()) { + entry->expireNow(); } - GuiTools::expireEntries(this, selectedEntries); calculateBrowserStatistics(); } diff --git a/src/gui/reports/ReportsWidgetHealthcheck.cpp b/src/gui/reports/ReportsWidgetHealthcheck.cpp index 7baffe25e2..f6151dda43 100644 --- a/src/gui/reports/ReportsWidgetHealthcheck.cpp +++ b/src/gui/reports/ReportsWidgetHealthcheck.cpp @@ -385,11 +385,9 @@ QList ReportsWidgetHealthcheck::getSelectedEntries() void ReportsWidgetHealthcheck::expireSelectedEntries() { - QList selectedEntries = getSelectedEntries(); - if (selectedEntries.isEmpty()) { - return; + for (auto entry : getSelectedEntries()) { + entry->expireNow(); } - GuiTools::expireEntries(this, selectedEntries); calculateHealth(); } diff --git a/src/gui/reports/ReportsWidgetHibp.cpp b/src/gui/reports/ReportsWidgetHibp.cpp index 9fa7e9b6c8..a559208aaa 100644 --- a/src/gui/reports/ReportsWidgetHibp.cpp +++ b/src/gui/reports/ReportsWidgetHibp.cpp @@ -431,8 +431,9 @@ QList ReportsWidgetHibp::getSelectedEntries() void ReportsWidgetHibp::expireSelectedEntries() { - QList selectedEntries = getSelectedEntries(); - GuiTools::expireEntries(this, selectedEntries); + for (auto entry : getSelectedEntries()) { + entry->expireNow(); + } makeHibpTable(); }