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::finished,
66 this, &DownloadImpl::onFinished);
69 "Could not connect to signal &DownloadInterface::finished");
72 connected = connect(_dbusInterface, &DownloadInterface::paused,
76 "Could not connect to signal DownloadInterface::paused");
79 connected = connect(_dbusInterface, &DownloadInterface::processing,
83 "Could not connect to signal DownloadInterface::processing");
86 connected = connect(_dbusInterface,
static_cast<void(DownloadInterface::*)
87 (qulonglong, qulonglong)
>(&DownloadInterface::progress),
92 "Could not connect to signal &DownloadInterface::progress");
95 connected = connect(_dbusInterface, &DownloadInterface::resumed,
99 "Could not connect to signal &DownloadInterface::resumed");
102 connected = connect(_dbusInterface, &DownloadInterface::started,
106 "Could not connect to signal &DownloadInterface::started");
111 connected = connect(_dbusInterface, &DownloadInterface::httpError,
112 this, &DownloadImpl::onHttpError);
115 "Could not connect to signal &DownloadInterface::httpError");
118 connected = connect(_dbusInterface, &DownloadInterface::networkError,
119 this, &DownloadImpl::onNetworkError);
122 "Could not connect to signal &DownloadInterface::networkError");
125 connected = connect(_dbusInterface, &DownloadInterface::processError,
126 this, &DownloadImpl::onProcessError);
129 "Could not connect to signal &DownloadInterface::processError");
132 connected = connect(_dbusInterface, &DownloadInterface::authError,
133 this, &DownloadImpl::onAuthError);
136 "Could not connect to signal &DownloadInterface::authError");
139 connected = connect(_dbusInterface, &DownloadInterface::hashError,
140 this, &DownloadImpl::onHashError);
143 "Could not connect to signal &DownloadInterface::authError");
147 this, &DownloadImpl::onPropertiesChanged);
150 "Could not connect to signal &PropertiesInterface::PropertiesChanged");
154 DownloadImpl::DownloadImpl(
const QDBusConnection& conn, Error* err,
QObject* parent)
161 DownloadImpl::~DownloadImpl() {
163 delete _dbusInterface;
164 delete _propertiesInterface;
168 DownloadImpl::setLastError(Error* err) {
170 QString(
"Download{%1} setLastError(%2)").arg(_id).arg(
171 err->errorString()));
172 if (_lastError !=
nullptr) {
181 DownloadImpl::setLastError(
const QDBusError& err) {
182 setLastError(
new DBusError(err,
this));
186 DownloadImpl::start() {
187 Logger::log(
Logger::Debug, QString(
"Download{%1} start())").arg(_id));
188 QDBusPendingCall call =
189 _dbusInterface->start();
190 auto watcher =
new DownloadPCW(_conn, _servicePath,
196 DownloadImpl::pause() {
197 Logger::log(
Logger::Debug, QString(
"Download{%1} pause())").arg(_id));
198 QDBusPendingCall call =
199 _dbusInterface->pause();
200 auto watcher =
new DownloadPCW(_conn, _servicePath,
206 DownloadImpl::resume() {
207 Logger::log(
Logger::Debug, QString(
"Download{%1} resume())").arg(_id));
208 QDBusPendingCall call =
209 _dbusInterface->resume();
210 auto watcher =
new DownloadPCW(_conn, _servicePath,
216 DownloadImpl::cancel() {
217 Logger::log(
Logger::Debug, QString(
"Download{%1} cancel())").arg(_id));
218 QDBusPendingCall call =
219 _dbusInterface->cancel();
220 auto watcher =
new DownloadPCW(_conn, _servicePath,
226 DownloadImpl::collected() {
227 Logger::log(
Logger::Debug, QString(
"Download{%1} collected()").arg(_id));
228 QDBusPendingReply<> reply =
229 _dbusInterface->collected();
231 reply.waitForFinished();
232 if (reply.isError()) {
233 Logger::log(
Logger::Error,
"Error when setting download collected");
234 setLastError(reply.error());
239 DownloadImpl::allowMobileDownload(
bool allowed) {
241 QString(
"Download{%1} allowMobileDownload%2())").arg(_id).arg(allowed));
242 QDBusPendingReply<> reply =
243 _dbusInterface->allowGSMDownload(allowed);
245 reply.waitForFinished();
246 if (reply.isError()) {
247 Logger::log(
Logger::Error,
"Error when setting mobile data usage");
248 setLastError(reply.error());
253 DownloadImpl::isMobileDownloadAllowed() {
255 QString(
"Download{%1} isMobileDownloadAllowed").arg(_id));
256 QDBusPendingReply<bool> reply =
257 _dbusInterface->isGSMDownloadAllowed();
259 reply.waitForFinished();
260 if (reply.isError()) {
261 Logger::log(
Logger::Error,
"Error when querying mobile data usage");
262 setLastError(reply.error());
265 auto result = reply.value();
271 DownloadImpl::setDestinationDir(
const QString& path) {
272 Logger::log(
Logger::Debug, QString(
"Dowmload{%1} setDestinationDir(%2)")
273 .arg(_id).arg(path));
274 QDBusPendingReply<> reply =
275 _dbusInterface->setDestinationDir(path);
277 reply.waitForFinished();
278 if (reply.isError()) {
279 Logger::log(
Logger::Error,
"Error setting the download directory");
280 setLastError(reply.error());
285 DownloadImpl::setHeaders(QMap<QString, QString> headers) {
287 QString(
"Download {%1} setHeaders(%2)").arg(_id), headers);
289 QDBusPendingReply<> reply =
290 _dbusInterface->setHeaders(headers);
292 reply.waitForFinished();
293 if (reply.isError()) {
294 Logger::log(
Logger::Error,
"Error setting the download headers");
295 setLastError(reply.error());
300 DownloadImpl::metadata() {
301 Logger::log(
Logger::Debug, QString(
"Download{%1} metadata()").arg(_id));
302 QDBusPendingReply<QVariantMap> reply =
303 _dbusInterface->metadata();
305 reply.waitForFinished();
306 if (reply.isError()) {
307 Logger::log(
Logger::Error,
"Error querying the download metadata");
308 QVariantMap emptyResult;
309 setLastError(reply.error());
312 auto result = reply.value();
318 DownloadImpl::setMetadata(QVariantMap map) {
320 QString(
"Download {%1} setMetadata(%2)").arg(_id), map);
322 QDBusPendingReply<> reply =
323 _dbusInterface->setMetadata(map);
325 reply.waitForFinished();
326 if (reply.isError()) {
327 Logger::log(
Logger::Error,
"Error setting the download metadata");
328 setLastError(reply.error());
332 QMap<QString, QString>
333 DownloadImpl::headers() {
334 Logger::log(
Logger::Debug, QString(
"Download{%1} headers()").arg(_id));
335 QDBusPendingReply<QMap<QString, QString> > reply =
336 _dbusInterface->headers();
338 reply.waitForFinished();
339 if (reply.isError()) {
340 Logger::log(
Logger::Error,
"Error querying the download headers");
341 setLastError(reply.error());
342 QMap<QString, QString> empty;
345 auto result = reply.value();
352 DownloadImpl::setThrottle(qulonglong speed) {
354 QString(
"Download{%1} setThrottle(%2)").arg(_id).arg(speed));
355 QDBusPendingReply<> reply =
356 _dbusInterface->setThrottle(speed);
358 reply.waitForFinished();
359 if (reply.isError()) {
360 Logger::log(
Logger::Error,
"Error setting the download throttle");
361 setLastError(reply.error());
366 DownloadImpl::throttle() {
367 Logger::log(
Logger::Debug, QString(
"Download{%1} throttle()").arg(_id));
368 QDBusPendingReply<qulonglong> reply =
369 _dbusInterface->throttle();
371 reply.waitForFinished();
372 if (reply.isError()) {
373 Logger::log(
Logger::Error,
"Error querying the download throttle");
374 setLastError(reply.error());
377 auto result = reply.value();
383 DownloadImpl::filePath() {
384 Logger::log(
Logger::Debug, QString(
"Download{%1} filePath()").arg(_id));
385 QDBusPendingReply<QString> reply =
386 _dbusInterface->filePath();
388 reply.waitForFinished();
389 if (reply.isError()) {
390 Logger::log(
Logger::Error,
"Error querying the download file path");
391 setLastError(reply.error());
394 auto result = reply.value();
400 DownloadImpl::state() {
401 Logger::log(
Logger::Debug, QString(
"Download{%1} state()").arg(_id));
402 QDBusPendingReply<int> reply =
403 _dbusInterface->state();
405 reply.waitForFinished();
406 if (reply.isError()) {
407 Logger::log(
Logger::Error,
"Error querying the download state");
408 setLastError(reply.error());
417 DownloadImpl::id()
const {
422 DownloadImpl::progress() {
423 Logger::log(
Logger::Debug, QString(
"Download{%1} progress()").arg(_id));
424 QDBusPendingReply<qulonglong> reply =
425 _dbusInterface->progress();
427 reply.waitForFinished();
428 if (reply.isError()) {
429 Logger::log(
Logger::Error,
"Error querying the download progress");
430 setLastError(reply.error());
433 auto result = reply.value();
439 DownloadImpl::totalSize() {
440 Logger::log(
Logger::Debug, QString(
"Download{%1} totalSize()").arg(_id));
441 QDBusPendingReply<qulonglong> reply =
442 _dbusInterface->totalSize();
444 reply.waitForFinished();
445 if (reply.isError()) {
446 Logger::log(
Logger::Error,
"Error querying the download size");
447 setLastError(reply.error());
450 auto result = reply.value();
456 DownloadImpl::isError()
const {
461 DownloadImpl::error()
const {
466 DownloadImpl::clickPackage()
const {
467 return _dbusInterface->clickPackage();
471 DownloadImpl::showInIndicator()
const {
472 return _dbusInterface->showInIndicator();
476 DownloadImpl::title()
const {
477 return _dbusInterface->title();
481 DownloadImpl::destinationApp()
const {
482 return _dbusInterface->destinationApp();
486 DownloadImpl::onHttpError(HttpErrorStruct errStruct) {
487 auto err =
new HttpError(errStruct,
this);
492 DownloadImpl::onNetworkError(NetworkErrorStruct errStruct) {
493 auto err =
new NetworkError(errStruct,
this);
498 DownloadImpl::onProcessError(ProcessErrorStruct errStruct) {
499 auto err =
new ProcessError(errStruct,
this);
504 DownloadImpl::onAuthError(AuthErrorStruct errStruct) {
505 auto err =
new AuthError(errStruct,
this);
510 DownloadImpl::onHashError(HashErrorStruct errStruct) {
511 auto err =
new HashError(errStruct,
this);
516 DownloadImpl::onPropertiesChanged(
const QString& interfaceName,
517 const QVariantMap& changedProperties,
518 const QStringList& invalidatedProperties) {
519 Q_UNUSED(invalidatedProperties);
521 if (interfaceName == DownloadInterface::staticInterfaceName()) {
522 if (changedProperties.contains(CLICK_PACKAGE_PROPERTY)) {
523 emit clickPackagedChanged();
526 if (changedProperties.contains(SHOW_INDICATOR_PROPERTY)) {
527 emit showInIndicatorChanged();
530 if (changedProperties.contains(TITLE_PROPERTY)) {
536 void DownloadImpl::onFinished(
const QString &path) {
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