From fa785e1745129c3c078752bc5b9a58653b706d0d Mon Sep 17 00:00:00 2001 From: Xavier Valls Date: Tue, 27 Apr 2021 17:56:39 +0200 Subject: [PATCH] allow automatic expiration date extension on pwd modification Addressed issue #2010 Creates a new Expiration Settings area in the Edit Entry widget, composed of the expiration date settings and a new optional feature that allows for automatic extension of the expiration date on password modification. --- src/gui/entry/EditEntryWidget.cpp | 17 ++- src/gui/entry/EditEntryWidget.h | 2 + src/gui/entry/EditEntryWidgetMain.ui | 164 +++++++++++++++++---------- 3 files changed, 124 insertions(+), 59 deletions(-) diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index df93c66f9..0b7f81163 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -168,7 +168,7 @@ void EditEntryWidget::setupMain() m_mainUi->urlEdit->enableVerifyMode(); #endif connect(m_mainUi->expireCheck, &QCheckBox::toggled, [&](bool enabled) { - m_mainUi->expireDatePicker->setEnabled(enabled); + m_mainUi->expirationBox->setEnabled(enabled); if (enabled) { m_mainUi->expireDatePicker->setDateTime(Clock::currentDateTime()); } @@ -178,6 +178,21 @@ void EditEntryWidget::setupMain() m_mainUi->expirePresets->setMenu(createPresetsMenu()); connect(m_mainUi->expirePresets->menu(), SIGNAL(triggered(QAction*)), this, SLOT(useExpiryPreset(QAction*))); + m_mainUi->extendPresets->setMenu(createPresetsMenu()); + connect(m_mainUi->extendPresets->menu(), &QMenu::triggered, this, [&](QAction* action) { + m_extensionOnPwUpdate = action->data().value(); + }); + connect(m_mainUi->autoExtendExpire, &QCheckBox::toggled, [&](bool enabled) { + m_mainUi->extendPresets->setEnabled(enabled); + }); + connect(m_mainUi->passwordEdit, &QLineEdit::textChanged, this, [&]() { + if (m_mainUi->extendPresets->isEnabled()) { + TimeDelta delta = m_extensionOnPwUpdate; + QDateTime now = Clock::currentDateTime(); + QDateTime expiryDateTime = now + delta; + m_mainUi->expireDatePicker->setDateTime(expiryDateTime); + } + }); } void EditEntryWidget::setupAdvanced() diff --git a/src/gui/entry/EditEntryWidget.h b/src/gui/entry/EditEntryWidget.h index e359d1029..c0abe6cb4 100644 --- a/src/gui/entry/EditEntryWidget.h +++ b/src/gui/entry/EditEntryWidget.h @@ -28,6 +28,7 @@ #include #include "config-keepassx.h" +#include "core/TimeDelta.h" #include "gui/EditWidget.h" class AutoTypeAssociations; @@ -162,6 +163,7 @@ private: QPointer m_entry; QSharedPointer m_db; + TimeDelta m_extensionOnPwUpdate; bool m_create; bool m_history; #ifdef WITH_XC_SSHAGENT diff --git a/src/gui/entry/EditEntryWidgetMain.ui b/src/gui/entry/EditEntryWidgetMain.ui index 07445261e..e028792e0 100644 --- a/src/gui/entry/EditEntryWidgetMain.ui +++ b/src/gui/entry/EditEntryWidgetMain.ui @@ -56,7 +56,7 @@ 8 - + @@ -99,7 +99,7 @@ - + @@ -129,45 +129,6 @@ - - - - 8 - - - - - false - - - Expiration field - - - true - - - - - - - - 0 - 0 - - - - Expiration Presets - - - Expiration presets - - - Presets - - - - - @@ -252,25 +213,112 @@ - - - - 0 + + + + Toggle expiration - - - - Toggle expiration - - - Toggle expiration - - - Expires: - - + + Toggle expiration + + + Configure an expiration date + + + + + + + false + + + Expiration settings + + + + + + 0 + + + + + + + 8 + + + + + Expiration field + + + true + + + + + + + + 0 + 0 + + + + Expiration Presets + + + Expiration presets + + + Presets + + + + + + + + + + + Toggle auto updating expiration + + + Toggle auto updating expiration date + + + Automatically extend expiration date on password modification by + + + + + + + false + + + + 0 + 0 + + + + Expiration extension Presets + + + Expiration extension presets + + + Time + + + + - + +