Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Group.h « core « src - github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cc923e43b4a3e48b01fa0dd9bf64b3ee22e0d52a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
 *  Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
 *  Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
 *
 *  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>

#include "core/Database.h"
#include "core/Entry.h"
#include "core/CustomData.h"
#include "core/TimeInfo.h"
#include "core/Uuid.h"

class Group : public QObject
{
    Q_OBJECT

public:
    enum TriState { Inherit, Enable, Disable };
    enum MergeMode { ModeInherit, KeepBoth, KeepNewer, KeepExisting };

    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
    };
    Q_DECLARE_FLAGS(CloneFlags, CloneFlag)

    struct GroupData
    {
        QString name;
        QString notes;
        int iconNumber;
        Uuid customIcon;
        TimeInfo timeInfo;
        bool isExpanded;
        QString defaultAutoTypeSequence;
        Group::TriState autoTypeEnabled;
        Group::TriState searchingEnabled;
        Group::MergeMode mergeMode;
    };

    Group();
    ~Group();

    static Group* createRecycleBin();

    Uuid uuid() const;
    QString name() const;
    QString notes() const;
    QImage icon() const;
    QPixmap iconPixmap() const;
    QPixmap iconScaledPixmap() const;
    int iconNumber() const;
    Uuid iconUuid() const;
    TimeInfo timeInfo() const;
    bool isExpanded() const;
    QString defaultAutoTypeSequence() const;
    QString effectiveAutoTypeSequence() const;
    Group::TriState autoTypeEnabled() const;
    Group::TriState searchingEnabled() const;
    Group::MergeMode mergeMode() const;
    bool resolveSearchingEnabled() const;
    bool resolveAutoTypeEnabled() const;
    Entry* lastTopVisibleEntry() const;
    bool isExpired() const;
    CustomData* customData();
    const CustomData* customData() const;

    static const int DefaultIconNumber;
    static const int RecycleBinIconNumber;
    static CloneFlags DefaultCloneFlags;
    static Entry::CloneFlags DefaultEntryCloneFlags;
    static const QString RootAutoTypeSequence;

    Group* findChildByName(const QString& name);
    Group* findChildByUuid(const Uuid& uuid);
    Entry* findEntry(QString entryId);
    Entry* findEntryByUuid(const Uuid& uuid);
    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);
    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);
    void setAutoTypeEnabled(TriState enable);
    void setSearchingEnabled(TriState enable);
    void setLastTopVisibleEntry(Entry* entry);
    void setExpires(bool value);
    void setExpiryTime(const QDateTime& dateTime);
    void setMergeMode(MergeMode newMode);

    void setUpdateTimeinfo(bool value);

    Group* parentGroup();
    const Group* parentGroup() const;
    void setParent(Group* parent, int index = -1);
    QStringList hierarchy() const;

    Database* database();
    const Database* database() const;
    QList<Group*> children();
    const QList<Group*>& children() const;
    QList<Entry*> entries();
    const QList<Entry*>& entries() const;
    QList<Entry*> entriesRecursive(bool includeHistoryItems = false) const;
    QList<const Group*> groupsRecursive(bool includeSelf) const;
    QList<Group*> groupsRecursive(bool includeSelf);
    QSet<Uuid> customIconsRecursive() const;
    /**
     * Creates a duplicate of this group.
     * Note that you need to copy the custom icons manually when inserting the
     * new group into another database.
     */
    Group* clone(Entry::CloneFlags entryFlags = DefaultEntryCloneFlags,
                 CloneFlags groupFlags = DefaultCloneFlags) const;

    void copyDataFrom(const Group* other);
    void merge(const Group* other);
    QString print(bool recursive = false, int depth = 0);

signals:
    void dataChanged(Group* group);

    void aboutToAdd(Group* group, int index);
    void added();
    void aboutToRemove(Group* group);
    void removed();
    /**
     * Group moved within the database.
     */
    void aboutToMove(Group* group, Group* toGroup, int index);
    void moved();

    void entryAboutToAdd(Entry* entry);
    void entryAdded(Entry* entry);
    void entryAboutToRemove(Entry* entry);
    void entryRemoved(Entry* entry);

    void entryDataChanged(Entry* entry);

    void modified();

private slots:
    void updateTimeinfo();

private:
    template <class P, class V> bool set(P& property, const V& value);

    void addEntry(Entry* entry);
    void removeEntry(Entry* entry);
    void setParent(Database* db);
    void markOlderEntry(Entry* entry);
    void resolveEntryConflict(Entry* existingEntry, Entry* otherEntry);
    void resolveGroupConflict(Group* existingGroup, Group* otherGroup);

    void recSetDatabase(Database* db);
    void cleanupParent();
    void recCreateDelObjects();

    QPointer<Database> m_db;
    Uuid m_uuid;
    GroupData m_data;
    QPointer<Entry> m_lastTopVisibleEntry;
    QList<Group*> m_children;
    QList<Entry*> m_entries;

    QPointer<CustomData> m_customData;

    QPointer<Group> m_parent;

    bool m_updateTimeinfo;

    friend void Database::setRootGroup(Group* group);
    friend Entry::~Entry();
    friend void Entry::setGroup(Group* group);
};

Q_DECLARE_OPERATORS_FOR_FLAGS(Group::CloneFlags)

#endif // KEEPASSX_GROUP_H