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");
133 this, &DownloadImpl::onPropertiesChanged);
136 "Could not connect to signal &PropertiesInterface::PropertiesChanged");
140 DownloadImpl::DownloadImpl(
const QDBusConnection& conn, Error* err,
QObject* parent)
147 DownloadImpl::~DownloadImpl() {
149 delete _dbusInterface;
150 delete _propertiesInterface;
154 DownloadImpl::setLastError(Error* err) {
156 QString(
"Download{%1} setLastError(%2)").arg(_id).arg(
157 err->errorString()));
158 if (_lastError !=
nullptr) {
167 DownloadImpl::setLastError(
const QDBusError& err) {
168 setLastError(
new DBusError(err,
this));
172 DownloadImpl::start() {
173 Logger::log(
Logger::Debug, QString(
"Download{%1} start())").arg(_id));
174 QDBusPendingCall call =
175 _dbusInterface->start();
176 auto watcher =
new DownloadPCW(_conn, _servicePath,
182 DownloadImpl::pause() {
183 Logger::log(
Logger::Debug, QString(
"Download{%1} pause())").arg(_id));
184 QDBusPendingCall call =
185 _dbusInterface->pause();
186 auto watcher =
new DownloadPCW(_conn, _servicePath,
192 DownloadImpl::resume() {
193 Logger::log(
Logger::Debug, QString(
"Download{%1} resume())").arg(_id));
194 QDBusPendingCall call =
195 _dbusInterface->resume();
196 auto watcher =
new DownloadPCW(_conn, _servicePath,
202 DownloadImpl::cancel() {
203 Logger::log(
Logger::Debug, QString(
"Download{%1} cancel())").arg(_id));
204 QDBusPendingCall call =
205 _dbusInterface->cancel();
206 auto watcher =
new DownloadPCW(_conn, _servicePath,
212 DownloadImpl::allowMobileDownload(
bool allowed) {
214 QString(
"Download{%1} allowMobileDownload%2())").arg(_id).arg(allowed));
215 QDBusPendingReply<> reply =
216 _dbusInterface->allowGSMDownload(allowed);
218 reply.waitForFinished();
219 if (reply.isError()) {
220 Logger::log(
Logger::Error,
"Error when setting mobile data usage");
221 setLastError(reply.error());
226 DownloadImpl::isMobileDownloadAllowed() {
228 QString(
"Download{%1} isMobileDownloadAllowed").arg(_id));
229 QDBusPendingReply<bool> reply =
230 _dbusInterface->isGSMDownloadAllowed();
232 reply.waitForFinished();
233 if (reply.isError()) {
234 Logger::log(
Logger::Error,
"Error when querying mobile data usage");
235 setLastError(reply.error());
238 auto result = reply.value();
244 DownloadImpl::setDestinationDir(
const QString& path) {
245 Logger::log(
Logger::Debug, QString(
"Dowmload{%1} setDestinationDir(%2)")
246 .arg(_id).arg(path));
247 QDBusPendingReply<> reply =
248 _dbusInterface->setDestinationDir(path);
250 reply.waitForFinished();
251 if (reply.isError()) {
252 Logger::log(
Logger::Error,
"Error setting the download directory");
253 setLastError(reply.error());
258 DownloadImpl::setHeaders(QMap<QString, QString> headers) {
260 QString(
"Download {%1} setHeaders(%2)").arg(_id), headers);
262 QDBusPendingReply<> reply =
263 _dbusInterface->setHeaders(headers);
265 reply.waitForFinished();
266 if (reply.isError()) {
267 Logger::log(
Logger::Error,
"Error setting the download headers");
268 setLastError(reply.error());
273 DownloadImpl::metadata() {
274 Logger::log(
Logger::Debug, QString(
"Download{%1} metadata()").arg(_id));
275 QDBusPendingReply<QVariantMap> reply =
276 _dbusInterface->metadata();
278 reply.waitForFinished();
279 if (reply.isError()) {
280 Logger::log(
Logger::Error,
"Error querying the download metadata");
281 QVariantMap emptyResult;
282 setLastError(reply.error());
285 auto result = reply.value();
291 DownloadImpl::setMetadata(QVariantMap map) {
293 QString(
"Download {%1} setMetadata(%2)").arg(_id), map);
295 QDBusPendingReply<> reply =
296 _dbusInterface->setMetadata(map);
298 reply.waitForFinished();
299 if (reply.isError()) {
300 qDebug() <<
"Error setting metadata";
301 Logger::log(
Logger::Error,
"Error setting the download metadata");
302 qDebug() << reply.error();
303 setLastError(reply.error());
307 QMap<QString, QString>
308 DownloadImpl::headers() {
309 Logger::log(
Logger::Debug, QString(
"Download{%1} headers()").arg(_id));
310 QDBusPendingReply<QMap<QString, QString> > reply =
311 _dbusInterface->headers();
313 reply.waitForFinished();
314 if (reply.isError()) {
315 Logger::log(
Logger::Error,
"Error querying the download headers");
316 setLastError(reply.error());
317 QMap<QString, QString> empty;
320 auto result = reply.value();
327 DownloadImpl::setThrottle(qulonglong speed) {
329 QString(
"Download{%1} setThrottle(%2)").arg(_id).arg(speed));
330 QDBusPendingReply<> reply =
331 _dbusInterface->setThrottle(speed);
333 reply.waitForFinished();
334 if (reply.isError()) {
335 Logger::log(
Logger::Error,
"Error setting the download throttle");
336 setLastError(reply.error());
341 DownloadImpl::throttle() {
342 Logger::log(
Logger::Debug, QString(
"Download{%1} throttle()").arg(_id));
343 QDBusPendingReply<qulonglong> reply =
344 _dbusInterface->throttle();
346 reply.waitForFinished();
347 if (reply.isError()) {
348 Logger::log(
Logger::Error,
"Error querying the download throttle");
349 setLastError(reply.error());
352 auto result = reply.value();
358 DownloadImpl::id()
const {
363 DownloadImpl::progress() {
364 Logger::log(
Logger::Debug, QString(
"Download{%1} progress()").arg(_id));
365 QDBusPendingReply<qulonglong> reply =
366 _dbusInterface->progress();
368 reply.waitForFinished();
369 if (reply.isError()) {
370 Logger::log(
Logger::Error,
"Error querying the download progress");
371 setLastError(reply.error());
374 auto result = reply.value();
380 DownloadImpl::totalSize() {
381 Logger::log(
Logger::Debug, QString(
"Download{%1} totalSize()").arg(_id));
382 QDBusPendingReply<qulonglong> reply =
383 _dbusInterface->totalSize();
385 reply.waitForFinished();
386 if (reply.isError()) {
387 Logger::log(
Logger::Error,
"Error querying the download size");
388 setLastError(reply.error());
391 auto result = reply.value();
397 DownloadImpl::isError()
const {
402 DownloadImpl::error()
const {
407 DownloadImpl::clickPackage()
const {
408 return _dbusInterface->clickPackage();
412 DownloadImpl::showInIndicator()
const {
413 return _dbusInterface->showInIndicator();
417 DownloadImpl::title()
const {
418 return _dbusInterface->title();
422 DownloadImpl::onHttpError(HttpErrorStruct errStruct) {
423 auto err =
new HttpError(errStruct,
this);
428 DownloadImpl::onNetworkError(NetworkErrorStruct errStruct) {
429 auto err =
new NetworkError(errStruct,
this);
434 DownloadImpl::onProcessError(ProcessErrorStruct errStruct) {
435 auto err =
new ProcessError(errStruct,
this);
440 DownloadImpl::onAuthError(AuthErrorStruct errStruct) {
441 auto err =
new AuthError(errStruct,
this);
446 DownloadImpl::onPropertiesChanged(
const QString& interfaceName,
447 const QVariantMap& changedProperties,
448 const QStringList& invalidatedProperties) {
449 Q_UNUSED(invalidatedProperties);
451 if (interfaceName == DownloadInterface::staticInterfaceName()) {
452 if (changedProperties.contains(CLICK_PACKAGE_PROPERTY)) {
453 emit clickPackagedChanged();
456 if (changedProperties.contains(SHOW_INDICATOR_PROPERTY)) {
457 emit showInIndicatorChanged();
460 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