qt: Support deferred start of jobs
* lang/qt/src/job.cpp, lang/qt/src/job.h (Job::startNow): New method. * lang/qt/src/job_p.h (JobPrivate::start): New pure virtual method. * lang/qt/src/qgpgmechangeexpiryjob.cpp (QGpgMEChangeExpiryJobPrivate::start): New. * lang/qt/src/qgpgmeencryptjob.cpp (QGpgMEEncryptJobPrivate::start): New. * lang/qt/src/qgpgmeimportjob.cpp (QGpgMEImportJobPrivate::start): New. * lang/qt/src/qgpgmelistallkeysjob.cpp (QGpgMEListAllKeysJobPrivate::start): New. * lang/qt/src/qgpgmesignencryptjob.cpp (QGpgMESignEncryptJobPrivate::start): New. * lang/qt/src/threadedjobmixin.h (Thread::hasFunction): New method. (ThreadedJobMixin::run, ThreadedJobMixin::setWorkerFunction): New methods. -- startNow() starts a deferred job for which the worker function has been set before. GnuPG-bug-id: 6323
This commit is contained in:
parent
270d752300
commit
18c2c0b250
1
NEWS
1
NEWS
@ -28,6 +28,7 @@ Noteworthy changes in version 1.18.1 (unreleased)
|
|||||||
qt: ListAllKeysJob::Options NEW.
|
qt: ListAllKeysJob::Options NEW.
|
||||||
qt: ListAllKeysJob::setOptions NEW.
|
qt: ListAllKeysJob::setOptions NEW.
|
||||||
qt: ListAllKeysJob::options NEW.
|
qt: ListAllKeysJob::options NEW.
|
||||||
|
qt: Job::startNow NEW.
|
||||||
|
|
||||||
|
|
||||||
Noteworthy changes in version 1.18.0 (2022-08-10)
|
Noteworthy changes in version 1.18.0 (2022-08-10)
|
||||||
|
@ -137,6 +137,13 @@ GpgME::Context *QGpgME::Job::context(QGpgME::Job *job)
|
|||||||
return QGpgME::g_context_map.value (job, nullptr);
|
return QGpgME::g_context_map.value (job, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QGpgME::Job::startNow()
|
||||||
|
{
|
||||||
|
auto d = getJobPrivate(this);
|
||||||
|
Q_ASSERT(d && "This Job class has no JobPrivate class");
|
||||||
|
d->start();
|
||||||
|
}
|
||||||
|
|
||||||
#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() {}
|
||||||
|
@ -95,6 +95,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
static GpgME::Context *context(Job *job);
|
static GpgME::Context *context(Job *job);
|
||||||
|
|
||||||
|
/** Starts a deferred job.
|
||||||
|
*
|
||||||
|
* The job needs to have been prepared for a deferred start by calling the
|
||||||
|
* startLater() function instead of the start() function of a leaf class.
|
||||||
|
*/
|
||||||
|
void startNow();
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
virtual void slotCancel() = 0;
|
virtual void slotCancel() = 0;
|
||||||
|
|
||||||
|
@ -46,6 +46,8 @@ class JobPrivate
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~JobPrivate() {}
|
virtual ~JobPrivate() {}
|
||||||
|
|
||||||
|
virtual void start() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Setter and getters for the externally stored pimpl instances of jobs
|
// Setter and getters for the externally stored pimpl instances of jobs
|
||||||
|
@ -64,6 +64,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
~QGpgMEChangeExpiryJobPrivate() override = default;
|
~QGpgMEChangeExpiryJobPrivate() override = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void start() override
|
||||||
|
{
|
||||||
|
q->run();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
~QGpgMEEncryptJobPrivate() override = default;
|
~QGpgMEEncryptJobPrivate() override = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void start() override
|
||||||
|
{
|
||||||
|
q->run();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
~QGpgMEImportJobPrivate() override = default;
|
~QGpgMEImportJobPrivate() override = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void start() override
|
||||||
|
{
|
||||||
|
q->run();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
~QGpgMEListAllKeysJobPrivate() override = default;
|
~QGpgMEListAllKeysJobPrivate() override = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void start() override
|
||||||
|
{
|
||||||
|
q->run();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
~QGpgMESignEncryptJobPrivate() override = default;
|
~QGpgMESignEncryptJobPrivate() override = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void start() override
|
||||||
|
{
|
||||||
|
q->run();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,12 @@ public:
|
|||||||
m_function = function;
|
m_function = function;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hasFunction()
|
||||||
|
{
|
||||||
|
const QMutexLocker locker(&m_mutex);
|
||||||
|
return static_cast<bool>(m_function);
|
||||||
|
}
|
||||||
|
|
||||||
T_result result() const
|
T_result result() const
|
||||||
{
|
{
|
||||||
const QMutexLocker locker(&m_mutex);
|
const QMutexLocker locker(&m_mutex);
|
||||||
@ -127,6 +133,12 @@ public:
|
|||||||
typedef ThreadedJobMixin<T_base, T_result> mixin_type;
|
typedef ThreadedJobMixin<T_base, T_result> mixin_type;
|
||||||
typedef T_result result_type;
|
typedef T_result result_type;
|
||||||
|
|
||||||
|
void run()
|
||||||
|
{
|
||||||
|
Q_ASSERT(m_thread.hasFunction() && "Call setWorkerFunction() before run()");
|
||||||
|
m_thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static_assert(std::tuple_size<T_result>::value > 2,
|
static_assert(std::tuple_size<T_result>::value > 2,
|
||||||
"Result tuple too small");
|
"Result tuple too small");
|
||||||
@ -166,6 +178,12 @@ protected:
|
|||||||
QGpgME::g_context_map.remove(this);
|
QGpgME::g_context_map.remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T_binder>
|
||||||
|
void setWorkerFunction(const T_binder &func)
|
||||||
|
{
|
||||||
|
m_thread.setFunction([this, func]() { return func(this->context()); });
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T_binder>
|
template <typename T_binder>
|
||||||
void run(const T_binder &func)
|
void run(const T_binder &func)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user