Commit e9c893fb authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Allow adding a group of keys

GnuPG-bug-id: 5175, 5239
parent 82b04017
......@@ -340,6 +340,36 @@ public:
readGroupsFromGroupsConfig();
}
bool insert(const KeyGroup &group)
{
Q_ASSERT(!group.isNull());
Q_ASSERT(group.source() == KeyGroup::ApplicationConfig);
if (group.isNull() || group.source() != KeyGroup::ApplicationConfig) {
qCDebug(LIBKLEO_LOG) << "KeyCache::Private::insert - Invalid group:" << group;
return false;
}
const auto it = std::find_if(m_groups.cbegin(), m_groups.cend(),
[group] (const auto &g) {
return g.source() == group.source() && g.id() == group.id();
});
if (it != m_groups.cend()) {
qCDebug(LIBKLEO_LOG) << "KeyCache::Private::insert - Group already present in list of groups:" << group;
return false;
}
const KeyGroup savedGroup = writeGroupToGroupsConfig(group);
if (savedGroup.isNull()) {
qCDebug(LIBKLEO_LOG) << "KeyCache::Private::insert - Writing group" << group.id() << "to config file failed";
return false;
}
m_groups.push_back(savedGroup);
Q_EMIT q->groupAdded(savedGroup);
return true;
}
bool update(const KeyGroup &group)
{
Q_ASSERT(!group.isNull());
......@@ -1041,6 +1071,17 @@ std::vector<KeyGroup> KeyCache::groups() const
return d->m_groups;
}
bool KeyCache::insert(const KeyGroup &group)
{
if (!d->insert(group)) {
return false;
}
Q_EMIT keysMayHaveChanged();
return true;
}
bool KeyCache::update(const KeyGroup &group)
{
if (!d->update(group)) {
......
......@@ -58,6 +58,7 @@ public:
void insert(const GpgME::Key &key);
void insert(const std::vector<GpgME::Key> &keys);
bool insert(const KeyGroup &group);
void refresh(const std::vector<GpgME::Key> &keys);
bool update(const KeyGroup &group);
......@@ -163,6 +164,7 @@ Q_SIGNALS:
void added(const GpgME::Key &key);
void keyListingDone(const GpgME::KeyListResult &result);
void keysMayHaveChanged();
void groupAdded(const KeyGroup &group);
void groupUpdated(const KeyGroup &group);
private:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment