[Pkg-gnupg-commit] [gpgme] 40/62: qt: Add API to get the context for a Job
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Sat Nov 19 04:03:35 UTC 2016
This is an automated email from the git hooks/post-receive script.
dkg pushed a commit to branch experimental
in repository gpgme.
commit 9451faa2ee333904cff59f92ab62918e13ab4b87
Author: Andre Heinecke <aheinecke at intevation.de>
Date: Mon Nov 14 20:40:29 2016 +0100
qt: Add API to get the context for a Job
* lang/qt/src/job.cpp,
lang/qt/src/job.h (Job::context): New.
* lang/qt/src/threadedjobmixin.cpp
(ThreadedJobMixin::~ThreadedJobMixin): New. Unregister context.
(ThreadedJobMixin::lateInitialization): Register context.
* NEWS: Update for cpp and qt.
--
The global map hack is necessary because the job class does
not know about the context which is held in threadedjobmixin.
Adding a virtual function in Job would be an ABI break which
I'd like to avoid at this point. Although QGpgME's API will
need a big ABI break to make it ABI maintainable. The virtual
jobs -> implementation classes are nearly unmaintainable ABI wise.
The context is exposed to provide more flexibility to users, e.g.
to add a passphrase callback or to set the sender in a context.
---
NEWS | 3 +++
lang/qt/src/job.cpp | 10 +++++++++-
lang/qt/src/job.h | 16 ++++++++++++++++
lang/qt/src/threadedjobmixin.h | 8 +++++++-
lang/qt/tests/t-tofuinfo.cpp | 4 ++++
5 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/NEWS b/NEWS
index 1cf401e..4bb0cfb 100644
--- a/NEWS
+++ b/NEWS
@@ -14,9 +14,12 @@ Noteworthy changes in version 1.7.2 (unreleased)
gpgme_query_swdb_result_t NEW.
qt: DN NEW.
qt: DN::Attribute NEW.
+ qt: Job::context(Job*) NEW.
cpp: EngineInfo::Version::Version(const char*) NEW.
cpp: EngineInfo::Version::Version() NEW.
cpp: SwdbResult NEW.
+ cpp: Context::setSender(const char*) NEW.
+ cpp: Context::getSender() NEW.
Noteworthy changes in version 1.7.1 (2016-10-18)
diff --git a/lang/qt/src/job.cpp b/lang/qt/src/job.cpp
index 38dbc99..9ae3f31 100644
--- a/lang/qt/src/job.cpp
+++ b/lang/qt/src/job.cpp
@@ -62,6 +62,7 @@
#include "keyformailboxjob.h"
#include "wkspublishjob.h"
#include "tofupolicyjob.h"
+#include "threadedjobmixin.h"
#include <QCoreApplication>
#include <QDebug>
@@ -78,7 +79,6 @@ QGpgME::Job::Job(QObject *parent)
QGpgME::Job::~Job()
{
-
}
QString QGpgME::Job::auditLogAsHtml() const
@@ -98,6 +98,14 @@ bool QGpgME::Job::isAuditLogSupported() const
return auditLogError().code() != GPG_ERR_NOT_IMPLEMENTED;
}
+QMap <QGpgME::Job *, GpgME::Context *> QGpgME::g_context_map;
+
+/* static */
+GpgME::Context *QGpgME::Job::context(QGpgME::Job *job)
+{
+ return QGpgME::g_context_map.value (job, nullptr);
+}
+
#define make_job_subclass_ext(x,y) \
QGpgME::x::x( QObject * parent ) : y( parent ) {} \
QGpgME::x::~x() {}
diff --git a/lang/qt/src/job.h b/lang/qt/src/job.h
index 5767729..a0c0285 100644
--- a/lang/qt/src/job.h
+++ b/lang/qt/src/job.h
@@ -38,6 +38,7 @@
#include <QObject>
#include <QString>
+#include <QMap>
#ifdef BUILDING_QGPGME
# include "error.h"
@@ -79,6 +80,20 @@ public:
virtual GpgME::Error auditLogError() const;
bool isAuditLogSupported() const;
+ /** Get the underlying context to set some additional options for a job.
+ *
+ * This is intended to provide more flexibility on configuring jobs before
+ * they are started.
+ * The context is still owned by the thread, do not delete it.
+ *
+ * This is a static method that takes the job as argument.
+ *
+ * This function may not be called for running jobs.
+ *
+ * @returns the context used by the job job or null.
+ */
+ static GpgME::Context *context(Job *job);
+
public Q_SLOTS:
virtual void slotCancel() = 0;
@@ -87,6 +102,7 @@ Q_SIGNALS:
void done();
};
+extern QMap <Job *, GpgME::Context *> g_context_map;
}
#endif // __KLEO_JOB_H__
diff --git a/lang/qt/src/threadedjobmixin.h b/lang/qt/src/threadedjobmixin.h
index d1b1043..aef2723 100644
--- a/lang/qt/src/threadedjobmixin.h
+++ b/lang/qt/src/threadedjobmixin.h
@@ -48,6 +48,7 @@
# include <gpgme++/interfaces/progressprovider.h>
#endif
+#include "job.h"
#include <cassert>
@@ -147,7 +148,6 @@ protected:
explicit ThreadedJobMixin(GpgME::Context *ctx)
: T_base(0), m_ctx(ctx), m_thread(), m_auditLog(), m_auditLogError()
{
-
}
void lateInitialization()
@@ -155,6 +155,12 @@ protected:
assert(m_ctx);
QObject::connect(&m_thread, SIGNAL(finished()), this, SLOT(slotFinished()));
m_ctx->setProgressProvider(this);
+ QGpgME::g_context_map.insert(this, m_ctx.get());
+ }
+
+ ~ThreadedJobMixin()
+ {
+ QGpgME::g_context_map.remove(this);
}
template <typename T_binder>
diff --git a/lang/qt/tests/t-tofuinfo.cpp b/lang/qt/tests/t-tofuinfo.cpp
index 2c87e4a..f89e1c2 100644
--- a/lang/qt/tests/t-tofuinfo.cpp
+++ b/lang/qt/tests/t-tofuinfo.cpp
@@ -152,6 +152,10 @@ private Q_SLOTS:
const QByteArray data1(testMsg1);
QByteArray plaintext;
+ auto ctx = Job::context(job);
+ Q_ASSERT(ctx);
+ ctx->setSender("alfa at example.net");
+
auto result = job->exec(data1, plaintext);
delete job;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git
More information about the Pkg-gnupg-commit
mailing list