2010-08-07 09:10:44 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 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 "Metadata.h"
|
|
|
|
|
2011-07-08 08:51:14 -04:00
|
|
|
#include "core/Database.h"
|
2012-04-18 15:59:00 -04:00
|
|
|
#include "core/Entry.h"
|
2012-04-21 17:54:15 -04:00
|
|
|
#include "core/Group.h"
|
2012-05-09 14:29:21 -04:00
|
|
|
#include "core/Tools.h"
|
2010-08-13 12:08:06 -04:00
|
|
|
|
2010-08-24 17:12:01 -04:00
|
|
|
Metadata::Metadata(Database* parent)
|
|
|
|
: QObject(parent)
|
2011-11-13 08:54:11 -05:00
|
|
|
, m_parent(parent)
|
2010-08-07 09:10:44 -04:00
|
|
|
{
|
2011-07-07 06:52:30 -04:00
|
|
|
m_generator = "KeePassX";
|
|
|
|
m_maintenanceHistoryDays = 365;
|
|
|
|
m_recycleBinEnabled = true;
|
|
|
|
m_masterKeyChangeRec = -1;
|
|
|
|
m_masterKeyChangeForce = -1;
|
2012-05-10 07:15:43 -04:00
|
|
|
m_historyMaxItems = defaultHistoryMaxItems;
|
|
|
|
m_historyMaxSize = defaultHistoryMaxSize;
|
2011-07-07 06:52:30 -04:00
|
|
|
|
2012-05-09 14:29:21 -04:00
|
|
|
QDateTime now = Tools::currentDateTimeUtc();
|
2011-06-29 10:47:05 -04:00
|
|
|
m_nameChanged = now;
|
|
|
|
m_descriptionChanged = now;
|
|
|
|
m_defaultUserNameChanged = now;
|
|
|
|
m_recycleBinChanged = now;
|
|
|
|
m_entryTemplatesGroupChanged = now;
|
|
|
|
m_masterKeyChanged = now;
|
2011-07-06 17:44:29 -04:00
|
|
|
|
|
|
|
m_protectTitle = false;
|
|
|
|
m_protectUsername = false;
|
|
|
|
m_protectPassword = true;
|
|
|
|
m_protectUrl = false;
|
|
|
|
m_protectNotes = false;
|
2012-04-21 10:45:46 -04:00
|
|
|
// m_autoEnableVisualHiding = false;
|
2012-04-11 09:57:11 -04:00
|
|
|
|
|
|
|
m_updateDatetime = true;
|
|
|
|
}
|
|
|
|
|
2012-05-10 07:15:43 -04:00
|
|
|
const int Metadata::defaultHistoryMaxItems = 10;
|
|
|
|
const int Metadata::defaultHistoryMaxSize = 6291456;
|
|
|
|
|
2012-04-21 17:54:15 -04:00
|
|
|
template <class P, class V> bool Metadata::set(P& property, const V& value)
|
|
|
|
{
|
2012-04-11 09:57:11 -04:00
|
|
|
if (property != value) {
|
|
|
|
property = value;
|
|
|
|
Q_EMIT modified();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-21 17:54:15 -04:00
|
|
|
template <class P, class V> bool Metadata::set(P& property, const V& value, QDateTime& dateTime) {
|
2012-04-11 09:57:11 -04:00
|
|
|
if (property != value) {
|
|
|
|
property = value;
|
|
|
|
if (m_updateDatetime) {
|
2012-05-09 14:29:21 -04:00
|
|
|
dateTime = Tools::currentDateTimeUtc();
|
2012-04-11 09:57:11 -04:00
|
|
|
}
|
|
|
|
Q_EMIT modified();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setUpdateDatetime(bool value) {
|
|
|
|
m_updateDatetime = value;
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Metadata::generator() const
|
|
|
|
{
|
|
|
|
return m_generator;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
QString Metadata::name() const
|
|
|
|
{
|
|
|
|
return m_name;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
QDateTime Metadata::nameChanged() const
|
|
|
|
{
|
|
|
|
return m_nameChanged;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
QString Metadata::description() const
|
|
|
|
{
|
|
|
|
return m_description;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
QDateTime Metadata::descriptionChanged() const
|
|
|
|
{
|
|
|
|
return m_descriptionChanged;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
QString Metadata::defaultUserName() const
|
|
|
|
{
|
|
|
|
return m_defaultUserName;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
QDateTime Metadata::defaultUserNameChanged() const
|
|
|
|
{
|
|
|
|
return m_defaultUserNameChanged;
|
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
int Metadata::maintenanceHistoryDays() const
|
|
|
|
{
|
|
|
|
return m_maintenanceHistoryDays;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2012-04-21 10:45:46 -04:00
|
|
|
QColor Metadata::color() const
|
|
|
|
{
|
|
|
|
return m_color;
|
|
|
|
}
|
|
|
|
|
2010-08-07 09:10:44 -04:00
|
|
|
bool Metadata::protectTitle() const
|
|
|
|
{
|
|
|
|
return m_protectTitle;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
bool Metadata::protectUsername() const
|
|
|
|
{
|
|
|
|
return m_protectUsername;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
bool Metadata::protectPassword() const
|
|
|
|
{
|
|
|
|
return m_protectPassword;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
bool Metadata::protectUrl() const
|
|
|
|
{
|
|
|
|
return m_protectUrl;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
bool Metadata::protectNotes() const
|
|
|
|
{
|
|
|
|
return m_protectNotes;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2012-04-21 10:45:46 -04:00
|
|
|
/*bool Metadata::autoEnableVisualHiding() const
|
2010-08-07 09:10:44 -04:00
|
|
|
{
|
|
|
|
return m_autoEnableVisualHiding;
|
2012-04-21 10:45:46 -04:00
|
|
|
}*/
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2012-01-01 15:52:54 -05:00
|
|
|
QImage Metadata::customIcon(const Uuid& uuid) const
|
2010-09-19 15:22:24 -04:00
|
|
|
{
|
|
|
|
return m_customIcons.value(uuid);
|
|
|
|
}
|
|
|
|
|
2012-04-27 05:22:02 -04:00
|
|
|
bool Metadata::containsCustomIcon(const Uuid& uuid) const
|
|
|
|
{
|
|
|
|
return m_customIcons.contains(uuid);
|
|
|
|
}
|
|
|
|
|
2012-01-01 15:52:54 -05:00
|
|
|
QHash<Uuid, QImage> Metadata::customIcons() const
|
2010-08-07 09:10:44 -04:00
|
|
|
{
|
|
|
|
return m_customIcons;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2012-05-13 14:50:41 -04:00
|
|
|
QList<Uuid> Metadata::customIconsOrder() const
|
|
|
|
{
|
|
|
|
return m_customIconsOrder;
|
|
|
|
}
|
|
|
|
|
2010-08-07 09:10:44 -04:00
|
|
|
bool Metadata::recycleBinEnabled() const
|
|
|
|
{
|
|
|
|
return m_recycleBinEnabled;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2012-04-18 17:17:29 -04:00
|
|
|
Group* Metadata::recycleBin()
|
|
|
|
{
|
|
|
|
return m_recycleBin;
|
|
|
|
}
|
|
|
|
|
2010-08-13 12:08:06 -04:00
|
|
|
const Group* Metadata::recycleBin() const
|
2010-08-07 09:10:44 -04:00
|
|
|
{
|
2010-08-13 12:08:06 -04:00
|
|
|
return m_recycleBin;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
QDateTime Metadata::recycleBinChanged() const
|
|
|
|
{
|
|
|
|
return m_recycleBinChanged;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2010-08-13 12:08:06 -04:00
|
|
|
const Group* Metadata::entryTemplatesGroup() const
|
2010-08-07 09:10:44 -04:00
|
|
|
{
|
|
|
|
return m_entryTemplatesGroup;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
QDateTime Metadata::entryTemplatesGroupChanged() const
|
|
|
|
{
|
|
|
|
return m_entryTemplatesGroupChanged;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2010-08-13 12:08:06 -04:00
|
|
|
const Group* Metadata::lastSelectedGroup() const
|
2010-08-07 09:10:44 -04:00
|
|
|
{
|
|
|
|
return m_lastSelectedGroup;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2010-08-13 12:08:06 -04:00
|
|
|
const Group* Metadata::lastTopVisibleGroup() const
|
2010-08-07 09:10:44 -04:00
|
|
|
{
|
|
|
|
return m_lastTopVisibleGroup;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2010-09-25 06:41:00 -04:00
|
|
|
QDateTime Metadata::masterKeyChanged() const
|
|
|
|
{
|
|
|
|
return m_masterKeyChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Metadata::masterKeyChangeRec() const
|
|
|
|
{
|
|
|
|
return m_masterKeyChangeRec;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Metadata::masterKeyChangeForce() const
|
|
|
|
{
|
|
|
|
return m_masterKeyChangeForce;
|
|
|
|
}
|
|
|
|
|
2012-04-21 10:45:46 -04:00
|
|
|
int Metadata::historyMaxItems() const
|
|
|
|
{
|
|
|
|
return m_historyMaxItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Metadata::historyMaxSize() const
|
|
|
|
{
|
|
|
|
return m_historyMaxSize;
|
|
|
|
}
|
|
|
|
|
2010-08-07 09:10:44 -04:00
|
|
|
QHash<QString, QString> Metadata::customFields() const
|
|
|
|
{
|
|
|
|
return m_customFields;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
void Metadata::setGenerator(const QString& value)
|
|
|
|
{
|
2012-04-11 09:57:11 -04:00
|
|
|
set(m_generator, value);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setName(const QString& value)
|
|
|
|
{
|
2012-04-11 09:57:11 -04:00
|
|
|
if (set(m_name, value, m_nameChanged)) {
|
|
|
|
Q_EMIT nameTextChanged(m_parent);
|
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setNameChanged(const QDateTime& value)
|
|
|
|
{
|
|
|
|
m_nameChanged = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setDescription(const QString& value)
|
|
|
|
{
|
2012-04-11 09:57:11 -04:00
|
|
|
set(m_description, value, m_descriptionChanged);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setDescriptionChanged(const QDateTime& value)
|
|
|
|
{
|
|
|
|
m_descriptionChanged = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setDefaultUserName(const QString& value)
|
|
|
|
{
|
2012-04-11 09:57:11 -04:00
|
|
|
set(m_defaultUserName, value, m_defaultUserNameChanged);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
void Metadata::setDefaultUserNameChanged(const QDateTime& value)
|
|
|
|
{
|
|
|
|
m_defaultUserNameChanged = value;
|
|
|
|
}
|
|
|
|
|
2010-08-07 09:10:44 -04:00
|
|
|
void Metadata::setMaintenanceHistoryDays(int value)
|
|
|
|
{
|
2012-04-11 09:57:11 -04:00
|
|
|
set(m_maintenanceHistoryDays, value);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
2012-04-21 10:45:46 -04:00
|
|
|
void Metadata::setColor(const QColor& value)
|
|
|
|
{
|
|
|
|
set(m_color, value);
|
|
|
|
}
|
|
|
|
|
2010-08-07 09:10:44 -04:00
|
|
|
void Metadata::setProtectTitle(bool value)
|
|
|
|
{
|
2012-04-11 09:57:11 -04:00
|
|
|
set(m_protectTitle, value);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setProtectUsername(bool value)
|
|
|
|
{
|
2012-04-11 09:57:11 -04:00
|
|
|
set(m_protectUsername, value);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setProtectPassword(bool value)
|
|
|
|
{
|
2012-04-11 09:57:11 -04:00
|
|
|
set(m_protectPassword, value);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setProtectUrl(bool value)
|
|
|
|
{
|
2012-04-11 09:57:11 -04:00
|
|
|
set(m_protectUrl, value);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setProtectNotes(bool value)
|
|
|
|
{
|
2012-04-11 09:57:11 -04:00
|
|
|
set(m_protectNotes, value);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
2012-04-21 10:45:46 -04:00
|
|
|
/*void Metadata::setAutoEnableVisualHiding(bool value)
|
2010-08-07 09:10:44 -04:00
|
|
|
{
|
2012-04-11 09:57:11 -04:00
|
|
|
set(m_autoEnableVisualHiding, value);
|
2012-04-21 10:45:46 -04:00
|
|
|
}*/
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2012-01-01 15:52:54 -05:00
|
|
|
void Metadata::addCustomIcon(const Uuid& uuid, const QImage& icon)
|
2010-08-07 09:10:44 -04:00
|
|
|
{
|
2010-08-13 12:08:06 -04:00
|
|
|
Q_ASSERT(!uuid.isNull());
|
2010-08-07 09:10:44 -04:00
|
|
|
Q_ASSERT(!m_customIcons.contains(uuid));
|
|
|
|
|
2010-09-19 15:22:24 -04:00
|
|
|
m_customIcons.insert(uuid, icon);
|
2012-05-13 14:50:41 -04:00
|
|
|
m_customIconsOrder.append(uuid);
|
|
|
|
Q_ASSERT(m_customIcons.count() == m_customIconsOrder.count());
|
2012-04-11 09:57:11 -04:00
|
|
|
Q_EMIT modified();
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::removeCustomIcon(const Uuid& uuid)
|
|
|
|
{
|
2010-08-13 12:08:06 -04:00
|
|
|
Q_ASSERT(!uuid.isNull());
|
2010-08-07 09:10:44 -04:00
|
|
|
Q_ASSERT(m_customIcons.contains(uuid));
|
|
|
|
|
|
|
|
m_customIcons.remove(uuid);
|
2012-05-13 14:50:41 -04:00
|
|
|
m_customIconsOrder.removeAll(uuid);
|
|
|
|
Q_ASSERT(m_customIcons.count() == m_customIconsOrder.count());
|
2012-04-11 09:57:11 -04:00
|
|
|
Q_EMIT modified();
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setRecycleBinEnabled(bool value)
|
|
|
|
{
|
2012-04-11 09:57:11 -04:00
|
|
|
set(m_recycleBinEnabled, value);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
2010-08-13 12:08:06 -04:00
|
|
|
void Metadata::setRecycleBin(Group* group)
|
2010-08-07 09:10:44 -04:00
|
|
|
{
|
2012-04-11 09:57:11 -04:00
|
|
|
set(m_recycleBin, group, m_recycleBinChanged);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setRecycleBinChanged(const QDateTime& value)
|
|
|
|
{
|
|
|
|
m_recycleBinChanged = value;
|
|
|
|
}
|
|
|
|
|
2010-08-13 12:08:06 -04:00
|
|
|
void Metadata::setEntryTemplatesGroup(Group* group)
|
2010-08-07 09:10:44 -04:00
|
|
|
{
|
2012-04-11 09:57:11 -04:00
|
|
|
set(m_entryTemplatesGroup, group, m_entryTemplatesGroupChanged);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setEntryTemplatesGroupChanged(const QDateTime& value)
|
|
|
|
{
|
|
|
|
m_entryTemplatesGroupChanged = value;
|
|
|
|
}
|
|
|
|
|
2010-08-13 12:08:06 -04:00
|
|
|
void Metadata::setLastSelectedGroup(Group* group)
|
2010-08-07 09:10:44 -04:00
|
|
|
{
|
2012-04-11 09:57:11 -04:00
|
|
|
set(m_lastSelectedGroup, group);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
2010-08-13 12:08:06 -04:00
|
|
|
void Metadata::setLastTopVisibleGroup(Group* group)
|
2010-08-07 09:10:44 -04:00
|
|
|
{
|
2012-04-11 09:57:11 -04:00
|
|
|
set(m_lastTopVisibleGroup, group);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
2010-09-25 06:41:00 -04:00
|
|
|
void Metadata::setMasterKeyChanged(const QDateTime& value)
|
|
|
|
{
|
|
|
|
m_masterKeyChanged = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setMasterKeyChangeRec(int value)
|
|
|
|
{
|
2012-04-11 09:57:11 -04:00
|
|
|
set(m_masterKeyChangeRec, value);
|
2010-09-25 06:41:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setMasterKeyChangeForce(int value)
|
|
|
|
{
|
2012-04-11 09:57:11 -04:00
|
|
|
set(m_masterKeyChangeForce, value);
|
2010-09-25 06:41:00 -04:00
|
|
|
}
|
|
|
|
|
2012-04-21 10:45:46 -04:00
|
|
|
void Metadata::setHistoryMaxItems(int value)
|
|
|
|
{
|
|
|
|
set(m_historyMaxItems, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setHistoryMaxSize(int value)
|
|
|
|
{
|
|
|
|
set(m_historyMaxSize, value);
|
|
|
|
}
|
|
|
|
|
2010-08-07 09:10:44 -04:00
|
|
|
void Metadata::addCustomField(const QString& key, const QString& value)
|
|
|
|
{
|
|
|
|
Q_ASSERT(!m_customFields.contains(key));
|
|
|
|
|
|
|
|
m_customFields.insert(key, value);
|
2012-04-11 09:57:11 -04:00
|
|
|
Q_EMIT modified();
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::removeCustomField(const QString& key)
|
|
|
|
{
|
|
|
|
Q_ASSERT(m_customFields.contains(key));
|
|
|
|
|
|
|
|
m_customFields.remove(key);
|
2012-04-11 09:57:11 -04:00
|
|
|
Q_EMIT modified();
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
2012-05-11 18:01:58 -04:00
|
|
|
|
|
|
|
const Database* Metadata::database() const
|
|
|
|
{
|
|
|
|
return m_parent;
|
|
|
|
}
|