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

Add button for editing group to group details dialog

GnuPG-bug-id: 5175, 5239
parent 15fb36c3
......@@ -11,6 +11,7 @@
#include "groupdetailsdialog.h"
#include "commands/detailscommand.h"
#include "dialogs/editgroupdialog.h"
#include "view/keytreeview.h"
#include <Libkleo/KeyGroup>
......@@ -45,6 +46,7 @@ class GroupDetailsDialog::Private
QLabel *groupNameLabel = nullptr;
KeyTreeView *treeView = nullptr;
QDialogButtonBox *buttonBox = nullptr;
QPushButton *editButton = nullptr;
} ui;
KeyGroup group;
......@@ -69,7 +71,11 @@ public:
ui.buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
KGuiItem::assign(ui.buttonBox->button(QDialogButtonBox::Close), KStandardGuiItem::close());
connect(ui.buttonBox, &QDialogButtonBox::clicked, q, &QDialog::close);
ui.editButton = ui.buttonBox->addButton(i18n("Edit"), QDialogButtonBox::ActionRole);
ui.editButton->setIcon(QIcon::fromTheme(QStringLiteral("document-edit")));
ui.editButton->setEnabled(false);
connect(ui.editButton, &QPushButton::clicked, q, [this] () { editGroup(); });
connect(ui.buttonBox, &QDialogButtonBox::rejected, q, &QDialog::close);
mainLayout->addWidget(ui.buttonBox);
// calculate default size with enough space for the key list
......@@ -113,6 +119,14 @@ private:
cmd->start();
}
}
void editGroup()
{
auto dialog = new EditGroupDialog(q->parentWidget());
dialog->setGroup(group);
dialog->show();
q->reject();
}
};
GroupDetailsDialog::GroupDetailsDialog(QWidget *parent)
......@@ -126,10 +140,34 @@ GroupDetailsDialog::~GroupDetailsDialog()
{
}
namespace
{
QString editButtonToolTip(const KeyGroup &group)
{
switch (group.source()) {
case KeyGroup::ApplicationConfig:
if (group.isImmutable()) {
return i18n("This group is locked down. It cannot be editted by you.");
} else {
return i18n("Edit this group");
}
case KeyGroup::GnuPGConfig:
return i18n("This group cannot be edited with Kleopatra. It is defined in the configuration files of gpg.");
case KeyGroup::Tags:
return i18n("This group is implicitly defined by tags assigned to keys. You need to change the tags of keys to add keys to or remove keys from the group.");
case KeyGroup::UnknownSource:
;
}
return i18n("This group cannot be edited with Kleopatra.");
}
}
void GroupDetailsDialog::setGroup(const KeyGroup &group)
{
d->group = group;
d->ui.groupNameLabel->setText(group.name());
const KeyGroup::Keys &keys = group.keys();
d->ui.treeView->setKeys(std::vector<GpgME::Key>(keys.cbegin(), keys.cend()));
d->ui.editButton->setEnabled(!group.isImmutable());
d->ui.editButton->setToolTip(editButtonToolTip(group));
}
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