-
Notifications
You must be signed in to change notification settings - Fork 6
/
Updater.cc
138 lines (103 loc) · 3.47 KB
/
Updater.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <QMetaMethod>
#include <QMetaObject>
#include "Updater.hpp"
#include "Updater_p.hpp"
static QMetaMethod getMethod(QObject *object, const char *function) {
auto metaObject = object->metaObject();
return metaObject->method(metaObject->indexOfMethod(QMetaObject::normalizedSignature(function)));
}
Updater::Updater(QObject *parent)
: QObject(parent) {
b_NoConfirm = false;
m_Private = new UpdaterPrivate;
m_Thread = new QThread;
m_Thread->start();
m_Private->moveToThread(m_Thread);
connect(m_Private, &UpdaterPrivate::removedFromQueue,
this, &Updater::removedFromQueue);
connect(m_Private, &UpdaterPrivate::queuedCountChanged,
this, &Updater::queuedCountChanged);
connect(m_Private, &UpdaterPrivate::failedCountChanged,
this, &Updater::failedCountChanged);
connect(m_Private, &UpdaterPrivate::completedCountChanged,
this, &Updater::completedCountChanged);
connect(m_Private, &UpdaterPrivate::progressText,
this, &Updater::progressText);
connect(m_Private, &UpdaterPrivate::torrentStatus,
this, &Updater::torrentStatus);
connect(m_Private, &UpdaterPrivate::loading,
this, &Updater::loading);
connect(m_Private, &UpdaterPrivate::metaInfo,
this, &Updater::metaInfo);
connect(m_Private, &UpdaterPrivate::queued,
this, &Updater::queued);
connect(m_Private, &UpdaterPrivate::failed,
this, &Updater::failed);
connect(m_Private, &UpdaterPrivate::started,
this, &Updater::started);
connect(m_Private, &UpdaterPrivate::finished,
this, &Updater::finished);
connect(m_Private, &UpdaterPrivate::canceled,
this, &Updater::canceled);
connect(m_Private, &UpdaterPrivate::retrySent,
this, &Updater::retrySent);
connect(m_Private, &UpdaterPrivate::finishedAll,
this, &Updater::finishedAll);
connect(m_Private, &UpdaterPrivate::noConfirmState,
this, &Updater::handleNoConfirmState);
}
Updater::~Updater() {
m_Private->disconnect();
m_Private->cancelAll();
m_Private->deleteLater();
m_Thread->quit();
m_Thread->wait();
m_Thread->deleteLater();
}
bool Updater::isNoConfirm() const {
return b_NoConfirm;
}
void Updater::handleNoConfirmState(bool value) {
b_NoConfirm = value;
emit isNoConfirmEnabledChanged();
}
void Updater::retry(const QJsonObject &json) {
getMethod(m_Private, "retry(const QJsonObject&)")
.invoke(m_Private,
Qt::QueuedConnection,
Q_ARG(QJsonObject, json));
}
void Updater::removeFromQueue(const QString &hash) {
getMethod(m_Private, "removeFromQueue(const QString&)")
.invoke(m_Private,
Qt::QueuedConnection,
Q_ARG(QString, hash));
}
void Updater::queue(const QString &path, const QString &name, QVariant icon) {
getMethod(m_Private, "queue(const QString&, const QString&, QVariant)")
.invoke(m_Private,
Qt::QueuedConnection,
Q_ARG(QString, path),
Q_ARG(QString, name),
Q_ARG(QVariant,icon));
}
void Updater::toggleNoConfirm() {
getMethod(m_Private, "toggleNoConfirm()")
.invoke(m_Private,
Qt::QueuedConnection);
}
void Updater::continueCurrentUpdate() {
getMethod(m_Private, "continueCurrentUpdate()")
.invoke(m_Private,
Qt::QueuedConnection);
}
void Updater::cancelCurrentUpdate() {
getMethod(m_Private, "cancelCurrentUpdate()")
.invoke(m_Private,
Qt::QueuedConnection);
}
void Updater::cancelAll() {
getMethod(m_Private, "cancelAll()")
.invoke(m_Private,
Qt::QueuedConnection);
}