Merge lp:~mandel/ubuntu-download-manager/all-downloads-client into lp:ubuntu-download-manager

Proposed by Manuel de la Peña
Status: Superseded
Proposed branch: lp:~mandel/ubuntu-download-manager/all-downloads-client
Merge into: lp:ubuntu-download-manager
Prerequisite: lp:~mandel/ubuntu-download-manager/second-reorg
Diff against target: 1729 lines (+1039/-89)
30 files modified
docs/com.canonical.applications.download.xml (+4/-0)
src/downloads/client/CMakeLists.txt (+3/-0)
src/downloads/client/ubuntu-download-manager-client.pro.THIS (+59/-0)
src/downloads/client/ubuntu/download_manager/download.h (+9/-0)
src/downloads/client/ubuntu/download_manager/download_impl.cpp (+15/-4)
src/downloads/client/ubuntu/download_manager/download_impl.h (+6/-2)
src/downloads/client/ubuntu/download_manager/download_interface.h (+7/-0)
src/downloads/client/ubuntu/download_manager/download_pendingcall_watcher.cpp (+4/-4)
src/downloads/client/ubuntu/download_manager/download_pendingcall_watcher.h (+2/-2)
src/downloads/client/ubuntu/download_manager/downloads_list.h (+50/-0)
src/downloads/client/ubuntu/download_manager/downloads_list_impl.cpp (+64/-0)
src/downloads/client/ubuntu/download_manager/downloads_list_impl.h (+53/-0)
src/downloads/client/ubuntu/download_manager/error.h (+5/-3)
src/downloads/client/ubuntu/download_manager/group_download.h (+1/-1)
src/downloads/client/ubuntu/download_manager/manager.h (+76/-2)
src/downloads/client/ubuntu/download_manager/manager_impl.cpp (+51/-22)
src/downloads/client/ubuntu/download_manager/manager_impl.h (+12/-2)
src/downloads/client/ubuntu/download_manager/manager_pendingcall_watcher.cpp (+111/-20)
src/downloads/client/ubuntu/download_manager/manager_pendingcall_watcher.h (+60/-17)
src/downloads/priv/ubuntu/downloads/download_adaptor.cpp (+6/-0)
src/downloads/priv/ubuntu/downloads/download_adaptor.h (+4/-0)
src/downloads/priv/ubuntu/downloads/file_download.cpp (+70/-4)
src/downloads/priv/ubuntu/downloads/file_download.h (+4/-1)
src/downloads/test-daemon/testing_file_download.h (+1/-1)
tests/test_client_download.cpp (+51/-3)
tests/test_client_download.h (+7/-0)
tests/test_client_manager.cpp (+202/-0)
tests/test_client_manager.h (+8/-0)
tests/test_download.cpp (+87/-1)
tests/test_download.h (+7/-0)
To merge this branch: bzr merge lp:~mandel/ubuntu-download-manager/all-downloads-client
Reviewer Review Type Date Requested Status
Mike McCracken (community) Abstain
dobey (community) Abstain
PS Jenkins bot continuous-integration Needs Fixing
Alejandro J. Cura Pending
Review via email: mp+215880@code.launchpad.net

This proposal supersedes a proposal from 2014-02-20.

This proposal has been superseded by a proposal from 2014-04-15.

Commit message

Provide the methods that allow to get all the downloads and all the downloads with a given metadata value.

Description of the change

Provide the methods that allow to get all the downloads and all the downloads with a given metadata value.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
Mike McCracken (mikemc) wrote : Posted in a previous version of this proposal

looks good, tests pass. will start adding it to unity-scope-click and I'll file separate bugs if there are any problems.

review: Approve
Revision history for this message
Alejandro J. Cura (alecu) wrote : Posted in a previous version of this proposal

puked a little bit in my mouth when I saw the size of this, but it looks good: +1

review: Approve
Revision history for this message
dobey (dobey) wrote : Posted in a previous version of this proposal

Why are so many changes in this one branch? Particularly the huge change to cmake, addition of coverage reporting (the necessary cmake files of which have some small licensing issues), and several other small bug fixes? The branch is now beyond unreasonably huge, due to r242..246 which were all added after the branch had been approved. Not to mention the 19 other current MPs, some of which are also extremely large.

I find it very hard to believe that a branch of this size, with this many changes, is acceptable to land. Are those commits made *after* the approval really necessary to have here? If so, why?

review: Needs Fixing
Revision history for this message
Manuel de la Peña (mandel) wrote :

We are not just landing this fix for unity-click-scope. Reproposed with the correct pre-requisite branch. Please take a look as soon as possible or we cannot block code any longer.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:246
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~mandel/ubuntu-download-manager/all-downloads-client/+merge/215880/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/ubuntu-download-manager-ci/614/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-download-manager-trusty-amd64-ci/504
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-download-manager-trusty-armhf-ci/503

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/ubuntu-download-manager-ci/614/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
dobey (dobey) wrote :

=== added file 'src/downloads/client/ubuntu-download-manager-client.pro.THIS'

Looks like this is left around from a conflict somewhere? Can you remove this?

review: Needs Fixing
247. By Manuel de la Peña

Remove useless files.

248. By Manuel de la Peña

Merged set-download-dir into all-downloads-client.

249. By Manuel de la Peña

Merged set-download-dir into all-downloads-client.

Revision history for this message
dobey (dobey) :
review: Abstain
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
Mike McCracken (mikemc) :
review: Abstain
250. By Manuel de la Peña

Remove the .THIS file.

251. By Manuel de la Peña

Fix the system dbus activation file location.

252. By Manuel de la Peña

Update the name of the package to match the names of the .so

253. By Manuel de la Peña

Move the location of the pkconfig files.

254. By Manuel de la Peña

Add pkgconfig to the .pc paths.

255. By Manuel de la Peña

Do not configure in the wrong dir and jsut move to libexdir on install time.

256. By Manuel de la Peña

