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
1=== modified file 'docs/com.canonical.applications.download.xml'
2--- docs/com.canonical.applications.download.xml 2014-02-11 15:35:52 +0000
3+++ docs/com.canonical.applications.download.xml 2014-04-15 13:56:56 +0000
4@@ -22,6 +22,10 @@
5 <arg name="speed" type="t" direction="out"/>
6 </method>
7
8+ <method name="setDestinationDir">
9+ <arg name="path" type="s" direction="in"/>
10+ </method>
11+
12 <method name="allowGSMDownload">
13 <arg name="allowed" type="b" direction="in"/>
14 </method>
15
16=== modified file 'src/downloads/client/CMakeLists.txt'
17--- src/downloads/client/CMakeLists.txt 2014-04-15 13:56:55 +0000
18+++ src/downloads/client/CMakeLists.txt 2014-04-15 13:56:56 +0000
19@@ -3,6 +3,7 @@
20 set(SOURCES
21 ubuntu/download_manager/download_impl.cpp
22 ubuntu/download_manager/download_interface.cpp
23+ ubuntu/download_manager/downloads_list_impl.cpp
24 ubuntu/download_manager/download_pendingcall_watcher.cpp
25 ubuntu/download_manager/error.cpp
26 ubuntu/download_manager/group_download.cpp
27@@ -15,6 +16,7 @@
28
29 set(PUBLIC_HEADERS
30 ubuntu/download_manager/download.h
31+ ubuntu/download_manager/downloads_list.h
32 ubuntu/download_manager/error.h
33 ubuntu/download_manager/group_download.h
34 ubuntu/download_manager/manager.h
35@@ -23,6 +25,7 @@
36 set(PRIVATE_HEADERS
37 ubuntu/download_manager/download_impl.h
38 ubuntu/download_manager/download_interface.h
39+ ubuntu/download_manager/downloads_list_impl.h
40 ubuntu/download_manager/download_pendingcall_watcher.h
41 ubuntu/download_manager/manager_impl.h
42 ubuntu/download_manager/manager_interface.h
43
44=== added file 'src/downloads/client/ubuntu-download-manager-client.pro.THIS'
45--- src/downloads/client/ubuntu-download-manager-client.pro.THIS 1970-01-01 00:00:00 +0000
46+++ src/downloads/client/ubuntu-download-manager-client.pro.THIS 2014-04-15 13:56:56 +0000
47@@ -0,0 +1,59 @@
48+include(../common-project-config.pri)
49+include(../common-vars.pri)
50+
51+QT += dbus
52+QT -= gui
53+
54+TARGET = ubuntu-download-manager-client
55+TEMPLATE = lib
56+
57+DEFINES += UBUNTUDOWNLOADMANAGERCLIENT_LIBRARY
58+
59+SOURCES += ubuntu/download_manager/manager.cpp \
60+ ubuntu/download_manager/manager_impl.cpp \
61+ ubuntu/download_manager/download_interface.cpp \
62+ ubuntu/download_manager/manager_interface.cpp \
63+ ubuntu/download_manager/download_impl.cpp \
64+ ubuntu/download_manager/downloads_list_impl.cpp \
65+ ubuntu/download_manager/group_download.cpp \
66+ ubuntu/download_manager/manager_pendingcall_watcher.cpp \
67+ ubuntu/download_manager/error.cpp \
68+ ubuntu/download_manager/pending_call_watcher.cpp \
69+ ubuntu/download_manager/download_pendingcall_watcher.cpp
70+
71+public_headers = \
72+ ubuntu/download_manager/manager.h \
73+ ubuntu/download_manager/download.h \
74+ ubuntu/download_manager/downloads_list.h \
75+ ubuntu/download_manager/group_download.h \
76+ ubuntu/download_manager/error.h
77+
78+private_headers = \
79+ ubuntu/download_manager/manager_impl.h \
80+ ubuntu/download_manager/download_impl.h \
81+ ubuntu/download_manager/downloads_list_impl.h \
82+ ubuntu/download_manager/download_interface.h \
83+ ubuntu/download_manager/manager_interface.h \
84+ ubuntu/download_manager/manager_pendingcall_watcher.h \
85+ ubuntu/download_manager/pending_call_watcher.h \
86+ ubuntu/download_manager/download_pendingcall_watcher.h
87+
88+HEADERS +=\
89+ $$public_headers \
90+ $$private_headers
91+
92+OTHER_FILES += \
93+ ubuntu-download-manager-client.pc.in
94+
95+headers.files = $$public_headers
96+
97+include(../common-installs-config.pri)
98+
99+pkgconfig.files = ubuntu-download-manager-client.pc
100+include(../common-pkgconfig.pri)
101+INSTALLS += pkgconfig
102+
103+LIBS += -L$$OUT_PWD/../ubuntu-download-manager-common/ -lubuntu-download-manager-common
104+
105+INCLUDEPATH += $$PWD/../ubuntu-download-manager-common
106+DEPENDPATH += $$PWD/../ubuntu-download-manager-common
107
108=== modified file 'src/downloads/client/ubuntu/download_manager/download.h'
109--- src/downloads/client/ubuntu/download_manager/download.h 2014-04-15 13:56:55 +0000
110+++ src/downloads/client/ubuntu/download_manager/download.h 2014-04-15 13:56:56 +0000
111@@ -114,6 +114,15 @@
112 virtual bool isMobileDownloadAllowed() = 0;
113
114 /*!
115+ \fn void setDestinationDir(const QString& path);
116+
117+ Notifies the download manager that the local path of the download
118+ must be a different one. This call can only be performed if the
119+ download was not started else it will result in an error.
120+ */
121+ virtual void setDestinationDir(const QString& path) = 0;
122+
123+ /*!
124 \fn void setThrottle(qulonglong speed)
125
126 Notifies the download manager that the download represented by this
127
128=== modified file 'src/downloads/client/ubuntu/download_manager/download_impl.cpp'
129--- src/downloads/client/ubuntu/download_manager/download_impl.cpp 2014-04-15 13:56:55 +0000
130+++ src/downloads/client/ubuntu/download_manager/download_impl.cpp 2014-04-15 13:56:56 +0000
131@@ -96,7 +96,7 @@
132 DownloadImpl::start() {
133 QDBusPendingCall call =
134 _dbusInterface->start();
135- auto watcher = new DownloadPendingCallWatcher(_conn, _servicePath,
136+ auto watcher = new DownloadPCW(_conn, _servicePath,
137 call, this);
138 Q_UNUSED(watcher);
139 }
140@@ -105,7 +105,7 @@
141 DownloadImpl::pause() {
142 QDBusPendingCall call =
143 _dbusInterface->pause();
144- auto watcher = new DownloadPendingCallWatcher(_conn, _servicePath,
145+ auto watcher = new DownloadPCW(_conn, _servicePath,
146 call, this);
147 Q_UNUSED(watcher);
148 }
149@@ -114,7 +114,7 @@
150 DownloadImpl::resume() {
151 QDBusPendingCall call =
152 _dbusInterface->resume();
153- auto watcher = new DownloadPendingCallWatcher(_conn, _servicePath,
154+ auto watcher = new DownloadPCW(_conn, _servicePath,
155 call, this);
156 Q_UNUSED(watcher);
157 }
158@@ -123,7 +123,7 @@
159 DownloadImpl::cancel() {
160 QDBusPendingCall call =
161 _dbusInterface->cancel();
162- auto watcher = new DownloadPendingCallWatcher(_conn, _servicePath,
163+ auto watcher = new DownloadPCW(_conn, _servicePath,
164 call, this);
165 Q_UNUSED(watcher);
166 }
167@@ -155,6 +155,17 @@
168 }
169
170 void
171+DownloadImpl::setDestinationDir(const QString& path) {
172+ QDBusPendingReply<> reply =
173+ _dbusInterface->setDestinationDir(path);
174+ // block, the call should be fast enough
175+ reply.waitForFinished();
176+ if (reply.isError()) {
177+ setLastError(reply.error());
178+ }
179+}
180+
181+void
182 DownloadImpl::setThrottle(qulonglong speed) {
183 QDBusPendingReply<> reply =
184 _dbusInterface->setThrottle(speed);
185
186=== modified file 'src/downloads/client/ubuntu/download_manager/download_impl.h'
187--- src/downloads/client/ubuntu/download_manager/download_impl.h 2014-04-15 13:56:55 +0000
188+++ src/downloads/client/ubuntu/download_manager/download_impl.h 2014-04-15 13:56:56 +0000
189@@ -43,8 +43,11 @@
190 Q_OBJECT
191
192 // allow the manager to create downloads
193- friend class DownloadPendingCallWatcher;
194- friend class DownloadManagerPendingCallWatcher;
195+ friend class ManagerImpl;
196+ friend class DownloadPCW;
197+ friend class MetadataDownloadsListManagerPCW;
198+ friend class DownloadsListManagerPCW;
199+ friend class DownloadManagerPCW;
200
201 public:
202 virtual ~DownloadImpl();
203@@ -57,6 +60,7 @@
204 void allowMobileDownload(bool allowed);
205 bool isMobileDownloadAllowed();
206
207+ void setDestinationDir(const QString& path);
208 void setThrottle(qulonglong speed);
209 qulonglong throttle();
210
211
212=== modified file 'src/downloads/client/ubuntu/download_manager/download_interface.h'
213--- src/downloads/client/ubuntu/download_manager/download_interface.h 2014-02-11 19:57:39 +0000
214+++ src/downloads/client/ubuntu/download_manager/download_interface.h 2014-04-15 13:56:56 +0000
215@@ -80,6 +80,13 @@
216 return asyncCallWithArgumentList(QLatin1String("resume"), argumentList);
217 }
218
219+ inline QDBusPendingReply<> setDestinationDir(const QString &path)
220+ {
221+ QList<QVariant> argumentList;
222+ argumentList << QVariant::fromValue(path);
223+ return asyncCallWithArgumentList(QLatin1String("setDestinationDir"), argumentList);
224+ }
225+
226 inline QDBusPendingReply<> setThrottle(qulonglong speed)
227 {
228 QList<QVariant> argumentList;
229
230=== modified file 'src/downloads/client/ubuntu/download_manager/download_pendingcall_watcher.cpp'
231--- src/downloads/client/ubuntu/download_manager/download_pendingcall_watcher.cpp 2014-04-15 13:56:55 +0000
232+++ src/downloads/client/ubuntu/download_manager/download_pendingcall_watcher.cpp 2014-04-15 13:56:56 +0000
233@@ -26,19 +26,19 @@
234
235 namespace DownloadManager {
236
237-DownloadPendingCallWatcher::DownloadPendingCallWatcher(
238+DownloadPCW::DownloadPCW(
239 const QDBusConnection& conn,
240 const QString& servicePath,
241 const QDBusPendingCall& call,
242 Download* parent)
243 : PendingCallWatcher(conn, servicePath, call, parent) {
244- CHECK(connect(this, &DownloadPendingCallWatcher::finished,
245- this, &DownloadPendingCallWatcher::onFinished))
246+ CHECK(connect(this, &DownloadPCW::finished,
247+ this, &DownloadPCW::onFinished))
248 << "Could not connect to signal";
249 }
250
251 void
252-DownloadPendingCallWatcher::onFinished(QDBusPendingCallWatcher* watcher) {
253+DownloadPCW::onFinished(QDBusPendingCallWatcher* watcher) {
254 auto down = qobject_cast<Download*>(parent());
255 QDBusPendingReply<> reply = *watcher;
256 if (reply.isError()) {
257
258=== modified file 'src/downloads/client/ubuntu/download_manager/download_pendingcall_watcher.h'
259--- src/downloads/client/ubuntu/download_manager/download_pendingcall_watcher.h 2014-01-22 16:26:29 +0000
260+++ src/downloads/client/ubuntu/download_manager/download_pendingcall_watcher.h 2014-04-15 13:56:56 +0000
261@@ -27,11 +27,11 @@
262
263 namespace DownloadManager {
264
265-class DownloadPendingCallWatcher : public PendingCallWatcher {
266+class DownloadPCW : public PendingCallWatcher {
267 Q_OBJECT
268
269 public:
270- DownloadPendingCallWatcher(const QDBusConnection& conn,
271+ DownloadPCW(const QDBusConnection& conn,
272 const QString& servicePath,
273 const QDBusPendingCall& call,
274 Download* parent = 0);
275
276=== added file 'src/downloads/client/ubuntu/download_manager/downloads_list.h'
277--- src/downloads/client/ubuntu/download_manager/downloads_list.h 1970-01-01 00:00:00 +0000
278+++ src/downloads/client/ubuntu/download_manager/downloads_list.h 2014-04-15 13:56:56 +0000
279@@ -0,0 +1,50 @@
280+/*
281+ * Copyright 2014 Canonical Ltd.
282+ *
283+ * This library is free software; you can redistribute it and/or
284+ * modify it under the terms of version 3 of the GNU Lesser General Public
285+ * License as published by the Free Software Foundation.
286+ *
287+ * This program is distributed in the hope that it will be useful,
288+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
289+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
290+ * General Public License for more details.
291+ *
292+ * You should have received a copy of the GNU Lesser General Public
293+ * License along with this library; if not, write to the
294+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
295+ * Boston, MA 02110-1301, USA.
296+ */
297+
298+#ifndef UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_LIST_H
299+#define UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_LIST_H
300+
301+#include <QList>
302+#include <QObject>
303+#include <QSharedPointer>
304+#include <ubuntu/download_manager/common.h>
305+
306+namespace Ubuntu {
307+
308+namespace DownloadManager {
309+
310+class Error;
311+class Download;
312+
313+class DOWNLOAD_MANAGER_EXPORT DownloadsList : public QObject {
314+ Q_OBJECT
315+
316+ public:
317+ explicit DownloadsList(QObject* parent = 0)
318+ : QObject(parent) {}
319+
320+ virtual QList<QSharedPointer<Download> > downloads() const = 0;
321+ virtual bool isError() const = 0;
322+ virtual Error* error() const = 0;
323+};
324+
325+} // Ubuntu
326+
327+} // DownloadManager
328+
329+#endif // UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_LIST_H
330
331=== added file 'src/downloads/client/ubuntu/download_manager/downloads_list_impl.cpp'
332--- src/downloads/client/ubuntu/download_manager/downloads_list_impl.cpp 1970-01-01 00:00:00 +0000
333+++ src/downloads/client/ubuntu/download_manager/downloads_list_impl.cpp 2014-04-15 13:56:56 +0000
334@@ -0,0 +1,64 @@
335+/*
336+ * Copyright 2014 Canonical Ltd.
337+ *
338+ * This library is free software; you can redistribute it and/or
339+ * modify it under the terms of version 3 of the GNU Lesser General Public
340+ * License as published by the Free Software Foundation.
341+ *
342+ * This program is distributed in the hope that it will be useful,
343+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
344+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
345+ * General Public License for more details.
346+ *
347+ * You should have received a copy of the GNU Lesser General Public
348+ * License along with this library; if not, write to the
349+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
350+ * Boston, MA 02110-1301, USA.
351+ */
352+
353+#include "download.h"
354+#include "error.h"
355+#include "downloads_list_impl.h"
356+
357+namespace Ubuntu {
358+
359+namespace DownloadManager {
360+
361+DownloadsListImpl::DownloadsListImpl(QObject* parent)
362+ : DownloadsList(parent) {
363+}
364+
365+DownloadsListImpl::DownloadsListImpl(
366+ const QList<QSharedPointer<Download> > downs,
367+ QObject* parent)
368+ : DownloadsList(parent),
369+ _downs(downs){
370+}
371+
372+DownloadsListImpl::DownloadsListImpl(Error* err, QObject* parent)
373+ : DownloadsList(parent),
374+ _lastError(err) {
375+}
376+
377+DownloadsListImpl::~DownloadsListImpl() {
378+ delete _lastError;
379+}
380+
381+QList<QSharedPointer<Download> >
382+DownloadsListImpl::downloads() const {
383+ return _downs;
384+}
385+
386+bool
387+DownloadsListImpl::isError() const {
388+ return _lastError != nullptr;
389+}
390+
391+Error*
392+DownloadsListImpl::error() const {
393+ return _lastError;
394+}
395+
396+} // Ubuntu
397+
398+} // DownloadManager
399
400=== added file 'src/downloads/client/ubuntu/download_manager/downloads_list_impl.h'
401--- src/downloads/client/ubuntu/download_manager/downloads_list_impl.h 1970-01-01 00:00:00 +0000
402+++ src/downloads/client/ubuntu/download_manager/downloads_list_impl.h 2014-04-15 13:56:56 +0000
403@@ -0,0 +1,53 @@
404+/*
405+ * Copyright 2014 Canonical Ltd.
406+ *
407+ * This library is free software; you can redistribute it and/or
408+ * modify it under the terms of version 3 of the GNU Lesser General Public
409+ * License as published by the Free Software Foundation.
410+ *
411+ * This program is distributed in the hope that it will be useful,
412+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
413+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
414+ * General Public License for more details.
415+ *
416+ * You should have received a copy of the GNU Lesser General Public
417+ * License along with this library; if not, write to the
418+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
419+ * Boston, MA 02110-1301, USA.
420+ */
421+
422+#ifndef UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_LIST_IMPL_H
423+#define UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_LIST_IMPL_H
424+
425+#include "downloads_list.h"
426+
427+namespace Ubuntu {
428+
429+namespace DownloadManager {
430+
431+class Error;
432+class Download;
433+
434+class DOWNLOAD_MANAGER_EXPORT DownloadsListImpl : public DownloadsList {
435+ Q_OBJECT
436+
437+ public:
438+ DownloadsListImpl(QObject* parent = 0);
439+ DownloadsListImpl(const QList<QSharedPointer<Download >> downs, QObject* parent = 0);
440+ DownloadsListImpl(Error* err, QObject* parent = 0);
441+ virtual ~DownloadsListImpl();
442+
443+ virtual QList<QSharedPointer<Download> > downloads() const;
444+ virtual bool isError() const;
445+ virtual Error* error() const;
446+
447+ private:
448+ QList<QSharedPointer<Download> > _downs;
449+ Error* _lastError = nullptr;
450+};
451+
452+} // Ubuntu
453+
454+} // DownloadManager
455+
456+#endif // UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_LIST_IMPL_H
457
458=== modified file 'src/downloads/client/ubuntu/download_manager/error.h'
459--- src/downloads/client/ubuntu/download_manager/error.h 2014-04-15 13:56:55 +0000
460+++ src/downloads/client/ubuntu/download_manager/error.h 2014-04-15 13:56:56 +0000
461@@ -120,9 +120,11 @@
462
463 friend class ManagerImpl;
464 friend class DownloadImpl;
465- friend class DownloadManagerPendingCallWatcher;
466- friend class DownloadPendingCallWatcher;
467- friend class GroupManagerPendingCallWatcher;
468+ friend class DownloadManagerPCW;
469+ friend class DownloadsListManagerPCW;
470+ friend class MetadataDownloadsListManagerPCW;
471+ friend class DownloadPCW;
472+ friend class GroupManagerPCW;
473
474 /*!
475 Disposes of this error and frees any resources associated with it.
476
477=== modified file 'src/downloads/client/ubuntu/download_manager/group_download.h'
478--- src/downloads/client/ubuntu/download_manager/group_download.h 2014-04-15 13:56:55 +0000
479+++ src/downloads/client/ubuntu/download_manager/group_download.h 2014-04-15 13:56:56 +0000
480@@ -36,7 +36,7 @@
481
482 // allow the manager to create downloads
483 friend class ManagerPrivate;
484- friend class GroupManagerPendingCallWatcher;
485+ friend class GroupManagerPCW;
486
487 public:
488
489
490=== modified file 'src/downloads/client/ubuntu/download_manager/manager.h'
491--- src/downloads/client/ubuntu/download_manager/manager.h 2014-04-15 13:56:55 +0000
492+++ src/downloads/client/ubuntu/download_manager/manager.h 2014-04-15 13:56:56 +0000
493@@ -20,7 +20,6 @@
494 #define UBUNTU_DOWNLOADMANAGER_CLIENT_MANAGER_H
495
496 #include <functional>
497-#include <QList>
498 #include <QObject>
499 #include <ubuntu/download_manager/metatypes.h>
500 #include <ubuntu/download_manager/common.h>
501@@ -33,6 +32,7 @@
502 namespace DownloadManager {
503
504 class Download;
505+class DownloadsList;
506 class Error;
507 class GroupDownload;
508
509@@ -43,6 +43,18 @@
510 typedef std::function<void(Download*)> DownloadCb;
511
512 /*!
513+ Callback to be executed that takes a download list object created by
514+ the manager.
515+*/
516+typedef std::function<void(DownloadsList*)> DownloadsListCb;
517+
518+/*!
519+ Callback to be executed that takes a download list object created by
520+ the manager for a given metadata value.
521+*/
522+typedef std::function<void(const QString&, const QString&, DownloadsList*)> MetadataDownloadsListCb;
523+
524+/*!
525 Callback to be executed that takes a group download object created by
526 the manager.
527 */
528@@ -74,6 +86,15 @@
529 : QObject(parent) {}
530
531 /*!
532+ \fn void getDownloadForId(const QString& id);
533+
534+ Returns a download object for the download with the given id. The
535+ id most be valid else the returned download will be in an unknown
536+ state meaning that most of the download operations will fail.
537+ */
538+ virtual Download* getDownloadForId(const QString& id) = 0;
539+
540+ /*!
541 \fn void createDownload(DownloadStruct downStruct)
542
543 Creates a new download using the data found in the structure.
544@@ -144,10 +165,59 @@
545 StringMap headers,
546 GroupCb cb,
547 GroupCb errCb) = 0;
548+ /*!
549+ \fn void getAllDownloads()
550+
551+ Returns all the downloads in the download manager that can be accessed
552+ by the calling client. If the client is not confined all downloads are
553+ returned, on the other hand if the client is confined the result will
554+ be only those downloads created by the client. The result of the method
555+ is returned via the downloadsFound signal.
556+ */
557+ virtual void getAllDownloads() = 0;
558+
559+ /*!
560+ \fn void getAllDownloads(DownloadsListCb cb, DownloadsListCb errCb)
561+
562+ Returns all the downloads in the download manager that can be accessed
563+ by the calling client. If the client is not confined all downloads are
564+ returned, on the other hand if the client is confined the result will
565+ be only those downloads created by the client. If the method is a
566+ success the \a cb is executed else \a errCb is executed.
567+ */
568+ virtual void getAllDownloads(DownloadsListCb cb,
569+ DownloadsListCb errCb) = 0;
570+ /*!
571+ \fn void getAllDownloadsWithMetadata(const QString &name, const QString &value)
572+
573+ Returns all the downloads in the download manager that can be accessed
574+ by the calling client. If the client is not confined all downloads are
575+ returned, on the other hand if the client is confined the result will
576+ be only those downloads created by the client. The result of the method
577+ is returned via the downloadsWithMetadataFound signal.
578+
579+ */
580+ virtual void getAllDownloadsWithMetadata(const QString &name,
581+ const QString &value) = 0;
582+ /*!
583+ \fn void getAllDownloadsWithMetadata(const QString &name,
584+ const QString &value,
585+ MetadataDownloadsListCb cb,
586+ MetadataDownloadsListCb errCb)
587+
588+ Returns all the downloads in the download manager that can be accessed
589+ by the calling client. If the client is not confined all downloads are
590+ returned, on the other hand if the client is confined the result will
591+ be only those downloads created by the client. If the method is a
592+ success the \a cb is executed else \a errCb is executed.
593+ */
594+ virtual void getAllDownloadsWithMetadata(const QString &name,
595+ const QString &value,
596+ MetadataDownloadsListCb cb,
597+ MetadataDownloadsListCb errCb) = 0;
598
599 /*!
600 \fn bool isError() const
601-
602 Returns if the manager received an error during the execution
603 of a command.
604 */
605@@ -249,6 +319,10 @@
606 download manager.
607 */
608 void downloadCreated(Download* down);
609+ void downloadsFound(DownloadsList* downloads);
610+ void downloadsWithMetadataFound(const QString& name,
611+ const QString& value,
612+ DownloadsList* downloads);
613
614 /*!
615 \fn void groupCreated(GroupDownload* down)
616
617=== modified file 'src/downloads/client/ubuntu/download_manager/manager_impl.cpp'
618--- src/downloads/client/ubuntu/download_manager/manager_impl.cpp 2014-04-15 13:56:55 +0000
619+++ src/downloads/client/ubuntu/download_manager/manager_impl.cpp 2014-04-15 13:56:56 +0000
620@@ -18,6 +18,8 @@
621
622 #include <QDebug>
623 #include <glog/logging.h>
624+#include "download_impl.h"
625+#include "downloads_list.h"
626 #include "manager_impl.h"
627
628 namespace {
629@@ -65,6 +67,7 @@
630 qRegisterMetaType<NetworkError*>("NetworkError*");
631 qRegisterMetaType<AuthError*>("AuthError*");
632 qRegisterMetaType<ProcessError*>("ProcessError*");
633+ qRegisterMetaType<DownloadsList*>("DownloadsList*");
634 qDBusRegisterMetaType<StringMap>();
635 qDBusRegisterMetaType<DownloadStruct>();
636 qDBusRegisterMetaType<GroupDownloadStruct>();
637@@ -75,17 +78,16 @@
638 qDBusRegisterMetaType<ProcessErrorStruct>();
639 }
640
641+Download*
642+ManagerImpl::getDownloadForId(const QString& id) {
643+ auto down = new DownloadImpl(_conn, _servicePath, QDBusObjectPath(id));
644+ return down;
645+}
646+
647 void
648 ManagerImpl::createDownload(DownloadStruct downStruct) {
649- QDBusPendingCall call =
650- _dbusInterface->createDownload(downStruct);
651 DownloadCb cb = [](Download*) {};
652-
653- auto watcher = new DownloadManagerPendingCallWatcher(_conn,
654- _servicePath, call, cb, cb, this);
655- CHECK(connect(watcher,
656- &DownloadManagerPendingCallWatcher::callbackExecuted,
657- this, &ManagerImpl::onWatcherDone)) << "Could not connect to signal";
658+ createDownload(downStruct, cb, cb);
659 }
660
661 void
662@@ -94,10 +96,9 @@
663 DownloadCb errCb) {
664 QDBusPendingCall call =
665 _dbusInterface->createDownload(downStruct);
666- auto watcher = new DownloadManagerPendingCallWatcher(_conn,
667+ auto watcher = new DownloadManagerPCW(_conn,
668 _servicePath, call, cb, errCb, this);
669- CHECK(connect(watcher,
670- &DownloadManagerPendingCallWatcher::callbackExecuted,
671+ CHECK(connect(watcher, &DownloadManagerPCW::callbackExecuted,
672 this, &ManagerImpl::onWatcherDone)) << "Could not connect to signal";
673 }
674
675@@ -107,16 +108,8 @@
676 bool allowed3G,
677 const QVariantMap& metadata,
678 StringMap headers) {
679- QDBusPendingCall call =
680- _dbusInterface->createDownloadGroup(downs,
681- algorithm, allowed3G, metadata, headers);
682-
683 GroupCb cb = [](GroupDownload*) {};
684-
685- auto watcher = new GroupManagerPendingCallWatcher(_conn, _servicePath,
686- call, cb, cb, this);
687- CHECK(connect(watcher, &GroupManagerPendingCallWatcher::callbackExecuted,
688- this, &ManagerImpl::onWatcherDone)) << "Could not connect to signal";
689+ createDownload(downs, algorithm, allowed3G, metadata, headers, cb, cb);
690 }
691
692 void
693@@ -130,9 +123,45 @@
694 QDBusPendingCall call =
695 _dbusInterface->createDownloadGroup(downs,
696 algorithm, allowed3G, metadata, headers);
697- auto watcher = new GroupManagerPendingCallWatcher(_conn, _servicePath,
698+ auto watcher = new GroupManagerPCW(_conn, _servicePath,
699 call, cb, errCb, this);
700- CHECK(connect(watcher, &GroupManagerPendingCallWatcher::callbackExecuted,
701+ CHECK(connect(watcher, &GroupManagerPCW::callbackExecuted,
702+ this, &ManagerImpl::onWatcherDone)) << "Could not connect to signal";
703+}
704+
705+void
706+ManagerImpl::getAllDownloads() {
707+ DownloadsListCb cb = [](DownloadsList*){};
708+ getAllDownloads(cb, cb);
709+}
710+
711+void
712+ManagerImpl::getAllDownloads(DownloadsListCb cb, DownloadsListCb errCb) {
713+ QDBusPendingCall call = _dbusInterface->getAllDownloads();
714+ auto watcher = new DownloadsListManagerPCW(
715+ _conn, _servicePath, call, cb, errCb, this);
716+ CHECK(connect(watcher, &GroupManagerPCW::callbackExecuted,
717+ this, &ManagerImpl::onWatcherDone)) << "Could not connect to signal";
718+}
719+
720+void
721+ManagerImpl::getAllDownloadsWithMetadata(const QString &name,
722+ const QString &value) {
723+ MetadataDownloadsListCb cb =
724+ [](const QString&, const QString&, DownloadsList*){};
725+ getAllDownloadsWithMetadata(name, value, cb, cb);
726+}
727+
728+void
729+ManagerImpl::getAllDownloadsWithMetadata(const QString &name,
730+ const QString &value,
731+ MetadataDownloadsListCb cb,
732+ MetadataDownloadsListCb errCb) {
733+ QDBusPendingCall call = _dbusInterface->getAllDownloadsWithMetadata(
734+ name, value);
735+ auto watcher = new MetadataDownloadsListManagerPCW(
736+ _conn, _servicePath, call, name, value, cb, errCb, this);
737+ CHECK(connect(watcher, &GroupManagerPCW::callbackExecuted,
738 this, &ManagerImpl::onWatcherDone)) << "Could not connect to signal";
739 }
740
741
742=== modified file 'src/downloads/client/ubuntu/download_manager/manager_impl.h'
743--- src/downloads/client/ubuntu/download_manager/manager_impl.h 2014-04-15 13:56:55 +0000
744+++ src/downloads/client/ubuntu/download_manager/manager_impl.h 2014-04-15 13:56:56 +0000
745@@ -46,11 +46,12 @@
746
747 // allow watchers to emit the signals
748 friend class Manager;
749- friend class DownloadManagerPendingCallWatcher;
750- friend class GroupManagerPendingCallWatcher;
751+ friend class DownloadManagerPCW;
752+ friend class GroupManagerPCW;
753
754 public:
755 virtual ~ManagerImpl();
756+ virtual Download* getDownloadForId(const QString& id);
757 virtual void createDownload(DownloadStruct downStruct);
758 virtual void createDownload(DownloadStruct downStruct,
759 DownloadCb cb,
760@@ -67,6 +68,15 @@
761 StringMap headers,
762 GroupCb cb,
763 GroupCb errCb);
764+ virtual void getAllDownloads();
765+ virtual void getAllDownloads(DownloadsListCb cb,
766+ DownloadsListCb errCb);
767+ virtual void getAllDownloadsWithMetadata(const QString &name,
768+ const QString &value);
769+ virtual void getAllDownloadsWithMetadata(const QString &name,
770+ const QString &value,
771+ MetadataDownloadsListCb cb,
772+ MetadataDownloadsListCb errCb);
773
774 bool isError() const;
775 Error* lastError() const;
776
777=== modified file 'src/downloads/client/ubuntu/download_manager/manager_pendingcall_watcher.cpp'
778--- src/downloads/client/ubuntu/download_manager/manager_pendingcall_watcher.cpp 2014-04-15 13:56:55 +0000
779+++ src/downloads/client/ubuntu/download_manager/manager_pendingcall_watcher.cpp 2014-04-15 13:56:56 +0000
780@@ -21,6 +21,7 @@
781 #include <QDBusObjectPath>
782 #include <glog/logging.h>
783 #include "download_impl.h"
784+#include "downloads_list_impl.h"
785 #include "error.h"
786 #include "group_download.h"
787 #include "manager.h"
788@@ -30,28 +31,27 @@
789
790 namespace DownloadManager {
791
792-DownloadManagerPendingCallWatcher::DownloadManagerPendingCallWatcher(
793- const QDBusConnection& conn,
794- const QString& servicePath,
795- const QDBusPendingCall& call,
796- DownloadCb cb,
797- DownloadCb errCb,
798- QObject* parent)
799+DownloadManagerPCW::DownloadManagerPCW(const QDBusConnection& conn,
800+ const QString& servicePath,
801+ const QDBusPendingCall& call,
802+ DownloadCb cb,
803+ DownloadCb errCb,
804+ QObject* parent)
805 : PendingCallWatcher(conn, servicePath, call, parent),
806 _cb(cb),
807 _errCb(errCb) {
808 CHECK(connect(this, &QDBusPendingCallWatcher::finished,
809- this, &DownloadManagerPendingCallWatcher::onFinished))
810+ this, &DownloadManagerPCW::onFinished))
811 << "Could not connect to signal";
812 }
813
814 void
815-DownloadManagerPendingCallWatcher::onFinished(QDBusPendingCallWatcher* watcher) {
816+DownloadManagerPCW::onFinished(QDBusPendingCallWatcher* watcher) {
817 QDBusPendingReply<QDBusObjectPath> reply = *watcher;
818 auto man = static_cast<Manager*>(parent());
819 if (reply.isError()) {
820 qDebug() << "ERROR" << reply.error() << reply.error().type();
821- // creater error and deal with it
822+ // create error and deal with it
823 auto err = new DBusError(reply.error());
824 auto down = new DownloadImpl(_conn, err);
825 _errCb(down);
826@@ -67,24 +67,115 @@
827 watcher->deleteLater();
828 }
829
830-
831-GroupManagerPendingCallWatcher::GroupManagerPendingCallWatcher(
832- const QDBusConnection& conn,
833- const QString& servicePath,
834- const QDBusPendingCall& call,
835- GroupCb cb,
836- GroupCb errCb,
837- QObject* parent)
838+DownloadsListManagerPCW::DownloadsListManagerPCW(const QDBusConnection& conn,
839+ const QString& servicePath,
840+ const QDBusPendingCall& call,
841+ DownloadsListCb cb,
842+ DownloadsListCb errCb,
843+ QObject* parent)
844+ : PendingCallWatcher(conn, servicePath, call, parent),
845+ _cb(cb),
846+ _errCb(errCb) {
847+ connect(this, &QDBusPendingCallWatcher::finished,
848+ this, &DownloadsListManagerPCW::onFinished);
849+}
850+
851+void
852+DownloadsListManagerPCW::onFinished(QDBusPendingCallWatcher* watcher) {
853+ QDBusPendingReply<QList<QDBusObjectPath> > reply = *watcher;
854+ DownloadsListImpl* list;
855+ auto man = static_cast<Manager*>(parent());
856+ if (reply.isError()) {
857+ qDebug() << "ERROR" << reply.error() << reply.error().type();
858+ // create error and deal with it
859+ auto err = new DBusError(reply.error());
860+ list = new DownloadsListImpl(err);
861+ _errCb(list);
862+ emit man->downloadsFound(list);
863+ } else {
864+ qDebug() << "Success!";
865+ auto paths = reply.value();
866+ QList<QSharedPointer<Download> > downloads;
867+ list = new DownloadsListImpl();
868+ foreach(const QDBusObjectPath& path, paths) {
869+ QSharedPointer<Download> down =
870+ QSharedPointer<Download>(new DownloadImpl(_conn,
871+ _servicePath, path));
872+ downloads.append(down);
873+ }
874+ list = new DownloadsListImpl(downloads);
875+ emit man->downloadsFound(list);
876+ _cb(list);
877+ }
878+ emit callbackExecuted();
879+ watcher->deleteLater();
880+}
881+
882+MetadataDownloadsListManagerPCW::MetadataDownloadsListManagerPCW(
883+ const QDBusConnection& conn,
884+ const QString& servicePath,
885+ const QDBusPendingCall& call,
886+ const QString& key,
887+ const QString& value,
888+ MetadataDownloadsListCb cb,
889+ MetadataDownloadsListCb errCb,
890+ QObject* parent)
891+ : PendingCallWatcher(conn, servicePath, call, parent),
892+ _key(key),
893+ _value(value),
894+ _cb(cb),
895+ _errCb(errCb) {
896+ connect(this, &QDBusPendingCallWatcher::finished,
897+ this, &MetadataDownloadsListManagerPCW::onFinished);
898+}
899+
900+void
901+MetadataDownloadsListManagerPCW::onFinished(QDBusPendingCallWatcher* watcher) {
902+ QDBusPendingReply<QList<QDBusObjectPath> > reply = *watcher;
903+ DownloadsListImpl* list;
904+ auto man = static_cast<Manager*>(parent());
905+ if (reply.isError()) {
906+ qDebug() << "ERROR" << reply.error() << reply.error().type();
907+ // create error and deal with it
908+ auto err = new DBusError(reply.error());
909+ list = new DownloadsListImpl(err);
910+ _errCb(_key, _value, list);
911+ emit man->downloadsWithMetadataFound(_key, _value, list);
912+ } else {
913+ qDebug() << "Success!";
914+ auto paths = reply.value();
915+ QList<QSharedPointer<Download> > downloads;
916+ list = new DownloadsListImpl();
917+ foreach(const QDBusObjectPath& path, paths) {
918+ QSharedPointer<Download> down =
919+ QSharedPointer<Download>(new DownloadImpl(
920+ _conn, _servicePath, path));
921+ downloads.append(down);
922+ }
923+ list = new DownloadsListImpl(downloads);
924+ emit man->downloadsWithMetadataFound(_key, _value, list);
925+ _cb(_key, _value, list);
926+ }
927+ emit callbackExecuted();
928+ watcher->deleteLater();
929+}
930+
931+GroupManagerPCW::GroupManagerPCW(const QDBusConnection& conn,
932+ const QString& servicePath,
933+ const QDBusPendingCall& call,
934+ GroupCb cb,
935+ GroupCb errCb,
936+ QObject* parent)
937 : PendingCallWatcher(conn, servicePath, call, parent),
938 _cb(cb),
939 _errCb(errCb) {
940 CHECK(connect(this, &QDBusPendingCallWatcher::finished,
941- this, &GroupManagerPendingCallWatcher::onFinished))
942+ this, &GroupManagerPCW::onFinished))
943 << "Could not connect to signal";
944 }
945
946 void
947-GroupManagerPendingCallWatcher::onFinished(QDBusPendingCallWatcher* watcher) {
948+GroupManagerPCW::onFinished(QDBusPendingCallWatcher* watcher) {
949 QDBusPendingReply<QDBusObjectPath> reply = *watcher;
950 auto man = static_cast<Manager*>(parent());
951 if (reply.isError()) {
952
953=== modified file 'src/downloads/client/ubuntu/download_manager/manager_pendingcall_watcher.h'
954--- src/downloads/client/ubuntu/download_manager/manager_pendingcall_watcher.h 2014-01-13 17:26:28 +0000
955+++ src/downloads/client/ubuntu/download_manager/manager_pendingcall_watcher.h 2014-04-15 13:56:56 +0000
956@@ -27,23 +27,26 @@
957 namespace DownloadManager {
958
959 class Download;
960+class DownloadsList;
961 class Error;
962 class GroupDownload;
963
964 typedef std::function<void(Download*)> DownloadCb;
965+typedef std::function<void(DownloadsList*)> DownloadsListCb;
966+typedef std::function<void(const QString&, const QString&, DownloadsList*)> MetadataDownloadsListCb;
967 typedef std::function<void(GroupDownload*)> GroupCb;
968
969
970-class DownloadManagerPendingCallWatcher : public PendingCallWatcher {
971+class DownloadManagerPCW : public PendingCallWatcher {
972 Q_OBJECT
973
974 public:
975- DownloadManagerPendingCallWatcher(const QDBusConnection& conn,
976- const QString& servicePath,
977- const QDBusPendingCall& call,
978- DownloadCb cb,
979- DownloadCb errCb,
980- QObject* parent = 0);
981+ DownloadManagerPCW(const QDBusConnection& conn,
982+ const QString& servicePath,
983+ const QDBusPendingCall& call,
984+ DownloadCb cb,
985+ DownloadCb errCb,
986+ QObject* parent = 0);
987
988 private slots:
989 void onFinished(QDBusPendingCallWatcher* watcher);
990@@ -54,16 +57,56 @@
991 };
992
993
994-class GroupManagerPendingCallWatcher : public PendingCallWatcher {
995- Q_OBJECT
996-
997- public:
998- GroupManagerPendingCallWatcher(const QDBusConnection& conn,
999- const QString& servicePath,
1000- const QDBusPendingCall& call,
1001- GroupCb cb,
1002- GroupCb errCb,
1003- QObject* parent = 0);
1004+class DownloadsListManagerPCW : public PendingCallWatcher {
1005+ Q_OBJECT
1006+
1007+ public:
1008+ DownloadsListManagerPCW(const QDBusConnection& conn,
1009+ const QString& servicePath,
1010+ const QDBusPendingCall& call,
1011+ DownloadsListCb cb,
1012+ DownloadsListCb errCb,
1013+ QObject* parent = 0);
1014+ private slots:
1015+ void onFinished(QDBusPendingCallWatcher* watcher);
1016+
1017+ private:
1018+ DownloadsListCb _cb;
1019+ DownloadsListCb _errCb;
1020+};
1021+
1022+class MetadataDownloadsListManagerPCW : public PendingCallWatcher {
1023+ Q_OBJECT
1024+
1025+ public:
1026+ MetadataDownloadsListManagerPCW(const QDBusConnection& conn,
1027+ const QString& servicePath,
1028+ const QDBusPendingCall& call,
1029+ const QString& key,
1030+ const QString& value,
1031+ MetadataDownloadsListCb cb,
1032+ MetadataDownloadsListCb errCb,
1033+ QObject* parent = 0);
1034+ private slots:
1035+ void onFinished(QDBusPendingCallWatcher* watcher);
1036+
1037+ private:
1038+ const QString& _key;
1039+ const QString& _value;
1040+ MetadataDownloadsListCb _cb;
1041+ MetadataDownloadsListCb _errCb;
1042+};
1043+
1044+class GroupManagerPCW : public PendingCallWatcher {
1045+ Q_OBJECT
1046+
1047+ public:
1048+ GroupManagerPCW(const QDBusConnection& conn,
1049+ const QString& servicePath,
1050+ const QDBusPendingCall& call,
1051+ GroupCb cb,
1052+ GroupCb errCb,
1053+ QObject* parent = 0);
1054
1055 private slots:
1056 void onFinished(QDBusPendingCallWatcher* watcher);
1057
1058=== modified file 'src/downloads/priv/ubuntu/downloads/download_adaptor.cpp'
1059--- src/downloads/priv/ubuntu/downloads/download_adaptor.cpp 2014-04-15 13:56:55 +0000
1060+++ src/downloads/priv/ubuntu/downloads/download_adaptor.cpp 2014-04-15 13:56:56 +0000
1061@@ -81,6 +81,12 @@
1062 QMetaObject::invokeMethod(parent(), "resume");
1063 }
1064
1065+void DownloadAdaptor::setDestinationDir(const QString &path)
1066+{
1067+ // handle method call com.canonical.applications.Download.setDestinationDir
1068+ QMetaObject::invokeMethod(parent(), "setDestinationDir", Q_ARG(QString, path));
1069+}
1070+
1071 void DownloadAdaptor::setThrottle(qulonglong speed)
1072 {
1073 // handle method call com.canonical.applications.Download.setThrottle
1074
1075=== modified file 'src/downloads/priv/ubuntu/downloads/download_adaptor.h'
1076--- src/downloads/priv/ubuntu/downloads/download_adaptor.h 2014-02-11 15:35:52 +0000
1077+++ src/downloads/priv/ubuntu/downloads/download_adaptor.h 2014-04-15 13:56:56 +0000
1078@@ -50,6 +50,9 @@
1079 " <method name=\"throttle\">\n"
1080 " <arg direction=\"out\" type=\"t\" name=\"speed\"/>\n"
1081 " </method>\n"
1082+" <method name=\"setDestinationDir\">\n"
1083+" <arg direction=\"in\" type=\"s\" name=\"path\"/>\n"
1084+" </method>\n"
1085 " <method name=\"allowGSMDownload\">\n"
1086 " <arg direction=\"in\" type=\"b\" name=\"allowed\"/>\n"
1087 " </method>\n"
1088@@ -116,6 +119,7 @@
1089 void pause();
1090 qulonglong progress();
1091 void resume();
1092+ void setDestinationDir(const QString &path);
1093 void setThrottle(qulonglong speed);
1094 void start();
1095 qulonglong throttle();
1096
1097=== modified file 'src/downloads/priv/ubuntu/downloads/file_download.cpp'
1098--- src/downloads/priv/ubuntu/downloads/file_download.cpp 2014-04-15 13:56:55 +0000
1099+++ src/downloads/priv/ubuntu/downloads/file_download.cpp 2014-04-15 13:56:56 +0000
1100@@ -29,6 +29,8 @@
1101 #include <ubuntu/transfers/system/logger.h>
1102 #include <ubuntu/transfers/system/network_reply.h>
1103 #include <ubuntu/transfers/system/filename_mutex.h>
1104+#include <ubuntu/transfers/system/uuid_factory.h>
1105+#include <ubuntu/transfers/system/uuid_utils.h>
1106 #include "file_download.h"
1107
1108 #define DOWN_LOG(LEVEL) LOG(LEVEL) << ((parent() != nullptr)?"GroupDownload {" + parent()->objectName() + " } ":"") << "Download ID{" << objectName() << " } "
1109@@ -63,6 +65,7 @@
1110 const QMap<QString, QString>& headers,
1111 QObject* parent)
1112 : Download(id, path, isConfined, rootPath, metadata, headers, parent),
1113+ QDBusContext(),
1114 _totalSize(0),
1115 _url(url),
1116 _hash(""),
1117@@ -81,6 +84,7 @@
1118 const QMap<QString, QString> &headers,
1119 QObject* parent)
1120 : Download(id, path, isConfined, rootPath, metadata, headers, parent),
1121+ QDBusContext(),
1122 _totalSize(0),
1123 _url(url),
1124 _hash(hash) {
1125@@ -237,6 +241,66 @@
1126 }
1127
1128 void
1129+FileDownload::setDestinationDir(const QString& path) {
1130+ // we have to perform several checks to ensure the integrity
1131+ // of the download
1132+ // 1. Trust apparmor that it will bock the call of this method
1133+ // from not confined apps
1134+ // 2. Ensure that the path is an absolute path.
1135+ // 3. Ensure that the path does exist.
1136+ // 4. Ensure that the path is a dir.
1137+ // 5. Ensure that the download was not started
1138+ QFileInfo info(path);
1139+ if (!info.isAbsolute()) {
1140+ DOWN_LOG(WARNING) << "Trying to set destination dir to '"
1141+ << path << "' when the path is not absolute.";
1142+ if (calledFromDBus()) {
1143+ sendErrorReply(QDBusError::InvalidArgs,
1144+ "The destination dir must be an absolute path.");
1145+ }
1146+ return;
1147+ }
1148+
1149+ if (!info.exists()) {
1150+ DOWN_LOG(WARNING) << "Trying to set destination dir to '"
1151+ << path << "' when the path does not exists.";
1152+ if (calledFromDBus()) {
1153+ sendErrorReply(QDBusError::InvalidArgs,
1154+ "The destination dir must be already present in the system.");
1155+ }
1156+ return;
1157+ }
1158+
1159+ if (!info.isDir()) {
1160+ DOWN_LOG(WARNING) << "Trying to set destination dir to '"
1161+ << path << "' when the path is not a dir.";
1162+ if (calledFromDBus()) {
1163+ sendErrorReply(QDBusError::InvalidArgs,
1164+ "The destination dir must be a dir and a file was found.");
1165+ }
1166+ return;
1167+ }
1168+
1169+ if (state() == Download::IDLE) {
1170+ // calculate the new path before we unlock the old one
1171+ auto desiredPath = path;
1172+ if (!desiredPath.endsWith(QDir::separator())) {
1173+ desiredPath += QDir::separator();
1174+ }
1175+ desiredPath += _basename;
1176+ desiredPath = _fileNameMutex->lockFileName(desiredPath);
1177+ _tempFilePath = desiredPath + TEMP_EXTENSION;
1178+ _fileNameMutex->unlockFileName(_filePath);
1179+ _filePath = desiredPath;
1180+ } else {
1181+ if (calledFromDBus()) {
1182+ sendErrorReply(QDBusError::NotSupported,
1183+ "The path cannot be changed in a started download.");
1184+ }
1185+ }
1186+}
1187+
1188+void
1189 FileDownload::onDownloadProgress(qint64 currentProgress, qint64 bytesTotal) {
1190 TRACE << _url << currentProgress << bytesTotal;
1191
1192@@ -603,10 +667,12 @@
1193 // the mutex will ensure that we do not have race conditions about
1194 // the file names in the download manager
1195 QString path = _url.path();
1196- QString basename = QFileInfo(path).fileName();
1197+ _basename = QFileInfo(path).fileName();
1198
1199- if (basename.isEmpty())
1200- basename = DATA_FILE_NAME;
1201+ if (_basename.isEmpty()) {
1202+ QScopedPointer<UuidFactory> uuidFactory(new UuidFactory());
1203+ _basename = UuidUtils::getDBusString(uuidFactory->createUuid());
1204+ }
1205
1206 auto metadataMap = metadata();
1207
1208@@ -624,7 +690,7 @@
1209 _filePath));
1210 }
1211 } else {
1212- auto desiredPath = rootPath() + QDir::separator() + basename;
1213+ auto desiredPath = rootPath() + QDir::separator() + _basename;
1214 _filePath = _fileNameMutex->lockFileName(desiredPath);
1215 _tempFilePath = _filePath + TEMP_EXTENSION;
1216 }
1217
1218=== modified file 'src/downloads/priv/ubuntu/downloads/file_download.h'
1219--- src/downloads/priv/ubuntu/downloads/file_download.h 2014-04-15 13:56:55 +0000
1220+++ src/downloads/priv/ubuntu/downloads/file_download.h 2014-04-15 13:56:56 +0000
1221@@ -19,6 +19,7 @@
1222 #ifndef DOWNLOADER_LIB_SINGLE_DOWNLOAD_H
1223 #define DOWNLOADER_LIB_SINGLE_DOWNLOAD_H
1224
1225+#include <QtDBus/QDBusContext>
1226 #include <QFile>
1227 #include <QNetworkReply>
1228 #include <QProcess>
1229@@ -41,7 +42,7 @@
1230
1231 namespace Daemon {
1232
1233-class FileDownload : public Download {
1234+class FileDownload : public Download, public QDBusContext {
1235 Q_OBJECT
1236
1237 public:
1238@@ -92,6 +93,7 @@
1239 qulonglong progress() override;
1240 qulonglong totalSize() override;
1241 virtual void setThrottle(qulonglong speed) override;
1242+ virtual void setDestinationDir(const QString& path);
1243
1244 signals:
1245 void finished(const QString& path);
1246@@ -132,6 +134,7 @@
1247 bool _connected = false;
1248 qulonglong _totalSize = 0;
1249 QUrl _url;
1250+ QString _basename;
1251 QString _filePath;
1252 QString _tempFilePath;
1253 QString _hash;
1254
1255=== modified file 'src/downloads/test-daemon/testing_file_download.h'
1256--- src/downloads/test-daemon/testing_file_download.h 2014-04-15 13:56:55 +0000
1257+++ src/downloads/test-daemon/testing_file_download.h 2014-04-15 13:56:56 +0000
1258@@ -26,7 +26,7 @@
1259
1260 using namespace Ubuntu::DownloadManager::Daemon;
1261
1262-class TestingFileDownload : public FileDownload, public QDBusContext {
1263+class TestingFileDownload : public FileDownload {
1264 Q_OBJECT
1265
1266 public:
1267
1268=== modified file 'tests/test_client_download.cpp'
1269--- tests/test_client_download.cpp 2014-04-15 13:56:55 +0000
1270+++ tests/test_client_download.cpp 2014-04-15 13:56:56 +0000
1271@@ -16,6 +16,7 @@
1272 * Boston, MA 02110-1301, USA.
1273 */
1274
1275+#include <QDir>
1276 #include <QNetworkReply>
1277 #include <ubuntu/download_manager/error.h>
1278 #include "test_client_download.h"
1279@@ -252,11 +253,11 @@
1280 QTest::addColumn<QString>("standardError");
1281
1282 QTest::newRow("Failed To Start") << 0 << "Failed To Start"
1283- << -1 << "" << "";
1284+ << -1 << "" << "";
1285 QTest::newRow("Crashed") << 1 << "Crashed" << -1 << "Calculating.."
1286- << "NULL pointer";
1287+ << "NULL pointer";
1288 QTest::newRow("Timedout") << 2 << "Timedout" << -1 << "stdout"
1289- << "";
1290+ << "";
1291 }
1292
1293 void
1294@@ -289,4 +290,51 @@
1295 QCOMPARE(standardError, processError->standardError());
1296 }
1297
1298+void
1299+TestDownload::testSetLocalDirectory() {
1300+ auto path = testDirectory();
1301+ _down->setDestinationDir(path);
1302+ QVERIFY(!_down->isError());
1303+ QVERIFY(_down->error() == nullptr);
1304+}
1305+
1306+void
1307+TestDownload::testSetLocalDirectoryNotAbsolute() {
1308+ _down->setDestinationDir("./test");
1309+ QVERIFY(_down->isError());
1310+ QVERIFY(_down->error() != nullptr);
1311+ QCOMPARE(Error::DBus, _down->error()->type());
1312+}
1313+
1314+void
1315+TestDownload::testSetLocalDirectoryNotPresent() {
1316+ _down->setDestinationDir("/etc/test");
1317+ QVERIFY(_down->isError());
1318+ QVERIFY(_down->error() != nullptr);
1319+ QCOMPARE(Error::DBus, _down->error()->type());
1320+}
1321+
1322+void
1323+TestDownload::testSetLocalDirectoryNotDir() {
1324+ auto path = testDirectory() + QDir::separator() + "test";
1325+ QFile file(path);
1326+ file.open(QIODevice::ReadWrite | QFile::Append);
1327+ file.write(QByteArray(100, 'w'));
1328+ file.close();
1329+ _down->setDestinationDir(path);
1330+ QVERIFY(_down->isError());
1331+ QVERIFY(_down->error() != nullptr);
1332+ QCOMPARE(Error::DBus, _down->error()->type());
1333+}
1334+
1335+void
1336+TestDownload::testSetLocalDirectoryStarted() {
1337+ auto path = testDirectory();
1338+ _down->start();
1339+ _down->setDestinationDir(path);
1340+ QVERIFY(_down->isError());
1341+ QVERIFY(_down->error() != nullptr);
1342+ QCOMPARE(Error::DBus, _down->error()->type());
1343+}
1344+
1345 QTEST_MAIN(TestDownload)
1346
1347=== modified file 'tests/test_client_download.h'
1348--- tests/test_client_download.h 2014-04-15 13:56:55 +0000
1349+++ tests/test_client_download.h 2014-04-15 13:56:56 +0000
1350@@ -55,6 +55,13 @@
1351 void testProcessErrorRaised_data();
1352 void testProcessErrorRaised();
1353
1354+ // set local dir tests
1355+ void testSetLocalDirectory();
1356+ void testSetLocalDirectoryNotAbsolute();
1357+ void testSetLocalDirectoryNotPresent();
1358+ void testSetLocalDirectoryNotDir();
1359+ void testSetLocalDirectoryStarted();
1360+
1361 private:
1362 QString _url;
1363 QVariantMap _metadata;
1364
1365=== modified file 'tests/test_client_manager.cpp'
1366--- tests/test_client_manager.cpp 2014-04-15 13:56:55 +0000
1367+++ tests/test_client_manager.cpp 2014-04-15 13:56:56 +0000
1368@@ -18,6 +18,7 @@
1369
1370 #include <QDebug>
1371 #include <ubuntu/download_manager/download.h>
1372+#include <ubuntu/download_manager/downloads_list.h>
1373 #include "test_client_manager.h"
1374
1375 TestManager::TestManager(QObject *parent)
1376@@ -136,4 +137,205 @@
1377 delete down;
1378 }
1379
1380+void
1381+TestManager::testGetAllDownloadsSignalsEmitted_data() {
1382+ QTest::addColumn<int>("count");
1383+
1384+ QTest::newRow("5 downloads") << 5;
1385+ QTest::newRow("10 downloads") << 10;
1386+ QTest::newRow("15 downloads") << 15;
1387+}
1388+
1389+void
1390+TestManager::testGetAllDownloadsSignalsEmitted() {
1391+ QFETCH(int, count);
1392+
1393+ QString url = "http://example.com/";
1394+ QVariantMap metadata;
1395+ QMap<QString, QString> headers;
1396+
1397+ SignalBarrier managerSpy(_man, SIGNAL(downloadCreated(Download*)));
1398+ SignalBarrier listSpy(_man, SIGNAL(downloadsFound(DownloadsList*)));
1399+
1400+ for (int index = 0; index < count; index++) {
1401+ url += index;
1402+ DownloadStruct downStruct(url, metadata, headers);
1403+ _man->createDownload(downStruct);
1404+ }
1405+
1406+ // ensure that all of the are created
1407+ QVERIFY(managerSpy.ensureSignalEmitted());
1408+ QTRY_COMPARE(count, managerSpy.count());
1409+ _man->getAllDownloads();
1410+
1411+ QVERIFY(listSpy.ensureSignalEmitted());
1412+ QTRY_COMPARE(1, listSpy.count());
1413+ auto downs = listSpy.takeFirst().at(0).value<DownloadsList*>();
1414+ QCOMPARE(count, downs->downloads().count());
1415+
1416+ delete downs;
1417+}
1418+
1419+void
1420+TestManager::testGetAllDownloadsSignalsEmittedCallbacks_data() {
1421+ QTest::addColumn<int>("count");
1422+
1423+ QTest::newRow("5 downloads") << 5;
1424+ QTest::newRow("10 downloads") << 10;
1425+ QTest::newRow("15 downloads") << 15;
1426+}
1427+
1428+void
1429+TestManager::testGetAllDownloadsSignalsEmittedCallbacks() {
1430+ QFETCH(int, count);
1431+
1432+ QString url = "http://example.com/";
1433+ QVariantMap metadata;
1434+ QMap<QString, QString> headers;
1435+ DownloadsListCb cb = [](DownloadsList*){};
1436+
1437+ SignalBarrier managerSpy(_man, SIGNAL(downloadCreated(Download*)));
1438+ SignalBarrier listSpy(_man, SIGNAL(downloadsFound(DownloadsList*)));
1439+
1440+ for (int index = 0; index < count; index++) {
1441+ url += index;
1442+ DownloadStruct downStruct(url, metadata, headers);
1443+ _man->createDownload(downStruct);
1444+ }
1445+
1446+ // ensure that all of the are created
1447+ QVERIFY(managerSpy.ensureSignalEmitted());
1448+ QTRY_COMPARE(count, managerSpy.count());
1449+ _man->getAllDownloads(cb, cb);
1450+
1451+ QVERIFY(listSpy.ensureSignalEmitted());
1452+ QTRY_COMPARE(1, listSpy.count());
1453+ auto downs = listSpy.takeFirst().at(0).value<DownloadsList*>();
1454+ QCOMPARE(count, downs->downloads().count());
1455+
1456+ delete downs;
1457+}
1458+
1459+void
1460+TestManager::testGetAllDownloadsMetadataSignalsEmitted_data() {
1461+ QTest::addColumn<int>("count");
1462+
1463+ QTest::newRow("5 downloads") << 5;
1464+ QTest::newRow("10 downloads") << 10;
1465+ QTest::newRow("15 downloads") << 15;
1466+}
1467+
1468+void
1469+TestManager::testGetAllDownloadsMetadataSignalsEmitted() {
1470+ QFETCH(int, count);
1471+ int metadataCount = 5;
1472+ QString key = "test";
1473+ QString value = "metadata";
1474+
1475+ QString url = "http://example.com/";
1476+ QVariantMap metadata;
1477+ QMap<QString, QString> headers;
1478+
1479+ SignalBarrier managerSpy(_man, SIGNAL(downloadCreated(Download*)));
1480+ SignalBarrier listSpy(_man, SIGNAL(
1481+ downloadsWithMetadataFound(const QString&, const QString&,
1482+ DownloadsList*)));
1483+
1484+ for (int index = 0; index < count; index++) {
1485+ url += index;
1486+ DownloadStruct downStruct(url, metadata, headers);
1487+ _man->createDownload(downStruct);
1488+ }
1489+
1490+ // add downloads with metadata
1491+ metadata[key] = value;
1492+ for (int index = count; index < metadataCount + count; index++) {
1493+ url += index;
1494+ DownloadStruct downStruct(url, metadata, headers);
1495+ _man->createDownload(downStruct);
1496+ }
1497+ // ensure that all of the are created
1498+ QVERIFY(managerSpy.ensureSignalEmitted());
1499+ QTRY_COMPARE(count + metadataCount, managerSpy.count());
1500+ _man->getAllDownloadsWithMetadata(key, value);
1501+
1502+ QVERIFY(listSpy.ensureSignalEmitted());
1503+ QTRY_COMPARE(1, listSpy.count());
1504+
1505+ auto signalInfo = listSpy.takeFirst();
1506+ auto signalKey = signalInfo.at(0).toString();
1507+ QCOMPARE(key, signalKey);
1508+
1509+ auto signalValue = signalInfo.at(1).toString();
1510+ QCOMPARE(value, signalValue);
1511+
1512+ auto downs = signalInfo.at(2).value<DownloadsList*>();
1513+
1514+ QCOMPARE(metadataCount, downs->downloads().count());
1515+
1516+ delete downs;
1517+}
1518+
1519+void
1520+TestManager::testGetAllDownloadsMetadataSignalsEmittedCallbacks_data() {
1521+ QTest::addColumn<int>("count");
1522+
1523+ QTest::newRow("5 downloads") << 5;
1524+ QTest::newRow("10 downloads") << 10;
1525+ QTest::newRow("15 downloads") << 15;
1526+}
1527+
1528+void
1529+TestManager::testGetAllDownloadsMetadataSignalsEmittedCallbacks() {
1530+ QFETCH(int, count);
1531+ int metadataCount = 5;
1532+ QString key = "test";
1533+ QString value = "metadata";
1534+
1535+ QString url = "http://example.com/";
1536+ QVariantMap metadata;
1537+ QMap<QString, QString> headers;
1538+ MetadataDownloadsListCb cb =
1539+ [](const QString&, const QString&, DownloadsList*){};
1540+
1541+ SignalBarrier managerSpy(_man, SIGNAL(downloadCreated(Download*)));
1542+ SignalBarrier listSpy(_man, SIGNAL(
1543+ downloadsWithMetadataFound(const QString&, const QString&,
1544+ DownloadsList*)));
1545+
1546+ for (int index = 0; index < count; index++) {
1547+ url += index;
1548+ DownloadStruct downStruct(url, metadata, headers);
1549+ _man->createDownload(downStruct);
1550+ }
1551+
1552+ // add downloads with metadata
1553+ metadata[key] = value;
1554+ for (int index = count; index < metadataCount + count; index++) {
1555+ url += index;
1556+ DownloadStruct downStruct(url, metadata, headers);
1557+ _man->createDownload(downStruct);
1558+ }
1559+ // ensure that all of the are created
1560+ QVERIFY(managerSpy.ensureSignalEmitted());
1561+ QTRY_COMPARE(count + metadataCount, managerSpy.count());
1562+ _man->getAllDownloadsWithMetadata(key, value, cb, cb);
1563+
1564+ QVERIFY(listSpy.ensureSignalEmitted());
1565+ QTRY_COMPARE(1, listSpy.count());
1566+
1567+ auto signalInfo = listSpy.takeFirst();
1568+ auto signalKey = signalInfo.at(0).toString();
1569+ QCOMPARE(key, signalKey);
1570+
1571+ auto signalValue = signalInfo.at(1).toString();
1572+ QCOMPARE(value, signalValue);
1573+
1574+ auto downs = signalInfo.at(2).value<DownloadsList*>();
1575+
1576+ QCOMPARE(metadataCount, downs->downloads().count());
1577+
1578+ delete downs;
1579+}
1580+
1581 QTEST_MAIN(TestManager)
1582
1583=== modified file 'tests/test_client_manager.h'
1584--- tests/test_client_manager.h 2014-04-15 13:56:55 +0000
1585+++ tests/test_client_manager.h 2014-04-15 13:56:56 +0000
1586@@ -46,6 +46,14 @@
1587 void testExitError();
1588 void testCreateDownloadSignalsEmitted();
1589 void testCreateDownloadSignalsEmittedCallbacks();
1590+ void testGetAllDownloadsSignalsEmitted_data();
1591+ void testGetAllDownloadsSignalsEmitted();
1592+ void testGetAllDownloadsSignalsEmittedCallbacks_data();
1593+ void testGetAllDownloadsSignalsEmittedCallbacks();
1594+ void testGetAllDownloadsMetadataSignalsEmitted_data();
1595+ void testGetAllDownloadsMetadataSignalsEmitted();
1596+ void testGetAllDownloadsMetadataSignalsEmittedCallbacks_data();
1597+ void testGetAllDownloadsMetadataSignalsEmittedCallbacks();
1598
1599 private:
1600 Manager* _man;
1601
1602=== modified file 'tests/test_download.cpp'
1603--- tests/test_download.cpp 2014-04-15 13:56:55 +0000
1604+++ tests/test_download.cpp 2014-04-15 13:56:56 +0000
1605@@ -16,6 +16,7 @@
1606 * Boston, MA 02110-1301, USA.
1607 */
1608
1609+#include <QDir>
1610 #include <QNetworkRequest>
1611 #include <QSslError>
1612 #include <ubuntu/download_manager/metatypes.h>
1613@@ -46,7 +47,7 @@
1614 _isConfined = false;
1615 _rootPath = testDirectory();
1616 _path = "random path to dbus";
1617- _url = QUrl("http://ubuntu.com");
1618+ _url = QUrl("http://ubuntu.com/data.txt");
1619 _algo = "Sha256";
1620 _networkInfo = new MockSystemNetworkInfo();
1621 SystemNetworkInfo::setInstance(_networkInfo);
1622@@ -3691,4 +3692,89 @@
1623 FileNameMutex::deleteInstance();
1624 }
1625
1626+void
1627+TestDownload::testSetLocalDirectory() {
1628+ auto path = testDirectory() + QDir::separator() + "test";
1629+ QDir().mkpath(path);
1630+
1631+ EXPECT_CALL(*_networkInfo, isOnline())
1632+ .WillRepeatedly(Return(true));
1633+
1634+ QScopedPointer<FileDownload> download(new FileDownload(_id, _path,
1635+ _isConfined, _rootPath, _url, _metadata, _headers));
1636+ auto original = download->filePath();
1637+ download->setDestinationDir(path);
1638+ QVERIFY(original != download->filePath());
1639+ QVERIFY(download->filePath().startsWith(path));
1640+ verifyMocks();
1641+}
1642+
1643+void
1644+TestDownload::testSetLocalDirectoryNotAbsolute() {
1645+ auto path = QString("./path");
1646+ EXPECT_CALL(*_networkInfo, isOnline())
1647+ .WillRepeatedly(Return(true));
1648+
1649+ QScopedPointer<FileDownload> download(new FileDownload(_id, _path,
1650+ _isConfined, _rootPath, _url, _metadata, _headers));
1651+
1652+ auto original = download->filePath();
1653+ download->setDestinationDir(path);
1654+ QCOMPARE(original, download->filePath());
1655+ verifyMocks();
1656+}
1657+
1658+void
1659+TestDownload::testSetLocalDirectoryNotPresent() {
1660+ auto path = QString("/not/present/path");
1661+ EXPECT_CALL(*_networkInfo, isOnline())
1662+ .WillRepeatedly(Return(true));
1663+
1664+ QScopedPointer<FileDownload> download(new FileDownload(_id, _path,
1665+ _isConfined, _rootPath, _url, _metadata, _headers));
1666+
1667+ auto original = download->filePath();
1668+ download->setDestinationDir(path);
1669+ QCOMPARE(original, download->filePath());
1670+ verifyMocks();
1671+}
1672+
1673+void
1674+TestDownload::testSetLocalDirectoryNotDir() {
1675+ auto path = testDirectory() + QDir::separator() + "test";
1676+ QFile file(path);
1677+ file.open(QIODevice::ReadWrite | QFile::Append);
1678+ file.write(QByteArray(100, 'w'));
1679+ file.close();
1680+
1681+ EXPECT_CALL(*_networkInfo, isOnline())
1682+ .WillRepeatedly(Return(true));
1683+
1684+ QScopedPointer<FileDownload> download(new FileDownload(_id, _path,
1685+ _isConfined, _rootPath, _url, _metadata, _headers));
1686+
1687+ auto original = download->filePath();
1688+ download->setDestinationDir(path);
1689+ QCOMPARE(original, download->filePath());
1690+ verifyMocks();
1691+}
1692+
1693+void
1694+TestDownload::testSetLocalDirectoryStarted() {
1695+ auto path = testDirectory() + QDir::separator() + "test";
1696+ QDir().mkpath(path);
1697+
1698+ EXPECT_CALL(*_networkInfo, isOnline())
1699+ .WillRepeatedly(Return(true));
1700+
1701+ QScopedPointer<FileDownload> download(new FileDownload(_id, _path,
1702+ _isConfined, _rootPath, _url, _metadata, _headers));
1703+
1704+ auto original = download->filePath();
1705+ download->start(); // change state
1706+ download->setDestinationDir(path);
1707+ QCOMPARE(original, download->filePath());
1708+ verifyMocks();
1709+}
1710+
1711 QTEST_MAIN(TestDownload)
1712
1713=== modified file 'tests/test_download.h'
1714--- tests/test_download.h 2014-04-15 13:56:55 +0000
1715+++ tests/test_download.h 2014-04-15 13:56:56 +0000
1716@@ -171,6 +171,13 @@
1717 void testErrorUnlocksPath();
1718 void testLockCustomLocalPath();
1719
1720+ // tests related to setting the dir
1721+ void testSetLocalDirectory();
1722+ void testSetLocalDirectoryNotAbsolute();
1723+ void testSetLocalDirectoryNotPresent();
1724+ void testSetLocalDirectoryNotDir();
1725+ void testSetLocalDirectoryStarted();
1726+
1727 private:
1728 QString _id;
1729 bool _isConfined;

Subscribers

People subscribed via source and target branches