2010-08-07 09:10:44 -04: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 09:10:44 -04: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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KEEPASSX_METADATA_H
|
|
|
|
#define KEEPASSX_METADATA_H
|
|
|
|
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QDateTime>
|
2021-03-13 14:07:49 -05:00
|
|
|
#include <QHash>
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QPointer>
|
2018-03-22 17:56:05 -04:00
|
|
|
#include <QUuid>
|
2022-09-07 19:25:23 -04:00
|
|
|
#include <QVariantMap>
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2018-02-06 10:37:06 -05:00
|
|
|
#include "core/CustomData.h"
|
2020-05-29 10:00:07 -04:00
|
|
|
#include "core/Global.h"
|
2011-07-08 08:51:14 -04:00
|
|
|
|
2010-08-13 12:08:06 -04:00
|
|
|
class Database;
|
|
|
|
class Group;
|
|
|
|
|
2021-05-27 21:50:15 -04:00
|
|
|
class Metadata : public ModifiableObject
|
2010-08-07 09:10:44 -04:00
|
|
|
{
|
2010-08-13 12:08:06 -04:00
|
|
|
Q_OBJECT
|
|
|
|
|
2010-08-07 09:10:44 -04:00
|
|
|
public:
|
2015-07-24 12:28:12 -04:00
|
|
|
explicit Metadata(QObject* parent = nullptr);
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2013-11-22 04:28:11 -05:00
|
|
|
struct MetadataData
|
|
|
|
{
|
|
|
|
QString generator;
|
|
|
|
QString name;
|
|
|
|
QDateTime nameChanged;
|
|
|
|
QString description;
|
|
|
|
QDateTime descriptionChanged;
|
|
|
|
QString defaultUserName;
|
|
|
|
QDateTime defaultUserNameChanged;
|
|
|
|
int maintenanceHistoryDays;
|
2020-01-26 21:38:43 -05:00
|
|
|
QString color;
|
2013-11-22 04:28:11 -05:00
|
|
|
bool recycleBinEnabled;
|
|
|
|
int historyMaxItems;
|
|
|
|
int historyMaxSize;
|
|
|
|
int masterKeyChangeRec;
|
|
|
|
int masterKeyChangeForce;
|
|
|
|
|
|
|
|
bool protectTitle;
|
|
|
|
bool protectUsername;
|
|
|
|
bool protectPassword;
|
|
|
|
bool protectUrl;
|
|
|
|
bool protectNotes;
|
|
|
|
};
|
|
|
|
|
2021-11-09 20:29:36 -05:00
|
|
|
struct CustomIconData
|
|
|
|
{
|
|
|
|
QByteArray data;
|
|
|
|
QString name;
|
|
|
|
QDateTime lastModified;
|
|
|
|
|
|
|
|
bool operator==(const CustomIconData& rhs) const
|
|
|
|
{
|
|
|
|
// Compare only actual icon data
|
|
|
|
return data == rhs.data;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-03-05 22:59:07 -05:00
|
|
|
void init();
|
|
|
|
void clear();
|
|
|
|
|
2010-08-07 09:10:44 -04:00
|
|
|
QString generator() const;
|
|
|
|
QString name() const;
|
|
|
|
QDateTime nameChanged() const;
|
|
|
|
QString description() const;
|
|
|
|
QDateTime descriptionChanged() const;
|
|
|
|
QString defaultUserName() const;
|
2010-08-12 15:38:59 -04:00
|
|
|
QDateTime defaultUserNameChanged() const;
|
2018-01-05 10:41:29 -05:00
|
|
|
QDateTime settingsChanged() const;
|
2010-08-07 09:10:44 -04:00
|
|
|
int maintenanceHistoryDays() const;
|
2020-01-26 21:38:43 -05:00
|
|
|
QString color() const;
|
2010-08-07 09:10:44 -04:00
|
|
|
bool protectTitle() const;
|
|
|
|
bool protectUsername() const;
|
|
|
|
bool protectPassword() const;
|
|
|
|
bool protectUrl() const;
|
|
|
|
bool protectNotes() const;
|
2021-11-09 20:29:36 -05:00
|
|
|
const CustomIconData& customIcon(const QUuid& uuid) const;
|
2020-05-29 10:00:07 -04:00
|
|
|
bool hasCustomIcon(const QUuid& uuid) const;
|
2018-03-22 17:56:05 -04:00
|
|
|
QList<QUuid> customIconsOrder() const;
|
2010-08-07 09:10:44 -04:00
|
|
|
bool recycleBinEnabled() const;
|
2012-04-18 17:17:29 -04:00
|
|
|
Group* recycleBin();
|
2010-08-13 12:08:06 -04:00
|
|
|
const Group* recycleBin() const;
|
2010-08-07 09:10:44 -04:00
|
|
|
QDateTime recycleBinChanged() const;
|
2010-08-13 12:08:06 -04:00
|
|
|
const Group* entryTemplatesGroup() const;
|
2010-08-07 09:10:44 -04:00
|
|
|
QDateTime entryTemplatesGroupChanged() const;
|
2010-08-13 12:08:06 -04:00
|
|
|
const Group* lastSelectedGroup() const;
|
|
|
|
const Group* lastTopVisibleGroup() const;
|
2020-07-01 19:16:40 -04:00
|
|
|
QDateTime databaseKeyChanged() const;
|
|
|
|
int databaseKeyChangeRec() const;
|
|
|
|
int databaseKeyChangeForce() const;
|
2012-04-21 10:45:46 -04:00
|
|
|
int historyMaxItems() const;
|
|
|
|
int historyMaxSize() const;
|
2018-02-18 15:01:22 -05:00
|
|
|
CustomData* customData();
|
|
|
|
const CustomData* customData() const;
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2012-05-14 13:10:42 -04:00
|
|
|
static const int DefaultHistoryMaxItems;
|
|
|
|
static const int DefaultHistoryMaxSize;
|
2012-05-10 07:15:43 -04:00
|
|
|
|
2010-08-07 09:10:44 -04:00
|
|
|
void setGenerator(const QString& value);
|
|
|
|
void setName(const QString& value);
|
|
|
|
void setNameChanged(const QDateTime& value);
|
|
|
|
void setDescription(const QString& value);
|
|
|
|
void setDescriptionChanged(const QDateTime& value);
|
|
|
|
void setDefaultUserName(const QString& value);
|
2010-08-12 15:38:59 -04:00
|
|
|
void setDefaultUserNameChanged(const QDateTime& value);
|
2018-01-05 10:41:29 -05:00
|
|
|
void setSettingsChanged(const QDateTime& value);
|
2010-08-07 09:10:44 -04:00
|
|
|
void setMaintenanceHistoryDays(int value);
|
2020-01-26 21:38:43 -05:00
|
|
|
void setColor(const QString& value);
|
2010-08-07 09:10:44 -04:00
|
|
|
void setProtectTitle(bool value);
|
|
|
|
void setProtectUsername(bool value);
|
|
|
|
void setProtectPassword(bool value);
|
|
|
|
void setProtectUrl(bool value);
|
|
|
|
void setProtectNotes(bool value);
|
2021-11-09 20:29:36 -05:00
|
|
|
void addCustomIcon(const QUuid& uuid, const CustomIconData& iconData);
|
|
|
|
void addCustomIcon(const QUuid& uuid,
|
|
|
|
const QByteArray& iconBytes,
|
|
|
|
const QString& name = {},
|
|
|
|
const QDateTime& lastModified = {});
|
2018-03-22 17:56:05 -04:00
|
|
|
void removeCustomIcon(const QUuid& uuid);
|
|
|
|
void copyCustomIcons(const QSet<QUuid>& iconList, const Metadata* otherMetadata);
|
2021-03-13 14:07:49 -05:00
|
|
|
QUuid findCustomIcon(const QByteArray& candidate);
|
2010-08-07 09:10:44 -04:00
|
|
|
void setRecycleBinEnabled(bool value);
|
2010-08-13 12:08:06 -04:00
|
|
|
void setRecycleBin(Group* group);
|
2010-08-07 09:10:44 -04:00
|
|
|
void setRecycleBinChanged(const QDateTime& value);
|
2010-08-13 12:08:06 -04:00
|
|
|
void setEntryTemplatesGroup(Group* group);
|
2010-08-07 09:10:44 -04:00
|
|
|
void setEntryTemplatesGroupChanged(const QDateTime& value);
|
2010-08-13 12:08:06 -04:00
|
|
|
void setLastSelectedGroup(Group* group);
|
|
|
|
void setLastTopVisibleGroup(Group* group);
|
2020-07-01 19:16:40 -04:00
|
|
|
void setDatabaseKeyChanged(const QDateTime& value);
|
2010-09-25 06:41:00 -04:00
|
|
|
void setMasterKeyChangeRec(int value);
|
|
|
|
void setMasterKeyChangeForce(int value);
|
2012-04-21 10:45:46 -04:00
|
|
|
void setHistoryMaxItems(int value);
|
|
|
|
void setHistoryMaxSize(int value);
|
2012-04-11 09:57:11 -04:00
|
|
|
void setUpdateDatetime(bool value);
|
2022-09-07 19:25:23 -04:00
|
|
|
void addSavedSearch(const QString& name, const QString& searchtext);
|
|
|
|
void deleteSavedSearch(const QString& name);
|
|
|
|
QVariantMap savedSearches();
|
2013-11-22 04:28:11 -05:00
|
|
|
/*
|
|
|
|
* Copy all attributes from other except:
|
|
|
|
* - Group pointers/uuids
|
2020-07-01 19:16:40 -04:00
|
|
|
* - Database key changed date
|
2013-11-22 04:28:11 -05:00
|
|
|
* - Custom icons
|
|
|
|
* - Custom fields
|
2018-01-05 10:41:29 -05:00
|
|
|
* - Settings changed date
|
2013-11-22 04:28:11 -05:00
|
|
|
*/
|
|
|
|
void copyAttributesFrom(const Metadata* other);
|
2010-08-07 09:10:44 -04:00
|
|
|
|
|
|
|
private:
|
2012-04-21 17:54:15 -04:00
|
|
|
template <class P, class V> bool set(P& property, const V& value);
|
|
|
|
template <class P, class V> bool set(P& property, const V& value, QDateTime& dateTime);
|
2012-04-11 09:57:11 -04:00
|
|
|
|
2021-03-13 14:07:49 -05:00
|
|
|
QByteArray hashIcon(const QByteArray& iconData);
|
2017-09-24 17:53:42 -04:00
|
|
|
|
2013-11-22 04:28:11 -05:00
|
|
|
MetadataData m_data;
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2018-03-22 17:56:05 -04:00
|
|
|
QList<QUuid> m_customIconsOrder;
|
2021-11-09 20:29:36 -05:00
|
|
|
QHash<QUuid, CustomIconData> m_customIcons;
|
2018-03-22 17:56:05 -04:00
|
|
|
QHash<QByteArray, QUuid> m_customIconsHashes;
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2012-04-21 17:54:15 -04:00
|
|
|
QPointer<Group> m_recycleBin;
|
2010-08-07 09:10:44 -04:00
|
|
|
QDateTime m_recycleBinChanged;
|
2012-04-21 17:54:15 -04:00
|
|
|
QPointer<Group> m_entryTemplatesGroup;
|
2010-08-07 09:10:44 -04:00
|
|
|
QDateTime m_entryTemplatesGroupChanged;
|
2012-04-21 17:54:15 -04:00
|
|
|
QPointer<Group> m_lastSelectedGroup;
|
|
|
|
QPointer<Group> m_lastTopVisibleGroup;
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2010-09-25 06:41:00 -04:00
|
|
|
QDateTime m_masterKeyChanged;
|
2018-01-05 10:41:29 -05:00
|
|
|
QDateTime m_settingsChanged;
|
2010-09-25 06:41:00 -04:00
|
|
|
|
2018-02-18 15:01:22 -05:00
|
|
|
QPointer<CustomData> m_customData;
|
2012-04-11 09:57:11 -04:00
|
|
|
|
|
|
|
bool m_updateDatetime;
|
2010-08-07 09:10:44 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // KEEPASSX_METADATA_H
|