24 namespace DownloadManager {
26 using namespace Logging;
28 DownloadImpl::DownloadImpl(
const QDBusConnection& conn,
29 const QString& servicePath,
30 const QDBusObjectPath& objectPath,
33 _id(objectPath.path()),
35 _servicePath(servicePath) {
37 _dbusInterface =
new DownloadInterface(servicePath,
41 auto connected = connect(_dbusInterface, &DownloadInterface::canceled,
46 "Could not connect to signal DownloadInterface::canceled");
49 connected = connect(_dbusInterface, &DownloadInterface::finished,
53 "Could not connect to signal &DownloadInterface::finished");
56 connected = connect(_dbusInterface, &DownloadInterface::paused,
60 "Could not connect to signal DownloadInterface::paused");
63 connected = connect(_dbusInterface, &DownloadInterface::processing,
67 "Could not connect to signal DownloadInterface::processing");
70 connected = connect(_dbusInterface,
static_cast<void(DownloadInterface::*)
71 (qulonglong, qulonglong)
>(&DownloadInterface::progress),
76 "Could not connect to signal &DownloadInterface::progress");
79 connected = connect(_dbusInterface, &DownloadInterface::resumed,
83 "Could not connect to signal &DownloadInterface::resumed");
86 connected = connect(_dbusInterface, &DownloadInterface::started,
90 "Could not connect to signal &DownloadInterface::started");
95 connected = connect(_dbusInterface, &DownloadInterface::httpError,
96 this, &DownloadImpl::onHttpError);
99 "Could not connect to signal &DownloadInterface::httpError");
102 connected = connect(_dbusInterface, &DownloadInterface::networkError,
103 this, &DownloadImpl::onNetworkError);
106 "Could not connect to signal &DownloadInterface::networkError");
109 connected = connect(_dbusInterface, &DownloadInterface::processError,
110 this, &DownloadImpl::onProcessError);
113 "Could not connect to signal &DownloadInterface::processError");
116 connected = connect(_dbusInterface, &DownloadInterface::authError,
117 this, &DownloadImpl::onAuthError);
120 "Could not connect to signal &DownloadInterface::authError");
124 DownloadImpl::DownloadImpl(
const QDBusConnection& conn, Error* err,
QObject* parent)
131 DownloadImpl::~DownloadImpl() {
133 delete _dbusInterface;
137 DownloadImpl::setLastError(Error* err) {
139 QString(
"Download{%1} setLastError(%2)").arg(_id).arg(
140 err->errorString()));
141 if (_lastError !=
nullptr) {
150 DownloadImpl::setLastError(
const QDBusError& err) {
151 setLastError(
new DBusError(err,
this));
155 DownloadImpl::start() {
156 Logger::log(
Logger::Debug, QString(
"Download{%1} start())").arg(_id));
157 QDBusPendingCall call =
158 _dbusInterface->start();
159 auto watcher =
new DownloadPCW(_conn, _servicePath,
165 DownloadImpl::pause() {
166 Logger::log(
Logger::Debug, QString(
"Download{%1} pause())").arg(_id));
167 QDBusPendingCall call =
168 _dbusInterface->pause();
169 auto watcher =
new DownloadPCW(_conn, _servicePath,
175 DownloadImpl::resume() {
176 Logger::log(
Logger::Debug, QString(
"Download{%1} resume())").arg(_id));
177 QDBusPendingCall call =
178 _dbusInterface->resume();
179 auto watcher =
new DownloadPCW(_conn, _servicePath,
185 DownloadImpl::cancel() {
186 Logger::log(
Logger::Debug, QString(
"Download{%1} cancel())").arg(_id));
187 QDBusPendingCall call =
188 _dbusInterface->cancel();
189 auto watcher =
new DownloadPCW(_conn, _servicePath,
195 DownloadImpl::allowMobileDownload(
bool allowed) {
197 QString(
"Download{%1} allowMobileDownload%2())").arg(_id).arg(allowed));
198 QDBusPendingReply<> reply =
199 _dbusInterface->allowGSMDownload(allowed);
201 reply.waitForFinished();
202 if (reply.isError()) {
203 Logger::log(
Logger::Error,
"Error when setting mobile data usage");
204 setLastError(reply.error());
209 DownloadImpl::isMobileDownloadAllowed() {
211 QString(
"Download{%1} isMobileDownloadAllowed").arg(_id));
212 QDBusPendingReply<bool> reply =
213 _dbusInterface->isGSMDownloadAllowed();
215 reply.waitForFinished();
216 if (reply.isError()) {
217 Logger::log(
Logger::Error,
"Error when querying mobile data usage");
218 setLastError(reply.error());
221 auto result = reply.value();
227 DownloadImpl::setDestinationDir(
const QString& path) {
228 Logger::log(
Logger::Debug, QString(
"Dowmload{%1} setDestinationDir(%2)")
229 .arg(_id).arg(path));
230 QDBusPendingReply<> reply =
231 _dbusInterface->setDestinationDir(path);
233 reply.waitForFinished();
234 if (reply.isError()) {
235 Logger::log(
Logger::Error,
"Error setting the download directory");
236 setLastError(reply.error());
241 DownloadImpl::setHeaders(QMap<QString, QString> headers) {
243 QString(
"Download {%1} setHeaders(%2)").arg(_id), headers);
245 QDBusPendingReply<> reply =
246 _dbusInterface->setHeaders(headers);
248 reply.waitForFinished();
249 if (reply.isError()) {
250 Logger::log(
Logger::Error,
"Error setting the download headers");
251 setLastError(reply.error());
255 QMap<QString, QString>
256 DownloadImpl::headers() {
257 Logger::log(
Logger::Debug, QString(
"Download{%1} headers()").arg(_id));
258 QDBusPendingReply<QMap<QString, QString> > reply =
259 _dbusInterface->headers();
261 reply.waitForFinished();
262 if (reply.isError()) {
263 Logger::log(
Logger::Error,
"Error querying the download headers");
264 setLastError(reply.error());
265 QMap<QString, QString> empty;
268 auto result = reply.value();
275 DownloadImpl::setThrottle(qulonglong speed) {
277 QString(
"Download{%1} setThrottle(%2)").arg(_id).arg(speed));
278 QDBusPendingReply<> reply =
279 _dbusInterface->setThrottle(speed);
281 reply.waitForFinished();
282 if (reply.isError()) {
283 Logger::log(
Logger::Error,
"Error setting the download throttle");
284 setLastError(reply.error());
289 DownloadImpl::throttle() {
290 Logger::log(
Logger::Debug, QString(
"Download{%1} throttle()").arg(_id));
291 QDBusPendingReply<qulonglong> reply =
292 _dbusInterface->throttle();
294 reply.waitForFinished();
295 if (reply.isError()) {
296 Logger::log(
Logger::Error,
"Error querying the download throttle");
297 setLastError(reply.error());
300 auto result = reply.value();
306 DownloadImpl::id()
const {
311 DownloadImpl::metadata() {
312 Logger::log(
Logger::Debug, QString(
"Download{%1} metadata()").arg(_id));
313 QDBusPendingReply<QVariantMap> reply =
314 _dbusInterface->metadata();
316 reply.waitForFinished();
317 if (reply.isError()) {
318 Logger::log(
Logger::Error,
"Error querying the download metadata");
319 QVariantMap emptyResult;
320 setLastError(reply.error());
323 auto result = reply.value();
329 DownloadImpl::progress() {
330 Logger::log(
Logger::Debug, QString(
"Download{%1} progress()").arg(_id));
331 QDBusPendingReply<qulonglong> reply =
332 _dbusInterface->progress();
334 reply.waitForFinished();
335 if (reply.isError()) {
336 Logger::log(
Logger::Error,
"Error querying the download progress");
337 setLastError(reply.error());
340 auto result = reply.value();
346 DownloadImpl::totalSize() {
347 Logger::log(
Logger::Debug, QString(
"Download{%1} totalSize()").arg(_id));
348 QDBusPendingReply<qulonglong> reply =
349 _dbusInterface->totalSize();
351 reply.waitForFinished();
352 if (reply.isError()) {
353 Logger::log(
Logger::Error,
"Error querying the download size");
354 setLastError(reply.error());
357 auto result = reply.value();
363 DownloadImpl::isError()
const {
368 DownloadImpl::error()
const {
373 DownloadImpl::onHttpError(HttpErrorStruct errStruct) {
374 auto err =
new HttpError(errStruct,
this);
379 DownloadImpl::onNetworkError(NetworkErrorStruct errStruct) {
380 auto err =
new NetworkError(errStruct,
this);
385 DownloadImpl::onProcessError(ProcessErrorStruct errStruct) {
386 auto err =
new ProcessError(errStruct,
this);
391 DownloadImpl::onAuthError(AuthErrorStruct errStruct) {
392 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