libkeepass 0.2.0
KeePass key database importer/exporter library
Loading...
Searching...
No Matches
group.hh
Go to the documentation of this file.
1/*
2 * libkeepass - KeePass key database importer/exporter
3 * Copyright (C) 2014 Christian Kindahl
4 * Copyright (C) 2024 Dominik Krümpelmann
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
25#pragma once
26#include <array>
27#include <ctime>
28#include <memory>
29#include <optional>
30#include <vector>
31
32#include "entry.hh"
33#include "libkeepass/export.hh"
34
35namespace keepass {
36
37class Icon;
38
45class LIBKEEPASS_API Group final : public std::enable_shared_from_this<Group> {
46private:
47 std::array<uint8_t, 16> uuid_;
48 uint32_t icon_ = 0;
49 std::weak_ptr<Icon> custom_icon_;
50 std::weak_ptr<Group> parent_;
51 std::string name_;
52 std::string notes_;
53 std::string tags_;
54 std::optional<std::array<uint8_t, 16>> previous_parent_group_;
55 std::time_t creation_time_ = 0;
56 std::time_t modification_time_ = 0;
57 std::time_t access_time_ = 0;
58 std::time_t expiry_time_ = 0;
59 std::time_t move_time_ = 0;
60 uint16_t flags_ = 0;
61 bool expires_ = false;
62 bool expanded_ = false;
63 uint32_t usage_count_ = 0;
64 std::string default_autotype_sequence_;
65 bool autotype_ = false;
66 bool search_ = false;
67 std::weak_ptr<Entry> last_visible_entry_;
68
69 std::vector<std::shared_ptr<Group>> groups_;
70 std::vector<std::shared_ptr<Entry>> entries_;
71
72public:
75
77 const std::array<uint8_t, 16>& uuid() const { return uuid_; }
78
80 void set_uuid(const std::array<uint8_t, 16>& uuid) { uuid_ = uuid; }
81
83 uint32_t icon() const { return icon_; }
84
86 void set_icon(const uint32_t& icon) { icon_ = icon; }
87
89 std::weak_ptr<Icon> custom_icon() const { return custom_icon_; }
90
92 void set_custom_icon(std::weak_ptr<Icon> icon) { custom_icon_ = std::move(icon); }
93
95 const std::string& name() const { return name_; }
96
98 void set_name(const std::string& name) { name_ = name; }
99
101 const std::string& notes() const { return notes_; }
102
104 void set_notes(const std::string& notes) { notes_ = notes; }
105
107 const std::string& tags() const { return tags_; }
108
110 void set_tags(const std::string& tags) { tags_ = tags; }
111
113 const std::optional<std::array<uint8_t, 16>>& previous_parent_group() const {
114 return previous_parent_group_;
115 }
116
119 void set_previous_parent_group(const std::optional<std::array<uint8_t, 16>>& uuid) {
120 previous_parent_group_ = uuid;
121 }
122
124 std::time_t creation_time() const { return creation_time_; }
125
127 void set_creation_time(const std::time_t& time) { creation_time_ = time; }
128
130 std::time_t modification_time() const { return modification_time_; }
131
133 void set_modification_time(const std::time_t& time) { modification_time_ = time; }
134
136 std::time_t access_time() const { return access_time_; }
137
139 void set_access_time(const std::time_t& time) { access_time_ = time; }
140
142 std::time_t expiry_time() const { return expiry_time_; }
143
145 void set_expiry_time(const std::time_t& time) { expiry_time_ = time; }
146
148 std::time_t move_time() const { return move_time_; }
149
151 void set_move_time(const std::time_t& time) { move_time_ = time; }
152
154 uint16_t flags() const { return flags_; }
155
157 void set_flags(const uint16_t& flags) { flags_ = flags; }
158
160 bool expires() const { return expires_; }
161
163 void set_expires(bool expires) { expires_ = expires; }
164
166 bool expanded() const { return expanded_; }
167
169 void set_expanded(bool expanded) { expanded_ = expanded; }
170
172 uint32_t usage_count() const { return usage_count_; }
173
175 void set_usage_count(uint32_t usage_count) { usage_count_ = usage_count; }
176
178 const std::string& default_autotype_sequence() const { return default_autotype_sequence_; }
179
181 void set_default_autotype_sequence(std::string sequence) {
182 default_autotype_sequence_ = std::move(sequence);
183 }
184
186 bool autotype() const { return autotype_; }
187
189 void set_autotype(bool autotype) { autotype_ = autotype; }
190
192 bool search() const { return search_; }
193
195 void set_search(bool search) { search_ = search; }
196
198 std::weak_ptr<Entry> last_visible_entry() const { return last_visible_entry_; }
199
201 void set_last_visible_entry(std::weak_ptr<Entry> entry) {
202 last_visible_entry_ = std::move(entry);
203 }
204
206 const std::vector<std::shared_ptr<Group>>& Groups() const;
207
209 const std::vector<std::shared_ptr<Entry>>& Entries() const;
210
212 std::weak_ptr<Group> parent() const { return parent_; }
213
215 void set_parent(std::weak_ptr<Group> parent) { parent_ = std::move(parent); }
216
218 bool is_root_group() const { return parent_.expired(); }
219
221 std::string path() const;
222
224 size_t entries_count() const { return entries_.size(); }
225
227 size_t groups_count() const { return groups_.size(); }
228
230
238 std::vector<std::shared_ptr<Entry>> FindEntries(const std::string& query, bool regex = false,
239 bool recursive = true) const;
240
242
250 std::vector<std::shared_ptr<Group>> FindGroups(const std::string& query, bool regex = false,
251 bool recursive = true) const;
252
254 void AddGroup(const std::shared_ptr<Group>& group);
255
257 void RemoveGroup(const std::shared_ptr<Group>& group);
258
260 void AddEntry(const std::shared_ptr<Entry>& entry);
261
263 void RemoveEntry(const std::shared_ptr<Entry>& entry);
264
266 bool HasNonMetaEntries() const;
267
270 std::string ToJson(bool include_attachments = false) const;
271
273 bool operator==(const Group& other) const;
274
276 bool operator!=(const Group& other) const;
277};
278
279} // namespace keepass
A KeePass group (a folder) that contains entries and subgroups.
Definition group.hh:45
const std::array< uint8_t, 16 > & uuid() const
Returns the group's unique identifier (UUID).
Definition group.hh:77
void RemoveGroup(const std::shared_ptr< Group > &group)
Removes a subgroup from this group.
std::weak_ptr< Entry > last_visible_entry() const
Returns a weak reference to the last visible entry.
Definition group.hh:198
void set_usage_count(uint32_t usage_count)
Sets the usage count.
Definition group.hh:175
void set_search(bool search)
Sets whether search is enabled for this group.
Definition group.hh:195
void set_default_autotype_sequence(std::string sequence)
Sets the default auto-type sequence.
Definition group.hh:181
void set_previous_parent_group(const std::optional< std::array< uint8_t, 16 > > &uuid)
Definition group.hh:119
std::weak_ptr< Group > parent() const
Returns the parent group (empty if this is the root group).
Definition group.hh:212
bool expires() const
Returns whether the group expires.
Definition group.hh:160
const std::string & tags() const
Returns the tags (space-separated).
Definition group.hh:107
std::string path() const
Returns the full path of this group from the database root.
const std::string & notes() const
Returns the group notes.
Definition group.hh:101
void set_creation_time(const std::time_t &time)
Sets the creation time.
Definition group.hh:127
void AddEntry(const std::shared_ptr< Entry > &entry)
Adds an entry to this group.
std::time_t access_time() const
Returns the last access time.
Definition group.hh:136
void set_uuid(const std::array< uint8_t, 16 > &uuid)
Sets the group's unique identifier (UUID).
Definition group.hh:80
bool is_root_group() const
Returns whether this group is the root group.
Definition group.hh:218
void set_autotype(bool autotype)
Sets whether auto-type is enabled for this group.
Definition group.hh:189
void set_expiry_time(const std::time_t &time)
Sets the expiry time.
Definition group.hh:145
bool autotype() const
Returns whether auto-type is enabled for this group.
Definition group.hh:186
const std::vector< std::shared_ptr< Group > > & Groups() const
Returns the list of subgroups.
const std::vector< std::shared_ptr< Entry > > & Entries() const
Returns the list of entries in this group.
void set_access_time(const std::time_t &time)
Sets the last access time.
Definition group.hh:139
bool search() const
Returns whether search is enabled for this group.
Definition group.hh:192
void set_parent(std::weak_ptr< Group > parent)
Sets the parent group.
Definition group.hh:215
void set_modification_time(const std::time_t &time)
Sets the last modification time.
Definition group.hh:133
bool HasNonMetaEntries() const
Returns whether the group contains any non-metadata entries.
size_t entries_count() const
Returns the number of entries directly contained in this group.
Definition group.hh:224
std::time_t creation_time() const
Returns the creation time.
Definition group.hh:124
size_t groups_count() const
Returns the number of subgroups directly contained in this group.
Definition group.hh:227
std::time_t modification_time() const
Returns the last modification time.
Definition group.hh:130
std::string ToJson(bool include_attachments=false) const
std::time_t move_time() const
Returns the last move time.
Definition group.hh:148
void set_last_visible_entry(std::weak_ptr< Entry > entry)
Sets the last visible entry.
Definition group.hh:201
std::vector< std::shared_ptr< Entry > > FindEntries(const std::string &query, bool regex=false, bool recursive=true) const
Finds entries matching the given query in this group's subtree.
void set_name(const std::string &name)
Sets the group name.
Definition group.hh:98
void set_notes(const std::string &notes)
Sets the group notes.
Definition group.hh:104
void set_expires(bool expires)
Sets whether the group expires.
Definition group.hh:163
void set_flags(const uint16_t &flags)
Sets the group flags.
Definition group.hh:157
void set_icon(const uint32_t &icon)
Sets the index of the stock icon.
Definition group.hh:86
const std::string & name() const
Returns the group name.
Definition group.hh:95
void set_move_time(const std::time_t &time)
Sets the last move time.
Definition group.hh:151
uint32_t usage_count() const
Returns the usage count.
Definition group.hh:172
void RemoveEntry(const std::shared_ptr< Entry > &entry)
Removes an entry from this group.
uint32_t icon() const
Returns the index of the stock icon.
Definition group.hh:83
std::time_t expiry_time() const
Returns the expiry time.
Definition group.hh:142
void AddGroup(const std::shared_ptr< Group > &group)
Adds a subgroup to this group.
Group()
Creates an empty group.
const std::string & default_autotype_sequence() const
Returns the default auto-type sequence.
Definition group.hh:178
bool operator!=(const Group &other) const
Inequality comparison.
bool operator==(const Group &other) const
Equality comparison.
void set_tags(const std::string &tags)
Sets the tags (space-separated).
Definition group.hh:110
void set_expanded(bool expanded)
Sets whether the group is expanded in the UI.
Definition group.hh:169
uint16_t flags() const
Returns the group flags.
Definition group.hh:154
const std::optional< std::array< uint8_t, 16 > > & previous_parent_group() const
Returns the UUID of the previous parent group (KDBX 4.1); empty if unset.
Definition group.hh:113
std::weak_ptr< Icon > custom_icon() const
Returns a weak reference to the custom icon (if any).
Definition group.hh:89
void set_custom_icon(std::weak_ptr< Icon > icon)
Sets the custom icon.
Definition group.hh:92
bool expanded() const
Returns whether the group is expanded in the UI.
Definition group.hh:166
std::vector< std::shared_ptr< Group > > FindGroups(const std::string &query, bool regex=false, bool recursive=true) const
Finds groups matching the given query in this group's subtree.
Type representing a single KeePass entry.
Visibility/export macro for the shared library.
#define LIBKEEPASS_API
Marks a class, function or variable as part of the public ABI.
Definition export.hh:43