Merge lp:~michael-sheldon/ubuntu-download-manager/persistent-download-model-vivid into lp:ubuntu-download-manager/vivid

Proposed by Michael Sheldon
Status: Rejected
Rejected by: Adam Collard
Proposed branch: lp:~michael-sheldon/ubuntu-download-manager/persistent-download-model-vivid
Merge into: lp:ubuntu-download-manager/vivid
Diff against target: 2419 lines (+1238/-115)
55 files modified
.bzrignore (+2/-0)
CMakeLists.txt (+1/-1)
debian/changelog (+16/-0)
debian/libubuntu-download-manager-client1.symbols (+11/-11)
debian/libubuntu-download-manager-common-dev.install (+1/-0)
debian/libubuntu-download-manager-common1.symbols (+23/-8)
debian/libudm-common1.symbols (+1/-1)
docs/dbus/com.canonical.applications.download.xml (+9/-0)
docs/dbus/com.canonical.applications.download_manager.xml (+11/-0)
docs/qml/pages/mainpage.qdoc (+3/-3)
docs/qml/pages/moduledef.qdoc (+1/-1)
src/common/priv/ubuntu/transfers/queue.cpp (+4/-0)
src/common/priv/ubuntu/transfers/transfer.cpp (+7/-0)
src/common/priv/ubuntu/transfers/transfer.h (+3/-4)
src/common/public/ubuntu/transfers/metadata.cpp (+8/-0)
src/downloads/client/ubuntu/download_manager/download.h (+35/-0)
src/downloads/client/ubuntu/download_manager/download_impl.cpp (+61/-2)
src/downloads/client/ubuntu/download_manager/download_impl.h (+4/-0)
src/downloads/client/ubuntu/download_manager/download_interface.h (+18/-0)
src/downloads/client/ubuntu/download_manager/manager.h (+27/-0)
src/downloads/client/ubuntu/download_manager/manager_impl.cpp (+23/-0)
src/downloads/client/ubuntu/download_manager/manager_impl.h (+4/-0)
src/downloads/client/ubuntu/download_manager/manager_interface.h (+7/-0)
src/downloads/common/CMakeLists.txt (+2/-0)
src/downloads/common/ubuntu/download_manager/download_state_struct.cpp (+119/-0)
src/downloads/common/ubuntu/download_manager/download_state_struct.h (+149/-0)
src/downloads/common/ubuntu/download_manager/metatypes.h (+2/-0)
src/downloads/priv/CMakeLists.txt (+2/-2)
src/downloads/priv/ubuntu/downloads/download.h (+1/-0)
src/downloads/priv/ubuntu/downloads/download_adaptor.cpp (+22/-0)
src/downloads/priv/ubuntu/downloads/download_adaptor.h (+12/-2)
src/downloads/priv/ubuntu/downloads/download_manager_adaptor.cpp (+17/-1)
src/downloads/priv/ubuntu/downloads/download_manager_adaptor.h (+12/-1)
src/downloads/priv/ubuntu/downloads/downloads_db.cpp (+105/-0)
src/downloads/priv/ubuntu/downloads/downloads_db.h (+9/-5)
src/downloads/priv/ubuntu/downloads/factory.cpp (+7/-1)
src/downloads/priv/ubuntu/downloads/file_download.cpp (+13/-1)
src/downloads/priv/ubuntu/downloads/file_download.h (+3/-4)
src/downloads/priv/ubuntu/downloads/group_download.cpp (+7/-0)
src/downloads/priv/ubuntu/downloads/group_download.h (+1/-0)
src/downloads/priv/ubuntu/downloads/manager.cpp (+39/-0)
src/downloads/priv/ubuntu/downloads/manager.h (+9/-3)
src/downloads/priv/ubuntu/downloads/state_machines/download_sm.h (+1/-0)
src/downloads/qml/CMakeLists.txt (+2/-0)
src/downloads/qml/backend.cpp (+4/-0)
src/downloads/qml/download_history.cpp (+143/-0)
src/downloads/qml/download_history.h (+69/-0)
src/downloads/qml/single_download.cpp (+36/-12)
src/downloads/qml/single_download.h (+1/-0)
src/downloads/qml/ubuntu_download_manager.cpp (+78/-36)
src/downloads/qml/ubuntu_download_manager.h (+8/-4)
tests/downloads/daemon/download.h (+1/-1)
tests/downloads/daemon/test_download.cpp (+7/-7)
tests/downloads/daemon/test_downloads_db.cpp (+73/-0)
tests/downloads/daemon/test_downloads_db.h (+4/-4)
To merge this branch: bzr merge lp:~michael-sheldon/ubuntu-download-manager/persistent-download-model-vivid
Reviewer Review Type Date Requested Status
Ubuntu One hackers Pending
Review via email: mp+278698@code.launchpad.net

Commit message

Provide a persistent download model available between application restarts

Description of the change

Provide a persistent download model available between application restarts

To post a comment you must log in.

Unmerged revisions

341. By Michael Sheldon

