2010-08-07 13:10:44 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
2017-06-09 21:40:36 +00:00
|
|
|
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
2010-08-07 13:10:44 +00: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 13:18:16 +00:00
|
|
|
#include <QImage>
|
|
|
|
|
#include <QPixmap>
|
|
|
|
|
#include <QPixmapCache>
|
|
|
|
|
#include <QPointer>
|
2010-08-12 19:38:59 +00:00
|
|
|
|
2011-07-08 12:51:14 +00:00
|
|
|
#include "core/Database.h"
|
|
|
|
|
#include "core/Entry.h"
|
|
|
|
|
#include "core/TimeInfo.h"
|
|
|
|
|
#include "core/Uuid.h"
|
2010-08-07 13:10:44 +00:00
|
|
|
|
2010-08-12 19:38:59 +00:00
|
|
|
class Group : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2011-07-07 10:45:14 +00:00
|
|
|
enum TriState { Inherit, Enable, Disable };
|
2016-11-08 03:37:42 +00:00
|
|
|
enum MergeMode { ModeInherit, KeepBoth, KeepNewer, KeepExisting };
|
2011-07-07 10:45:14 +00:00
|
|
|
|
2013-04-04 19:48:55 +00:00
|
|
|
struct GroupData
|
|
|
|
|
{
|
|
|
|
|
QString name;
|
|
|
|
|
QString notes;
|
|
|
|
|
int iconNumber;
|
|
|
|
|
Uuid customIcon;
|
|
|
|
|
TimeInfo timeInfo;
|
|
|
|
|
bool isExpanded;
|
|
|
|
|
QString defaultAutoTypeSequence;
|
|
|
|
|
Group::TriState autoTypeEnabled;
|
|
|
|
|
Group::TriState searchingEnabled;
|
2016-11-08 03:37:42 +00:00
|
|
|
Group::MergeMode mergeMode;
|
2013-04-04 19:48:55 +00:00
|
|
|
};
|
|
|
|
|
|
2010-08-12 19:38:59 +00:00
|
|
|
Group();
|
2010-08-18 14:22:48 +00:00
|
|
|
~Group();
|
2012-07-21 09:57:00 +00:00
|
|
|
|
|
|
|
|
static Group* createRecycleBin();
|
|
|
|
|
|
2010-08-12 19:38:59 +00:00
|
|
|
Uuid uuid() const;
|
|
|
|
|
QString name() const;
|
|
|
|
|
QString notes() const;
|
2012-01-01 20:52:54 +00:00
|
|
|
QImage icon() const;
|
|
|
|
|
QPixmap iconPixmap() const;
|
2016-01-24 17:45:10 +00:00
|
|
|
QPixmap iconScaledPixmap() const;
|
2010-08-18 20:57:26 +00:00
|
|
|
int iconNumber() const;
|
|
|
|
|
Uuid iconUuid() const;
|
2010-08-12 19:38:59 +00:00
|
|
|
TimeInfo timeInfo() const;
|
|
|
|
|
bool isExpanded() const;
|
|
|
|
|
QString defaultAutoTypeSequence() const;
|
2016-11-11 21:26:07 +00:00
|
|
|
QString effectiveAutoTypeSequence() const;
|
2011-07-07 10:45:14 +00:00
|
|
|
Group::TriState autoTypeEnabled() const;
|
2012-05-13 11:33:55 +00:00
|
|
|
Group::TriState searchingEnabled() const;
|
2016-11-08 03:37:42 +00:00
|
|
|
Group::MergeMode mergeMode() const;
|
2014-04-26 16:27:52 +00:00
|
|
|
bool resolveSearchingEnabled() const;
|
2014-04-26 16:30:22 +00:00
|
|
|
bool resolveAutoTypeEnabled() const;
|
2010-08-12 19:38:59 +00:00
|
|
|
Entry* lastTopVisibleEntry() const;
|
2012-05-15 17:58:10 +00:00
|
|
|
bool isExpired() const;
|
2010-08-12 19:38:59 +00:00
|
|
|
|
2012-05-15 14:47:46 +00:00
|
|
|
static const int DefaultIconNumber;
|
2012-07-21 09:57:00 +00:00
|
|
|
static const int RecycleBinIconNumber;
|
2012-05-15 14:47:46 +00:00
|
|
|
|
2017-06-21 21:34:49 +00:00
|
|
|
Group* findChildByName(const QString& name);
|
2017-05-19 18:04:11 +00:00
|
|
|
Entry* findEntry(QString entryId);
|
|
|
|
|
Entry* findEntryByUuid(const Uuid& uuid);
|
|
|
|
|
Entry* findEntryByPath(QString entryPath, QString basePath = QString(""));
|
2017-06-21 21:34:49 +00:00
|
|
|
Group* findGroupByPath(QString groupPath, QString basePath = QString("/"));
|
2017-08-05 16:20:26 +00:00
|
|
|
QStringList locate(QString locateTerm, QString currentPath = QString("/"));
|
2017-09-06 13:14:41 +00:00
|
|
|
Entry* addEntryWithPath(QString entryPath);
|
2010-08-12 19:38:59 +00:00
|
|
|
void setUuid(const Uuid& uuid);
|
|
|
|
|
void setName(const QString& name);
|
|
|
|
|
void setNotes(const QString& notes);
|
|
|
|
|
void setIcon(int iconNumber);
|
|
|
|
|
void setIcon(const Uuid& uuid);
|
|
|
|
|
void setTimeInfo(const TimeInfo& timeInfo);
|
|
|
|
|
void setExpanded(bool expanded);
|
|
|
|
|
void setDefaultAutoTypeSequence(const QString& sequence);
|
2011-07-07 10:45:14 +00:00
|
|
|
void setAutoTypeEnabled(TriState enable);
|
|
|
|
|
void setSearchingEnabled(TriState enable);
|
2010-08-12 19:38:59 +00:00
|
|
|
void setLastTopVisibleEntry(Entry* entry);
|
2013-03-26 22:53:34 +00:00
|
|
|
void setExpires(bool value);
|
2012-05-18 08:52:05 +00:00
|
|
|
void setExpiryTime(const QDateTime& dateTime);
|
2016-11-08 03:37:42 +00:00
|
|
|
void setMergeMode(MergeMode newMode);
|
2010-08-12 19:38:59 +00:00
|
|
|
|
2012-04-11 16:00:28 +00:00
|
|
|
void setUpdateTimeinfo(bool value);
|
|
|
|
|
|
2010-08-23 19:30:20 +00:00
|
|
|
Group* parentGroup();
|
2010-08-15 10:31:48 +00:00
|
|
|
const Group* parentGroup() const;
|
2010-08-18 08:27:40 +00:00
|
|
|
void setParent(Group* parent, int index = -1);
|
2017-08-17 19:02:21 +00:00
|
|
|
QStringList hierarchy();
|
2010-08-12 19:38:59 +00:00
|
|
|
|
2012-04-21 22:29:39 +00:00
|
|
|
Database* database();
|
2010-08-14 10:24:35 +00:00
|
|
|
const Database* database() const;
|
2010-08-15 10:31:48 +00:00
|
|
|
QList<Group*> children();
|
2010-08-25 12:00:46 +00:00
|
|
|
const QList<Group*>& children() const;
|
2010-08-15 10:31:48 +00:00
|
|
|
QList<Entry*> entries();
|
2010-08-25 12:00:46 +00:00
|
|
|
const QList<Entry*>& entries() const;
|
2012-05-11 22:01:58 +00:00
|
|
|
QList<Entry*> entriesRecursive(bool includeHistoryItems = false) const;
|
2012-05-12 11:22:41 +00:00
|
|
|
QList<const Group*> groupsRecursive(bool includeSelf) const;
|
2015-01-11 15:20:24 +00:00
|
|
|
QList<Group*> groupsRecursive(bool includeSelf);
|
2013-04-07 16:32:43 +00:00
|
|
|
QSet<Uuid> customIconsRecursive() const;
|
2013-07-04 11:59:32 +00:00
|
|
|
/**
|
2017-09-05 14:28:47 +00:00
|
|
|
* Creates a duplicate of this group including all child entries and groups (if not shallow).
|
2013-07-04 11:59:32 +00:00
|
|
|
* The exceptions are that the returned group doesn't have a parent group
|
|
|
|
|
* and all TimeInfo attributes are set to the current time.
|
|
|
|
|
* Note that you need to copy the custom icons manually when inserting the
|
|
|
|
|
* new group into another database.
|
|
|
|
|
*/
|
2017-09-05 14:28:47 +00:00
|
|
|
Group* clone(Entry::CloneFlags entryFlags = Entry::CloneNewUuid | Entry::CloneResetTimeInfo,
|
|
|
|
|
bool shallow = false) const;
|
2013-04-14 12:54:56 +00:00
|
|
|
void copyDataFrom(const Group* other);
|
2016-11-08 03:37:42 +00:00
|
|
|
void merge(const Group* other);
|
2017-07-17 19:16:53 +00:00
|
|
|
QString print(bool recursive = false, int depth = 0);
|
2012-04-21 17:06:28 +00:00
|
|
|
|
2017-03-10 14:58:42 +00:00
|
|
|
signals:
|
2010-08-23 19:30:20 +00:00
|
|
|
void dataChanged(Group* group);
|
2010-08-18 14:22:48 +00:00
|
|
|
|
2010-08-23 19:30:20 +00:00
|
|
|
void aboutToAdd(Group* group, int index);
|
2010-08-18 08:27:40 +00:00
|
|
|
void added();
|
2010-08-23 19:30:20 +00:00
|
|
|
void aboutToRemove(Group* group);
|
2010-08-18 14:22:48 +00:00
|
|
|
void removed();
|
2012-04-23 14:57:08 +00:00
|
|
|
/**
|
|
|
|
|
* Group moved within the database.
|
|
|
|
|
*/
|
|
|
|
|
void aboutToMove(Group* group, Group* toGroup, int index);
|
|
|
|
|
void moved();
|
2010-08-18 14:22:48 +00:00
|
|
|
|
2010-08-23 19:30:20 +00:00
|
|
|
void entryAboutToAdd(Entry* entry);
|
2012-07-21 16:19:40 +00:00
|
|
|
void entryAdded(Entry* entry);
|
2010-08-23 19:30:20 +00:00
|
|
|
void entryAboutToRemove(Entry* entry);
|
2012-07-21 16:19:40 +00:00
|
|
|
void entryRemoved(Entry* entry);
|
2010-08-18 14:22:48 +00:00
|
|
|
|
2010-08-23 19:30:20 +00:00
|
|
|
void entryDataChanged(Entry* entry);
|
2010-08-15 13:03:47 +00:00
|
|
|
|
2012-04-11 16:00:28 +00:00
|
|
|
void modified();
|
|
|
|
|
|
2010-08-07 13:10:44 +00:00
|
|
|
private:
|
2012-08-01 08:40:38 +00:00
|
|
|
template <class P, class V> bool set(P& property, const V& value);
|
2012-04-11 16:00:28 +00:00
|
|
|
|
2011-07-08 11:57:02 +00:00
|
|
|
void addEntry(Entry* entry);
|
|
|
|
|
void removeEntry(Entry* entry);
|
|
|
|
|
void setParent(Database* db);
|
2016-11-08 03:37:42 +00:00
|
|
|
void markOlderEntry(Entry* entry);
|
|
|
|
|
void resolveConflict(Entry* existingEntry, Entry* otherEntry);
|
2011-07-08 11:57:02 +00:00
|
|
|
|
2010-08-14 10:24:35 +00:00
|
|
|
void recSetDatabase(Database* db);
|
2011-07-09 19:54:01 +00:00
|
|
|
void cleanupParent();
|
2012-04-21 17:06:28 +00:00
|
|
|
void recCreateDelObjects();
|
2012-04-23 15:02:09 +00:00
|
|
|
void updateTimeinfo();
|
2010-08-14 10:24:35 +00:00
|
|
|
|
2011-07-09 19:54:01 +00:00
|
|
|
QPointer<Database> m_db;
|
2010-08-07 13:10:44 +00:00
|
|
|
Uuid m_uuid;
|
2013-04-04 19:48:55 +00:00
|
|
|
GroupData m_data;
|
2012-04-21 22:10:04 +00:00
|
|
|
QPointer<Entry> m_lastTopVisibleEntry;
|
2010-08-12 19:38:59 +00:00
|
|
|
QList<Group*> m_children;
|
|
|
|
|
QList<Entry*> m_entries;
|
2010-08-07 13:10:44 +00:00
|
|
|
|
2011-07-09 19:54:01 +00:00
|
|
|
QPointer<Group> m_parent;
|
2011-07-08 11:57:02 +00:00
|
|
|
|
2012-04-11 16:00:28 +00:00
|
|
|
bool m_updateTimeinfo;
|
|
|
|
|
|
2011-07-08 11:57:02 +00:00
|
|
|
friend void Database::setRootGroup(Group* group);
|
2011-07-09 19:54:01 +00:00
|
|
|
friend Entry::~Entry();
|
2012-05-02 15:04:03 +00:00
|
|
|
friend void Entry::setGroup(Group* group);
|
2010-08-07 13:10:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // KEEPASSX_GROUP_H
|