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

Extract "Choose Protocol" dialog from NewCertificateWizard

This change converts the "Choose Protocol" page of the NewCertificateWizard
to a dialog of its own. This improves accessibility at least when using
orca because orca works very poorly with wizards, e.g. orca doesn't read
the title of the new page when the next page is shown in the wizard.

GnuPG-bug-id: 5832
parent 48611e21
......@@ -313,6 +313,8 @@ set(_kleopatra_SRCS
dialogs/certifycertificatedialog.h
dialogs/certifywidget.cpp
dialogs/certifywidget.h
dialogs/choosecertificateprotocoldialog.cpp
dialogs/choosecertificateprotocoldialog.h
dialogs/createcsrforcardkeydialog.cpp
dialogs/createcsrforcardkeydialog.h
dialogs/deletecertificatesdialog.cpp
......
......@@ -13,6 +13,7 @@
#include "command_p.h"
#include "dialogs/choosecertificateprotocoldialog.h"
#include "newcertificatewizard/newcertificatewizard.h"
#include <settings.h>
......@@ -35,7 +36,12 @@ public:
{
}
void chooseProtocol();
void createCertificate();
private:
void onProtocolChosen();
void slotDialogAccepted();
private:
......@@ -43,6 +49,7 @@ private:
private:
Protocol protocol = GpgME::UnknownProtocol;
QPointer<ChooseCertificateProtocolDialog> protocolDialog;
QPointer<NewCertificateWizard> dialog;
};
......@@ -58,6 +65,53 @@ const NewCertificateCommand::Private *NewCertificateCommand::d_func() const
#define d d_func()
#define q q_func()
void NewCertificateCommand::Private::chooseProtocol()
{
Q_ASSERT(protocol == GpgME::UnknownProtocol);
Q_ASSERT(!protocolDialog);
protocolDialog = new ChooseCertificateProtocolDialog;
applyWindowID(protocolDialog);
connect(protocolDialog, &QDialog::accepted, q, [this]() {
onProtocolChosen();
});
connect(protocolDialog, &QDialog::rejected, q, [this]() {
canceled();
protocolDialog->deleteLater();
});
protocolDialog->show();
}
void NewCertificateCommand::Private::onProtocolChosen()
{
protocol = protocolDialog->protocol();
protocolDialog->deleteLater();
createCertificate();
}
void Kleo::Commands::NewCertificateCommand::Private::createCertificate()
{
Q_ASSERT(protocol != GpgME::UnknownProtocol);
Q_ASSERT(!dialog);
dialog = new NewCertificateWizard;
applyWindowID(dialog);
dialog->setAttribute(Qt::WA_DeleteOnClose);
connect(dialog, &QDialog::accepted, q, [this]() {
slotDialogAccepted();
});
connect(dialog, &QDialog::rejected, q, [this]() {
canceled();
});
dialog->setProtocol(protocol);
dialog->show();
}
void NewCertificateCommand::Private::slotDialogAccepted()
{
finished();
......@@ -83,35 +137,26 @@ NewCertificateCommand::~NewCertificateCommand() = default;
void NewCertificateCommand::setProtocol(Protocol proto)
{
d->protocol = proto;
if (d->dialog) {
d->dialog->setProtocol(proto);
}
}
Protocol NewCertificateCommand::protocol() const
{
if (d->dialog) {
return d->dialog->protocol();
} else {
return d->protocol;
}
return d->protocol;
}
void NewCertificateCommand::doStart()
{
d->ensureDialogCreated();
Q_ASSERT(d->dialog);
const Kleo::Settings settings{};
const auto cmsAllowed = settings.cmsEnabled() && settings.cmsCertificateCreationAllowed();
if (d->protocol == UnknownProtocol && !cmsAllowed) {
d->protocol = GpgME::OpenPGP;
}
if (d->protocol != UnknownProtocol) {
d->dialog->setProtocol(d->protocol);
}
d->dialog->show();
if (d->protocol == UnknownProtocol) {
d->chooseProtocol();
} else {
d->createCertificate();
}
}
void NewCertificateCommand::doCancel()
......@@ -121,20 +166,6 @@ void NewCertificateCommand::doCancel()
}
}
void NewCertificateCommand::Private::ensureDialogCreated()
{
if (dialog) {
return;
}
dialog = new NewCertificateWizard;
applyWindowID(dialog);
dialog->setAttribute(Qt::WA_DeleteOnClose);
connect(dialog, &QDialog::accepted, q, [this]() { slotDialogAccepted(); });
connect(dialog, &QDialog::rejected, q, [this]() { canceled(); });
}
#undef d
#undef q
......
/* -*- mode: c++; c-basic-offset:4 -*-
dialogs/choosecertificateprotocoldialog.cpp
This file is part of Kleopatra, the KDE keymanager
SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB
SPDX-FileCopyrightText: 2016, 2017 Bundesamt für Sicherheit in der Informationstechnik
SPDX-FileContributor: Intevation GmbH
SPDX-FileCopyrightText: 2022 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <config-kleopatra.h>
#include "choosecertificateprotocoldialog.h"
#include "utils/scrollarea.h"
#include <KLocalizedString>
#include <KSeparator>
#include <QCommandLinkButton>
#include <QDialogButtonBox>
#include <QLabel>
#include <QVBoxLayout>
using namespace Kleo;
class ChooseCertificateProtocolDialog::Private
{
friend class ::Kleo::ChooseCertificateProtocolDialog;
ChooseCertificateProtocolDialog *const q;
struct UI {
QCommandLinkButton *pgpCLB = nullptr;
QCommandLinkButton *x509CLB = nullptr;
UI(QDialog *parent)
{
auto mainLayout = new QVBoxLayout{parent};
{
auto label = new QLabel{i18n("Choose which type of key pair you want to create."), parent};
label->setWordWrap(true);
mainLayout->addWidget(label);
}
mainLayout->addWidget(new KSeparator{Qt::Horizontal, parent});
auto scrollArea = new ScrollArea{parent};
scrollArea->setFocusPolicy(Qt::NoFocus);
scrollArea->setFrameStyle(QFrame::NoFrame);
scrollArea->setBackgroundRole(parent->backgroundRole());
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
auto scrollAreaLayout = qobject_cast<QBoxLayout *>(scrollArea->widget()->layout());
scrollAreaLayout->setContentsMargins(0, 0, 0, 0);
pgpCLB = new QCommandLinkButton{parent};
pgpCLB->setText(i18n("Create a Personal OpenPGP Key Pair"));
pgpCLB->setDescription(i18n("OpenPGP key pairs are certified by confirming the fingerprint of the public key."));
pgpCLB->setAccessibleDescription(pgpCLB->description());
pgpCLB->setCheckable(true);
pgpCLB->setAutoExclusive(true);
scrollAreaLayout->addWidget(pgpCLB);
x509CLB = new QCommandLinkButton{parent};
x509CLB->setText(i18n("Create a Personal X.509 Key Pair and Certification Request"));
x509CLB->setDescription(i18n("X.509 key pairs are certified by a certification authority (CA). The generated request needs to be sent to a CA to finalize creation."));
x509CLB->setAccessibleDescription(x509CLB->description());
x509CLB->setCheckable(true);
x509CLB->setAutoExclusive(true);
scrollAreaLayout->addWidget(x509CLB);
mainLayout->addWidget(scrollArea);
mainLayout->addStretch(1);
mainLayout->addWidget(new KSeparator{Qt::Horizontal, parent});
auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Cancel, parent};
mainLayout->addWidget(buttonBox);
connect(pgpCLB, &QAbstractButton::clicked, parent, &QDialog::accept);
connect(x509CLB, &QAbstractButton::clicked, parent, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, parent, &QDialog::reject);
}
} ui;
public:
explicit Private(ChooseCertificateProtocolDialog *qq)
: q{qq}
, ui{qq}
{
q->setWindowTitle(i18nc("@title:window", "Choose Type of Key Pair"));
}
};
ChooseCertificateProtocolDialog::ChooseCertificateProtocolDialog(QWidget *parent, Qt::WindowFlags f)
: QDialog{parent, f}
, d{new Private{this}}
{
}
ChooseCertificateProtocolDialog::~ChooseCertificateProtocolDialog() = default;
GpgME::Protocol ChooseCertificateProtocolDialog::protocol() const
{
return
d->ui.pgpCLB->isChecked() ? GpgME::OpenPGP :
d->ui.x509CLB->isChecked() ? GpgME::CMS : GpgME::UnknownProtocol;
}
void ChooseCertificateProtocolDialog::showEvent(QShowEvent *event)
{
// set WA_KeyboardFocusChange attribute to force visual focus of the
// focussed command link button when the dialog is shown (required
// for Breeze style and some other styles)
window()->setAttribute(Qt::WA_KeyboardFocusChange);
QDialog::showEvent(event);
}
/* -*- mode: c++; c-basic-offset:4 -*-
dialogs/choosecertificateprotocoldialog.h
This file is part of Kleopatra, the KDE keymanager
SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB
SPDX-FileCopyrightText: 2016, 2017 Bundesamt für Sicherheit in der Informationstechnik
SPDX-FileContributor: Intevation GmbH
SPDX-FileCopyrightText: 2022 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <QDialog>
#include <gpgme++/global.h>
#include <memory>
namespace Kleo
{
class ChooseCertificateProtocolDialog : public QDialog
{
Q_OBJECT
public:
explicit ChooseCertificateProtocolDialog(QWidget *parent = nullptr, Qt::WindowFlags f = {});
~ChooseCertificateProtocolDialog() override;
GpgME::Protocol protocol() const;
protected:
void showEvent(QShowEvent *event) override;
private:
class Private;
const std::unique_ptr<Private> d;
};
}
Supports Markdown
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