qt: Allow deferred start of import job

* lang/qt/src/importjob.h (ImportJob::startLater): New pure virtual
method.
* lang/qt/src/qgpgmeimportjob.cpp, lang/qt/src/qgpgmeimportjob.h
(QGpgMEImportJob::startLater): New method.

* lang/qt/tests/t-import.cpp (ImportTest::testDeferredStart): New.
--

This makes it possible to prepare an import job for a deferred start.

GnuPG-bug-id: 6323
This commit is contained in:
Ingo Klöcker 2023-01-04 11:36:09 +01:00
parent 18c2c0b250
commit 398375a0ab
No known key found for this signature in database
GPG Key ID: F5A5D1692277A1E9
5 changed files with 54 additions and 0 deletions

3
NEWS
View File

@ -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)

View File

@ -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 <dev@ingo-kloecker.de>
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;
};
}

View File

@ -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)

View File

@ -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 <dev@ingo-kloecker.de>
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;

View File

@ -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)