Provide a persistent download model available between application restarts

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2013-11-12 12:30:18 +0000
3+++ .bzrignore 2015-11-26 12:58:55 +0000
4@@ -12,3 +12,5 @@
5 libubuntudownloadmanager-common/libubuntudownloadmanager-common.so.1
6 libubuntudownloadmanager-common/libubuntudownloadmanager-common.so.1.0
7 libubuntudownloadmanager-common/libubuntudownloadmanager-common.so.1.0.0
8+.idea
9+build
10
11=== modified file 'CMakeLists.txt'
12--- CMakeLists.txt 2015-09-22 14:14:06 +0000
13+++ CMakeLists.txt 2015-11-26 12:58:55 +0000
14@@ -31,7 +31,7 @@
15 )
16
17 set(UDM_VERSION_MAJOR 1)
18-set(UDM_VERSION_MINOR 1)
19+set(UDM_VERSION_MINOR 2)
20 set(UDM_VERSION_PATCH 0)
21
22 find_package(Gtest REQUIRED)
23
24=== modified file 'debian/changelog'
25--- debian/changelog 2015-09-22 15:27:25 +0000
26+++ debian/changelog 2015-11-26 12:58:55 +0000
27@@ -1,3 +1,11 @@
28+ubuntu-download-manager (1.2) UNRELEASED; urgency=medium
29+
30+ * Provide a shared download history for the downloads model that presents
31+ all uncollected downloads from previous app launches.
32+ * Update symbol files
33+
34+ -- Michael Sheldon <michael.sheldon@canonical.com> Wed, 21 Oct 2015 10:03:21 +0100
35+
36 ubuntu-download-manager (1.1+15.04.20150922.4-0ubuntu1) vivid; urgency=medium
37
38 [ Manuel de la Pena ]
39@@ -11,6 +19,14 @@
40
41 -- Bill Filler <ci-train-bot@canonical.com> Tue, 22 Sep 2015 15:27:25 +0000
42
43+ubuntu-download-manager (1.1) UNRELEASED; urgency=medium
44+
45+ * Ensure that the app id of the application that created the download is
46+ present in the metadata and can be accessed via dbus.
47+ * Update the symbol files.
48+
49+ -- Manuel de la Pena <manuel.delapena@canonical.com> Tue, 01 Sep 2015 17:07:58 +0100
50+
51 ubuntu-download-manager (1.0+15.04-0ubuntu1) wily; urgency=medium
52
53 [ Manuel de la Pena ]
54
55=== modified file 'debian/libubuntu-download-manager-client1.symbols'
56--- debian/libubuntu-download-manager-client1.symbols 2015-09-22 15:27:25 +0000
57+++ debian/libubuntu-download-manager-client1.symbols 2015-11-26 12:58:55 +0000
58@@ -95,17 +95,17 @@
59 (c++)"Ubuntu::DownloadManager::AuthError::metaObject() const@Base" 0.4+14.10.20140618
60 (c++)"Ubuntu::DownloadManager::DBusError::metaObject() const@Base" 0.4+14.10.20140618
61 (c++)"Ubuntu::DownloadManager::HttpError::metaObject() const@Base" 0.4+14.10.20140618
62- (c++)"std::function<void (Ubuntu::DownloadManager::DownloadsList*)>::operator()(Ubuntu::DownloadManager::DownloadsList*) const@Base" 0.4+14.10.20140618
63- (c++)"std::function<void (Ubuntu::DownloadManager::GroupDownload*)>::operator()(Ubuntu::DownloadManager::GroupDownload*) const@Base" 0.4+14.10.20140618
64- (c++)"std::function<void (Ubuntu::DownloadManager::Download*)>::operator()(Ubuntu::DownloadManager::Download*) const@Base" 0.4+14.10.20140618
65- (c++)"std::function<void (Ubuntu::DownloadManager::DownloadsList*)>::function(std::function<void (Ubuntu::DownloadManager::DownloadsList*)> const&)@Base" 0.4+14.10.20140618
66- (c++)"std::function<void (Ubuntu::DownloadManager::DownloadsList*)>::function(std::function<void (Ubuntu::DownloadManager::DownloadsList*)> const&)@Base" 0.4+14.10.20140618
67- (c++)"std::function<void (Ubuntu::DownloadManager::GroupDownload*)>::function(std::function<void (Ubuntu::DownloadManager::GroupDownload*)> const&)@Base" 0.4+14.10.20140618
68- (c++)"std::function<void (Ubuntu::DownloadManager::GroupDownload*)>::function(std::function<void (Ubuntu::DownloadManager::GroupDownload*)> const&)@Base" 0.4+14.10.20140618
69- (c++)"std::function<void (Ubuntu::DownloadManager::Download*)>::function(std::function<void (Ubuntu::DownloadManager::Download*)> const&)@Base" 0.4+14.10.20140618
70- (c++)"std::function<void (Ubuntu::DownloadManager::Download*)>::function(std::function<void (Ubuntu::DownloadManager::Download*)> const&)@Base" 0.4+14.10.20140618
71- (c++)"std::function<void (QString const&, QString const&, Ubuntu::DownloadManager::DownloadsList*)>::function(std::function<void (QString const&, QString const&, Ubuntu::DownloadManager::DownloadsList*)> const&)@Base" 0.4+14.10.20140618
72- (c++)"std::function<void (QString const&, QString const&, Ubuntu::DownloadManager::DownloadsList*)>::function(std::function<void (QString const&, QString const&, Ubuntu::DownloadManager::DownloadsList*)> const&)@Base" 0.4+14.10.20140618
73+ (c++)"std::function<void (Ubuntu::DownloadManager::DownloadsList*)>::function(std::function<void (Ubuntu::DownloadManager::DownloadsList*)> const&)@Base" 0.4+14.10.20140618
74+ (c++)"std::function<void (Ubuntu::DownloadManager::DownloadsList*)>::function(std::function<void (Ubuntu::DownloadManager::DownloadsList*)> const&)@Base" 0.4+14.10.20140618
75+ (c++)"std::function<void (Ubuntu::DownloadManager::GroupDownload*)>::function(std::function<void (Ubuntu::DownloadManager::GroupDownload*)> const&)@Base" 0.4+14.10.20140618
76+ (c++)"std::function<void (Ubuntu::DownloadManager::GroupDownload*)>::function(std::function<void (Ubuntu::DownloadManager::GroupDownload*)> const&)@Base" 0.4+14.10.20140618
77+ (c++)"std::function<void (Ubuntu::DownloadManager::Download*)>::function(std::function<void (Ubuntu::DownloadManager::Download*)> const&)@Base" 0.4+14.10.20140618
78+ (c++)"std::function<void (Ubuntu::DownloadManager::Download*)>::function(std::function<void (Ubuntu::DownloadManager::Download*)> const&)@Base" 0.4+14.10.20140618
79+ (c++)"std::function<void (QString const&, QString const&, Ubuntu::DownloadManager::DownloadsList*)>::function(std::function<void (QString const&, QString const&, Ubuntu::DownloadManager::DownloadsList*)> const&)@Base" 0.4+14.10.20140618
80+ (c++)"std::function<void (QString const&, QString const&, Ubuntu::DownloadManager::DownloadsList*)>::function(std::function<void (QString const&, QString const&, Ubuntu::DownloadManager::DownloadsList*)> const&)@Base" 0.4+14.10.20140618
81+ (c++)"std::function<void (Ubuntu::DownloadManager::DownloadsList*)>::operator()(Ubuntu::DownloadManager::DownloadsList*) const@Base" 1.2
82+ (c++)"std::function<void (Ubuntu::DownloadManager::GroupDownload*)>::operator()(Ubuntu::DownloadManager::GroupDownload*) const@Base" 1.2
83+ (c++)"std::function<void (Ubuntu::DownloadManager::Download*)>::operator()(Ubuntu::DownloadManager::Download*) const@Base" 1.2
84 (c++)"typeinfo for Ubuntu::DownloadManager::NetworkError@Base" 0.4+14.10.20140618
85 (c++)"typeinfo for Ubuntu::DownloadManager::ProcessError@Base" 0.4+14.10.20140618
86 (c++)"typeinfo for Ubuntu::DownloadManager::DownloadsList@Base" 0.4+14.10.20140618
87
88=== modified file 'debian/libubuntu-download-manager-common-dev.install'
89--- debian/libubuntu-download-manager-common-dev.install 2014-06-06 10:05:15 +0000
90+++ debian/libubuntu-download-manager-common-dev.install 2015-11-26 12:58:55 +0000
91@@ -1,4 +1,5 @@
92 usr/include/ubuntu/download_manager/metatypes.h
93+usr/include/ubuntu/download_manager/download_state_struct.h
94 usr/include/ubuntu/download_manager/download_struct.h
95 usr/include/ubuntu/download_manager/group_download_struct.h
96 usr/lib/*/pkgconfig/ubuntu-download-manager-common.pc
97
98=== modified file 'debian/libubuntu-download-manager-common1.symbols'
99--- debian/libubuntu-download-manager-common1.symbols 2015-07-23 14:02:27 +0000
100+++ debian/libubuntu-download-manager-common1.symbols 2015-11-26 12:58:55 +0000
101@@ -15,14 +15,29 @@
102 (c++)"Ubuntu::DownloadManager::DownloadStruct::DownloadStruct(Ubuntu::DownloadManager::DownloadStruct const&)@Base" 0.4+14.10.20140618
103 (c++)"Ubuntu::DownloadManager::DownloadStruct::DownloadStruct()@Base" 0.4+14.10.20140618
104 (c++)"Ubuntu::DownloadManager::DownloadStruct::operator=(Ubuntu::DownloadManager::DownloadStruct const&)@Base" 0.4+14.10.20140618
105- (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct(QString const&, QString const&, QString const&)@Base" 0.4+14.10.20140618
106- (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct(Ubuntu::DownloadManager::GroupDownloadStruct const&)@Base" 0.4+14.10.20140618
107- (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct()@Base" 0.4+14.10.20140618
108- (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct(QString const&, QString const&, QString const&)@Base" 0.4+14.10.20140618
109- (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct(Ubuntu::DownloadManager::GroupDownloadStruct const&)@Base" 0.4+14.10.20140618
110- (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct()@Base" 0.4+14.10.20140618
111- (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::~GroupDownloadStruct()@Base" 0.4+14.10.20140618
112- (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::~GroupDownloadStruct()@Base" 0.4+14.10.20140618
113+ (c++)"Ubuntu::DownloadManager::DownloadStateStruct::isValid()@Base" 1.2
114+ (c++)"Ubuntu::DownloadManager::DownloadStateStruct::DownloadStateStruct(Ubuntu::DownloadManager::DownloadStateStruct const&)@Base" 1.2
115+ (c++)"Ubuntu::DownloadManager::DownloadStateStruct::DownloadStateStruct(int, QString const&, QString const&)@Base" 1.2
116+ (c++)"Ubuntu::DownloadManager::DownloadStateStruct::DownloadStateStruct(int, QString const&, QString const&, QString const&)@Base" 1.2
117+ (c++)"Ubuntu::DownloadManager::DownloadStateStruct::DownloadStateStruct()@Base" 1.2
118+ (c++)"Ubuntu::DownloadManager::DownloadStateStruct::DownloadStateStruct(Ubuntu::DownloadManager::DownloadStateStruct const&)@Base" 1.2
119+ (c++)"Ubuntu::DownloadManager::DownloadStateStruct::DownloadStateStruct(int, QString const&, QString const&)@Base" 1.2
120+ (c++)"Ubuntu::DownloadManager::DownloadStateStruct::DownloadStateStruct(int, QString const&, QString const&, QString const&)@Base" 1.2
121+ (c++)"Ubuntu::DownloadManager::DownloadStateStruct::operator=(Ubuntu::DownloadManager::DownloadStateStruct const&)@Base" 1.2
122+ (c++)"Ubuntu::DownloadManager::operator<<(QDBusArgument&, Ubuntu::DownloadManager::DownloadStateStruct const&)@Base" 1.2
123+ (c++)"Ubuntu::DownloadManager::operator>>(QDBusArgument const&, Ubuntu::DownloadManager::DownloadStateStruct&)@Base" 1.2
124+ (c++)"Ubuntu::DownloadManager::DownloadStateStruct::getFilePath() const@Base" 1.2
125+ (c++)"Ubuntu::DownloadManager::DownloadStateStruct::getUrl() const@Base" 1.2
126+ (c++)"Ubuntu::DownloadManager::DownloadStateStruct::getHash() const@Base" 1.2
127+ (c++)"Ubuntu::DownloadManager::DownloadStateStruct::getState() const@Base" 1.2
128+ (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::~GroupDownloadStruct()@Base" 1.2
129+ (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::~GroupDownloadStruct()@Base" 1.2
130+ (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct(QString const&, QString const&, QString const&)@Base" 0.4+14.10.20140618
131+ (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct(Ubuntu::DownloadManager::GroupDownloadStruct const&)@Base" 0.4+14.10.20140618
132+ (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct()@Base" 0.4+14.10.20140618
133+ (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct(QString const&, QString const&, QString const&)@Base" 0.4+14.10.20140618
134+ (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct(Ubuntu::DownloadManager::GroupDownloadStruct const&)@Base" 0.4+14.10.20140618
135+ (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct()@Base" 0.4+14.10.20140618
136 (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::operator=(Ubuntu::DownloadManager::GroupDownloadStruct const&)@Base" 0.4+14.10.20140618
137 (c++)"Ubuntu::DownloadManager::operator<<(QDBusArgument&, Ubuntu::DownloadManager::DownloadStruct const&)@Base" 0.4+14.10.20140618
138 (c++)"Ubuntu::DownloadManager::operator<<(QDBusArgument&, Ubuntu::DownloadManager::GroupDownloadStruct const&)@Base" 0.4+14.10.20140618
139
140=== modified file 'debian/libudm-common1.symbols'
141--- debian/libudm-common1.symbols 2015-09-22 15:27:25 +0000
142+++ debian/libudm-common1.symbols 2015-11-26 12:58:55 +0000
143@@ -56,7 +56,7 @@
144 (c++)"Ubuntu::Transfers::System::Logger::qt_metacall(QMetaObject::Call, int, void**)@Base" 0.4+14.10.20140618
145 (c++)"Ubuntu::Transfers::System::Logger::qt_metacast(char const*)@Base" 0.4+14.10.20140618
146 (c++)"Ubuntu::Transfers::System::Logger::setLogLevel(QtMsgType)@Base" 0.4+14.10.20140618
147- (c++)"Ubuntu::Transfers::System::Logger::toStdString(QString const&)@Base" 0.4+14.10.20140618
148+ (c++)"Ubuntu::Transfers::System::Logger::toStdString(QString const&)@Base" 0replaceme
149 (c++)"Ubuntu::Transfers::System::Logger::setupLogging(QString)@Base" 0.4+14.10.20140618
150 (c++)"Ubuntu::Transfers::System::Logger::staticMetaObject@Base" 0.4+14.10.20140618
151 (c++)"Ubuntu::Transfers::System::Logger::getLogDir()@Base" 0.4+14.10.20140618
152
153=== modified file 'docs/dbus/com.canonical.applications.download.xml'
154--- docs/dbus/com.canonical.applications.download.xml 2015-09-22 15:25:33 +0000
155+++ docs/dbus/com.canonical.applications.download.xml 2015-11-26 12:58:55 +0000
156@@ -49,10 +49,19 @@
157 <arg name="allowed" type="b" direction="out"/>
158 </method>
159
160+ <method name="filePath">
161+ <arg name="filepath" type="s" direction="out"/>
162+ </method>
163+
164+ <method name="state">
165+ <arg name="state" type="i" direction="out"/>
166+ </method>
167+
168 <method name="start" />
169 <method name="pause" />
170 <method name="resume" />
171 <method name="cancel" />
172+ <method name="collected" />
173
174 <signal name="started">
175 <arg name="success" type="b" direction="out"/>
176
177=== modified file 'docs/dbus/com.canonical.applications.download_manager.xml'
178--- docs/dbus/com.canonical.applications.download_manager.xml 2014-04-30 14:47:38 +0000
179+++ docs/dbus/com.canonical.applications.download_manager.xml 2015-11-26 12:58:55 +0000
180@@ -35,6 +35,17 @@
181 <arg name="downloads" type="ao" direction="out" />
182 </method>
183
184+ <method name="getUncollectedDownloads">
185+ <arg name="appId" type="s" direction="in"/>
186+ <arg name="downloads" type="ao" direction="out"/>
187+ </method>
188+
189+ <method name="getDownloadState">
190+ <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="DownloadStateStruct"/>
191+ <arg name="downloadId" type="s" direction="in"/>
192+ <arg name="state" type="(issss)" direction="out"/>
193+ </method>
194+
195 <method name="setDefaultThrottle">
196 <arg name="speed" type="t" direction="in"/>
197 </method>
198
199=== modified file 'docs/qml/pages/mainpage.qdoc'
200--- docs/qml/pages/mainpage.qdoc 2014-06-20 10:10:50 +0000
201+++ docs/qml/pages/mainpage.qdoc 2015-11-26 12:58:55 +0000
202@@ -35,7 +35,7 @@
203 \section1 Components
204 Available through:
205 \code
206- import Ubuntu.DownloadManager 0.1
207+ import Ubuntu.DownloadManager 1.2
208 \endcode
209
210 \list
211@@ -47,8 +47,8 @@
212
213 \qml
214 import QtQuick 2.0
215- import Ubuntu.Components 0.1
216- import Ubuntu.DownloadManager 0.1
217+ import Ubuntu.Components 1.2
218+ import Ubuntu.DownloadManager 1.2
219
220 Rectangle {
221 width: units.gu(100)
222
223=== modified file 'docs/qml/pages/moduledef.qdoc'
224--- docs/qml/pages/moduledef.qdoc 2014-06-20 10:10:50 +0000
225+++ docs/qml/pages/moduledef.qdoc 2015-11-26 12:58:55 +0000
226@@ -1,3 +1,3 @@
227 /*!
228- \qmlmodule Ubuntu.DownloadManager 0.1
229+ \qmlmodule Ubuntu.DownloadManager 1.2
230 */
231
232=== modified file 'src/common/priv/ubuntu/transfers/queue.cpp'
233--- src/common/priv/ubuntu/transfers/queue.cpp 2014-11-24 16:39:17 +0000
234+++ src/common/priv/ubuntu/transfers/queue.cpp 2015-11-26 12:58:55 +0000
235@@ -127,6 +127,7 @@
236 break;
237 case Transfer::ERROR:
238 case Transfer::FINISH:
239+ case Transfer::UNCOLLECTED:
240 // remove the registered object in dbus, remove the transfer
241 // and the adapter from the list
242 if (!_current.isEmpty() && _current == transfer->path())
243@@ -177,6 +178,9 @@
244 LOG(INFO) << "State is CANCEL || FINISH || ERROR";
245 remove(_current);
246 _current = "";
247+ } else if (state == Transfer::UNCOLLECTED) {
248+ LOG(INFO) << "State is UNCOLLECTED";
249+ _current = "";
250 } else if (!currentTransfer->canTransfer()
251 || state == Transfer::PAUSE) {
252 LOG(INFO) << "States is Cannot Transfer || PAUSE";
253
254=== modified file 'src/common/priv/ubuntu/transfers/transfer.cpp'
255--- src/common/priv/ubuntu/transfers/transfer.cpp 2014-11-26 12:21:53 +0000
256+++ src/common/priv/ubuntu/transfers/transfer.cpp 2015-11-26 12:58:55 +0000
257@@ -194,6 +194,13 @@
258 startTransfer();
259 }
260
261+void
262+Transfer::collected() {
263+ if (state() == Transfer::UNCOLLECTED) {
264+ setState(Transfer::FINISH);
265+ }
266+}
267+
268 } // General
269
270 } // Ubuntu
271
272=== modified file 'src/common/priv/ubuntu/transfers/transfer.h'
273--- src/common/priv/ubuntu/transfers/transfer.h 2015-02-02 11:05:15 +0000
274+++ src/common/priv/ubuntu/transfers/transfer.h 2015-11-26 12:58:55 +0000
275@@ -16,8 +16,7 @@
276 * Boston, MA 02110-1301, USA.
277 */
278
279-#ifndef UBUNTU_GENERAL_LIB_TRANSFER_H
280-#define UBUNTU_GENERAL_LIB_TRANSFER_H
281+#pragma once
282
283 #include <QObject>
284 #include "ubuntu/transfers/system/network_session.h"
285@@ -36,6 +35,7 @@
286 PAUSE,
287 RESUME,
288 CANCEL,
289+ UNCOLLECTED,
290 FINISH,
291 ERROR
292 };
293@@ -78,6 +78,7 @@
294 virtual void pause();
295 virtual void resume();
296 virtual void start();
297+ virtual void collected();
298
299 signals:
300 void canceled(bool success);
301@@ -112,5 +113,3 @@
302 } // Transfers
303
304 } // Ubuntu
305-
306-#endif
307
308=== modified file 'src/common/public/ubuntu/transfers/metadata.cpp'
309--- src/common/public/ubuntu/transfers/metadata.cpp 2015-09-22 15:25:33 +0000
310+++ src/common/public/ubuntu/transfers/metadata.cpp 2015-11-26 12:58:55 +0000
311@@ -17,6 +17,7 @@
312 */
313
314 #include <QProcessEnvironment>
315+#include <QCoreApplication>
316
317 #include "metadata.h"
318
319@@ -43,6 +44,8 @@
320 auto environment = QProcessEnvironment::systemEnvironment();
321 if (environment.contains(APP_ID_ENV)) {
322 setDestinationApp(environment.value(APP_ID_ENV));
323+ } else {
324+ setDestinationApp(QCoreApplication::applicationFilePath());
325 }
326 }
327
328@@ -53,6 +56,11 @@
329 auto environment = QProcessEnvironment::systemEnvironment();
330 environment.contains(APP_ID_ENV);
331 setDestinationApp(environment.value(APP_ID_ENV));
332+ if (environment.contains(APP_ID_ENV)) {
333+ setDestinationApp(environment.value(APP_ID_ENV));
334+ } else {
335+ setDestinationApp(QCoreApplication::applicationFilePath());
336+ }
337 }
338 }
339
340
341=== modified file 'src/downloads/client/ubuntu/download_manager/download.h'
342--- src/downloads/client/ubuntu/download_manager/download.h 2015-09-22 14:54:32 +0000
343+++ src/downloads/client/ubuntu/download_manager/download.h 2015-11-26 12:58:55 +0000
344@@ -56,6 +56,17 @@
345 explicit Download(QObject* parent = 0)
346 : QObject(parent) {}
347
348+ enum State {
349+ IDLE,
350+ START,
351+ PAUSE,
352+ RESUME,
353+ CANCEL,
354+ UNCOLLECTED,
355+ FINISH,
356+ ERROR
357+ };
358+
359 /*!
360 \fn void Download::start()
361
362@@ -97,6 +108,15 @@
363 virtual void cancel() = 0;
364
365 /*!
366+ \fn void Download::collected()
367+
368+ Notifies the download manager that the finished signal for this
369+ download object has been received by the client. This allows UDM
370+ to report downloads that have finished while a client isn't running.
371+ */
372+ virtual void collected() = 0;
373+
374+ /*!
375 \fn void Download::allowMobileDownload(bool allowed)
376
377 Notifies the download manager that the download represented by this
378@@ -201,6 +221,21 @@
379 virtual qulonglong totalSize() = 0;
380
381 /*!
382+ \fn QString filePath()
383+
384+ Returns the value of the downloaded file's location. This is only set once
385+ the download is complete.
386+ */
387+ virtual QString filePath() = 0;
388+
389+ /*!
390+ \fn State state()
391+
392+ Returns the current state of the download.
393+ */
394+ virtual State state() = 0;
395+
396+ /*!
397 \fn bool isError() const
398
399 Returns if the download represented by the object has had an error.
400
401=== modified file 'src/downloads/client/ubuntu/download_manager/download_impl.cpp'
402--- src/downloads/client/ubuntu/download_manager/download_impl.cpp 2015-09-22 14:54:32 +0000
403+++ src/downloads/client/ubuntu/download_manager/download_impl.cpp 2015-11-26 12:58:55 +0000
404@@ -62,6 +62,13 @@
405 "Could not connect to signal &DownloadInterface::finished");
406 }
407
408+ connected = connect(_dbusInterface, &DownloadInterface::finished,
409+ this, &DownloadImpl::onFinished);
410+ if (!connected) {
411+ Logger::log(Logger::Critical,
412+ "Could not connect to signal &DownloadInterface::finished");
413+ }
414+
415 connected = connect(_dbusInterface, &DownloadInterface::paused,
416 this, &Download::paused);
417 if (!connected) {
418@@ -216,6 +223,19 @@
419 }
420
421 void
422+DownloadImpl::collected() {
423+ Logger::log(Logger::Debug, QString("Download{%1} collected()").arg(_id));
424+ QDBusPendingReply<> reply =
425+ _dbusInterface->collected();
426+ // block, the call should be fast enough
427+ reply.waitForFinished();
428+ if (reply.isError()) {
429+ Logger::log(Logger::Error, "Error when setting download collected");
430+ setLastError(reply.error());
431+ }
432+}
433+
434+void
435 DownloadImpl::allowMobileDownload(bool allowed) {
436 Logger::log(Logger::Debug,
437 QString("Download{%1} allowMobileDownload%2())").arg(_id).arg(allowed));
438@@ -304,9 +324,7 @@
439 // block, the call should be fast enough
440 reply.waitForFinished();
441 if (reply.isError()) {
442- qDebug() << "Error setting metadata";
443 Logger::log(Logger::Error, "Error setting the download metadata");
444- qDebug() << reply.error();
445 setLastError(reply.error());
446 }
447 }
448@@ -362,6 +380,40 @@
449 }
450
451 QString
452+DownloadImpl::filePath() {
453+ Logger::log(Logger::Debug, QString("Download{%1} filePath()").arg(_id));
454+ QDBusPendingReply<QString> reply =
455+ _dbusInterface->filePath();
456+ // block, the call is fast enough
457+ reply.waitForFinished();
458+ if (reply.isError()) {
459+ Logger::log(Logger::Error, "Error querying the download file path");
460+ setLastError(reply.error());
461+ return "";
462+ } else {
463+ auto result = reply.value();
464+ return result;
465+ }
466+}
467+
468+Download::State
469+DownloadImpl::state() {
470+ Logger::log(Logger::Debug, QString("Download{%1} state()").arg(_id));
471+ QDBusPendingReply<int> reply =
472+ _dbusInterface->state();
473+ // block, the call is fast enough
474+ reply.waitForFinished();
475+ if (reply.isError()) {
476+ Logger::log(Logger::Error, "Error querying the download state");
477+ setLastError(reply.error());
478+ return Download::ERROR;
479+ } else {
480+ auto result = static_cast<Download::State>(reply.value());
481+ return result;
482+ }
483+}
484+
485+QString
486 DownloadImpl::id() const {
487 return _id;
488 }
489@@ -481,6 +533,13 @@
490 }
491 }
492
493+void DownloadImpl::onFinished(const QString &path) {
494+ Q_UNUSED(path);
495+ // Inform UDM that we've received the finished signal, so the download
496+ // can be considered completely finished.
497+ collected();
498+}
499+
500 } // DownloadManager
501
502 } // Ubuntu
503
504=== modified file 'src/downloads/client/ubuntu/download_manager/download_impl.h'
505--- src/downloads/client/ubuntu/download_manager/download_impl.h 2015-09-22 14:14:06 +0000
506+++ src/downloads/client/ubuntu/download_manager/download_impl.h 2015-11-26 12:58:55 +0000
507@@ -59,6 +59,7 @@
508 void pause();
509 void resume();
510 void cancel();
511+ void collected();
512
513 void allowMobileDownload(bool allowed);
514 bool isMobileDownloadAllowed();
515@@ -70,6 +71,8 @@
516 void setMetadata(QVariantMap map);
517 void setThrottle(qulonglong speed);
518 qulonglong throttle();
519+ QString filePath();
520+ Download::State state();
521
522 QString id() const;
523 qulonglong progress();
524@@ -101,6 +104,7 @@
525 void onPropertiesChanged(const QString& interfaceName,
526 const QVariantMap& changedProperties,
527 const QStringList& invalidatedProperties);
528+ void onFinished(const QString& path);
529
530 private:
531 QString _id;
532
533=== modified file 'src/downloads/client/ubuntu/download_manager/download_interface.h'
534--- src/downloads/client/ubuntu/download_manager/download_interface.h 2015-09-22 14:54:32 +0000
535+++ src/downloads/client/ubuntu/download_manager/download_interface.h 2015-11-26 12:58:55 +0000
536@@ -66,6 +66,18 @@
537 return asyncCallWithArgumentList(QStringLiteral("cancel"), argumentList);
538 }
539
540+ inline QDBusPendingReply<> collected()
541+ {
542+ QList<QVariant> argumentList;
543+ return asyncCallWithArgumentList(QStringLiteral("collected"), argumentList);
544+ }
545+
546+ inline QDBusPendingReply<QString> filePath()
547+ {
548+ QList<QVariant> argumentList;
549+ return asyncCallWithArgumentList(QStringLiteral("filePath"), argumentList);
550+ }
551+
552 inline QDBusPendingReply<StringMap> headers()
553 {
554 QList<QVariant> argumentList;
555@@ -136,6 +148,12 @@
556 return asyncCallWithArgumentList(QStringLiteral("start"), argumentList);
557 }
558
559+ inline QDBusPendingReply<int> state()
560+ {
561+ QList<QVariant> argumentList;
562+ return asyncCallWithArgumentList(QStringLiteral("state"), argumentList);
563+ }
564+
565 inline QDBusPendingReply<qulonglong> throttle()
566 {
567 QList<QVariant> argumentList;
568
569=== modified file 'src/downloads/client/ubuntu/download_manager/manager.h'
570--- src/downloads/client/ubuntu/download_manager/manager.h 2014-06-06 10:05:15 +0000
571+++ src/downloads/client/ubuntu/download_manager/manager.h 2015-11-26 12:58:55 +0000
572@@ -216,6 +216,33 @@
573 MetadataDownloadsListCb errCb) = 0;
574
575 /*!
576+ \fn void getUncollectedDownloads(const QString &appId)
577+
578+ Returns uncollected downloads in the download manager that can be accessed
579+ by the calling client. If the client is not confined then the downloads
580+ returned will be those belonging to the app specified via the appId
581+ parameter, on the other hand if the client is confined the result will
582+ be only those downloads created by the client. The result of the method
583+ is returned via the downloadsFound signal.
584+ */
585+ virtual void getUncollectedDownloads(const QString &appId) = 0;
586+
587+ /*!
588+ \fn void getUncollectedDownloads(const QString &appId)
589+
590+ Returns uncollected downloads in the download manager that can be accessed
591+ by the calling client. If the client is not confined then the downloads
592+ returned will be those belonging to the app specified via the appId
593+ parameter, on the other hand if the client is confined the result will
594+ be only those downloads created by the client. . If the method is a
595+ success the \a cb is executed else \a errCb is executed.
596+ */
597+
598+ virtual void getUncollectedDownloads(const QString &appId,
599+ DownloadsListCb cb,
600+ DownloadsListCb errCb) = 0;
601+
602+ /*!
603 \fn bool isError() const
604 Returns if the manager received an error during the execution
605 of a command.
606
607=== modified file 'src/downloads/client/ubuntu/download_manager/manager_impl.cpp'
608--- src/downloads/client/ubuntu/download_manager/manager_impl.cpp 2015-02-25 16:24:24 +0000
609+++ src/downloads/client/ubuntu/download_manager/manager_impl.cpp 2015-11-26 12:58:55 +0000
610@@ -193,6 +193,29 @@
611 }
612 }
613
614+void
615+ManagerImpl::getUncollectedDownloads(const QString &appId) {
616+ Logger::log(Logger::Debug, "Manager getUncollectedDownloads()");
617+ DownloadsListCb cb = [](DownloadsList*){};
618+ getUncollectedDownloads(appId, cb, cb);
619+}
620+
621+void
622+ManagerImpl::getUncollectedDownloads(const QString &appId,
623+ DownloadsListCb cb,
624+ DownloadsListCb errCb) {
625+ Logger::log(Logger::Debug, "Manager getUncollectedDownloads()");
626+ QDBusPendingCall call = _dbusInterface->getUncollectedDownloads(appId);
627+ auto watcher = new DownloadsListManagerPCW(
628+ _conn, _servicePath, call, cb, errCb, this);
629+ auto connected = connect(watcher, &GroupManagerPCW::callbackExecuted,
630+ this, &ManagerImpl::onWatcherDone);
631+ if (!connected) {
632+ Logger::log(Logger::Critical,
633+ "Could not connect to signal");
634+ }
635+}
636+
637 bool
638 ManagerImpl::isError() const {
639 return _isError;
640
641=== modified file 'src/downloads/client/ubuntu/download_manager/manager_impl.h'
642--- src/downloads/client/ubuntu/download_manager/manager_impl.h 2014-06-29 12:45:29 +0000
643+++ src/downloads/client/ubuntu/download_manager/manager_impl.h 2015-11-26 12:58:55 +0000
644@@ -81,6 +81,10 @@
645 const QString &value,
646 MetadataDownloadsListCb cb,
647 MetadataDownloadsListCb errCb);
648+ virtual void getUncollectedDownloads(const QString &appId);
649+ virtual void getUncollectedDownloads(const QString &appId,
650+ DownloadsListCb cb,
651+ DownloadsListCb errCb);
652
653 bool isError() const;
654 Error* lastError() const;
655
656=== modified file 'src/downloads/client/ubuntu/download_manager/manager_interface.h'
657--- src/downloads/client/ubuntu/download_manager/manager_interface.h 2014-02-26 19:54:31 +0000
658+++ src/downloads/client/ubuntu/download_manager/manager_interface.h 2015-11-26 12:58:55 +0000
659@@ -89,6 +89,13 @@
660 return asyncCallWithArgumentList(QLatin1String("getAllDownloadsWithMetadata"), argumentList);
661 }
662
663+ inline QDBusPendingReply<QList<QDBusObjectPath> > getUncollectedDownloads(const QString &appId)
664+ {
665+ QList<QVariant> argumentList;
666+ argumentList << QVariant::fromValue(appId);
667+ return asyncCallWithArgumentList(QLatin1String("getUncollectedDownloads"), argumentList);
668+ }
669+
670 inline QDBusPendingReply<bool> isGSMDownloadAllowed()
671 {
672 QList<QVariant> argumentList;
673
674=== modified file 'src/downloads/common/CMakeLists.txt'
675--- src/downloads/common/CMakeLists.txt 2014-06-16 12:38:08 +0000
676+++ src/downloads/common/CMakeLists.txt 2015-11-26 12:58:55 +0000
677@@ -1,12 +1,14 @@
678 set(TARGET ubuntu-download-manager-common)
679
680 set(SOURCES
681+ ubuntu/download_manager/download_state_struct.cpp
682 ubuntu/download_manager/download_struct.cpp
683 ubuntu/download_manager/group_download_struct.cpp
684 ubuntu/download_manager/system/logger.cpp
685 )
686
687 set(PUBLIC_HEADERS
688+ ubuntu/download_manager/download_state_struct.h
689 ubuntu/download_manager/download_struct.h
690 ubuntu/download_manager/group_download_struct.h
691 ubuntu/download_manager/metatypes.h
692
693=== added file 'src/downloads/common/ubuntu/download_manager/download_state_struct.cpp'
694--- src/downloads/common/ubuntu/download_manager/download_state_struct.cpp 1970-01-01 00:00:00 +0000
695+++ src/downloads/common/ubuntu/download_manager/download_state_struct.cpp 2015-11-26 12:58:55 +0000
696@@ -0,0 +1,119 @@
697+/*
698+ * Copyright 2013-2014 Canonical Ltd.
699+ *
700+ * This library is free software; you can redistribute it and/or
701+ * modify it under the terms of version 3 of the GNU Lesser General Public
702+ * License as published by the Free Software Foundation.
703+ *
704+ * This program is distributed in the hope that it will be useful,
705+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
706+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
707+ * General Public License for more details.
708+ *
709+ * You should have received a copy of the GNU Lesser General Public
710+ * License along with this library; if not, write to the
711+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
712+ * Boston, MA 02110-1301, USA.
713+ */
714+
715+#include <QDBusArgument>
716+#include "download_state_struct.h"
717+
718+namespace Ubuntu {
719+
720+namespace DownloadManager {
721+
722+DownloadStateStruct::DownloadStateStruct()
723+ : _state(-1),
724+ _url(QString::null),
725+ _filePath(QString::null),
726+ _hash(QString::null) {
727+
728+}
729+
730+DownloadStateStruct::DownloadStateStruct(int state, const QString& url, const QString& hash)
731+ : _state(state),
732+ _url(url),
733+ _filePath(QString::null),
734+ _hash(hash) {
735+
736+}
737+
738+DownloadStateStruct::DownloadStateStruct(int state, const QString& url, const QString& filePath,
739+ const QString& hash)
740+ : _state(state),
741+ _url(url),
742+ _filePath(filePath),
743+ _hash(hash) {
744+
745+}
746+
747+DownloadStateStruct::DownloadStateStruct(const DownloadStateStruct& other)
748+ : _state(other._state),
749+ _url(other._url),
750+ _filePath(other._filePath),
751+ _hash(other._hash) {
752+}
753+
754+DownloadStateStruct& DownloadStateStruct::operator=(const DownloadStateStruct& other) {
755+ _state = other._state;
756+ _url = other._url;
757+ _filePath= other._filePath;
758+ _hash = other._hash;
759+
760+ return *this;
761+}
762+
763+QDBusArgument &operator<<(QDBusArgument &argument,
764+ const DownloadStateStruct& download) {
765+ argument.beginStructure();
766+ argument << download._state;
767+ argument << download._url;
768+ argument << download._filePath;
769+ argument << download._hash;
770+ argument.endStructure();
771+
772+ return argument;
773+}
774+
775+const QDBusArgument &operator>>(const QDBusArgument &argument,
776+ DownloadStateStruct& download) {
777+ argument.beginStructure();
778+ argument >> download._state;
779+ argument >> download._url;
780+ argument >> download._filePath;
781+ argument >> download._hash;
782+ argument.endStructure();
783+
784+ return argument;
785+}
786+
787+int
788+DownloadStateStruct::getState() const {
789+ return _state;
790+}
791+
792+QString
793+DownloadStateStruct::getUrl() const {
794+ return _url;
795+}
796+
797+QString
798+DownloadStateStruct::getFilePath() const {
799+ return _filePath;
800+}
801+
802+QString
803+DownloadStateStruct::getHash() const {
804+ return _hash;
805+}
806+
807+bool
808+DownloadStateStruct::isValid() {
809+ return _url != QString::null;
810+}
811+
812+} // DownloadManager
813+
814+} // Ubuntu
815+
816
817=== added file 'src/downloads/common/ubuntu/download_manager/download_state_struct.h'
818--- src/downloads/common/ubuntu/download_manager/download_state_struct.h 1970-01-01 00:00:00 +0000
819+++ src/downloads/common/ubuntu/download_manager/download_state_struct.h 2015-11-26 12:58:55 +0000
820@@ -0,0 +1,149 @@
821+/*
822+ * Copyright 2015 Canonical Ltd.
823+ *
824+ * This library is free software; you can redistribute it and/or
825+ * modify it under the terms of version 3 of the GNU Lesser General Public
826+ * License as published by the Free Software Foundation.
827+ *
828+ * This program is distributed in the hope that it will be useful,
829+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
830+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
831+ * General Public License for more details.
832+ *
833+ * You should have received a copy of the GNU Lesser General Public
834+ * License along with this library; if not, write to the
835+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
836+ * Boston, MA 02110-1301, USA.
837+ */
838+
839+#pragma once
840+
841+#include <QString>
842+
843+class QDBusArgument;
844+namespace Ubuntu {
845+
846+namespace DownloadManager {
847+
848+namespace Daemon {
849+class DownloadsDb;
850+}
851+
852+/*!
853+ \class DownloadStateStruct
854+ \brief The DownloadStateStruct represents the dbus structure that is used
855+ to communicate the download manager the details of a past or
856+ current download.
857+ \since 1.1
858+
859+ The DownloadStateStruct allows to get the basic information of a download that
860+ was created by an application in the download manager.
861+*/
862+class DownloadStateStruct {
863+ Q_PROPERTY(int state READ getState)
864+ Q_PROPERTY(QString url READ getUrl)
865+ Q_PROPERTY(QString filePath READ getFilePath)
866+ Q_PROPERTY(QString hash READ getHash)
867+
868+ friend class Ubuntu::DownloadManager::Daemon::DownloadsDb;
869+
870+ public:
871+
872+ /*
873+ Default constructor.
874+ */
875+ DownloadStateStruct();
876+
877+ /*
878+ Copy constructor.
879+ */
880+ DownloadStateStruct(const DownloadStateStruct& other);
881+
882+ /*
883+ Assign operator.
884+ */
885+ DownloadStateStruct& operator=(const DownloadStateStruct& other);
886+
887+ /*
888+ \internal
889+ */
890+ friend QDBusArgument &operator<<(QDBusArgument &argument, const DownloadStateStruct& download);
891+
892+ /*
893+ \internal
894+ */
895+ friend const QDBusArgument &operator>>(const QDBusArgument &argument, DownloadStateStruct& download);
896+
897+ /*
898+ \fn QString getUrl()
899+
900+ Returns the url that points to the file that will be downloaded.
901+ */
902+ int getState() const;
903+
904+ /*
905+ \fn QString getUrl()
906+
907+ Returns the url that points to the file that will be downloaded.
908+ */
909+ QString getUrl() const;
910+
911+ /*
912+ \fn QString getUrl()
913+
914+ Returns the url that points to the file that will be downloaded.
915+ */
916+ QString getFilePath() const;
917+
918+ /*
919+ \fn QString getUrl()
920+
921+ Returns the url that points to the file that will be downloaded.
922+ */
923+ QString getHash() const;
924+
925+ /*
926+ \fn bool isValid();
927+
928+ Returns if the download state if valid.
929+ */
930+ bool isValid();
931+
932+ protected:
933+
934+ /*
935+ \internal
936+ */
937+ DownloadStateStruct(int state, const QString& url, const QString& hash=QString::null);
938+
939+ /*
940+ \internal
941+ */
942+ DownloadStateStruct(int state, const QString& url, const QString& filePath, const QString& hash=QString::null);
943+
944+ private:
945+
946+ /*
947+ \internal
948+ */
949+ int _state = -1;
950+
951+ /*
952+ \internal
953+ */
954+ QString _url = QString::null;
955+
956+ /*
957+ \internal
958+ */
959+ QString _filePath = QString::null;
960+
961+ /*
962+ \internal
963+ */
964+ QString _hash = QString::null;
965+};
966+
967+}
968+
969+}
970\ No newline at end of file
971
972=== modified file 'src/downloads/common/ubuntu/download_manager/metatypes.h'
973--- src/downloads/common/ubuntu/download_manager/metatypes.h 2015-02-25 16:24:24 +0000
974+++ src/downloads/common/ubuntu/download_manager/metatypes.h 2015-11-26 12:58:55 +0000
975@@ -25,6 +25,7 @@
976 #include <ubuntu/transfers/errors/http_error_struct.h>
977 #include <ubuntu/transfers/errors/network_error_struct.h>
978 #include <ubuntu/transfers/errors/process_error_struct.h>
979+#include "download_state_struct.h"
980 #include "download_struct.h"
981 #include "group_download_struct.h"
982
983@@ -40,6 +41,7 @@
984 Q_DECLARE_METATYPE(NetworkErrorStruct)
985 Q_DECLARE_METATYPE(ProcessErrorStruct)
986 Q_DECLARE_METATYPE(DownloadStruct)
987+Q_DECLARE_METATYPE(DownloadStateStruct)
988 Q_DECLARE_METATYPE(StringMap)
989 Q_DECLARE_METATYPE(StructList)
990
991
992=== modified file 'src/downloads/priv/CMakeLists.txt'
993--- src/downloads/priv/CMakeLists.txt 2014-11-17 23:07:13 +0000
994+++ src/downloads/priv/CMakeLists.txt 2015-11-26 12:58:55 +0000
995@@ -12,7 +12,7 @@
996 ubuntu/downloads/file_download.cpp
997 ubuntu/downloads/group_download.cpp
998 ubuntu/downloads/group_download_adaptor.cpp
999- ubuntu/downloads/header_parser.cpp
1000+ ubuntu/downloads/header_parser.cpp
1001 ubuntu/downloads/manager.cpp
1002 ubuntu/downloads/mms_file_download.cpp
1003 ubuntu/downloads/sm_file_download.cpp
1004@@ -33,7 +33,7 @@
1005 ubuntu/downloads/file_download.h
1006 ubuntu/downloads/group_download.h
1007 ubuntu/downloads/group_download_adaptor.h
1008- ubuntu/downloads/header_parser.h
1009+ ubuntu/downloads/header_parser.h
1010 ubuntu/downloads/manager.h
1011 ubuntu/downloads/mms_file_download.h
1012 ubuntu/downloads/sm_file_download.h
1013
1014=== modified file 'src/downloads/priv/ubuntu/downloads/download.h'
1015--- src/downloads/priv/ubuntu/downloads/download.h 2015-09-22 14:54:32 +0000
1016+++ src/downloads/priv/ubuntu/downloads/download.h 2015-11-26 12:58:55 +0000
1017@@ -105,6 +105,7 @@
1018 // slots to be implemented by the children
1019 virtual qulonglong progress() = 0;
1020 virtual qulonglong totalSize() = 0;
1021+ virtual QString filePath() = 0;
1022
1023 signals:
1024 // signals that are exposed via dbus
1025
1026=== modified file 'src/downloads/priv/ubuntu/downloads/download_adaptor.cpp'
1027--- src/downloads/priv/ubuntu/downloads/download_adaptor.cpp 2015-09-22 14:54:32 +0000
1028+++ src/downloads/priv/ubuntu/downloads/download_adaptor.cpp 2015-11-26 12:58:55 +0000
1029@@ -69,6 +69,20 @@
1030 QMetaObject::invokeMethod(parent(), "cancel");
1031 }
1032
1033+void DownloadAdaptor::collected()
1034+{
1035+ // handle method call com.canonical.applications.Download.collected
1036+ QMetaObject::invokeMethod(parent(), "collected");
1037+}
1038+
1039+QString DownloadAdaptor::filePath()
1040+{
1041+ // handle method call com.canonical.applications.Download.filePath
1042+ QString filePath;
1043+ QMetaObject::invokeMethod(parent(), "filePath", Q_RETURN_ARG(QString, filePath));
1044+ return filePath;
1045+}
1046+
1047 StringMap DownloadAdaptor::headers()
1048 {
1049 // handle method call com.canonical.applications.Download.headers
1050@@ -143,6 +157,14 @@
1051 QMetaObject::invokeMethod(parent(), "start");
1052 }
1053
1054+int DownloadAdaptor::state()
1055+{
1056+ // handle method call com.canonical.applications.Download.state
1057+ int state;
1058+ QMetaObject::invokeMethod(parent(), "state", Q_RETURN_ARG(int, state));
1059+ return state;
1060+}
1061+
1062 qulonglong DownloadAdaptor::throttle()
1063 {
1064 // handle method call com.canonical.applications.Download.throttle
1065
1066=== modified file 'src/downloads/priv/ubuntu/downloads/download_adaptor.h'
1067--- src/downloads/priv/ubuntu/downloads/download_adaptor.h 2015-09-22 14:54:32 +0000
1068+++ src/downloads/priv/ubuntu/downloads/download_adaptor.h 2015-11-26 12:58:55 +0000
1069@@ -9,8 +9,8 @@
1070 * before re-generating it.
1071 */
1072
1073-#ifndef DOWNLOAD_ADAPTOR_H_1440513488
1074-#define DOWNLOAD_ADAPTOR_H_1440513488
1075+#ifndef DOWNLOAD_ADAPTOR_H_1446124951
1076+#define DOWNLOAD_ADAPTOR_H_1446124951
1077
1078 #include <QtCore/QObject>
1079 #include <QtDBus/QtDBus>
1080@@ -71,10 +71,17 @@
1081 " <method name=\"isGSMDownloadAllowed\">\n"
1082 " <arg direction=\"out\" type=\"b\" name=\"allowed\"/>\n"
1083 " </method>\n"
1084+" <method name=\"filePath\">\n"
1085+" <arg direction=\"out\" type=\"s\" name=\"filepath\"/>\n"
1086+" </method>\n"
1087+" <method name=\"state\">\n"
1088+" <arg direction=\"out\" type=\"i\" name=\"state\"/>\n"
1089+" </method\n"
1090 " <method name=\"start\"/>\n"
1091 " <method name=\"pause\"/>\n"
1092 " <method name=\"resume\"/>\n"
1093 " <method name=\"cancel\"/>\n"
1094+" <method name=\"collected\"/>\n"
1095 " <signal name=\"started\">\n"
1096 " <arg direction=\"out\" type=\"b\" name=\"success\"/>\n"
1097 " </signal>\n"
1098@@ -146,6 +153,8 @@
1099 public Q_SLOTS: // METHODS
1100 void allowGSMDownload(bool allowed);
1101 void cancel();
1102+ void collected();
1103+ QString filePath();
1104 StringMap headers();
1105 bool isGSMDownloadAllowed();
1106 QVariantMap metadata();
1107@@ -157,6 +166,7 @@
1108 void setMetadata(const QVariantMap &data);
1109 void setThrottle(qulonglong speed);
1110 void start();
1111+ int state();
1112 qulonglong throttle();
1113 qulonglong totalSize();
1114 Q_SIGNALS: // SIGNALS
1115
1116=== modified file 'src/downloads/priv/ubuntu/downloads/download_manager_adaptor.cpp'
1117--- src/downloads/priv/ubuntu/downloads/download_manager_adaptor.cpp 2014-03-18 12:07:06 +0000
1118+++ src/downloads/priv/ubuntu/downloads/download_manager_adaptor.cpp 2015-11-26 12:58:55 +0000
1119@@ -2,7 +2,7 @@
1120 * This file was generated by qdbusxml2cpp version 0.8
1121 * Command line was: qdbusxml2cpp -c DownloadManagerAdaptor -a download_manager_adaptor.h:download_manager_adaptor.cpp -i metatypes.h com.canonical.applications.download_manager.xml
1122 *
1123- * qdbusxml2cpp is Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
1124+ * qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
1125 *
1126 * This is an auto-generated file.
1127 * Do not edit! All changes made to it will be lost.
1128@@ -99,6 +99,22 @@
1129 return downloads;
1130 }
1131
1132+QList<QDBusObjectPath> DownloadManagerAdaptor::getUncollectedDownloads(const QString &appId)
1133+{
1134+ // handle method call com.canonical.applications.DownloadManager.getUncollectedDownloads
1135+ QList<QDBusObjectPath> downloads;
1136+ QMetaObject::invokeMethod(parent(), "getUncollectedDownloads", Q_RETURN_ARG(QList<QDBusObjectPath>, downloads), Q_ARG(QString, appId));
1137+ return downloads;
1138+}
1139+
1140+DownloadStateStruct DownloadManagerAdaptor::getDownloadState(const QString &downloadId)
1141+{
1142+ // handle method call com.canonical.applications.DownloadManager.getDownloadState
1143+ DownloadStateStruct state;
1144+ QMetaObject::invokeMethod(parent(), "getDownloadState", Q_RETURN_ARG(DownloadStateStruct, state), Q_ARG(QString, downloadId));
1145+ return state;
1146+}
1147+
1148 bool DownloadManagerAdaptor::isGSMDownloadAllowed()
1149 {
1150 // handle method call com.canonical.applications.DownloadManager.isGSMDownloadAllowed
1151
1152=== modified file 'src/downloads/priv/ubuntu/downloads/download_manager_adaptor.h'
1153--- src/downloads/priv/ubuntu/downloads/download_manager_adaptor.h 2014-03-18 12:07:06 +0000
1154+++ src/downloads/priv/ubuntu/downloads/download_manager_adaptor.h 2015-11-26 12:58:55 +0000
1155@@ -2,7 +2,7 @@
1156 * This file was generated by qdbusxml2cpp version 0.8
1157 * Command line was: qdbusxml2cpp -c DownloadManagerAdaptor -a download_manager_adaptor.h:download_manager_adaptor.cpp -i metatypes.h com.canonical.applications.download_manager.xml
1158 *
1159- * qdbusxml2cpp is Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
1160+ * qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
1161 *
1162 * This is an auto-generated file.
1163 * This file may have been hand-edited. Look for HAND-EDIT comments
1164@@ -70,6 +70,15 @@
1165 " <arg direction=\"in\" type=\"s\" name=\"value\"/>\n"
1166 " <arg direction=\"out\" type=\"ao\" name=\"downloads\"/>\n"
1167 " </method>\n"
1168+" <method name=\"getUncollectedDownloads\">\n"
1169+" <arg direction=\"in\" type=\"s\" name=\"appId\"/>\n"
1170+" <arg direction=\"out\" type=\"ao\" name=\"downloads\"/>\n"
1171+" </method>\n"
1172+" <method name=\"getDownloadState\">\n"
1173+" <annotation value=\"DownloadStateStruct\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
1174+" <arg direction=\"in\" type=\"s\" name=\"downloadId\"/>\n"
1175+" <arg direction=\"out\" type=\"(issss)\" name=\"state\"/>\n"
1176+" </method>\n"
1177 " <method name=\"setDefaultThrottle\">\n"
1178 " <arg direction=\"in\" type=\"t\" name=\"speed\"/>\n"
1179 " </method>\n"
1180@@ -102,6 +111,8 @@
1181 void exit();
1182 QList<QDBusObjectPath> getAllDownloads();
1183 QList<QDBusObjectPath> getAllDownloadsWithMetadata(const QString &name, const QString &value);
1184+ DownloadStateStruct getDownloadState(const QString &downloadId);
1185+ QList<QDBusObjectPath> getUncollectedDownloads(const QString &appId);
1186 bool isGSMDownloadAllowed();
1187 void setDefaultThrottle(qulonglong speed);
1188 Q_SIGNALS: // SIGNALS
1189
1190=== modified file 'src/downloads/priv/ubuntu/downloads/downloads_db.cpp'
1191--- src/downloads/priv/ubuntu/downloads/downloads_db.cpp 2014-04-15 15:15:28 +0000
1192+++ src/downloads/priv/ubuntu/downloads/downloads_db.cpp 2015-11-26 12:58:55 +0000
1193@@ -29,6 +29,7 @@
1194 #include <unistd.h>
1195 #include "ubuntu/transfers/system/logger.h"
1196 #include "downloads_db.h"
1197+#include "download_adaptor.h"
1198
1199 namespace {
1200 const QString SINGLE_DOWNLOAD_TABLE = "CREATE TABLE IF NOT EXISTS SingleDownload("\
1201@@ -75,14 +76,26 @@
1202 "throttle=:throttle, metadata=:metadata, headers=:headers "\
1203 "WHERE uuid=:uuid";
1204
1205+ const QString GET_SINGLE_DOWNLOAD_STATE = "SELECT state, url, local_path, hash FROM SingleDownload "\
1206+ "WHERE uuid=:uuid";
1207+
1208+ const QString GET_UNCOLLECTED_DOWNLOADS = "SELECT uuid, appId, url, dbus_path, "\
1209+ "local_path, hash, hash_algo, state FROM SingleDownload "\
1210+ "WHERE appId=:appId AND state='uncoll'";
1211+
1212+ const QString UPDATE_UNCOLLECTED_DOWNLOADS = "UPDATE SingleDownload SET state='finish' "\
1213+ "WHERE state='uncoll' AND appId=:appId";
1214+
1215 const QString IDLE_STRING = "idle";
1216 const QString START_STRING = "start";
1217 const QString PAUSE_STRING = "pause";
1218 const QString RESUME_STRING = "resume";
1219 const QString CANCEL_STRING = "cancel";
1220+ const QString UNCOLLECTED_STRING = "uncoll";
1221 const QString FINISH_STRING = "finish";
1222 const QString ERROR_STRING = "error";
1223
1224+ const QString DOWNLOAD_INTERFACE = "com.canonical.applications.Download";
1225 }
1226
1227 namespace Ubuntu {
1228@@ -178,6 +191,8 @@
1229 return RESUME_STRING;
1230 case Download::CANCEL:
1231 return CANCEL_STRING;
1232+ case Download::UNCOLLECTED:
1233+ return UNCOLLECTED_STRING;
1234 case Download::FINISH:
1235 return FINISH_STRING;
1236 case Download::ERROR:
1237@@ -200,6 +215,8 @@
1238 return Download::RESUME;
1239 if (lowerState == CANCEL_STRING)
1240 return Download::CANCEL;
1241+ if (lowerState == UNCOLLECTED_STRING)
1242+ return Download::UNCOLLECTED;
1243 if (lowerState == FINISH_STRING)
1244 return Download::FINISH;
1245 if (lowerState == ERROR_STRING)
1246@@ -235,6 +252,94 @@
1247 return false;
1248 }
1249
1250+DownloadStateStruct
1251+DownloadsDb::getDownloadState(const QString &downloadId) {
1252+ bool opened = _db.open();
1253+
1254+ if (!opened) {
1255+ LOG(ERROR) << _db.lastError().text();
1256+ return DownloadStateStruct();
1257+ }
1258+
1259+ QSqlQuery query;
1260+ // QString GET_SINGLE_DOWNLOAD_STATE = "SELECT state, url, local_path, hash FROM SingleDownload "
1261+ // "WHERE uuid=:uuid";
1262+ query.prepare(GET_SINGLE_DOWNLOAD_STATE);
1263+ query.bindValue(":uuid", downloadId);
1264+
1265+ bool success = query.exec();
1266+ if (success && query.next()) {
1267+ // grab the data and create the state structure
1268+ auto state = stringToState(query.value(0).toString());
1269+ auto url = query.value(1).toString();
1270+ auto localPath = query.value(2).toString();
1271+ auto hash = query.value(3).isValid()?query.value(3).toString():"";
1272+
1273+ DownloadStateStruct result(state, url, localPath, hash);
1274+ _db.close();
1275+
1276+ return result;
1277+ }
1278+ if (!success) {
1279+ LOG(ERROR) << query.lastError().text();
1280+ }
1281+ return DownloadStateStruct();
1282+}
1283+
1284+QList<Download*>
1285+DownloadsDb::getUncollectedDownloads(const QString &appId) {
1286+ bool opened = _db.open();
1287+ QList<Download*> downloadList;
1288+
1289+ if (!opened) {
1290+ LOG(ERROR) << _db.lastError().text();
1291+ return downloadList;
1292+ }
1293+
1294+ QSqlQuery query;
1295+ query.prepare(GET_UNCOLLECTED_DOWNLOADS);
1296+ query.bindValue(":appId", appId);
1297+
1298+ bool success = query.exec();
1299+ if (!success) {
1300+ LOG(ERROR) << query.lastError().text();
1301+ _db.close();
1302+ return downloadList;
1303+ }
1304+ while (query.next()) {
1305+ auto uuid = query.value(0).toString();
1306+ auto appId = query.value(1).toString();
1307+ auto url = query.value(2).toString();
1308+ auto dbusPath = query.value(3).toString();
1309+ auto filePath = query.value(4).toString();
1310+ auto basePath = QFileInfo(filePath).absolutePath();
1311+ auto hash = query.value(5).isValid() ? query.value(5).toString() : "";
1312+ auto algo = query.value(6).isValid() ? query.value(6).toString() : "";
1313+ auto state = stringToState(query.value(7).toString());
1314+ QVariantMap metadata;
1315+ QMap<QString, QString> headers;
1316+ FileDownload *download = new FileDownload(uuid, appId, dbusPath, 1, basePath, url, hash, algo, metadata, headers);
1317+ download->setState(state);
1318+ download->setFilePath(filePath);
1319+ auto downAdaptor = new DownloadAdaptor(download);
1320+ download->setAdaptor(DOWNLOAD_INTERFACE, downAdaptor);
1321+
1322+ downloadList << download;
1323+
1324+ }
1325+
1326+ QSqlQuery updateQuery;
1327+ updateQuery.prepare(UPDATE_UNCOLLECTED_DOWNLOADS);
1328+ updateQuery.bindValue(":appId", appId);
1329+ success = updateQuery.exec();
1330+ if (!success) {
1331+ LOG(ERROR) << updateQuery.lastError().text();
1332+ }
1333+
1334+ _db.close();
1335+ return downloadList;
1336+}
1337+
1338 bool
1339 DownloadsDb::storeSingleDownload(FileDownload* download) {
1340 // decide if we store it as a new download or update an existing one
1341
1342=== modified file 'src/downloads/priv/ubuntu/downloads/downloads_db.h'
1343--- src/downloads/priv/ubuntu/downloads/downloads_db.h 2014-02-26 16:23:46 +0000
1344+++ src/downloads/priv/ubuntu/downloads/downloads_db.h 2015-11-26 12:58:55 +0000
1345@@ -16,12 +16,14 @@
1346 * Boston, MA 02110-1301, USA.
1347 */
1348
1349-#ifndef DOWNLOADER_LIB_DOWNLOADS_DATABASE_H
1350-#define DOWNLOADER_LIB_DOWNLOADS_DATABASE_H
1351+#pragma once
1352
1353 #include <QSqlDatabase>
1354 #include <QObject>
1355-#include "ubuntu/transfers/system/file_manager.h"
1356+
1357+#include <ubuntu/transfers/system/file_manager.h>
1358+#include <ubuntu/download_manager/download_state_struct.h>
1359+
1360 #include "file_download.h"
1361
1362 namespace Ubuntu {
1363@@ -45,7 +47,11 @@
1364 QString filename();
1365 bool dbExists(); // return if the db is present and valid
1366 bool init(); // init or update the db
1367+
1368 virtual bool store(Download* down);
1369+ virtual DownloadStateStruct getDownloadState(const QString &downloadId);
1370+ virtual QList<Download*> getUncollectedDownloads(const QString &appId);
1371+
1372 bool storeSingleDownload(FileDownload* download);
1373 void connectToDownload(Download* download);
1374 void disconnectFromDownload(Download* download);
1375@@ -78,5 +84,3 @@
1376 } // DownloadManager
1377
1378 } // Ubuntu
1379-
1380-#endif // DOWNLOADER_LIB_DOWNLOADS_DATABASE_H
1381
1382=== modified file 'src/downloads/priv/ubuntu/downloads/factory.cpp'
1383--- src/downloads/priv/ubuntu/downloads/factory.cpp 2014-10-22 23:32:28 +0000
1384+++ src/downloads/priv/ubuntu/downloads/factory.cpp 2015-11-26 12:58:55 +0000
1385@@ -80,7 +80,13 @@
1386 QScopedPointer<SecurityDetails> details(
1387 getSecurityDetails(dbusOwner, metadata));
1388 auto dbusPath = details->dbusPath.arg("download");
1389- auto down = new FileDownload(details->id, details->appId,
1390+ QString appId = details->appId;
1391+ if (!details->isConfined && metadata.contains(Metadata::APP_ID)) {
1392+ // If we're unconfined use the metadata app id to
1393+ // distinguish between different unconfined apps
1394+ appId = metadata[Metadata::APP_ID].toString();
1395+ }
1396+ auto down = new FileDownload(details->id, appId,
1397 dbusPath, details->isConfined, details->localPath, url, metadata, headers);
1398 auto downAdaptor = new DownloadAdaptor(down);
1399 down->setAdaptor(DOWNLOAD_INTERFACE, downAdaptor);
1400
1401=== modified file 'src/downloads/priv/ubuntu/downloads/file_download.cpp'
1402--- src/downloads/priv/ubuntu/downloads/file_download.cpp 2015-02-25 16:24:24 +0000
1403+++ src/downloads/priv/ubuntu/downloads/file_download.cpp 2015-11-26 12:58:55 +0000
1404@@ -1095,7 +1095,7 @@
1405 }
1406 }
1407
1408- setState(Download::FINISH);
1409+ setState(Download::UNCOLLECTED);
1410 unlockFilePath();
1411
1412 DOWN_LOG(INFO) << "EMIT finished" << filePath();
1413@@ -1211,6 +1211,18 @@
1414 Download::emitError(error);
1415 }
1416
1417+void
1418+FileDownload::setFilePath(const QString& filePath) {
1419+ // Used to recreate downloads from the database with the correct path
1420+ _fileNameMutex->unlockFileName(_filePath);
1421+ _filePath = filePath;
1422+}
1423+
1424+QString
1425+FileDownload::filePath() {
1426+ return _filePath;
1427+}
1428+
1429 } // Daemon
1430
1431 } // DownloadManager
1432
1433=== modified file 'src/downloads/priv/ubuntu/downloads/file_download.h'
1434--- src/downloads/priv/ubuntu/downloads/file_download.h 2015-02-25 16:24:24 +0000
1435+++ src/downloads/priv/ubuntu/downloads/file_download.h 2015-11-26 12:58:55 +0000
1436@@ -71,10 +71,6 @@
1437 return _url;
1438 }
1439
1440- virtual QString filePath() const {
1441- return _filePath;
1442- }
1443-
1444 virtual QString hash() const {
1445 return _hash;
1446 }
1447@@ -89,6 +85,8 @@
1448 virtual void resumeTransfer() override;
1449 virtual void startTransfer() override;
1450
1451+ void setFilePath(const QString& path);
1452+
1453 public slots: // NOLINT(whitespace/indent)
1454 qulonglong progress() override;
1455 qulonglong totalSize() override;
1456@@ -96,6 +94,7 @@
1457 virtual void setDestinationDir(const QString& path);
1458 virtual void setHeaders(StringMap headers) override;
1459 virtual void setMetadata(const QVariantMap& metadata) override;
1460+ virtual QString filePath() override;
1461
1462 signals:
1463 void finished(const QString& path);
1464
1465=== modified file 'src/downloads/priv/ubuntu/downloads/group_download.cpp'
1466--- src/downloads/priv/ubuntu/downloads/group_download.cpp 2014-05-21 15:17:52 +0000
1467+++ src/downloads/priv/ubuntu/downloads/group_download.cpp 2015-11-26 12:58:55 +0000
1468@@ -275,6 +275,13 @@
1469 return total;
1470 }
1471
1472+QString
1473+GroupDownload::filePath() {
1474+ // A group download never has a file path of its own, each individual
1475+ // download within the group has its own path
1476+ return "";
1477+}
1478+
1479 void
1480 GroupDownload::onError(const QString& error) {
1481 TRACE;
1482
1483=== modified file 'src/downloads/priv/ubuntu/downloads/group_download.h'
1484--- src/downloads/priv/ubuntu/downloads/group_download.h 2014-10-22 23:40:53 +0000
1485+++ src/downloads/priv/ubuntu/downloads/group_download.h 2015-11-26 12:58:55 +0000
1486@@ -63,6 +63,7 @@
1487 virtual qulonglong progress(qulonglong &started, qulonglong &paused,
1488 qulonglong &finished);
1489 virtual qulonglong totalSize() override;
1490+ virtual QString filePath() override;
1491
1492 signals:
1493 void finished(const QStringList &path);
1494
1495=== modified file 'src/downloads/priv/ubuntu/downloads/manager.cpp'
1496--- src/downloads/priv/ubuntu/downloads/manager.cpp 2015-09-22 14:14:06 +0000
1497+++ src/downloads/priv/ubuntu/downloads/manager.cpp 2015-11-26 12:58:55 +0000
1498@@ -334,6 +334,45 @@
1499 return paths;
1500 }
1501
1502+QList<QDBusObjectPath>
1503+DownloadManager::getUncollectedDownloads(const QString &appId) {
1504+ QScopedPointer<System::AppArmor> appArmor(new System::AppArmor(_conn));
1505+ auto owner = getCaller();
1506+ auto callerAppId = appArmor->appId(owner);
1507+ QList<QDBusObjectPath> paths;
1508+ QString testAppId = appId;
1509+ if (appArmor->isConfined(callerAppId)) {
1510+ // Confined apps always get their own downloads returned
1511+ testAppId = callerAppId;
1512+ }
1513+
1514+ LOG(INFO) << "Returning uncollected downloads for app with id" << testAppId;
1515+
1516+ // Fetch uncollected downloads that are still in memory
1517+ auto transfers = _queue->transfers();
1518+ foreach(const QString& path, transfers.keys()) {
1519+ auto t = transfers[path];
1520+ if (t->transferAppId() == testAppId && t->state() != Transfer::FINISH
1521+ && t->state() != Transfer::CANCEL
1522+ && t->state() != Transfer::ERROR)
1523+ paths << QDBusObjectPath(path);
1524+ }
1525+
1526+ // Fetch uncollected downloads from previous UDM sessions that are
1527+ // in the database
1528+ foreach(Download *download, _db->getUncollectedDownloads(testAppId)) {
1529+ _conn->registerObject(download->path(), download);
1530+ paths << QDBusObjectPath(download->path());
1531+ }
1532+
1533+ return paths;
1534+}
1535+
1536+DownloadStateStruct
1537+DownloadManager::getDownloadState(const QString &downloadId) {
1538+ return _db->getDownloadState(downloadId);
1539+}
1540+
1541 } // Daemon
1542
1543 } // DownloadManager
1544
1545=== modified file 'src/downloads/priv/ubuntu/downloads/manager.h'
1546--- src/downloads/priv/ubuntu/downloads/manager.h 2015-08-27 09:02:19 +0000
1547+++ src/downloads/priv/ubuntu/downloads/manager.h 2015-11-26 12:58:55 +0000
1548@@ -18,14 +18,17 @@
1549
1550 #pragma once
1551
1552+#include <functional>
1553+
1554+#include <QByteArray>
1555+#include <QDBusObjectPath>
1556 #include <QObject>
1557-#include <QByteArray>
1558-#include <QtDBus/QDBusObjectPath>
1559 #include <QSslCertificate>
1560+
1561 #include <ubuntu/transfers/queue.h>
1562 #include <ubuntu/transfers/system/dbus_connection.h>
1563 #include <ubuntu/download_manager/metatypes.h>
1564-#include <functional>
1565+
1566 #include "ubuntu/transfers/base_manager.h"
1567 #include "ubuntu/transfers/system/application.h"
1568 #include "download.h"
1569@@ -83,6 +86,9 @@
1570 virtual QList<QDBusObjectPath> getAllDownloadsWithMetadata(
1571 const QString& name,
1572 const QString& value);
1573+ virtual QList<QDBusObjectPath> getUncollectedDownloads(
1574+ const QString& appId);
1575+ virtual DownloadStateStruct getDownloadState(const QString &downloadId);
1576 signals:
1577 void downloadCreated(const QDBusObjectPath& path);
1578
1579
1580=== modified file 'src/downloads/priv/ubuntu/downloads/state_machines/download_sm.h'
1581--- src/downloads/priv/ubuntu/downloads/state_machines/download_sm.h 2014-02-21 12:46:26 +0000
1582+++ src/downloads/priv/ubuntu/downloads/state_machines/download_sm.h 2015-11-26 12:58:55 +0000
1583@@ -157,6 +157,7 @@
1584 static QString POST_PROCESSING;
1585 static QString ERROR;
1586 static QString CANCELED;
1587+ static QString UNCOLLECTED;
1588 static QString FINISHED;
1589
1590 signals:
1591
1592=== modified file 'src/downloads/qml/CMakeLists.txt'
1593--- src/downloads/qml/CMakeLists.txt 2014-09-05 14:40:54 +0000
1594+++ src/downloads/qml/CMakeLists.txt 2015-11-26 12:58:55 +0000
1595@@ -5,6 +5,7 @@
1596 backend.cpp
1597 metadata.cpp
1598 download_error.cpp
1599+ download_history.cpp
1600 single_download.cpp
1601 ubuntu_download_manager.cpp
1602 )
1603@@ -13,6 +14,7 @@
1604 backend.h
1605 metadata.h
1606 download_error.h
1607+ download_history.h
1608 single_download.h
1609 ubuntu_download_manager.h
1610 )
1611
1612=== modified file 'src/downloads/qml/backend.cpp'
1613--- src/downloads/qml/backend.cpp 2014-09-23 10:38:11 +0000
1614+++ src/downloads/qml/backend.cpp 2015-11-26 12:58:55 +0000
1615@@ -15,6 +15,10 @@
1616 qmlRegisterType<Ubuntu::DownloadManager::Metadata>(uri, 0, 1, "Metadata");
1617 qmlRegisterType<Ubuntu::DownloadManager::SingleDownload>(uri, 0, 1, "SingleDownload");
1618 qmlRegisterType<Ubuntu::DownloadManager::UbuntuDownloadManager>(uri, 0, 1, "DownloadManager");
1619+ qmlRegisterType<Ubuntu::DownloadManager::DownloadError>(uri, 1, 2, "Error");
1620+ qmlRegisterType<Ubuntu::DownloadManager::Metadata>(uri, 1, 2, "Metadata");
1621+ qmlRegisterType<Ubuntu::DownloadManager::SingleDownload>(uri, 1, 2, "SingleDownload");
1622+ qmlRegisterType<Ubuntu::DownloadManager::UbuntuDownloadManager>(uri, 1, 2, "DownloadManager");
1623 }
1624
1625 void BackendPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
1626
1627=== added file 'src/downloads/qml/download_history.cpp'
1628--- src/downloads/qml/download_history.cpp 1970-01-01 00:00:00 +0000
1629+++ src/downloads/qml/download_history.cpp 2015-11-26 12:58:55 +0000
1630@@ -0,0 +1,143 @@
1631+#include "download_history.h"
1632+#include <glog/logging.h>
1633+#include <ubuntu/download_manager/download_struct.h>
1634+#include <QCoreApplication>
1635+
1636+namespace Ubuntu {
1637+
1638+namespace DownloadManager {
1639+
1640+DownloadHistory::DownloadHistory(QObject *parent) :
1641+ QObject(parent),
1642+ m_manager(nullptr)
1643+{
1644+ m_manager = Manager::createSessionManager("", this);
1645+
1646+ CHECK(connect(m_manager, &Manager::downloadsFound,
1647+ this, &DownloadHistory::downloadsFound))
1648+ << "Could not connect to signal";
1649+
1650+ // Get previous downloads for this app
1651+ auto environment = QProcessEnvironment::systemEnvironment();
1652+ if (environment.contains("APP_ID")) {
1653+ m_manager->getUncollectedDownloads(environment.value("APP_ID"));
1654+ } else {
1655+ m_manager->getUncollectedDownloads(QCoreApplication::applicationFilePath());
1656+ }
1657+}
1658+
1659+DownloadHistory *DownloadHistory::instance()
1660+{
1661+ static DownloadHistory *downloadHistory = new DownloadHistory();
1662+ return downloadHistory;
1663+}
1664+
1665+QVariantList DownloadHistory::downloads() const
1666+{
1667+ return m_downloads;
1668+}
1669+
1670+void DownloadHistory::addDownload(SingleDownload *singleDownload)
1671+{
1672+ m_downloads.append(QVariant::fromValue(singleDownload));
1673+ CHECK(connect(singleDownload, &SingleDownload::finished,
1674+ this, &DownloadHistory::downloadCompleted))
1675+ << "Could not connect to signal";
1676+ CHECK(connect(singleDownload, &SingleDownload::errorFound,
1677+ this, &DownloadHistory::onError))
1678+ << "Could not connect to signal";
1679+ CHECK(connect(singleDownload, &SingleDownload::paused,
1680+ this, &DownloadHistory::onPaused))
1681+ << "Could not connect to signal";
1682+ CHECK(connect(singleDownload, &SingleDownload::resumed,
1683+ this, &DownloadHistory::onResumed))
1684+ << "Could not connect to signal";
1685+ CHECK(connect(singleDownload, &SingleDownload::canceled,
1686+ this, &DownloadHistory::onCanceled))
1687+ << "Could not connect to signal";
1688+ emit downloadsChanged();
1689+}
1690+
1691+void DownloadHistory::downloadsFound(DownloadsList* downloadsList)
1692+{
1693+ foreach(QSharedPointer<Download> download, downloadsList->downloads()) {
1694+ SingleDownload* singleDownload = new SingleDownload(this);
1695+ singleDownload->bindDownload(download.data());
1696+ if (download->state() == Download::UNCOLLECTED && !download->filePath().isEmpty()) {
1697+ emit singleDownload->finished(download.data()->filePath());
1698+ }
1699+ }
1700+ emit downloadsChanged();
1701+}
1702+
1703+bool DownloadHistory::cleanDownloads() const
1704+{
1705+ return m_cleanDownloads;
1706+}
1707+
1708+void DownloadHistory::setCleanDownloads(bool value)
1709+{
1710+ m_cleanDownloads = value;
1711+ if (m_cleanDownloads) {
1712+ QVariantList newList;
1713+ foreach(QVariant var, m_downloads) {
1714+ SingleDownload *download = qobject_cast<SingleDownload*>(var.value<SingleDownload*>());
1715+ if (download != nullptr && !download->isCompleted()) {
1716+ newList.append(QVariant::fromValue(download));
1717+ } else {
1718+ download->deleteLater();
1719+ }
1720+ }
1721+ m_downloads = newList;
1722+ emit downloadsChanged();
1723+ }
1724+}
1725+
1726+void DownloadHistory::downloadCompleted(const QString& path)
1727+{
1728+ SingleDownload* download = qobject_cast<SingleDownload*>(sender());
1729+ if (download != nullptr) {
1730+ emit downloadFinished(download, path);
1731+ if (m_cleanDownloads) {
1732+ int index = m_downloads.indexOf(QVariant::fromValue(download));
1733+ m_downloads.removeAt(index);
1734+ emit downloadsChanged();
1735+ }
1736+ }
1737+}
1738+
1739+void DownloadHistory::onError(DownloadError& downloadError)
1740+{
1741+ Q_UNUSED(downloadError);
1742+ SingleDownload* download = qobject_cast<SingleDownload*>(sender());
1743+ if (download != nullptr) {
1744+ emit errorFound(download);
1745+ }
1746+}
1747+
1748+void DownloadHistory::onPaused()
1749+{
1750+ SingleDownload* download = qobject_cast<SingleDownload*>(sender());
1751+ if (download != nullptr) {
1752+ emit downloadPaused(download);
1753+ }
1754+}
1755+
1756+void DownloadHistory::onResumed()
1757+{
1758+ SingleDownload* download = qobject_cast<SingleDownload*>(sender());
1759+ if (download != nullptr) {
1760+ emit downloadResumed(download);
1761+ }
1762+}
1763+
1764+void DownloadHistory::onCanceled()
1765+{
1766+ SingleDownload* download = qobject_cast<SingleDownload*>(sender());
1767+ if (download != nullptr) {
1768+ emit downloadCanceled(download);
1769+ }
1770+}
1771+
1772+}
1773+}
1774
1775=== added file 'src/downloads/qml/download_history.h'
1776--- src/downloads/qml/download_history.h 1970-01-01 00:00:00 +0000
1777+++ src/downloads/qml/download_history.h 2015-11-26 12:58:55 +0000
1778@@ -0,0 +1,69 @@
1779+/*
1780+ * Copyright 2015 Canonical Ltd.
1781+ *
1782+ * This library is free software; you can redistribute it and/or
1783+ * modify it under the terms of version 3 of the GNU Lesser General Public
1784+ * License as published by the Free Software Foundation.
1785+ *
1786+ * This program is distributed in the hope that it will be useful,
1787+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1788+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1789+ * General Public License for more details.
1790+ *
1791+ * You should have received a copy of the GNU Lesser General Public
1792+ * License along with this library; if not, write to the
1793+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
1794+ * Boston, MA 02110-1301, USA.
1795+ */
1796+
1797+#ifndef DOWNLOAD_HISTORY_H
1798+#define DOWNLOAD_HISTORY_H
1799+
1800+#include <ubuntu/download_manager/manager.h>
1801+#include <ubuntu/download_manager/downloads_list.h>
1802+
1803+#include "single_download.h"
1804+
1805+namespace Ubuntu {
1806+
1807+namespace DownloadManager {
1808+
1809+class DownloadHistory : public QObject {
1810+ Q_OBJECT
1811+
1812+ public:
1813+ explicit DownloadHistory(QObject* parent=0);
1814+ static DownloadHistory *instance();
1815+
1816+ QVariantList downloads() const;
1817+ void downloadsFound(DownloadsList* downloadsList);
1818+ void addDownload(SingleDownload *singleDownload);
1819+ bool cleanDownloads() const;
1820+ void setCleanDownloads(bool value);
1821+
1822+ signals:
1823+ void downloadsChanged();
1824+ void downloadFinished(SingleDownload *singleDownload, const QString& path);
1825+ void errorFound(SingleDownload *download);
1826+ void downloadPaused(SingleDownload *singleDownload);
1827+ void downloadResumed(SingleDownload *singleDownload);
1828+ void downloadCanceled(SingleDownload *singleDownload);
1829+
1830+ private slots:
1831+ void downloadCompleted(const QString& path);
1832+ void onError(DownloadError& error);
1833+ void onPaused();
1834+ void onResumed();
1835+ void onCanceled();
1836+
1837+ private:
1838+ Manager* m_manager;
1839+ QVariantList m_downloads;
1840+ bool m_cleanDownloads;
1841+};
1842+
1843+} // Ubuntu
1844+
1845+} // DownloadManager
1846+
1847+#endif
1848
1849=== modified file 'src/downloads/qml/single_download.cpp'
1850--- src/downloads/qml/single_download.cpp 2014-10-07 14:44:11 +0000
1851+++ src/downloads/qml/single_download.cpp 2015-11-26 12:58:55 +0000
1852@@ -20,6 +20,7 @@
1853 #include <ubuntu/download_manager/download_struct.h>
1854
1855 #include "single_download.h"
1856+#include "download_history.h"
1857
1858 namespace Ubuntu {
1859
1860@@ -28,7 +29,7 @@
1861 /*!
1862 \qmltype SingleDownload
1863 \instantiates SingleDownload
1864- \inqmlmodule Ubuntu.DownloadManager 0.1
1865+ \inqmlmodule Ubuntu.DownloadManager 1.2
1866 \ingroup download
1867 \brief Manage file downloads and tracking the progress.
1868
1869@@ -39,8 +40,8 @@
1870
1871 \qml
1872 import QtQuick 2.0
1873- import Ubuntu.Components 0.1
1874- import Ubuntu.DownloadManager 0.1
1875+ import Ubuntu.Components 1.2
1876+ import Ubuntu.DownloadManager 1.2
1877
1878 Rectangle {
1879 width: units.gu(100)
1880@@ -152,8 +153,6 @@
1881 &SingleDownload::onStarted))
1882 << "Could not connect to signal";
1883
1884- emit downloadIdChanged();
1885-
1886 // is the current in memory setting dirty, if they are, we do set the before we
1887 // start
1888 if (m_dirty) {
1889@@ -169,6 +168,14 @@
1890 if (m_manager != nullptr && m_autoStart) {
1891 startDownload();
1892 }
1893+
1894+ DownloadHistory::instance()->addDownload(this);
1895+
1896+ // Keep a record of the downloadId so clients can still access the property
1897+ // after a download has finished
1898+ m_downloadId = m_download->id();
1899+
1900+ emit downloadIdChanged();
1901 }
1902
1903 void
1904@@ -222,7 +229,9 @@
1905 &SingleDownload::bindDownload))
1906 << "Could not connect to signal";
1907 }
1908- DownloadStruct dstruct(url);
1909+ Metadata metadata;
1910+ QMap<QString, QString> headers;
1911+ DownloadStruct dstruct(url, metadata.map(), headers);
1912 m_manager->createDownload(dstruct);
1913 } else {
1914 m_error.setMessage("Current download still in progress.");
1915@@ -258,7 +267,9 @@
1916 void
1917 SingleDownload::pause()
1918 {
1919- m_download->pause();
1920+ if (m_download != nullptr) {
1921+ m_download->pause();
1922+ }
1923 }
1924
1925 /*!
1926@@ -270,7 +281,9 @@
1927 void
1928 SingleDownload::resume()
1929 {
1930- m_download->resume();
1931+ if (m_download != nullptr) {
1932+ m_download->resume();
1933+ }
1934 }
1935
1936 /*!
1937@@ -281,7 +294,9 @@
1938 void
1939 SingleDownload::cancel()
1940 {
1941- m_download->cancel();
1942+ if (m_download != nullptr) {
1943+ m_download->cancel();
1944+ }
1945 }
1946
1947 void
1948@@ -354,7 +369,7 @@
1949 bool
1950 SingleDownload::allowMobileDownload() const {
1951 if (m_download == nullptr) {
1952- return m_mobile;
1953+ return m_mobile;
1954 } else {
1955 return m_download->isMobileDownloadAllowed();
1956 }
1957@@ -412,7 +427,7 @@
1958 QString
1959 SingleDownload::downloadId() const {
1960 if (m_download == nullptr) {
1961- return "";
1962+ return m_downloadId;
1963 } else {
1964 return m_download->id();
1965 }
1966@@ -577,11 +592,20 @@
1967 */
1968
1969 /*!
1970- \qmlproperty QVariantMap SingleDownload:metadata:
1971+ \qmlproperty QVariantMap SingleDownload::metadata
1972
1973 This property allows to get and set the metadata that will be linked to
1974 the download request.
1975 */
1976
1977+/*!
1978+ \qmlsignal SingleDownload::downloadFinished(QString path)
1979+
1980+ This signal is emitted when a download has finished. The downloaded file
1981+ path is provided via the 'path' paremeter. The corresponding handler is
1982+ \c onDownloadFinished
1983+*/
1984+
1985+
1986 }
1987 }
1988
1989=== modified file 'src/downloads/qml/single_download.h'
1990--- src/downloads/qml/single_download.h 2015-02-02 11:22:26 +0000
1991+++ src/downloads/qml/single_download.h 2015-11-26 12:58:55 +0000
1992@@ -171,6 +171,7 @@
1993 DownloadError m_error;
1994 Download* m_download = nullptr;
1995 Manager* m_manager = nullptr;
1996+ QString m_downloadId;
1997
1998 };
1999
2000
2001=== modified file 'src/downloads/qml/ubuntu_download_manager.cpp'
2002--- src/downloads/qml/ubuntu_download_manager.cpp 2014-05-07 12:27:08 +0000
2003+++ src/downloads/qml/ubuntu_download_manager.cpp 2015-11-26 12:58:55 +0000
2004@@ -1,6 +1,8 @@
2005 #include "ubuntu_download_manager.h"
2006+#include "download_history.h"
2007 #include <glog/logging.h>
2008 #include <ubuntu/download_manager/download_struct.h>
2009+#include <QDebug>
2010
2011 namespace Ubuntu {
2012
2013@@ -9,7 +11,7 @@
2014 /*!
2015 \qmltype DownloadManager
2016 \instantiates DownloadManager
2017- \inqmlmodule Ubuntu.DownloadManager 0.1
2018+ \inqmlmodule Ubuntu.DownloadManager 1.2
2019 \ingroup download
2020 \brief Manage downloads for several files.
2021
2022@@ -23,8 +25,8 @@
2023
2024 \qml
2025 import QtQuick 2.0
2026- import Ubuntu.Components 0.1
2027- import Ubuntu.DownloadManager 0.1
2028+ import Ubuntu.Components 1.2
2029+ import Ubuntu.DownloadManager 1.2
2030
2031 Rectangle {
2032 width: units.gu(100)
2033@@ -89,6 +91,24 @@
2034 CHECK(connect(m_manager, &Manager::downloadCreated,
2035 this, &UbuntuDownloadManager::downloadFileCreated))
2036 << "Could not connect to signal";
2037+ CHECK(connect(DownloadHistory::instance(), &DownloadHistory::downloadsChanged,
2038+ this, &UbuntuDownloadManager::downloadsChanged))
2039+ << "Could not connect to signal";
2040+ CHECK(connect(DownloadHistory::instance(), &DownloadHistory::downloadFinished,
2041+ this, &UbuntuDownloadManager::downloadFinished))
2042+ << "Could not connect to signal";
2043+ CHECK(connect(DownloadHistory::instance(), &DownloadHistory::downloadPaused,
2044+ this, &UbuntuDownloadManager::downloadPaused))
2045+ << "Could not connect to signal";
2046+ CHECK(connect(DownloadHistory::instance(), &DownloadHistory::downloadResumed,
2047+ this, &UbuntuDownloadManager::downloadResumed))
2048+ << "Could not connect to signal";
2049+ CHECK(connect(DownloadHistory::instance(), &DownloadHistory::downloadCanceled,
2050+ this, &UbuntuDownloadManager::downloadCanceled))
2051+ << "Could not connect to signal";
2052+ CHECK(connect(DownloadHistory::instance(), &DownloadHistory::errorFound,
2053+ this, &UbuntuDownloadManager::errorFound))
2054+ << "Could not connect to signal";
2055 }
2056
2057 UbuntuDownloadManager::~UbuntuDownloadManager()
2058@@ -96,7 +116,6 @@
2059 if (m_manager != nullptr) {
2060 m_manager->deleteLater();
2061 }
2062- m_downloads.clear();
2063 }
2064
2065 /*!
2066@@ -106,7 +125,9 @@
2067 */
2068 void UbuntuDownloadManager::download(QString url)
2069 {
2070- DownloadStruct dstruct(url);
2071+ Metadata metadata;
2072+ QMap<QString, QString> headers;
2073+ DownloadStruct dstruct(url, metadata.map(), headers);
2074 m_manager->createDownload(dstruct);
2075 }
2076
2077@@ -116,12 +137,7 @@
2078 CHECK(connect(singleDownload, &SingleDownload::errorFound,
2079 this, &UbuntuDownloadManager::registerError))
2080 << "Could not connect to signal";
2081- CHECK(connect(singleDownload, &SingleDownload::finished,
2082- this, &UbuntuDownloadManager::downloadCompleted))
2083- << "Could not connect to signal";
2084 singleDownload->bindDownload(download);
2085- m_downloads.append(QVariant::fromValue(singleDownload));
2086- emit downloadsChanged();
2087 if (m_autoStart) {
2088 singleDownload->startDownload();
2089 }
2090@@ -132,41 +148,25 @@
2091 Q_UNUSED(group);
2092 }
2093
2094-void UbuntuDownloadManager::registerError(DownloadError& error)
2095+void UbuntuDownloadManager::registerError(DownloadError& downloadError)
2096 {
2097- m_errorMessage = error.message();
2098+ m_errorMessage = downloadError.message();
2099 emit errorChanged();
2100 }
2101
2102+bool UbuntuDownloadManager::cleanDownloads() const
2103+{
2104+ return DownloadHistory::instance()->cleanDownloads();
2105+}
2106+
2107 void UbuntuDownloadManager::setCleanDownloads(bool value)
2108 {
2109- m_cleanDownloads = value;
2110- if (m_cleanDownloads) {
2111- QVariantList newList;
2112- foreach(QVariant var, m_downloads) {
2113- SingleDownload *download = qobject_cast<SingleDownload*>(var.value<SingleDownload*>());
2114- if (download != nullptr && !download->isCompleted()) {
2115- newList.append(QVariant::fromValue(download));
2116- } else {
2117- download->deleteLater();
2118- }
2119- }
2120- m_downloads = newList;
2121- emit downloadsChanged();
2122- }
2123+ DownloadHistory::instance()->setCleanDownloads(value);
2124 }
2125
2126-void UbuntuDownloadManager::downloadCompleted()
2127+QVariantList UbuntuDownloadManager::downloads()
2128 {
2129- if (m_cleanDownloads) {
2130- SingleDownload* download = qobject_cast<SingleDownload*>(sender());
2131- if (download != nullptr) {
2132- int index = m_downloads.indexOf(QVariant::fromValue(download));
2133- m_downloads.removeAt(index);
2134- emit downloadsChanged();
2135- download->deleteLater();
2136- }
2137- }
2138+ return DownloadHistory::instance()->downloads();
2139 }
2140
2141 /*!
2142@@ -198,5 +198,47 @@
2143 started, and let a custom delegate how to represent the UI for each download.
2144 */
2145
2146+/*!
2147+ \qmlsignal DownloadManager::errorFound(SingleDownload download)
2148+ \since Ubuntu.DownloadManager 1.2
2149+
2150+ This signal is emitted when an error occurs in a download. The download in which the
2151+ error occurred is provided via the 'download' parameter, from which the error message
2152+ can be accessed via download.errorMessage. The corresponding handler is \c onErrorFound
2153+*/
2154+
2155+/*!
2156+ \qmlsignal DownloadManager::downloadFinished(SingleDownload download, QString path)
2157+ \since Ubuntu.DownloadManager 1.2
2158+
2159+ This signal is emitted when a download has finished. The finished download is provided
2160+ via the 'download' parameter and the downloaded file path is provided via the 'path'
2161+ paremeter. The corresponding handler is \c onDownloadFinished
2162+*/
2163+
2164+/*!
2165+ \qmlsignal DownloadManager::downloadPaused(SingleDownload download)
2166+ \since Ubuntu.DownloadManager 1.2
2167+
2168+ This signal is emitted when a download has been paused. The paused download is provided
2169+ via the 'download' parameter. The corresponding handler is \c onDownloadPaused
2170+*/
2171+
2172+/*!
2173+ \qmlsignal DownloadManager::downloadResumed(SingleDownload download)
2174+ \since Ubuntu.DownloadManager 1.2
2175+
2176+ This signal is emitted when a download has been resumed. The resumed download is provided
2177+ via the 'download' parameter. The corresponding handler is \c onDownloadResumed
2178+*/
2179+
2180+/*!
2181+ \qmlsignal DownloadManager::downloadCanceled(SingleDownload download)
2182+ \since Ubuntu.DownloadManager 1.2
2183+
2184+ This signal is emitted when a download has been canceled. The canceled download is provided
2185+ via the 'download' parameter. The corresponding handler is \c onDownloadCanceled
2186+*/
2187 }
2188+
2189 }
2190
2191=== modified file 'src/downloads/qml/ubuntu_download_manager.h'
2192--- src/downloads/qml/ubuntu_download_manager.h 2014-06-25 08:46:25 +0000
2193+++ src/downloads/qml/ubuntu_download_manager.h 2015-11-26 12:58:55 +0000
2194@@ -45,27 +45,31 @@
2195
2196 Q_INVOKABLE void download(QString url);
2197
2198- QVariantList downloads() { return m_downloads; }
2199+ QVariantList downloads();
2200 QString errorMessage() const { return m_errorMessage; }
2201 bool autoStart() const { return m_autoStart; }
2202- bool cleanDownloads() const { return m_cleanDownloads; }
2203+ bool cleanDownloads() const;
2204 void setCleanDownloads(bool value);
2205 void setAutoStart(bool value) { m_autoStart = value; }
2206
2207 signals:
2208 void errorChanged();
2209 void downloadsChanged();
2210+ void downloadFinished(SingleDownload *download, const QString& path);
2211+ void errorFound(SingleDownload *download);
2212+ void downloadPaused(SingleDownload *download);
2213+ void downloadResumed(SingleDownload *download);
2214+ void downloadCanceled(SingleDownload *download);
2215
2216 private slots:
2217 void registerError(DownloadError& error);
2218 void downloadFileCreated(Download* download);
2219 void downloadGroupCreated(GroupDownload* group);
2220- void downloadCompleted();
2221+ void downloadsFound(DownloadsList* downloads);
2222
2223 private:
2224 bool m_autoStart;
2225 bool m_cleanDownloads;
2226- QVariantList m_downloads;
2227 QString m_errorMessage;
2228 Manager* m_manager;
2229 };
2230
2231=== modified file 'tests/downloads/daemon/download.h'
2232--- tests/downloads/daemon/download.h 2014-07-03 09:01:01 +0000
2233+++ tests/downloads/daemon/download.h 2015-11-26 12:58:55 +0000
2234@@ -84,8 +84,8 @@
2235 MOCK_METHOD0(pauseTransfer, void());
2236 MOCK_METHOD0(resumeTransfer, void());
2237 MOCK_METHOD0(startTransfer, void());
2238+ MOCK_METHOD0(filePath, QString());
2239 MOCK_CONST_METHOD0(isValid, bool());
2240- MOCK_CONST_METHOD0(filePath, QString());
2241 MOCK_CONST_METHOD0(state, Transfer::State());
2242 MOCK_CONST_METHOD0(path, QString());
2243 MOCK_CONST_METHOD0(metadata, QVariantMap());
2244
2245=== modified file 'tests/downloads/daemon/test_download.cpp'
2246--- tests/downloads/daemon/test_download.cpp 2015-02-25 16:24:24 +0000
2247+++ tests/downloads/daemon/test_download.cpp 2015-11-26 12:58:55 +0000
2248@@ -1301,7 +1301,7 @@
2249 QVERIFY(spy.ensureSignalEmitted());
2250 QTRY_COMPARE(spy.count(), 1);
2251 QTRY_COMPARE(processingSpy.count(), 0);
2252- QCOMPARE(download->state(), Download::FINISH);
2253+ QCOMPARE(download->state(), Download::UNCOLLECTED);
2254
2255 delete download;
2256
2257@@ -1481,7 +1481,7 @@
2258 QVERIFY(spy.ensureSignalEmitted());
2259 QTRY_COMPARE(spy.count(), 1);
2260 QTRY_COMPARE(processingSpy.count(), 1);
2261- QCOMPARE(download->state(), Download::FINISH);
2262+ QCOMPARE(download->state(), Download::UNCOLLECTED);
2263
2264 delete download;
2265
2266@@ -2196,7 +2196,7 @@
2267
2268 QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 20000);
2269 QTRY_COMPARE_WITH_TIMEOUT(processingSpy.count(), 1, 20000);
2270- QCOMPARE(download->state(), Download::FINISH);
2271+ QCOMPARE(download->state(), Download::UNCOLLECTED);
2272
2273 delete download;
2274
2275@@ -2309,7 +2309,7 @@
2276
2277 QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 20000);
2278 QTRY_COMPARE_WITH_TIMEOUT(processingSpy.count(), 1, 20000);
2279- QCOMPARE(download->state(), Download::FINISH);
2280+ QCOMPARE(download->state(), Download::UNCOLLECTED);
2281
2282 delete download;
2283
2284@@ -2431,7 +2431,7 @@
2285 QVERIFY(spy.ensureSignalEmitted());
2286 QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 20000);
2287 QTRY_COMPARE_WITH_TIMEOUT(processingSpy.count(), 1, 20000);
2288- QCOMPARE(download->state(), Download::FINISH);
2289+ QCOMPARE(download->state(), Download::UNCOLLECTED);
2290
2291 delete download;
2292
2293@@ -3735,7 +3735,7 @@
2294 QVERIFY(spy.ensureSignalEmitted());
2295 QCOMPARE(spy.count(), 1);
2296 QCOMPARE(processingSpy.count(), 1);
2297- QCOMPARE(download->state(), Download::FINISH);
2298+ QCOMPARE(download->state(), Download::UNCOLLECTED);
2299
2300 delete download;
2301
2302@@ -4167,7 +4167,7 @@
2303
2304 QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 20000);
2305 QTRY_COMPARE_WITH_TIMEOUT(processingSpy.count(), 1, 20000);
2306- QCOMPARE(download->state(), Download::FINISH);
2307+ QCOMPARE(download->state(), Download::UNCOLLECTED);
2308
2309 delete download;
2310
2311
2312=== modified file 'tests/downloads/daemon/test_downloads_db.cpp'
2313--- tests/downloads/daemon/test_downloads_db.cpp 2014-11-17 20:34:24 +0000
2314+++ tests/downloads/daemon/test_downloads_db.cpp 2015-11-26 12:58:55 +0000
2315@@ -351,4 +351,77 @@
2316 QTRY_COMPARE(1, spy.count());
2317 }
2318
2319+void
2320+TestDownloadsDb::testGetStateMissingDownload() {
2321+ _db->init();
2322+ auto result = _db->getDownloadState("random uuid");
2323+ QVERIFY(!result.isValid());
2324+}
2325+
2326+void
2327+TestDownloadsDb::testGetStateDownload_data() {
2328+ QTest::addColumn<QString>("id");
2329+ QTest::addColumn<QString>("appId");
2330+ QTest::addColumn<QString>("path");
2331+ QTest::addColumn<QUrl>("url");
2332+ QTest::addColumn<QString>("hash");
2333+ QTest::addColumn<QString>("hashAlgoString");
2334+ QTest::addColumn<QVariantMap>("metadata");
2335+ QTest::addColumn<QMap<QString, QString> >("headers");
2336+
2337+ QTest::newRow("First Row") << UuidUtils::getDBusString(QUuid::createUuid())
2338+ << "FIRST APP" << "first path" << QUrl("http://ubuntu.com") << ""
2339+ << "md5" << QVariantMap() << QMap<QString, QString>();
2340+
2341+ QVariantMap secondMetadata;
2342+ secondMetadata["test"] = 1;
2343+ secondMetadata["command"] = "cd";
2344+ secondMetadata["hello"] = 23;
2345+
2346+ QTest::newRow("Second Row") << UuidUtils::getDBusString(QUuid::createUuid())
2347+ << "SECOND APP" << "second path" << QUrl("http://ubuntu.com/phone")
2348+ << "" << "sha512" << secondMetadata << QMap<QString, QString>();
2349+
2350+ QVariantMap thirdMetadata;
2351+ secondMetadata["test"] = 3;
2352+ secondMetadata["command"] = "return";
2353+ secondMetadata["hello"] = 500;
2354+
2355+ QMap<QString, QString> thirdHeaders;
2356+ thirdHeaders["my-header"] = "I do something cool";
2357+
2358+ QTest::newRow("Third Row") << UuidUtils::getDBusString(QUuid::createUuid())
2359+ << "THIRD APP" << "third path" << QUrl("http://ubuntu.com/tablet")
2360+ << "" << "sha384" << thirdMetadata << thirdHeaders;
2361+}
2362+
2363+void
2364+TestDownloadsDb::testGetStateDownload() {
2365+ _db->init();
2366+ QFETCH(QString, id);
2367+ QFETCH(QString, appId);
2368+ QFETCH(QString, path);
2369+ QFETCH(QUrl, url);
2370+ QFETCH(QString, hash);
2371+ QFETCH(QString, hashAlgoString);
2372+ QFETCH(QVariantMap, metadata);
2373+ QFETCH(StringMap, headers);
2374+
2375+ QScopedPointer<FileDownload> download(new FileDownload(id, appId, path, true, "", url, hash,
2376+ hashAlgoString, metadata, headers));
2377+
2378+ _db->storeSingleDownload(download.data());
2379+
2380+ // create a second download with same id but a diff path to test is update
2381+ QString newPath = path + path;
2382+ QScopedPointer<FileDownload> secondDownload(new FileDownload(id, appId,
2383+ newPath, true, "", url, hash, hashAlgoString, metadata, headers));
2384+
2385+ _db->storeSingleDownload(secondDownload.data());
2386+ auto state = _db->getDownloadState(id);
2387+ QVERIFY(state.isValid());
2388+ QCOMPARE(state.getUrl(), url.toString());
2389+ QCOMPARE(state.getHash(), state.getHash());
2390+}
2391+
2392 QTEST_MAIN(TestDownloadsDb)
2393
2394=== modified file 'tests/downloads/daemon/test_downloads_db.h'
2395--- tests/downloads/daemon/test_downloads_db.h 2014-07-03 09:01:01 +0000
2396+++ tests/downloads/daemon/test_downloads_db.h 2015-11-26 12:58:55 +0000
2397@@ -15,8 +15,7 @@
2398 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
2399 * Boston, MA 02110-1301, USA.
2400 */
2401-#ifndef TEST_DOWNLOADS_DB_H
2402-#define TEST_DOWNLOADS_DB_H
2403+#pragma once
2404
2405 #include <QDir>
2406 #include <QObject>
2407@@ -65,9 +64,10 @@
2408 void testStoreSingleDownloadPresent();
2409 void testConnectedToDownload();
2410 void testDisconnectedFromDownload();
2411+ void testGetStateMissingDownload();
2412+ void testGetStateDownload_data();
2413+ void testGetStateDownload();
2414
2415 private:
2416 DownloadsDb* _db;
2417 };
2418-
2419-#endif // TEST_DOWNLOADS_DB_H

Subscribers

People subscribed via source and target branches