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"
|
|
|
|
|
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)
|
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;
|
|
|
|
// m_data.autoEnableVisualHiding = false;
|
|
|
|
|
2015-07-22 17:48:08 -04:00
|
|
|
QDateTime now = QDateTime::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;
|
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;
|
2017-03-10 09:58:42 -05:00
|
|
|
emit modified();
|
2012-04-11 09:57:11 -04:00
|
|
|
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) {
|
2015-07-22 17:48:08 -04:00
|
|
|
dateTime = QDateTime::currentDateTimeUtc();
|
2012-04-11 09:57:11 -04:00
|
|
|
}
|
2017-03-10 09:58:42 -05:00
|
|
|
emit modified();
|
2012-04-11 09:57:11 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
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
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-01-24 11:56:35 -05:00
|
|
|
QPixmap Metadata::customIconPixmap(const Uuid& uuid) const
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-01-24 12:42:27 -05:00
|
|
|
QPixmap Metadata::customIconScaledPixmap(const Uuid& uuid) const
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2016-01-24 13:03:50 -05:00
|
|
|
QHash<Uuid, QPixmap> Metadata::customIconsScaledPixmaps() const
|
|
|
|
{
|
|
|
|
QHash<Uuid, QPixmap> result;
|
|
|
|
|
2016-09-02 13:51:51 -04:00
|
|
|
for (const Uuid& uuid : m_customIconsOrder) {
|
2016-01-24 13:03:50 -05:00
|
|
|
result.insert(uuid, customIconScaledPixmap(uuid));
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
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)
|
|
|
|
{
|
2013-11-22 04:28:11 -05:00
|
|
|
if (set(m_data.name, value, m_data.nameChanged)) {
|
2017-03-10 09:58:42 -05:00
|
|
|
emit nameTextChanged();
|
2012-04-11 09:57:11 -04:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
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);
|
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);
|
|
|
|
Q_ASSERT(m_customIcons.count() == m_customIconsOrder.count());
|
2017-03-10 09:58:42 -05:00
|
|
|
emit modified();
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
2015-03-31 16:31:04 -04:00
|
|
|
void Metadata::addCustomIconScaled(const Uuid& uuid, const QImage& icon)
|
|
|
|
{
|
|
|
|
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) {
|
|
|
|
iconScaled = icon.scaled(QSize(128, 128), Qt::KeepAspectRatio,
|
2015-03-31 16:31:04 -04:00
|
|
|
Qt::SmoothTransformation);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
iconScaled = icon;
|
|
|
|
}
|
|
|
|
|
|
|
|
addCustomIcon(uuid, iconScaled);
|
|
|
|
}
|
|
|
|
|
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);
|
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());
|
2017-03-10 09:58:42 -05:00
|
|
|
emit modified();
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
|
|
|
|
2013-04-07 12:32:43 -04:00
|
|
|
void Metadata::copyCustomIcons(const QSet<Uuid>& iconList, const Metadata* otherMetadata)
|
|
|
|
{
|
2016-09-02 13:51:51 -04:00
|
|
|
for (const Uuid& 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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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);
|
2017-03-10 09:58:42 -05:00
|
|
|
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);
|
2017-03-10 09:58:42 -05:00
|
|
|
emit modified();
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|