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