Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
Kleopatra
Commits
cdd1b8ce
Commit
cdd1b8ce
authored
Nov 16, 2021
by
Ingo Klöcker
Browse files
Allow export (and deletion) of multiple groups
GnuPG-bug-id: 5638
parent
3b8e4044
Pipeline
#98145
canceled with stage
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/conf/groupsconfigwidget.cpp
View file @
cdd1b8ce
...
...
@@ -100,7 +100,7 @@ public:
ui
.
groupsList
->
setModel
(
groupsFilterModel
);
ui
.
groupsList
->
setModelColumn
(
KeyList
::
Summary
);
ui
.
groupsList
->
setSelectionBehavior
(
QAbstractItemView
::
SelectRows
);
ui
.
groupsList
->
setSelectionMode
(
QAbstractItemView
::
Single
Selection
);
ui
.
groupsList
->
setSelectionMode
(
QAbstractItemView
::
Extended
Selection
);
groupsLayout
->
addWidget
(
ui
.
groupsList
,
1
,
0
);
...
...
@@ -143,24 +143,34 @@ public:
}
private:
QModelIndex
selected
Index
()
auto
selected
Rows
()
{
const
QModelIndexList
selected
=
ui
.
groupsList
->
selectionModel
()
->
selectedRows
();
return
selected
.
empty
()
?
QModelIndex
()
:
selected
[
0
];
return
ui
.
groupsList
->
selectionModel
()
->
selectedRows
();
}
KeyGroup
getGroup
(
const
QModelIndex
&
index
)
auto
getGroup
(
const
QModelIndex
&
index
)
{
return
index
.
isValid
()
?
ui
.
groupsList
->
model
()
->
data
(
index
,
KeyList
::
GroupRole
).
value
<
KeyGroup
>
()
:
KeyGroup
();
return
index
.
isValid
()
?
ui
.
groupsList
->
model
()
->
data
(
index
,
KeyList
::
GroupRole
).
value
<
KeyGroup
>
()
:
KeyGroup
{};
}
auto
getGroups
(
const
QModelIndexList
&
indexes
)
{
std
::
vector
<
KeyGroup
>
groups
;
std
::
transform
(
std
::
begin
(
indexes
),
std
::
end
(
indexes
),
std
::
back_inserter
(
groups
),
[
this
](
const
auto
&
index
)
{
return
getGroup
(
index
);
});
return
groups
;
}
void
selectionChanged
()
{
const
KeyGroup
selectedGroup
=
getGroup
(
selectedIndex
());
const
bool
selectedGroupIsEditable
=
!
selectedGroup
.
isNull
()
&&
!
selectedGroup
.
isImmutable
();
ui
.
editButton
->
setEnabled
(
selectedGroupIsEditable
);
ui
.
deleteButton
->
setEnabled
(
selectedGroupIsEditable
);
ui
.
exportButton
->
setEnabled
(
!
selectedGroup
.
isNull
());
const
auto
selectedGroups
=
getGroups
(
selectedRows
());
const
bool
allSelectedGroupsAreEditable
=
std
::
all_of
(
std
::
begin
(
selectedGroups
),
std
::
end
(
selectedGroups
),
[](
const
auto
&
g
)
{
return
!
g
.
isNull
()
&&
!
g
.
isImmutable
();
});
ui
.
editButton
->
setEnabled
(
selectedGroups
.
size
()
==
1
&&
allSelectedGroupsAreEditable
);
ui
.
deleteButton
->
setEnabled
(
!
selectedGroups
.
empty
()
&&
allSelectedGroupsAreEditable
);
ui
.
exportButton
->
setEnabled
(
!
selectedGroups
.
empty
());
}
KeyGroup
showEditGroupDialog
(
KeyGroup
group
,
const
QString
&
windowTitle
,
EditGroupDialog
::
FocusWidget
focusWidget
)
...
...
@@ -204,12 +214,18 @@ private:
Q_EMIT
q
->
changed
();
}
void
editGroup
(
const
QModelIndex
&
index
=
QModelIndex
()
)
void
editGroup
(
const
QModelIndex
&
index
=
{}
)
{
const
QModelIndex
groupIndex
=
index
.
isValid
()
?
index
:
selectedIndex
();
if
(
!
groupIndex
.
isValid
())
{
qCDebug
(
KLEOPATRA_LOG
)
<<
"selection is empty"
;
return
;
QModelIndex
groupIndex
;
if
(
index
.
isValid
())
{
groupIndex
=
index
;
}
else
{
const
auto
selection
=
selectedRows
();
if
(
selection
.
size
()
!=
1
)
{
qCDebug
(
KLEOPATRA_LOG
)
<<
(
selection
.
empty
()
?
"selection is empty"
:
"more than one group is selected"
);
return
;
}
groupIndex
=
selection
.
front
();
}
const
KeyGroup
group
=
getGroup
(
groupIndex
);
if
(
group
.
isNull
())
{
...
...
@@ -238,21 +254,17 @@ private:
void
deleteGroup
()
{
const
QModelIndex
groupIndex
=
selected
Index
(
);
if
(
!
groupIndex
.
isValid
())
{
const
auto
selectedGroups
=
getGroups
(
selected
Rows
()
);
if
(
selectedGroups
.
empty
())
{
qCDebug
(
KLEOPATRA_LOG
)
<<
"selection is empty"
;
return
;
}
const
KeyGroup
group
=
getGroup
(
groupIndex
);
if
(
group
.
isNull
())
{
qCDebug
(
KLEOPATRA_LOG
)
<<
"selected group is null"
;
return
;
}
const
bool
success
=
groupsModel
->
removeGroup
(
group
);
if
(
!
success
)
{
qCDebug
(
KLEOPATRA_LOG
)
<<
"Removing group from model failed"
;
return
;
for
(
const
auto
&
group
:
selectedGroups
)
{
const
bool
success
=
groupsModel
->
removeGroup
(
group
);
if
(
!
success
)
{
qCDebug
(
KLEOPATRA_LOG
)
<<
"Removing group from model failed:"
<<
group
;
}
}
Q_EMIT
q
->
changed
();
...
...
@@ -260,19 +272,14 @@ private:
void
exportGroup
()
{
const
QModelIndex
groupIndex
=
selected
Index
(
);
if
(
!
groupIndex
.
isValid
())
{
const
auto
selectedGroups
=
getGroups
(
selected
Rows
()
);
if
(
selectedGroups
.
empty
())
{
qCDebug
(
KLEOPATRA_LOG
)
<<
"selection is empty"
;
return
;
}
const
KeyGroup
group
=
getGroup
(
groupIndex
);
if
(
group
.
isNull
())
{
qCDebug
(
KLEOPATRA_LOG
)
<<
"selected group is null"
;
return
;
}
// execute export group command
auto
cmd
=
new
ExportGroupsCommand
(
{
g
roup
}
);
auto
cmd
=
new
ExportGroupsCommand
(
selectedG
roup
s
);
cmd
->
start
();
}
};
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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