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> 61 QString audit_log_as_html(GpgME::Context *ctx, GpgME::Error &err);
65 const QList<QByteArray> m_list;
66 mutable const char **m_patterns;
74 const char **patterns()
const;
79 QObject *
const m_object;
80 QThread *
const m_thread;
82 ToThreadMover(QObject *o, QThread *t) : m_object(o), m_thread(t) {}
83 ToThreadMover(QObject &o, QThread *t) : m_object(&o), m_thread(t) {}
84 ToThreadMover(
const std::shared_ptr<QObject> &o, QThread *t) : m_object(o.get()), m_thread(t) {}
87 if (m_object && m_thread) {
88 m_object->moveToThread(m_thread);
93 template <
typename T_result>
97 explicit Thread(QObject *parent = Q_NULLPTR) : QThread(parent) {}
99 void setFunction(
const std::function<T_result()> &
function)
101 const QMutexLocker locker(&m_mutex);
102 m_function =
function;
105 T_result result()
const 107 const QMutexLocker locker(&m_mutex);
112 void run() Q_DECL_OVERRIDE {
113 const QMutexLocker locker(&m_mutex);
114 m_result = m_function();
117 mutable QMutex m_mutex;
118 std::function<T_result()> m_function;
122 template <
typename T_base,
typename T_result = std::tuple<GpgME::Error, QString, GpgME::Error> >
127 typedef T_result result_type;
130 static_assert(std::tuple_size<T_result>::value > 2,
131 "Result tuple too small");
132 static_assert(std::is_same <
133 typename std::tuple_element <
134 std::tuple_size<T_result>::value - 2,
139 "Second to last result type not a QString");
140 static_assert(std::is_same <
141 typename std::tuple_element <
142 std::tuple_size<T_result>::value - 1,
147 "Last result type not a GpgME::Error");
150 : T_base(0), m_ctx(ctx), m_thread(), m_auditLog(), m_auditLogError()
154 void lateInitialization()
157 QObject::connect(&m_thread, &QThread::finished,
this,
158 &mixin_type::slotFinished);
159 m_ctx->setProgressProvider(
this);
160 QGpgME::g_context_map.insert(
this, m_ctx.get());
165 QGpgME::g_context_map.remove(
this);
168 template <
typename T_binder>
169 void run(
const T_binder &func)
171 m_thread.setFunction(std::bind(func, this->context()));
174 template <
typename T_binder>
175 void run(
const T_binder &func,
const std::shared_ptr<QIODevice> &io)
178 io->moveToThread(&m_thread);
184 m_thread.setFunction(std::bind(func, this->context(), this->thread(), std::weak_ptr<QIODevice>(io)));
187 template <
typename T_binder>
188 void run(
const T_binder &func,
const std::shared_ptr<QIODevice> &io1,
const std::shared_ptr<QIODevice> &io2)
191 io1->moveToThread(&m_thread);
194 io2->moveToThread(&m_thread);
200 m_thread.setFunction(std::bind(func, this->context(), this->thread(), std::weak_ptr<QIODevice>(io1), std::weak_ptr<QIODevice>(io2)));
203 GpgME::Context *context()
const 208 virtual void resultHook(
const result_type &) {}
212 const T_result r = m_thread.result();
213 m_auditLog = std::get < std::tuple_size<T_result>::value - 2 > (r);
214 m_auditLogError = std::get < std::tuple_size<T_result>::value - 1 > (r);
220 void slotCancel() Q_DECL_OVERRIDE {
223 m_ctx->cancelPendingOperation();
226 QString auditLogAsHtml()
const Q_DECL_OVERRIDE
230 GpgME::Error auditLogError()
const Q_DECL_OVERRIDE
232 return m_auditLogError;
234 void showProgress(
const char * ,
235 int ,
int current,
int total) Q_DECL_OVERRIDE {
240 QMetaObject::invokeMethod(
this,
"progress", Qt::QueuedConnection,
242 Q_ARG(QString, QString()),
247 template <
typename T1,
typename T2>
248 void doEmitResult(
const std::tuple<T1, T2> &tuple)
250 Q_EMIT this->result(std::get<0>(tuple), std::get<1>(tuple));
253 template <
typename T1,
typename T2,
typename T3>
254 void doEmitResult(
const std::tuple<T1, T2, T3> &tuple)
256 Q_EMIT this->result(std::get<0>(tuple), std::get<1>(tuple), std::get<2>(tuple));
259 template <
typename T1,
typename T2,
typename T3,
typename T4>
260 void doEmitResult(
const std::tuple<T1, T2, T3, T4> &tuple)
262 Q_EMIT this->result(std::get<0>(tuple), std::get<1>(tuple), std::get<2>(tuple), std::get<3>(tuple));
265 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5>
266 void doEmitResult(
const std::tuple<T1, T2, T3, T4, T5> &tuple)
268 Q_EMIT this->result(std::get<0>(tuple), std::get<1>(tuple), std::get<2>(tuple), std::get<3>(tuple), std::get<4>(tuple));
272 std::shared_ptr<GpgME::Context> m_ctx;
275 GpgME::Error m_auditLogError;
Definition: threadedjobmixin.h:63
Definition: threadedjobmixin.h:77
Definition: threadedjobmixin.h:94
Definition: threadedjobmixin.h:123
Definition: abstractimportjob.h:47