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

Remove Edit button from group details dialog

Groups shall only be edited via the configuration dialog.

GnuPG-bug-id: 5175, 5239
parent 5ff134b2
......@@ -255,7 +255,6 @@ set(_kleopatra_SRCS
commands/importcertificatefrompivcardcommand.cpp
commands/createopenpgpkeyfromcardkeyscommand.cpp
commands/createcsrforcardkeycommand.cpp
commands/editgroupcommand.cpp
${_kleopatra_uiserver_files}
......
/* -*- mode: c++; c-basic-offset:4 -*-
commands/editgroupcommand.cpp
This file is part of Kleopatra, the KDE keymanager
SPDX-FileCopyrightText: 2021 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "editgroupcommand.h"
#include "command_p.h"
#include "dialogs/editgroupdialog.h"
#include <Libkleo/KeyCache>
#include <Libkleo/KeyGroup>
#include <KLocalizedString>
using namespace Kleo;
using namespace Kleo::Commands;
using namespace Kleo::Dialogs;
class EditGroupCommand::Private : public Command::Private
{
friend class ::Kleo::Commands::EditGroupCommand;
EditGroupCommand *q_func() const
{
return static_cast<EditGroupCommand *>(q);
}
public:
explicit Private(EditGroupCommand *qq, const KeyGroup &group, QWidget *parent);
~Private();
private:
void start();
void slotDialogAccepted();
void slotDialogRejected();
void ensureDialogCreated();
private:
KeyGroup group;
QPointer<EditGroupDialog> dialog;
};
EditGroupCommand::Private *EditGroupCommand::d_func()
{
return static_cast<Private *>(d.get());
}
const EditGroupCommand::Private *EditGroupCommand::d_func() const
{
return static_cast<const Private *>(d.get());
}
#define d d_func()
#define q q_func()
EditGroupCommand::Private::Private(EditGroupCommand *qq, const KeyGroup &group, QWidget *parent)
: Command::Private(qq, parent)
, group(group)
{
}
EditGroupCommand::Private::~Private()
{
}
void EditGroupCommand::Private::start()
{
ensureDialogCreated();
dialog->setWindowTitle(i18nc("@title:window", "Edit Group"));
dialog->setGroupName(group.name());
const KeyGroup::Keys &keys = group.keys();
dialog->setGroupKeys(std::vector<GpgME::Key>(keys.cbegin(), keys.cend()));
dialog->show();
}
void EditGroupCommand::Private::slotDialogAccepted()
{
group.setName(dialog->groupName());
group.setKeys(dialog->groupKeys());
KeyCache::mutableInstance()->update(group);
finished();
}
void EditGroupCommand::Private::slotDialogRejected()
{
canceled();
}
void EditGroupCommand::Private::ensureDialogCreated()
{
if (dialog) {
return;
}
dialog = new EditGroupDialog;
applyWindowID(dialog);
dialog->setAttribute(Qt::WA_DeleteOnClose);
connect(dialog, &QDialog::accepted, q, [this] () { slotDialogAccepted(); });
connect(dialog, &QDialog::rejected, q, [this] () { slotDialogRejected(); });
}
EditGroupCommand::EditGroupCommand(const KeyGroup &group, QWidget *parent)
: Command(new Private(this, group, parent))
{
}
EditGroupCommand::~EditGroupCommand()
{
}
void EditGroupCommand::doStart()
{
d->start();
}
void EditGroupCommand::doCancel()
{
}
#undef d
#undef q
/* -*- mode: c++; c-basic-offset:4 -*-
commands/editgroupcommand.h
This file is part of Kleopatra, the KDE keymanager
SPDX-FileCopyrightText: 2021 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef __KLEOPATRA_COMMANDS_EDITGROUPCOMMAND_H__
#define __KLEOPATRA_COMMANDS_EDITGROUPCOMMAND_H__
#include "command.h"
namespace Kleo
{
class KeyGroup;
namespace Commands
{
class EditGroupCommand : public Command
{
Q_OBJECT
public:
explicit EditGroupCommand(const KeyGroup &group, QWidget *parent = nullptr);
~EditGroupCommand() override;
private:
void doStart() override;
void doCancel() override;
private:
class Private;
inline Private *d_func();
inline const Private *d_func() const;
};
} // namespace Commands
} // namespace Kleo
#endif // __KLEOPATRA_COMMANDS_EDITGROUPCOMMAND_H__
......@@ -10,7 +10,6 @@
#include "groupdetailsdialog.h"
#include "commands/editgroupcommand.h"
#include "commands/detailscommand.h"
#include "view/keytreeview.h"
......@@ -46,7 +45,6 @@ class GroupDetailsDialog::Private
QLabel *groupNameLabel = nullptr;
KeyTreeView *treeView = nullptr;
QDialogButtonBox *buttonBox = nullptr;
QPushButton *editButton = nullptr;
} ui;
KeyGroup group;
......@@ -71,10 +69,6 @@ public:
ui.buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
KGuiItem::assign(ui.buttonBox->button(QDialogButtonBox::Close), KStandardGuiItem::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);
......@@ -119,13 +113,6 @@ private:
cmd->start();
}
}
void editGroup()
{
auto cmd = new EditGroupCommand(group, q->parentWidget());
cmd->start();
q->reject();
}
};
GroupDetailsDialog::GroupDetailsDialog(QWidget *parent)
......@@ -139,34 +126,10 @@ 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 edited 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