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

Group.cpp « core « src - github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e5732c8f1445cba30519409a1b632c9c49d4f414 (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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/*
    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    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 of the License, or
    (at your option) any later version.

    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, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

*/

#include "Group.h"

#include "core/DatabaseIcons.h"
#include "core/Metadata.h"

Group::Group()
{
    m_parent = 0;
    m_db = 0;
    m_lastTopVisibleEntry = 0;

    m_iconNumber = 48;
    m_isExpanded = true;
    m_autoTypeEnabled = Inherit;
    m_searchingEnabled = Inherit;
}

Group::~Group()
{
    cleanupParent();
}

Uuid Group::uuid() const
{
    return m_uuid;
}

QString Group::name() const
{
    return m_name;
}

QString Group::notes() const
{
    return m_notes;
}

QIcon Group::icon() const
{
    if (m_customIcon.isNull()) {
        return DatabaseIcons::icon(m_iconNumber);
    }
    else {
        return m_db->metadata()->customIcon(m_customIcon);
    }
}

int Group::iconNumber() const
{
    return m_iconNumber;
}

Uuid Group::iconUuid() const
{
    return m_customIcon;
}

TimeInfo Group::timeInfo() const
{
    return m_timeInfo;
}

bool Group::isExpanded() const
{
    return m_isExpanded;
}

QString Group::defaultAutoTypeSequence() const
{
    return m_defaultAutoTypeSequence;
}

Group::TriState Group::autoTypeEnabled() const
{
    return m_autoTypeEnabled;
}

Group::TriState Group::searchingEnabed() const
{
    return m_searchingEnabled;
}

Entry* Group::lastTopVisibleEntry() const
{
    return m_lastTopVisibleEntry;
}

void Group::setUuid(const Uuid& uuid)
{
    m_uuid = uuid;
}

void Group::setName(const QString& name)
{
    m_name = name;

    Q_EMIT dataChanged(this);
}

void Group::setNotes(const QString& notes)
{
    m_notes = notes;
}

void Group::setIcon(int iconNumber)
{
    Q_ASSERT(iconNumber >= 0);

    m_iconNumber = iconNumber;
    m_customIcon = Uuid();

    Q_EMIT dataChanged(this);
}

void Group::setIcon(const Uuid& uuid)
{
    Q_ASSERT(!uuid.isNull());

    m_iconNumber = 0;
    m_customIcon = uuid;

    Q_EMIT dataChanged(this);
}

void Group::setTimeInfo(const TimeInfo& timeInfo)
{
    m_timeInfo = timeInfo;
}

void Group::setExpanded(bool expanded)
{
    m_isExpanded = expanded;
}

void Group::setDefaultAutoTypeSequence(const QString& sequence)
{
    m_defaultAutoTypeSequence = sequence;
}

void Group::setAutoTypeEnabled(TriState enable)
{
    m_autoTypeEnabled = enable;
}

void Group::setSearchingEnabled(TriState enable)
{
    m_searchingEnabled = enable;
}

void Group::setLastTopVisibleEntry(Entry* entry)
{
    m_lastTopVisibleEntry = entry;
}

Group* Group::parentGroup()
{
    return m_parent;
}

const Group* Group::parentGroup() const
{
    return m_parent;
}

void Group::setParent(Group* parent, int index)
{
    Q_ASSERT(parent);
    Q_ASSERT(index >= -1 && index <= parent->children().size());
    // setting a new parent for root groups is not allowed
    Q_ASSERT(!m_db || (m_db->rootGroup() != this));

    if (index == -1) {
        index = parent->children().size();
    }

    cleanupParent();

    m_parent = parent;

    if (m_db != parent->m_db) {
        recSetDatabase(parent->m_db);
    }

    QObject::setParent(parent);

    Q_EMIT aboutToAdd(this, index);

    parent->m_children.insert(index, this);

    Q_EMIT added();
}

void Group::setParent(Database* db)
{
    Q_ASSERT(db);

    cleanupParent();

    m_parent = 0;
    recSetDatabase(db);

    QObject::setParent(db);
}

const Database* Group::database() const
{
    return m_db;
}

QList<Group*> Group::children()
{
    return m_children;
}

const QList<Group*>& Group::children() const
{
    return m_children;
}

QList<Entry*> Group::entries()
{
    return m_entries;
}

const QList<Entry*>& Group::entries() const
{
    return m_entries;
}

void Group::addEntry(Entry *entry)
{
    Q_ASSERT(entry);

    Q_EMIT entryAboutToAdd(entry);

    m_entries << entry;
    connect(entry, SIGNAL(dataChanged(Entry*)), SIGNAL(entryDataChanged(Entry*)));

    Q_EMIT entryAdded();
}

void Group::removeEntry(Entry* entry)
{
    Q_EMIT entryAboutToRemove(entry);

    entry->disconnect(this);
    m_entries.removeAll(entry);

    Q_EMIT entryRemoved();
}

void Group::recSetDatabase(Database* db)
{
    disconnect(SIGNAL(dataChanged(Group*)), m_db);
    disconnect(SIGNAL(aboutToRemove(Group*)), m_db);
    disconnect(SIGNAL(removed()), m_db);
    disconnect(SIGNAL(aboutToAdd(Group*,int)), m_db);
    disconnect(SIGNAL(added()), m_db);

    connect(this, SIGNAL(dataChanged(Group*)), db, SIGNAL(groupDataChanged(Group*)));

    connect(this, SIGNAL(aboutToRemove(Group*)), db, SIGNAL(groupAboutToRemove(Group*)));
    connect(this, SIGNAL(removed()), db, SIGNAL(groupRemoved()));
    connect(this, SIGNAL(aboutToAdd(Group*,int)), db, SIGNAL(groupAboutToAdd(Group*,int)));
    connect(this, SIGNAL(added()), db, SIGNAL(groupAdded()));

    m_db = db;

    Q_FOREACH (Group* group, m_children) {
        group->recSetDatabase(db);
    }
}

void Group::cleanupParent()
{
    if (m_parent) {
        Q_EMIT aboutToRemove(this);
        m_parent->m_children.removeAll(this);
        Q_EMIT removed();
    }
}