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.
This commit is contained in:
parent
d09a84eaf1
commit
9451faa2ee
3
NEWS
3
NEWS
@ -14,9 +14,12 @@ Noteworthy changes in version 1.7.2 (unreleased)
|
|||||||
gpgme_query_swdb_result_t NEW.
|
gpgme_query_swdb_result_t NEW.
|
||||||
qt: DN NEW.
|
qt: DN NEW.
|
||||||
qt: DN::Attribute NEW.
|
qt: DN::Attribute NEW.
|
||||||
|
qt: Job::context(Job*) NEW.
|
||||||
cpp: EngineInfo::Version::Version(const char*) NEW.
|
cpp: EngineInfo::Version::Version(const char*) NEW.
|
||||||
cpp: EngineInfo::Version::Version() NEW.
|
cpp: EngineInfo::Version::Version() NEW.
|
||||||
cpp: SwdbResult NEW.
|
cpp: SwdbResult NEW.
|
||||||
|
cpp: Context::setSender(const char*) NEW.
|
||||||
|
cpp: Context::getSender() NEW.
|
||||||
|
|
||||||
|
|
||||||
Noteworthy changes in version 1.7.1 (2016-10-18)
|
Noteworthy changes in version 1.7.1 (2016-10-18)
|
||||||
|
@ -62,6 +62,7 @@
|
|||||||
#include "keyformailboxjob.h"
|
#include "keyformailboxjob.h"
|
||||||
#include "wkspublishjob.h"
|
#include "wkspublishjob.h"
|
||||||
#include "tofupolicyjob.h"
|
#include "tofupolicyjob.h"
|
||||||
|
#include "threadedjobmixin.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@ -78,7 +79,6 @@ QGpgME::Job::Job(QObject *parent)
|
|||||||
|
|
||||||
QGpgME::Job::~Job()
|
QGpgME::Job::~Job()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QGpgME::Job::auditLogAsHtml() const
|
QString QGpgME::Job::auditLogAsHtml() const
|
||||||
@ -98,6 +98,14 @@ bool QGpgME::Job::isAuditLogSupported() const
|
|||||||
return auditLogError().code() != GPG_ERR_NOT_IMPLEMENTED;
|
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) \
|
#define make_job_subclass_ext(x,y) \
|
||||||
QGpgME::x::x( QObject * parent ) : y( parent ) {} \
|
QGpgME::x::x( QObject * parent ) : y( parent ) {} \
|
||||||
QGpgME::x::~x() {}
|
QGpgME::x::~x() {}
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
#ifdef BUILDING_QGPGME
|
#ifdef BUILDING_QGPGME
|
||||||
# include "error.h"
|
# include "error.h"
|
||||||
@ -79,6 +80,20 @@ public:
|
|||||||
virtual GpgME::Error auditLogError() const;
|
virtual GpgME::Error auditLogError() const;
|
||||||
bool isAuditLogSupported() 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:
|
public Q_SLOTS:
|
||||||
virtual void slotCancel() = 0;
|
virtual void slotCancel() = 0;
|
||||||
|
|
||||||
@ -87,6 +102,7 @@ Q_SIGNALS:
|
|||||||
void done();
|
void done();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern QMap <Job *, GpgME::Context *> g_context_map;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // __KLEO_JOB_H__
|
#endif // __KLEO_JOB_H__
|
||||||
|
@ -48,6 +48,7 @@
|
|||||||
# include <gpgme++/interfaces/progressprovider.h>
|
# include <gpgme++/interfaces/progressprovider.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "job.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
@ -147,7 +148,6 @@ protected:
|
|||||||
explicit ThreadedJobMixin(GpgME::Context *ctx)
|
explicit ThreadedJobMixin(GpgME::Context *ctx)
|
||||||
: T_base(0), m_ctx(ctx), m_thread(), m_auditLog(), m_auditLogError()
|
: T_base(0), m_ctx(ctx), m_thread(), m_auditLog(), m_auditLogError()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void lateInitialization()
|
void lateInitialization()
|
||||||
@ -155,6 +155,12 @@ protected:
|
|||||||
assert(m_ctx);
|
assert(m_ctx);
|
||||||
QObject::connect(&m_thread, SIGNAL(finished()), this, SLOT(slotFinished()));
|
QObject::connect(&m_thread, SIGNAL(finished()), this, SLOT(slotFinished()));
|
||||||
m_ctx->setProgressProvider(this);
|
m_ctx->setProgressProvider(this);
|
||||||
|
QGpgME::g_context_map.insert(this, m_ctx.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
~ThreadedJobMixin()
|
||||||
|
{
|
||||||
|
QGpgME::g_context_map.remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T_binder>
|
template <typename T_binder>
|
||||||
|
@ -152,6 +152,10 @@ private Q_SLOTS:
|
|||||||
const QByteArray data1(testMsg1);
|
const QByteArray data1(testMsg1);
|
||||||
QByteArray plaintext;
|
QByteArray plaintext;
|
||||||
|
|
||||||
|
auto ctx = Job::context(job);
|
||||||
|
Q_ASSERT(ctx);
|
||||||
|
ctx->setSender("alfa@example.net");
|
||||||
|
|
||||||
auto result = job->exec(data1, plaintext);
|
auto result = job->exec(data1, plaintext);
|
||||||
delete job;
|
delete job;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user