diff --git a/src/kleo/keygroup.cpp b/src/kleo/keygroup.cpp index 02ee4e172..3f56ef367 100644 --- a/src/kleo/keygroup.cpp +++ b/src/kleo/keygroup.cpp @@ -1,134 +1,155 @@ /* kleo/keygroup.cpp This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2021 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker SPDX-License-Identifier: GPL-2.0-or-later */ #include "keygroup.h" #include #include using namespace Kleo; using namespace GpgME; static const KeyGroup::Id nullId = -1; class KeyGroup::Private { public: explicit Private(Id id, const QString &name, const std::vector &keys, Source source); Id id; QString name; QString configName; Keys keys; Source source; bool isImmutable = true; }; KeyGroup::Private::Private(Id id, const QString &name, const std::vector &keys, Source source) : id(id) , name(name) , keys(keys.cbegin(), keys.cend()) , source(source) { } KeyGroup::KeyGroup() : KeyGroup(nullId, QString(), {}, UnknownSource) { } KeyGroup::~KeyGroup() = default; KeyGroup::KeyGroup(Id id, const QString &name, const std::vector &keys, Source source) : d(new Private(id, name, keys, source)) { } KeyGroup::KeyGroup(const KeyGroup &other) : d(new Private(*other.d)) { } KeyGroup &KeyGroup::operator=(const KeyGroup &other) { *d = *other.d; return *this; } KeyGroup::KeyGroup(KeyGroup &&other) = default; KeyGroup &KeyGroup::operator=(KeyGroup &&other) = default; bool KeyGroup::isNull() const { return !d || d->id == nullId; } KeyGroup::Id KeyGroup::id() const { return d ? d->id : nullId; } +void KeyGroup::setName(const QString &name) +{ + if (d) { + d->name = name; + } +} + QString KeyGroup::name() const { return d ? d->name : QString(); } +void KeyGroup::setKeys(const KeyGroup::Keys &keys) +{ + if (d) { + d->keys = keys; + } +} + +void KeyGroup::setKeys(const std::vector &keys) +{ + if (d) { + d->keys = Keys(keys.cbegin(), keys.cend()); + } +} + const KeyGroup::Keys &KeyGroup::keys() const { static const Keys empty; return d ? d->keys : empty; } KeyGroup::Source KeyGroup::source() const { return d ? d->source : UnknownSource; } void KeyGroup::setConfigName(const QString &configName) { if (d) { d->configName = configName; } } QString KeyGroup::configName() const { return d ? d->configName : QString(); } void KeyGroup::setIsImmutable(bool isImmutable) { if (d) { d->isImmutable = isImmutable; } } bool KeyGroup::isImmutable() const { return d ? d->isImmutable : true; } bool KeyGroup::insert(const GpgME::Key &key) { if (!d || key.isNull()) { return false; } return d->keys.insert(key).second; } bool KeyGroup::erase(const GpgME::Key &key) { if (!d || key.isNull()) { return false; } return d->keys.erase(key) > 0; } diff --git a/src/kleo/keygroup.h b/src/kleo/keygroup.h index b4866d01e..43259ee6b 100644 --- a/src/kleo/keygroup.h +++ b/src/kleo/keygroup.h @@ -1,79 +1,84 @@ /* kleo/keygroup.h This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2021 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker SPDX-License-Identifier: GPL-2.0-or-later */ #ifndef LIBKLEO_KEYGROUP_H #define LIBKLEO_KEYGROUP_H #include "kleo_export.h" #include #include #include #include class QString; namespace GpgME { class Key; } namespace Kleo { class KLEO_EXPORT KeyGroup { public: typedef int32_t Id; typedef std::set> Keys; enum Source { UnknownSource, ApplicationConfig, GnuPGConfig, Tags }; KeyGroup(); ~KeyGroup(); explicit KeyGroup(Id id, const QString &name, const std::vector &keys, Source source); KeyGroup(const KeyGroup &other); KeyGroup &operator=(const KeyGroup &other); KeyGroup(KeyGroup &&other); KeyGroup &operator=(KeyGroup &&other); bool isNull() const; Id id() const; + Source source() const; + + void setName(const QString &name); QString name() const; + + void setKeys(const Keys &keys); + void setKeys(const std::vector &keys); const Keys &keys() const; - Source source() const; void setConfigName(const QString &configName); QString configName() const; void setIsImmutable(bool isImmutable); bool isImmutable() const; bool insert(const GpgME::Key &key); bool erase(const GpgME::Key &key); private: class Private; std::unique_ptr d; }; } #endif // LIBKLEO_KEYGROUP_H