From c64a8daf507a2216611861a12f312466b0bae8b2 Mon Sep 17 00:00:00 2001 From: Ingo Klöcker Date: Wed, 4 May 2022 14:51:50 +0200 Subject: qt: Emit import result when refreshing OpenPGP keys * lang/qt/src/refreshopenpgpkeysjob.h: New. * lang/qt/src/Makefile.am, lang/qt/src/job.cpp: Update accordingly. * lang/qt/src/qgpgmerefreshopenpgpkeysjob.h (class QGpgMERefreshOpenPGPKeysJob): Derive from RefreshOpenPGPKeysJob with result ImportResult. Remove unused start overload. * lang/qt/src/qgpgmerefreshopenpgpkeysjob.cpp (locate_external_keys): Ignore result of KeyListJob. Return import result. (receive_keys): Return import result. (refresh_keys): Merge the two import results and return the result. * lang/qt/src/protocol.h (class Protocol): Add pure virtual member function refreshOpenPGPKeysJob. * lang/qt/src/protocol_p.h (Protocol::refreshKeysJob): Return nullptr for OpenPGP protocol. (Protocol::refreshOpenPGPKeysJob): New. * lang/qt/tests/run-refreshkeysjob.cpp (main): Use appropriate job for the protocol of the key to refresh. -- This adds RefreshOpenPGPKeysJob complementing RefreshKeysJob (for S/MIME keys). Changing the result type of RefreshKeysJob would break the ABI. Therefore we have to introduce a new base class for the refresh job for OpenPGP. We derive this base class from AbstractImportJob because we want to return an import result. GnuPG-bug-id: 5951 --- lang/qt/tests/run-refreshkeysjob.cpp | 47 ++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 15 deletions(-) (limited to 'lang/qt/tests') diff --git a/lang/qt/tests/run-refreshkeysjob.cpp b/lang/qt/tests/run-refreshkeysjob.cpp index a9cf5e61..4c8f4086 100644 --- a/lang/qt/tests/run-refreshkeysjob.cpp +++ b/lang/qt/tests/run-refreshkeysjob.cpp @@ -36,11 +36,13 @@ #include #include +#include #include #include #include +#include #include @@ -117,21 +119,36 @@ int main(int argc, char **argv) auto key = openPGPKey.key.isNull() ? smimeKey.key : openPGPKey.key; std::cout << "Refreshing " << displayName(key.protocol()) << " key " << key.userID(0).id() << std::endl; - auto jobFactory = key.protocol() == GpgME::OpenPGP ? QGpgME::openpgp() : QGpgME::smime(); - auto job = jobFactory->refreshKeysJob(); - if (!job) { - std::cerr << "Error: Could not create job to refresh " << displayName(key.protocol()) << " key" << std::endl; - return 1; - } - QObject::connect(job, &QGpgME::RefreshKeysJob::result, &app, [](const GpgME::Error &err, const QString &, const GpgME::Error &) { - std::cout << "Result: " << err.asString() << std::endl; - qApp->quit(); - }); - - const auto err = job->start({key}); - if (err) { - std::cerr << "Error: " << err.asString() << std::endl; - return 1; + if (key.protocol() == GpgME::OpenPGP) { + auto job = QGpgME::openpgp()->refreshOpenPGPKeysJob(); + if (!job) { + std::cerr << "Error: Could not create job to refresh OpenPGP key" << std::endl; + return 1; + } + QObject::connect(job, &QGpgME::RefreshOpenPGPKeysJob::result, &app, [](const GpgME::ImportResult &result, const QString &, const GpgME::Error &) { + std::cout << "Result: " << result << std::endl; + qApp->quit(); + }); + const auto err = job->start({key}); + if (err) { + std::cerr << "Error: " << err.asString() << std::endl; + return 1; + } + } else { + auto job = QGpgME::smime()->refreshKeysJob(); + if (!job) { + std::cerr << "Error: Could not create job to refresh S/MIME key" << std::endl; + return 1; + } + QObject::connect(job, &QGpgME::RefreshKeysJob::result, &app, [](const GpgME::Error &err, const QString &, const GpgME::Error &) { + std::cout << "Result: " << err.asString() << std::endl; + qApp->quit(); + }); + const auto err = job->start({key}); + if (err) { + std::cerr << "Error: " << err.asString() << std::endl; + return 1; + } } return app.exec(); -- cgit