Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 12 hours expiration preset #7738

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions share/translations/keepassxc_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2537,10 +2537,6 @@ Would you like to correct it?</source>
<source>Hide</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Tomorrow</source>
<translation type="unfinished"></translation>
</message>
<message numerus="yes">
<source>%n week(s)</source>
<translation type="unfinished">
Expand All @@ -2562,6 +2558,13 @@ Would you like to correct it?</source>
<numerusform></numerusform>
</translation>
</message>
<message numerus="yes">
<source>%n hour(s)</source>
<translation type="unfinished">
<numerusform></numerusform>
<numerusform></numerusform>
</translation>
</message>
</context>
<context>
<name>EditEntryWidgetAdvanced</name>
Expand Down
29 changes: 22 additions & 7 deletions src/core/TimeDelta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,53 @@

QDateTime operator+(const QDateTime& dateTime, const TimeDelta& delta)
{
return dateTime.addDays(delta.getDays()).addMonths(delta.getMonths()).addYears(delta.getYears());
return dateTime.addSecs(delta.getHours() * 3600)
.addDays(delta.getDays())
.addMonths(delta.getMonths())
.addYears(delta.getYears());
}

TimeDelta TimeDelta::fromHours(int hours)
{
return TimeDelta(hours, 0, 0, 0);
}

TimeDelta TimeDelta::fromDays(int days)
{
return TimeDelta(days, 0, 0);
return TimeDelta(0, days, 0, 0);
}

TimeDelta TimeDelta::fromMonths(int months)
{
return TimeDelta(0, months, 0);
return TimeDelta(0, 0, months, 0);
}

TimeDelta TimeDelta::fromYears(int years)
{
return TimeDelta(0, 0, years);
return TimeDelta(0, 0, 0, years);
}

TimeDelta::TimeDelta()
: m_days(0)
: m_hours(0)
, m_days(0)
, m_months(0)
, m_years(0)
{
}

TimeDelta::TimeDelta(int days, int months, int years)
: m_days(days)
TimeDelta::TimeDelta(int hours, int days, int months, int years)
: m_hours(hours)
, m_days(days)
, m_months(months)
, m_years(years)
{
}

int TimeDelta::getHours() const
{
return m_hours;
}

int TimeDelta::getDays() const
{
return m_days;
Expand Down
5 changes: 4 additions & 1 deletion src/core/TimeDelta.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,21 @@ QDateTime operator+(const QDateTime& dateTime, const TimeDelta& delta);
class TimeDelta
{
public:
static TimeDelta fromHours(int hours);
static TimeDelta fromDays(int days);
static TimeDelta fromMonths(int months);
static TimeDelta fromYears(int years);

TimeDelta();
TimeDelta(int days, int months, int years);
TimeDelta(int hours, int days, int months, int years);

int getHours() const;
int getDays() const;
int getMonths() const;
int getYears() const;

private:
int m_hours;
int m_days;
int m_months;
int m_years;
Expand Down
3 changes: 2 additions & 1 deletion src/gui/entry/EditEntryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,8 @@ void EditEntryWidget::deleteAllHistoryEntries()
QMenu* EditEntryWidget::createPresetsMenu()
{
auto* expirePresetsMenu = new QMenu(this);
expirePresetsMenu->addAction(tr("Tomorrow"))->setData(QVariant::fromValue(TimeDelta::fromDays(1)));
expirePresetsMenu->addAction(tr("%n hour(s)", nullptr, 12))->setData(QVariant::fromValue(TimeDelta::fromHours(12)));
expirePresetsMenu->addAction(tr("%n hour(s)", nullptr, 24))->setData(QVariant::fromValue(TimeDelta::fromHours(24)));
expirePresetsMenu->addSeparator();
expirePresetsMenu->addAction(tr("%n week(s)", nullptr, 1))->setData(QVariant::fromValue(TimeDelta::fromDays(7)));
expirePresetsMenu->addAction(tr("%n week(s)", nullptr, 2))->setData(QVariant::fromValue(TimeDelta::fromDays(14)));
Expand Down