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

Entry.cpp « core « src - github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ac47a2fc3f9672f658b0417c4bccd3cde29d1203 (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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/*
 *  Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
 *
 *  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/>.
 */

#include "Entry.h"

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

const QStringList Entry::m_defaultAttibutes(QStringList() << "Title" << "URL" << "UserName" << "Password" << "Notes");

Entry::Entry()
{
    m_group = 0;
    m_db = 0;

    m_iconNumber = 0;
    m_autoTypeEnabled = true;
    m_autoTypeObfuscation = 0;

    Q_FOREACH (const QString& key, m_defaultAttibutes) {
        addAttribute(key, "");
    }
}

Entry::~Entry()
{
    // TODO notify group
    qDeleteAll(m_history);
}

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

QIcon Entry::icon() const
{
    if (m_customIcon.isNull()) {
        return DatabaseIcons::icon(m_iconNumber);
    }
    else {
        // TODO check if m_db is 0
        return m_db->metadata()->customIcon(m_customIcon);
    }
}

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

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

QColor Entry::foregroundColor() const
{
    return m_foregroundColor;
}

QColor Entry::backgroundColor() const
{
    return m_backgroundColor;
}

QString Entry::overrideUrl() const
{
    return m_overrideUrl;
}

QString Entry::tags() const
{
    return m_tags;
}

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

bool Entry::autoTypeEnabled() const
{
    return m_autoTypeEnabled;
}

int Entry::autoTypeObfuscation() const
{
    return m_autoTypeObfuscation;
}

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

const QList<AutoTypeAssociation>& Entry::autoTypeAssociations() const
{
    return m_autoTypeAssociations;
}

const QHash<QString, QString>& Entry::attributes() const
{
    return m_attributes;
}

const QHash<QString, QByteArray>& Entry::attachments() const
{
    return m_binaries;
}

bool Entry::isAttributeProtected(const QString& key) const
{
    return m_protectedAttributes.contains(key);
}

bool Entry::isAttachmentProtected(const QString& key) const
{
    return m_protectedAttachments.contains(key);
}

QString Entry::title() const
{
    return m_attributes.value("Title");
}

QString Entry::url() const
{
    return m_attributes.value("URL");
}

QString Entry::username() const
{
    return m_attributes.value("UserName");
}

QString Entry::password() const
{
    return m_attributes.value("Password");
}

QString Entry::notes() const
{
    return m_attributes.value("Notes");
}

void Entry::setUuid(const Uuid& uuid)
{
    Q_ASSERT(!uuid.isNull());

    m_uuid = uuid;
}

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

    m_iconNumber = iconNumber;
    m_customIcon = Uuid();
}

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

    m_iconNumber = 0;
    m_customIcon = uuid;
}

void Entry::setForegroundColor(const QColor& color)
{
    m_foregroundColor = color;
}

void Entry::setBackgroundColor(const QColor& color)
{
    m_backgroundColor = color;
}

void Entry::setOverrideUrl(const QString& url)
{
    m_overrideUrl = url;
}

void Entry::setTags(const QString& tags)
{
    m_tags = tags;
}

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

void Entry::setAutoTypeEnabled(bool enable)
{
    m_autoTypeEnabled = enable;
}

void Entry::setAutoTypeObfuscation(int obfuscation)
{
    m_autoTypeObfuscation = obfuscation;
}

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

void Entry::addAutoTypeAssociation(const AutoTypeAssociation& assoc)
{
    m_autoTypeAssociations << assoc;
}

void Entry::addAttribute(const QString& key, const QString& value, bool protect)
{
    m_attributes.insert(key, value);
    if (protect) {
        m_protectedAttributes.insert(key);
    }

    if (isDefaultAttributue(key)) {
        Q_EMIT dataChanged(this);
    }
}

void Entry::removeAttribute(const QString& key)
{
    Q_ASSERT(!isDefaultAttributue(key));

    m_attributes.remove(key);
    m_protectedAttributes.remove(key);
}

void Entry::addAttachment(const QString& key, const QByteArray& value, bool protect)
{
    m_binaries.insert(key, value);
    if (protect) {
        m_protectedAttachments.insert(key);
    }
}

void Entry::removeAttachment(const QString& key)
{
    m_binaries.remove(key);
    m_protectedAttachments.remove(key);
}

void Entry::setTitle(const QString& title)
{
    addAttribute("Title", title);
}

void Entry::setUrl(const QString& url)
{
    addAttribute("URL", url);
}

void Entry::setUsername(const QString& username)
{
    addAttribute("UserName", username);
}

void Entry::setPassword(const QString& password)
{
    addAttribute("Password", password);
}

void Entry::setNotes(const QString& notes)
{
    addAttribute("Notes", notes);
}

QList<Entry*> Entry::historyItems()
{
    return m_history;
}

const QList<Entry*>& Entry::historyItems() const
{
    return m_history;
}

void Entry::addHistoryItem(Entry* entry)
{
    Q_ASSERT(!entry->parent());

    m_history.append(entry);
}

Group* Entry::group()
{
    return m_group;
}

void Entry::setGroup(Group* group)
{
    if (m_group) {
        m_group->removeEntry(this);
    }
    group->addEntry(this);
    m_group = group;
    m_db = group->database();
    QObject::setParent(group);
}

bool Entry::isDefaultAttributue(const QString& key)
{
    return m_defaultAttibutes.contains(key);
}