diff --git a/NEWS b/NEWS index 1094b77a..b5fb0a73 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,8 @@ Noteworthy changes in version 1.18.1 (unreleased) * qt: Extend ListAllKeysJob to allow disabling the automatic trust database check when listing all keys. [T6261] + * qt: Allow deferred start of import jobs. [T6323] + * Interface changes relative to the 1.18.0 release: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gpgme_get_ctx_flag EXTENDED: New flag 'no-auto-check-trustdb'. @@ -29,6 +31,7 @@ Noteworthy changes in version 1.18.1 (unreleased) qt: ListAllKeysJob::setOptions NEW. qt: ListAllKeysJob::options NEW. qt: Job::startNow NEW. + qt: ImportJob::startLater NEW. Noteworthy changes in version 1.18.0 (2022-08-10) diff --git a/lang/qt/src/importjob.h b/lang/qt/src/importjob.h index a81dcf26..0d677bed 100644 --- a/lang/qt/src/importjob.h +++ b/lang/qt/src/importjob.h @@ -5,6 +5,8 @@ Copyright (c) 2004 Klarälvdalens Datakonsult AB Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik Software engineering by Intevation GmbH + Copyright (c) 2023 g10 Code GmbH + Software engineering by Ingo Klöcker QGpgME is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -88,6 +90,8 @@ public: virtual GpgME::Error start(const QByteArray &keyData) = 0; virtual GpgME::ImportResult exec(const QByteArray &keyData) = 0; + + virtual GpgME::Error startLater(const QByteArray &keyData) = 0; }; } diff --git a/lang/qt/src/qgpgmeimportjob.cpp b/lang/qt/src/qgpgmeimportjob.cpp index 2da54582..9f09ca7c 100644 --- a/lang/qt/src/qgpgmeimportjob.cpp +++ b/lang/qt/src/qgpgmeimportjob.cpp @@ -154,6 +154,12 @@ GpgME::ImportResult QGpgME::QGpgMEImportJob::exec(const QByteArray &keyData) return mResult; } +Error QGpgMEImportJob::startLater(const QByteArray &certData) +{ + setWorkerFunction(std::bind(&import_qba, std::placeholders::_1, certData, importFilter(), keyOrigin(), keyOriginUrl())); + return {}; +} + // PENDING(marc) implement showErrorDialog() void QGpgME::QGpgMEImportJob::resultHook(const result_type &tuple) diff --git a/lang/qt/src/qgpgmeimportjob.h b/lang/qt/src/qgpgmeimportjob.h index 860db226..ec4d39b4 100644 --- a/lang/qt/src/qgpgmeimportjob.h +++ b/lang/qt/src/qgpgmeimportjob.h @@ -5,6 +5,8 @@ Copyright (c) 2004,2008 Klarälvdalens Datakonsult AB Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik Software engineering by Intevation GmbH + Copyright (c) 2023 g10 Code GmbH + Software engineering by Ingo Klöcker QGpgME is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -70,6 +72,8 @@ public: /* from ImportJob */ GpgME::ImportResult exec(const QByteArray &keyData) Q_DECL_OVERRIDE; + GpgME::Error startLater(const QByteArray &keyData) override; + /* from ThreadedJobMixin */ void resultHook(const result_type &r) Q_DECL_OVERRIDE; diff --git a/lang/qt/tests/t-import.cpp b/lang/qt/tests/t-import.cpp index 33e242f0..ad226ba5 100644 --- a/lang/qt/tests/t-import.cpp +++ b/lang/qt/tests/t-import.cpp @@ -162,6 +162,43 @@ private Q_SLOTS: QVERIFY(key.origin() == Key::OriginWKD); // the origin URL is currently not available in GpgME } + + void testDeferredStart() + { + // pub ed25519 2023-01-05 [SC] + // 4D1367FE9AF6334D8A55BA635A817A94C7B37E5D + // uid importDeferred@example.net + static const char keyFpr[] = "4D1367FE9AF6334D8A55BA635A817A94C7B37E5D"; + static const char keyData[] = + "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + "\n" + "mDMEY7bNSxYJKwYBBAHaRw8BAQdAazIWyd/xEMeObDSUnh2+AXQuo0oM+TDBG49z\n" + "KHvTAYG0GmltcG9ydERlZmVycmVkQGV4YW1wbGUubmV0iJMEExYKADsWIQRNE2f+\n" + "mvYzTYpVumNagXqUx7N+XQUCY7bNSwIbAwULCQgHAgIiAgYVCgkICwIEFgIDAQIe\n" + "BwIXgAAKCRBagXqUx7N+XasrAP4qPzLzPd6tWDZvP29ZYPTSrjrTb0U5MOJeIPKX\n" + "73jZswEAwWRvgH+GmhTOigw0UVtinAFvUEFVyvcW/GR19mw5XA0=\n" + "=JnpA\n" + "-----END PGP PUBLIC KEY BLOCK-----\n"; + + auto *job = openpgp()->importJob(); + job->startLater(QByteArray{keyData}); + connect(job, &ImportJob::result, this, + [this](ImportResult result, QString, Error) + { + QVERIFY(!result.error()); + QVERIFY(!result.imports().empty()); + QVERIFY(result.numImported()); + Q_EMIT asyncDone(); + }); + job->startNow(); + QSignalSpy spy (this, SIGNAL(asyncDone())); + QVERIFY(spy.wait()); + + auto ctx = Context::createForProtocol(GpgME::OpenPGP); + GpgME::Error err; + const auto key = ctx->key(keyFpr, err, false); + QVERIFY(!key.isNull()); + } }; QTEST_MAIN(ImportTest)