34 #ifndef __QGPGME_THREADEDJOBMIXING_H__ 35 #define __QGPGME_THREADEDJOBMIXING_H__ 38 #include <QMutexLocker> 43 #ifdef BUILDING_QGPGME 45 # include "interfaces/progressprovider.h" 47 # include <gpgme++/context.h> 48 # include <gpgme++/interfaces/progressprovider.h> 60 QString audit_log_as_html(GpgME::Context *ctx, GpgME::Error &err);
64 const QList<QByteArray> m_list;
65 mutable const char **m_patterns;
73 const char **patterns()
const;
78 QObject *
const m_object;
79 QThread *
const m_thread;
81 ToThreadMover(QObject *o, QThread *t) : m_object(o), m_thread(t) {}
82 ToThreadMover(QObject &o, QThread *t) : m_object(&o), m_thread(t) {}
83 ToThreadMover(
const std::shared_ptr<QObject> &o, QThread *t) : m_object(o.get()), m_thread(t) {}
86 if (m_object && m_thread) {
87 m_object->moveToThread(m_thread);
92 template <
typename T_result>
96 explicit Thread(QObject *parent = Q_NULLPTR) : QThread(parent) {}
98 void setFunction(
const std::function<T_result()> &
function)
100 const QMutexLocker locker(&m_mutex);
101 m_function =
function;
104 T_result result()
const 106 const QMutexLocker locker(&m_mutex);
111 void run() Q_DECL_OVERRIDE {
112 const QMutexLocker locker(&m_mutex);
113 m_result = m_function();
116 mutable QMutex m_mutex;
117 std::function<T_result()> m_function;
121 template <
typename T_base,
typename T_result = std::tuple<GpgME::Error, QString, GpgME::Error> >
126 typedef T_result result_type;
129 static_assert(std::tuple_size<T_result>::value > 2,
130 "Result tuple too small");
131 static_assert(std::is_same <
132 typename std::tuple_element <
133 std::tuple_size<T_result>::value - 2,
138 "Second to last result type not a QString");
139 static_assert(std::is_same <
140 typename std::tuple_element <
141 std::tuple_size<T_result>::value - 1,
146 "Last result type not a GpgME::Error");
149 : T_base(0), m_ctx(ctx), m_thread(), m_auditLog(), m_auditLogError()
153 void lateInitialization()
156 QObject::connect(&m_thread, &QThread::finished,
this,
157 &mixin_type::slotFinished);
158 m_ctx->setProgressProvider(
this);
159 QGpgME::g_context_map.insert(
this, m_ctx.get());
164 QGpgME::g_context_map.remove(
this);
167 template <
typename T_binder>
168 void run(
const T_binder &func)
170 m_thread.setFunction(std::bind(func, this->context()));
173 template <
typename T_binder>
174 void run(
const T_binder &func,
const std::shared_ptr<QIODevice> &io)
177 io->moveToThread(&m_thread);
183 m_thread.setFunction(std::bind(func, this->context(), this->thread(), std::weak_ptr<QIODevice>(io)));
186 template <
typename T_binder>
187 void run(
const T_binder &func,
const std::shared_ptr<QIODevice> &io1,
const std::shared_ptr<QIODevice> &io2)
190 io1->moveToThread(&m_thread);
193 io2->moveToThread(&m_thread);
199 m_thread.setFunction(std::bind(func, this->context(), this->thread(), std::weak_ptr<QIODevice>(io1), std::weak_ptr<QIODevice>(io2)));
202 GpgME::Context *context()
const 207 virtual void resultHook(
const result_type &) {}
211 const T_result r = m_thread.result();
212 m_auditLog = std::get < std::tuple_size<T_result>::value - 2 > (r);
213 m_auditLogError = std::get < std::tuple_size<T_result>::value - 1 > (r);
219 void slotCancel() Q_DECL_OVERRIDE {
222 m_ctx->cancelPendingOperation();
225 QString auditLogAsHtml()
const Q_DECL_OVERRIDE
229 GpgME::Error auditLogError()
const Q_DECL_OVERRIDE
231 return m_auditLogError;
233 void showProgress(
const char * ,
234 int ,
int current,
int total) Q_DECL_OVERRIDE {
239 QMetaObject::invokeMethod(
this,
"progress", Qt::QueuedConnection,
241 Q_ARG(QString, QString()),
246 template <
typename T1,
typename T2>
247 void doEmitResult(
const std::tuple<T1, T2> &tuple)
249 Q_EMIT this->result(std::get<0>(tuple), std::get<1>(tuple));
252 template <
typename T1,
typename T2,
typename T3>
253 void doEmitResult(
const std::tuple<T1, T2, T3> &tuple)
255 Q_EMIT this->result(std::get<0>(tuple), std::get<1>(tuple), std::get<2>(tuple));
258 template <
typename T1,
typename T2,
typename T3,
typename T4>
259 void doEmitResult(
const std::tuple<T1, T2, T3, T4> &tuple)
261 Q_EMIT this->result(std::get<0>(tuple), std::get<1>(tuple), std::get<2>(tuple), std::get<3>(tuple));
264 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5>
265 void doEmitResult(
const std::tuple<T1, T2, T3, T4, T5> &tuple)
267 Q_EMIT this->result(std::get<0>(tuple), std::get<1>(tuple), std::get<2>(tuple), std::get<3>(tuple), std::get<4>(tuple));
271 std::shared_ptr<GpgME::Context> m_ctx;
274 GpgME::Error m_auditLogError;
Definition: threadedjobmixin.h:62
Definition: threadedjobmixin.h:76
Definition: threadedjobmixin.h:93
Definition: threadedjobmixin.h:122
Definition: abstractimportjob.h:47