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/src/qgpgmerefreshopenpgpkeysjob.cpp | 32 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'lang/qt/src/qgpgmerefreshopenpgpkeysjob.cpp') diff --git a/lang/qt/src/qgpgmerefreshopenpgpkeysjob.cpp b/lang/qt/src/qgpgmerefreshopenpgpkeysjob.cpp index 425b9bf7..36ea9a1b 100644 --- a/lang/qt/src/qgpgmerefreshopenpgpkeysjob.cpp +++ b/lang/qt/src/qgpgmerefreshopenpgpkeysjob.cpp @@ -80,7 +80,7 @@ QGpgMERefreshOpenPGPKeysJob::QGpgMERefreshOpenPGPKeysJob(Context *context) QGpgMERefreshOpenPGPKeysJob::~QGpgMERefreshOpenPGPKeysJob() = default; -static Error locate_external_keys(Context *ctx, const std::vector &keys) +static ImportResult locate_external_keys(Context *ctx, const std::vector &keys) { Context::KeyListModeSaver saver{ctx}; ctx->setKeyListMode(GpgME::LocateExternal); @@ -88,13 +88,14 @@ static Error locate_external_keys(Context *ctx, const std::vector &keys) const auto emails = toEmailAddresses(keys); std::vector dummy; auto job = std::unique_ptr{new QGpgMEKeyListJob{ctx}}; - const auto result = job->exec(emails, false, dummy); + (void) job->exec(emails, false, dummy); + const auto result = ctx->importResult(); job.release(); - return result.error(); + return result; } -static Error receive_keys(Context *ctx, const std::vector &keys) +static ImportResult receive_keys(Context *ctx, const std::vector &keys) { const auto fprs = toFingerprints(keys); @@ -102,25 +103,22 @@ static Error receive_keys(Context *ctx, const std::vector &keys) const auto result = job->exec(fprs); job.release(); - return result.error(); + return result; } static QGpgMERefreshOpenPGPKeysJob::result_type refresh_keys(Context *ctx, const std::vector &keys) { - Error err; - - err = locate_external_keys(ctx, keys); - if (!err) { - err = receive_keys(ctx, keys); + ImportResult result; + + result = locate_external_keys(ctx, keys); + if (!result.error()) { + const auto res2 = receive_keys(ctx, keys); + if (!res2.error()) { + result.mergeWith(res2); + } } - return std::make_tuple(err, /*err ? WKDLookupResult{pattern, err} : result,*/ QString{}, Error{}); -} - -GpgME::Error QGpgMERefreshOpenPGPKeysJob::start(const QStringList &patterns) -{ - Q_UNUSED(patterns); - return GpgME::Error::fromCode(GPG_ERR_NOT_IMPLEMENTED); + return std::make_tuple(result, QString{}, Error{}); } GpgME::Error QGpgMERefreshOpenPGPKeysJob::start(const std::vector &keys) -- cgit