diff --git a/src/commands/checksumcreatefilescommand.cpp b/src/commands/checksumcreatefilescommand.cpp index 91122af70..3f5f6dba2 100644 --- a/src/commands/checksumcreatefilescommand.cpp +++ b/src/commands/checksumcreatefilescommand.cpp @@ -1,170 +1,170 @@ /* -*- mode: c++; c-basic-offset:4 -*- commands/checksumcreatefilescommand.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "checksumcreatefilescommand.h" #include "command_p.h" #include #include #include #include #include "kleopatra_debug.h" #include using namespace Kleo; using namespace Kleo::Commands; using namespace Kleo::Crypto; class ChecksumCreateFilesCommand::Private : public Command::Private { friend class ::Kleo::Commands::ChecksumCreateFilesCommand; ChecksumCreateFilesCommand *q_func() const { return static_cast(q); } public: explicit Private(ChecksumCreateFilesCommand *qq, KeyListController *c); ~Private() override; QStringList selectFiles() const; void init(); private: void slotControllerDone() { finished(); } void slotControllerError(int, const QString &) { finished(); } private: QStringList files; std::shared_ptr shared_qq; CreateChecksumsController controller; }; ChecksumCreateFilesCommand::Private *ChecksumCreateFilesCommand::d_func() { return static_cast(d.get()); } const ChecksumCreateFilesCommand::Private *ChecksumCreateFilesCommand::d_func() const { return static_cast(d.get()); } #define d d_func() #define q q_func() ChecksumCreateFilesCommand::Private::Private(ChecksumCreateFilesCommand *qq, KeyListController *c) : Command::Private(qq, c), files(), shared_qq(qq, [](ChecksumCreateFilesCommand*){}), controller() { controller.setAllowAddition(true); } ChecksumCreateFilesCommand::Private::~Private() { qCDebug(KLEOPATRA_LOG); } ChecksumCreateFilesCommand::ChecksumCreateFilesCommand(KeyListController *c) : Command(new Private(this, c)) { d->init(); } ChecksumCreateFilesCommand::ChecksumCreateFilesCommand(QAbstractItemView *v, KeyListController *c) : Command(v, new Private(this, c)) { d->init(); } ChecksumCreateFilesCommand::ChecksumCreateFilesCommand(const QStringList &files, KeyListController *c) : Command(new Private(this, c)) { d->init(); d->files = files; } ChecksumCreateFilesCommand::ChecksumCreateFilesCommand(const QStringList &files, QAbstractItemView *v, KeyListController *c) : Command(v, new Private(this, c)) { d->init(); d->files = files; } void ChecksumCreateFilesCommand::Private::init() { controller.setExecutionContext(shared_qq); - connect(&controller, SIGNAL(done()), q, SLOT(slotControllerDone())); - connect(&controller, SIGNAL(error(int,QString)), q, SLOT(slotControllerError(int,QString))); + connect(&controller, &Crypto::Controller::done, q, [this]() { slotControllerDone(); }); + connect(&controller, &Crypto::Controller::error, q, [this](int err, const QString &details) { slotControllerError(err,details); }); } ChecksumCreateFilesCommand::~ChecksumCreateFilesCommand() { qCDebug(KLEOPATRA_LOG); } void ChecksumCreateFilesCommand::setFiles(const QStringList &files) { d->files = files; } void ChecksumCreateFilesCommand::doStart() { try { if (d->files.empty()) { d->files = d->selectFiles(); } if (d->files.empty()) { d->finished(); return; } d->controller.setFiles(d->files); d->controller.start(); } catch (const std::exception &e) { d->information(i18n("An error occurred: %1", QString::fromLocal8Bit(e.what())), i18n("Create Checksum Files Error")); d->finished(); } } void ChecksumCreateFilesCommand::doCancel() { qCDebug(KLEOPATRA_LOG); d->controller.cancel(); } QStringList ChecksumCreateFilesCommand::Private::selectFiles() const { return FileDialog::getOpenFileNames(parentWidgetOrView(), i18n("Select One or More Files to Create Checksums For"), QStringLiteral("chk")); } #undef d #undef q #include "moc_checksumcreatefilescommand.cpp" diff --git a/src/crypto/controller.cpp b/src/crypto/controller.cpp index 3064bbad8..abf2c1c43 100644 --- a/src/crypto/controller.cpp +++ b/src/crypto/controller.cpp @@ -1,79 +1,79 @@ /* -*- mode: c++; c-basic-offset:4 -*- crypto/controller.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "controller.h" using namespace Kleo; using namespace Kleo::Crypto; class Controller::Private { friend class ::Kleo::Crypto::Controller; Controller *const q; public: explicit Private(Controller *qq) : q(qq) { } private: int lastError = 0; QString lastErrorString; }; Controller::Controller(QObject *parent) : QObject(parent), ExecutionContextUser(), d(new Private(this)) { } Controller::Controller(const std::shared_ptr &ctx, QObject *parent) : QObject(parent), ExecutionContextUser(ctx), d(new Private(this)) { } Controller::~Controller() {} void Controller::taskDone(const std::shared_ptr &result) { const Task *task = qobject_cast(sender()); Q_ASSERT(task); doTaskDone(task, result); } void Controller::doTaskDone(const Task *, const std::shared_ptr &) {} void Controller::connectTask(const std::shared_ptr &task) { Q_ASSERT(task); connect(task.get(), &Task::result, this, &Controller::taskDone); } void Controller::setLastError(int err, const QString &msg) { d->lastError = err; d->lastErrorString = msg; } void Controller::emitDoneOrError() { if (d->lastError) { - Q_EMIT error(d->lastError, d->lastErrorString); + Q_EMIT error(d->lastError, d->lastErrorString, QPrivateSignal{}); d->lastError = 0; d->lastErrorString = QString(); } else { - done(); + Q_EMIT done(QPrivateSignal{}); } } diff --git a/src/crypto/controller.h b/src/crypto/controller.h index ab3d51250..493ad1c9c 100644 --- a/src/crypto/controller.h +++ b/src/crypto/controller.h @@ -1,66 +1,75 @@ /* -*- mode: c++; c-basic-offset:4 -*- crypto/controller.h This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once #include #include #include #include #include namespace Kleo { namespace Crypto { class Controller : public QObject, protected ExecutionContextUser { Q_OBJECT public: explicit Controller(QObject *parent = nullptr); explicit Controller(const std::shared_ptr &cmd, QObject *parent = nullptr); ~Controller() override; using ExecutionContextUser::setExecutionContext; Q_SIGNALS: void progress(int current, int total, const QString &what); protected: void emitDoneOrError(); void setLastError(int err, const QString &details); void connectTask(const std::shared_ptr &task); virtual void doTaskDone(const Task *task, const std::shared_ptr &result); protected Q_SLOTS: void taskDone(const std::shared_ptr &); Q_SIGNALS: - -#ifndef Q_MOC_RUN -# ifndef DOXYGEN_SHOULD_SKIP_THIS -private: // don't tell moc or doxygen, but those signals are in fact private -# endif -#endif - void error(int err, const QString &details); - void done(); + /** + * Private signal, you can connect to it, but derived classes cannot emit it. + */ + void error(int err, const QString &details + # ifndef DOXYGEN_SHOULD_SKIP_THIS + , QPrivateSignal + #endif + ); + + /** + * Private signal, you can connect to it, but derived classes cannot emit it. + */ + void done( + # ifndef DOXYGEN_SHOULD_SKIP_THIS + QPrivateSignal + #endif + ); private: class Private; kdtools::pimpl_ptr d; }; } }