23 const QString CLICK_PACKAGE_PROPERTY =
"ClickPackage";
24 const QString SHOW_INDICATOR_PROPERTY =
"ShowInIndicator";
25 const QString TITLE_PROPERTY =
"Title";
30 namespace DownloadManager {
32 using namespace Logging;
34 DownloadImpl::DownloadImpl(
const QDBusConnection& conn,
35 const QString& servicePath,
36 const QDBusObjectPath& objectPath,
39 _id(objectPath.path()),
41 _servicePath(servicePath) {
43 _dbusInterface =
new DownloadInterface(servicePath,
50 auto connected = connect(_dbusInterface, &DownloadInterface::canceled,
55 "Could not connect to signal DownloadInterface::canceled");
58 connected = connect(_dbusInterface, &DownloadInterface::finished,
62 "Could not connect to signal &DownloadInterface::finished");
65 connected = connect(_dbusInterface, &DownloadInterface::paused,
69 "Could not connect to signal DownloadInterface::paused");
72 connected = connect(_dbusInterface, &DownloadInterface::processing,
76 "Could not connect to signal DownloadInterface::processing");
79 connected = connect(_dbusInterface,
static_cast<void(DownloadInterface::*)
80 (qulonglong, qulonglong)
>(&DownloadInterface::progress),
85 "Could not connect to signal &DownloadInterface::progress");
88 connected = connect(_dbusInterface, &DownloadInterface::resumed,
92 "Could not connect to signal &DownloadInterface::resumed");
95 connected = connect(_dbusInterface, &DownloadInterface::started,
99 "Could not connect to signal &DownloadInterface::started");
104 connected = connect(_dbusInterface, &DownloadInterface::httpError,
105 this, &DownloadImpl::onHttpError);
108 "Could not connect to signal &DownloadInterface::httpError");
111 connected = connect(_dbusInterface, &DownloadInterface::networkError,
112 this, &DownloadImpl::onNetworkError);
115 "Could not connect to signal &DownloadInterface::networkError");
118 connected = connect(_dbusInterface, &DownloadInterface::processError,
119 this, &DownloadImpl::onProcessError);
122 "Could not connect to signal &DownloadInterface::processError");
125 connected = connect(_dbusInterface, &DownloadInterface::authError,
126 this, &DownloadImpl::onAuthError);
129 "Could not connect to signal &DownloadInterface::authError");
132 connected = connect(_dbusInterface, &DownloadInterface::hashError,
133 this, &DownloadImpl::onHashError);
136 "Could not connect to signal &DownloadInterface::authError");
140 this, &DownloadImpl::onPropertiesChanged);
143 "Could not connect to signal &PropertiesInterface::PropertiesChanged");
147 DownloadImpl::DownloadImpl(
const QDBusConnection& conn, Error* err,
QObject* parent)
154 DownloadImpl::~DownloadImpl() {
156 delete _dbusInterface;
157 delete _propertiesInterface;
161 DownloadImpl::setLastError(Error* err) {
163 QString(
"Download{%1} setLastError(%2)").arg(_id).arg(
164 err->errorString()));
165 if (_lastError !=
nullptr) {
174 DownloadImpl::setLastError(
const QDBusError& err) {
175 setLastError(
new DBusError(err,
this));
179 DownloadImpl::start() {
180 Logger::log(
Logger::Debug, QString(
"Download{%1} start())").arg(_id));
181 QDBusPendingCall call =
182 _dbusInterface->start();
183 auto watcher =
new DownloadPCW(_conn, _servicePath,
189 DownloadImpl::pause() {
190 Logger::log(
Logger::Debug, QString(
"Download{%1} pause())").arg(_id));
191 QDBusPendingCall call =
192 _dbusInterface->pause();
193 auto watcher =
new DownloadPCW(_conn, _servicePath,
199 DownloadImpl::resume() {
200 Logger::log(
Logger::Debug, QString(
"Download{%1} resume())").arg(_id));
201 QDBusPendingCall call =
202 _dbusInterface->resume();
203 auto watcher =
new DownloadPCW(_conn, _servicePath,
209 DownloadImpl::cancel() {
210 Logger::log(
Logger::Debug, QString(
"Download{%1} cancel())").arg(_id));
211 QDBusPendingCall call =
212 _dbusInterface->cancel();
213 auto watcher =
new DownloadPCW(_conn, _servicePath,
219 DownloadImpl::allowMobileDownload(
bool allowed) {
221 QString(
"Download{%1} allowMobileDownload%2())").arg(_id).arg(allowed));
222 QDBusPendingReply<> reply =
223 _dbusInterface->allowGSMDownload(allowed);
225 reply.waitForFinished();
226 if (reply.isError()) {
227 Logger::log(
Logger::Error,
"Error when setting mobile data usage");
228 setLastError(reply.error());
233 DownloadImpl::isMobileDownloadAllowed() {
235 QString(
"Download{%1} isMobileDownloadAllowed").arg(_id));
236 QDBusPendingReply<bool> reply =
237 _dbusInterface->isGSMDownloadAllowed();
239 reply.waitForFinished();
240 if (reply.isError()) {
241 Logger::log(
Logger::Error,
"Error when querying mobile data usage");
242 setLastError(reply.error());
245 auto result = reply.value();
251 DownloadImpl::setDestinationDir(
const QString& path) {
252 Logger::log(
Logger::Debug, QString(
"Dowmload{%1} setDestinationDir(%2)")
253 .arg(_id).arg(path));
254 QDBusPendingReply<> reply =
255 _dbusInterface->setDestinationDir(path);
257 reply.waitForFinished();
258 if (reply.isError()) {
259 Logger::log(
Logger::Error,
"Error setting the download directory");
260 setLastError(reply.error());
265 DownloadImpl::setHeaders(QMap<QString, QString> headers) {
267 QString(
"Download {%1} setHeaders(%2)").arg(_id), headers);
269 QDBusPendingReply<> reply =
270 _dbusInterface->setHeaders(headers);
272 reply.waitForFinished();
273 if (reply.isError()) {
274 Logger::log(
Logger::Error,
"Error setting the download headers");
275 setLastError(reply.error());
280 DownloadImpl::metadata() {
281 Logger::log(
Logger::Debug, QString(
"Download{%1} metadata()").arg(_id));
282 QDBusPendingReply<QVariantMap> reply =
283 _dbusInterface->metadata();
285 reply.waitForFinished();
286 if (reply.isError()) {
287 Logger::log(
Logger::Error,
"Error querying the download metadata");
288 QVariantMap emptyResult;
289 setLastError(reply.error());
292 auto result = reply.value();
298 DownloadImpl::setMetadata(QVariantMap map) {
300 QString(
"Download {%1} setMetadata(%2)").arg(_id), map);
302 QDBusPendingReply<> reply =
303 _dbusInterface->setMetadata(map);
305 reply.waitForFinished();
306 if (reply.isError()) {
307 qDebug() <<
"Error setting metadata";
308 Logger::log(
Logger::Error,
"Error setting the download metadata");
309 qDebug() << reply.error();
310 setLastError(reply.error());
314 QMap<QString, QString>
315 DownloadImpl::headers() {
316 Logger::log(
Logger::Debug, QString(
"Download{%1} headers()").arg(_id));
317 QDBusPendingReply<QMap<QString, QString> > reply =
318 _dbusInterface->headers();
320 reply.waitForFinished();
321 if (reply.isError()) {
322 Logger::log(
Logger::Error,
"Error querying the download headers");
323 setLastError(reply.error());
324 QMap<QString, QString> empty;
327 auto result = reply.value();
334 DownloadImpl::setThrottle(qulonglong speed) {
336 QString(
"Download{%1} setThrottle(%2)").arg(_id).arg(speed));
337 QDBusPendingReply<> reply =
338 _dbusInterface->setThrottle(speed);
340 reply.waitForFinished();
341 if (reply.isError()) {
342 Logger::log(
Logger::Error,
"Error setting the download throttle");
343 setLastError(reply.error());
348 DownloadImpl::throttle() {
349 Logger::log(
Logger::Debug, QString(
"Download{%1} throttle()").arg(_id));
350 QDBusPendingReply<qulonglong> reply =
351 _dbusInterface->throttle();
353 reply.waitForFinished();
354 if (reply.isError()) {
355 Logger::log(
Logger::Error,
"Error querying the download throttle");
356 setLastError(reply.error());
359 auto result = reply.value();
365 DownloadImpl::id()
const {
370 DownloadImpl::progress() {
371 Logger::log(
Logger::Debug, QString(
"Download{%1} progress()").arg(_id));
372 QDBusPendingReply<qulonglong> reply =
373 _dbusInterface->progress();
375 reply.waitForFinished();
376 if (reply.isError()) {
377 Logger::log(
Logger::Error,
"Error querying the download progress");
378 setLastError(reply.error());
381 auto result = reply.value();
387 DownloadImpl::totalSize() {
388 Logger::log(
Logger::Debug, QString(
"Download{%1} totalSize()").arg(_id));
389 QDBusPendingReply<qulonglong> reply =
390 _dbusInterface->totalSize();
392 reply.waitForFinished();
393 if (reply.isError()) {
394 Logger::log(
Logger::Error,
"Error querying the download size");
395 setLastError(reply.error());
398 auto result = reply.value();
404 DownloadImpl::isError()
const {
409 DownloadImpl::error()
const {
414 DownloadImpl::clickPackage()
const {
415 return _dbusInterface->clickPackage();
419 DownloadImpl::showInIndicator()
const {
420 return _dbusInterface->showInIndicator();
424 DownloadImpl::title()
const {
425 return _dbusInterface->title();
429 DownloadImpl::onHttpError(HttpErrorStruct errStruct) {
430 auto err =
new HttpError(errStruct,
this);
435 DownloadImpl::onNetworkError(NetworkErrorStruct errStruct) {
436 auto err =
new NetworkError(errStruct,
this);
441 DownloadImpl::onProcessError(ProcessErrorStruct errStruct) {
442 auto err =
new ProcessError(errStruct,
this);
447 DownloadImpl::onAuthError(AuthErrorStruct errStruct) {
448 auto err =
new AuthError(errStruct,
this);
453 DownloadImpl::onHashError(HashErrorStruct errStruct) {
454 auto err =
new HashError(errStruct,
this);
459 DownloadImpl::onPropertiesChanged(
const QString& interfaceName,
460 const QVariantMap& changedProperties,
461 const QStringList& invalidatedProperties) {
462 Q_UNUSED(invalidatedProperties);
464 if (interfaceName == DownloadInterface::staticInterfaceName()) {
465 if (changedProperties.contains(CLICK_PACKAGE_PROPERTY)) {
466 emit clickPackagedChanged();
469 if (changedProperties.contains(SHOW_INDICATOR_PROPERTY)) {
470 emit showInIndicatorChanged();
473 if (changedProperties.contains(TITLE_PROPERTY)) {
void paused(bool success)
void finished(const QString &path)
void canceled(bool success)
void resumed(bool success)
Download(QObject *parent=0)
void PropertiesChanged(const QString &interface_name, const QVariantMap &changed_properties, const QStringList &invalidated_properties)
void processing(const QString &path)
void started(bool success)
virtual Error * error() const =0
virtual qulonglong progress()=0