diff --git a/src/uiserver/createchecksumscommand.cpp b/src/uiserver/createchecksumscommand.cpp index 80f1a197b..c35aefb25 100644 --- a/src/uiserver/createchecksumscommand.cpp +++ b/src/uiserver/createchecksumscommand.cpp @@ -1,87 +1,85 @@ /* -*- mode: c++; c-basic-offset:4 -*- uiserver/createchecksumscommand.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "createchecksumscommand.h" #include #include #include using namespace Kleo; using namespace Kleo::Crypto; class CreateChecksumsCommand::Private { private: friend class ::Kleo::CreateChecksumsCommand; CreateChecksumsCommand *const q; public: explicit Private(CreateChecksumsCommand *qq) : q(qq), controller() { } private: void checkForErrors() const; private: std::shared_ptr controller; }; CreateChecksumsCommand::CreateChecksumsCommand() : AssuanCommandMixin(), d(new Private(this)) { } CreateChecksumsCommand::~CreateChecksumsCommand() {} void CreateChecksumsCommand::Private::checkForErrors() const { if (!q->numFiles()) throw Exception(makeError(GPG_ERR_ASS_NO_INPUT), i18n("At least one FILE must be present")); } int CreateChecksumsCommand::doStart() { d->checkForErrors(); d->controller.reset(new CreateChecksumsController(shared_from_this())); d->controller->setAllowAddition(hasOption("allow-addition")); d->controller->setFiles(fileNames()); - connect(d->controller.get(), SIGNAL(done()), - this, SLOT(done()), Qt::QueuedConnection); - connect(d->controller.get(), SIGNAL(error(int,QString)), - this, SLOT(done(int,QString)), Qt::QueuedConnection); + connect(d->controller.get(), &Controller::done, this, [this]() { done(); }, Qt::QueuedConnection); + connect(d->controller.get(), &Controller::error, this, [this](int err, const QString &details) { done(err, details); }, Qt::QueuedConnection); d->controller->start(); return 0; } void CreateChecksumsCommand::doCanceled() { if (d->controller) { d->controller->cancel(); } } diff --git a/src/uiserver/decryptverifycommandemailbase.cpp b/src/uiserver/decryptverifycommandemailbase.cpp index 5e4fc683b..e4cdef2e5 100644 --- a/src/uiserver/decryptverifycommandemailbase.cpp +++ b/src/uiserver/decryptverifycommandemailbase.cpp @@ -1,214 +1,212 @@ /* -*- mode: c++; c-basic-offset:4 -*- uiserver/decryptverifycommandemailbase.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "decryptverifycommandemailbase.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace Kleo; using namespace Kleo::Crypto; using namespace Kleo::Formatting; using namespace GpgME; class DecryptVerifyCommandEMailBase::Private : public QObject { Q_OBJECT friend class ::Kleo::DecryptVerifyCommandEMailBase; DecryptVerifyCommandEMailBase *const q; public: explicit Private(DecryptVerifyCommandEMailBase *qq) : QObject(), q(qq), controller() { } ~Private() override { } void checkForErrors() const; public Q_SLOTS: void slotProgress(const QString &what, int current, int total); void verificationResult(const GpgME::VerificationResult &); void slotDone() { q->done(); } void slotError(int err, const QString &details) { q->done(err, details); } public: private: std::shared_ptr controller; }; DecryptVerifyCommandEMailBase::DecryptVerifyCommandEMailBase() : AssuanCommandMixin(), d(new Private(this)) { } DecryptVerifyCommandEMailBase::~DecryptVerifyCommandEMailBase() {} int DecryptVerifyCommandEMailBase::doStart() { d->checkForErrors(); d->controller.reset(new DecryptVerifyEMailController(shared_from_this())); const QString st = sessionTitle(); if (!st.isEmpty()) { const std::vector> allInputs = inputs(); for (const std::shared_ptr &i : allInputs) { i->setLabel(st); } } d->controller->setSessionId(sessionId()); d->controller->setOperation(operation()); d->controller->setVerificationMode(messages().empty() ? Opaque : Detached); d->controller->setInputs(inputs()); d->controller->setSignedData(messages()); d->controller->setOutputs(outputs()); d->controller->setWizardShown(!hasOption("silent")); d->controller->setProtocol(checkProtocol(mode())); if (informativeSenders()) { d->controller->setInformativeSenders(senders()); } - QObject::connect(d->controller.get(), SIGNAL(done()), - d.get(), SLOT(slotDone()), Qt::QueuedConnection); - QObject::connect(d->controller.get(), SIGNAL(error(int,QString)), - d.get(), SLOT(slotError(int,QString)), Qt::QueuedConnection); + QObject::connect(d->controller.get(), &Controller::done, d.get(), &Private::slotDone, Qt::QueuedConnection); + QObject::connect(d->controller.get(), &Controller::error, d.get(), &Private::slotError, Qt::QueuedConnection); QObject::connect(d->controller.get(), &DecryptVerifyEMailController::verificationResult, d.get(), &Private::verificationResult, Qt::QueuedConnection); d->controller->start(); return 0; } void DecryptVerifyCommandEMailBase::Private::checkForErrors() const { if (!q->senders().empty() && !q->informativeSenders()) throw Kleo::Exception(q->makeError(GPG_ERR_CONFLICT), i18n("Cannot use non-info SENDER")); if (!q->recipients().empty() && !q->informativeRecipients()) throw Kleo::Exception(q->makeError(GPG_ERR_CONFLICT), i18n("Cannot use non-info RECIPIENT")); // ### use informative recipients and senders const unsigned int numInputs = q->inputs().size(); const unsigned int numMessages = q->messages().size(); const unsigned int numOutputs = q->outputs().size(); const unsigned int numInformativeSenders = q->informativeSenders() ? q->senders().size() : 0; const DecryptVerifyOperation op = q->operation(); const GpgME::Protocol proto = q->checkProtocol(q->mode()); const unsigned int numFiles = q->numFiles(); if (numFiles) { throw Kleo::Exception(q->makeError(GPG_ERR_CONFLICT), i18n("FILES present")); } if (!numInputs) throw Kleo::Exception(q->makeError(GPG_ERR_ASS_NO_INPUT), i18n("At least one INPUT needs to be provided")); if (numInformativeSenders != 0) if (numInformativeSenders != numInputs) throw Kleo::Exception(q->makeError(GPG_ERR_ASS_NO_INPUT), //TODO use better error code if possible i18n("INPUT/SENDER --info count mismatch")); if (numMessages) { if (numMessages != numInputs) throw Kleo::Exception(q->makeError(GPG_ERR_ASS_NO_INPUT), //TODO use better error code if possible i18n("INPUT/MESSAGE count mismatch")); else if (op != Verify) throw Kleo::Exception(q->makeError(GPG_ERR_CONFLICT), i18n("MESSAGE can only be given for detached signature verification")); } if (numOutputs) { if (numOutputs != numInputs) throw Kleo::Exception(q->makeError(GPG_ERR_ASS_NO_OUTPUT), //TODO use better error code if possible i18n("INPUT/OUTPUT count mismatch")); else if (numMessages) throw Kleo::Exception(q->makeError(GPG_ERR_CONFLICT), i18n("Cannot use OUTPUT and MESSAGE simultaneously")); } kleo_assert(proto != UnknownProtocol); const auto backend = (proto == GpgME::OpenPGP) ? QGpgME::openpgp() : QGpgME::smime(); if (!backend) throw Kleo::Exception(q->makeError(GPG_ERR_UNSUPPORTED_PROTOCOL), proto == OpenPGP ? i18n("No backend support for OpenPGP") : proto == CMS ? i18n("No backend support for S/MIME") : QString()); } void DecryptVerifyCommandEMailBase::doCanceled() { if (d->controller) { d->controller->cancel(); } } void DecryptVerifyCommandEMailBase::Private::slotProgress(const QString &what, int current, int total) { Q_UNUSED(what) Q_UNUSED(current) Q_UNUSED(total) // ### FIXME report progress, via sendStatus() } void DecryptVerifyCommandEMailBase::Private::verificationResult(const VerificationResult &vResult) { try { const std::vector sigs = vResult.signatures(); for (const Signature &sig : sigs) { const QString s = signatureToString(sig, sig.key(true, true)); const char *color = summaryToString(sig.summary()); q->sendStatusEncoded("SIGSTATUS", color + (' ' + hexencode(s.toUtf8().constData()))); } } catch (...) {} } #include "decryptverifycommandemailbase.moc" diff --git a/src/uiserver/decryptverifycommandfilesbase.cpp b/src/uiserver/decryptverifycommandfilesbase.cpp index a9b89cf5e..db2632945 100644 --- a/src/uiserver/decryptverifycommandfilesbase.cpp +++ b/src/uiserver/decryptverifycommandfilesbase.cpp @@ -1,192 +1,190 @@ /* -*- mode: c++; c-basic-offset:4 -*- uiserver/decryptverifycommandfilesbase.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "decryptverifycommandfilesbase.h" #include "fileoperationspreferences.h" #include #include "crypto/decryptverifyfilescontroller.h" #include "crypto/autodecryptverifyfilescontroller.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace Kleo; using namespace Kleo::Crypto; using namespace Kleo::Formatting; using namespace GpgME; class DecryptVerifyCommandFilesBase::Private : public QObject { Q_OBJECT friend class ::Kleo::DecryptVerifyCommandFilesBase; DecryptVerifyCommandFilesBase *const q; public: explicit Private(DecryptVerifyCommandFilesBase *qq) : QObject(), q(qq), controller() { } ~Private() override { } void checkForErrors() const; public Q_SLOTS: void slotProgress(const QString &what, int current, int total); void verificationResult(const GpgME::VerificationResult &); void slotDone() { q->done(); } void slotError(int err, const QString &details) { q->done(err, details); } public: private: std::shared_ptr controller; }; DecryptVerifyCommandFilesBase::DecryptVerifyCommandFilesBase() : AssuanCommandMixin(), d(new Private(this)) { } DecryptVerifyCommandFilesBase::~DecryptVerifyCommandFilesBase() {} int DecryptVerifyCommandFilesBase::doStart() { d->checkForErrors(); FileOperationsPreferences prefs; if (prefs.autoDecryptVerify()) { d->controller.reset(new AutoDecryptVerifyFilesController()); } else { d->controller.reset(new DecryptVerifyFilesController(shared_from_this())); } d->controller->setOperation(operation()); d->controller->setFiles(fileNames()); - QObject::connect(d->controller.get(), SIGNAL(done()), - d.get(), SLOT(slotDone()), Qt::QueuedConnection); - QObject::connect(d->controller.get(), SIGNAL(error(int,QString)), - d.get(), SLOT(slotError(int,QString)), Qt::QueuedConnection); + QObject::connect(d->controller.get(), &Controller::done, d.get(), &Private::slotDone, Qt::QueuedConnection); + QObject::connect(d->controller.get(), &Controller::error, d.get(), &Private::slotError, Qt::QueuedConnection); QObject::connect(d->controller.get(), &DecryptVerifyFilesController::verificationResult, d.get(), &Private::verificationResult, Qt::QueuedConnection); d->controller->start(); return 0; } namespace { struct is_file { bool operator()(const QString &file) const { return QFileInfo(file).isFile(); } }; } void DecryptVerifyCommandFilesBase::Private::checkForErrors() const { if (!q->senders().empty()) throw Kleo::Exception(q->makeError(GPG_ERR_CONFLICT), i18n("Cannot use SENDER")); if (!q->recipients().empty()) throw Kleo::Exception(q->makeError(GPG_ERR_CONFLICT), i18n("Cannot use RECIPIENT")); const unsigned int numInputs = q->inputs().size(); const unsigned int numMessages = q->messages().size(); const unsigned int numOutputs = q->outputs().size(); if (numInputs) { throw Kleo::Exception(q->makeError(GPG_ERR_CONFLICT), i18n("INPUT present")); } if (numMessages) { throw Kleo::Exception(q->makeError(GPG_ERR_CONFLICT), i18n("MESSAGE present")); } if (numOutputs) { throw Kleo::Exception(q->makeError(GPG_ERR_CONFLICT), i18n("OUTPUT present")); } const QStringList fileNames = q->fileNames(); if (fileNames.empty()) throw Exception(makeError(GPG_ERR_ASS_NO_INPUT), i18n("At least one FILE must be present")); if (!std::all_of(fileNames.cbegin(), fileNames.cend(), is_file())) throw Exception(makeError(GPG_ERR_INV_ARG), i18n("DECRYPT/VERIFY_FILES cannot use directories as input")); } void DecryptVerifyCommandFilesBase::doCanceled() { if (d->controller) { d->controller->cancel(); } } void DecryptVerifyCommandFilesBase::Private::slotProgress(const QString &what, int current, int total) { Q_UNUSED(what) Q_UNUSED(current) Q_UNUSED(total) // ### FIXME report progress, via sendStatus() } void DecryptVerifyCommandFilesBase::Private::verificationResult(const VerificationResult &vResult) { try { const std::vector sigs = vResult.signatures(); for (const Signature &sig : sigs) { const QString s = signatureToString(sig, sig.key(true, true)); const char *color = summaryToString(sig.summary()); q->sendStatusEncoded("SIGSTATUS", color + (' ' + hexencode(s.toUtf8().constData()))); } } catch (...) {} } #include "decryptverifycommandfilesbase.moc" diff --git a/src/uiserver/encryptcommand.cpp b/src/uiserver/encryptcommand.cpp index 8e65d221e..f8c7224f1 100644 --- a/src/uiserver/encryptcommand.cpp +++ b/src/uiserver/encryptcommand.cpp @@ -1,210 +1,210 @@ /* -*- mode: c++; c-basic-offset:4 -*- uiserver/encryptcommand.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "encryptcommand.h" #include #include #include #include #include #include #include using namespace Kleo; using namespace Kleo::Crypto; class EncryptCommand::Private : public QObject { Q_OBJECT private: friend class ::Kleo::EncryptCommand; EncryptCommand *const q; public: explicit Private(EncryptCommand *qq) : q(qq), controller() { } private: void checkForErrors() const; + void connectController(); private Q_SLOTS: void slotDone(); void slotError(int, const QString &); void slotRecipientsResolved(); private: std::shared_ptr controller; }; EncryptCommand::EncryptCommand() : AssuanCommandMixin(), d(new Private(this)) { } EncryptCommand::~EncryptCommand() {} void EncryptCommand::Private::checkForErrors() const { if (q->numFiles()) throw Exception(makeError(GPG_ERR_CONFLICT), i18n("ENCRYPT is an email mode command, connection seems to be in filemanager mode")); if (!q->senders().empty() && !q->informativeSenders()) throw Exception(makeError(GPG_ERR_CONFLICT), i18n("SENDER may not be given prior to ENCRYPT, except with --info")); if (q->inputs().empty()) throw Exception(makeError(GPG_ERR_ASS_NO_INPUT), i18n("At least one INPUT must be present")); if (q->outputs().empty()) throw Exception(makeError(GPG_ERR_ASS_NO_OUTPUT), i18n("At least one OUTPUT must be present")); if (q->outputs().size() != q->inputs().size()) throw Exception(makeError(GPG_ERR_CONFLICT), i18n("INPUT/OUTPUT count mismatch")); if (!q->messages().empty()) throw Exception(makeError(GPG_ERR_INV_VALUE), i18n("MESSAGE command is not allowed before ENCRYPT")); const auto m = q->mementoContent< std::shared_ptr >(NewSignEncryptEMailController::mementoName()); kleo_assert(m); if (m && m->isEncrypting()) { if (m->protocol() != q->checkProtocol(EMail)) throw Exception(makeError(GPG_ERR_CONFLICT), i18n("Protocol given conflicts with protocol determined by PREP_ENCRYPT")); if (!q->recipients().empty()) throw Exception(makeError(GPG_ERR_CONFLICT), i18n("New recipients added after PREP_ENCRYPT command")); if (!q->senders().empty()) throw Exception(makeError(GPG_ERR_CONFLICT), i18n("New senders added after PREP_ENCRYPT command")); } else { if (q->recipients().empty() || q->informativeRecipients()) throw Exception(makeError(GPG_ERR_MISSING_VALUE), i18n("No recipients given, or only with --info")); } } -static void connectController(const QObject *controller, const QObject *d) +void EncryptCommand::Private::connectController() { - - QObject::connect(controller, SIGNAL(certificatesResolved()), d, SLOT(slotRecipientsResolved())); - QObject::connect(controller, SIGNAL(done()), d, SLOT(slotDone())); - QObject::connect(controller, SIGNAL(error(int,QString)), d, SLOT(slotError(int,QString))); - + auto ptr = controller.get(); + connect(ptr, &NewSignEncryptEMailController::certificatesResolved, this, &EncryptCommand::Private::slotRecipientsResolved); + connect(ptr, &Controller::done, this, &EncryptCommand::Private::slotDone); + connect(ptr, &Controller::error, this, &EncryptCommand::Private::slotError); } int EncryptCommand::doStart() { d->checkForErrors(); const auto seec = mementoContent< std::shared_ptr >(NewSignEncryptEMailController::mementoName()); if (seec && seec->isEncrypting()) { // reuse the controller from a previous PREP_ENCRYPT, if available: d->controller = seec; - connectController(seec.get(), d.get()); + d->connectController(); removeMemento(NewSignEncryptEMailController::mementoName()); d->controller->setExecutionContext(shared_from_this()); if (seec->areCertificatesResolved()) { QTimer::singleShot(0, d.get(), &Private::slotRecipientsResolved); } else { kleo_assert(seec->isResolvingInProgress()); } } else { // use a new controller d->controller.reset(new NewSignEncryptEMailController(shared_from_this())); const QString session = sessionTitle(); if (!session.isEmpty()) { d->controller->setSubject(session); } d->controller->setEncrypting(true); d->controller->setSigning(false); d->controller->setProtocol(checkProtocol(EMail)); - connectController(d->controller.get(), d.get()); + d->connectController(); d->controller->startResolveCertificates(recipients(), senders()); } return 0; } void EncryptCommand::Private::slotRecipientsResolved() { //hold local std::shared_ptr to member as q->done() deletes *this const std::shared_ptr cont(controller); try { const QString sessionTitle = q->sessionTitle(); if (!sessionTitle.isEmpty()) { const std::vector> allInputs = q->inputs(); for (const std::shared_ptr &i : allInputs) { i->setLabel(sessionTitle); } } cont->startEncryption(q->inputs(), q->outputs()); return; } catch (const Exception &e) { q->done(e.error(), e.message()); } catch (const std::exception &e) { q->done(makeError(GPG_ERR_UNEXPECTED), i18n("Caught unexpected exception in EncryptCommand::Private::slotRecipientsResolved: %1", QString::fromLocal8Bit(e.what()))); } catch (...) { q->done(makeError(GPG_ERR_UNEXPECTED), i18n("Caught unknown exception in EncryptCommand::Private::slotRecipientsResolved")); } cont->cancel(); } void EncryptCommand::Private::slotDone() { q->done(); } void EncryptCommand::Private::slotError(int err, const QString &details) { q->done(err, details); } void EncryptCommand::doCanceled() { if (d->controller) { d->controller->cancel(); } } #include "encryptcommand.moc" diff --git a/src/uiserver/prepsigncommand.cpp b/src/uiserver/prepsigncommand.cpp index 883ada643..c9cf3f696 100644 --- a/src/uiserver/prepsigncommand.cpp +++ b/src/uiserver/prepsigncommand.cpp @@ -1,178 +1,180 @@ /* -*- mode: c++; c-basic-offset:4 -*- uiserver/prepsigncommand.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "prepsigncommand.h" #include #include #include #include #include #include using namespace Kleo; using namespace Kleo::Crypto; class PrepSignCommand::Private : public QObject { Q_OBJECT private: friend class ::Kleo::PrepSignCommand; PrepSignCommand *const q; public: explicit Private(PrepSignCommand *qq) : q(qq), controller() {} private: void checkForErrors() const; + void connectController(); public Q_SLOTS: void slotSignersResolved(); void slotError(int, const QString &); private: std::shared_ptr controller; }; PrepSignCommand::PrepSignCommand() : AssuanCommandMixin(), d(new Private(this)) { } PrepSignCommand::~PrepSignCommand() {} void PrepSignCommand::Private::checkForErrors() const { if (!q->inputs().empty() || !q->outputs().empty() || !q->messages().empty()) throw Exception(makeError(GPG_ERR_CONFLICT), i18n("INPUT/OUTPUT/MESSAGE may only be given after PREP_SIGN")); if (q->numFiles()) throw Exception(makeError(GPG_ERR_CONFLICT), i18n("PREP_SIGN is an email mode command, connection seems to be in filemanager mode")); if (q->senders().empty()) throw Exception(makeError(GPG_ERR_CONFLICT), i18n("No SENDER given")); const auto m = q->mementoContent< std::shared_ptr >(NewSignEncryptEMailController::mementoName()); if (m && m->isSigning()) { if (q->hasOption("protocol")) if (m->protocol() != q->checkProtocol(EMail)) throw Exception(makeError(GPG_ERR_CONFLICT), i18n("Protocol given conflicts with protocol determined by PREP_ENCRYPT in this session")); // ### check that any SENDER here is the same as the one for PREP_ENCRYPT // ### ditto RECIPIENT } } -static void connectController(const QObject *controller, const QObject *d) +void PrepSignCommand::Private::connectController() { - QObject::connect(controller, SIGNAL(certificatesResolved()), d, SLOT(slotSignersResolved())); - QObject::connect(controller, SIGNAL(error(int,QString)), d, SLOT(slotError(int,QString))); + auto ptr = controller.get(); + connect(ptr, &NewSignEncryptEMailController::certificatesResolved, this, &PrepSignCommand::Private::slotSignersResolved); + connect(ptr, &Controller::error, this, &PrepSignCommand::Private::slotError); } int PrepSignCommand::doStart() { d->checkForErrors(); const auto seec = mementoContent< std::shared_ptr >(NewSignEncryptEMailController::mementoName()); if (seec && seec->isSigning()) { // reuse the controller from a previous PREP_ENCRYPT --expect-sign, if available: d->controller = seec; - connectController(seec.get(), d.get()); + d->connectController(); seec->setExecutionContext(shared_from_this()); if (seec->areCertificatesResolved()) { QTimer::singleShot(0, d.get(), &Private::slotSignersResolved); } else { kleo_assert(seec->isResolvingInProgress()); } } else { // use a new controller d->controller.reset(new NewSignEncryptEMailController(shared_from_this())); const QString session = sessionTitle(); if (!session.isEmpty()) { d->controller->setSubject(session); } if (hasOption("protocol")) // --protocol is optional for PREP_SIGN { d->controller->setProtocol(checkProtocol(EMail)); } d->controller->setEncrypting(false); d->controller->setSigning(true); - connectController(d->controller.get(), d.get()); + d->connectController(); d->controller->startResolveCertificates(recipients(), senders()); } return 0; } void PrepSignCommand::Private::slotSignersResolved() { //hold local std::shared_ptr to member as q->done() deletes *this const std::shared_ptr cont = controller; QPointer that(this); try { q->sendStatus("PROTOCOL", QLatin1String(controller->protocolAsString())); q->registerMemento(NewSignEncryptEMailController::mementoName(), make_typed_memento(controller)); q->done(); return; } catch (const Exception &e) { q->done(e.error(), e.message()); } catch (const std::exception &e) { q->done(makeError(GPG_ERR_UNEXPECTED), i18n("Caught unexpected exception in PrepSignCommand::Private::slotRecipientsResolved: %1", QString::fromLocal8Bit(e.what()))); } catch (...) { q->done(makeError(GPG_ERR_UNEXPECTED), i18n("Caught unknown exception in PrepSignCommand::Private::slotRecipientsResolved")); } if (that) { // isn't this always deleted here and thus unnecessary? q->removeMemento(NewSignEncryptEMailController::mementoName()); } cont->cancel(); } void PrepSignCommand::Private::slotError(int err, const QString &details) { q->done(err, details); } void PrepSignCommand::doCanceled() { if (d->controller) { d->controller->cancel(); } } #include "prepsigncommand.moc" diff --git a/src/uiserver/signcommand.cpp b/src/uiserver/signcommand.cpp index 71d908b84..170ab21d5 100644 --- a/src/uiserver/signcommand.cpp +++ b/src/uiserver/signcommand.cpp @@ -1,230 +1,233 @@ /* -*- mode: c++; c-basic-offset:4 -*- uiserver/signcommand.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "signcommand.h" #include #include #include #include #include #include #include using namespace Kleo; using namespace Kleo::Crypto; class SignCommand::Private : public QObject { Q_OBJECT private: friend class ::Kleo::SignCommand; SignCommand *const q; public: explicit Private(SignCommand *qq) : q(qq), controller() { } private: void checkForErrors() const; + void connectController(); + private Q_SLOTS: void slotSignersResolved(); void slotMicAlgDetermined(const QString &); void slotDone(); void slotError(int, const QString &); private: std::shared_ptr controller; }; SignCommand::SignCommand() : AssuanCommandMixin(), d(new Private(this)) { } SignCommand::~SignCommand() {} void SignCommand::Private::checkForErrors() const { if (q->numFiles()) throw Exception(makeError(GPG_ERR_CONFLICT), i18n("SIGN is an email mode command, connection seems to be in filemanager mode")); if (!q->recipients().empty() && !q->informativeRecipients()) throw Exception(makeError(GPG_ERR_CONFLICT), i18n("RECIPIENT may not be given prior to SIGN, except with --info")); if (q->inputs().empty()) throw Exception(makeError(GPG_ERR_ASS_NO_INPUT), i18n("At least one INPUT must be present")); if (q->outputs().size() != q->inputs().size()) throw Exception(makeError(GPG_ERR_ASS_NO_INPUT), i18n("INPUT/OUTPUT count mismatch")); if (!q->messages().empty()) throw Exception(makeError(GPG_ERR_INV_VALUE), i18n("MESSAGE command is not allowed before SIGN")); const auto m = q->mementoContent< std::shared_ptr >(NewSignEncryptEMailController::mementoName()); if (m && m->isSigning()) { if (m->protocol() != q->checkProtocol(EMail)) throw Exception(makeError(GPG_ERR_CONFLICT), i18n("Protocol given conflicts with protocol determined by PREP_ENCRYPT in this session")); // ### check that any SENDER here is the same as the one for PREP_ENCRYPT // ### ditto RECIPIENT } else { // ### support the stupid "default signer" semantics of GpgOL // ### where SENDER is missing if (false) if (q->senders().empty() || q->informativeSenders()) throw Exception(makeError(GPG_ERR_MISSING_VALUE), i18n("No senders given, or only with --info")); } } -static void connectController(const QObject *controller, const QObject *d) +void SignCommand::Private::connectController() { - QObject::connect(controller, SIGNAL(certificatesResolved()), d, SLOT(slotSignersResolved())); - QObject::connect(controller, SIGNAL(reportMicAlg(QString)), d, SLOT(slotMicAlgDetermined(QString))); - QObject::connect(controller, SIGNAL(done()), d, SLOT(slotDone())); - QObject::connect(controller, SIGNAL(error(int,QString)), d, SLOT(slotError(int,QString))); + NewSignEncryptEMailController *ptr = controller.get(); + QObject::connect(ptr, &NewSignEncryptEMailController::certificatesResolved, this, &SignCommand::Private::slotSignersResolved); + QObject::connect(ptr, &NewSignEncryptEMailController::reportMicAlg, this, &SignCommand::Private::slotMicAlgDetermined); + QObject::connect(ptr, &Controller::done, this, &SignCommand::Private::slotDone); + QObject::connect(ptr, &Controller::error, this, &SignCommand::Private::slotError); } int SignCommand::doStart() { d->checkForErrors(); const auto seec = mementoContent< std::shared_ptr >(NewSignEncryptEMailController::mementoName()); if (seec && seec->isSigning()) { // reuse the controller from a previous PREP_ENCRYPT --expect-sign, if available: d->controller = seec; - connectController(seec.get(), d.get()); + d->connectController(); if (!seec->isEncrypting()) { removeMemento(NewSignEncryptEMailController::mementoName()); } seec->setExecutionContext(shared_from_this()); if (seec->areCertificatesResolved()) { QTimer::singleShot(0, d.get(), &Private::slotSignersResolved); } else { kleo_assert(seec->isResolvingInProgress()); } } else { // use a new controller d->controller.reset(new NewSignEncryptEMailController(shared_from_this())); const QString session = sessionTitle(); if (!session.isEmpty()) { d->controller->setSubject(session); } d->controller->setSigning(true); d->controller->setEncrypting(false); d->controller->setProtocol(checkProtocol(EMail, AssuanCommand::AllowProtocolMissing)); - connectController(d->controller.get(), d.get()); + d->connectController(); d->controller->startResolveCertificates(recipients(), senders()); } return 0; } void SignCommand::Private::slotSignersResolved() { //hold local std::shared_ptr to member as q->done() deletes *this const std::shared_ptr cont(controller); try { const QString sessionTitle = q->sessionTitle(); if (!sessionTitle.isEmpty()) { const std::vector> allInputs = q->inputs(); for (const std::shared_ptr &i : allInputs) { i->setLabel(sessionTitle); } } cont->setDetachedSignature(q->hasOption("detached")); cont->startSigning(q->inputs(), q->outputs()); return; } catch (const Exception &e) { q->done(e.error(), e.message()); } catch (const std::exception &e) { q->done(makeError(GPG_ERR_UNEXPECTED), i18n("Caught unexpected exception in SignCommand::Private::slotRecipientsResolved: %1", QString::fromLocal8Bit(e.what()))); } catch (...) { q->done(makeError(GPG_ERR_UNEXPECTED), i18n("Caught unknown exception in SignCommand::Private::slotRecipientsResolved")); } cont->cancel(); } void SignCommand::Private::slotMicAlgDetermined(const QString &micalg) { //hold local std::shared_ptr to member as q->done() deletes *this const std::shared_ptr cont(controller); try { q->sendStatus("MICALG", micalg); return; } catch (const Exception &e) { q->done(e.error(), e.message()); } catch (const std::exception &e) { q->done(makeError(GPG_ERR_UNEXPECTED), i18n("Caught unexpected exception in SignCommand::Private::slotMicAlgDetermined: %1", QString::fromLocal8Bit(e.what()))); } catch (...) { q->done(makeError(GPG_ERR_UNEXPECTED), i18n("Caught unknown exception in SignCommand::Private::slotMicAlgDetermined")); } cont->cancel(); } void SignCommand::Private::slotDone() { q->done(); } void SignCommand::Private::slotError(int err, const QString &details) { q->done(err, details); } void SignCommand::doCanceled() { if (d->controller) { d->controller->cancel(); } } #include "signcommand.moc" diff --git a/src/uiserver/signencryptfilescommand.cpp b/src/uiserver/signencryptfilescommand.cpp index 594c1b666..318b1a642 100644 --- a/src/uiserver/signencryptfilescommand.cpp +++ b/src/uiserver/signencryptfilescommand.cpp @@ -1,135 +1,135 @@ /* -*- mode: c++; c-basic-offset:4 -*- uiserver/signencryptfilescommand.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "signencryptfilescommand.h" #include #include #include using namespace Kleo; using namespace Kleo::Crypto; class SignEncryptFilesCommand::Private : public QObject { Q_OBJECT private: friend class ::Kleo::SignEncryptFilesCommand; SignEncryptFilesCommand *const q; public: explicit Private(SignEncryptFilesCommand *qq) : q(qq), controller() { } private: void checkForErrors() const; private Q_SLOTS: void slotDone(); void slotError(int, const QString &); private: std::shared_ptr controller; }; SignEncryptFilesCommand::SignEncryptFilesCommand() : AssuanCommandMixin(), d(new Private(this)) { } SignEncryptFilesCommand::~SignEncryptFilesCommand() {} void SignEncryptFilesCommand::Private::checkForErrors() const { if (!q->numFiles()) throw Exception(makeError(GPG_ERR_ASS_NO_INPUT), i18n("At least one FILE must be present")); if (!q->senders().empty()) throw Exception(makeError(GPG_ERR_CONFLICT), i18n("%1 is a filemanager mode command, " "connection seems to be in email mode (%2 present)", QString::fromLatin1(q->name()), QStringLiteral("SENDER"))); if (!q->recipients().empty()) throw Exception(makeError(GPG_ERR_CONFLICT), i18n("%1 is a filemanager mode command, " "connection seems to be in email mode (%2 present)", QString::fromLatin1(q->name()), QStringLiteral("RECIPIENT"))); if (!q->inputs().empty()) throw Exception(makeError(GPG_ERR_CONFLICT), i18n("%1 is a filemanager mode command, " "connection seems to be in email mode (%2 present)", QString::fromLatin1(q->name()), QStringLiteral("INPUT"))); if (!q->outputs().empty()) throw Exception(makeError(GPG_ERR_CONFLICT), i18n("%1 is a filemanager mode command, " "connection seems to be in email mode (%2 present)", QString::fromLatin1(q->name()), QStringLiteral("OUTPUT"))); if (!q->messages().empty()) throw Exception(makeError(GPG_ERR_CONFLICT), i18n("%1 is a filemanager mode command, " "connection seems to be in email mode (%2 present)", QString::fromLatin1(q->name()), QStringLiteral("MESSAGE"))); } int SignEncryptFilesCommand::doStart() { d->checkForErrors(); d->controller.reset(new SignEncryptFilesController(shared_from_this())); d->controller->setProtocol(checkProtocol(FileManager)); unsigned int op = operation(); if (hasOption("archive")) { op |= SignEncryptFilesController::ArchiveForced; } else { op |= SignEncryptFilesController::ArchiveAllowed; } d->controller->setOperationMode(op); d->controller->setFiles(fileNames()); - QObject::connect(d->controller.get(), SIGNAL(done()), d.get(), SLOT(slotDone()), Qt::QueuedConnection); - QObject::connect(d->controller.get(), SIGNAL(error(int,QString)), d.get(), SLOT(slotError(int,QString)), Qt::QueuedConnection); + QObject::connect(d->controller.get(), &Controller::done, d.get(), &Private::slotDone, Qt::QueuedConnection); + QObject::connect(d->controller.get(), &Controller::error, d.get(), &Private::slotError, Qt::QueuedConnection); d->controller->start(); return 0; } void SignEncryptFilesCommand::Private::slotDone() { q->done(); } void SignEncryptFilesCommand::Private::slotError(int err, const QString &details) { q->done(err, details); } void SignEncryptFilesCommand::doCanceled() { if (d->controller) { d->controller->cancel(); } } #include "signencryptfilescommand.moc" diff --git a/src/uiserver/verifychecksumscommand.cpp b/src/uiserver/verifychecksumscommand.cpp index b659f66af..4783761f9 100644 --- a/src/uiserver/verifychecksumscommand.cpp +++ b/src/uiserver/verifychecksumscommand.cpp @@ -1,88 +1,86 @@ /* -*- mode: c++; c-basic-offset:4 -*- uiserver/verifychecksumscommand.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "verifychecksumscommand.h" #ifndef QT_NO_DIRMODEL #include #include #include using namespace Kleo; using namespace Kleo::Crypto; class VerifyChecksumsCommand::Private { private: friend class ::Kleo::VerifyChecksumsCommand; VerifyChecksumsCommand *const q; public: explicit Private(VerifyChecksumsCommand *qq) : q(qq), controller() { } private: void checkForErrors() const; private: std::shared_ptr controller; }; VerifyChecksumsCommand::VerifyChecksumsCommand() : AssuanCommandMixin(), d(new Private(this)) { } VerifyChecksumsCommand::~VerifyChecksumsCommand() {} void VerifyChecksumsCommand::Private::checkForErrors() const { if (!q->numFiles()) throw Exception(makeError(GPG_ERR_ASS_NO_INPUT), i18n("At least one FILE must be present")); } int VerifyChecksumsCommand::doStart() { d->checkForErrors(); d->controller.reset(new VerifyChecksumsController(shared_from_this())); d->controller->setFiles(fileNames()); - QObject::connect(d->controller.get(), SIGNAL(done()), - this, SLOT(done()), Qt::QueuedConnection); - QObject::connect(d->controller.get(), SIGNAL(error(int,QString)), - this, SLOT(done(int,QString)), Qt::QueuedConnection); + QObject::connect(d->controller.get(), &Controller::done, this, [this]() { done(); }, Qt::QueuedConnection); + QObject::connect(d->controller.get(), &Controller::error, this, [this](int err, const QString &details) { done(err, details); }, Qt::QueuedConnection); d->controller->start(); return 0; } void VerifyChecksumsCommand::doCanceled() { if (d->controller) { d->controller->cancel(); } } #endif // QT_NO_DIRMODEL diff --git a/src/uiserver/verifychecksumscommand.h b/src/uiserver/verifychecksumscommand.h index 776b0b835..df6caa534 100644 --- a/src/uiserver/verifychecksumscommand.h +++ b/src/uiserver/verifychecksumscommand.h @@ -1,53 +1,51 @@ /* -*- mode: c++; c-basic-offset:4 -*- uiserver/verifychecksumscommand.h This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once #include "assuancommand.h" #ifndef QT_NO_DIRMODEL #include namespace Kleo { class VerifyChecksumsCommand : public QObject, public AssuanCommandMixin { Q_OBJECT public: VerifyChecksumsCommand(); ~VerifyChecksumsCommand() override; static const char *staticName() { return "CHECKSUM_VERIFY_FILES"; } private: int doStart() override; void doCanceled() override; #ifdef Q_MOC_RUN private Q_SLOTS: void done(); void done(int, QString); #endif private: class Private; kdtools::pimpl_ptr d; - //Q_PRIVATE_SLOT( this, void done() ) - //Q_PRIVATE_SLOT( this, void done(int,QString) ) }; } #endif // QT_NO_DIRMODEL