-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathExecuter.cc
56 lines (44 loc) · 1.39 KB
/
Executer.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <QMetaMethod>
#include <QMetaObject>
#include "Executer_p.hpp"
#include "Executer.hpp"
static QMetaMethod getMethod(QObject *object, const char *function) {
auto metaObject = object->metaObject();
return metaObject->method(metaObject->indexOfMethod(QMetaObject::normalizedSignature(function)));
}
Executer::Executer(QObject *parent)
: QObject(parent) {
m_Private = new ExecuterPrivate;
m_Thread = new QThread;
m_Thread->start();
m_Private->moveToThread(m_Thread);
connect(m_Private, &ExecuterPrivate::loading,
this, &Executer::loading,
Qt::DirectConnection);
connect(m_Private, &ExecuterPrivate::terminalApp,
this, &Executer::terminalApp,
Qt::DirectConnection);
connect(m_Private, &ExecuterPrivate::finished,
this, &Executer::finished,
Qt::DirectConnection);
}
Executer::~Executer() {
m_Private->disconnect();
m_Private->deleteLater();
m_Thread->quit();
m_Thread->wait();
m_Thread->deleteLater();
}
void Executer::exec(const QString &hash, const QString &path) {
getMethod(m_Private, "exec(const QString&, const QString&)")
.invoke(m_Private,
Qt::QueuedConnection,
Q_ARG(QString, hash),
Q_ARG(QString, path));
}
void Executer::openDirectory(const QString &path) {
getMethod(m_Private, "openDirectory(const QString&)")
.invoke(m_Private,
Qt::QueuedConnection,
Q_ARG(QString, path));
}