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"
|
2018-03-31 16:01:30 -04:00
|
|
|
#include <QtCore/QCryptographicHash>
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2018-09-30 08:45:06 -04:00
|
|
|
#include "core/Clock.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
|
|
|
|
2012-07-01 15:58:45 -04:00
|
|
|
const int Metadata::DefaultHistoryMaxItems = 10;
|
|
|
|
const int Metadata::DefaultHistoryMaxSize = 6 * 1024 * 1024;
|
|
|
|
|
2012-05-14 11:04:05 -04:00
|
|
|
Metadata::Metadata(QObject* parent)
|
2010-08-24 17:12:01 -04:00
|
|
|
: QObject(parent)
|
2018-02-06 10:37:06 -05:00
|
|
|
, m_customData(new CustomData(this))
|
2012-07-19 07:57:55 -04:00
|
|
|
, m_updateDatetime(true)
|
2010-08-07 09:10:44 -04:00
|
|
|
{
|
2016-11-03 00:05:30 -04:00
|
|
|
m_data.generator = "KeePassXC";
|
2013-11-22 04:28:11 -05: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 04:28:11 -05:00
|
|
|
m_data.nameChanged = now;
|
|
|
|
m_data.descriptionChanged = now;
|
|
|
|
m_data.defaultUserNameChanged = now;
|
2011-06-29 10:47:05 -04:00
|
|
|
m_recycleBinChanged = now;
|
|
|
|
m_entryTemplatesGroupChanged = now;
|
|
|
|
m_masterKeyChanged = now;
|
2018-01-05 10:41:29 -05:00
|
|
|
m_settingsChanged = now;
|
2018-02-06 10:37:06 -05:00
|
|
|
|
2018-11-22 05:47:31 -05:00
|
|
|
connect(m_customData, SIGNAL(customDataModified()), this, SIGNAL(metadataModified()));
|
2012-04-11 09:57:11 -04:00
|
|
|
}
|
|
|
|
|
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;
|
2018-11-22 05:47:31 -05:00
|
|
|
emit metadataModified();
|
2012-04-11 09:57:11 -04:00
|
|
|
return true;
|
2018-03-31 16:01:30 -04:00
|
|
|
} else {
|
2012-04-11 09:57:11 -04: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 09:57:11 -04:00
|
|
|
if (property != value) {
|
|
|
|
property = value;
|
|
|
|
if (m_updateDatetime) {
|
2018-09-30 08:45:06 -04:00
|
|
|
dateTime = Clock::currentDateTimeUtc();
|
2012-04-11 09:57:11 -04:00
|
|
|
}
|
2018-11-22 05:47:31 -05:00
|
|
|
emit metadataModified();
|
2012-04-11 09:57:11 -04:00
|
|
|
return true;
|
2018-03-31 16:01:30 -04:00
|
|
|
} else {
|
2012-04-11 09:57:11 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-29 18:22:07 -04:00
|
|
|
void Metadata::setUpdateDatetime(bool value)
|
|
|
|
{
|
2012-04-11 09:57:11 -04:00
|
|
|
m_updateDatetime = value;
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
2013-11-22 04:28:11 -05:00
|
|
|
void Metadata::copyAttributesFrom(const Metadata* other)
|
|
|
|
{
|
|
|
|
m_data = other->m_data;
|
|
|
|
}
|
|
|
|
|
2010-08-07 09:10:44 -04:00
|
|
|
QString Metadata::generator() const
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
return m_data.generator;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
QString Metadata::name() const
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
return m_data.name;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
QDateTime Metadata::nameChanged() const
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
return m_data.nameChanged;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
QString Metadata::description() const
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
return m_data.description;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
QDateTime Metadata::descriptionChanged() const
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
return m_data.descriptionChanged;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
QString Metadata::defaultUserName() const
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
return m_data.defaultUserName;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
QDateTime Metadata::defaultUserNameChanged() const
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
return m_data.defaultUserNameChanged;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
int Metadata::maintenanceHistoryDays() const
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
return m_data.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
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
return m_data.color;
|
2012-04-21 10:45:46 -04:00
|
|
|
}
|
|
|
|
|
2010-08-07 09:10:44 -04:00
|
|
|
bool Metadata::protectTitle() const
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
return m_data.protectTitle;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
bool Metadata::protectUsername() const
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
return m_data.protectUsername;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
bool Metadata::protectPassword() const
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
return m_data.protectPassword;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
bool Metadata::protectUrl() const
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
return m_data.protectUrl;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
bool Metadata::protectNotes() const
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
return m_data.protectNotes;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2018-03-22 17:56:05 -04:00
|
|
|
QImage Metadata::customIcon(const QUuid& uuid) const
|
2010-09-19 15:22:24 -04:00
|
|
|
{
|
|
|
|
return m_customIcons.value(uuid);
|
|
|
|
}
|
|
|
|
|
2018-03-22 17:56:05 -04:00
|
|
|
QPixmap Metadata::customIconPixmap(const QUuid& uuid) const
|
2016-01-24 11:56:35 -05:00
|
|
|
{
|
|
|
|
QPixmap pixmap;
|
|
|
|
|
|
|
|
if (!m_customIcons.contains(uuid)) {
|
|
|
|
return pixmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPixmapCache::Key& cacheKey = m_customIconCacheKeys[uuid];
|
|
|
|
|
|
|
|
if (!QPixmapCache::find(cacheKey, &pixmap)) {
|
|
|
|
pixmap = QPixmap::fromImage(m_customIcons.value(uuid));
|
|
|
|
cacheKey = QPixmapCache::insert(pixmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pixmap;
|
|
|
|
}
|
|
|
|
|
2018-03-22 17:56:05 -04:00
|
|
|
QPixmap Metadata::customIconScaledPixmap(const QUuid& uuid) const
|
2016-01-24 12:42:27 -05:00
|
|
|
{
|
|
|
|
QPixmap pixmap;
|
|
|
|
|
|
|
|
if (!m_customIcons.contains(uuid)) {
|
|
|
|
return pixmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPixmapCache::Key& cacheKey = m_customIconScaledCacheKeys[uuid];
|
|
|
|
|
|
|
|
if (!QPixmapCache::find(cacheKey, &pixmap)) {
|
|
|
|
QImage image = m_customIcons.value(uuid).scaled(16, 16, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
|
|
|
pixmap = QPixmap::fromImage(image);
|
|
|
|
cacheKey = QPixmapCache::insert(pixmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pixmap;
|
|
|
|
}
|
|
|
|
|
2018-03-22 17:56:05 -04:00
|
|
|
bool Metadata::containsCustomIcon(const QUuid& uuid) const
|
2012-04-27 05:22:02 -04:00
|
|
|
{
|
|
|
|
return m_customIcons.contains(uuid);
|
|
|
|
}
|
|
|
|
|
2018-03-22 17:56:05 -04:00
|
|
|
QHash<QUuid, 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
|
|
|
|
2018-03-22 17:56:05 -04:00
|
|
|
QHash<QUuid, QPixmap> Metadata::customIconsScaledPixmaps() const
|
2016-01-24 13:03:50 -05:00
|
|
|
{
|
2018-03-22 17:56:05 -04:00
|
|
|
QHash<QUuid, QPixmap> result;
|
2016-01-24 13:03:50 -05:00
|
|
|
|
2018-03-22 17:56:05 -04:00
|
|
|
for (const QUuid& uuid : m_customIconsOrder) {
|
2016-01-24 13:03:50 -05:00
|
|
|
result.insert(uuid, customIconScaledPixmap(uuid));
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-03-22 17:56:05 -04:00
|
|
|
QList<QUuid> Metadata::customIconsOrder() const
|
2012-05-13 14:50:41 -04:00
|
|
|
{
|
|
|
|
return m_customIconsOrder;
|
|
|
|
}
|
|
|
|
|
2010-08-07 09:10:44 -04:00
|
|
|
bool Metadata::recycleBinEnabled() const
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
return m_data.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
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
return m_data.masterKeyChangeRec;
|
2010-09-25 06:41:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int Metadata::masterKeyChangeForce() const
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
return m_data.masterKeyChangeForce;
|
2010-09-25 06:41:00 -04:00
|
|
|
}
|
|
|
|
|
2012-04-21 10:45:46 -04:00
|
|
|
int Metadata::historyMaxItems() const
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
return m_data.historyMaxItems;
|
2012-04-21 10:45:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int Metadata::historyMaxSize() const
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
return m_data.historyMaxSize;
|
2012-04-21 10:45:46 -04:00
|
|
|
}
|
|
|
|
|
2018-02-18 15:01:22 -05:00
|
|
|
CustomData* Metadata::customData()
|
2018-02-06 10:37:06 -05:00
|
|
|
{
|
|
|
|
return m_customData;
|
|
|
|
}
|
|
|
|
|
2018-02-18 15:01:22 -05:00
|
|
|
const CustomData* Metadata::customData() const
|
2010-08-07 09:10:44 -04:00
|
|
|
{
|
2018-02-06 10:37:06 -05:00
|
|
|
return m_customData;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
void Metadata::setGenerator(const QString& value)
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
set(m_data.generator, value);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setName(const QString& value)
|
|
|
|
{
|
2018-11-22 05:47:31 -05:00
|
|
|
set(m_data.name, value, m_data.nameChanged);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setNameChanged(const QDateTime& value)
|
|
|
|
{
|
2012-05-15 18:04:10 -04:00
|
|
|
Q_ASSERT(value.timeSpec() == Qt::UTC);
|
2013-11-22 04:28:11 -05:00
|
|
|
m_data.nameChanged = value;
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setDescription(const QString& value)
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
set(m_data.description, value, m_data.descriptionChanged);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setDescriptionChanged(const QDateTime& value)
|
|
|
|
{
|
2012-05-15 18:04:10 -04:00
|
|
|
Q_ASSERT(value.timeSpec() == Qt::UTC);
|
2013-11-22 04:28:11 -05:00
|
|
|
m_data.descriptionChanged = value;
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setDefaultUserName(const QString& value)
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
set(m_data.defaultUserName, value, m_data.defaultUserNameChanged);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
void Metadata::setDefaultUserNameChanged(const QDateTime& value)
|
|
|
|
{
|
2012-05-15 18:04:10 -04:00
|
|
|
Q_ASSERT(value.timeSpec() == Qt::UTC);
|
2013-11-22 04:28:11 -05:00
|
|
|
m_data.defaultUserNameChanged = value;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
2010-08-07 09:10:44 -04:00
|
|
|
void Metadata::setMaintenanceHistoryDays(int value)
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
set(m_data.maintenanceHistoryDays, value);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
2012-04-21 10:45:46 -04:00
|
|
|
void Metadata::setColor(const QColor& value)
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
set(m_data.color, value);
|
2012-04-21 10:45:46 -04:00
|
|
|
}
|
|
|
|
|
2010-08-07 09:10:44 -04:00
|
|
|
void Metadata::setProtectTitle(bool value)
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
set(m_data.protectTitle, value);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setProtectUsername(bool value)
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
set(m_data.protectUsername, value);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setProtectPassword(bool value)
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
set(m_data.protectPassword, value);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setProtectUrl(bool value)
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
set(m_data.protectUrl, value);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setProtectNotes(bool value)
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
set(m_data.protectNotes, value);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
2018-03-22 17:56:05 -04:00
|
|
|
void Metadata::addCustomIcon(const QUuid& 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);
|
2016-01-24 11:56:35 -05:00
|
|
|
// reset cache in case there is also an icon with that uuid
|
|
|
|
m_customIconCacheKeys[uuid] = QPixmapCache::Key();
|
2016-01-24 12:42:27 -05:00
|
|
|
m_customIconScaledCacheKeys[uuid] = QPixmapCache::Key();
|
2012-05-13 14:50:41 -04:00
|
|
|
m_customIconsOrder.append(uuid);
|
2017-09-24 17:53:42 -04:00
|
|
|
// Associate image hash to uuid
|
|
|
|
QByteArray hash = hashImage(icon);
|
|
|
|
m_customIconsHashes[hash] = uuid;
|
2012-05-13 14:50:41 -04:00
|
|
|
Q_ASSERT(m_customIcons.count() == m_customIconsOrder.count());
|
2018-11-22 05:47:31 -05:00
|
|
|
emit metadataModified();
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
2018-03-22 17:56:05 -04:00
|
|
|
void Metadata::addCustomIconScaled(const QUuid& uuid, const QImage& icon)
|
2015-03-31 16:31:04 -04:00
|
|
|
{
|
|
|
|
QImage iconScaled;
|
|
|
|
|
2015-04-08 12:19:50 -04:00
|
|
|
// scale down to 128x128 if icon is larger
|
|
|
|
if (icon.width() > 128 || icon.height() > 128) {
|
2018-03-31 16:01:30 -04:00
|
|
|
iconScaled = icon.scaled(QSize(128, 128), Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
|
|
|
} else {
|
2015-03-31 16:31:04 -04:00
|
|
|
iconScaled = icon;
|
|
|
|
}
|
|
|
|
|
|
|
|
addCustomIcon(uuid, iconScaled);
|
|
|
|
}
|
|
|
|
|
2018-03-22 17:56:05 -04:00
|
|
|
void Metadata::removeCustomIcon(const QUuid& uuid)
|
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));
|
|
|
|
|
2017-09-24 17:53:42 -04:00
|
|
|
// Remove hash record only if this is the same uuid
|
|
|
|
QByteArray hash = hashImage(m_customIcons[uuid]);
|
|
|
|
if (m_customIconsHashes.contains(hash) && m_customIconsHashes[hash] == uuid) {
|
|
|
|
m_customIconsHashes.remove(hash);
|
|
|
|
}
|
|
|
|
|
2010-08-07 09:10:44 -04:00
|
|
|
m_customIcons.remove(uuid);
|
2016-01-24 11:56:35 -05:00
|
|
|
QPixmapCache::remove(m_customIconCacheKeys.value(uuid));
|
|
|
|
m_customIconCacheKeys.remove(uuid);
|
2016-01-24 12:42:27 -05:00
|
|
|
QPixmapCache::remove(m_customIconScaledCacheKeys.value(uuid));
|
|
|
|
m_customIconScaledCacheKeys.remove(uuid);
|
2012-05-13 14:50:41 -04:00
|
|
|
m_customIconsOrder.removeAll(uuid);
|
|
|
|
Q_ASSERT(m_customIcons.count() == m_customIconsOrder.count());
|
2018-11-22 05:47:31 -05:00
|
|
|
emit metadataModified();
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
2018-10-31 23:27:38 -04:00
|
|
|
QUuid Metadata::findCustomIcon(const QImage& candidate)
|
2017-09-24 17:53:42 -04:00
|
|
|
{
|
|
|
|
QByteArray hash = hashImage(candidate);
|
2018-03-22 17:56:05 -04:00
|
|
|
return m_customIconsHashes.value(hash, QUuid());
|
2017-09-24 17:53:42 -04:00
|
|
|
}
|
|
|
|
|
2018-03-22 17:56:05 -04:00
|
|
|
void Metadata::copyCustomIcons(const QSet<QUuid>& iconList, const Metadata* otherMetadata)
|
2013-04-07 12:32:43 -04:00
|
|
|
{
|
2018-03-22 17:56:05 -04:00
|
|
|
for (const QUuid& uuid : iconList) {
|
2013-04-07 12:32:43 -04:00
|
|
|
Q_ASSERT(otherMetadata->containsCustomIcon(uuid));
|
|
|
|
|
2013-04-07 13:37:44 -04:00
|
|
|
if (!containsCustomIcon(uuid) && otherMetadata->containsCustomIcon(uuid)) {
|
2013-04-07 12:32:43 -04:00
|
|
|
addCustomIcon(uuid, otherMetadata->customIcon(uuid));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-24 17:53:42 -04:00
|
|
|
QByteArray Metadata::hashImage(const QImage& image)
|
|
|
|
{
|
2018-10-26 09:19:04 -04:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
|
|
|
auto data = QByteArray(reinterpret_cast<const char*>(image.bits()), static_cast<int>(image.sizeInBytes()));
|
|
|
|
#else
|
2017-10-03 15:40:15 -04:00
|
|
|
auto data = QByteArray(reinterpret_cast<const char*>(image.bits()), image.byteCount());
|
2018-10-26 09:19:04 -04:00
|
|
|
#endif
|
2017-09-24 17:53:42 -04:00
|
|
|
return QCryptographicHash::hash(data, QCryptographicHash::Md5);
|
|
|
|
}
|
|
|
|
|
2010-08-07 09:10:44 -04:00
|
|
|
void Metadata::setRecycleBinEnabled(bool value)
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
set(m_data.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)
|
|
|
|
{
|
2012-05-15 18:04:10 -04:00
|
|
|
Q_ASSERT(value.timeSpec() == Qt::UTC);
|
2010-08-07 09:10:44 -04:00
|
|
|
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)
|
|
|
|
{
|
2012-05-15 18:04:10 -04:00
|
|
|
Q_ASSERT(value.timeSpec() == Qt::UTC);
|
2010-08-07 09:10:44 -04:00
|
|
|
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)
|
|
|
|
{
|
2012-05-15 18:04:10 -04:00
|
|
|
Q_ASSERT(value.timeSpec() == Qt::UTC);
|
2010-09-25 06:41:00 -04:00
|
|
|
m_masterKeyChanged = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setMasterKeyChangeRec(int value)
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
set(m_data.masterKeyChangeRec, value);
|
2010-09-25 06:41:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setMasterKeyChangeForce(int value)
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
set(m_data.masterKeyChangeForce, value);
|
2010-09-25 06:41:00 -04:00
|
|
|
}
|
|
|
|
|
2012-04-21 10:45:46 -04:00
|
|
|
void Metadata::setHistoryMaxItems(int value)
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
set(m_data.historyMaxItems, value);
|
2012-04-21 10:45:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Metadata::setHistoryMaxSize(int value)
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
set(m_data.historyMaxSize, value);
|
2012-04-21 10:45:46 -04:00
|
|
|
}
|
|
|
|
|
2018-02-06 10:37:06 -05:00
|
|
|
QDateTime Metadata::settingsChanged() const
|
2010-08-07 09:10:44 -04:00
|
|
|
{
|
2018-01-05 10:41:29 -05:00
|
|
|
return m_settingsChanged;
|
|
|
|
}
|
|
|
|
|
2018-02-06 10:37:06 -05:00
|
|
|
void Metadata::setSettingsChanged(const QDateTime& value)
|
|
|
|
{
|
2018-01-05 10:41:29 -05:00
|
|
|
Q_ASSERT(value.timeSpec() == Qt::UTC);
|
|
|
|
m_settingsChanged = value;
|
|
|
|
}
|