diff --git a/src/dialogs/choosecertificateprotocoldialog.cpp b/src/dialogs/choosecertificateprotocoldialog.cpp index f78e6be3b..ef0b8dbdc 100644 --- a/src/dialogs/choosecertificateprotocoldialog.cpp +++ b/src/dialogs/choosecertificateprotocoldialog.cpp @@ -1,124 +1,150 @@ /* -*- 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 SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "choosecertificateprotocoldialog.h" #include "utils/scrollarea.h" #include #include -#include #include +#include #include +#include #include using namespace Kleo; class ChooseCertificateProtocolDialog::Private { friend class ::Kleo::ChooseCertificateProtocolDialog; ChooseCertificateProtocolDialog *const q; struct UI { - QCommandLinkButton *pgpCLB = nullptr; - QCommandLinkButton *x509CLB = nullptr; + QPushButton *openpgpButton = nullptr; + QPushButton *x509Button = nullptr; + QDialogButtonBox *buttonBox = 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(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); + { + auto group = new QGroupBox{i18n("OpenPGP"), parent}; + group->setFlat(true); + auto groupLayout = new QVBoxLayout{group}; + const auto infoText = i18n("OpenPGP key pairs are certified by confirming the fingerprint of the public key."); + auto label = new QLabel{infoText, parent}; + label->setWordWrap(true); + groupLayout->addWidget(label); + openpgpButton = new QPushButton{parent}; + openpgpButton->setText(i18n("Create a Personal OpenPGP Key Pair")); + openpgpButton->setAccessibleDescription(infoText); - scrollAreaLayout->addWidget(pgpCLB); + groupLayout->addWidget(openpgpButton); + scrollAreaLayout->addWidget(group); + } - 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(new KSeparator{Qt::Horizontal, parent}); + + { + auto group = new QGroupBox{i18n("X.509"), parent}; + group->setFlat(true); + auto groupLayout = new QVBoxLayout{group}; + const auto infoText = 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."); + auto label = new QLabel{infoText, parent}; + label->setWordWrap(true); + groupLayout->addWidget(label); + x509Button = new QPushButton{parent}; + x509Button->setText(i18n("Create a Personal X.509 Key Pair and Certification Request")); + x509Button->setAccessibleDescription(infoText); - scrollAreaLayout->addWidget(x509CLB); + groupLayout->addWidget(x509Button); + scrollAreaLayout->addWidget(group); + } mainLayout->addWidget(scrollArea); mainLayout->addStretch(1); mainLayout->addWidget(new KSeparator{Qt::Horizontal, parent}); - auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Cancel, parent}; + buttonBox = new QDialogButtonBox{QDialogButtonBox::Cancel, parent}; + buttonBox->button(QDialogButtonBox::Cancel)->setAutoDefault(false); 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")); + + connect(ui.openpgpButton, &QAbstractButton::clicked, q, [this]() { + protocol = GpgME::OpenPGP; + q->accept(); + }); + connect(ui.x509Button, &QAbstractButton::clicked, q, [this]() { + protocol = GpgME::CMS; + q->accept(); + }); + connect(ui.buttonBox, &QDialogButtonBox::rejected, q, &QDialog::reject); } + +private: + GpgME::Protocol protocol = GpgME::UnknownProtocol; }; 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; + return d->protocol; } 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); }