19 #include <glog/logging.h>
24 namespace DownloadManager {
26 DownloadImpl::DownloadImpl(
const QDBusConnection& conn,
27 const QString& servicePath,
28 const QDBusObjectPath& objectPath,
31 _id(objectPath.path()),
33 _servicePath(servicePath) {
34 _dbusInterface =
new DownloadInterface(servicePath,
38 CHECK(connect(_dbusInterface, &DownloadInterface::canceled,
40 CHECK(connect(_dbusInterface, &DownloadInterface::finished,
42 CHECK(connect(_dbusInterface, &DownloadInterface::paused,
44 CHECK(connect(_dbusInterface, &DownloadInterface::processing,
46 CHECK(connect(_dbusInterface,
static_cast<void(DownloadInterface::*)
47 (qulonglong, qulonglong)
>(&DownloadInterface::progress),
50 <<
"Could not connect to signal";
51 CHECK(connect(_dbusInterface, &DownloadInterface::resumed,
53 CHECK(connect(_dbusInterface, &DownloadInterface::started,
58 CHECK(connect(_dbusInterface, &DownloadInterface::httpError,
59 this, &DownloadImpl::onHttpError)) <<
"Could not connect to signal";
60 CHECK(connect(_dbusInterface, &DownloadInterface::networkError,
61 this, &DownloadImpl::onNetworkError)) <<
"Could not connect to signal";
62 CHECK(connect(_dbusInterface, &DownloadInterface::processError,
63 this, &DownloadImpl::onProcessError)) <<
"Could not connect to signal";
64 CHECK(connect(_dbusInterface, &DownloadInterface::authError,
65 this, &DownloadImpl::onAuthError)) <<
"Could not connect to signal";
68 DownloadImpl::DownloadImpl(
const QDBusConnection& conn, Error* err,
QObject* parent)
75 DownloadImpl::~DownloadImpl() {
77 delete _dbusInterface;
81 DownloadImpl::setLastError(Error* err) {
82 if (_lastError !=
nullptr) {
91 DownloadImpl::setLastError(
const QDBusError& err) {
92 setLastError(
new DBusError(err,
this));
96 DownloadImpl::start() {
97 QDBusPendingCall call =
98 _dbusInterface->start();
99 auto watcher =
new DownloadPCW(_conn, _servicePath,
105 DownloadImpl::pause() {
106 QDBusPendingCall call =
107 _dbusInterface->pause();
108 auto watcher =
new DownloadPCW(_conn, _servicePath,
114 DownloadImpl::resume() {
115 QDBusPendingCall call =
116 _dbusInterface->resume();
117 auto watcher =
new DownloadPCW(_conn, _servicePath,
123 DownloadImpl::cancel() {
124 QDBusPendingCall call =
125 _dbusInterface->cancel();
126 auto watcher =
new DownloadPCW(_conn, _servicePath,
132 DownloadImpl::allowMobileDownload(
bool allowed) {
133 QDBusPendingReply<> reply =
134 _dbusInterface->allowGSMDownload(allowed);
136 reply.waitForFinished();
137 if (reply.isError()) {
138 setLastError(reply.error());
143 DownloadImpl::isMobileDownloadAllowed() {
144 QDBusPendingReply<bool> reply =
145 _dbusInterface->isGSMDownloadAllowed();
147 reply.waitForFinished();
148 if (reply.isError()) {
149 setLastError(reply.error());
152 auto result = reply.value();
158 DownloadImpl::setDestinationDir(
const QString& path) {
159 QDBusPendingReply<> reply =
160 _dbusInterface->setDestinationDir(path);
162 reply.waitForFinished();
163 if (reply.isError()) {
164 setLastError(reply.error());
169 DownloadImpl::setThrottle(qulonglong speed) {
170 QDBusPendingReply<> reply =
171 _dbusInterface->setThrottle(speed);
173 reply.waitForFinished();
174 if (reply.isError()) {
175 setLastError(reply.error());
180 DownloadImpl::throttle() {
181 QDBusPendingReply<qulonglong> reply =
182 _dbusInterface->throttle();
184 reply.waitForFinished();
185 if (reply.isError()) {
186 setLastError(reply.error());
189 auto result = reply.value();
195 DownloadImpl::id()
const {
200 DownloadImpl::metadata() {
201 QDBusPendingReply<QVariantMap> reply =
202 _dbusInterface->metadata();
204 reply.waitForFinished();
205 if (reply.isError()) {
206 QVariantMap emptyResult;
207 setLastError(reply.error());
210 auto result = reply.value();
216 DownloadImpl::progress() {
217 QDBusPendingReply<qulonglong> reply =
218 _dbusInterface->progress();
220 reply.waitForFinished();
221 if (reply.isError()) {
222 setLastError(reply.error());
225 auto result = reply.value();
231 DownloadImpl::totalSize() {
232 QDBusPendingReply<qulonglong> reply =
233 _dbusInterface->totalSize();
235 reply.waitForFinished();
236 if (reply.isError()) {
237 setLastError(reply.error());
240 auto result = reply.value();
246 DownloadImpl::isError()
const {
251 DownloadImpl::error()
const {
256 DownloadImpl::onHttpError(HttpErrorStruct errStruct) {
257 auto err =
new HttpError(errStruct,
this);
262 DownloadImpl::onNetworkError(NetworkErrorStruct errStruct) {
263 auto err =
new NetworkError(errStruct,
this);
268 DownloadImpl::onProcessError(ProcessErrorStruct errStruct) {
269 auto err =
new ProcessError(errStruct,
this);
274 DownloadImpl::onAuthError(AuthErrorStruct errStruct) {
275 auto err =
new AuthError(errStruct,
this);
void paused(bool success)
void finished(const QString &path)
void canceled(bool success)
void resumed(bool success)
Download(QObject *parent=0)
void processing(const QString &path)
void started(bool success)
virtual Error * error() const =0
virtual qulonglong progress()=0