2010-08-07 09:10:44 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
2017-06-09 17:40:36 -04:00
|
|
|
* Copyright (C) 2017 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_GROUP_H
|
|
|
|
#define KEEPASSX_GROUP_H
|
|
|
|
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QImage>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QPixmapCache>
|
|
|
|
#include <QPointer>
|
2010-08-12 15:38:59 -04:00
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
#include "core/CustomData.h"
|
2011-07-08 08:51:14 -04:00
|
|
|
#include "core/Database.h"
|
|
|
|
#include "core/Entry.h"
|
|
|
|
#include "core/TimeInfo.h"
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
class Group : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-03-31 16:01:30 -04:00
|
|
|
enum TriState
|
|
|
|
{
|
|
|
|
Inherit,
|
|
|
|
Enable,
|
|
|
|
Disable
|
|
|
|
};
|
|
|
|
enum MergeMode
|
|
|
|
{
|
2018-09-30 08:45:06 -04:00
|
|
|
Default, // Determine merge strategy from parent or fallback (Synchronize)
|
|
|
|
Duplicate, // lossy strategy regarding deletions, duplicate older changes in a new entry
|
|
|
|
KeepLocal, // merge history forcing local as top regardless of age
|
|
|
|
KeepRemote, // merge history forcing remote as top regardless of age
|
|
|
|
KeepNewer, // merge history
|
|
|
|
Synchronize, // merge history keeping most recent as top entry and appling deletions
|
2018-03-31 16:01:30 -04:00
|
|
|
};
|
2011-07-07 06:45:14 -04:00
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
enum CloneFlag
|
|
|
|
{
|
|
|
|
CloneNoFlags = 0,
|
|
|
|
CloneNewUuid = 1, // generate a random uuid for the clone
|
|
|
|
CloneResetTimeInfo = 2, // set all TimeInfo attributes to the current time
|
|
|
|
CloneIncludeEntries = 4, // clone the group entries
|
2017-11-03 16:29:42 -04:00
|
|
|
};
|
|
|
|
Q_DECLARE_FLAGS(CloneFlags, CloneFlag)
|
|
|
|
|
2013-04-04 15:48:55 -04:00
|
|
|
struct GroupData
|
|
|
|
{
|
|
|
|
QString name;
|
|
|
|
QString notes;
|
|
|
|
int iconNumber;
|
2018-03-22 17:56:05 -04:00
|
|
|
QUuid customIcon;
|
2013-04-04 15:48:55 -04:00
|
|
|
TimeInfo timeInfo;
|
|
|
|
bool isExpanded;
|
|
|
|
QString defaultAutoTypeSequence;
|
|
|
|
Group::TriState autoTypeEnabled;
|
|
|
|
Group::TriState searchingEnabled;
|
2016-11-07 22:37:42 -05:00
|
|
|
Group::MergeMode mergeMode;
|
2018-09-30 08:45:06 -04:00
|
|
|
|
|
|
|
bool operator==(const GroupData& other) const;
|
|
|
|
bool operator!=(const GroupData& other) const;
|
|
|
|
bool equals(const GroupData& other, CompareItemOptions options) const;
|
2013-04-04 15:48:55 -04:00
|
|
|
};
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
Group();
|
2010-08-18 10:22:48 -04:00
|
|
|
~Group();
|
2012-07-21 05:57:00 -04:00
|
|
|
|
|
|
|
static Group* createRecycleBin();
|
|
|
|
|
2018-03-22 17:56:05 -04:00
|
|
|
const QUuid& uuid() const;
|
2018-09-30 08:45:06 -04:00
|
|
|
const QString uuidToHex() const;
|
2010-08-12 15:38:59 -04:00
|
|
|
QString name() const;
|
|
|
|
QString notes() const;
|
2012-01-01 15:52:54 -05:00
|
|
|
QImage icon() const;
|
|
|
|
QPixmap iconPixmap() const;
|
2016-01-24 12:45:10 -05:00
|
|
|
QPixmap iconScaledPixmap() const;
|
2010-08-18 16:57:26 -04:00
|
|
|
int iconNumber() const;
|
2018-03-22 17:56:05 -04:00
|
|
|
const QUuid& iconUuid() const;
|
2018-09-30 08:45:06 -04:00
|
|
|
const TimeInfo& timeInfo() const;
|
2010-08-12 15:38:59 -04:00
|
|
|
bool isExpanded() const;
|
|
|
|
QString defaultAutoTypeSequence() const;
|
2016-11-11 16:26:07 -05:00
|
|
|
QString effectiveAutoTypeSequence() const;
|
2011-07-07 06:45:14 -04:00
|
|
|
Group::TriState autoTypeEnabled() const;
|
2012-05-13 07:33:55 -04:00
|
|
|
Group::TriState searchingEnabled() const;
|
2016-11-07 22:37:42 -05:00
|
|
|
Group::MergeMode mergeMode() const;
|
2014-04-26 12:27:52 -04:00
|
|
|
bool resolveSearchingEnabled() const;
|
2014-04-26 12:30:22 -04:00
|
|
|
bool resolveAutoTypeEnabled() const;
|
2010-08-12 15:38:59 -04:00
|
|
|
Entry* lastTopVisibleEntry() const;
|
2012-05-15 13:58:10 -04:00
|
|
|
bool isExpired() const;
|
2019-01-30 09:48:22 -05:00
|
|
|
bool isRecycled();
|
2018-02-18 15:01:22 -05:00
|
|
|
CustomData* customData();
|
|
|
|
const CustomData* customData() const;
|
2010-08-12 15:38:59 -04:00
|
|
|
|
2018-09-30 08:45:06 -04:00
|
|
|
bool equals(const Group* other, CompareItemOptions options) const;
|
|
|
|
|
2012-05-15 10:47:46 -04:00
|
|
|
static const int DefaultIconNumber;
|
2012-07-21 05:57:00 -04:00
|
|
|
static const int RecycleBinIconNumber;
|
2017-11-21 14:02:21 -05:00
|
|
|
static CloneFlags DefaultCloneFlags;
|
|
|
|
static Entry::CloneFlags DefaultEntryCloneFlags;
|
2018-01-18 17:45:09 -05:00
|
|
|
static const QString RootAutoTypeSequence;
|
2012-05-15 10:47:46 -04:00
|
|
|
|
2017-06-21 17:34:49 -04:00
|
|
|
Group* findChildByName(const QString& name);
|
2018-09-30 08:45:06 -04:00
|
|
|
Entry* findEntryByUuid(const QUuid& uuid) const;
|
2018-10-28 07:49:32 -04:00
|
|
|
Entry* findEntryByPath(const QString& entryPath);
|
2018-11-22 05:47:31 -05:00
|
|
|
Entry* findEntryBySearchTerm(const QString& term, EntryReferenceType referenceType);
|
2018-09-30 08:45:06 -04:00
|
|
|
Group* findGroupByUuid(const QUuid& uuid);
|
2018-10-28 07:49:32 -04:00
|
|
|
Group* findGroupByPath(const QString& groupPath);
|
|
|
|
QStringList locate(const QString& locateTerm, const QString& currentPath = {"/"}) const;
|
|
|
|
Entry* addEntryWithPath(const QString& entryPath);
|
2018-03-22 17:56:05 -04:00
|
|
|
void setUuid(const QUuid& uuid);
|
2010-08-12 15:38:59 -04:00
|
|
|
void setName(const QString& name);
|
|
|
|
void setNotes(const QString& notes);
|
|
|
|
void setIcon(int iconNumber);
|
2018-03-22 17:56:05 -04:00
|
|
|
void setIcon(const QUuid& uuid);
|
2010-08-12 15:38:59 -04:00
|
|
|
void setTimeInfo(const TimeInfo& timeInfo);
|
|
|
|
void setExpanded(bool expanded);
|
|
|
|
void setDefaultAutoTypeSequence(const QString& sequence);
|
2011-07-07 06:45:14 -04:00
|
|
|
void setAutoTypeEnabled(TriState enable);
|
|
|
|
void setSearchingEnabled(TriState enable);
|
2010-08-12 15:38:59 -04:00
|
|
|
void setLastTopVisibleEntry(Entry* entry);
|
2013-03-26 18:53:34 -04:00
|
|
|
void setExpires(bool value);
|
2012-05-18 04:52:05 -04:00
|
|
|
void setExpiryTime(const QDateTime& dateTime);
|
2016-11-07 22:37:42 -05:00
|
|
|
void setMergeMode(MergeMode newMode);
|
2010-08-12 15:38:59 -04:00
|
|
|
|
2018-09-30 08:45:06 -04:00
|
|
|
bool canUpdateTimeinfo() const;
|
2012-04-11 12:00:28 -04:00
|
|
|
void setUpdateTimeinfo(bool value);
|
|
|
|
|
2010-08-23 15:30:20 -04:00
|
|
|
Group* parentGroup();
|
2010-08-15 06:31:48 -04:00
|
|
|
const Group* parentGroup() const;
|
2010-08-18 04:27:40 -04:00
|
|
|
void setParent(Group* parent, int index = -1);
|
2019-06-18 20:42:19 -04:00
|
|
|
QStringList hierarchy(int height = -1) const;
|
2019-06-18 16:58:47 -04:00
|
|
|
bool hasChildren() const;
|
2010-08-12 15:38:59 -04:00
|
|
|
|
2012-04-21 18:29:39 -04:00
|
|
|
Database* database();
|
2010-08-14 06:24:35 -04:00
|
|
|
const Database* database() const;
|
2010-08-15 06:31:48 -04:00
|
|
|
QList<Group*> children();
|
2010-08-25 08:00:46 -04:00
|
|
|
const QList<Group*>& children() const;
|
2010-08-15 06:31:48 -04:00
|
|
|
QList<Entry*> entries();
|
2010-08-25 08:00:46 -04:00
|
|
|
const QList<Entry*>& entries() const;
|
2018-11-22 05:47:31 -05:00
|
|
|
Entry* findEntryRecursive(const QString& text, EntryReferenceType referenceType, Group* group = nullptr);
|
2018-12-24 18:15:46 -05:00
|
|
|
QList<Entry*> referencesRecursive(const Entry* entry) const;
|
2012-05-11 18:01:58 -04:00
|
|
|
QList<Entry*> entriesRecursive(bool includeHistoryItems = false) const;
|
2012-05-12 07:22:41 -04:00
|
|
|
QList<const Group*> groupsRecursive(bool includeSelf) const;
|
2015-01-11 10:20:24 -05:00
|
|
|
QList<Group*> groupsRecursive(bool includeSelf);
|
2018-03-22 17:56:05 -04:00
|
|
|
QSet<QUuid> customIconsRecursive() const;
|
2018-10-30 08:42:35 -04:00
|
|
|
|
2017-11-21 14:03:24 -05:00
|
|
|
Group* clone(Entry::CloneFlags entryFlags = DefaultEntryCloneFlags,
|
|
|
|
CloneFlags groupFlags = DefaultCloneFlags) const;
|
2017-11-21 14:02:21 -05:00
|
|
|
|
2013-04-14 08:54:56 -04:00
|
|
|
void copyDataFrom(const Group* other);
|
2019-06-18 20:42:19 -04:00
|
|
|
QString print(bool recursive = false, bool flatten = false, int depth = 0);
|
2012-04-21 13:06:28 -04:00
|
|
|
|
2018-09-30 08:45:06 -04:00
|
|
|
void addEntry(Entry* entry);
|
|
|
|
void removeEntry(Entry* entry);
|
2018-10-30 08:42:35 -04:00
|
|
|
|
2019-06-19 10:02:07 -04:00
|
|
|
void applyGroupIconOnCreateTo(Entry* entry);
|
2019-02-21 00:51:23 -05:00
|
|
|
void applyGroupIconTo(Entry* entry);
|
2019-06-19 10:02:07 -04:00
|
|
|
void applyGroupIconTo(Group* other);
|
|
|
|
void applyGroupIconToChildGroups();
|
|
|
|
void applyGroupIconToChildEntries();
|
2019-02-21 00:51:23 -05:00
|
|
|
|
2019-06-18 16:58:47 -04:00
|
|
|
void sortChildrenRecursively(bool reverse = false);
|
|
|
|
|
2017-03-10 09:58:42 -05:00
|
|
|
signals:
|
2018-11-22 05:47:31 -05:00
|
|
|
void groupDataChanged(Group* group);
|
|
|
|
void groupAboutToAdd(Group* group, int index);
|
|
|
|
void groupAdded();
|
|
|
|
void groupAboutToRemove(Group* group);
|
|
|
|
void groupRemoved();
|
2012-04-23 10:57:08 -04:00
|
|
|
void aboutToMove(Group* group, Group* toGroup, int index);
|
2018-11-22 05:47:31 -05:00
|
|
|
void groupMoved();
|
|
|
|
void groupModified();
|
2010-08-23 15:30:20 -04:00
|
|
|
void entryAboutToAdd(Entry* entry);
|
2012-07-21 12:19:40 -04:00
|
|
|
void entryAdded(Entry* entry);
|
2010-08-23 15:30:20 -04:00
|
|
|
void entryAboutToRemove(Entry* entry);
|
2012-07-21 12:19:40 -04:00
|
|
|
void entryRemoved(Entry* entry);
|
2010-08-23 15:30:20 -04:00
|
|
|
void entryDataChanged(Entry* entry);
|
2010-08-15 09:03:47 -04:00
|
|
|
|
2018-02-06 10:37:06 -05:00
|
|
|
private slots:
|
|
|
|
void updateTimeinfo();
|
|
|
|
|
2010-08-07 09:10:44 -04:00
|
|
|
private:
|
2012-08-01 04:40:38 -04:00
|
|
|
template <class P, class V> bool set(P& property, const V& value);
|
2012-04-11 12:00:28 -04:00
|
|
|
|
2011-07-08 07:57:02 -04:00
|
|
|
void setParent(Database* db);
|
|
|
|
|
2018-11-22 05:47:31 -05:00
|
|
|
void connectDatabaseSignalsRecursive(Database* db);
|
2011-07-09 15:54:01 -04:00
|
|
|
void cleanupParent();
|
2012-04-21 13:06:28 -04:00
|
|
|
void recCreateDelObjects();
|
2010-08-14 06:24:35 -04:00
|
|
|
|
2018-10-28 07:49:32 -04:00
|
|
|
Entry* findEntryByPathRecursive(const QString& entryPath, const QString& basePath);
|
|
|
|
Group* findGroupByPathRecursive(const QString& groupPath, const QString& basePath);
|
2018-09-18 22:44:39 -04:00
|
|
|
|
2011-07-09 15:54:01 -04:00
|
|
|
QPointer<Database> m_db;
|
2018-03-22 17:56:05 -04:00
|
|
|
QUuid m_uuid;
|
2013-04-04 15:48:55 -04:00
|
|
|
GroupData m_data;
|
2012-04-21 18:10:04 -04:00
|
|
|
QPointer<Entry> m_lastTopVisibleEntry;
|
2010-08-12 15:38:59 -04:00
|
|
|
QList<Group*> m_children;
|
|
|
|
QList<Entry*> m_entries;
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2018-02-18 15:01:22 -05:00
|
|
|
QPointer<CustomData> m_customData;
|
2018-02-06 10:37:06 -05:00
|
|
|
|
2011-07-09 15:54:01 -04:00
|
|
|
QPointer<Group> m_parent;
|
2011-07-08 07:57:02 -04:00
|
|
|
|
2012-04-11 12:00:28 -04:00
|
|
|
bool m_updateTimeinfo;
|
|
|
|
|
2011-07-08 07:57:02 -04:00
|
|
|
friend void Database::setRootGroup(Group* group);
|
2011-07-09 15:54:01 -04:00
|
|
|
friend Entry::~Entry();
|
2012-05-02 11:04:03 -04:00
|
|
|
friend void Entry::setGroup(Group* group);
|
2010-08-07 09:10:44 -04:00
|
|
|
};
|
|
|
|
|
2017-11-03 16:29:42 -04:00
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(Group::CloneFlags)
|
|
|
|
|
2010-08-07 09:10:44 -04:00
|
|
|
#endif // KEEPASSX_GROUP_H
|