2010-08-07 15:10:44 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
2021-03-13 14:07:49 -05:00
|
|
|
* Copyright (C) 2021 KeePassXC Team <team@keepassxc.org>
|
2010-08-07 15:10:44 +02:00
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2021-03-13 14:07:49 -05:00
|
|
|
#include "core/Clock.h"
|
|
|
|
#include "core/Entry.h"
|
2012-04-21 23:54:15 +02:00
|
|
|
#include "core/Group.h"
|
2021-07-11 22:10:29 -04:00
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QCryptographicHash>
|
2022-09-07 19:25:23 -04:00
|
|
|
#include <QJsonDocument>
|
2010-08-13 18:08:06 +02:00
|
|
|
|
2012-07-01 21:58:45 +02:00
|
|
|
const int Metadata::DefaultHistoryMaxItems = 10;
|
|
|
|
const int Metadata::DefaultHistoryMaxSize = 6 * 1024 * 1024;
|
|
|
|
|
2021-11-10 02:29:36 +01:00
|
|
|
// Fallback icon for return by reference
|
2021-11-25 04:36:31 +01:00
|
|
|
static const Metadata::CustomIconData NULL_ICON{};
|
2021-11-10 02:29:36 +01:00
|
|
|
|
2012-05-14 17:04:05 +02:00
|
|
|
Metadata::Metadata(QObject* parent)
|
2021-05-27 21:50:15 -04:00
|
|
|
: ModifiableObject(parent)
|
2018-02-06 16:37:06 +01:00
|
|
|
, m_customData(new CustomData(this))
|
2012-07-19 13:57:55 +02:00
|
|
|
, m_updateDatetime(true)
|
2010-08-07 15:10:44 +02:00
|
|
|
{
|
2020-03-05 22:59:07 -05:00
|
|
|
init();
|
2021-05-27 21:50:15 -04:00
|
|
|
connect(m_customData, &CustomData::modified, this, &Metadata::modified);
|
2020-03-05 22:59:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::init()
|
|
|
|
{
|
|
|
|
m_data.generator = QStringLiteral("KeePassXC");
|
2013-11-22 10:28:11 +01:00
|
|
|
m_data.maintenanceHistoryDays = 365;
|
|
|
|
m_data.masterKeyChangeRec = -1;
|
|
|
|
m_data.masterKeyChangeForce = -1;
|
|
|
|
m_data.historyMaxItems = DefaultHistoryMaxItems;
|
|
|
|
m_data.historyMaxSize = DefaultHistoryMaxSize;
|
|
|
|
m_data.recycleBinEnabled = true;
|
|
|
|
m_data.protectTitle = false;
|
|
|
|
m_data.protectUsername = false;
|
|
|
|
m_data.protectPassword = true;
|
|
|
|
m_data.protectUrl = false;
|
|
|
|
m_data.protectNotes = false;
|
|
|
|
|
2018-09-30 08:45:06 -04:00
|
|
|
QDateTime now = Clock::currentDateTimeUtc();
|
2013-11-22 10:28:11 +01:00
|
|
|
m_data.nameChanged = now;
|
|
|
|
m_data.descriptionChanged = now;
|
|
|
|
m_data.defaultUserNameChanged = now;
|
2011-06-29 16:47:05 +02:00
|
|
|
m_recycleBinChanged = now;
|
|
|
|
m_entryTemplatesGroupChanged = now;
|
|
|
|
m_masterKeyChanged = now;
|
2018-01-05 10:41:29 -05:00
|
|
|
m_settingsChanged = now;
|
2020-03-05 22:59:07 -05:00
|
|
|
}
|
2018-02-06 16:37:06 +01:00
|
|
|
|
2020-03-05 22:59:07 -05:00
|
|
|
void Metadata::clear()
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
m_customIcons.clear();
|
|
|
|
m_customIconsOrder.clear();
|
|
|
|
m_customIconsHashes.clear();
|
|
|
|
m_customData->clear();
|
2012-04-11 15:57:11 +02:00
|
|
|
}
|
|
|
|
|
2012-04-21 23:54:15 +02:00
|
|
|
template <class P, class V> bool Metadata::set(P& property, const V& value)
|
|
|
|
{
|
2012-04-11 15:57:11 +02:00
|
|
|
if (property != value) {
|
|
|
|
property = value;
|
2021-05-27 21:50:15 -04:00
|
|
|
emitModified();
|
2012-04-11 15:57:11 +02:00
|
|
|
return true;
|
2018-03-31 16:01:30 -04:00
|
|
|
} else {
|
2012-04-11 15:57:11 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
template <class P, class V> bool Metadata::set(P& property, const V& value, QDateTime& dateTime)
|
|
|
|
{
|
2012-04-11 15:57:11 +02:00
|
|
|
if (property != value) {
|
|
|
|
property = value;
|
|
|
|
if (m_updateDatetime) {
|
2018-09-30 08:45:06 -04:00
|
|
|
dateTime = Clock::currentDateTimeUtc();
|
2012-04-11 15:57:11 +02:00
|
|
|
}
|
2021-05-27 21:50:15 -04:00
|
|
|
emitModified();
|
2012-04-11 15:57:11 +02:00
|
|
|
return true;
|
2018-03-31 16:01:30 -04:00
|
|
|
} else {
|
2012-04-11 15:57:11 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-30 00:22:07 +02:00
|
|
|
void Metadata::setUpdateDatetime(bool value)
|
|
|
|
{
|
2012-04-11 15:57:11 +02:00
|
|
|
m_updateDatetime = value;
|
2010-08-07 15:10:44 +02:00
|
|
|
}
|
|
|
|
|
2013-11-22 10:28:11 +01:00
|
|
|
void Metadata::copyAttributesFrom(const Metadata* other)
|
|
|
|
{
|
|
|
|
m_data = other->m_data;
|
|
|
|
}
|
|
|
|
|
2010-08-07 15:10:44 +02:00
|
|
|
QString Metadata::generator() const
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
return m_data.generator;
|
2010-08-12 21:38:59 +02:00
|
|
|
}
|
2010-08-07 15:10:44 +02:00
|
|
|
|
|
|
|
QString Metadata::name() const
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
return m_data.name;
|
2010-08-12 21:38:59 +02:00
|
|
|
}
|
2010-08-07 15:10:44 +02:00
|
|
|
|
|
|
|
QDateTime Metadata::nameChanged() const
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
return m_data.nameChanged;
|
2010-08-12 21:38:59 +02:00
|
|
|
}
|
2010-08-07 15:10:44 +02:00
|
|
|
|
|
|
|
QString Metadata::description() const
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
return m_data.description;
|
2010-08-12 21:38:59 +02:00
|
|
|
}
|
2010-08-07 15:10:44 +02:00
|
|
|
|
|
|
|
QDateTime Metadata::descriptionChanged() const
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
return m_data.descriptionChanged;
|
2010-08-12 21:38:59 +02:00
|
|
|
}
|
2010-08-07 15:10:44 +02:00
|
|
|
|
|
|
|
QString Metadata::defaultUserName() const
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
return m_data.defaultUserName;
|
2010-08-12 21:38:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QDateTime Metadata::defaultUserNameChanged() const
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
return m_data.defaultUserNameChanged;
|
2010-08-12 21:38:59 +02:00
|
|
|
}
|
2010-08-07 15:10:44 +02:00
|
|
|
|
|
|
|
int Metadata::maintenanceHistoryDays() const
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
return m_data.maintenanceHistoryDays;
|
2010-08-12 21:38:59 +02:00
|
|
|
}
|
2010-08-07 15:10:44 +02:00
|
|
|
|
2020-01-26 21:38:43 -05:00
|
|
|
QString Metadata::color() const
|
2012-04-21 16:45:46 +02:00
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
return m_data.color;
|
2012-04-21 16:45:46 +02:00
|
|
|
}
|
|
|
|
|
2010-08-07 15:10:44 +02:00
|
|
|
bool Metadata::protectTitle() const
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
return m_data.protectTitle;
|
2010-08-12 21:38:59 +02:00
|
|
|
}
|
2010-08-07 15:10:44 +02:00
|
|
|
|
|
|
|
bool Metadata::protectUsername() const
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
return m_data.protectUsername;
|
2010-08-12 21:38:59 +02:00
|
|
|
}
|
2010-08-07 15:10:44 +02:00
|
|
|
|
|
|
|
bool Metadata::protectPassword() const
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
return m_data.protectPassword;
|
2010-08-12 21:38:59 +02:00
|
|
|
}
|
2010-08-07 15:10:44 +02:00
|
|
|
|
|
|
|
bool Metadata::protectUrl() const
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
return m_data.protectUrl;
|
2010-08-12 21:38:59 +02:00
|
|
|
}
|
2010-08-07 15:10:44 +02:00
|
|
|
|
|
|
|
bool Metadata::protectNotes() const
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
return m_data.protectNotes;
|
2010-08-12 21:38:59 +02:00
|
|
|
}
|
2010-08-07 15:10:44 +02:00
|
|
|
|
2021-11-10 02:29:36 +01:00
|
|
|
const Metadata::CustomIconData& Metadata::customIcon(const QUuid& uuid) const
|
2010-09-19 21:22:24 +02:00
|
|
|
{
|
2021-11-10 02:29:36 +01:00
|
|
|
auto icon = m_customIcons.find(uuid);
|
|
|
|
Q_ASSERT(icon != m_customIcons.end());
|
|
|
|
if (icon == m_customIcons.end()) {
|
|
|
|
return NULL_ICON;
|
|
|
|
}
|
|
|
|
return icon.value();
|
2016-01-24 19:03:50 +01:00
|
|
|
}
|
|
|
|
|
2020-05-29 10:00:07 -04:00
|
|
|
bool Metadata::hasCustomIcon(const QUuid& uuid) const
|
|
|
|
{
|
2021-03-13 14:07:49 -05:00
|
|
|
return m_customIcons.contains(uuid);
|
2020-05-29 10:00:07 -04:00
|
|
|
}
|
|
|
|
|
2018-03-22 22:56:05 +01:00
|
|
|
QList<QUuid> Metadata::customIconsOrder() const
|
2012-05-13 20:50:41 +02:00
|
|
|
{
|
|
|
|
return m_customIconsOrder;
|
|
|
|
}
|
|
|
|
|
2010-08-07 15:10:44 +02:00
|
|
|
bool Metadata::recycleBinEnabled() const
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
return m_data.recycleBinEnabled;
|
2010-08-12 21:38:59 +02:00
|
|
|
}
|
2010-08-07 15:10:44 +02:00
|
|
|
|
2012-04-18 23:17:29 +02:00
|
|
|
Group* Metadata::recycleBin()
|
|
|
|
{
|
|
|
|
return m_recycleBin;
|
|
|
|
}
|
|
|
|
|
2010-08-13 18:08:06 +02:00
|
|
|
const Group* Metadata::recycleBin() const
|
2010-08-07 15:10:44 +02:00
|
|
|
{
|
2010-08-13 18:08:06 +02:00
|
|
|
return m_recycleBin;
|
2010-08-12 21:38:59 +02:00
|
|
|
}
|
2010-08-07 15:10:44 +02:00
|
|
|
|
|
|
|
QDateTime Metadata::recycleBinChanged() const
|
|
|
|
{
|
|
|
|
return m_recycleBinChanged;
|
2010-08-12 21:38:59 +02:00
|
|
|
}
|
2010-08-07 15:10:44 +02:00
|
|
|
|
2010-08-13 18:08:06 +02:00
|
|
|
const Group* Metadata::entryTemplatesGroup() const
|
2010-08-07 15:10:44 +02:00
|
|
|
{
|
|
|
|
return m_entryTemplatesGroup;
|
2010-08-12 21:38:59 +02:00
|
|
|
}
|
2010-08-07 15:10:44 +02:00
|
|
|
|
|
|
|
QDateTime Metadata::entryTemplatesGroupChanged() const
|
|
|
|
{
|
|
|
|
return m_entryTemplatesGroupChanged;
|
2010-08-12 21:38:59 +02:00
|
|
|
}
|
2010-08-07 15:10:44 +02:00
|
|
|
|
2010-08-13 18:08:06 +02:00
|
|
|
const Group* Metadata::lastSelectedGroup() const
|
2010-08-07 15:10:44 +02:00
|
|
|
{
|
|
|
|
return m_lastSelectedGroup;
|
2010-08-12 21:38:59 +02:00
|
|
|
}
|
2010-08-07 15:10:44 +02:00
|
|
|
|
2010-08-13 18:08:06 +02:00
|
|
|
const Group* Metadata::lastTopVisibleGroup() const
|
2010-08-07 15:10:44 +02:00
|
|
|
{
|
|
|
|
return m_lastTopVisibleGroup;
|
2010-08-12 21:38:59 +02:00
|
|
|
}
|
2010-08-07 15:10:44 +02:00
|
|
|
|
2020-07-01 19:16:40 -04:00
|
|
|
QDateTime Metadata::databaseKeyChanged() const
|
2010-09-25 12:41:00 +02:00
|
|
|
{
|
|
|
|
return m_masterKeyChanged;
|
|
|
|
}
|
|
|
|
|
2020-07-01 19:16:40 -04:00
|
|
|
int Metadata::databaseKeyChangeRec() const
|
2010-09-25 12:41:00 +02:00
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
return m_data.masterKeyChangeRec;
|
2010-09-25 12:41:00 +02:00
|
|
|
}
|
|
|
|
|
2020-07-01 19:16:40 -04:00
|
|
|
int Metadata::databaseKeyChangeForce() const
|
2010-09-25 12:41:00 +02:00
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
return m_data.masterKeyChangeForce;
|
2010-09-25 12:41:00 +02:00
|
|
|
}
|
|
|
|
|
2012-04-21 16:45:46 +02:00
|
|
|
int Metadata::historyMaxItems() const
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
return m_data.historyMaxItems;
|
2012-04-21 16:45:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int Metadata::historyMaxSize() const
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
return m_data.historyMaxSize;
|
2012-04-21 16:45:46 +02:00
|
|
|
}
|
|
|
|
|
2018-02-18 21:01:22 +01:00
|
|
|
CustomData* Metadata::customData()
|
2018-02-06 16:37:06 +01:00
|
|
|
{
|
|
|
|
return m_customData;
|
|
|
|
}
|
|
|
|
|
2018-02-18 21:01:22 +01:00
|
|
|
const CustomData* Metadata::customData() const
|
2010-08-07 15:10:44 +02:00
|
|
|
{
|
2018-02-06 16:37:06 +01:00
|
|
|
return m_customData;
|
2010-08-12 21:38:59 +02:00
|
|
|
}
|
2010-08-07 15:10:44 +02:00
|
|
|
|
|
|
|
void Metadata::setGenerator(const QString& value)
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
set(m_data.generator, value);
|
2010-08-07 15:10:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setName(const QString& value)
|
|
|
|
{
|
2018-11-22 11:47:31 +01:00
|
|
|
set(m_data.name, value, m_data.nameChanged);
|
2010-08-07 15:10:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setNameChanged(const QDateTime& value)
|
|
|
|
{
|
2012-05-16 00:04:10 +02:00
|
|
|
Q_ASSERT(value.timeSpec() == Qt::UTC);
|
2013-11-22 10:28:11 +01:00
|
|
|
m_data.nameChanged = value;
|
2010-08-07 15:10:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setDescription(const QString& value)
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
set(m_data.description, value, m_data.descriptionChanged);
|
2010-08-07 15:10:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setDescriptionChanged(const QDateTime& value)
|
|
|
|
{
|
2012-05-16 00:04:10 +02:00
|
|
|
Q_ASSERT(value.timeSpec() == Qt::UTC);
|
2013-11-22 10:28:11 +01:00
|
|
|
m_data.descriptionChanged = value;
|
2010-08-07 15:10:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setDefaultUserName(const QString& value)
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
set(m_data.defaultUserName, value, m_data.defaultUserNameChanged);
|
2010-08-07 15:10:44 +02:00
|
|
|
}
|
|
|
|
|
2010-08-12 21:38:59 +02:00
|
|
|
void Metadata::setDefaultUserNameChanged(const QDateTime& value)
|
|
|
|
{
|
2012-05-16 00:04:10 +02:00
|
|
|
Q_ASSERT(value.timeSpec() == Qt::UTC);
|
2013-11-22 10:28:11 +01:00
|
|
|
m_data.defaultUserNameChanged = value;
|
2010-08-12 21:38:59 +02:00
|
|
|
}
|
|
|
|
|
2010-08-07 15:10:44 +02:00
|
|
|
void Metadata::setMaintenanceHistoryDays(int value)
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
set(m_data.maintenanceHistoryDays, value);
|
2010-08-07 15:10:44 +02:00
|
|
|
}
|
|
|
|
|
2020-01-26 21:38:43 -05:00
|
|
|
void Metadata::setColor(const QString& value)
|
2012-04-21 16:45:46 +02:00
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
set(m_data.color, value);
|
2012-04-21 16:45:46 +02:00
|
|
|
}
|
|
|
|
|
2010-08-07 15:10:44 +02:00
|
|
|
void Metadata::setProtectTitle(bool value)
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
set(m_data.protectTitle, value);
|
2010-08-07 15:10:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setProtectUsername(bool value)
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
set(m_data.protectUsername, value);
|
2010-08-07 15:10:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setProtectPassword(bool value)
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
set(m_data.protectPassword, value);
|
2010-08-07 15:10:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setProtectUrl(bool value)
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
set(m_data.protectUrl, value);
|
2010-08-07 15:10:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setProtectNotes(bool value)
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
set(m_data.protectNotes, value);
|
2010-08-07 15:10:44 +02:00
|
|
|
}
|
|
|
|
|
2021-11-10 02:29:36 +01:00
|
|
|
void Metadata::addCustomIcon(const QUuid& uuid, const CustomIconData& iconData)
|
2010-08-07 15:10:44 +02:00
|
|
|
{
|
2021-11-10 02:29:36 +01:00
|
|
|
|
2010-08-13 18:08:06 +02:00
|
|
|
Q_ASSERT(!uuid.isNull());
|
2021-03-13 14:07:49 -05:00
|
|
|
Q_ASSERT(!m_customIcons.contains(uuid));
|
2010-08-07 15:10:44 +02:00
|
|
|
|
2019-04-12 12:21:20 +02:00
|
|
|
// remove all uuids to prevent duplicates in release mode
|
2021-11-10 02:29:36 +01:00
|
|
|
m_customIcons[uuid] = iconData;
|
2019-04-12 12:21:20 +02:00
|
|
|
m_customIconsOrder.removeAll(uuid);
|
2012-05-13 20:50:41 +02:00
|
|
|
m_customIconsOrder.append(uuid);
|
2021-11-10 02:29:36 +01:00
|
|
|
|
2017-09-24 17:53:42 -04:00
|
|
|
// Associate image hash to uuid
|
2021-11-10 02:29:36 +01:00
|
|
|
QByteArray hash = hashIcon(iconData.data);
|
2017-09-24 17:53:42 -04:00
|
|
|
m_customIconsHashes[hash] = uuid;
|
2021-03-13 14:07:49 -05:00
|
|
|
Q_ASSERT(m_customIcons.count() == m_customIconsOrder.count());
|
2015-03-31 22:31:04 +02:00
|
|
|
|
2021-05-27 21:50:15 -04:00
|
|
|
emitModified();
|
2015-03-31 22:31:04 +02:00
|
|
|
}
|
|
|
|
|
2021-11-10 02:29:36 +01:00
|
|
|
void Metadata::addCustomIcon(const QUuid& uuid,
|
|
|
|
const QByteArray& iconBytes,
|
|
|
|
const QString& name,
|
|
|
|
const QDateTime& lastModified)
|
|
|
|
{
|
|
|
|
addCustomIcon(uuid, {iconBytes, name, lastModified});
|
|
|
|
}
|
|
|
|
|
2018-03-22 22:56:05 +01:00
|
|
|
void Metadata::removeCustomIcon(const QUuid& uuid)
|
2010-08-07 15:10:44 +02:00
|
|
|
{
|
2010-08-13 18:08:06 +02:00
|
|
|
Q_ASSERT(!uuid.isNull());
|
2021-03-13 14:07:49 -05:00
|
|
|
Q_ASSERT(m_customIcons.contains(uuid));
|
2010-08-07 15:10:44 +02:00
|
|
|
|
2017-09-24 17:53:42 -04:00
|
|
|
// Remove hash record only if this is the same uuid
|
2021-11-10 02:29:36 +01:00
|
|
|
QByteArray hash = hashIcon(m_customIcons[uuid].data);
|
2017-09-24 17:53:42 -04:00
|
|
|
if (m_customIconsHashes.contains(hash) && m_customIconsHashes[hash] == uuid) {
|
|
|
|
m_customIconsHashes.remove(hash);
|
|
|
|
}
|
|
|
|
|
2010-08-07 15:10:44 +02:00
|
|
|
m_customIcons.remove(uuid);
|
2012-05-13 20:50:41 +02:00
|
|
|
m_customIconsOrder.removeAll(uuid);
|
2021-03-13 14:07:49 -05:00
|
|
|
Q_ASSERT(m_customIcons.count() == m_customIconsOrder.count());
|
2021-11-10 02:29:36 +01:00
|
|
|
dynamic_cast<Database*>(parent())->addDeletedObject(uuid);
|
2021-05-27 21:50:15 -04:00
|
|
|
emitModified();
|
2010-08-07 15:10:44 +02:00
|
|
|
}
|
|
|
|
|
2021-03-13 14:07:49 -05:00
|
|
|
QUuid Metadata::findCustomIcon(const QByteArray& candidate)
|
2017-09-24 17:53:42 -04:00
|
|
|
{
|
2021-03-13 14:07:49 -05:00
|
|
|
QByteArray hash = hashIcon(candidate);
|
2018-03-22 22:56:05 +01:00
|
|
|
return m_customIconsHashes.value(hash, QUuid());
|
2017-09-24 17:53:42 -04:00
|
|
|
}
|
|
|
|
|
2018-03-22 22:56:05 +01:00
|
|
|
void Metadata::copyCustomIcons(const QSet<QUuid>& iconList, const Metadata* otherMetadata)
|
2013-04-07 18:32:43 +02:00
|
|
|
{
|
2018-03-22 22:56:05 +01:00
|
|
|
for (const QUuid& uuid : iconList) {
|
2020-05-29 10:00:07 -04:00
|
|
|
Q_ASSERT(otherMetadata->hasCustomIcon(uuid));
|
2013-04-07 18:32:43 +02:00
|
|
|
|
2020-05-29 10:00:07 -04:00
|
|
|
if (!hasCustomIcon(uuid) && otherMetadata->hasCustomIcon(uuid)) {
|
2013-04-07 18:32:43 +02:00
|
|
|
addCustomIcon(uuid, otherMetadata->customIcon(uuid));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-13 14:07:49 -05:00
|
|
|
QByteArray Metadata::hashIcon(const QByteArray& iconData)
|
2017-09-24 17:53:42 -04:00
|
|
|
{
|
2021-03-13 14:07:49 -05:00
|
|
|
return QCryptographicHash::hash(iconData, QCryptographicHash::Md5);
|
2017-09-24 17:53:42 -04:00
|
|
|
}
|
|
|
|
|
2010-08-07 15:10:44 +02:00
|
|
|
void Metadata::setRecycleBinEnabled(bool value)
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
set(m_data.recycleBinEnabled, value);
|
2010-08-07 15:10:44 +02:00
|
|
|
}
|
|
|
|
|
2010-08-13 18:08:06 +02:00
|
|
|
void Metadata::setRecycleBin(Group* group)
|
2010-08-07 15:10:44 +02:00
|
|
|
{
|
2012-04-11 15:57:11 +02:00
|
|
|
set(m_recycleBin, group, m_recycleBinChanged);
|
2010-08-07 15:10:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setRecycleBinChanged(const QDateTime& value)
|
|
|
|
{
|
2012-05-16 00:04:10 +02:00
|
|
|
Q_ASSERT(value.timeSpec() == Qt::UTC);
|
2010-08-07 15:10:44 +02:00
|
|
|
m_recycleBinChanged = value;
|
|
|
|
}
|
|
|
|
|
2010-08-13 18:08:06 +02:00
|
|
|
void Metadata::setEntryTemplatesGroup(Group* group)
|
2010-08-07 15:10:44 +02:00
|
|
|
{
|
2012-04-11 15:57:11 +02:00
|
|
|
set(m_entryTemplatesGroup, group, m_entryTemplatesGroupChanged);
|
2010-08-07 15:10:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setEntryTemplatesGroupChanged(const QDateTime& value)
|
|
|
|
{
|
2012-05-16 00:04:10 +02:00
|
|
|
Q_ASSERT(value.timeSpec() == Qt::UTC);
|
2010-08-07 15:10:44 +02:00
|
|
|
m_entryTemplatesGroupChanged = value;
|
|
|
|
}
|
|
|
|
|
2010-08-13 18:08:06 +02:00
|
|
|
void Metadata::setLastSelectedGroup(Group* group)
|
2010-08-07 15:10:44 +02:00
|
|
|
{
|
2012-04-11 15:57:11 +02:00
|
|
|
set(m_lastSelectedGroup, group);
|
2010-08-07 15:10:44 +02:00
|
|
|
}
|
|
|
|
|
2010-08-13 18:08:06 +02:00
|
|
|
void Metadata::setLastTopVisibleGroup(Group* group)
|
2010-08-07 15:10:44 +02:00
|
|
|
{
|
2012-04-11 15:57:11 +02:00
|
|
|
set(m_lastTopVisibleGroup, group);
|
2010-08-07 15:10:44 +02:00
|
|
|
}
|
|
|
|
|
2020-07-01 19:16:40 -04:00
|
|
|
void Metadata::setDatabaseKeyChanged(const QDateTime& value)
|
2010-09-25 12:41:00 +02:00
|
|
|
{
|
2012-05-16 00:04:10 +02:00
|
|
|
Q_ASSERT(value.timeSpec() == Qt::UTC);
|
2010-09-25 12:41:00 +02:00
|
|
|
m_masterKeyChanged = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setMasterKeyChangeRec(int value)
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
set(m_data.masterKeyChangeRec, value);
|
2010-09-25 12:41:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setMasterKeyChangeForce(int value)
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
set(m_data.masterKeyChangeForce, value);
|
2010-09-25 12:41:00 +02:00
|
|
|
}
|
|
|
|
|
2012-04-21 16:45:46 +02:00
|
|
|
void Metadata::setHistoryMaxItems(int value)
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
set(m_data.historyMaxItems, value);
|
2012-04-21 16:45:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setHistoryMaxSize(int value)
|
|
|
|
{
|
2013-11-22 10:28:11 +01:00
|
|
|
set(m_data.historyMaxSize, value);
|
2012-04-21 16:45:46 +02:00
|
|
|
}
|
|
|
|
|
2018-02-06 16:37:06 +01:00
|
|
|
QDateTime Metadata::settingsChanged() const
|
2010-08-07 15:10:44 +02:00
|
|
|
{
|
2018-01-05 10:41:29 -05:00
|
|
|
return m_settingsChanged;
|
|
|
|
}
|
|
|
|
|
2018-02-06 16:37:06 +01:00
|
|
|
void Metadata::setSettingsChanged(const QDateTime& value)
|
|
|
|
{
|
2018-01-05 10:41:29 -05:00
|
|
|
Q_ASSERT(value.timeSpec() == Qt::UTC);
|
|
|
|
m_settingsChanged = value;
|
|
|
|
}
|
2022-09-07 19:25:23 -04:00
|
|
|
|
|
|
|
void Metadata::addSavedSearch(const QString& name, const QString& searchtext)
|
|
|
|
{
|
|
|
|
auto searches = savedSearches();
|
|
|
|
searches.insert(name, searchtext);
|
|
|
|
auto json = QJsonDocument::fromVariant(searches);
|
|
|
|
m_customData->set("KPXC_SavedSearch", json.toJson());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::deleteSavedSearch(const QString& name)
|
|
|
|
{
|
|
|
|
auto searches = savedSearches();
|
|
|
|
searches.remove(name);
|
|
|
|
auto json = QJsonDocument::fromVariant(searches);
|
|
|
|
m_customData->set("KPXC_SavedSearch", json.toJson());
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariantMap Metadata::savedSearches()
|
|
|
|
{
|
|
|
|
auto searches = m_customData->value("KPXC_SavedSearch");
|
|
|
|
auto json = QJsonDocument::fromJson(searches.toUtf8());
|
|
|
|
return json.toVariant().toMap();
|
|
|
|
}
|