Libkleo

keygroup.cpp
1/*
2 kleo/keygroup.cpp
3
4 This file is part of libkleopatra, the KDE keymanagement library
5 SPDX-FileCopyrightText: 2021 g10 Code GmbH
6 SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9*/
10
11#include <config-libkleo.h>
12
13#include "keygroup.h"
14
15#include <QString>
16
17#include <gpgme++/key.h>
18
19using namespace Kleo;
20using namespace GpgME;
21
22class KeyGroup::Private
23{
24public:
25 explicit Private(const Id &id, const QString &name, const std::vector<Key> &keys, Source source);
26
27 Id id;
28 QString name;
29 Keys keys;
30 Source source;
31 bool isImmutable = true;
32};
33
34KeyGroup::Private::Private(const Id &id, const QString &name, const std::vector<Key> &keys, Source source)
35 : id(id)
36 , name(name)
37 , keys(keys.cbegin(), keys.cend())
38 , source(source)
39{
40}
41
42KeyGroup::KeyGroup()
43 : KeyGroup(QString(), QString(), {}, UnknownSource)
44{
45}
46
47KeyGroup::~KeyGroup() = default;
48
49KeyGroup::KeyGroup(const Id &id, const QString &name, const std::vector<Key> &keys, Source source)
50 : d(new Private(id, name, keys, source))
51{
52}
53
54KeyGroup::KeyGroup(const KeyGroup &other)
55 : d(new Private(*other.d))
56{
57}
58
59KeyGroup &KeyGroup::operator=(const KeyGroup &other)
60{
61 *d = *other.d;
62 return *this;
63}
64
65KeyGroup::KeyGroup(KeyGroup &&other) = default;
66
67KeyGroup &KeyGroup::operator=(KeyGroup &&other) = default;
68
69bool KeyGroup::isNull() const
70{
71 return !d || d->id.isEmpty();
72}
73
74KeyGroup::Id KeyGroup::id() const
75{
76 return d ? d->id : QString();
77}
78
79void KeyGroup::setName(const QString &name)
80{
81 if (d) {
82 d->name = name;
83 }
84}
85
86QString KeyGroup::name() const
87{
88 return d ? d->name : QString();
89}
90
91void KeyGroup::setKeys(const KeyGroup::Keys &keys)
92{
93 if (d) {
94 d->keys = keys;
95 }
96}
97
98void KeyGroup::setKeys(const std::vector<GpgME::Key> &keys)
99{
100 if (d) {
101 d->keys = Keys(keys.cbegin(), keys.cend());
102 }
103}
104
105const KeyGroup::Keys &KeyGroup::keys() const
106{
107 static const Keys empty;
108 return d ? d->keys : empty;
109}
110
111KeyGroup::Source KeyGroup::source() const
112{
113 return d ? d->source : UnknownSource;
114}
115
116void KeyGroup::setIsImmutable(bool isImmutable)
117{
118 if (d) {
119 d->isImmutable = isImmutable;
120 }
121}
122
123bool KeyGroup::isImmutable() const
124{
125 return d ? d->isImmutable : true;
126}
127
128bool KeyGroup::insert(const GpgME::Key &key)
129{
130 if (!d || key.isNull()) {
131 return false;
132 }
133 return d->keys.insert(key).second;
134}
135
136bool KeyGroup::erase(const GpgME::Key &key)
137{
138 if (!d || key.isNull()) {
139 return false;
140 }
141 return d->keys.erase(key) > 0;
142}
int64_t Id
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:39:42 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.