keepassxc/src/core/Group.h

219 lines
6.5 KiB
C++
Raw Normal View History

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
#include <QImage>
#include <QPixmap>
#include <QPixmapCache>
#include <QPointer>
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
class Group : public QObject
{
Q_OBJECT
public:
2018-03-31 16:01:30 -04:00
enum TriState
{
Inherit,
Enable,
Disable
};
enum MergeMode
{
ModeInherit,
KeepBoth,
KeepNewer,
KeepExisting
};
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)
struct GroupData
{
QString name;
QString notes;
int iconNumber;
2018-03-22 17:56:05 -04:00
QUuid customIcon;
TimeInfo timeInfo;
bool isExpanded;
QString defaultAutoTypeSequence;
Group::TriState autoTypeEnabled;
Group::TriState searchingEnabled;
Group::MergeMode mergeMode;
};
Group();
2010-08-18 10:22:48 -04:00
~Group();
static Group* createRecycleBin();
2018-03-22 17:56:05 -04:00
const QUuid& uuid() const;
QString name() const;
QString notes() const;
QImage icon() const;
QPixmap iconPixmap() const;
QPixmap iconScaledPixmap() const;
int iconNumber() const;
2018-03-22 17:56:05 -04:00
const QUuid& iconUuid() const;
TimeInfo timeInfo() const;
bool isExpanded() const;
QString defaultAutoTypeSequence() const;
QString effectiveAutoTypeSequence() const;
Group::TriState autoTypeEnabled() const;
2012-05-13 07:33:55 -04:00
Group::TriState searchingEnabled() const;
Group::MergeMode mergeMode() const;
bool resolveSearchingEnabled() const;
2014-04-26 12:30:22 -04:00
bool resolveAutoTypeEnabled() const;
Entry* lastTopVisibleEntry() const;
bool isExpired() const;
CustomData* customData();
const CustomData* customData() const;
static const int DefaultIconNumber;
static const int RecycleBinIconNumber;
2017-11-21 14:02:21 -05:00
static CloneFlags DefaultCloneFlags;
static Entry::CloneFlags DefaultEntryCloneFlags;
static const QString RootAutoTypeSequence;
Group* findChildByName(const QString& name);
2018-03-22 17:56:05 -04:00
Group* findChildByUuid(const QUuid& uuid);
2017-05-19 14:04:11 -04:00
Entry* findEntry(QString entryId);
2018-03-22 17:56:05 -04:00
Entry* findEntryByUuid(const QUuid& uuid);
2017-05-19 14:04:11 -04:00
Entry* findEntryByPath(QString entryPath, QString basePath = QString(""));
Group* findGroupByPath(QString groupPath, QString basePath = QString("/"));
QStringList locate(QString locateTerm, QString currentPath = QString("/"));
Entry* addEntryWithPath(QString entryPath);
2018-03-22 17:56:05 -04:00
void setUuid(const QUuid& uuid);
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);
void setTimeInfo(const TimeInfo& timeInfo);
void setExpanded(bool expanded);
void setDefaultAutoTypeSequence(const QString& sequence);
void setAutoTypeEnabled(TriState enable);
void setSearchingEnabled(TriState enable);
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);
void setMergeMode(MergeMode newMode);
2012-04-11 12:00:28 -04:00
void setUpdateTimeinfo(bool value);
Group* parentGroup();
const Group* parentGroup() const;
void setParent(Group* parent, int index = -1);
2017-12-25 08:53:22 -05:00
QStringList hierarchy() const;
Database* database();
2010-08-14 06:24:35 -04:00
const Database* database() const;
QList<Group*> children();
2010-08-25 08:00:46 -04:00
const QList<Group*>& children() const;
QList<Entry*> entries();
2010-08-25 08:00:46 -04:00
const QList<Entry*>& entries() const;
QList<Entry*> entriesRecursive(bool includeHistoryItems = false) const;
2012-05-12 07:22:41 -04:00
QList<const Group*> groupsRecursive(bool includeSelf) const;
QList<Group*> groupsRecursive(bool includeSelf);
2018-03-22 17:56:05 -04:00
QSet<QUuid> customIconsRecursive() const;
2013-07-04 07:59:32 -04:00
/**
2017-11-21 14:02:21 -05:00
* Creates a duplicate of this group.
2013-07-04 07:59:32 -04:00
* Note that you need to copy the custom icons manually when inserting the
* new group into another database.
*/
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
void copyDataFrom(const Group* other);
void merge(const Group* other);
QString print(bool recursive = false, int depth = 0);
2012-04-21 13:06:28 -04:00
signals:
void dataChanged(Group* group);
2010-08-18 10:22:48 -04:00
void aboutToAdd(Group* group, int index);
void added();
void aboutToRemove(Group* group);
2010-08-18 10:22:48 -04:00
void removed();
/**
* Group moved within the database.
*/
void aboutToMove(Group* group, Group* toGroup, int index);
void moved();
2010-08-18 10:22:48 -04:00
void entryAboutToAdd(Entry* entry);
void entryAdded(Entry* entry);
void entryAboutToRemove(Entry* entry);
void entryRemoved(Entry* entry);
2010-08-18 10:22:48 -04:00
void entryDataChanged(Entry* entry);
2010-08-15 09:03:47 -04:00
2012-04-11 12:00:28 -04:00
void modified();
private slots:
void updateTimeinfo();
2010-08-07 09:10:44 -04:00
private:
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 addEntry(Entry* entry);
void removeEntry(Entry* entry);
void setParent(Database* db);
void markOlderEntry(Entry* entry);
2017-11-03 16:29:42 -04:00
void resolveEntryConflict(Entry* existingEntry, Entry* otherEntry);
void resolveGroupConflict(Group* existingGroup, Group* otherGroup);
2011-07-08 07:57:02 -04:00
2010-08-14 06:24:35 -04:00
void recSetDatabase(Database* db);
void cleanupParent();
2012-04-21 13:06:28 -04:00
void recCreateDelObjects();
2010-08-14 06:24:35 -04:00
QPointer<Database> m_db;
2018-03-22 17:56:05 -04:00
QUuid m_uuid;
GroupData m_data;
QPointer<Entry> m_lastTopVisibleEntry;
QList<Group*> m_children;
QList<Entry*> m_entries;
2010-08-07 09:10:44 -04:00
QPointer<CustomData> m_customData;
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);
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