Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
droidmonkey committed Jan 12, 2025
1 parent 5860e3e commit 43915ec
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 51 deletions.
8 changes: 4 additions & 4 deletions share/translations/keepassxc_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5950,10 +5950,6 @@ Expect some bugs and minor issues, this version is meant for testing purposes.</
<source>Import Passkey</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&amp;Expire Entry…</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Remote S&amp;ync…</source>
<translation type="unfinished"></translation>
Expand Down Expand Up @@ -6226,6 +6222,10 @@ Expect some bugs and minor issues, this version is meant for testing purposes.</
<source>Password Generator</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>E&amp;xpire Entry…</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ManageDatabase</name>
Expand Down
6 changes: 6 additions & 0 deletions src/core/Entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/core/Entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 5 additions & 19 deletions src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Entry*> 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()
Expand Down Expand Up @@ -621,15 +616,6 @@ void DatabaseWidget::restoreSelectedEntries()
}
}

void DatabaseWidget::expireEntries(QList<Entry*> selectedEntries)
{
if (selectedEntries.isEmpty()) {
return;
}

GuiTools::expireEntries(this, selectedEntries);
}

void DatabaseWidget::deleteEntries(QList<Entry*> selectedEntries, bool confirm)
{
if (selectedEntries.isEmpty()) {
Expand Down
1 change: 0 additions & 1 deletion src/gui/DatabaseWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ public slots:
void expireSelectedEntries();
void deleteSelectedEntries();
void restoreSelectedEntries();
void expireEntries(QList<Entry*> entries);
void deleteEntries(QList<Entry*> entries, bool confirm = true);
void focusOnEntries(bool editIfFocused = false);
void focusOnGroups(bool editIfFocused = false);
Expand Down
14 changes: 0 additions & 14 deletions src/gui/GuiTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include "GuiTools.h"

#include "core/Clock.h"
#include "core/Config.h"
#include "core/Group.h"
#include "gui/MessageBox.h"
Expand Down Expand Up @@ -82,19 +81,6 @@ namespace GuiTools
return answer == MessageBox::Delete;
}

size_t expireEntries(QWidget* parent, const QList<Entry*>& 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<Entry*>& entries, bool permanent)
{
if (!parent || entries.isEmpty()) {
Expand Down
1 change: 0 additions & 1 deletion src/gui/GuiTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ namespace GuiTools
{
bool confirmDeleteEntries(QWidget* parent, const QList<Entry*>& entries, bool permanent);
bool confirmDeletePluginData(QWidget* parent, const QList<Entry*>& entries);
size_t expireEntries(QWidget* parent, const QList<Entry*>& entries);
size_t deleteEntriesResolveReferences(QWidget* parent, const QList<Entry*>& entries, bool permanent);
} // namespace GuiTools
#endif // KEEPASSXC_GUITOOLS_H
3 changes: 1 addition & 2 deletions src/gui/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@
<addaction name="separator"/>
<addaction name="actionEntryNew"/>
<addaction name="actionEntryEdit"/>
<addaction name="actionEntryExpire"/>
<addaction name="actionEntryDelete"/>
<addaction name="separator"/>
<addaction name="actionEntryCopyUsername"/>
Expand Down Expand Up @@ -551,7 +550,7 @@
<bool>false</bool>
</property>
<property name="text">
<string>&amp;Expire Entry…</string>
<string>E&amp;xpire Entry…</string>
</property>
</action>
<action name="actionEntryDelete">
Expand Down
6 changes: 2 additions & 4 deletions src/gui/reports/ReportsWidgetBrowserStatistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,9 @@ QList<Entry*> ReportsWidgetBrowserStatistics::getSelectedEntries()

void ReportsWidgetBrowserStatistics::expireSelectedEntries()
{
QList<Entry*> selectedEntries = getSelectedEntries();
if (selectedEntries.isEmpty()) {
return;
for (auto entry : getSelectedEntries()) {
entry->expireNow();
}
GuiTools::expireEntries(this, selectedEntries);

calculateBrowserStatistics();
}
Expand Down
6 changes: 2 additions & 4 deletions src/gui/reports/ReportsWidgetHealthcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,9 @@ QList<Entry*> ReportsWidgetHealthcheck::getSelectedEntries()

void ReportsWidgetHealthcheck::expireSelectedEntries()
{
QList<Entry*> selectedEntries = getSelectedEntries();
if (selectedEntries.isEmpty()) {
return;
for (auto entry : getSelectedEntries()) {
entry->expireNow();
}
GuiTools::expireEntries(this, selectedEntries);

calculateHealth();
}
Expand Down
5 changes: 3 additions & 2 deletions src/gui/reports/ReportsWidgetHibp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,9 @@ QList<Entry*> ReportsWidgetHibp::getSelectedEntries()

void ReportsWidgetHibp::expireSelectedEntries()
{
QList<Entry*> selectedEntries = getSelectedEntries();
GuiTools::expireEntries(this, selectedEntries);
for (auto entry : getSelectedEntries()) {
entry->expireNow();
}

makeHibpTable();
}
Expand Down

0 comments on commit 43915ec

Please sign in to comment.