From 8b9fabf5d55419a68c2b0fc7fd1a90517c881d78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Mon, 19 Jun 2023 14:40:47 +0200 Subject: [PATCH] qt: Add a generic hook to start a job * lang/qt/src/job.cpp, lang/qt/src/job.h (Job::startIt): New method. * lang/qt/src/job_p.h (JobPrivate::startIt): New pure virtual method. * lang/qt/src/qgpgmechangeexpiryjob.cpp (QGpgMEChangeExpiryJobPrivate::startIt): New. * lang/qt/src/qgpgmedecryptverifyarchivejob.cpp (QGpgMEDecryptVerifyArchiveJobPrivate::startIt): New. * lang/qt/src/qgpgmeencryptarchivejob.cpp (QGpgMEEncryptArchiveJobPrivate::startIt): New. * lang/qt/src/qgpgmeencryptjob.cpp (QGpgMEEncryptJobPrivate::startIt): New. * lang/qt/src/qgpgmeimportjob.cpp (QGpgMEImportJobPrivate::startIt): New. * lang/qt/src/qgpgmelistallkeysjob.cpp (QGpgMEListAllKeysJobPrivate::startIt): New. * lang/qt/src/qgpgmesignarchivejob.cpp (QGpgMESignArchiveJobPrivate::startIt): New. * lang/qt/src/qgpgmesignencryptarchivejob.cpp (QGpgMESignEncryptArchiveJobPrivate::startIt): New. * lang/qt/src/qgpgmesignencryptjob.cpp (QGpgMESignEncryptJobPrivate::startIt): New. -- startIt() starts a job if the necessary values have been set before. This makes it possible to extend jobs with additional ways to start them without having to worry about overloading existing virtual start() methods. This will be used first for the different archive jobs. GnuPG-bug-id: 6530 --- NEWS | 1 + lang/qt/src/job.cpp | 7 +++++++ lang/qt/src/job.h | 6 ++++++ lang/qt/src/job_p.h | 2 ++ lang/qt/src/qgpgmechangeexpiryjob.cpp | 6 ++++++ lang/qt/src/qgpgmedecryptverifyarchivejob.cpp | 6 ++++++ lang/qt/src/qgpgmeencryptarchivejob.cpp | 6 ++++++ lang/qt/src/qgpgmeencryptjob.cpp | 6 ++++++ lang/qt/src/qgpgmeimportjob.cpp | 6 ++++++ lang/qt/src/qgpgmelistallkeysjob.cpp | 6 ++++++ lang/qt/src/qgpgmesignarchivejob.cpp | 6 ++++++ lang/qt/src/qgpgmesignencryptarchivejob.cpp | 6 ++++++ lang/qt/src/qgpgmesignencryptjob.cpp | 6 ++++++ 13 files changed, 70 insertions(+) diff --git a/NEWS b/NEWS index 7c92e62f..f61b354b 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,7 @@ Noteworthy changes in version 1.21.0 (unreleased) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cpp: Data::setFlag NEW. cpp: Data::setSizeHint NEW. + qt: Job::startIt NEW. Noteworthy changes in version 1.20.0 (2023-04-20) ------------------------------------------------- diff --git a/lang/qt/src/job.cpp b/lang/qt/src/job.cpp index 9e01a0ea..3e19e64a 100644 --- a/lang/qt/src/job.cpp +++ b/lang/qt/src/job.cpp @@ -142,6 +142,13 @@ GpgME::Context *QGpgME::Job::context(QGpgME::Job *job) return QGpgME::g_context_map.value (job, nullptr); } +GpgME::Error QGpgME::Job::startIt() +{ + auto d = getJobPrivate(this); + Q_ASSERT(d && "This Job class has no JobPrivate class"); + return d->startIt(); +} + void QGpgME::Job::startNow() { auto d = getJobPrivate(this); diff --git a/lang/qt/src/job.h b/lang/qt/src/job.h index 46c5e717..297dfe06 100644 --- a/lang/qt/src/job.h +++ b/lang/qt/src/job.h @@ -95,6 +95,12 @@ public: */ static GpgME::Context *context(Job *job); + /** Starts the job. + * + * Starts the job with the values set for the concrete job. + */ + GpgME::Error startIt(); + /** Starts a deferred job. * * The job needs to have been prepared for a deferred start by calling the diff --git a/lang/qt/src/job_p.h b/lang/qt/src/job_p.h index e4397465..597b1a17 100644 --- a/lang/qt/src/job_p.h +++ b/lang/qt/src/job_p.h @@ -49,6 +49,8 @@ class JobPrivate public: virtual ~JobPrivate() {} + virtual GpgME::Error startIt() = 0; + virtual void startNow() = 0; }; diff --git a/lang/qt/src/qgpgmechangeexpiryjob.cpp b/lang/qt/src/qgpgmechangeexpiryjob.cpp index 83a5b172..3cca6ca8 100644 --- a/lang/qt/src/qgpgmechangeexpiryjob.cpp +++ b/lang/qt/src/qgpgmechangeexpiryjob.cpp @@ -66,6 +66,12 @@ public: ~QGpgMEChangeExpiryJobPrivate() override = default; private: + GpgME::Error startIt() override + { + Q_ASSERT(!"Not supported by this Job class."); + return Error::fromCode(GPG_ERR_NOT_SUPPORTED); + } + void startNow() override { q->run(); diff --git a/lang/qt/src/qgpgmedecryptverifyarchivejob.cpp b/lang/qt/src/qgpgmedecryptverifyarchivejob.cpp index e47ca5e6..3fd58e35 100644 --- a/lang/qt/src/qgpgmedecryptverifyarchivejob.cpp +++ b/lang/qt/src/qgpgmedecryptverifyarchivejob.cpp @@ -64,6 +64,12 @@ public: ~QGpgMEDecryptVerifyArchiveJobPrivate() override = default; private: + GpgME::Error startIt() override + { + Q_ASSERT(!"Not supported by this Job class."); + return Error::fromCode(GPG_ERR_NOT_SUPPORTED); + } + void startNow() override { q->run(); diff --git a/lang/qt/src/qgpgmeencryptarchivejob.cpp b/lang/qt/src/qgpgmeencryptarchivejob.cpp index 2a7855c3..6ae310e7 100644 --- a/lang/qt/src/qgpgmeencryptarchivejob.cpp +++ b/lang/qt/src/qgpgmeencryptarchivejob.cpp @@ -65,6 +65,12 @@ public: ~QGpgMEEncryptArchiveJobPrivate() override = default; private: + GpgME::Error startIt() override + { + Q_ASSERT(!"Not supported by this Job class."); + return Error::fromCode(GPG_ERR_NOT_SUPPORTED); + } + void startNow() override { q->run(); diff --git a/lang/qt/src/qgpgmeencryptjob.cpp b/lang/qt/src/qgpgmeencryptjob.cpp index 8ad9cc2c..5ea6162c 100644 --- a/lang/qt/src/qgpgmeencryptjob.cpp +++ b/lang/qt/src/qgpgmeencryptjob.cpp @@ -72,6 +72,12 @@ public: ~QGpgMEEncryptJobPrivate() override = default; private: + GpgME::Error startIt() override + { + Q_ASSERT(!"Not supported by this Job class."); + return Error::fromCode(GPG_ERR_NOT_SUPPORTED); + } + void startNow() override { q->run(); diff --git a/lang/qt/src/qgpgmeimportjob.cpp b/lang/qt/src/qgpgmeimportjob.cpp index 239cb84c..1d838150 100644 --- a/lang/qt/src/qgpgmeimportjob.cpp +++ b/lang/qt/src/qgpgmeimportjob.cpp @@ -67,6 +67,12 @@ public: ~QGpgMEImportJobPrivate() override = default; private: + GpgME::Error startIt() override + { + Q_ASSERT(!"Not supported by this Job class."); + return Error::fromCode(GPG_ERR_NOT_SUPPORTED); + } + void startNow() override { q->run(); diff --git a/lang/qt/src/qgpgmelistallkeysjob.cpp b/lang/qt/src/qgpgmelistallkeysjob.cpp index bc6ea0d7..48f8dc3d 100644 --- a/lang/qt/src/qgpgmelistallkeysjob.cpp +++ b/lang/qt/src/qgpgmelistallkeysjob.cpp @@ -77,6 +77,12 @@ public: ~QGpgMEListAllKeysJobPrivate() override = default; private: + GpgME::Error startIt() override + { + Q_ASSERT(!"Not supported by this Job class."); + return Error::fromCode(GPG_ERR_NOT_SUPPORTED); + } + void startNow() override { q->run(); diff --git a/lang/qt/src/qgpgmesignarchivejob.cpp b/lang/qt/src/qgpgmesignarchivejob.cpp index 59614916..c25ea89f 100644 --- a/lang/qt/src/qgpgmesignarchivejob.cpp +++ b/lang/qt/src/qgpgmesignarchivejob.cpp @@ -65,6 +65,12 @@ public: ~QGpgMESignArchiveJobPrivate() override = default; private: + GpgME::Error startIt() override + { + Q_ASSERT(!"Not supported by this Job class."); + return Error::fromCode(GPG_ERR_NOT_SUPPORTED); + } + void startNow() override { q->run(); diff --git a/lang/qt/src/qgpgmesignencryptarchivejob.cpp b/lang/qt/src/qgpgmesignencryptarchivejob.cpp index e7f5f30f..2c029a25 100644 --- a/lang/qt/src/qgpgmesignencryptarchivejob.cpp +++ b/lang/qt/src/qgpgmesignencryptarchivejob.cpp @@ -72,6 +72,12 @@ public: ~QGpgMESignEncryptArchiveJobPrivate() override = default; private: + GpgME::Error startIt() override + { + Q_ASSERT(!"Not supported by this Job class."); + return Error::fromCode(GPG_ERR_NOT_SUPPORTED); + } + void startNow() override { q->run(); diff --git a/lang/qt/src/qgpgmesignencryptjob.cpp b/lang/qt/src/qgpgmesignencryptjob.cpp index 6a62ee86..c2ced590 100644 --- a/lang/qt/src/qgpgmesignencryptjob.cpp +++ b/lang/qt/src/qgpgmesignencryptjob.cpp @@ -73,6 +73,12 @@ public: ~QGpgMESignEncryptJobPrivate() override = default; private: + GpgME::Error startIt() override + { + Q_ASSERT(!"Not supported by this Job class."); + return Error::fromCode(GPG_ERR_NOT_SUPPORTED); + } + void startNow() override { q->run();