aboutsummaryrefslogtreecommitdiffstats
path: root/lang/qt/tests/run-refreshkeysjob.cpp
diff options
context:
space:
mode:
authorIngo Klöcker <[email protected]>2022-05-04 12:51:50 +0000
committerIngo Klöcker <[email protected]>2022-05-04 12:51:50 +0000
commitc64a8daf507a2216611861a12f312466b0bae8b2 (patch)
tree11e1a969269fef29992c40e6f73af60bd00de41a /lang/qt/tests/run-refreshkeysjob.cpp
parentcpp: Allow retrieving import result of key listing with locate mode (diff)
downloadgpgme-c64a8daf507a2216611861a12f312466b0bae8b2.tar.gz
gpgme-c64a8daf507a2216611861a12f312466b0bae8b2.zip
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
Diffstat (limited to 'lang/qt/tests/run-refreshkeysjob.cpp')
-rw-r--r--lang/qt/tests/run-refreshkeysjob.cpp47
1 files changed, 32 insertions, 15 deletions
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 <protocol.h>
#include <refreshkeysjob.h>
+#include <refreshopenpgpkeysjob.h>
#include <QCoreApplication>
#include <QDebug>
#include <context.h>
+#include <importresult.h>
#include <iostream>
@@ -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();