Fix broken install path.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'docs/com.canonical.applications.download.xml'
--- docs/com.canonical.applications.download.xml 2014-02-11 15:35:52 +0000
+++ docs/com.canonical.applications.download.xml 2014-04-15 13:56:56 +0000
@@ -22,6 +22,10 @@
22 <arg name="speed" type="t" direction="out"/>22 <arg name="speed" type="t" direction="out"/>
23 </method>23 </method>
2424
25 <method name="setDestinationDir">
26 <arg name="path" type="s" direction="in"/>
27 </method>
28
25 <method name="allowGSMDownload">29 <method name="allowGSMDownload">
26 <arg name="allowed" type="b" direction="in"/>30 <arg name="allowed" type="b" direction="in"/>
27 </method>31 </method>
2832
=== modified file 'src/downloads/client/CMakeLists.txt'
--- src/downloads/client/CMakeLists.txt 2014-04-15 13:56:55 +0000
+++ src/downloads/client/CMakeLists.txt 2014-04-15 13:56:56 +0000
@@ -3,6 +3,7 @@
3set(SOURCES3set(SOURCES
4 ubuntu/download_manager/download_impl.cpp4 ubuntu/download_manager/download_impl.cpp
5 ubuntu/download_manager/download_interface.cpp5 ubuntu/download_manager/download_interface.cpp
6 ubuntu/download_manager/downloads_list_impl.cpp
6 ubuntu/download_manager/download_pendingcall_watcher.cpp7 ubuntu/download_manager/download_pendingcall_watcher.cpp
7 ubuntu/download_manager/error.cpp8 ubuntu/download_manager/error.cpp
8 ubuntu/download_manager/group_download.cpp9 ubuntu/download_manager/group_download.cpp
@@ -15,6 +16,7 @@
1516
16set(PUBLIC_HEADERS17set(PUBLIC_HEADERS
17 ubuntu/download_manager/download.h18 ubuntu/download_manager/download.h
19 ubuntu/download_manager/downloads_list.h
18 ubuntu/download_manager/error.h20 ubuntu/download_manager/error.h
19 ubuntu/download_manager/group_download.h21 ubuntu/download_manager/group_download.h
20 ubuntu/download_manager/manager.h22 ubuntu/download_manager/manager.h
@@ -23,6 +25,7 @@
23set(PRIVATE_HEADERS25set(PRIVATE_HEADERS
24 ubuntu/download_manager/download_impl.h26 ubuntu/download_manager/download_impl.h
25 ubuntu/download_manager/download_interface.h27 ubuntu/download_manager/download_interface.h
28 ubuntu/download_manager/downloads_list_impl.h
26 ubuntu/download_manager/download_pendingcall_watcher.h29 ubuntu/download_manager/download_pendingcall_watcher.h
27 ubuntu/download_manager/manager_impl.h30 ubuntu/download_manager/manager_impl.h
28 ubuntu/download_manager/manager_interface.h31 ubuntu/download_manager/manager_interface.h
2932
=== added file 'src/downloads/client/ubuntu-download-manager-client.pro.THIS'
--- src/downloads/client/ubuntu-download-manager-client.pro.THIS 1970-01-01 00:00:00 +0000
+++ src/downloads/client/ubuntu-download-manager-client.pro.THIS 2014-04-15 13:56:56 +0000
@@ -0,0 +1,59 @@
1include(../common-project-config.pri)
2include(../common-vars.pri)
3
4QT += dbus
5QT -= gui
6
7TARGET = ubuntu-download-manager-client
8TEMPLATE = lib
9
10DEFINES += UBUNTUDOWNLOADMANAGERCLIENT_LIBRARY
11
12SOURCES += ubuntu/download_manager/manager.cpp \
13 ubuntu/download_manager/manager_impl.cpp \
14 ubuntu/download_manager/download_interface.cpp \
15 ubuntu/download_manager/manager_interface.cpp \
16 ubuntu/download_manager/download_impl.cpp \
17 ubuntu/download_manager/downloads_list_impl.cpp \
18 ubuntu/download_manager/group_download.cpp \
19 ubuntu/download_manager/manager_pendingcall_watcher.cpp \
20 ubuntu/download_manager/error.cpp \
21 ubuntu/download_manager/pending_call_watcher.cpp \
22 ubuntu/download_manager/download_pendingcall_watcher.cpp
23
24public_headers = \
25 ubuntu/download_manager/manager.h \
26 ubuntu/download_manager/download.h \
27 ubuntu/download_manager/downloads_list.h \
28 ubuntu/download_manager/group_download.h \
29 ubuntu/download_manager/error.h
30
31private_headers = \
32 ubuntu/download_manager/manager_impl.h \
33 ubuntu/download_manager/download_impl.h \
34 ubuntu/download_manager/downloads_list_impl.h \
35 ubuntu/download_manager/download_interface.h \
36 ubuntu/download_manager/manager_interface.h \
37 ubuntu/download_manager/manager_pendingcall_watcher.h \
38 ubuntu/download_manager/pending_call_watcher.h \
39 ubuntu/download_manager/download_pendingcall_watcher.h
40
41HEADERS +=\
42 $$public_headers \
43 $$private_headers
44
45OTHER_FILES += \
46 ubuntu-download-manager-client.pc.in
47
48headers.files = $$public_headers
49
50include(../common-installs-config.pri)
51
52pkgconfig.files = ubuntu-download-manager-client.pc
53include(../common-pkgconfig.pri)
54INSTALLS += pkgconfig
55
56LIBS += -L$$OUT_PWD/../ubuntu-download-manager-common/ -lubuntu-download-manager-common
57
58INCLUDEPATH += $$PWD/../ubuntu-download-manager-common
59DEPENDPATH += $$PWD/../ubuntu-download-manager-common
060
=== modified file 'src/downloads/client/ubuntu/download_manager/download.h'
--- src/downloads/client/ubuntu/download_manager/download.h 2014-04-15 13:56:55 +0000
+++ src/downloads/client/ubuntu/download_manager/download.h 2014-04-15 13:56:56 +0000
@@ -114,6 +114,15 @@
114 virtual bool isMobileDownloadAllowed() = 0;114 virtual bool isMobileDownloadAllowed() = 0;
115115
116 /*!116 /*!
117 \fn void setDestinationDir(const QString& path);
118
119 Notifies the download manager that the local path of the download
120 must be a different one. This call can only be performed if the
121 download was not started else it will result in an error.
122 */
123 virtual void setDestinationDir(const QString& path) = 0;
124
125 /*!
117 \fn void setThrottle(qulonglong speed)126 \fn void setThrottle(qulonglong speed)
118127
119 Notifies the download manager that the download represented by this128 Notifies the download manager that the download represented by this
120129
=== modified file 'src/downloads/client/ubuntu/download_manager/download_impl.cpp'
--- src/downloads/client/ubuntu/download_manager/download_impl.cpp 2014-04-15 13:56:55 +0000
+++ src/downloads/client/ubuntu/download_manager/download_impl.cpp 2014-04-15 13:56:56 +0000
@@ -96,7 +96,7 @@
96DownloadImpl::start() {96DownloadImpl::start() {
97 QDBusPendingCall call =97 QDBusPendingCall call =
98 _dbusInterface->start();98 _dbusInterface->start();
99 auto watcher = new DownloadPendingCallWatcher(_conn, _servicePath,99 auto watcher = new DownloadPCW(_conn, _servicePath,
100 call, this);100 call, this);
101 Q_UNUSED(watcher);101 Q_UNUSED(watcher);
102}102}
@@ -105,7 +105,7 @@
105DownloadImpl::pause() {105DownloadImpl::pause() {
106 QDBusPendingCall call =106 QDBusPendingCall call =
107 _dbusInterface->pause();107 _dbusInterface->pause();
108 auto watcher = new DownloadPendingCallWatcher(_conn, _servicePath,108 auto watcher = new DownloadPCW(_conn, _servicePath,
109 call, this);109 call, this);
110 Q_UNUSED(watcher);110 Q_UNUSED(watcher);
111}111}
@@ -114,7 +114,7 @@
114DownloadImpl::resume() {114DownloadImpl::resume() {
115 QDBusPendingCall call =115 QDBusPendingCall call =
116 _dbusInterface->resume();116 _dbusInterface->resume();
117 auto watcher = new DownloadPendingCallWatcher(_conn, _servicePath,117 auto watcher = new DownloadPCW(_conn, _servicePath,
118 call, this);118 call, this);
119 Q_UNUSED(watcher);119 Q_UNUSED(watcher);
120}120}
@@ -123,7 +123,7 @@
123DownloadImpl::cancel() {123DownloadImpl::cancel() {
124 QDBusPendingCall call =124 QDBusPendingCall call =
125 _dbusInterface->cancel();125 _dbusInterface->cancel();
126 auto watcher = new DownloadPendingCallWatcher(_conn, _servicePath,126 auto watcher = new DownloadPCW(_conn, _servicePath,
127 call, this);127 call, this);
128 Q_UNUSED(watcher);128 Q_UNUSED(watcher);
129}129}
@@ -155,6 +155,17 @@
155}155}
156156
157void157void
158DownloadImpl::setDestinationDir(const QString& path) {
159 QDBusPendingReply<> reply =
160 _dbusInterface->setDestinationDir(path);
161 // block, the call should be fast enough
162 reply.waitForFinished();
163 if (reply.isError()) {
164 setLastError(reply.error());
165 }
166}
167
168void
158DownloadImpl::setThrottle(qulonglong speed) {169DownloadImpl::setThrottle(qulonglong speed) {
159 QDBusPendingReply<> reply =170 QDBusPendingReply<> reply =
160 _dbusInterface->setThrottle(speed);171 _dbusInterface->setThrottle(speed);
161172
=== modified file 'src/downloads/client/ubuntu/download_manager/download_impl.h'
--- src/downloads/client/ubuntu/download_manager/download_impl.h 2014-04-15 13:56:55 +0000
+++ src/downloads/client/ubuntu/download_manager/download_impl.h 2014-04-15 13:56:56 +0000
@@ -43,8 +43,11 @@
43 Q_OBJECT43 Q_OBJECT
4444
45 // allow the manager to create downloads45 // allow the manager to create downloads
46 friend class DownloadPendingCallWatcher;46 friend class ManagerImpl;
47 friend class DownloadManagerPendingCallWatcher;47 friend class DownloadPCW;
48 friend class MetadataDownloadsListManagerPCW;
49 friend class DownloadsListManagerPCW;
50 friend class DownloadManagerPCW;
4851
49 public:52 public:
50 virtual ~DownloadImpl();53 virtual ~DownloadImpl();
@@ -57,6 +60,7 @@
57 void allowMobileDownload(bool allowed);60 void allowMobileDownload(bool allowed);
58 bool isMobileDownloadAllowed();61 bool isMobileDownloadAllowed();
5962
63 void setDestinationDir(const QString& path);
60 void setThrottle(qulonglong speed);64 void setThrottle(qulonglong speed);
61 qulonglong throttle();65 qulonglong throttle();
6266
6367
=== modified file 'src/downloads/client/ubuntu/download_manager/download_interface.h'
--- src/downloads/client/ubuntu/download_manager/download_interface.h 2014-02-11 19:57:39 +0000
+++ src/downloads/client/ubuntu/download_manager/download_interface.h 2014-04-15 13:56:56 +0000
@@ -80,6 +80,13 @@
80 return asyncCallWithArgumentList(QLatin1String("resume"), argumentList);80 return asyncCallWithArgumentList(QLatin1String("resume"), argumentList);
81 }81 }
8282
83 inline QDBusPendingReply<> setDestinationDir(const QString &path)
84 {
85 QList<QVariant> argumentList;
86 argumentList << QVariant::fromValue(path);
87 return asyncCallWithArgumentList(QLatin1String("setDestinationDir"), argumentList);
88 }
89
83 inline QDBusPendingReply<> setThrottle(qulonglong speed)90 inline QDBusPendingReply<> setThrottle(qulonglong speed)
84 {91 {
85 QList<QVariant> argumentList;92 QList<QVariant> argumentList;
8693
=== modified file 'src/downloads/client/ubuntu/download_manager/download_pendingcall_watcher.cpp'
--- src/downloads/client/ubuntu/download_manager/download_pendingcall_watcher.cpp 2014-04-15 13:56:55 +0000
+++ src/downloads/client/ubuntu/download_manager/download_pendingcall_watcher.cpp 2014-04-15 13:56:56 +0000
@@ -26,19 +26,19 @@
2626
27namespace DownloadManager {27namespace DownloadManager {
2828
29DownloadPendingCallWatcher::DownloadPendingCallWatcher(29DownloadPCW::DownloadPCW(
30 const QDBusConnection& conn,30 const QDBusConnection& conn,
31 const QString& servicePath,31 const QString& servicePath,
32 const QDBusPendingCall& call,32 const QDBusPendingCall& call,
33 Download* parent)33 Download* parent)
34 : PendingCallWatcher(conn, servicePath, call, parent) {34 : PendingCallWatcher(conn, servicePath, call, parent) {
35 CHECK(connect(this, &DownloadPendingCallWatcher::finished,35 CHECK(connect(this, &DownloadPCW::finished,
36 this, &DownloadPendingCallWatcher::onFinished))36 this, &DownloadPCW::onFinished))
37 << "Could not connect to signal";37 << "Could not connect to signal";
38}38}
3939
40void40void
41DownloadPendingCallWatcher::onFinished(QDBusPendingCallWatcher* watcher) {41DownloadPCW::onFinished(QDBusPendingCallWatcher* watcher) {
42 auto down = qobject_cast<Download*>(parent());42 auto down = qobject_cast<Download*>(parent());
43 QDBusPendingReply<> reply = *watcher;43 QDBusPendingReply<> reply = *watcher;
44 if (reply.isError()) {44 if (reply.isError()) {
4545
=== modified file 'src/downloads/client/ubuntu/download_manager/download_pendingcall_watcher.h'
--- src/downloads/client/ubuntu/download_manager/download_pendingcall_watcher.h 2014-01-22 16:26:29 +0000
+++ src/downloads/client/ubuntu/download_manager/download_pendingcall_watcher.h 2014-04-15 13:56:56 +0000
@@ -27,11 +27,11 @@
2727
28namespace DownloadManager {28namespace DownloadManager {
2929
30class DownloadPendingCallWatcher : public PendingCallWatcher {30class DownloadPCW : public PendingCallWatcher {
31 Q_OBJECT31 Q_OBJECT
3232
33 public:33 public:
34 DownloadPendingCallWatcher(const QDBusConnection& conn,34 DownloadPCW(const QDBusConnection& conn,
35 const QString& servicePath,35 const QString& servicePath,
36 const QDBusPendingCall& call,36 const QDBusPendingCall& call,
37 Download* parent = 0);37 Download* parent = 0);
3838
=== added file 'src/downloads/client/ubuntu/download_manager/downloads_list.h'
--- src/downloads/client/ubuntu/download_manager/downloads_list.h 1970-01-01 00:00:00 +0000
+++ src/downloads/client/ubuntu/download_manager/downloads_list.h 2014-04-15 13:56:56 +0000
@@ -0,0 +1,50 @@
1/*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of version 3 of the GNU Lesser General Public
6 * License as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17 */
18
19#ifndef UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_LIST_H
20#define UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_LIST_H
21
22#include <QList>
23#include <QObject>
24#include <QSharedPointer>
25#include <ubuntu/download_manager/common.h>
26
27namespace Ubuntu {
28
29namespace DownloadManager {
30
31class Error;
32class Download;
33
34class DOWNLOAD_MANAGER_EXPORT DownloadsList : public QObject {
35 Q_OBJECT
36
37 public:
38 explicit DownloadsList(QObject* parent = 0)
39 : QObject(parent) {}
40
41 virtual QList<QSharedPointer<Download> > downloads() const = 0;
42 virtual bool isError() const = 0;
43 virtual Error* error() const = 0;
44};
45
46} // Ubuntu
47
48} // DownloadManager
49
50#endif // UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_LIST_H
051
=== added file 'src/downloads/client/ubuntu/download_manager/downloads_list_impl.cpp'
--- src/downloads/client/ubuntu/download_manager/downloads_list_impl.cpp 1970-01-01 00:00:00 +0000
+++ src/downloads/client/ubuntu/download_manager/downloads_list_impl.cpp 2014-04-15 13:56:56 +0000
@@ -0,0 +1,64 @@
1/*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of version 3 of the GNU Lesser General Public
6 * License as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17 */
18
19#include "download.h"
20#include "error.h"
21#include "downloads_list_impl.h"
22
23namespace Ubuntu {
24
25namespace DownloadManager {
26
27DownloadsListImpl::DownloadsListImpl(QObject* parent)
28 : DownloadsList(parent) {
29}
30
31DownloadsListImpl::DownloadsListImpl(
32 const QList<QSharedPointer<Download> > downs,
33 QObject* parent)
34 : DownloadsList(parent),
35 _downs(downs){
36}
37
38DownloadsListImpl::DownloadsListImpl(Error* err, QObject* parent)
39 : DownloadsList(parent),
40 _lastError(err) {
41}
42
43DownloadsListImpl::~DownloadsListImpl() {
44 delete _lastError;
45}
46
47QList<QSharedPointer<Download> >
48DownloadsListImpl::downloads() const {
49 return _downs;
50}
51
52bool
53DownloadsListImpl::isError() const {
54 return _lastError != nullptr;
55}
56
57Error*
58DownloadsListImpl::error() const {
59 return _lastError;
60}
61
62} // Ubuntu
63
64} // DownloadManager
065
=== added file 'src/downloads/client/ubuntu/download_manager/downloads_list_impl.h'
--- src/downloads/client/ubuntu/download_manager/downloads_list_impl.h 1970-01-01 00:00:00 +0000
+++ src/downloads/client/ubuntu/download_manager/downloads_list_impl.h 2014-04-15 13:56:56 +0000
@@ -0,0 +1,53 @@
1/*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of version 3 of the GNU Lesser General Public
6 * License as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17 */
18
19#ifndef UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_LIST_IMPL_H
20#define UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_LIST_IMPL_H
21
22#include "downloads_list.h"
23
24namespace Ubuntu {
25
26namespace DownloadManager {
27
28class Error;
29class Download;
30
31class DOWNLOAD_MANAGER_EXPORT DownloadsListImpl : public DownloadsList {
32 Q_OBJECT
33
34 public:
35 DownloadsListImpl(QObject* parent = 0);
36 DownloadsListImpl(const QList<QSharedPointer<Download >> downs, QObject* parent = 0);
37 DownloadsListImpl(Error* err, QObject* parent = 0);
38 virtual ~DownloadsListImpl();
39
40 virtual QList<QSharedPointer<Download> > downloads() const;
41 virtual bool isError() const;
42 virtual Error* error() const;
43
44 private:
45 QList<QSharedPointer<Download> > _downs;
46 Error* _lastError = nullptr;
47};
48
49} // Ubuntu
50
51} // DownloadManager
52
53#endif // UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_LIST_IMPL_H
054
=== modified file 'src/downloads/client/ubuntu/download_manager/error.h'
--- src/downloads/client/ubuntu/download_manager/error.h 2014-04-15 13:56:55 +0000
+++ src/downloads/client/ubuntu/download_manager/error.h 2014-04-15 13:56:56 +0000
@@ -120,9 +120,11 @@
120120
121 friend class ManagerImpl;121 friend class ManagerImpl;
122 friend class DownloadImpl;122 friend class DownloadImpl;
123 friend class DownloadManagerPendingCallWatcher;123 friend class DownloadManagerPCW;
124 friend class DownloadPendingCallWatcher;124 friend class DownloadsListManagerPCW;
125 friend class GroupManagerPendingCallWatcher;125 friend class MetadataDownloadsListManagerPCW;
126 friend class DownloadPCW;
127 friend class GroupManagerPCW;
126128
127 /*!129 /*!
128 Disposes of this error and frees any resources associated with it.130 Disposes of this error and frees any resources associated with it.
129131
=== modified file 'src/downloads/client/ubuntu/download_manager/group_download.h'
--- src/downloads/client/ubuntu/download_manager/group_download.h 2014-04-15 13:56:55 +0000
+++ src/downloads/client/ubuntu/download_manager/group_download.h 2014-04-15 13:56:56 +0000
@@ -36,7 +36,7 @@
3636
37 // allow the manager to create downloads37 // allow the manager to create downloads
38 friend class ManagerPrivate;38 friend class ManagerPrivate;
39 friend class GroupManagerPendingCallWatcher;39 friend class GroupManagerPCW;
4040
41 public:41 public:
4242
4343
=== modified file 'src/downloads/client/ubuntu/download_manager/manager.h'
--- src/downloads/client/ubuntu/download_manager/manager.h 2014-04-15 13:56:55 +0000
+++ src/downloads/client/ubuntu/download_manager/manager.h 2014-04-15 13:56:56 +0000
@@ -20,7 +20,6 @@
20#define UBUNTU_DOWNLOADMANAGER_CLIENT_MANAGER_H20#define UBUNTU_DOWNLOADMANAGER_CLIENT_MANAGER_H
2121
22#include <functional>22#include <functional>
23#include <QList>
24#include <QObject>23#include <QObject>
25#include <ubuntu/download_manager/metatypes.h>24#include <ubuntu/download_manager/metatypes.h>
26#include <ubuntu/download_manager/common.h>25#include <ubuntu/download_manager/common.h>
@@ -33,6 +32,7 @@
33namespace DownloadManager {32namespace DownloadManager {
3433
35class Download;34class Download;
35class DownloadsList;
36class Error;36class Error;
37class GroupDownload;37class GroupDownload;
3838
@@ -43,6 +43,18 @@
43typedef std::function<void(Download*)> DownloadCb;43typedef std::function<void(Download*)> DownloadCb;
4444
45/*!45/*!
46 Callback to be executed that takes a download list object created by
47 the manager.
48*/
49typedef std::function<void(DownloadsList*)> DownloadsListCb;
50
51/*!
52 Callback to be executed that takes a download list object created by
53 the manager for a given metadata value.
54*/
55typedef std::function<void(const QString&, const QString&, DownloadsList*)> MetadataDownloadsListCb;
56
57/*!
46 Callback to be executed that takes a group download object created by58 Callback to be executed that takes a group download object created by
47 the manager.59 the manager.
48*/60*/
@@ -74,6 +86,15 @@
74 : QObject(parent) {}86 : QObject(parent) {}
7587
76 /*!88 /*!
89 \fn void getDownloadForId(const QString& id);
90
91 Returns a download object for the download with the given id. The
92 id most be valid else the returned download will be in an unknown
93 state meaning that most of the download operations will fail.
94 */
95 virtual Download* getDownloadForId(const QString& id) = 0;
96
97 /*!
77 \fn void createDownload(DownloadStruct downStruct)98 \fn void createDownload(DownloadStruct downStruct)
7899
79 Creates a new download using the data found in the structure.100 Creates a new download using the data found in the structure.
@@ -144,10 +165,59 @@
144 StringMap headers,165 StringMap headers,
145 GroupCb cb,166 GroupCb cb,
146 GroupCb errCb) = 0;167 GroupCb errCb) = 0;
168 /*!
169 \fn void getAllDownloads()
170
171 Returns all the downloads in the download manager that can be accessed
172 by the calling client. If the client is not confined all downloads are
173 returned, on the other hand if the client is confined the result will
174 be only those downloads created by the client. The result of the method
175 is returned via the downloadsFound signal.
176 */
177 virtual void getAllDownloads() = 0;
178
179 /*!
180 \fn void getAllDownloads(DownloadsListCb cb, DownloadsListCb errCb)
181
182 Returns all the downloads in the download manager that can be accessed
183 by the calling client. If the client is not confined all downloads are
184 returned, on the other hand if the client is confined the result will
185 be only those downloads created by the client. If the method is a
186 success the \a cb is executed else \a errCb is executed.
187 */
188 virtual void getAllDownloads(DownloadsListCb cb,
189 DownloadsListCb errCb) = 0;
190 /*!
191 \fn void getAllDownloadsWithMetadata(const QString &name, const QString &value)
192
193 Returns all the downloads in the download manager that can be accessed
194 by the calling client. If the client is not confined all downloads are
195 returned, on the other hand if the client is confined the result will
196 be only those downloads created by the client. The result of the method
197 is returned via the downloadsWithMetadataFound signal.
198
199 */
200 virtual void getAllDownloadsWithMetadata(const QString &name,
201 const QString &value) = 0;
202 /*!
203 \fn void getAllDownloadsWithMetadata(const QString &name,
204 const QString &value,
205 MetadataDownloadsListCb cb,
206 MetadataDownloadsListCb errCb)
207
208 Returns all the downloads in the download manager that can be accessed
209 by the calling client. If the client is not confined all downloads are
210 returned, on the other hand if the client is confined the result will
211 be only those downloads created by the client. If the method is a
212 success the \a cb is executed else \a errCb is executed.
213 */
214 virtual void getAllDownloadsWithMetadata(const QString &name,
215 const QString &value,
216 MetadataDownloadsListCb cb,
217 MetadataDownloadsListCb errCb) = 0;
147218
148 /*!219 /*!
149 \fn bool isError() const220 \fn bool isError() const
150
151 Returns if the manager received an error during the execution221 Returns if the manager received an error during the execution
152 of a command.222 of a command.
153 */223 */
@@ -249,6 +319,10 @@
249 download manager.319 download manager.
250 */320 */
251 void downloadCreated(Download* down);321 void downloadCreated(Download* down);
322 void downloadsFound(DownloadsList* downloads);
323 void downloadsWithMetadataFound(const QString& name,
324 const QString& value,
325 DownloadsList* downloads);
252326
253 /*!327 /*!
254 \fn void groupCreated(GroupDownload* down)328 \fn void groupCreated(GroupDownload* down)
255329
=== modified file 'src/downloads/client/ubuntu/download_manager/manager_impl.cpp'
--- src/downloads/client/ubuntu/download_manager/manager_impl.cpp 2014-04-15 13:56:55 +0000
+++ src/downloads/client/ubuntu/download_manager/manager_impl.cpp 2014-04-15 13:56:56 +0000
@@ -18,6 +18,8 @@
1818
19#include <QDebug>19#include <QDebug>
20#include <glog/logging.h>20#include <glog/logging.h>
21#include "download_impl.h"
22#include "downloads_list.h"
21#include "manager_impl.h"23#include "manager_impl.h"
2224
23namespace {25namespace {
@@ -65,6 +67,7 @@
65 qRegisterMetaType<NetworkError*>("NetworkError*");67 qRegisterMetaType<NetworkError*>("NetworkError*");
66 qRegisterMetaType<AuthError*>("AuthError*");68 qRegisterMetaType<AuthError*>("AuthError*");
67 qRegisterMetaType<ProcessError*>("ProcessError*");69 qRegisterMetaType<ProcessError*>("ProcessError*");
70 qRegisterMetaType<DownloadsList*>("DownloadsList*");
68 qDBusRegisterMetaType<StringMap>();71 qDBusRegisterMetaType<StringMap>();
69 qDBusRegisterMetaType<DownloadStruct>();72 qDBusRegisterMetaType<DownloadStruct>();
70 qDBusRegisterMetaType<GroupDownloadStruct>();73 qDBusRegisterMetaType<GroupDownloadStruct>();
@@ -75,17 +78,16 @@
75 qDBusRegisterMetaType<ProcessErrorStruct>();78 qDBusRegisterMetaType<ProcessErrorStruct>();
76}79}
7780
81Download*
82ManagerImpl::getDownloadForId(const QString& id) {
83 auto down = new DownloadImpl(_conn, _servicePath, QDBusObjectPath(id));
84 return down;
85}
86
78void87void
79ManagerImpl::createDownload(DownloadStruct downStruct) {88ManagerImpl::createDownload(DownloadStruct downStruct) {
80 QDBusPendingCall call =
81 _dbusInterface->createDownload(downStruct);
82 DownloadCb cb = [](Download*) {};89 DownloadCb cb = [](Download*) {};
8390 createDownload(downStruct, cb, cb);
84 auto watcher = new DownloadManagerPendingCallWatcher(_conn,
85 _servicePath, call, cb, cb, this);
86 CHECK(connect(watcher,
87 &DownloadManagerPendingCallWatcher::callbackExecuted,
88 this, &ManagerImpl::onWatcherDone)) << "Could not connect to signal";
89}91}
9092
91void93void
@@ -94,10 +96,9 @@
94 DownloadCb errCb) {96 DownloadCb errCb) {
95 QDBusPendingCall call =97 QDBusPendingCall call =
96 _dbusInterface->createDownload(downStruct);98 _dbusInterface->createDownload(downStruct);
97 auto watcher = new DownloadManagerPendingCallWatcher(_conn,99 auto watcher = new DownloadManagerPCW(_conn,
98 _servicePath, call, cb, errCb, this);100 _servicePath, call, cb, errCb, this);
99 CHECK(connect(watcher,101 CHECK(connect(watcher, &DownloadManagerPCW::callbackExecuted,
100 &DownloadManagerPendingCallWatcher::callbackExecuted,
101 this, &ManagerImpl::onWatcherDone)) << "Could not connect to signal";102 this, &ManagerImpl::onWatcherDone)) << "Could not connect to signal";
102}103}
103104
@@ -107,16 +108,8 @@
107 bool allowed3G,108 bool allowed3G,
108 const QVariantMap& metadata,109 const QVariantMap& metadata,
109 StringMap headers) {110 StringMap headers) {
110 QDBusPendingCall call =
111 _dbusInterface->createDownloadGroup(downs,
112 algorithm, allowed3G, metadata, headers);
113
114 GroupCb cb = [](GroupDownload*) {};111 GroupCb cb = [](GroupDownload*) {};
115112 createDownload(downs, algorithm, allowed3G, metadata, headers, cb, cb);
116 auto watcher = new GroupManagerPendingCallWatcher(_conn, _servicePath,
117 call, cb, cb, this);
118 CHECK(connect(watcher, &GroupManagerPendingCallWatcher::callbackExecuted,
119 this, &ManagerImpl::onWatcherDone)) << "Could not connect to signal";
120}113}
121114
122void115void
@@ -130,9 +123,45 @@
130 QDBusPendingCall call =123 QDBusPendingCall call =
131 _dbusInterface->createDownloadGroup(downs,124 _dbusInterface->createDownloadGroup(downs,
132 algorithm, allowed3G, metadata, headers);125 algorithm, allowed3G, metadata, headers);
133 auto watcher = new GroupManagerPendingCallWatcher(_conn, _servicePath,126 auto watcher = new GroupManagerPCW(_conn, _servicePath,
134 call, cb, errCb, this);127 call, cb, errCb, this);
135 CHECK(connect(watcher, &GroupManagerPendingCallWatcher::callbackExecuted,128 CHECK(connect(watcher, &GroupManagerPCW::callbackExecuted,
129 this, &ManagerImpl::onWatcherDone)) << "Could not connect to signal";
130}
131
132void
133ManagerImpl::getAllDownloads() {
134 DownloadsListCb cb = [](DownloadsList*){};
135 getAllDownloads(cb, cb);
136}
137
138void
139ManagerImpl::getAllDownloads(DownloadsListCb cb, DownloadsListCb errCb) {
140 QDBusPendingCall call = _dbusInterface->getAllDownloads();
141 auto watcher = new DownloadsListManagerPCW(
142 _conn, _servicePath, call, cb, errCb, this);
143 CHECK(connect(watcher, &GroupManagerPCW::callbackExecuted,
144 this, &ManagerImpl::onWatcherDone)) << "Could not connect to signal";
145}
146
147void
148ManagerImpl::getAllDownloadsWithMetadata(const QString &name,
149 const QString &value) {
150 MetadataDownloadsListCb cb =
151 [](const QString&, const QString&, DownloadsList*){};
152 getAllDownloadsWithMetadata(name, value, cb, cb);
153}
154
155void
156ManagerImpl::getAllDownloadsWithMetadata(const QString &name,
157 const QString &value,
158 MetadataDownloadsListCb cb,
159 MetadataDownloadsListCb errCb) {
160 QDBusPendingCall call = _dbusInterface->getAllDownloadsWithMetadata(
161 name, value);
162 auto watcher = new MetadataDownloadsListManagerPCW(
163 _conn, _servicePath, call, name, value, cb, errCb, this);
164 CHECK(connect(watcher, &GroupManagerPCW::callbackExecuted,
136 this, &ManagerImpl::onWatcherDone)) << "Could not connect to signal";165 this, &ManagerImpl::onWatcherDone)) << "Could not connect to signal";
137}166}
138167
139168
=== modified file 'src/downloads/client/ubuntu/download_manager/manager_impl.h'
--- src/downloads/client/ubuntu/download_manager/manager_impl.h 2014-04-15 13:56:55 +0000
+++ src/downloads/client/ubuntu/download_manager/manager_impl.h 2014-04-15 13:56:56 +0000
@@ -46,11 +46,12 @@
4646
47 // allow watchers to emit the signals47 // allow watchers to emit the signals
48 friend class Manager;48 friend class Manager;
49 friend class DownloadManagerPendingCallWatcher;49 friend class DownloadManagerPCW;
50 friend class GroupManagerPendingCallWatcher;50 friend class GroupManagerPCW;
5151
52 public:52 public:
53 virtual ~ManagerImpl();53 virtual ~ManagerImpl();
54 virtual Download* getDownloadForId(const QString& id);
54 virtual void createDownload(DownloadStruct downStruct);55 virtual void createDownload(DownloadStruct downStruct);
55 virtual void createDownload(DownloadStruct downStruct,56 virtual void createDownload(DownloadStruct downStruct,
56 DownloadCb cb,57 DownloadCb cb,
@@ -67,6 +68,15 @@
67 StringMap headers,68 StringMap headers,
68 GroupCb cb,69 GroupCb cb,
69 GroupCb errCb);70 GroupCb errCb);
71 virtual void getAllDownloads();
72 virtual void getAllDownloads(DownloadsListCb cb,
73 DownloadsListCb errCb);
74 virtual void getAllDownloadsWithMetadata(const QString &name,
75 const QString &value);
76 virtual void getAllDownloadsWithMetadata(const QString &name,
77 const QString &value,
78 MetadataDownloadsListCb cb,
79 MetadataDownloadsListCb errCb);
7080
71 bool isError() const;81 bool isError() const;
72 Error* lastError() const;82 Error* lastError() const;
7383
=== modified file 'src/downloads/client/ubuntu/download_manager/manager_pendingcall_watcher.cpp'
--- src/downloads/client/ubuntu/download_manager/manager_pendingcall_watcher.cpp 2014-04-15 13:56:55 +0000
+++ src/downloads/client/ubuntu/download_manager/manager_pendingcall_watcher.cpp 2014-04-15 13:56:56 +0000
@@ -21,6 +21,7 @@
21#include <QDBusObjectPath>21#include <QDBusObjectPath>
22#include <glog/logging.h>22#include <glog/logging.h>
23#include "download_impl.h"23#include "download_impl.h"
24#include "downloads_list_impl.h"
24#include "error.h"25#include "error.h"
25#include "group_download.h"26#include "group_download.h"
26#include "manager.h"27#include "manager.h"
@@ -30,28 +31,27 @@
3031
31namespace DownloadManager {32namespace DownloadManager {
3233
33DownloadManagerPendingCallWatcher::DownloadManagerPendingCallWatcher(34DownloadManagerPCW::DownloadManagerPCW(const QDBusConnection& conn,
34 const QDBusConnection& conn,35 const QString& servicePath,
35 const QString& servicePath,36 const QDBusPendingCall& call,
36 const QDBusPendingCall& call,37 DownloadCb cb,
37 DownloadCb cb,38 DownloadCb errCb,
38 DownloadCb errCb,39 QObject* parent)
39 QObject* parent)
40 : PendingCallWatcher(conn, servicePath, call, parent),40 : PendingCallWatcher(conn, servicePath, call, parent),
41 _cb(cb),41 _cb(cb),
42 _errCb(errCb) {42 _errCb(errCb) {
43 CHECK(connect(this, &QDBusPendingCallWatcher::finished,43 CHECK(connect(this, &QDBusPendingCallWatcher::finished,
44 this, &DownloadManagerPendingCallWatcher::onFinished))44 this, &DownloadManagerPCW::onFinished))
45 << "Could not connect to signal";45 << "Could not connect to signal";
46}46}
4747
48void48void
49DownloadManagerPendingCallWatcher::onFinished(QDBusPendingCallWatcher* watcher) {49DownloadManagerPCW::onFinished(QDBusPendingCallWatcher* watcher) {
50 QDBusPendingReply<QDBusObjectPath> reply = *watcher;50 QDBusPendingReply<QDBusObjectPath> reply = *watcher;
51 auto man = static_cast<Manager*>(parent());51 auto man = static_cast<Manager*>(parent());
52 if (reply.isError()) {52 if (reply.isError()) {
53 qDebug() << "ERROR" << reply.error() << reply.error().type();53 qDebug() << "ERROR" << reply.error() << reply.error().type();
54 // creater error and deal with it54 // create error and deal with it
55 auto err = new DBusError(reply.error());55 auto err = new DBusError(reply.error());
56 auto down = new DownloadImpl(_conn, err);56 auto down = new DownloadImpl(_conn, err);
57 _errCb(down);57 _errCb(down);
@@ -67,24 +67,115 @@
67 watcher->deleteLater();67 watcher->deleteLater();
68}68}
6969
7070DownloadsListManagerPCW::DownloadsListManagerPCW(const QDBusConnection& conn,
71GroupManagerPendingCallWatcher::GroupManagerPendingCallWatcher(71 const QString& servicePath,
72 const QDBusConnection& conn,72 const QDBusPendingCall& call,
73 const QString& servicePath,73 DownloadsListCb cb,
74 const QDBusPendingCall& call,74 DownloadsListCb errCb,
75 GroupCb cb,75 QObject* parent)
76 GroupCb errCb,76 : PendingCallWatcher(conn, servicePath, call, parent),
77 QObject* parent)77 _cb(cb),
78 _errCb(errCb) {
79 connect(this, &QDBusPendingCallWatcher::finished,
80 this, &DownloadsListManagerPCW::onFinished);
81}
82
83void
84DownloadsListManagerPCW::onFinished(QDBusPendingCallWatcher* watcher) {
85 QDBusPendingReply<QList<QDBusObjectPath> > reply = *watcher;
86 DownloadsListImpl* list;
87 auto man = static_cast<Manager*>(parent());
88 if (reply.isError()) {
89 qDebug() << "ERROR" << reply.error() << reply.error().type();
90 // create error and deal with it
91 auto err = new DBusError(reply.error());
92 list = new DownloadsListImpl(err);
93 _errCb(list);
94 emit man->downloadsFound(list);
95 } else {
96 qDebug() << "Success!";
97 auto paths = reply.value();
98 QList<QSharedPointer<Download> > downloads;
99 list = new DownloadsListImpl();
100 foreach(const QDBusObjectPath& path, paths) {
101 QSharedPointer<Download> down =
102 QSharedPointer<Download>(new DownloadImpl(_conn,
103 _servicePath, path));
104 downloads.append(down);
105 }
106 list = new DownloadsListImpl(downloads);
107 emit man->downloadsFound(list);
108 _cb(list);
109 }
110 emit callbackExecuted();
111 watcher->deleteLater();
112}
113
114MetadataDownloadsListManagerPCW::MetadataDownloadsListManagerPCW(
115 const QDBusConnection& conn,
116 const QString& servicePath,
117 const QDBusPendingCall& call,
118 const QString& key,
119 const QString& value,
120 MetadataDownloadsListCb cb,
121 MetadataDownloadsListCb errCb,
122 QObject* parent)
123 : PendingCallWatcher(conn, servicePath, call, parent),
124 _key(key),
125 _value(value),
126 _cb(cb),
127 _errCb(errCb) {
128 connect(this, &QDBusPendingCallWatcher::finished,
129 this, &MetadataDownloadsListManagerPCW::onFinished);
130}
131
132void
133MetadataDownloadsListManagerPCW::onFinished(QDBusPendingCallWatcher* watcher) {
134 QDBusPendingReply<QList<QDBusObjectPath> > reply = *watcher;
135 DownloadsListImpl* list;
136 auto man = static_cast<Manager*>(parent());
137 if (reply.isError()) {
138 qDebug() << "ERROR" << reply.error() << reply.error().type();
139 // create error and deal with it
140 auto err = new DBusError(reply.error());
141 list = new DownloadsListImpl(err);
142 _errCb(_key, _value, list);
143 emit man->downloadsWithMetadataFound(_key, _value, list);
144 } else {
145 qDebug() << "Success!";
146 auto paths = reply.value();
147 QList<QSharedPointer<Download> > downloads;
148 list = new DownloadsListImpl();
149 foreach(const QDBusObjectPath& path, paths) {
150 QSharedPointer<Download> down =
151 QSharedPointer<Download>(new DownloadImpl(
152 _conn, _servicePath, path));
153 downloads.append(down);
154 }
155 list = new DownloadsListImpl(downloads);
156 emit man->downloadsWithMetadataFound(_key, _value, list);
157 _cb(_key, _value, list);
158 }
159 emit callbackExecuted();
160 watcher->deleteLater();
161}
162
163GroupManagerPCW::GroupManagerPCW(const QDBusConnection& conn,
164 const QString& servicePath,
165 const QDBusPendingCall& call,
166 GroupCb cb,
167 GroupCb errCb,
168 QObject* parent)
78 : PendingCallWatcher(conn, servicePath, call, parent),169 : PendingCallWatcher(conn, servicePath, call, parent),
79 _cb(cb),170 _cb(cb),
80 _errCb(errCb) {171 _errCb(errCb) {
81 CHECK(connect(this, &QDBusPendingCallWatcher::finished,172 CHECK(connect(this, &QDBusPendingCallWatcher::finished,
82 this, &GroupManagerPendingCallWatcher::onFinished))173 this, &GroupManagerPCW::onFinished))
83 << "Could not connect to signal";174 << "Could not connect to signal";
84}175}
85176
86void177void
87GroupManagerPendingCallWatcher::onFinished(QDBusPendingCallWatcher* watcher) {178GroupManagerPCW::onFinished(QDBusPendingCallWatcher* watcher) {
88 QDBusPendingReply<QDBusObjectPath> reply = *watcher;179 QDBusPendingReply<QDBusObjectPath> reply = *watcher;
89 auto man = static_cast<Manager*>(parent());180 auto man = static_cast<Manager*>(parent());
90 if (reply.isError()) {181 if (reply.isError()) {
91182
=== modified file 'src/downloads/client/ubuntu/download_manager/manager_pendingcall_watcher.h'
--- src/downloads/client/ubuntu/download_manager/manager_pendingcall_watcher.h 2014-01-13 17:26:28 +0000
+++ src/downloads/client/ubuntu/download_manager/manager_pendingcall_watcher.h 2014-04-15 13:56:56 +0000
@@ -27,23 +27,26 @@
27namespace DownloadManager {27namespace DownloadManager {
2828
29class Download;29class Download;
30class DownloadsList;
30class Error;31class Error;
31class GroupDownload;32class GroupDownload;
3233
33typedef std::function<void(Download*)> DownloadCb;34typedef std::function<void(Download*)> DownloadCb;
35typedef std::function<void(DownloadsList*)> DownloadsListCb;
36typedef std::function<void(const QString&, const QString&, DownloadsList*)> MetadataDownloadsListCb;
34typedef std::function<void(GroupDownload*)> GroupCb;37typedef std::function<void(GroupDownload*)> GroupCb;
3538
3639
37class DownloadManagerPendingCallWatcher : public PendingCallWatcher {40class DownloadManagerPCW : public PendingCallWatcher {
38 Q_OBJECT41 Q_OBJECT
3942
40 public:43 public:
41 DownloadManagerPendingCallWatcher(const QDBusConnection& conn,44 DownloadManagerPCW(const QDBusConnection& conn,
42 const QString& servicePath,45 const QString& servicePath,
43 const QDBusPendingCall& call,46 const QDBusPendingCall& call,
44 DownloadCb cb,47 DownloadCb cb,
45 DownloadCb errCb,48 DownloadCb errCb,
46 QObject* parent = 0);49 QObject* parent = 0);
4750
48 private slots:51 private slots:
49 void onFinished(QDBusPendingCallWatcher* watcher);52 void onFinished(QDBusPendingCallWatcher* watcher);
@@ -54,16 +57,56 @@
54};57};
5558
5659
57class GroupManagerPendingCallWatcher : public PendingCallWatcher {60class DownloadsListManagerPCW : public PendingCallWatcher {
58 Q_OBJECT61 Q_OBJECT
5962
60 public:63 public:
61 GroupManagerPendingCallWatcher(const QDBusConnection& conn,64 DownloadsListManagerPCW(const QDBusConnection& conn,
62 const QString& servicePath,65 const QString& servicePath,
63 const QDBusPendingCall& call,66 const QDBusPendingCall& call,
64 GroupCb cb,67 DownloadsListCb cb,
65 GroupCb errCb,68 DownloadsListCb errCb,
66 QObject* parent = 0);69 QObject* parent = 0);
70 private slots:
71 void onFinished(QDBusPendingCallWatcher* watcher);
72
73 private:
74 DownloadsListCb _cb;
75 DownloadsListCb _errCb;
76};
77
78class MetadataDownloadsListManagerPCW : public PendingCallWatcher {
79 Q_OBJECT
80
81 public:
82 MetadataDownloadsListManagerPCW(const QDBusConnection& conn,
83 const QString& servicePath,
84 const QDBusPendingCall& call,
85 const QString& key,
86 const QString& value,
87 MetadataDownloadsListCb cb,
88 MetadataDownloadsListCb errCb,
89 QObject* parent = 0);
90 private slots:
91 void onFinished(QDBusPendingCallWatcher* watcher);
92
93 private:
94 const QString& _key;
95 const QString& _value;
96 MetadataDownloadsListCb _cb;
97 MetadataDownloadsListCb _errCb;
98};
99
100class GroupManagerPCW : public PendingCallWatcher {
101 Q_OBJECT
102
103 public:
104 GroupManagerPCW(const QDBusConnection& conn,
105 const QString& servicePath,
106 const QDBusPendingCall& call,
107 GroupCb cb,
108 GroupCb errCb,
109 QObject* parent = 0);
67110
68 private slots:111 private slots:
69 void onFinished(QDBusPendingCallWatcher* watcher);112 void onFinished(QDBusPendingCallWatcher* watcher);
70113
=== modified file 'src/downloads/priv/ubuntu/downloads/download_adaptor.cpp'
--- src/downloads/priv/ubuntu/downloads/download_adaptor.cpp 2014-04-15 13:56:55 +0000
+++ src/downloads/priv/ubuntu/downloads/download_adaptor.cpp 2014-04-15 13:56:56 +0000
@@ -81,6 +81,12 @@
81 QMetaObject::invokeMethod(parent(), "resume");81 QMetaObject::invokeMethod(parent(), "resume");
82}82}
8383
84void DownloadAdaptor::setDestinationDir(const QString &path)
85{
86 // handle method call com.canonical.applications.Download.setDestinationDir
87 QMetaObject::invokeMethod(parent(), "setDestinationDir", Q_ARG(QString, path));
88}
89
84void DownloadAdaptor::setThrottle(qulonglong speed)90void DownloadAdaptor::setThrottle(qulonglong speed)
85{91{
86 // handle method call com.canonical.applications.Download.setThrottle92 // handle method call com.canonical.applications.Download.setThrottle
8793
=== modified file 'src/downloads/priv/ubuntu/downloads/download_adaptor.h'
--- src/downloads/priv/ubuntu/downloads/download_adaptor.h 2014-02-11 15:35:52 +0000
+++ src/downloads/priv/ubuntu/downloads/download_adaptor.h 2014-04-15 13:56:56 +0000
@@ -50,6 +50,9 @@
50" <method name=\"throttle\">\n"50" <method name=\"throttle\">\n"
51" <arg direction=\"out\" type=\"t\" name=\"speed\"/>\n"51" <arg direction=\"out\" type=\"t\" name=\"speed\"/>\n"
52" </method>\n"52" </method>\n"
53" <method name=\"setDestinationDir\">\n"
54" <arg direction=\"in\" type=\"s\" name=\"path\"/>\n"
55" </method>\n"
53" <method name=\"allowGSMDownload\">\n"56" <method name=\"allowGSMDownload\">\n"
54" <arg direction=\"in\" type=\"b\" name=\"allowed\"/>\n"57" <arg direction=\"in\" type=\"b\" name=\"allowed\"/>\n"
55" </method>\n"58" </method>\n"
@@ -116,6 +119,7 @@
116 void pause();119 void pause();
117 qulonglong progress();120 qulonglong progress();
118 void resume();121 void resume();
122 void setDestinationDir(const QString &path);
119 void setThrottle(qulonglong speed);123 void setThrottle(qulonglong speed);
120 void start();124 void start();
121 qulonglong throttle();125 qulonglong throttle();
122126
=== modified file 'src/downloads/priv/ubuntu/downloads/file_download.cpp'
--- src/downloads/priv/ubuntu/downloads/file_download.cpp 2014-04-15 13:56:55 +0000
+++ src/downloads/priv/ubuntu/downloads/file_download.cpp 2014-04-15 13:56:56 +0000
@@ -29,6 +29,8 @@
29#include <ubuntu/transfers/system/logger.h>29#include <ubuntu/transfers/system/logger.h>
30#include <ubuntu/transfers/system/network_reply.h>30#include <ubuntu/transfers/system/network_reply.h>
31#include <ubuntu/transfers/system/filename_mutex.h>31#include <ubuntu/transfers/system/filename_mutex.h>
32#include <ubuntu/transfers/system/uuid_factory.h>
33#include <ubuntu/transfers/system/uuid_utils.h>
32#include "file_download.h"34#include "file_download.h"
3335
34#define DOWN_LOG(LEVEL) LOG(LEVEL) << ((parent() != nullptr)?"GroupDownload {" + parent()->objectName() + " } ":"") << "Download ID{" << objectName() << " } "36#define DOWN_LOG(LEVEL) LOG(LEVEL) << ((parent() != nullptr)?"GroupDownload {" + parent()->objectName() + " } ":"") << "Download ID{" << objectName() << " } "
@@ -63,6 +65,7 @@
63 const QMap<QString, QString>& headers,65 const QMap<QString, QString>& headers,
64 QObject* parent)66 QObject* parent)
65 : Download(id, path, isConfined, rootPath, metadata, headers, parent),67 : Download(id, path, isConfined, rootPath, metadata, headers, parent),
68 QDBusContext(),
66 _totalSize(0),69 _totalSize(0),
67 _url(url),70 _url(url),
68 _hash(""),71 _hash(""),
@@ -81,6 +84,7 @@
81 const QMap<QString, QString> &headers,84 const QMap<QString, QString> &headers,
82 QObject* parent)85 QObject* parent)
83 : Download(id, path, isConfined, rootPath, metadata, headers, parent),86 : Download(id, path, isConfined, rootPath, metadata, headers, parent),
87 QDBusContext(),
84 _totalSize(0),88 _totalSize(0),
85 _url(url),89 _url(url),
86 _hash(hash) {90 _hash(hash) {
@@ -237,6 +241,66 @@
237}241}
238242
239void243void
244FileDownload::setDestinationDir(const QString& path) {
245 // we have to perform several checks to ensure the integrity
246 // of the download
247 // 1. Trust apparmor that it will bock the call of this method
248 // from not confined apps
249 // 2. Ensure that the path is an absolute path.
250 // 3. Ensure that the path does exist.
251 // 4. Ensure that the path is a dir.
252 // 5. Ensure that the download was not started
253 QFileInfo info(path);
254 if (!info.isAbsolute()) {
255 DOWN_LOG(WARNING) << "Trying to set destination dir to '"
256 << path << "' when the path is not absolute.";
257 if (calledFromDBus()) {
258 sendErrorReply(QDBusError::InvalidArgs,
259 "The destination dir must be an absolute path.");
260 }
261 return;
262 }
263
264 if (!info.exists()) {
265 DOWN_LOG(WARNING) << "Trying to set destination dir to '"
266 << path << "' when the path does not exists.";
267 if (calledFromDBus()) {
268 sendErrorReply(QDBusError::InvalidArgs,
269 "The destination dir must be already present in the system.");
270 }
271 return;
272 }
273
274 if (!info.isDir()) {
275 DOWN_LOG(WARNING) << "Trying to set destination dir to '"
276 << path << "' when the path is not a dir.";
277 if (calledFromDBus()) {
278 sendErrorReply(QDBusError::InvalidArgs,
279 "The destination dir must be a dir and a file was found.");
280 }
281 return;
282 }
283
284 if (state() == Download::IDLE) {
285 // calculate the new path before we unlock the old one
286 auto desiredPath = path;
287 if (!desiredPath.endsWith(QDir::separator())) {
288 desiredPath += QDir::separator();
289 }
290 desiredPath += _basename;
291 desiredPath = _fileNameMutex->lockFileName(desiredPath);
292 _tempFilePath = desiredPath + TEMP_EXTENSION;
293 _fileNameMutex->unlockFileName(_filePath);
294 _filePath = desiredPath;
295 } else {
296 if (calledFromDBus()) {
297 sendErrorReply(QDBusError::NotSupported,
298 "The path cannot be changed in a started download.");
299 }
300 }
301}
302
303void
240FileDownload::onDownloadProgress(qint64 currentProgress, qint64 bytesTotal) {304FileDownload::onDownloadProgress(qint64 currentProgress, qint64 bytesTotal) {
241 TRACE << _url << currentProgress << bytesTotal;305 TRACE << _url << currentProgress << bytesTotal;
242306
@@ -603,10 +667,12 @@
603 // the mutex will ensure that we do not have race conditions about667 // the mutex will ensure that we do not have race conditions about
604 // the file names in the download manager668 // the file names in the download manager
605 QString path = _url.path();669 QString path = _url.path();
606 QString basename = QFileInfo(path).fileName();670 _basename = QFileInfo(path).fileName();
607671
608 if (basename.isEmpty())672 if (_basename.isEmpty()) {
609 basename = DATA_FILE_NAME;673 QScopedPointer<UuidFactory> uuidFactory(new UuidFactory());
674 _basename = UuidUtils::getDBusString(uuidFactory->createUuid());
675 }
610676
611 auto metadataMap = metadata();677 auto metadataMap = metadata();
612678
@@ -624,7 +690,7 @@
624 _filePath));690 _filePath));
625 }691 }
626 } else {692 } else {
627 auto desiredPath = rootPath() + QDir::separator() + basename;693 auto desiredPath = rootPath() + QDir::separator() + _basename;
628 _filePath = _fileNameMutex->lockFileName(desiredPath);694 _filePath = _fileNameMutex->lockFileName(desiredPath);
629 _tempFilePath = _filePath + TEMP_EXTENSION;695 _tempFilePath = _filePath + TEMP_EXTENSION;
630 }696 }
631697
=== modified file 'src/downloads/priv/ubuntu/downloads/file_download.h'
--- src/downloads/priv/ubuntu/downloads/file_download.h 2014-04-15 13:56:55 +0000
+++ src/downloads/priv/ubuntu/downloads/file_download.h 2014-04-15 13:56:56 +0000
@@ -19,6 +19,7 @@
19#ifndef DOWNLOADER_LIB_SINGLE_DOWNLOAD_H19#ifndef DOWNLOADER_LIB_SINGLE_DOWNLOAD_H
20#define DOWNLOADER_LIB_SINGLE_DOWNLOAD_H20#define DOWNLOADER_LIB_SINGLE_DOWNLOAD_H
2121
22#include <QtDBus/QDBusContext>
22#include <QFile>23#include <QFile>
23#include <QNetworkReply>24#include <QNetworkReply>
24#include <QProcess>25#include <QProcess>
@@ -41,7 +42,7 @@
4142
42namespace Daemon {43namespace Daemon {
4344
44class FileDownload : public Download {45class FileDownload : public Download, public QDBusContext {
45 Q_OBJECT46 Q_OBJECT
4647
47 public:48 public:
@@ -92,6 +93,7 @@
92 qulonglong progress() override;93 qulonglong progress() override;
93 qulonglong totalSize() override;94 qulonglong totalSize() override;
94 virtual void setThrottle(qulonglong speed) override;95 virtual void setThrottle(qulonglong speed) override;
96 virtual void setDestinationDir(const QString& path);
9597
96 signals:98 signals:
97 void finished(const QString& path);99 void finished(const QString& path);
@@ -132,6 +134,7 @@
132 bool _connected = false;134 bool _connected = false;
133 qulonglong _totalSize = 0;135 qulonglong _totalSize = 0;
134 QUrl _url;136 QUrl _url;
137 QString _basename;
135 QString _filePath;138 QString _filePath;
136 QString _tempFilePath;139 QString _tempFilePath;
137 QString _hash;140 QString _hash;
138141
=== modified file 'src/downloads/test-daemon/testing_file_download.h'
--- src/downloads/test-daemon/testing_file_download.h 2014-04-15 13:56:55 +0000
+++ src/downloads/test-daemon/testing_file_download.h 2014-04-15 13:56:56 +0000
@@ -26,7 +26,7 @@
2626
27using namespace Ubuntu::DownloadManager::Daemon;27using namespace Ubuntu::DownloadManager::Daemon;
2828
29class TestingFileDownload : public FileDownload, public QDBusContext {29class TestingFileDownload : public FileDownload {
30 Q_OBJECT30 Q_OBJECT
3131
32 public:32 public:
3333
=== modified file 'tests/test_client_download.cpp'
--- tests/test_client_download.cpp 2014-04-15 13:56:55 +0000
+++ tests/test_client_download.cpp 2014-04-15 13:56:56 +0000
@@ -16,6 +16,7 @@
16 * Boston, MA 02110-1301, USA.16 * Boston, MA 02110-1301, USA.
17 */17 */
1818
19#include <QDir>
19#include <QNetworkReply>20#include <QNetworkReply>
20#include <ubuntu/download_manager/error.h>21#include <ubuntu/download_manager/error.h>
21#include "test_client_download.h"22#include "test_client_download.h"
@@ -252,11 +253,11 @@
252 QTest::addColumn<QString>("standardError");253 QTest::addColumn<QString>("standardError");
253254
254 QTest::newRow("Failed To Start") << 0 << "Failed To Start"255 QTest::newRow("Failed To Start") << 0 << "Failed To Start"
255 << -1 << "" << ""; 256 << -1 << "" << "";
256 QTest::newRow("Crashed") << 1 << "Crashed" << -1 << "Calculating.."257 QTest::newRow("Crashed") << 1 << "Crashed" << -1 << "Calculating.."
257 << "NULL pointer"; 258 << "NULL pointer";
258 QTest::newRow("Timedout") << 2 << "Timedout" << -1 << "stdout"259 QTest::newRow("Timedout") << 2 << "Timedout" << -1 << "stdout"
259 << ""; 260 << "";
260}261}
261262
262void263void
@@ -289,4 +290,51 @@
289 QCOMPARE(standardError, processError->standardError());290 QCOMPARE(standardError, processError->standardError());
290}291}
291292
293void
294TestDownload::testSetLocalDirectory() {
295 auto path = testDirectory();
296 _down->setDestinationDir(path);
297 QVERIFY(!_down->isError());
298 QVERIFY(_down->error() == nullptr);
299}
300
301void
302TestDownload::testSetLocalDirectoryNotAbsolute() {
303 _down->setDestinationDir("./test");
304 QVERIFY(_down->isError());
305 QVERIFY(_down->error() != nullptr);
306 QCOMPARE(Error::DBus, _down->error()->type());
307}
308
309void
310TestDownload::testSetLocalDirectoryNotPresent() {
311 _down->setDestinationDir("/etc/test");
312 QVERIFY(_down->isError());
313 QVERIFY(_down->error() != nullptr);
314 QCOMPARE(Error::DBus, _down->error()->type());
315}
316
317void
318TestDownload::testSetLocalDirectoryNotDir() {
319 auto path = testDirectory() + QDir::separator() + "test";
320 QFile file(path);
321 file.open(QIODevice::ReadWrite | QFile::Append);
322 file.write(QByteArray(100, 'w'));
323 file.close();
324 _down->setDestinationDir(path);
325 QVERIFY(_down->isError());
326 QVERIFY(_down->error() != nullptr);
327 QCOMPARE(Error::DBus, _down->error()->type());
328}
329
330void
331TestDownload::testSetLocalDirectoryStarted() {
332 auto path = testDirectory();
333 _down->start();
334 _down->setDestinationDir(path);
335 QVERIFY(_down->isError());
336 QVERIFY(_down->error() != nullptr);
337 QCOMPARE(Error::DBus, _down->error()->type());
338}
339
292QTEST_MAIN(TestDownload)340QTEST_MAIN(TestDownload)
293341
=== modified file 'tests/test_client_download.h'
--- tests/test_client_download.h 2014-04-15 13:56:55 +0000
+++ tests/test_client_download.h 2014-04-15 13:56:56 +0000
@@ -55,6 +55,13 @@
55 void testProcessErrorRaised_data();55 void testProcessErrorRaised_data();
56 void testProcessErrorRaised();56 void testProcessErrorRaised();
5757
58 // set local dir tests
59 void testSetLocalDirectory();
60 void testSetLocalDirectoryNotAbsolute();
61 void testSetLocalDirectoryNotPresent();
62 void testSetLocalDirectoryNotDir();
63 void testSetLocalDirectoryStarted();
64
58 private:65 private:
59 QString _url;66 QString _url;
60 QVariantMap _metadata;67 QVariantMap _metadata;
6168
=== modified file 'tests/test_client_manager.cpp'
--- tests/test_client_manager.cpp 2014-04-15 13:56:55 +0000
+++ tests/test_client_manager.cpp 2014-04-15 13:56:56 +0000
@@ -18,6 +18,7 @@
1818
19#include <QDebug>19#include <QDebug>
20#include <ubuntu/download_manager/download.h>20#include <ubuntu/download_manager/download.h>
21#include <ubuntu/download_manager/downloads_list.h>
21#include "test_client_manager.h"22#include "test_client_manager.h"
2223
23TestManager::TestManager(QObject *parent)24TestManager::TestManager(QObject *parent)
@@ -136,4 +137,205 @@
136 delete down;137 delete down;
137}138}
138139
140void
141TestManager::testGetAllDownloadsSignalsEmitted_data() {
142 QTest::addColumn<int>("count");
143
144 QTest::newRow("5 downloads") << 5;
145 QTest::newRow("10 downloads") << 10;
146 QTest::newRow("15 downloads") << 15;
147}
148
149void
150TestManager::testGetAllDownloadsSignalsEmitted() {
151 QFETCH(int, count);
152
153 QString url = "http://example.com/";
154 QVariantMap metadata;
155 QMap<QString, QString> headers;
156
157 SignalBarrier managerSpy(_man, SIGNAL(downloadCreated(Download*)));
158 SignalBarrier listSpy(_man, SIGNAL(downloadsFound(DownloadsList*)));
159
160 for (int index = 0; index < count; index++) {
161 url += index;
162 DownloadStruct downStruct(url, metadata, headers);
163 _man->createDownload(downStruct);
164 }
165
166 // ensure that all of the are created
167 QVERIFY(managerSpy.ensureSignalEmitted());
168 QTRY_COMPARE(count, managerSpy.count());
169 _man->getAllDownloads();
170
171 QVERIFY(listSpy.ensureSignalEmitted());
172 QTRY_COMPARE(1, listSpy.count());
173 auto downs = listSpy.takeFirst().at(0).value<DownloadsList*>();
174 QCOMPARE(count, downs->downloads().count());
175
176 delete downs;
177}
178
179void
180TestManager::testGetAllDownloadsSignalsEmittedCallbacks_data() {
181 QTest::addColumn<int>("count");
182
183 QTest::newRow("5 downloads") << 5;
184 QTest::newRow("10 downloads") << 10;
185 QTest::newRow("15 downloads") << 15;
186}
187
188void
189TestManager::testGetAllDownloadsSignalsEmittedCallbacks() {
190 QFETCH(int, count);
191
192 QString url = "http://example.com/";
193 QVariantMap metadata;
194 QMap<QString, QString> headers;
195 DownloadsListCb cb = [](DownloadsList*){};
196
197 SignalBarrier managerSpy(_man, SIGNAL(downloadCreated(Download*)));
198 SignalBarrier listSpy(_man, SIGNAL(downloadsFound(DownloadsList*)));
199
200 for (int index = 0; index < count; index++) {
201 url += index;
202 DownloadStruct downStruct(url, metadata, headers);
203 _man->createDownload(downStruct);
204 }
205
206 // ensure that all of the are created
207 QVERIFY(managerSpy.ensureSignalEmitted());
208 QTRY_COMPARE(count, managerSpy.count());
209 _man->getAllDownloads(cb, cb);
210
211 QVERIFY(listSpy.ensureSignalEmitted());
212 QTRY_COMPARE(1, listSpy.count());
213 auto downs = listSpy.takeFirst().at(0).value<DownloadsList*>();
214 QCOMPARE(count, downs->downloads().count());
215
216 delete downs;
217}
218
219void
220TestManager::testGetAllDownloadsMetadataSignalsEmitted_data() {
221 QTest::addColumn<int>("count");
222
223 QTest::newRow("5 downloads") << 5;
224 QTest::newRow("10 downloads") << 10;
225 QTest::newRow("15 downloads") << 15;
226}
227
228void
229TestManager::testGetAllDownloadsMetadataSignalsEmitted() {
230 QFETCH(int, count);
231 int metadataCount = 5;
232 QString key = "test";
233 QString value = "metadata";
234
235 QString url = "http://example.com/";
236 QVariantMap metadata;
237 QMap<QString, QString> headers;
238
239 SignalBarrier managerSpy(_man, SIGNAL(downloadCreated(Download*)));
240 SignalBarrier listSpy(_man, SIGNAL(
241 downloadsWithMetadataFound(const QString&, const QString&,
242 DownloadsList*)));
243
244 for (int index = 0; index < count; index++) {
245 url += index;
246 DownloadStruct downStruct(url, metadata, headers);
247 _man->createDownload(downStruct);
248 }
249
250 // add downloads with metadata
251 metadata[key] = value;
252 for (int index = count; index < metadataCount + count; index++) {
253 url += index;
254 DownloadStruct downStruct(url, metadata, headers);
255 _man->createDownload(downStruct);
256 }
257 // ensure that all of the are created
258 QVERIFY(managerSpy.ensureSignalEmitted());
259 QTRY_COMPARE(count + metadataCount, managerSpy.count());
260 _man->getAllDownloadsWithMetadata(key, value);
261
262 QVERIFY(listSpy.ensureSignalEmitted());
263 QTRY_COMPARE(1, listSpy.count());
264
265 auto signalInfo = listSpy.takeFirst();
266 auto signalKey = signalInfo.at(0).toString();
267 QCOMPARE(key, signalKey);
268
269 auto signalValue = signalInfo.at(1).toString();
270 QCOMPARE(value, signalValue);
271
272 auto downs = signalInfo.at(2).value<DownloadsList*>();
273
274 QCOMPARE(metadataCount, downs->downloads().count());
275
276 delete downs;
277}
278
279void
280TestManager::testGetAllDownloadsMetadataSignalsEmittedCallbacks_data() {
281 QTest::addColumn<int>("count");
282
283 QTest::newRow("5 downloads") << 5;
284 QTest::newRow("10 downloads") << 10;
285 QTest::newRow("15 downloads") << 15;
286}
287
288void
289TestManager::testGetAllDownloadsMetadataSignalsEmittedCallbacks() {
290 QFETCH(int, count);
291 int metadataCount = 5;
292 QString key = "test";
293 QString value = "metadata";
294
295 QString url = "http://example.com/";
296 QVariantMap metadata;
297 QMap<QString, QString> headers;
298 MetadataDownloadsListCb cb =
299 [](const QString&, const QString&, DownloadsList*){};
300
301 SignalBarrier managerSpy(_man, SIGNAL(downloadCreated(Download*)));
302 SignalBarrier listSpy(_man, SIGNAL(
303 downloadsWithMetadataFound(const QString&, const QString&,
304 DownloadsList*)));
305
306 for (int index = 0; index < count; index++) {
307 url += index;
308 DownloadStruct downStruct(url, metadata, headers);
309 _man->createDownload(downStruct);
310 }
311
312 // add downloads with metadata
313 metadata[key] = value;
314 for (int index = count; index < metadataCount + count; index++) {
315 url += index;
316 DownloadStruct downStruct(url, metadata, headers);
317 _man->createDownload(downStruct);
318 }
319 // ensure that all of the are created
320 QVERIFY(managerSpy.ensureSignalEmitted());
321 QTRY_COMPARE(count + metadataCount, managerSpy.count());
322 _man->getAllDownloadsWithMetadata(key, value, cb, cb);
323
324 QVERIFY(listSpy.ensureSignalEmitted());
325 QTRY_COMPARE(1, listSpy.count());
326
327 auto signalInfo = listSpy.takeFirst();
328 auto signalKey = signalInfo.at(0).toString();
329 QCOMPARE(key, signalKey);
330
331 auto signalValue = signalInfo.at(1).toString();
332 QCOMPARE(value, signalValue);
333
334 auto downs = signalInfo.at(2).value<DownloadsList*>();
335
336 QCOMPARE(metadataCount, downs->downloads().count());
337
338 delete downs;
339}
340
139QTEST_MAIN(TestManager)341QTEST_MAIN(TestManager)
140342
=== modified file 'tests/test_client_manager.h'
--- tests/test_client_manager.h 2014-04-15 13:56:55 +0000
+++ tests/test_client_manager.h 2014-04-15 13:56:56 +0000
@@ -46,6 +46,14 @@
46 void testExitError();46 void testExitError();
47 void testCreateDownloadSignalsEmitted();47 void testCreateDownloadSignalsEmitted();
48 void testCreateDownloadSignalsEmittedCallbacks();48 void testCreateDownloadSignalsEmittedCallbacks();
49 void testGetAllDownloadsSignalsEmitted_data();
50 void testGetAllDownloadsSignalsEmitted();
51 void testGetAllDownloadsSignalsEmittedCallbacks_data();
52 void testGetAllDownloadsSignalsEmittedCallbacks();
53 void testGetAllDownloadsMetadataSignalsEmitted_data();
54 void testGetAllDownloadsMetadataSignalsEmitted();
55 void testGetAllDownloadsMetadataSignalsEmittedCallbacks_data();
56 void testGetAllDownloadsMetadataSignalsEmittedCallbacks();
4957
50 private:58 private:
51 Manager* _man;59 Manager* _man;
5260
=== modified file 'tests/test_download.cpp'
--- tests/test_download.cpp 2014-04-15 13:56:55 +0000
+++ tests/test_download.cpp 2014-04-15 13:56:56 +0000
@@ -16,6 +16,7 @@
16 * Boston, MA 02110-1301, USA.16 * Boston, MA 02110-1301, USA.
17 */17 */
1818
19#include <QDir>
19#include <QNetworkRequest>20#include <QNetworkRequest>
20#include <QSslError>21#include <QSslError>
21#include <ubuntu/download_manager/metatypes.h>22#include <ubuntu/download_manager/metatypes.h>
@@ -46,7 +47,7 @@
46 _isConfined = false;47 _isConfined = false;
47 _rootPath = testDirectory();48 _rootPath = testDirectory();
48 _path = "random path to dbus";49 _path = "random path to dbus";
49 _url = QUrl("http://ubuntu.com");50 _url = QUrl("http://ubuntu.com/data.txt");
50 _algo = "Sha256";51 _algo = "Sha256";
51 _networkInfo = new MockSystemNetworkInfo();52 _networkInfo = new MockSystemNetworkInfo();
52 SystemNetworkInfo::setInstance(_networkInfo);53 SystemNetworkInfo::setInstance(_networkInfo);
@@ -3691,4 +3692,89 @@
3691 FileNameMutex::deleteInstance();3692 FileNameMutex::deleteInstance();
3692}3693}
36933694
3695void
3696TestDownload::testSetLocalDirectory() {
3697 auto path = testDirectory() + QDir::separator() + "test";
3698 QDir().mkpath(path);
3699
3700 EXPECT_CALL(*_networkInfo, isOnline())
3701 .WillRepeatedly(Return(true));
3702
3703 QScopedPointer<FileDownload> download(new FileDownload(_id, _path,
3704 _isConfined, _rootPath, _url, _metadata, _headers));
3705 auto original = download->filePath();
3706 download->setDestinationDir(path);
3707 QVERIFY(original != download->filePath());
3708 QVERIFY(download->filePath().startsWith(path));
3709 verifyMocks();
3710}
3711
3712void
3713TestDownload::testSetLocalDirectoryNotAbsolute() {
3714 auto path = QString("./path");
3715 EXPECT_CALL(*_networkInfo, isOnline())
3716 .WillRepeatedly(Return(true));
3717
3718 QScopedPointer<FileDownload> download(new FileDownload(_id, _path,
3719 _isConfined, _rootPath, _url, _metadata, _headers));
3720
3721 auto original = download->filePath();
3722 download->setDestinationDir(path);
3723 QCOMPARE(original, download->filePath());
3724 verifyMocks();
3725}
3726
3727void
3728TestDownload::testSetLocalDirectoryNotPresent() {
3729 auto path = QString("/not/present/path");
3730 EXPECT_CALL(*_networkInfo, isOnline())
3731 .WillRepeatedly(Return(true));
3732
3733 QScopedPointer<FileDownload> download(new FileDownload(_id, _path,
3734 _isConfined, _rootPath, _url, _metadata, _headers));
3735
3736 auto original = download->filePath();
3737 download->setDestinationDir(path);
3738 QCOMPARE(original, download->filePath());
3739 verifyMocks();
3740}
3741
3742void
3743TestDownload::testSetLocalDirectoryNotDir() {
3744 auto path = testDirectory() + QDir::separator() + "test";
3745 QFile file(path);
3746 file.open(QIODevice::ReadWrite | QFile::Append);
3747 file.write(QByteArray(100, 'w'));
3748 file.close();
3749
3750 EXPECT_CALL(*_networkInfo, isOnline())
3751 .WillRepeatedly(Return(true));
3752
3753 QScopedPointer<FileDownload> download(new FileDownload(_id, _path,
3754 _isConfined, _rootPath, _url, _metadata, _headers));
3755
3756 auto original = download->filePath();
3757 download->setDestinationDir(path);
3758 QCOMPARE(original, download->filePath());
3759 verifyMocks();
3760}
3761
3762void
3763TestDownload::testSetLocalDirectoryStarted() {
3764 auto path = testDirectory() + QDir::separator() + "test";
3765 QDir().mkpath(path);
3766
3767 EXPECT_CALL(*_networkInfo, isOnline())
3768 .WillRepeatedly(Return(true));
3769
3770 QScopedPointer<FileDownload> download(new FileDownload(_id, _path,
3771 _isConfined, _rootPath, _url, _metadata, _headers));
3772
3773 auto original = download->filePath();
3774 download->start(); // change state
3775 download->setDestinationDir(path);
3776 QCOMPARE(original, download->filePath());
3777 verifyMocks();
3778}
3779
3694QTEST_MAIN(TestDownload)3780QTEST_MAIN(TestDownload)
36953781
=== modified file 'tests/test_download.h'
--- tests/test_download.h 2014-04-15 13:56:55 +0000
+++ tests/test_download.h 2014-04-15 13:56:56 +0000
@@ -171,6 +171,13 @@
171 void testErrorUnlocksPath();171 void testErrorUnlocksPath();
172 void testLockCustomLocalPath();172 void testLockCustomLocalPath();
173173
174 // tests related to setting the dir
175 void testSetLocalDirectory();
176 void testSetLocalDirectoryNotAbsolute();
177 void testSetLocalDirectoryNotPresent();
178 void testSetLocalDirectoryNotDir();
179 void testSetLocalDirectoryStarted();
180
174 private:181 private:
175 QString _id;182 QString _id;
176 bool _isConfined;183 bool _isConfined;

Subscribers

People subscribed via source and target branches