Add presets for expire date.

Closes #44
This commit is contained in:
Florian Geyer 2012-08-15 22:47:41 +02:00
parent 6c695e3fd0
commit de1a94ff61
6 changed files with 180 additions and 10 deletions

View File

@ -39,6 +39,7 @@ set(keepassx_SOURCES
core/Metadata.cpp
core/qsavefile.cpp
core/SignalMultiplexer.cpp
core/TimeDelta.cpp
core/TimeInfo.cpp
core/Tools.cpp
core/Uuid.cpp

70
src/core/TimeDelta.cpp Normal file
View File

@ -0,0 +1,70 @@
/*
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "TimeDelta.h"
#include <QtCore/QDateTime>
QDateTime operator+(const QDateTime& dateTime, const TimeDelta& delta) {
return dateTime.addDays(delta.getDays())
.addMonths(delta.getMonths())
.addYears(delta.getYears());
}
TimeDelta TimeDelta::fromDays(int days)
{
return TimeDelta(days, 0, 0);
}
TimeDelta TimeDelta::fromMonths(int months)
{
return TimeDelta(0, months, 0);
}
TimeDelta TimeDelta::fromYears(int years)
{
return TimeDelta(0, 0, years);
}
TimeDelta::TimeDelta()
: m_days(0)
, m_months(0)
, m_years(0)
{
}
TimeDelta::TimeDelta(int days, int months, int years)
: m_days(days)
, m_months(months)
, m_years(years)
{
}
int TimeDelta::getDays() const
{
return m_days;
}
int TimeDelta::getMonths() const
{
return m_months;
}
int TimeDelta::getYears() const
{
return m_years;
}

50
src/core/TimeDelta.h Normal file
View File

@ -0,0 +1,50 @@
/*
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KEEPASSX_TIMEDELTA_H
#define KEEPASSX_TIMEDELTA_H
#include <QtCore/QMetaType>
class QDateTime;
class TimeDelta;
QDateTime operator+(const QDateTime& dateTime, const TimeDelta& delta);
class TimeDelta
{
public:
static TimeDelta fromDays(int days);
static TimeDelta fromMonths(int months);
static TimeDelta fromYears(int years);
TimeDelta();
TimeDelta(int days, int months, int years);
int getDays() const;
int getMonths() const;
int getYears() const;
private:
int m_days;
int m_months;
int m_years;
};
Q_DECLARE_METATYPE(TimeDelta)
#endif // KEEPASSX_TIMEDELTA_H

View File

@ -26,12 +26,14 @@
#include <QtGui/QDesktopServices>
#include <QtGui/QStackedLayout>
#include <QtGui/QMenu>
#include <QtGui/QMessageBox>
#include <QtGui/QSortFilterProxyModel>
#include "core/Database.h"
#include "core/Entry.h"
#include "core/Metadata.h"
#include "core/TimeDelta.h"
#include "core/Tools.h"
#include "gui/EditWidgetIcons.h"
#include "gui/FileDialog.h"
@ -150,6 +152,9 @@ EditEntryWidget::EditEntryWidget(QWidget* parent)
connect(m_historyUi->deleteButton, SIGNAL(clicked()), SLOT(deleteHistoryEntry()));
connect(m_historyUi->deleteAllButton, SIGNAL(clicked()), SLOT(deleteAllHistoryEntries()));
m_mainUi->expirePresets->setMenu(createPresetsMenu());
connect(m_mainUi->expirePresets->menu(), SIGNAL(triggered(QAction*)), this, SLOT(useExpiryPreset(QAction*)));
connect(this, SIGNAL(accepted()), SLOT(saveEntry()));
connect(this, SIGNAL(rejected()), SLOT(cancel()));
}
@ -195,6 +200,15 @@ void EditEntryWidget::updateHistoryButtons(const QModelIndex& current, const QMo
}
}
void EditEntryWidget::useExpiryPreset(QAction* action)
{
m_mainUi->expireCheck->setChecked(true);
TimeDelta delta = action->data().value<TimeDelta>();
QDateTime now = Tools::currentDateTimeUtc().toLocalTime();
QDateTime expiryDateTime = now + delta;
m_mainUi->expireDatePicker->setDateTime(expiryDateTime);
}
void EditEntryWidget::loadEntry(Entry* entry, bool create, bool history, const QString& groupName,
Database* database)
{
@ -259,6 +273,7 @@ void EditEntryWidget::setForms(const Entry* entry, bool restore)
setPasswordCheckColors();
m_mainUi->expireCheck->setChecked(entry->timeInfo().expires());
m_mainUi->expireDatePicker->setDateTime(entry->timeInfo().expiryTime().toLocalTime());
m_mainUi->expirePresets->setEnabled(!m_history);
m_mainUi->togglePasswordButton->setChecked(true);
m_notesUi->notesEdit->setPlainText(entry->notes());
@ -722,3 +737,20 @@ void EditEntryWidget::deleteAllHistoryEntries()
m_historyUi->deleteAllButton->setEnabled(false);
}
}
QMenu* EditEntryWidget::createPresetsMenu()
{
QMenu* expirePresetsMenu = new QMenu();
expirePresetsMenu->addAction(tr("Tomorrow"))->setData(QVariant::fromValue(TimeDelta::fromDays(1)));
expirePresetsMenu->addSeparator();
expirePresetsMenu->addAction(tr("1 week"))->setData(QVariant::fromValue(TimeDelta::fromDays(7)));
expirePresetsMenu->addAction(tr("2 weeks"))->setData(QVariant::fromValue(TimeDelta::fromDays(14)));
expirePresetsMenu->addAction(tr("3 weeks"))->setData(QVariant::fromValue(TimeDelta::fromDays(21)));
expirePresetsMenu->addSeparator();
expirePresetsMenu->addAction(tr("1 month"))->setData(QVariant::fromValue(TimeDelta::fromMonths(1)));
expirePresetsMenu->addAction(tr("3 months"))->setData(QVariant::fromValue(TimeDelta::fromMonths(3)));
expirePresetsMenu->addAction(tr("6 months"))->setData(QVariant::fromValue(TimeDelta::fromMonths(6)));
expirePresetsMenu->addSeparator();
expirePresetsMenu->addAction(tr("1 year"))->setData(QVariant::fromValue(TimeDelta::fromYears(1)));
return expirePresetsMenu;
}

View File

@ -34,6 +34,7 @@ class EntryAttributes;
class EntryAttributesModel;
class EntryHistoryModel;
class QButtonGroup;
class QMenu;
class QSortFilterProxyModel;
class QStackedLayout;
@ -60,6 +61,7 @@ public:
static const QColor CorrectSoFarColor;
static const QColor ErrorColor;
void createPresetsMenu(QMenu* expirePresetsMenu);
Q_SIGNALS:
void editFinished(bool accepted);
void historyEntryActivated(Entry* entry);
@ -89,10 +91,12 @@ private Q_SLOTS:
void emitHistoryEntryActivated(const QModelIndex& index);
void histEntryActivated(const QModelIndex& index);
void updateHistoryButtons(const QModelIndex& current, const QModelIndex& previous);
void useExpiryPreset(QAction* action);
private:
bool passwordsEqual();
void setForms(const Entry* entry, bool restore = false);
QMenu *createPresetsMenu();
Entry* m_entry;
Database* m_database;
@ -121,6 +125,7 @@ private:
AutoTypeAssociationsModel* const m_autoTypeAssocModel;
QButtonGroup* const m_autoTypeDefaultSequenceGroup;
QButtonGroup* const m_autoTypeWindowSequenceGroup;
QMenu* m_expirePresetsMenu;
Q_DISABLE_COPY(EditEntryWidget)
};

View File

@ -89,6 +89,27 @@
</property>
</widget>
</item>
<item row="5" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QDateTimeEdit" name="expireDatePicker">
<property name="enabled">
<bool>false</bool>
</property>
<property name="calendarPopup">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="expirePresets">
<property name="text">
<string>Presets</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="expireCheck">
<property name="text">
@ -96,16 +117,6 @@
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QDateTimeEdit" name="expireDatePicker">
<property name="enabled">
<bool>false</bool>
</property>
<property name="calendarPopup">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
@ -117,6 +128,7 @@
<tabstop>togglePasswordButton</tabstop>
<tabstop>expireCheck</tabstop>
<tabstop>expireDatePicker</tabstop>
<tabstop>expirePresets</tabstop>
</tabstops>
<resources/>
<connections/>