Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
libkleo
Commits
611cd4fb
Commit
611cd4fb
authored
Feb 17, 2021
by
Ingo Klöcker
Browse files
Allow retrieving and saving of configurable groups of keys
GnuPG-bug-id: 5175, 5239
parent
b70c7f47
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/models/keycache.cpp
View file @
611cd4fb
...
...
@@ -1124,6 +1124,72 @@ std::vector<KeyGroup> KeyCache::groups() const
return
d
->
m_groups
;
}
std
::
vector
<
KeyGroup
>
KeyCache
::
configurableGroups
()
const
{
std
::
vector
<
KeyGroup
>
groups
;
groups
.
reserve
(
d
->
m_groups
.
size
());
std
::
copy_if
(
d
->
m_groups
.
cbegin
(),
d
->
m_groups
.
cend
(),
std
::
back_inserter
(
groups
),
[]
(
const
KeyGroup
&
group
)
{
return
group
.
source
()
==
KeyGroup
::
ApplicationConfig
;
});
return
groups
;
}
namespace
{
bool
compareById
(
const
KeyGroup
&
lhs
,
const
KeyGroup
&
rhs
)
{
return
lhs
.
id
()
<
rhs
.
id
();
}
std
::
vector
<
KeyGroup
>
sortedById
(
std
::
vector
<
KeyGroup
>
groups
)
{
std
::
sort
(
groups
.
begin
(),
groups
.
end
(),
&
compareById
);
return
groups
;
}
}
void
KeyCache
::
saveConfigurableGroups
(
const
std
::
vector
<
KeyGroup
>
&
groups
)
{
const
std
::
vector
<
KeyGroup
>
oldGroups
=
sortedById
(
configurableGroups
());
const
std
::
vector
<
KeyGroup
>
newGroups
=
sortedById
(
groups
);
{
std
::
vector
<
KeyGroup
>
removedGroups
;
std
::
set_difference
(
oldGroups
.
begin
(),
oldGroups
.
end
(),
newGroups
.
begin
(),
newGroups
.
end
(),
std
::
back_inserter
(
removedGroups
),
&
compareById
);
for
(
const
auto
&
group
:
qAsConst
(
removedGroups
))
{
qCDebug
(
LIBKLEO_LOG
)
<<
"Removing group"
<<
group
;
d
->
remove
(
group
);
}
}
{
std
::
vector
<
KeyGroup
>
updatedGroups
;
std
::
set_intersection
(
newGroups
.
begin
(),
newGroups
.
end
(),
oldGroups
.
begin
(),
oldGroups
.
end
(),
std
::
back_inserter
(
updatedGroups
),
&
compareById
);
for
(
const
auto
&
group
:
qAsConst
(
updatedGroups
))
{
qCDebug
(
LIBKLEO_LOG
)
<<
"Updating group"
<<
group
;
d
->
update
(
group
);
}
}
{
std
::
vector
<
KeyGroup
>
addedGroups
;
std
::
set_difference
(
newGroups
.
begin
(),
newGroups
.
end
(),
oldGroups
.
begin
(),
oldGroups
.
end
(),
std
::
back_inserter
(
addedGroups
),
&
compareById
);
for
(
const
auto
&
group
:
qAsConst
(
addedGroups
))
{
qCDebug
(
LIBKLEO_LOG
)
<<
"Adding group"
<<
group
;
d
->
insert
(
group
);
}
}
Q_EMIT
keysMayHaveChanged
();
}
bool
KeyCache
::
insert
(
const
KeyGroup
&
group
)
{
if
(
!
d
->
insert
(
group
))
{
...
...
src/models/keycache.h
View file @
611cd4fb
...
...
@@ -81,6 +81,8 @@ public:
std
::
vector
<
GpgME
::
Key
>
secretKeys
()
const
;
std
::
vector
<
KeyGroup
>
groups
()
const
;
std
::
vector
<
KeyGroup
>
configurableGroups
()
const
;
void
saveConfigurableGroups
(
const
std
::
vector
<
KeyGroup
>
&
groups
);
const
GpgME
::
Key
&
findByFingerprint
(
const
char
*
fpr
)
const
;
const
GpgME
::
Key
&
findByFingerprint
(
const
std
::
string
&
fpr
)
const
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment