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

Modernize and clean up code

* Remove unused c'tor
* Use new style connects
* Use QObjectCleanupHandler for resource handling
* Print actually useful debug information

GnuPG-bug-id: 5916
parent 301f02e6
......@@ -3,6 +3,8 @@
This file is part of Kleopatra, the KDE keymanager
SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB
SPDX-FileCopyrightText: 2022 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -19,12 +21,13 @@
#include <QGpgME/Protocol>
#include <QGpgME/QuickJob>
#include <QObjectCleanupHandler>
#include <gpgme++/key.h>
#include <KLocalizedString>
#include "kleopatra_debug.h"
using namespace Kleo;
using namespace Kleo::Commands;
using namespace GpgME;
......@@ -40,8 +43,6 @@ public:
explicit Private(AddUserIDCommand *qq, KeyListController *c);
~Private() override;
void init();
private:
void slotDialogAccepted();
void slotDialogRejected();
......@@ -55,6 +56,7 @@ private:
private:
GpgME::Key key;
QObjectCleanupHandler cleaner;
QPointer<AddUserIDDialog> dialog;
QPointer<QGpgME::QuickJob> job;
};
......@@ -72,64 +74,43 @@ const AddUserIDCommand::Private *AddUserIDCommand::d_func() const
#define q q_func()
AddUserIDCommand::Private::Private(AddUserIDCommand *qq, KeyListController *c)
: Command::Private(qq, c),
key(),
dialog(),
job()
: Command::Private{qq, c}
{
}
AddUserIDCommand::Private::~Private()
{
qCDebug(KLEOPATRA_LOG);
if (dialog) {
delete dialog;
}
}
AddUserIDCommand::AddUserIDCommand(KeyListController *c)
: Command(new Private(this, c))
{
d->init();
}
AddUserIDCommand::Private::~Private() = default;
AddUserIDCommand::AddUserIDCommand(QAbstractItemView *v, KeyListController *c)
: Command(v, new Private(this, c))
: Command{v, new Private{this, c}}
{
d->init();
}
AddUserIDCommand::AddUserIDCommand(const GpgME::Key &key)
: Command(key, new Private(this, nullptr))
: Command{key, new Private{this, nullptr}}
{
d->init();
}
void AddUserIDCommand::Private::init()
{
}
AddUserIDCommand::~AddUserIDCommand()
{
qCDebug(KLEOPATRA_LOG);
qCDebug(KLEOPATRA_LOG).nospace() << this << "::" << __func__;
}
void AddUserIDCommand::doStart()
{
const std::vector<Key> keys = d->keys();
if (keys.size() != 1 ||
keys.front().protocol() != GpgME::OpenPGP ||
!keys.front().hasSecret()) {
if (keys.size() != 1) {
d->finished();
return;
}
d->key = keys.front();
if (d->key.protocol() != GpgME::OpenPGP
|| !d->key.hasSecret()) {
d->finished();
return;
}
d->ensureDialogCreated();
Q_ASSERT(d->dialog);
const UserID uid = d->key.userID(0);
......@@ -159,9 +140,8 @@ void AddUserIDCommand::Private::slotDialogRejected()
void AddUserIDCommand::Private::slotResult(const Error &err)
{
if (err.isCanceled())
;
else if (err) {
if (err.isCanceled()) {
} else if (err) {
showErrorDialog(err);
} else {
showSuccessDialog();
......@@ -171,7 +151,7 @@ void AddUserIDCommand::Private::slotResult(const Error &err)
void AddUserIDCommand::doCancel()
{
qCDebug(KLEOPATRA_LOG);
qCDebug(KLEOPATRA_LOG).nospace() << this << "::" << __func__;
if (d->job) {
d->job->slotCancel();
}
......@@ -184,10 +164,11 @@ void AddUserIDCommand::Private::ensureDialogCreated()
}
dialog = new AddUserIDDialog;
cleaner.add(dialog);
applyWindowID(dialog);
connect(dialog, SIGNAL(accepted()), q, SLOT(slotDialogAccepted()));
connect(dialog, SIGNAL(rejected()), q, SLOT(slotDialogRejected()));
connect(dialog, &QDialog::accepted, q, [this]() { slotDialogAccepted(); });
connect(dialog, &QDialog::rejected, q, [this]() { slotDialogRejected(); });
}
void AddUserIDCommand::Private::createJob()
......@@ -206,8 +187,8 @@ void AddUserIDCommand::Private::createJob()
connect(j, &QGpgME::Job::progress,
q, &Command::progress);
connect(j, SIGNAL(result(GpgME::Error)),
q, SLOT(slotResult(GpgME::Error)));
connect(j, &QGpgME::QuickJob::result,
q, [this](const GpgME::Error &err) { slotResult(err); });
job = j;
}
......
......@@ -3,13 +3,15 @@
This file is part of Kleopatra, the KDE keymanager
SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB
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 <commands/command.h>
#include "command.h"
namespace Kleo
{
......@@ -21,7 +23,6 @@ class AddUserIDCommand : public Command
Q_OBJECT
public:
explicit AddUserIDCommand(QAbstractItemView *view, KeyListController *parent);
explicit AddUserIDCommand(KeyListController *parent);
explicit AddUserIDCommand(const GpgME::Key &key);
~AddUserIDCommand() override;
......@@ -47,11 +48,7 @@ private:
class Private;
inline Private *d_func();
inline const Private *d_func() const;
Q_PRIVATE_SLOT(d_func(), void slotResult(GpgME::Error))
Q_PRIVATE_SLOT(d_func(), void slotDialogAccepted())
Q_PRIVATE_SLOT(d_func(), void slotDialogRejected())
};
}
}
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