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
=== modified file '.bzrignore'
--- .bzrignore 2013-11-12 12:30:18 +0000
+++ .bzrignore 2015-11-26 12:58:55 +0000
@@ -12,3 +12,5 @@
12libubuntudownloadmanager-common/libubuntudownloadmanager-common.so.112libubuntudownloadmanager-common/libubuntudownloadmanager-common.so.1
13libubuntudownloadmanager-common/libubuntudownloadmanager-common.so.1.013libubuntudownloadmanager-common/libubuntudownloadmanager-common.so.1.0
14libubuntudownloadmanager-common/libubuntudownloadmanager-common.so.1.0.014libubuntudownloadmanager-common/libubuntudownloadmanager-common.so.1.0.0
15.idea
16build
1517
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2015-09-22 14:14:06 +0000
+++ CMakeLists.txt 2015-11-26 12:58:55 +0000
@@ -31,7 +31,7 @@
31)31)
3232
33set(UDM_VERSION_MAJOR 1)33set(UDM_VERSION_MAJOR 1)
34set(UDM_VERSION_MINOR 1)34set(UDM_VERSION_MINOR 2)
35set(UDM_VERSION_PATCH 0)35set(UDM_VERSION_PATCH 0)
3636
37find_package(Gtest REQUIRED)37find_package(Gtest REQUIRED)
3838
=== modified file 'debian/changelog'
--- debian/changelog 2015-09-22 15:27:25 +0000
+++ debian/changelog 2015-11-26 12:58:55 +0000
@@ -1,3 +1,11 @@
1ubuntu-download-manager (1.2) UNRELEASED; urgency=medium
2
3 * Provide a shared download history for the downloads model that presents
4 all uncollected downloads from previous app launches.
5 * Update symbol files
6
7 -- Michael Sheldon <michael.sheldon@canonical.com> Wed, 21 Oct 2015 10:03:21 +0100
8
1ubuntu-download-manager (1.1+15.04.20150922.4-0ubuntu1) vivid; urgency=medium9ubuntu-download-manager (1.1+15.04.20150922.4-0ubuntu1) vivid; urgency=medium
210
3 [ Manuel de la Pena ]11 [ Manuel de la Pena ]
@@ -11,6 +19,14 @@
1119
12 -- Bill Filler <ci-train-bot@canonical.com> Tue, 22 Sep 2015 15:27:25 +000020 -- Bill Filler <ci-train-bot@canonical.com> Tue, 22 Sep 2015 15:27:25 +0000
1321
22ubuntu-download-manager (1.1) UNRELEASED; urgency=medium
23
24 * Ensure that the app id of the application that created the download is
25 present in the metadata and can be accessed via dbus.
26 * Update the symbol files.
27
28 -- Manuel de la Pena <manuel.delapena@canonical.com> Tue, 01 Sep 2015 17:07:58 +0100
29
14ubuntu-download-manager (1.0+15.04-0ubuntu1) wily; urgency=medium30ubuntu-download-manager (1.0+15.04-0ubuntu1) wily; urgency=medium
1531
16 [ Manuel de la Pena ]32 [ Manuel de la Pena ]
1733
=== modified file 'debian/libubuntu-download-manager-client1.symbols'
--- debian/libubuntu-download-manager-client1.symbols 2015-09-22 15:27:25 +0000
+++ debian/libubuntu-download-manager-client1.symbols 2015-11-26 12:58:55 +0000
@@ -95,17 +95,17 @@
95 (c++)"Ubuntu::DownloadManager::AuthError::metaObject() const@Base" 0.4+14.10.2014061895 (c++)"Ubuntu::DownloadManager::AuthError::metaObject() const@Base" 0.4+14.10.20140618
96 (c++)"Ubuntu::DownloadManager::DBusError::metaObject() const@Base" 0.4+14.10.2014061896 (c++)"Ubuntu::DownloadManager::DBusError::metaObject() const@Base" 0.4+14.10.20140618
97 (c++)"Ubuntu::DownloadManager::HttpError::metaObject() const@Base" 0.4+14.10.2014061897 (c++)"Ubuntu::DownloadManager::HttpError::metaObject() const@Base" 0.4+14.10.20140618
98 (c++)"std::function<void (Ubuntu::DownloadManager::DownloadsList*)>::operator()(Ubuntu::DownloadManager::DownloadsList*) const@Base" 0.4+14.10.2014061898 (c++)"std::function<void (Ubuntu::DownloadManager::DownloadsList*)>::function(std::function<void (Ubuntu::DownloadManager::DownloadsList*)> const&)@Base" 0.4+14.10.20140618
99 (c++)"std::function<void (Ubuntu::DownloadManager::GroupDownload*)>::operator()(Ubuntu::DownloadManager::GroupDownload*) const@Base" 0.4+14.10.2014061899 (c++)"std::function<void (Ubuntu::DownloadManager::DownloadsList*)>::function(std::function<void (Ubuntu::DownloadManager::DownloadsList*)> const&)@Base" 0.4+14.10.20140618
100 (c++)"std::function<void (Ubuntu::DownloadManager::Download*)>::operator()(Ubuntu::DownloadManager::Download*) const@Base" 0.4+14.10.20140618100 (c++)"std::function<void (Ubuntu::DownloadManager::GroupDownload*)>::function(std::function<void (Ubuntu::DownloadManager::GroupDownload*)> const&)@Base" 0.4+14.10.20140618
101 (c++)"std::function<void (Ubuntu::DownloadManager::DownloadsList*)>::function(std::function<void (Ubuntu::DownloadManager::DownloadsList*)> const&)@Base" 0.4+14.10.20140618101 (c++)"std::function<void (Ubuntu::DownloadManager::GroupDownload*)>::function(std::function<void (Ubuntu::DownloadManager::GroupDownload*)> const&)@Base" 0.4+14.10.20140618
102 (c++)"std::function<void (Ubuntu::DownloadManager::DownloadsList*)>::function(std::function<void (Ubuntu::DownloadManager::DownloadsList*)> const&)@Base" 0.4+14.10.20140618102 (c++)"std::function<void (Ubuntu::DownloadManager::Download*)>::function(std::function<void (Ubuntu::DownloadManager::Download*)> const&)@Base" 0.4+14.10.20140618
103 (c++)"std::function<void (Ubuntu::DownloadManager::GroupDownload*)>::function(std::function<void (Ubuntu::DownloadManager::GroupDownload*)> const&)@Base" 0.4+14.10.20140618103 (c++)"std::function<void (Ubuntu::DownloadManager::Download*)>::function(std::function<void (Ubuntu::DownloadManager::Download*)> const&)@Base" 0.4+14.10.20140618
104 (c++)"std::function<void (Ubuntu::DownloadManager::GroupDownload*)>::function(std::function<void (Ubuntu::DownloadManager::GroupDownload*)> const&)@Base" 0.4+14.10.20140618104 (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
105 (c++)"std::function<void (Ubuntu::DownloadManager::Download*)>::function(std::function<void (Ubuntu::DownloadManager::Download*)> const&)@Base" 0.4+14.10.20140618105 (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
106 (c++)"std::function<void (Ubuntu::DownloadManager::Download*)>::function(std::function<void (Ubuntu::DownloadManager::Download*)> const&)@Base" 0.4+14.10.20140618106 (c++)"std::function<void (Ubuntu::DownloadManager::DownloadsList*)>::operator()(Ubuntu::DownloadManager::DownloadsList*) const@Base" 1.2
107 (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.20140618107 (c++)"std::function<void (Ubuntu::DownloadManager::GroupDownload*)>::operator()(Ubuntu::DownloadManager::GroupDownload*) const@Base" 1.2
108 (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.20140618108 (c++)"std::function<void (Ubuntu::DownloadManager::Download*)>::operator()(Ubuntu::DownloadManager::Download*) const@Base" 1.2
109 (c++)"typeinfo for Ubuntu::DownloadManager::NetworkError@Base" 0.4+14.10.20140618109 (c++)"typeinfo for Ubuntu::DownloadManager::NetworkError@Base" 0.4+14.10.20140618
110 (c++)"typeinfo for Ubuntu::DownloadManager::ProcessError@Base" 0.4+14.10.20140618110 (c++)"typeinfo for Ubuntu::DownloadManager::ProcessError@Base" 0.4+14.10.20140618
111 (c++)"typeinfo for Ubuntu::DownloadManager::DownloadsList@Base" 0.4+14.10.20140618111 (c++)"typeinfo for Ubuntu::DownloadManager::DownloadsList@Base" 0.4+14.10.20140618
112112
=== modified file 'debian/libubuntu-download-manager-common-dev.install'
--- debian/libubuntu-download-manager-common-dev.install 2014-06-06 10:05:15 +0000
+++ debian/libubuntu-download-manager-common-dev.install 2015-11-26 12:58:55 +0000
@@ -1,4 +1,5 @@
1usr/include/ubuntu/download_manager/metatypes.h1usr/include/ubuntu/download_manager/metatypes.h
2usr/include/ubuntu/download_manager/download_state_struct.h
2usr/include/ubuntu/download_manager/download_struct.h3usr/include/ubuntu/download_manager/download_struct.h
3usr/include/ubuntu/download_manager/group_download_struct.h4usr/include/ubuntu/download_manager/group_download_struct.h
4usr/lib/*/pkgconfig/ubuntu-download-manager-common.pc5usr/lib/*/pkgconfig/ubuntu-download-manager-common.pc
56
=== modified file 'debian/libubuntu-download-manager-common1.symbols'
--- debian/libubuntu-download-manager-common1.symbols 2015-07-23 14:02:27 +0000
+++ debian/libubuntu-download-manager-common1.symbols 2015-11-26 12:58:55 +0000
@@ -15,14 +15,29 @@
15 (c++)"Ubuntu::DownloadManager::DownloadStruct::DownloadStruct(Ubuntu::DownloadManager::DownloadStruct const&)@Base" 0.4+14.10.2014061815 (c++)"Ubuntu::DownloadManager::DownloadStruct::DownloadStruct(Ubuntu::DownloadManager::DownloadStruct const&)@Base" 0.4+14.10.20140618
16 (c++)"Ubuntu::DownloadManager::DownloadStruct::DownloadStruct()@Base" 0.4+14.10.2014061816 (c++)"Ubuntu::DownloadManager::DownloadStruct::DownloadStruct()@Base" 0.4+14.10.20140618
17 (c++)"Ubuntu::DownloadManager::DownloadStruct::operator=(Ubuntu::DownloadManager::DownloadStruct const&)@Base" 0.4+14.10.2014061817 (c++)"Ubuntu::DownloadManager::DownloadStruct::operator=(Ubuntu::DownloadManager::DownloadStruct const&)@Base" 0.4+14.10.20140618
18 (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct(QString const&, QString const&, QString const&)@Base" 0.4+14.10.2014061818 (c++)"Ubuntu::DownloadManager::DownloadStateStruct::isValid()@Base" 1.2
19 (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct(Ubuntu::DownloadManager::GroupDownloadStruct const&)@Base" 0.4+14.10.2014061819 (c++)"Ubuntu::DownloadManager::DownloadStateStruct::DownloadStateStruct(Ubuntu::DownloadManager::DownloadStateStruct const&)@Base" 1.2
20 (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct()@Base" 0.4+14.10.2014061820 (c++)"Ubuntu::DownloadManager::DownloadStateStruct::DownloadStateStruct(int, QString const&, QString const&)@Base" 1.2
21 (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct(QString const&, QString const&, QString const&)@Base" 0.4+14.10.2014061821 (c++)"Ubuntu::DownloadManager::DownloadStateStruct::DownloadStateStruct(int, QString const&, QString const&, QString const&)@Base" 1.2
22 (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct(Ubuntu::DownloadManager::GroupDownloadStruct const&)@Base" 0.4+14.10.2014061822 (c++)"Ubuntu::DownloadManager::DownloadStateStruct::DownloadStateStruct()@Base" 1.2
23 (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct()@Base" 0.4+14.10.2014061823 (c++)"Ubuntu::DownloadManager::DownloadStateStruct::DownloadStateStruct(Ubuntu::DownloadManager::DownloadStateStruct const&)@Base" 1.2
24 (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::~GroupDownloadStruct()@Base" 0.4+14.10.2014061824 (c++)"Ubuntu::DownloadManager::DownloadStateStruct::DownloadStateStruct(int, QString const&, QString const&)@Base" 1.2
25 (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::~GroupDownloadStruct()@Base" 0.4+14.10.2014061825 (c++)"Ubuntu::DownloadManager::DownloadStateStruct::DownloadStateStruct(int, QString const&, QString const&, QString const&)@Base" 1.2
26 (c++)"Ubuntu::DownloadManager::DownloadStateStruct::operator=(Ubuntu::DownloadManager::DownloadStateStruct const&)@Base" 1.2
27 (c++)"Ubuntu::DownloadManager::operator<<(QDBusArgument&, Ubuntu::DownloadManager::DownloadStateStruct const&)@Base" 1.2
28 (c++)"Ubuntu::DownloadManager::operator>>(QDBusArgument const&, Ubuntu::DownloadManager::DownloadStateStruct&)@Base" 1.2
29 (c++)"Ubuntu::DownloadManager::DownloadStateStruct::getFilePath() const@Base" 1.2
30 (c++)"Ubuntu::DownloadManager::DownloadStateStruct::getUrl() const@Base" 1.2
31 (c++)"Ubuntu::DownloadManager::DownloadStateStruct::getHash() const@Base" 1.2
32 (c++)"Ubuntu::DownloadManager::DownloadStateStruct::getState() const@Base" 1.2
33 (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::~GroupDownloadStruct()@Base" 1.2
34 (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::~GroupDownloadStruct()@Base" 1.2
35 (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct(QString const&, QString const&, QString const&)@Base" 0.4+14.10.20140618
36 (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct(Ubuntu::DownloadManager::GroupDownloadStruct const&)@Base" 0.4+14.10.20140618
37 (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct()@Base" 0.4+14.10.20140618
38 (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct(QString const&, QString const&, QString const&)@Base" 0.4+14.10.20140618
39 (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct(Ubuntu::DownloadManager::GroupDownloadStruct const&)@Base" 0.4+14.10.20140618
40 (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::GroupDownloadStruct()@Base" 0.4+14.10.20140618
26 (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::operator=(Ubuntu::DownloadManager::GroupDownloadStruct const&)@Base" 0.4+14.10.2014061841 (c++)"Ubuntu::DownloadManager::GroupDownloadStruct::operator=(Ubuntu::DownloadManager::GroupDownloadStruct const&)@Base" 0.4+14.10.20140618
27 (c++)"Ubuntu::DownloadManager::operator<<(QDBusArgument&, Ubuntu::DownloadManager::DownloadStruct const&)@Base" 0.4+14.10.2014061842 (c++)"Ubuntu::DownloadManager::operator<<(QDBusArgument&, Ubuntu::DownloadManager::DownloadStruct const&)@Base" 0.4+14.10.20140618
28 (c++)"Ubuntu::DownloadManager::operator<<(QDBusArgument&, Ubuntu::DownloadManager::GroupDownloadStruct const&)@Base" 0.4+14.10.2014061843 (c++)"Ubuntu::DownloadManager::operator<<(QDBusArgument&, Ubuntu::DownloadManager::GroupDownloadStruct const&)@Base" 0.4+14.10.20140618
2944
=== modified file 'debian/libudm-common1.symbols'
--- debian/libudm-common1.symbols 2015-09-22 15:27:25 +0000
+++ debian/libudm-common1.symbols 2015-11-26 12:58:55 +0000
@@ -56,7 +56,7 @@
56 (c++)"Ubuntu::Transfers::System::Logger::qt_metacall(QMetaObject::Call, int, void**)@Base" 0.4+14.10.2014061856 (c++)"Ubuntu::Transfers::System::Logger::qt_metacall(QMetaObject::Call, int, void**)@Base" 0.4+14.10.20140618
57 (c++)"Ubuntu::Transfers::System::Logger::qt_metacast(char const*)@Base" 0.4+14.10.2014061857 (c++)"Ubuntu::Transfers::System::Logger::qt_metacast(char const*)@Base" 0.4+14.10.20140618
58 (c++)"Ubuntu::Transfers::System::Logger::setLogLevel(QtMsgType)@Base" 0.4+14.10.2014061858 (c++)"Ubuntu::Transfers::System::Logger::setLogLevel(QtMsgType)@Base" 0.4+14.10.20140618
59 (c++)"Ubuntu::Transfers::System::Logger::toStdString(QString const&)@Base" 0.4+14.10.2014061859 (c++)"Ubuntu::Transfers::System::Logger::toStdString(QString const&)@Base" 0replaceme
60 (c++)"Ubuntu::Transfers::System::Logger::setupLogging(QString)@Base" 0.4+14.10.2014061860 (c++)"Ubuntu::Transfers::System::Logger::setupLogging(QString)@Base" 0.4+14.10.20140618
61 (c++)"Ubuntu::Transfers::System::Logger::staticMetaObject@Base" 0.4+14.10.2014061861 (c++)"Ubuntu::Transfers::System::Logger::staticMetaObject@Base" 0.4+14.10.20140618
62 (c++)"Ubuntu::Transfers::System::Logger::getLogDir()@Base" 0.4+14.10.2014061862 (c++)"Ubuntu::Transfers::System::Logger::getLogDir()@Base" 0.4+14.10.20140618
6363
=== modified file 'docs/dbus/com.canonical.applications.download.xml'
--- docs/dbus/com.canonical.applications.download.xml 2015-09-22 15:25:33 +0000
+++ docs/dbus/com.canonical.applications.download.xml 2015-11-26 12:58:55 +0000
@@ -49,10 +49,19 @@
49 <arg name="allowed" type="b" direction="out"/>49 <arg name="allowed" type="b" direction="out"/>
50 </method>50 </method>
5151
52 <method name="filePath">
53 <arg name="filepath" type="s" direction="out"/>
54 </method>
55
56 <method name="state">
57 <arg name="state" type="i" direction="out"/>
58 </method>
59
52 <method name="start" />60 <method name="start" />
53 <method name="pause" />61 <method name="pause" />
54 <method name="resume" />62 <method name="resume" />
55 <method name="cancel" />63 <method name="cancel" />
64 <method name="collected" />
5665
57 <signal name="started">66 <signal name="started">
58 <arg name="success" type="b" direction="out"/>67 <arg name="success" type="b" direction="out"/>
5968
=== modified file 'docs/dbus/com.canonical.applications.download_manager.xml'
--- docs/dbus/com.canonical.applications.download_manager.xml 2014-04-30 14:47:38 +0000
+++ docs/dbus/com.canonical.applications.download_manager.xml 2015-11-26 12:58:55 +0000
@@ -35,6 +35,17 @@
35 <arg name="downloads" type="ao" direction="out" />35 <arg name="downloads" type="ao" direction="out" />
36 </method>36 </method>
3737
38 <method name="getUncollectedDownloads">
39 <arg name="appId" type="s" direction="in"/>
40 <arg name="downloads" type="ao" direction="out"/>
41 </method>
42
43 <method name="getDownloadState">
44 <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="DownloadStateStruct"/>
45 <arg name="downloadId" type="s" direction="in"/>
46 <arg name="state" type="(issss)" direction="out"/>
47 </method>
48
38 <method name="setDefaultThrottle">49 <method name="setDefaultThrottle">
39 <arg name="speed" type="t" direction="in"/>50 <arg name="speed" type="t" direction="in"/>
40 </method>51 </method>
4152
=== modified file 'docs/qml/pages/mainpage.qdoc'
--- docs/qml/pages/mainpage.qdoc 2014-06-20 10:10:50 +0000
+++ docs/qml/pages/mainpage.qdoc 2015-11-26 12:58:55 +0000
@@ -35,7 +35,7 @@
35\section1 Components35\section1 Components
36Available through:36Available through:
37\code37\code
38 import Ubuntu.DownloadManager 0.138 import Ubuntu.DownloadManager 1.2
39\endcode39\endcode
4040
41\list41\list
@@ -47,8 +47,8 @@
4747
48\qml48\qml
49 import QtQuick 2.049 import QtQuick 2.0
50 import Ubuntu.Components 0.150 import Ubuntu.Components 1.2
51 import Ubuntu.DownloadManager 0.151 import Ubuntu.DownloadManager 1.2
5252
53 Rectangle {53 Rectangle {
54 width: units.gu(100)54 width: units.gu(100)
5555
=== modified file 'docs/qml/pages/moduledef.qdoc'
--- docs/qml/pages/moduledef.qdoc 2014-06-20 10:10:50 +0000
+++ docs/qml/pages/moduledef.qdoc 2015-11-26 12:58:55 +0000
@@ -1,3 +1,3 @@
1/*!1/*!
2 \qmlmodule Ubuntu.DownloadManager 0.12 \qmlmodule Ubuntu.DownloadManager 1.2
3*/3*/
44
=== modified file 'src/common/priv/ubuntu/transfers/queue.cpp'
--- src/common/priv/ubuntu/transfers/queue.cpp 2014-11-24 16:39:17 +0000
+++ src/common/priv/ubuntu/transfers/queue.cpp 2015-11-26 12:58:55 +0000
@@ -127,6 +127,7 @@
127 break;127 break;
128 case Transfer::ERROR:128 case Transfer::ERROR:
129 case Transfer::FINISH:129 case Transfer::FINISH:
130 case Transfer::UNCOLLECTED:
130 // remove the registered object in dbus, remove the transfer131 // remove the registered object in dbus, remove the transfer
131 // and the adapter from the list132 // and the adapter from the list
132 if (!_current.isEmpty() && _current == transfer->path())133 if (!_current.isEmpty() && _current == transfer->path())
@@ -177,6 +178,9 @@
177 LOG(INFO) << "State is CANCEL || FINISH || ERROR";178 LOG(INFO) << "State is CANCEL || FINISH || ERROR";
178 remove(_current);179 remove(_current);
179 _current = "";180 _current = "";
181 } else if (state == Transfer::UNCOLLECTED) {
182 LOG(INFO) << "State is UNCOLLECTED";
183 _current = "";
180 } else if (!currentTransfer->canTransfer()184 } else if (!currentTransfer->canTransfer()
181 || state == Transfer::PAUSE) {185 || state == Transfer::PAUSE) {
182 LOG(INFO) << "States is Cannot Transfer || PAUSE";186 LOG(INFO) << "States is Cannot Transfer || PAUSE";
183187
=== modified file 'src/common/priv/ubuntu/transfers/transfer.cpp'
--- src/common/priv/ubuntu/transfers/transfer.cpp 2014-11-26 12:21:53 +0000
+++ src/common/priv/ubuntu/transfers/transfer.cpp 2015-11-26 12:58:55 +0000
@@ -194,6 +194,13 @@
194 startTransfer();194 startTransfer();
195}195}
196196
197void
198Transfer::collected() {
199 if (state() == Transfer::UNCOLLECTED) {
200 setState(Transfer::FINISH);
201 }
202}
203
197} // General204} // General
198205
199} // Ubuntu206} // Ubuntu
200207
=== modified file 'src/common/priv/ubuntu/transfers/transfer.h'
--- src/common/priv/ubuntu/transfers/transfer.h 2015-02-02 11:05:15 +0000
+++ src/common/priv/ubuntu/transfers/transfer.h 2015-11-26 12:58:55 +0000
@@ -16,8 +16,7 @@
16 * Boston, MA 02110-1301, USA.16 * Boston, MA 02110-1301, USA.
17 */17 */
1818
19#ifndef UBUNTU_GENERAL_LIB_TRANSFER_H19#pragma once
20#define UBUNTU_GENERAL_LIB_TRANSFER_H
2120
22#include <QObject>21#include <QObject>
23#include "ubuntu/transfers/system/network_session.h"22#include "ubuntu/transfers/system/network_session.h"
@@ -36,6 +35,7 @@
36 PAUSE,35 PAUSE,
37 RESUME,36 RESUME,
38 CANCEL,37 CANCEL,
38 UNCOLLECTED,
39 FINISH,39 FINISH,
40 ERROR40 ERROR
41 };41 };
@@ -78,6 +78,7 @@
78 virtual void pause();78 virtual void pause();
79 virtual void resume();79 virtual void resume();
80 virtual void start();80 virtual void start();
81 virtual void collected();
8182
82 signals:83 signals:
83 void canceled(bool success);84 void canceled(bool success);
@@ -112,5 +113,3 @@
112} // Transfers113} // Transfers
113114
114} // Ubuntu115} // Ubuntu
115
116#endif
117116
=== modified file 'src/common/public/ubuntu/transfers/metadata.cpp'
--- src/common/public/ubuntu/transfers/metadata.cpp 2015-09-22 15:25:33 +0000
+++ src/common/public/ubuntu/transfers/metadata.cpp 2015-11-26 12:58:55 +0000
@@ -17,6 +17,7 @@
17 */17 */
1818
19#include <QProcessEnvironment>19#include <QProcessEnvironment>
20#include <QCoreApplication>
2021
21#include "metadata.h"22#include "metadata.h"
2223
@@ -43,6 +44,8 @@
43 auto environment = QProcessEnvironment::systemEnvironment();44 auto environment = QProcessEnvironment::systemEnvironment();
44 if (environment.contains(APP_ID_ENV)) {45 if (environment.contains(APP_ID_ENV)) {
45 setDestinationApp(environment.value(APP_ID_ENV));46 setDestinationApp(environment.value(APP_ID_ENV));
47 } else {
48 setDestinationApp(QCoreApplication::applicationFilePath());
46 }49 }
47}50}
4851
@@ -53,6 +56,11 @@
53 auto environment = QProcessEnvironment::systemEnvironment();56 auto environment = QProcessEnvironment::systemEnvironment();
54 environment.contains(APP_ID_ENV);57 environment.contains(APP_ID_ENV);
55 setDestinationApp(environment.value(APP_ID_ENV));58 setDestinationApp(environment.value(APP_ID_ENV));
59 if (environment.contains(APP_ID_ENV)) {
60 setDestinationApp(environment.value(APP_ID_ENV));
61 } else {
62 setDestinationApp(QCoreApplication::applicationFilePath());
63 }
56 }64 }
57}65}
5866
5967
=== modified file 'src/downloads/client/ubuntu/download_manager/download.h'
--- src/downloads/client/ubuntu/download_manager/download.h 2015-09-22 14:54:32 +0000
+++ src/downloads/client/ubuntu/download_manager/download.h 2015-11-26 12:58:55 +0000
@@ -56,6 +56,17 @@
56 explicit Download(QObject* parent = 0)56 explicit Download(QObject* parent = 0)
57 : QObject(parent) {}57 : QObject(parent) {}
5858
59 enum State {
60 IDLE,
61 START,
62 PAUSE,
63 RESUME,
64 CANCEL,
65 UNCOLLECTED,
66 FINISH,
67 ERROR
68 };
69
59 /*!70 /*!
60 \fn void Download::start()71 \fn void Download::start()
6172
@@ -97,6 +108,15 @@
97 virtual void cancel() = 0;108 virtual void cancel() = 0;
98109
99 /*!110 /*!
111 \fn void Download::collected()
112
113 Notifies the download manager that the finished signal for this
114 download object has been received by the client. This allows UDM
115 to report downloads that have finished while a client isn't running.
116 */
117 virtual void collected() = 0;
118
119 /*!
100 \fn void Download::allowMobileDownload(bool allowed)120 \fn void Download::allowMobileDownload(bool allowed)
101121
102 Notifies the download manager that the download represented by this122 Notifies the download manager that the download represented by this
@@ -201,6 +221,21 @@
201 virtual qulonglong totalSize() = 0;221 virtual qulonglong totalSize() = 0;
202222
203 /*!223 /*!
224 \fn QString filePath()
225
226 Returns the value of the downloaded file's location. This is only set once
227 the download is complete.
228 */
229 virtual QString filePath() = 0;
230
231 /*!
232 \fn State state()
233
234 Returns the current state of the download.
235 */
236 virtual State state() = 0;
237
238 /*!
204 \fn bool isError() const239 \fn bool isError() const
205240
206 Returns if the download represented by the object has had an error.241 Returns if the download represented by the object has had an error.
207242
=== modified file 'src/downloads/client/ubuntu/download_manager/download_impl.cpp'
--- src/downloads/client/ubuntu/download_manager/download_impl.cpp 2015-09-22 14:54:32 +0000
+++ src/downloads/client/ubuntu/download_manager/download_impl.cpp 2015-11-26 12:58:55 +0000
@@ -62,6 +62,13 @@
62 "Could not connect to signal &DownloadInterface::finished");62 "Could not connect to signal &DownloadInterface::finished");
63 }63 }
6464
65 connected = connect(_dbusInterface, &DownloadInterface::finished,
66 this, &DownloadImpl::onFinished);
67 if (!connected) {
68 Logger::log(Logger::Critical,
69 "Could not connect to signal &DownloadInterface::finished");
70 }
71
65 connected = connect(_dbusInterface, &DownloadInterface::paused,72 connected = connect(_dbusInterface, &DownloadInterface::paused,
66 this, &Download::paused);73 this, &Download::paused);
67 if (!connected) {74 if (!connected) {
@@ -216,6 +223,19 @@
216}223}
217224
218void225void
226DownloadImpl::collected() {
227 Logger::log(Logger::Debug, QString("Download{%1} collected()").arg(_id));
228 QDBusPendingReply<> reply =
229 _dbusInterface->collected();
230 // block, the call should be fast enough
231 reply.waitForFinished();
232 if (reply.isError()) {
233 Logger::log(Logger::Error, "Error when setting download collected");
234 setLastError(reply.error());
235 }
236}
237
238void
219DownloadImpl::allowMobileDownload(bool allowed) {239DownloadImpl::allowMobileDownload(bool allowed) {
220 Logger::log(Logger::Debug,240 Logger::log(Logger::Debug,
221 QString("Download{%1} allowMobileDownload%2())").arg(_id).arg(allowed));241 QString("Download{%1} allowMobileDownload%2())").arg(_id).arg(allowed));
@@ -304,9 +324,7 @@
304 // block, the call should be fast enough324 // block, the call should be fast enough
305 reply.waitForFinished();325 reply.waitForFinished();
306 if (reply.isError()) {326 if (reply.isError()) {
307 qDebug() << "Error setting metadata";
308 Logger::log(Logger::Error, "Error setting the download metadata");327 Logger::log(Logger::Error, "Error setting the download metadata");
309 qDebug() << reply.error();
310 setLastError(reply.error());328 setLastError(reply.error());
311 }329 }
312}330}
@@ -362,6 +380,40 @@
362}380}
363381
364QString382QString
383DownloadImpl::filePath() {
384 Logger::log(Logger::Debug, QString("Download{%1} filePath()").arg(_id));
385 QDBusPendingReply<QString> reply =
386 _dbusInterface->filePath();
387 // block, the call is fast enough
388 reply.waitForFinished();
389 if (reply.isError()) {
390 Logger::log(Logger::Error, "Error querying the download file path");
391 setLastError(reply.error());
392 return "";
393 } else {
394 auto result = reply.value();
395 return result;
396 }
397}
398
399Download::State
400DownloadImpl::state() {
401 Logger::log(Logger::Debug, QString("Download{%1} state()").arg(_id));
402 QDBusPendingReply<int> reply =
403 _dbusInterface->state();
404 // block, the call is fast enough
405 reply.waitForFinished();
406 if (reply.isError()) {
407 Logger::log(Logger::Error, "Error querying the download state");
408 setLastError(reply.error());
409 return Download::ERROR;
410 } else {
411 auto result = static_cast<Download::State>(reply.value());
412 return result;
413 }
414}
415
416QString
365DownloadImpl::id() const {417DownloadImpl::id() const {
366 return _id;418 return _id;
367}419}
@@ -481,6 +533,13 @@
481 }533 }
482}534}
483535
536void DownloadImpl::onFinished(const QString &path) {
537 Q_UNUSED(path);
538 // Inform UDM that we've received the finished signal, so the download
539 // can be considered completely finished.
540 collected();
541}
542
484} // DownloadManager543} // DownloadManager
485544
486} // Ubuntu545} // Ubuntu
487546
=== modified file 'src/downloads/client/ubuntu/download_manager/download_impl.h'
--- src/downloads/client/ubuntu/download_manager/download_impl.h 2015-09-22 14:14:06 +0000
+++ src/downloads/client/ubuntu/download_manager/download_impl.h 2015-11-26 12:58:55 +0000
@@ -59,6 +59,7 @@
59 void pause();59 void pause();
60 void resume();60 void resume();
61 void cancel();61 void cancel();
62 void collected();
6263
63 void allowMobileDownload(bool allowed);64 void allowMobileDownload(bool allowed);
64 bool isMobileDownloadAllowed();65 bool isMobileDownloadAllowed();
@@ -70,6 +71,8 @@
70 void setMetadata(QVariantMap map);71 void setMetadata(QVariantMap map);
71 void setThrottle(qulonglong speed);72 void setThrottle(qulonglong speed);
72 qulonglong throttle();73 qulonglong throttle();
74 QString filePath();
75 Download::State state();
7376
74 QString id() const;77 QString id() const;
75 qulonglong progress();78 qulonglong progress();
@@ -101,6 +104,7 @@
101 void onPropertiesChanged(const QString& interfaceName,104 void onPropertiesChanged(const QString& interfaceName,
102 const QVariantMap& changedProperties,105 const QVariantMap& changedProperties,
103 const QStringList& invalidatedProperties);106 const QStringList& invalidatedProperties);
107 void onFinished(const QString& path);
104108
105 private:109 private:
106 QString _id;110 QString _id;
107111
=== modified file 'src/downloads/client/ubuntu/download_manager/download_interface.h'
--- src/downloads/client/ubuntu/download_manager/download_interface.h 2015-09-22 14:54:32 +0000
+++ src/downloads/client/ubuntu/download_manager/download_interface.h 2015-11-26 12:58:55 +0000
@@ -66,6 +66,18 @@
66 return asyncCallWithArgumentList(QStringLiteral("cancel"), argumentList);66 return asyncCallWithArgumentList(QStringLiteral("cancel"), argumentList);
67 }67 }
6868
69 inline QDBusPendingReply<> collected()
70 {
71 QList<QVariant> argumentList;
72 return asyncCallWithArgumentList(QStringLiteral("collected"), argumentList);
73 }
74
75 inline QDBusPendingReply<QString> filePath()
76 {
77 QList<QVariant> argumentList;
78 return asyncCallWithArgumentList(QStringLiteral("filePath"), argumentList);
79 }
80
69 inline QDBusPendingReply<StringMap> headers()81 inline QDBusPendingReply<StringMap> headers()
70 {82 {
71 QList<QVariant> argumentList;83 QList<QVariant> argumentList;
@@ -136,6 +148,12 @@
136 return asyncCallWithArgumentList(QStringLiteral("start"), argumentList);148 return asyncCallWithArgumentList(QStringLiteral("start"), argumentList);
137 }149 }
138150
151 inline QDBusPendingReply<int> state()
152 {
153 QList<QVariant> argumentList;
154 return asyncCallWithArgumentList(QStringLiteral("state"), argumentList);
155 }
156
139 inline QDBusPendingReply<qulonglong> throttle()157 inline QDBusPendingReply<qulonglong> throttle()
140 {158 {
141 QList<QVariant> argumentList;159 QList<QVariant> argumentList;
142160
=== modified file 'src/downloads/client/ubuntu/download_manager/manager.h'
--- src/downloads/client/ubuntu/download_manager/manager.h 2014-06-06 10:05:15 +0000
+++ src/downloads/client/ubuntu/download_manager/manager.h 2015-11-26 12:58:55 +0000
@@ -216,6 +216,33 @@
216 MetadataDownloadsListCb errCb) = 0;216 MetadataDownloadsListCb errCb) = 0;
217217
218 /*!218 /*!
219 \fn void getUncollectedDownloads(const QString &appId)
220
221 Returns uncollected downloads in the download manager that can be accessed
222 by the calling client. If the client is not confined then the downloads
223 returned will be those belonging to the app specified via the appId
224 parameter, on the other hand if the client is confined the result will
225 be only those downloads created by the client. The result of the method
226 is returned via the downloadsFound signal.
227 */
228 virtual void getUncollectedDownloads(const QString &appId) = 0;
229
230 /*!
231 \fn void getUncollectedDownloads(const QString &appId)
232
233 Returns uncollected downloads in the download manager that can be accessed
234 by the calling client. If the client is not confined then the downloads
235 returned will be those belonging to the app specified via the appId
236 parameter, on the other hand if the client is confined the result will
237 be only those downloads created by the client. . If the method is a
238 success the \a cb is executed else \a errCb is executed.
239 */
240
241 virtual void getUncollectedDownloads(const QString &appId,
242 DownloadsListCb cb,
243 DownloadsListCb errCb) = 0;
244
245 /*!
219 \fn bool isError() const246 \fn bool isError() const
220 Returns if the manager received an error during the execution247 Returns if the manager received an error during the execution
221 of a command.248 of a command.
222249
=== modified file 'src/downloads/client/ubuntu/download_manager/manager_impl.cpp'
--- src/downloads/client/ubuntu/download_manager/manager_impl.cpp 2015-02-25 16:24:24 +0000
+++ src/downloads/client/ubuntu/download_manager/manager_impl.cpp 2015-11-26 12:58:55 +0000
@@ -193,6 +193,29 @@
193 }193 }
194}194}
195195
196void
197ManagerImpl::getUncollectedDownloads(const QString &appId) {
198 Logger::log(Logger::Debug, "Manager getUncollectedDownloads()");
199 DownloadsListCb cb = [](DownloadsList*){};
200 getUncollectedDownloads(appId, cb, cb);
201}
202
203void
204ManagerImpl::getUncollectedDownloads(const QString &appId,
205 DownloadsListCb cb,
206 DownloadsListCb errCb) {
207 Logger::log(Logger::Debug, "Manager getUncollectedDownloads()");
208 QDBusPendingCall call = _dbusInterface->getUncollectedDownloads(appId);
209 auto watcher = new DownloadsListManagerPCW(
210 _conn, _servicePath, call, cb, errCb, this);
211 auto connected = connect(watcher, &GroupManagerPCW::callbackExecuted,
212 this, &ManagerImpl::onWatcherDone);
213 if (!connected) {
214 Logger::log(Logger::Critical,
215 "Could not connect to signal");
216 }
217}
218
196bool219bool
197ManagerImpl::isError() const {220ManagerImpl::isError() const {
198 return _isError;221 return _isError;
199222
=== modified file 'src/downloads/client/ubuntu/download_manager/manager_impl.h'
--- src/downloads/client/ubuntu/download_manager/manager_impl.h 2014-06-29 12:45:29 +0000
+++ src/downloads/client/ubuntu/download_manager/manager_impl.h 2015-11-26 12:58:55 +0000
@@ -81,6 +81,10 @@
81 const QString &value,81 const QString &value,
82 MetadataDownloadsListCb cb,82 MetadataDownloadsListCb cb,
83 MetadataDownloadsListCb errCb);83 MetadataDownloadsListCb errCb);
84 virtual void getUncollectedDownloads(const QString &appId);
85 virtual void getUncollectedDownloads(const QString &appId,
86 DownloadsListCb cb,
87 DownloadsListCb errCb);
8488
85 bool isError() const;89 bool isError() const;
86 Error* lastError() const;90 Error* lastError() const;
8791
=== modified file 'src/downloads/client/ubuntu/download_manager/manager_interface.h'
--- src/downloads/client/ubuntu/download_manager/manager_interface.h 2014-02-26 19:54:31 +0000
+++ src/downloads/client/ubuntu/download_manager/manager_interface.h 2015-11-26 12:58:55 +0000
@@ -89,6 +89,13 @@
89 return asyncCallWithArgumentList(QLatin1String("getAllDownloadsWithMetadata"), argumentList);89 return asyncCallWithArgumentList(QLatin1String("getAllDownloadsWithMetadata"), argumentList);
90 }90 }
9191
92 inline QDBusPendingReply<QList<QDBusObjectPath> > getUncollectedDownloads(const QString &appId)
93 {
94 QList<QVariant> argumentList;
95 argumentList << QVariant::fromValue(appId);
96 return asyncCallWithArgumentList(QLatin1String("getUncollectedDownloads"), argumentList);
97 }
98
92 inline QDBusPendingReply<bool> isGSMDownloadAllowed()99 inline QDBusPendingReply<bool> isGSMDownloadAllowed()
93 {100 {
94 QList<QVariant> argumentList;101 QList<QVariant> argumentList;
95102
=== modified file 'src/downloads/common/CMakeLists.txt'
--- src/downloads/common/CMakeLists.txt 2014-06-16 12:38:08 +0000
+++ src/downloads/common/CMakeLists.txt 2015-11-26 12:58:55 +0000
@@ -1,12 +1,14 @@
1set(TARGET ubuntu-download-manager-common)1set(TARGET ubuntu-download-manager-common)
22
3set(SOURCES3set(SOURCES
4 ubuntu/download_manager/download_state_struct.cpp
4 ubuntu/download_manager/download_struct.cpp5 ubuntu/download_manager/download_struct.cpp
5 ubuntu/download_manager/group_download_struct.cpp6 ubuntu/download_manager/group_download_struct.cpp
6 ubuntu/download_manager/system/logger.cpp7 ubuntu/download_manager/system/logger.cpp
7)8)
89
9set(PUBLIC_HEADERS10set(PUBLIC_HEADERS
11 ubuntu/download_manager/download_state_struct.h
10 ubuntu/download_manager/download_struct.h12 ubuntu/download_manager/download_struct.h
11 ubuntu/download_manager/group_download_struct.h13 ubuntu/download_manager/group_download_struct.h
12 ubuntu/download_manager/metatypes.h14 ubuntu/download_manager/metatypes.h
1315
=== added file 'src/downloads/common/ubuntu/download_manager/download_state_struct.cpp'
--- src/downloads/common/ubuntu/download_manager/download_state_struct.cpp 1970-01-01 00:00:00 +0000
+++ src/downloads/common/ubuntu/download_manager/download_state_struct.cpp 2015-11-26 12:58:55 +0000
@@ -0,0 +1,119 @@
1/*
2 * Copyright 2013-2014 Canonical Ltd.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of version 3 of the GNU Lesser General Public
6 * License as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17 */
18
19#include <QDBusArgument>
20#include "download_state_struct.h"
21
22namespace Ubuntu {
23
24namespace DownloadManager {
25
26DownloadStateStruct::DownloadStateStruct()
27 : _state(-1),
28 _url(QString::null),
29 _filePath(QString::null),
30 _hash(QString::null) {
31
32}
33
34DownloadStateStruct::DownloadStateStruct(int state, const QString& url, const QString& hash)
35 : _state(state),
36 _url(url),
37 _filePath(QString::null),
38 _hash(hash) {
39
40}
41
42DownloadStateStruct::DownloadStateStruct(int state, const QString& url, const QString& filePath,
43 const QString& hash)
44 : _state(state),
45 _url(url),
46 _filePath(filePath),
47 _hash(hash) {
48
49}
50
51DownloadStateStruct::DownloadStateStruct(const DownloadStateStruct& other)
52 : _state(other._state),
53 _url(other._url),
54 _filePath(other._filePath),
55 _hash(other._hash) {
56}
57
58DownloadStateStruct& DownloadStateStruct::operator=(const DownloadStateStruct& other) {
59 _state = other._state;
60 _url = other._url;
61 _filePath= other._filePath;
62 _hash = other._hash;
63
64 return *this;
65}
66
67QDBusArgument &operator<<(QDBusArgument &argument,
68 const DownloadStateStruct& download) {
69 argument.beginStructure();
70 argument << download._state;
71 argument << download._url;
72 argument << download._filePath;
73 argument << download._hash;
74 argument.endStructure();
75
76 return argument;
77}
78
79const QDBusArgument &operator>>(const QDBusArgument &argument,
80 DownloadStateStruct& download) {
81 argument.beginStructure();
82 argument >> download._state;
83 argument >> download._url;
84 argument >> download._filePath;
85 argument >> download._hash;
86 argument.endStructure();
87
88 return argument;
89}
90
91int
92DownloadStateStruct::getState() const {
93 return _state;
94}
95
96QString
97DownloadStateStruct::getUrl() const {
98 return _url;
99}
100
101QString
102DownloadStateStruct::getFilePath() const {
103 return _filePath;
104}
105
106QString
107DownloadStateStruct::getHash() const {
108 return _hash;
109}
110
111bool
112DownloadStateStruct::isValid() {
113 return _url != QString::null;
114}
115
116} // DownloadManager
117
118} // Ubuntu
119
0120
=== added file 'src/downloads/common/ubuntu/download_manager/download_state_struct.h'
--- src/downloads/common/ubuntu/download_manager/download_state_struct.h 1970-01-01 00:00:00 +0000
+++ src/downloads/common/ubuntu/download_manager/download_state_struct.h 2015-11-26 12:58:55 +0000
@@ -0,0 +1,149 @@
1/*
2 * Copyright 2015 Canonical Ltd.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of version 3 of the GNU Lesser General Public
6 * License as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17 */
18
19#pragma once
20
21#include <QString>
22
23class QDBusArgument;
24namespace Ubuntu {
25
26namespace DownloadManager {
27
28namespace Daemon {
29class DownloadsDb;
30}
31
32/*!
33 \class DownloadStateStruct
34 \brief The DownloadStateStruct represents the dbus structure that is used
35 to communicate the download manager the details of a past or
36 current download.
37 \since 1.1
38
39 The DownloadStateStruct allows to get the basic information of a download that
40 was created by an application in the download manager.
41*/
42class DownloadStateStruct {
43 Q_PROPERTY(int state READ getState)
44 Q_PROPERTY(QString url READ getUrl)
45 Q_PROPERTY(QString filePath READ getFilePath)
46 Q_PROPERTY(QString hash READ getHash)
47
48 friend class Ubuntu::DownloadManager::Daemon::DownloadsDb;
49
50 public:
51
52 /*
53 Default constructor.
54 */
55 DownloadStateStruct();
56
57 /*
58 Copy constructor.
59 */
60 DownloadStateStruct(const DownloadStateStruct& other);
61
62 /*
63 Assign operator.
64 */
65 DownloadStateStruct& operator=(const DownloadStateStruct& other);
66
67 /*
68 \internal
69 */
70 friend QDBusArgument &operator<<(QDBusArgument &argument, const DownloadStateStruct& download);
71
72 /*
73 \internal
74 */
75 friend const QDBusArgument &operator>>(const QDBusArgument &argument, DownloadStateStruct& download);
76
77 /*
78 \fn QString getUrl()
79
80 Returns the url that points to the file that will be downloaded.
81 */
82 int getState() const;
83
84 /*
85 \fn QString getUrl()
86
87 Returns the url that points to the file that will be downloaded.
88 */
89 QString getUrl() const;
90
91 /*
92 \fn QString getUrl()
93
94 Returns the url that points to the file that will be downloaded.
95 */
96 QString getFilePath() const;
97
98 /*
99 \fn QString getUrl()
100
101 Returns the url that points to the file that will be downloaded.
102 */
103 QString getHash() const;
104
105 /*
106 \fn bool isValid();
107
108 Returns if the download state if valid.
109 */
110 bool isValid();
111
112 protected:
113
114 /*
115 \internal
116 */
117 DownloadStateStruct(int state, const QString& url, const QString& hash=QString::null);
118
119 /*
120 \internal
121 */
122 DownloadStateStruct(int state, const QString& url, const QString& filePath, const QString& hash=QString::null);
123
124 private:
125
126 /*
127 \internal
128 */
129 int _state = -1;
130
131 /*
132 \internal
133 */
134 QString _url = QString::null;
135
136 /*
137 \internal
138 */
139 QString _filePath = QString::null;
140
141 /*
142 \internal
143 */
144 QString _hash = QString::null;
145};
146
147}
148
149}
0\ No newline at end of file150\ No newline at end of file
1151
=== modified file 'src/downloads/common/ubuntu/download_manager/metatypes.h'
--- src/downloads/common/ubuntu/download_manager/metatypes.h 2015-02-25 16:24:24 +0000
+++ src/downloads/common/ubuntu/download_manager/metatypes.h 2015-11-26 12:58:55 +0000
@@ -25,6 +25,7 @@
25#include <ubuntu/transfers/errors/http_error_struct.h>25#include <ubuntu/transfers/errors/http_error_struct.h>
26#include <ubuntu/transfers/errors/network_error_struct.h>26#include <ubuntu/transfers/errors/network_error_struct.h>
27#include <ubuntu/transfers/errors/process_error_struct.h>27#include <ubuntu/transfers/errors/process_error_struct.h>
28#include "download_state_struct.h"
28#include "download_struct.h"29#include "download_struct.h"
29#include "group_download_struct.h"30#include "group_download_struct.h"
3031
@@ -40,6 +41,7 @@
40Q_DECLARE_METATYPE(NetworkErrorStruct)41Q_DECLARE_METATYPE(NetworkErrorStruct)
41Q_DECLARE_METATYPE(ProcessErrorStruct)42Q_DECLARE_METATYPE(ProcessErrorStruct)
42Q_DECLARE_METATYPE(DownloadStruct)43Q_DECLARE_METATYPE(DownloadStruct)
44Q_DECLARE_METATYPE(DownloadStateStruct)
43Q_DECLARE_METATYPE(StringMap)45Q_DECLARE_METATYPE(StringMap)
44Q_DECLARE_METATYPE(StructList)46Q_DECLARE_METATYPE(StructList)
4547
4648
=== modified file 'src/downloads/priv/CMakeLists.txt'
--- src/downloads/priv/CMakeLists.txt 2014-11-17 23:07:13 +0000
+++ src/downloads/priv/CMakeLists.txt 2015-11-26 12:58:55 +0000
@@ -12,7 +12,7 @@
12 ubuntu/downloads/file_download.cpp12 ubuntu/downloads/file_download.cpp
13 ubuntu/downloads/group_download.cpp13 ubuntu/downloads/group_download.cpp
14 ubuntu/downloads/group_download_adaptor.cpp14 ubuntu/downloads/group_download_adaptor.cpp
15 ubuntu/downloads/header_parser.cpp15 ubuntu/downloads/header_parser.cpp
16 ubuntu/downloads/manager.cpp16 ubuntu/downloads/manager.cpp
17 ubuntu/downloads/mms_file_download.cpp17 ubuntu/downloads/mms_file_download.cpp
18 ubuntu/downloads/sm_file_download.cpp18 ubuntu/downloads/sm_file_download.cpp
@@ -33,7 +33,7 @@
33 ubuntu/downloads/file_download.h33 ubuntu/downloads/file_download.h
34 ubuntu/downloads/group_download.h34 ubuntu/downloads/group_download.h
35 ubuntu/downloads/group_download_adaptor.h35 ubuntu/downloads/group_download_adaptor.h
36 ubuntu/downloads/header_parser.h36 ubuntu/downloads/header_parser.h
37 ubuntu/downloads/manager.h37 ubuntu/downloads/manager.h
38 ubuntu/downloads/mms_file_download.h38 ubuntu/downloads/mms_file_download.h
39 ubuntu/downloads/sm_file_download.h39 ubuntu/downloads/sm_file_download.h
4040
=== modified file 'src/downloads/priv/ubuntu/downloads/download.h'
--- src/downloads/priv/ubuntu/downloads/download.h 2015-09-22 14:54:32 +0000
+++ src/downloads/priv/ubuntu/downloads/download.h 2015-11-26 12:58:55 +0000
@@ -105,6 +105,7 @@
105 // slots to be implemented by the children105 // slots to be implemented by the children
106 virtual qulonglong progress() = 0;106 virtual qulonglong progress() = 0;
107 virtual qulonglong totalSize() = 0;107 virtual qulonglong totalSize() = 0;
108 virtual QString filePath() = 0;
108109
109 signals:110 signals:
110 // signals that are exposed via dbus111 // signals that are exposed via dbus
111112
=== modified file 'src/downloads/priv/ubuntu/downloads/download_adaptor.cpp'
--- src/downloads/priv/ubuntu/downloads/download_adaptor.cpp 2015-09-22 14:54:32 +0000
+++ src/downloads/priv/ubuntu/downloads/download_adaptor.cpp 2015-11-26 12:58:55 +0000
@@ -69,6 +69,20 @@
69 QMetaObject::invokeMethod(parent(), "cancel");69 QMetaObject::invokeMethod(parent(), "cancel");
70}70}
7171
72void DownloadAdaptor::collected()
73{
74 // handle method call com.canonical.applications.Download.collected
75 QMetaObject::invokeMethod(parent(), "collected");
76}
77
78QString DownloadAdaptor::filePath()
79{
80 // handle method call com.canonical.applications.Download.filePath
81 QString filePath;
82 QMetaObject::invokeMethod(parent(), "filePath", Q_RETURN_ARG(QString, filePath));
83 return filePath;
84}
85
72StringMap DownloadAdaptor::headers()86StringMap DownloadAdaptor::headers()
73{87{
74 // handle method call com.canonical.applications.Download.headers88 // handle method call com.canonical.applications.Download.headers
@@ -143,6 +157,14 @@
143 QMetaObject::invokeMethod(parent(), "start");157 QMetaObject::invokeMethod(parent(), "start");
144}158}
145159
160int DownloadAdaptor::state()
161{
162 // handle method call com.canonical.applications.Download.state
163 int state;
164 QMetaObject::invokeMethod(parent(), "state", Q_RETURN_ARG(int, state));
165 return state;
166}
167
146qulonglong DownloadAdaptor::throttle()168qulonglong DownloadAdaptor::throttle()
147{169{
148 // handle method call com.canonical.applications.Download.throttle170 // handle method call com.canonical.applications.Download.throttle
149171
=== modified file 'src/downloads/priv/ubuntu/downloads/download_adaptor.h'
--- src/downloads/priv/ubuntu/downloads/download_adaptor.h 2015-09-22 14:54:32 +0000
+++ src/downloads/priv/ubuntu/downloads/download_adaptor.h 2015-11-26 12:58:55 +0000
@@ -9,8 +9,8 @@
9 * before re-generating it.9 * before re-generating it.
10 */10 */
1111
12#ifndef DOWNLOAD_ADAPTOR_H_144051348812#ifndef DOWNLOAD_ADAPTOR_H_1446124951
13#define DOWNLOAD_ADAPTOR_H_144051348813#define DOWNLOAD_ADAPTOR_H_1446124951
1414
15#include <QtCore/QObject>15#include <QtCore/QObject>
16#include <QtDBus/QtDBus>16#include <QtDBus/QtDBus>
@@ -71,10 +71,17 @@
71" <method name=\"isGSMDownloadAllowed\">\n"71" <method name=\"isGSMDownloadAllowed\">\n"
72" <arg direction=\"out\" type=\"b\" name=\"allowed\"/>\n"72" <arg direction=\"out\" type=\"b\" name=\"allowed\"/>\n"
73" </method>\n"73" </method>\n"
74" <method name=\"filePath\">\n"
75" <arg direction=\"out\" type=\"s\" name=\"filepath\"/>\n"
76" </method>\n"
77" <method name=\"state\">\n"
78" <arg direction=\"out\" type=\"i\" name=\"state\"/>\n"
79" </method\n"
74" <method name=\"start\"/>\n"80" <method name=\"start\"/>\n"
75" <method name=\"pause\"/>\n"81" <method name=\"pause\"/>\n"
76" <method name=\"resume\"/>\n"82" <method name=\"resume\"/>\n"
77" <method name=\"cancel\"/>\n"83" <method name=\"cancel\"/>\n"
84" <method name=\"collected\"/>\n"
78" <signal name=\"started\">\n"85" <signal name=\"started\">\n"
79" <arg direction=\"out\" type=\"b\" name=\"success\"/>\n"86" <arg direction=\"out\" type=\"b\" name=\"success\"/>\n"
80" </signal>\n"87" </signal>\n"
@@ -146,6 +153,8 @@
146public Q_SLOTS: // METHODS153public Q_SLOTS: // METHODS
147 void allowGSMDownload(bool allowed);154 void allowGSMDownload(bool allowed);
148 void cancel();155 void cancel();
156 void collected();
157 QString filePath();
149 StringMap headers();158 StringMap headers();
150 bool isGSMDownloadAllowed();159 bool isGSMDownloadAllowed();
151 QVariantMap metadata();160 QVariantMap metadata();
@@ -157,6 +166,7 @@
157 void setMetadata(const QVariantMap &data);166 void setMetadata(const QVariantMap &data);
158 void setThrottle(qulonglong speed);167 void setThrottle(qulonglong speed);
159 void start();168 void start();
169 int state();
160 qulonglong throttle();170 qulonglong throttle();
161 qulonglong totalSize();171 qulonglong totalSize();
162Q_SIGNALS: // SIGNALS172Q_SIGNALS: // SIGNALS
163173
=== modified file 'src/downloads/priv/ubuntu/downloads/download_manager_adaptor.cpp'
--- src/downloads/priv/ubuntu/downloads/download_manager_adaptor.cpp 2014-03-18 12:07:06 +0000
+++ src/downloads/priv/ubuntu/downloads/download_manager_adaptor.cpp 2015-11-26 12:58:55 +0000
@@ -2,7 +2,7 @@
2 * This file was generated by qdbusxml2cpp version 0.82 * This file was generated by qdbusxml2cpp version 0.8
3 * Command line was: qdbusxml2cpp -c DownloadManagerAdaptor -a download_manager_adaptor.h:download_manager_adaptor.cpp -i metatypes.h com.canonical.applications.download_manager.xml3 * Command line was: qdbusxml2cpp -c DownloadManagerAdaptor -a download_manager_adaptor.h:download_manager_adaptor.cpp -i metatypes.h com.canonical.applications.download_manager.xml
4 *4 *
5 * qdbusxml2cpp is Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).5 * qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
6 *6 *
7 * This is an auto-generated file.7 * This is an auto-generated file.
8 * Do not edit! All changes made to it will be lost.8 * Do not edit! All changes made to it will be lost.
@@ -99,6 +99,22 @@
99 return downloads;99 return downloads;
100}100}
101101
102QList<QDBusObjectPath> DownloadManagerAdaptor::getUncollectedDownloads(const QString &appId)
103{
104 // handle method call com.canonical.applications.DownloadManager.getUncollectedDownloads
105 QList<QDBusObjectPath> downloads;
106 QMetaObject::invokeMethod(parent(), "getUncollectedDownloads", Q_RETURN_ARG(QList<QDBusObjectPath>, downloads), Q_ARG(QString, appId));
107 return downloads;
108}
109
110DownloadStateStruct DownloadManagerAdaptor::getDownloadState(const QString &downloadId)
111{
112 // handle method call com.canonical.applications.DownloadManager.getDownloadState
113 DownloadStateStruct state;
114 QMetaObject::invokeMethod(parent(), "getDownloadState", Q_RETURN_ARG(DownloadStateStruct, state), Q_ARG(QString, downloadId));
115 return state;
116}
117
102bool DownloadManagerAdaptor::isGSMDownloadAllowed()118bool DownloadManagerAdaptor::isGSMDownloadAllowed()
103{119{
104 // handle method call com.canonical.applications.DownloadManager.isGSMDownloadAllowed120 // handle method call com.canonical.applications.DownloadManager.isGSMDownloadAllowed
105121
=== modified file 'src/downloads/priv/ubuntu/downloads/download_manager_adaptor.h'
--- src/downloads/priv/ubuntu/downloads/download_manager_adaptor.h 2014-03-18 12:07:06 +0000
+++ src/downloads/priv/ubuntu/downloads/download_manager_adaptor.h 2015-11-26 12:58:55 +0000
@@ -2,7 +2,7 @@
2 * This file was generated by qdbusxml2cpp version 0.82 * This file was generated by qdbusxml2cpp version 0.8
3 * Command line was: qdbusxml2cpp -c DownloadManagerAdaptor -a download_manager_adaptor.h:download_manager_adaptor.cpp -i metatypes.h com.canonical.applications.download_manager.xml3 * Command line was: qdbusxml2cpp -c DownloadManagerAdaptor -a download_manager_adaptor.h:download_manager_adaptor.cpp -i metatypes.h com.canonical.applications.download_manager.xml
4 *4 *
5 * qdbusxml2cpp is Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).5 * qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
6 *6 *
7 * This is an auto-generated file.7 * This is an auto-generated file.
8 * This file may have been hand-edited. Look for HAND-EDIT comments8 * This file may have been hand-edited. Look for HAND-EDIT comments
@@ -70,6 +70,15 @@
70" <arg direction=\"in\" type=\"s\" name=\"value\"/>\n"70" <arg direction=\"in\" type=\"s\" name=\"value\"/>\n"
71" <arg direction=\"out\" type=\"ao\" name=\"downloads\"/>\n"71" <arg direction=\"out\" type=\"ao\" name=\"downloads\"/>\n"
72" </method>\n"72" </method>\n"
73" <method name=\"getUncollectedDownloads\">\n"
74" <arg direction=\"in\" type=\"s\" name=\"appId\"/>\n"
75" <arg direction=\"out\" type=\"ao\" name=\"downloads\"/>\n"
76" </method>\n"
77" <method name=\"getDownloadState\">\n"
78" <annotation value=\"DownloadStateStruct\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
79" <arg direction=\"in\" type=\"s\" name=\"downloadId\"/>\n"
80" <arg direction=\"out\" type=\"(issss)\" name=\"state\"/>\n"
81" </method>\n"
73" <method name=\"setDefaultThrottle\">\n"82" <method name=\"setDefaultThrottle\">\n"
74" <arg direction=\"in\" type=\"t\" name=\"speed\"/>\n"83" <arg direction=\"in\" type=\"t\" name=\"speed\"/>\n"
75" </method>\n"84" </method>\n"
@@ -102,6 +111,8 @@
102 void exit();111 void exit();
103 QList<QDBusObjectPath> getAllDownloads();112 QList<QDBusObjectPath> getAllDownloads();
104 QList<QDBusObjectPath> getAllDownloadsWithMetadata(const QString &name, const QString &value);113 QList<QDBusObjectPath> getAllDownloadsWithMetadata(const QString &name, const QString &value);
114 DownloadStateStruct getDownloadState(const QString &downloadId);
115 QList<QDBusObjectPath> getUncollectedDownloads(const QString &appId);
105 bool isGSMDownloadAllowed();116 bool isGSMDownloadAllowed();
106 void setDefaultThrottle(qulonglong speed);117 void setDefaultThrottle(qulonglong speed);
107Q_SIGNALS: // SIGNALS118Q_SIGNALS: // SIGNALS
108119
=== modified file 'src/downloads/priv/ubuntu/downloads/downloads_db.cpp'
--- src/downloads/priv/ubuntu/downloads/downloads_db.cpp 2014-04-15 15:15:28 +0000
+++ src/downloads/priv/ubuntu/downloads/downloads_db.cpp 2015-11-26 12:58:55 +0000
@@ -29,6 +29,7 @@
29#include <unistd.h>29#include <unistd.h>
30#include "ubuntu/transfers/system/logger.h"30#include "ubuntu/transfers/system/logger.h"
31#include "downloads_db.h"31#include "downloads_db.h"
32#include "download_adaptor.h"
3233
33namespace {34namespace {
34 const QString SINGLE_DOWNLOAD_TABLE = "CREATE TABLE IF NOT EXISTS SingleDownload("\35 const QString SINGLE_DOWNLOAD_TABLE = "CREATE TABLE IF NOT EXISTS SingleDownload("\
@@ -75,14 +76,26 @@
75 "throttle=:throttle, metadata=:metadata, headers=:headers "\76 "throttle=:throttle, metadata=:metadata, headers=:headers "\
76 "WHERE uuid=:uuid";77 "WHERE uuid=:uuid";
7778
79 const QString GET_SINGLE_DOWNLOAD_STATE = "SELECT state, url, local_path, hash FROM SingleDownload "\
80 "WHERE uuid=:uuid";
81
82 const QString GET_UNCOLLECTED_DOWNLOADS = "SELECT uuid, appId, url, dbus_path, "\
83 "local_path, hash, hash_algo, state FROM SingleDownload "\
84 "WHERE appId=:appId AND state='uncoll'";
85
86 const QString UPDATE_UNCOLLECTED_DOWNLOADS = "UPDATE SingleDownload SET state='finish' "\
87 "WHERE state='uncoll' AND appId=:appId";
88
78 const QString IDLE_STRING = "idle";89 const QString IDLE_STRING = "idle";
79 const QString START_STRING = "start";90 const QString START_STRING = "start";
80 const QString PAUSE_STRING = "pause";91 const QString PAUSE_STRING = "pause";
81 const QString RESUME_STRING = "resume";92 const QString RESUME_STRING = "resume";
82 const QString CANCEL_STRING = "cancel";93 const QString CANCEL_STRING = "cancel";
94 const QString UNCOLLECTED_STRING = "uncoll";
83 const QString FINISH_STRING = "finish";95 const QString FINISH_STRING = "finish";
84 const QString ERROR_STRING = "error";96 const QString ERROR_STRING = "error";
8597
98 const QString DOWNLOAD_INTERFACE = "com.canonical.applications.Download";
86}99}
87100
88namespace Ubuntu {101namespace Ubuntu {
@@ -178,6 +191,8 @@
178 return RESUME_STRING;191 return RESUME_STRING;
179 case Download::CANCEL:192 case Download::CANCEL:
180 return CANCEL_STRING;193 return CANCEL_STRING;
194 case Download::UNCOLLECTED:
195 return UNCOLLECTED_STRING;
181 case Download::FINISH:196 case Download::FINISH:
182 return FINISH_STRING;197 return FINISH_STRING;
183 case Download::ERROR:198 case Download::ERROR:
@@ -200,6 +215,8 @@
200 return Download::RESUME;215 return Download::RESUME;
201 if (lowerState == CANCEL_STRING)216 if (lowerState == CANCEL_STRING)
202 return Download::CANCEL;217 return Download::CANCEL;
218 if (lowerState == UNCOLLECTED_STRING)
219 return Download::UNCOLLECTED;
203 if (lowerState == FINISH_STRING)220 if (lowerState == FINISH_STRING)
204 return Download::FINISH;221 return Download::FINISH;
205 if (lowerState == ERROR_STRING)222 if (lowerState == ERROR_STRING)
@@ -235,6 +252,94 @@
235 return false;252 return false;
236}253}
237254
255DownloadStateStruct
256DownloadsDb::getDownloadState(const QString &downloadId) {
257 bool opened = _db.open();
258
259 if (!opened) {
260 LOG(ERROR) << _db.lastError().text();
261 return DownloadStateStruct();
262 }
263
264 QSqlQuery query;
265 // QString GET_SINGLE_DOWNLOAD_STATE = "SELECT state, url, local_path, hash FROM SingleDownload "
266 // "WHERE uuid=:uuid";
267 query.prepare(GET_SINGLE_DOWNLOAD_STATE);
268 query.bindValue(":uuid", downloadId);
269
270 bool success = query.exec();
271 if (success && query.next()) {
272 // grab the data and create the state structure
273 auto state = stringToState(query.value(0).toString());
274 auto url = query.value(1).toString();
275 auto localPath = query.value(2).toString();
276 auto hash = query.value(3).isValid()?query.value(3).toString():"";
277
278 DownloadStateStruct result(state, url, localPath, hash);
279 _db.close();
280
281 return result;
282 }
283 if (!success) {
284 LOG(ERROR) << query.lastError().text();
285 }
286 return DownloadStateStruct();
287}
288
289QList<Download*>
290DownloadsDb::getUncollectedDownloads(const QString &appId) {
291 bool opened = _db.open();
292 QList<Download*> downloadList;
293
294 if (!opened) {
295 LOG(ERROR) << _db.lastError().text();
296 return downloadList;
297 }
298
299 QSqlQuery query;
300 query.prepare(GET_UNCOLLECTED_DOWNLOADS);
301 query.bindValue(":appId", appId);
302
303 bool success = query.exec();
304 if (!success) {
305 LOG(ERROR) << query.lastError().text();
306 _db.close();
307 return downloadList;
308 }
309 while (query.next()) {
310 auto uuid = query.value(0).toString();
311 auto appId = query.value(1).toString();
312 auto url = query.value(2).toString();
313 auto dbusPath = query.value(3).toString();
314 auto filePath = query.value(4).toString();
315 auto basePath = QFileInfo(filePath).absolutePath();
316 auto hash = query.value(5).isValid() ? query.value(5).toString() : "";
317 auto algo = query.value(6).isValid() ? query.value(6).toString() : "";
318 auto state = stringToState(query.value(7).toString());
319 QVariantMap metadata;
320 QMap<QString, QString> headers;
321 FileDownload *download = new FileDownload(uuid, appId, dbusPath, 1, basePath, url, hash, algo, metadata, headers);
322 download->setState(state);
323 download->setFilePath(filePath);
324 auto downAdaptor = new DownloadAdaptor(download);
325 download->setAdaptor(DOWNLOAD_INTERFACE, downAdaptor);
326
327 downloadList << download;
328
329 }
330
331 QSqlQuery updateQuery;
332 updateQuery.prepare(UPDATE_UNCOLLECTED_DOWNLOADS);
333 updateQuery.bindValue(":appId", appId);
334 success = updateQuery.exec();
335 if (!success) {
336 LOG(ERROR) << updateQuery.lastError().text();
337 }
338
339 _db.close();
340 return downloadList;
341}
342
238bool343bool
239DownloadsDb::storeSingleDownload(FileDownload* download) {344DownloadsDb::storeSingleDownload(FileDownload* download) {
240 // decide if we store it as a new download or update an existing one345 // decide if we store it as a new download or update an existing one
241346
=== modified file 'src/downloads/priv/ubuntu/downloads/downloads_db.h'
--- src/downloads/priv/ubuntu/downloads/downloads_db.h 2014-02-26 16:23:46 +0000
+++ src/downloads/priv/ubuntu/downloads/downloads_db.h 2015-11-26 12:58:55 +0000
@@ -16,12 +16,14 @@
16 * Boston, MA 02110-1301, USA.16 * Boston, MA 02110-1301, USA.
17 */17 */
1818
19#ifndef DOWNLOADER_LIB_DOWNLOADS_DATABASE_H19#pragma once
20#define DOWNLOADER_LIB_DOWNLOADS_DATABASE_H
2120
22#include <QSqlDatabase>21#include <QSqlDatabase>
23#include <QObject>22#include <QObject>
24#include "ubuntu/transfers/system/file_manager.h"23
24#include <ubuntu/transfers/system/file_manager.h>
25#include <ubuntu/download_manager/download_state_struct.h>
26
25#include "file_download.h"27#include "file_download.h"
2628
27namespace Ubuntu {29namespace Ubuntu {
@@ -45,7 +47,11 @@
45 QString filename();47 QString filename();
46 bool dbExists(); // return if the db is present and valid48 bool dbExists(); // return if the db is present and valid
47 bool init(); // init or update the db49 bool init(); // init or update the db
50
48 virtual bool store(Download* down);51 virtual bool store(Download* down);
52 virtual DownloadStateStruct getDownloadState(const QString &downloadId);
53 virtual QList<Download*> getUncollectedDownloads(const QString &appId);
54
49 bool storeSingleDownload(FileDownload* download);55 bool storeSingleDownload(FileDownload* download);
50 void connectToDownload(Download* download);56 void connectToDownload(Download* download);
51 void disconnectFromDownload(Download* download);57 void disconnectFromDownload(Download* download);
@@ -78,5 +84,3 @@
78} // DownloadManager84} // DownloadManager
7985
80} // Ubuntu86} // Ubuntu
81
82#endif // DOWNLOADER_LIB_DOWNLOADS_DATABASE_H
8387
=== modified file 'src/downloads/priv/ubuntu/downloads/factory.cpp'
--- src/downloads/priv/ubuntu/downloads/factory.cpp 2014-10-22 23:32:28 +0000
+++ src/downloads/priv/ubuntu/downloads/factory.cpp 2015-11-26 12:58:55 +0000
@@ -80,7 +80,13 @@
80 QScopedPointer<SecurityDetails> details(80 QScopedPointer<SecurityDetails> details(
81 getSecurityDetails(dbusOwner, metadata));81 getSecurityDetails(dbusOwner, metadata));
82 auto dbusPath = details->dbusPath.arg("download");82 auto dbusPath = details->dbusPath.arg("download");
83 auto down = new FileDownload(details->id, details->appId,83 QString appId = details->appId;
84 if (!details->isConfined && metadata.contains(Metadata::APP_ID)) {
85 // If we're unconfined use the metadata app id to
86 // distinguish between different unconfined apps
87 appId = metadata[Metadata::APP_ID].toString();
88 }
89 auto down = new FileDownload(details->id, appId,
84 dbusPath, details->isConfined, details->localPath, url, metadata, headers);90 dbusPath, details->isConfined, details->localPath, url, metadata, headers);
85 auto downAdaptor = new DownloadAdaptor(down);91 auto downAdaptor = new DownloadAdaptor(down);
86 down->setAdaptor(DOWNLOAD_INTERFACE, downAdaptor);92 down->setAdaptor(DOWNLOAD_INTERFACE, downAdaptor);
8793
=== modified file 'src/downloads/priv/ubuntu/downloads/file_download.cpp'
--- src/downloads/priv/ubuntu/downloads/file_download.cpp 2015-02-25 16:24:24 +0000
+++ src/downloads/priv/ubuntu/downloads/file_download.cpp 2015-11-26 12:58:55 +0000
@@ -1095,7 +1095,7 @@
1095 }1095 }
1096 }1096 }
10971097
1098 setState(Download::FINISH);1098 setState(Download::UNCOLLECTED);
1099 unlockFilePath();1099 unlockFilePath();
11001100
1101 DOWN_LOG(INFO) << "EMIT finished" << filePath();1101 DOWN_LOG(INFO) << "EMIT finished" << filePath();
@@ -1211,6 +1211,18 @@
1211 Download::emitError(error);1211 Download::emitError(error);
1212}1212}
12131213
1214void
1215FileDownload::setFilePath(const QString& filePath) {
1216 // Used to recreate downloads from the database with the correct path
1217 _fileNameMutex->unlockFileName(_filePath);
1218 _filePath = filePath;
1219}
1220
1221QString
1222FileDownload::filePath() {
1223 return _filePath;
1224}
1225
1214} // Daemon1226} // Daemon
12151227
1216} // DownloadManager1228} // DownloadManager
12171229
=== modified file 'src/downloads/priv/ubuntu/downloads/file_download.h'
--- src/downloads/priv/ubuntu/downloads/file_download.h 2015-02-25 16:24:24 +0000
+++ src/downloads/priv/ubuntu/downloads/file_download.h 2015-11-26 12:58:55 +0000
@@ -71,10 +71,6 @@
71 return _url;71 return _url;
72 }72 }
7373
74 virtual QString filePath() const {
75 return _filePath;
76 }
77
78 virtual QString hash() const {74 virtual QString hash() const {
79 return _hash;75 return _hash;
80 }76 }
@@ -89,6 +85,8 @@
89 virtual void resumeTransfer() override;85 virtual void resumeTransfer() override;
90 virtual void startTransfer() override;86 virtual void startTransfer() override;
9187
88 void setFilePath(const QString& path);
89
92 public slots: // NOLINT(whitespace/indent)90 public slots: // NOLINT(whitespace/indent)
93 qulonglong progress() override;91 qulonglong progress() override;
94 qulonglong totalSize() override;92 qulonglong totalSize() override;
@@ -96,6 +94,7 @@
96 virtual void setDestinationDir(const QString& path);94 virtual void setDestinationDir(const QString& path);
97 virtual void setHeaders(StringMap headers) override;95 virtual void setHeaders(StringMap headers) override;
98 virtual void setMetadata(const QVariantMap& metadata) override;96 virtual void setMetadata(const QVariantMap& metadata) override;
97 virtual QString filePath() override;
9998
100 signals:99 signals:
101 void finished(const QString& path);100 void finished(const QString& path);
102101
=== modified file 'src/downloads/priv/ubuntu/downloads/group_download.cpp'
--- src/downloads/priv/ubuntu/downloads/group_download.cpp 2014-05-21 15:17:52 +0000
+++ src/downloads/priv/ubuntu/downloads/group_download.cpp 2015-11-26 12:58:55 +0000
@@ -275,6 +275,13 @@
275 return total;275 return total;
276}276}
277277
278QString
279GroupDownload::filePath() {
280 // A group download never has a file path of its own, each individual
281 // download within the group has its own path
282 return "";
283}
284
278void285void
279GroupDownload::onError(const QString& error) {286GroupDownload::onError(const QString& error) {
280 TRACE;287 TRACE;
281288
=== modified file 'src/downloads/priv/ubuntu/downloads/group_download.h'
--- src/downloads/priv/ubuntu/downloads/group_download.h 2014-10-22 23:40:53 +0000
+++ src/downloads/priv/ubuntu/downloads/group_download.h 2015-11-26 12:58:55 +0000
@@ -63,6 +63,7 @@
63 virtual qulonglong progress(qulonglong &started, qulonglong &paused,63 virtual qulonglong progress(qulonglong &started, qulonglong &paused,
64 qulonglong &finished);64 qulonglong &finished);
65 virtual qulonglong totalSize() override;65 virtual qulonglong totalSize() override;
66 virtual QString filePath() override;
6667
67 signals:68 signals:
68 void finished(const QStringList &path);69 void finished(const QStringList &path);
6970
=== modified file 'src/downloads/priv/ubuntu/downloads/manager.cpp'
--- src/downloads/priv/ubuntu/downloads/manager.cpp 2015-09-22 14:14:06 +0000
+++ src/downloads/priv/ubuntu/downloads/manager.cpp 2015-11-26 12:58:55 +0000
@@ -334,6 +334,45 @@
334 return paths;334 return paths;
335}335}
336336
337QList<QDBusObjectPath>
338DownloadManager::getUncollectedDownloads(const QString &appId) {
339 QScopedPointer<System::AppArmor> appArmor(new System::AppArmor(_conn));
340 auto owner = getCaller();
341 auto callerAppId = appArmor->appId(owner);
342 QList<QDBusObjectPath> paths;
343 QString testAppId = appId;
344 if (appArmor->isConfined(callerAppId)) {
345 // Confined apps always get their own downloads returned
346 testAppId = callerAppId;
347 }
348
349 LOG(INFO) << "Returning uncollected downloads for app with id" << testAppId;
350
351 // Fetch uncollected downloads that are still in memory
352 auto transfers = _queue->transfers();
353 foreach(const QString& path, transfers.keys()) {
354 auto t = transfers[path];
355 if (t->transferAppId() == testAppId && t->state() != Transfer::FINISH
356 && t->state() != Transfer::CANCEL
357 && t->state() != Transfer::ERROR)
358 paths << QDBusObjectPath(path);
359 }
360
361 // Fetch uncollected downloads from previous UDM sessions that are
362 // in the database
363 foreach(Download *download, _db->getUncollectedDownloads(testAppId)) {
364 _conn->registerObject(download->path(), download);
365 paths << QDBusObjectPath(download->path());
366 }
367
368 return paths;
369}
370
371DownloadStateStruct
372DownloadManager::getDownloadState(const QString &downloadId) {
373 return _db->getDownloadState(downloadId);
374}
375
337} // Daemon376} // Daemon
338377
339} // DownloadManager378} // DownloadManager
340379
=== modified file 'src/downloads/priv/ubuntu/downloads/manager.h'
--- src/downloads/priv/ubuntu/downloads/manager.h 2015-08-27 09:02:19 +0000
+++ src/downloads/priv/ubuntu/downloads/manager.h 2015-11-26 12:58:55 +0000
@@ -18,14 +18,17 @@
1818
19#pragma once19#pragma once
2020
21#include <functional>
22
23#include <QByteArray>
24#include <QDBusObjectPath>
21#include <QObject>25#include <QObject>
22#include <QByteArray>
23#include <QtDBus/QDBusObjectPath>
24#include <QSslCertificate>26#include <QSslCertificate>
27
25#include <ubuntu/transfers/queue.h>28#include <ubuntu/transfers/queue.h>
26#include <ubuntu/transfers/system/dbus_connection.h>29#include <ubuntu/transfers/system/dbus_connection.h>
27#include <ubuntu/download_manager/metatypes.h>30#include <ubuntu/download_manager/metatypes.h>
28#include <functional>31
29#include "ubuntu/transfers/base_manager.h"32#include "ubuntu/transfers/base_manager.h"
30#include "ubuntu/transfers/system/application.h"33#include "ubuntu/transfers/system/application.h"
31#include "download.h"34#include "download.h"
@@ -83,6 +86,9 @@
83 virtual QList<QDBusObjectPath> getAllDownloadsWithMetadata(86 virtual QList<QDBusObjectPath> getAllDownloadsWithMetadata(
84 const QString& name,87 const QString& name,
85 const QString& value);88 const QString& value);
89 virtual QList<QDBusObjectPath> getUncollectedDownloads(
90 const QString& appId);
91 virtual DownloadStateStruct getDownloadState(const QString &downloadId);
86 signals:92 signals:
87 void downloadCreated(const QDBusObjectPath& path);93 void downloadCreated(const QDBusObjectPath& path);
8894
8995
=== modified file 'src/downloads/priv/ubuntu/downloads/state_machines/download_sm.h'
--- src/downloads/priv/ubuntu/downloads/state_machines/download_sm.h 2014-02-21 12:46:26 +0000
+++ src/downloads/priv/ubuntu/downloads/state_machines/download_sm.h 2015-11-26 12:58:55 +0000
@@ -157,6 +157,7 @@
157 static QString POST_PROCESSING;157 static QString POST_PROCESSING;
158 static QString ERROR;158 static QString ERROR;
159 static QString CANCELED;159 static QString CANCELED;
160 static QString UNCOLLECTED;
160 static QString FINISHED;161 static QString FINISHED;
161162
162 signals:163 signals:
163164
=== modified file 'src/downloads/qml/CMakeLists.txt'
--- src/downloads/qml/CMakeLists.txt 2014-09-05 14:40:54 +0000
+++ src/downloads/qml/CMakeLists.txt 2015-11-26 12:58:55 +0000
@@ -5,6 +5,7 @@
5 backend.cpp5 backend.cpp
6 metadata.cpp6 metadata.cpp
7 download_error.cpp7 download_error.cpp
8 download_history.cpp
8 single_download.cpp9 single_download.cpp
9 ubuntu_download_manager.cpp10 ubuntu_download_manager.cpp
10)11)
@@ -13,6 +14,7 @@
13 backend.h14 backend.h
14 metadata.h15 metadata.h
15 download_error.h16 download_error.h
17 download_history.h
16 single_download.h18 single_download.h
17 ubuntu_download_manager.h19 ubuntu_download_manager.h
18)20)
1921
=== modified file 'src/downloads/qml/backend.cpp'
--- src/downloads/qml/backend.cpp 2014-09-23 10:38:11 +0000
+++ src/downloads/qml/backend.cpp 2015-11-26 12:58:55 +0000
@@ -15,6 +15,10 @@
15 qmlRegisterType<Ubuntu::DownloadManager::Metadata>(uri, 0, 1, "Metadata");15 qmlRegisterType<Ubuntu::DownloadManager::Metadata>(uri, 0, 1, "Metadata");
16 qmlRegisterType<Ubuntu::DownloadManager::SingleDownload>(uri, 0, 1, "SingleDownload");16 qmlRegisterType<Ubuntu::DownloadManager::SingleDownload>(uri, 0, 1, "SingleDownload");
17 qmlRegisterType<Ubuntu::DownloadManager::UbuntuDownloadManager>(uri, 0, 1, "DownloadManager");17 qmlRegisterType<Ubuntu::DownloadManager::UbuntuDownloadManager>(uri, 0, 1, "DownloadManager");
18 qmlRegisterType<Ubuntu::DownloadManager::DownloadError>(uri, 1, 2, "Error");
19 qmlRegisterType<Ubuntu::DownloadManager::Metadata>(uri, 1, 2, "Metadata");
20 qmlRegisterType<Ubuntu::DownloadManager::SingleDownload>(uri, 1, 2, "SingleDownload");
21 qmlRegisterType<Ubuntu::DownloadManager::UbuntuDownloadManager>(uri, 1, 2, "DownloadManager");
18}22}
1923
20void BackendPlugin::initializeEngine(QQmlEngine *engine, const char *uri)24void BackendPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
2125
=== added file 'src/downloads/qml/download_history.cpp'
--- src/downloads/qml/download_history.cpp 1970-01-01 00:00:00 +0000
+++ src/downloads/qml/download_history.cpp 2015-11-26 12:58:55 +0000
@@ -0,0 +1,143 @@
1#include "download_history.h"
2#include <glog/logging.h>
3#include <ubuntu/download_manager/download_struct.h>
4#include <QCoreApplication>
5
6namespace Ubuntu {
7
8namespace DownloadManager {
9
10DownloadHistory::DownloadHistory(QObject *parent) :
11 QObject(parent),
12 m_manager(nullptr)
13{
14 m_manager = Manager::createSessionManager("", this);
15
16 CHECK(connect(m_manager, &Manager::downloadsFound,
17 this, &DownloadHistory::downloadsFound))
18 << "Could not connect to signal";
19
20 // Get previous downloads for this app
21 auto environment = QProcessEnvironment::systemEnvironment();
22 if (environment.contains("APP_ID")) {
23 m_manager->getUncollectedDownloads(environment.value("APP_ID"));
24 } else {
25 m_manager->getUncollectedDownloads(QCoreApplication::applicationFilePath());
26 }
27}
28
29DownloadHistory *DownloadHistory::instance()
30{
31 static DownloadHistory *downloadHistory = new DownloadHistory();
32 return downloadHistory;
33}
34
35QVariantList DownloadHistory::downloads() const
36{
37 return m_downloads;
38}
39
40void DownloadHistory::addDownload(SingleDownload *singleDownload)
41{
42 m_downloads.append(QVariant::fromValue(singleDownload));
43 CHECK(connect(singleDownload, &SingleDownload::finished,
44 this, &DownloadHistory::downloadCompleted))
45 << "Could not connect to signal";
46 CHECK(connect(singleDownload, &SingleDownload::errorFound,
47 this, &DownloadHistory::onError))
48 << "Could not connect to signal";
49 CHECK(connect(singleDownload, &SingleDownload::paused,
50 this, &DownloadHistory::onPaused))
51 << "Could not connect to signal";
52 CHECK(connect(singleDownload, &SingleDownload::resumed,
53 this, &DownloadHistory::onResumed))
54 << "Could not connect to signal";
55 CHECK(connect(singleDownload, &SingleDownload::canceled,
56 this, &DownloadHistory::onCanceled))
57 << "Could not connect to signal";
58 emit downloadsChanged();
59}
60
61void DownloadHistory::downloadsFound(DownloadsList* downloadsList)
62{
63 foreach(QSharedPointer<Download> download, downloadsList->downloads()) {
64 SingleDownload* singleDownload = new SingleDownload(this);
65 singleDownload->bindDownload(download.data());
66 if (download->state() == Download::UNCOLLECTED && !download->filePath().isEmpty()) {
67 emit singleDownload->finished(download.data()->filePath());
68 }
69 }
70 emit downloadsChanged();
71}
72
73bool DownloadHistory::cleanDownloads() const
74{
75 return m_cleanDownloads;
76}
77
78void DownloadHistory::setCleanDownloads(bool value)
79{
80 m_cleanDownloads = value;
81 if (m_cleanDownloads) {
82 QVariantList newList;
83 foreach(QVariant var, m_downloads) {
84 SingleDownload *download = qobject_cast<SingleDownload*>(var.value<SingleDownload*>());
85 if (download != nullptr && !download->isCompleted()) {
86 newList.append(QVariant::fromValue(download));
87 } else {
88 download->deleteLater();
89 }
90 }
91 m_downloads = newList;
92 emit downloadsChanged();
93 }
94}
95
96void DownloadHistory::downloadCompleted(const QString& path)
97{
98 SingleDownload* download = qobject_cast<SingleDownload*>(sender());
99 if (download != nullptr) {
100 emit downloadFinished(download, path);
101 if (m_cleanDownloads) {
102 int index = m_downloads.indexOf(QVariant::fromValue(download));
103 m_downloads.removeAt(index);
104 emit downloadsChanged();
105 }
106 }
107}
108
109void DownloadHistory::onError(DownloadError& downloadError)
110{
111 Q_UNUSED(downloadError);
112 SingleDownload* download = qobject_cast<SingleDownload*>(sender());
113 if (download != nullptr) {
114 emit errorFound(download);
115 }
116}
117
118void DownloadHistory::onPaused()
119{
120 SingleDownload* download = qobject_cast<SingleDownload*>(sender());
121 if (download != nullptr) {
122 emit downloadPaused(download);
123 }
124}
125
126void DownloadHistory::onResumed()
127{
128 SingleDownload* download = qobject_cast<SingleDownload*>(sender());
129 if (download != nullptr) {
130 emit downloadResumed(download);
131 }
132}
133
134void DownloadHistory::onCanceled()
135{
136 SingleDownload* download = qobject_cast<SingleDownload*>(sender());
137 if (download != nullptr) {
138 emit downloadCanceled(download);
139 }
140}
141
142}
143}
0144
=== added file 'src/downloads/qml/download_history.h'
--- src/downloads/qml/download_history.h 1970-01-01 00:00:00 +0000
+++ src/downloads/qml/download_history.h 2015-11-26 12:58:55 +0000
@@ -0,0 +1,69 @@
1/*
2 * Copyright 2015 Canonical Ltd.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of version 3 of the GNU Lesser General Public
6 * License as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17 */
18
19#ifndef DOWNLOAD_HISTORY_H
20#define DOWNLOAD_HISTORY_H
21
22#include <ubuntu/download_manager/manager.h>
23#include <ubuntu/download_manager/downloads_list.h>
24
25#include "single_download.h"
26
27namespace Ubuntu {
28
29namespace DownloadManager {
30
31class DownloadHistory : public QObject {
32 Q_OBJECT
33
34 public:
35 explicit DownloadHistory(QObject* parent=0);
36 static DownloadHistory *instance();
37
38 QVariantList downloads() const;
39 void downloadsFound(DownloadsList* downloadsList);
40 void addDownload(SingleDownload *singleDownload);
41 bool cleanDownloads() const;
42 void setCleanDownloads(bool value);
43
44 signals:
45 void downloadsChanged();
46 void downloadFinished(SingleDownload *singleDownload, const QString& path);
47 void errorFound(SingleDownload *download);
48 void downloadPaused(SingleDownload *singleDownload);
49 void downloadResumed(SingleDownload *singleDownload);
50 void downloadCanceled(SingleDownload *singleDownload);
51
52 private slots:
53 void downloadCompleted(const QString& path);
54 void onError(DownloadError& error);
55 void onPaused();
56 void onResumed();
57 void onCanceled();
58
59 private:
60 Manager* m_manager;
61 QVariantList m_downloads;
62 bool m_cleanDownloads;
63};
64
65} // Ubuntu
66
67} // DownloadManager
68
69#endif
070
=== modified file 'src/downloads/qml/single_download.cpp'
--- src/downloads/qml/single_download.cpp 2014-10-07 14:44:11 +0000
+++ src/downloads/qml/single_download.cpp 2015-11-26 12:58:55 +0000
@@ -20,6 +20,7 @@
20#include <ubuntu/download_manager/download_struct.h>20#include <ubuntu/download_manager/download_struct.h>
2121
22#include "single_download.h"22#include "single_download.h"
23#include "download_history.h"
2324
24namespace Ubuntu {25namespace Ubuntu {
2526
@@ -28,7 +29,7 @@
28/*!29/*!
29 \qmltype SingleDownload30 \qmltype SingleDownload
30 \instantiates SingleDownload31 \instantiates SingleDownload
31 \inqmlmodule Ubuntu.DownloadManager 0.132 \inqmlmodule Ubuntu.DownloadManager 1.2
32 \ingroup download33 \ingroup download
33 \brief Manage file downloads and tracking the progress.34 \brief Manage file downloads and tracking the progress.
3435
@@ -39,8 +40,8 @@
3940
40 \qml41 \qml
41 import QtQuick 2.042 import QtQuick 2.0
42 import Ubuntu.Components 0.143 import Ubuntu.Components 1.2
43 import Ubuntu.DownloadManager 0.144 import Ubuntu.DownloadManager 1.2
4445
45 Rectangle {46 Rectangle {
46 width: units.gu(100)47 width: units.gu(100)
@@ -152,8 +153,6 @@
152 &SingleDownload::onStarted))153 &SingleDownload::onStarted))
153 << "Could not connect to signal";154 << "Could not connect to signal";
154155
155 emit downloadIdChanged();
156
157 // is the current in memory setting dirty, if they are, we do set the before we156 // is the current in memory setting dirty, if they are, we do set the before we
158 // start157 // start
159 if (m_dirty) {158 if (m_dirty) {
@@ -169,6 +168,14 @@
169 if (m_manager != nullptr && m_autoStart) {168 if (m_manager != nullptr && m_autoStart) {
170 startDownload();169 startDownload();
171 }170 }
171
172 DownloadHistory::instance()->addDownload(this);
173
174 // Keep a record of the downloadId so clients can still access the property
175 // after a download has finished
176 m_downloadId = m_download->id();
177
178 emit downloadIdChanged();
172}179}
173180
174void181void
@@ -222,7 +229,9 @@
222 &SingleDownload::bindDownload))229 &SingleDownload::bindDownload))
223 << "Could not connect to signal";230 << "Could not connect to signal";
224 }231 }
225 DownloadStruct dstruct(url);232 Metadata metadata;
233 QMap<QString, QString> headers;
234 DownloadStruct dstruct(url, metadata.map(), headers);
226 m_manager->createDownload(dstruct);235 m_manager->createDownload(dstruct);
227 } else {236 } else {
228 m_error.setMessage("Current download still in progress.");237 m_error.setMessage("Current download still in progress.");
@@ -258,7 +267,9 @@
258void267void
259SingleDownload::pause()268SingleDownload::pause()
260{269{
261 m_download->pause();270 if (m_download != nullptr) {
271 m_download->pause();
272 }
262}273}
263274
264/*!275/*!
@@ -270,7 +281,9 @@
270void281void
271SingleDownload::resume()282SingleDownload::resume()
272{283{
273 m_download->resume();284 if (m_download != nullptr) {
285 m_download->resume();
286 }
274}287}
275288
276/*!289/*!
@@ -281,7 +294,9 @@
281void294void
282SingleDownload::cancel()295SingleDownload::cancel()
283{296{
284 m_download->cancel();297 if (m_download != nullptr) {
298 m_download->cancel();
299 }
285}300}
286301
287void302void
@@ -354,7 +369,7 @@
354bool369bool
355SingleDownload::allowMobileDownload() const {370SingleDownload::allowMobileDownload() const {
356 if (m_download == nullptr) {371 if (m_download == nullptr) {
357 return m_mobile;372 return m_mobile;
358 } else {373 } else {
359 return m_download->isMobileDownloadAllowed();374 return m_download->isMobileDownloadAllowed();
360 }375 }
@@ -412,7 +427,7 @@
412QString427QString
413SingleDownload::downloadId() const {428SingleDownload::downloadId() const {
414 if (m_download == nullptr) {429 if (m_download == nullptr) {
415 return "";430 return m_downloadId;
416 } else {431 } else {
417 return m_download->id();432 return m_download->id();
418 }433 }
@@ -577,11 +592,20 @@
577*/592*/
578593
579/*!594/*!
580 \qmlproperty QVariantMap SingleDownload:metadata:595 \qmlproperty QVariantMap SingleDownload::metadata
581596
582 This property allows to get and set the metadata that will be linked to 597 This property allows to get and set the metadata that will be linked to
583 the download request. 598 the download request.
584*/599*/
585600
601/*!
602 \qmlsignal SingleDownload::downloadFinished(QString path)
603
604 This signal is emitted when a download has finished. The downloaded file
605 path is provided via the 'path' paremeter. The corresponding handler is
606 \c onDownloadFinished
607*/
608
609
586}610}
587}611}
588612
=== modified file 'src/downloads/qml/single_download.h'
--- src/downloads/qml/single_download.h 2015-02-02 11:22:26 +0000
+++ src/downloads/qml/single_download.h 2015-11-26 12:58:55 +0000
@@ -171,6 +171,7 @@
171 DownloadError m_error;171 DownloadError m_error;
172 Download* m_download = nullptr;172 Download* m_download = nullptr;
173 Manager* m_manager = nullptr;173 Manager* m_manager = nullptr;
174 QString m_downloadId;
174175
175};176};
176177
177178
=== modified file 'src/downloads/qml/ubuntu_download_manager.cpp'
--- src/downloads/qml/ubuntu_download_manager.cpp 2014-05-07 12:27:08 +0000
+++ src/downloads/qml/ubuntu_download_manager.cpp 2015-11-26 12:58:55 +0000
@@ -1,6 +1,8 @@
1#include "ubuntu_download_manager.h"1#include "ubuntu_download_manager.h"
2#include "download_history.h"
2#include <glog/logging.h>3#include <glog/logging.h>
3#include <ubuntu/download_manager/download_struct.h>4#include <ubuntu/download_manager/download_struct.h>
5#include <QDebug>
46
5namespace Ubuntu {7namespace Ubuntu {
68
@@ -9,7 +11,7 @@
9/*!11/*!
10 \qmltype DownloadManager12 \qmltype DownloadManager
11 \instantiates DownloadManager13 \instantiates DownloadManager
12 \inqmlmodule Ubuntu.DownloadManager 0.114 \inqmlmodule Ubuntu.DownloadManager 1.2
13 \ingroup download15 \ingroup download
14 \brief Manage downloads for several files.16 \brief Manage downloads for several files.
1517
@@ -23,8 +25,8 @@
2325
24 \qml26 \qml
25 import QtQuick 2.027 import QtQuick 2.0
26 import Ubuntu.Components 0.128 import Ubuntu.Components 1.2
27 import Ubuntu.DownloadManager 0.129 import Ubuntu.DownloadManager 1.2
2830
29 Rectangle {31 Rectangle {
30 width: units.gu(100)32 width: units.gu(100)
@@ -89,6 +91,24 @@
89 CHECK(connect(m_manager, &Manager::downloadCreated,91 CHECK(connect(m_manager, &Manager::downloadCreated,
90 this, &UbuntuDownloadManager::downloadFileCreated))92 this, &UbuntuDownloadManager::downloadFileCreated))
91 << "Could not connect to signal";93 << "Could not connect to signal";
94 CHECK(connect(DownloadHistory::instance(), &DownloadHistory::downloadsChanged,
95 this, &UbuntuDownloadManager::downloadsChanged))
96 << "Could not connect to signal";
97 CHECK(connect(DownloadHistory::instance(), &DownloadHistory::downloadFinished,
98 this, &UbuntuDownloadManager::downloadFinished))
99 << "Could not connect to signal";
100 CHECK(connect(DownloadHistory::instance(), &DownloadHistory::downloadPaused,
101 this, &UbuntuDownloadManager::downloadPaused))
102 << "Could not connect to signal";
103 CHECK(connect(DownloadHistory::instance(), &DownloadHistory::downloadResumed,
104 this, &UbuntuDownloadManager::downloadResumed))
105 << "Could not connect to signal";
106 CHECK(connect(DownloadHistory::instance(), &DownloadHistory::downloadCanceled,
107 this, &UbuntuDownloadManager::downloadCanceled))
108 << "Could not connect to signal";
109 CHECK(connect(DownloadHistory::instance(), &DownloadHistory::errorFound,
110 this, &UbuntuDownloadManager::errorFound))
111 << "Could not connect to signal";
92}112}
93113
94UbuntuDownloadManager::~UbuntuDownloadManager()114UbuntuDownloadManager::~UbuntuDownloadManager()
@@ -96,7 +116,6 @@
96 if (m_manager != nullptr) {116 if (m_manager != nullptr) {
97 m_manager->deleteLater();117 m_manager->deleteLater();
98 }118 }
99 m_downloads.clear();
100}119}
101120
102/*!121/*!
@@ -106,7 +125,9 @@
106*/125*/
107void UbuntuDownloadManager::download(QString url)126void UbuntuDownloadManager::download(QString url)
108{127{
109 DownloadStruct dstruct(url);128 Metadata metadata;
129 QMap<QString, QString> headers;
130 DownloadStruct dstruct(url, metadata.map(), headers);
110 m_manager->createDownload(dstruct);131 m_manager->createDownload(dstruct);
111}132}
112133
@@ -116,12 +137,7 @@
116 CHECK(connect(singleDownload, &SingleDownload::errorFound,137 CHECK(connect(singleDownload, &SingleDownload::errorFound,
117 this, &UbuntuDownloadManager::registerError))138 this, &UbuntuDownloadManager::registerError))
118 << "Could not connect to signal";139 << "Could not connect to signal";
119 CHECK(connect(singleDownload, &SingleDownload::finished,
120 this, &UbuntuDownloadManager::downloadCompleted))
121 << "Could not connect to signal";
122 singleDownload->bindDownload(download);140 singleDownload->bindDownload(download);
123 m_downloads.append(QVariant::fromValue(singleDownload));
124 emit downloadsChanged();
125 if (m_autoStart) {141 if (m_autoStart) {
126 singleDownload->startDownload();142 singleDownload->startDownload();
127 }143 }
@@ -132,41 +148,25 @@
132 Q_UNUSED(group);148 Q_UNUSED(group);
133}149}
134150
135void UbuntuDownloadManager::registerError(DownloadError& error)151void UbuntuDownloadManager::registerError(DownloadError& downloadError)
136{152{
137 m_errorMessage = error.message();153 m_errorMessage = downloadError.message();
138 emit errorChanged();154 emit errorChanged();
139}155}
140156
157bool UbuntuDownloadManager::cleanDownloads() const
158{
159 return DownloadHistory::instance()->cleanDownloads();
160}
161
141void UbuntuDownloadManager::setCleanDownloads(bool value)162void UbuntuDownloadManager::setCleanDownloads(bool value)
142{163{
143 m_cleanDownloads = value;164 DownloadHistory::instance()->setCleanDownloads(value);
144 if (m_cleanDownloads) {
145 QVariantList newList;
146 foreach(QVariant var, m_downloads) {
147 SingleDownload *download = qobject_cast<SingleDownload*>(var.value<SingleDownload*>());
148 if (download != nullptr && !download->isCompleted()) {
149 newList.append(QVariant::fromValue(download));
150 } else {
151 download->deleteLater();
152 }
153 }
154 m_downloads = newList;
155 emit downloadsChanged();
156 }
157}165}
158166
159void UbuntuDownloadManager::downloadCompleted()167QVariantList UbuntuDownloadManager::downloads()
160{168{
161 if (m_cleanDownloads) {169 return DownloadHistory::instance()->downloads();
162 SingleDownload* download = qobject_cast<SingleDownload*>(sender());
163 if (download != nullptr) {
164 int index = m_downloads.indexOf(QVariant::fromValue(download));
165 m_downloads.removeAt(index);
166 emit downloadsChanged();
167 download->deleteLater();
168 }
169 }
170}170}
171171
172/*!172/*!
@@ -198,5 +198,47 @@
198 started, and let a custom delegate how to represent the UI for each download.198 started, and let a custom delegate how to represent the UI for each download.
199*/199*/
200200
201/*!
202 \qmlsignal DownloadManager::errorFound(SingleDownload download)
203 \since Ubuntu.DownloadManager 1.2
204
205 This signal is emitted when an error occurs in a download. The download in which the
206 error occurred is provided via the 'download' parameter, from which the error message
207 can be accessed via download.errorMessage. The corresponding handler is \c onErrorFound
208*/
209
210/*!
211 \qmlsignal DownloadManager::downloadFinished(SingleDownload download, QString path)
212 \since Ubuntu.DownloadManager 1.2
213
214 This signal is emitted when a download has finished. The finished download is provided
215 via the 'download' parameter and the downloaded file path is provided via the 'path'
216 paremeter. The corresponding handler is \c onDownloadFinished
217*/
218
219/*!
220 \qmlsignal DownloadManager::downloadPaused(SingleDownload download)
221 \since Ubuntu.DownloadManager 1.2
222
223 This signal is emitted when a download has been paused. The paused download is provided
224 via the 'download' parameter. The corresponding handler is \c onDownloadPaused
225*/
226
227/*!
228 \qmlsignal DownloadManager::downloadResumed(SingleDownload download)
229 \since Ubuntu.DownloadManager 1.2
230
231 This signal is emitted when a download has been resumed. The resumed download is provided
232 via the 'download' parameter. The corresponding handler is \c onDownloadResumed
233*/
234
235/*!
236 \qmlsignal DownloadManager::downloadCanceled(SingleDownload download)
237 \since Ubuntu.DownloadManager 1.2
238
239 This signal is emitted when a download has been canceled. The canceled download is provided
240 via the 'download' parameter. The corresponding handler is \c onDownloadCanceled
241*/
201}242}
243
202}244}
203245
=== modified file 'src/downloads/qml/ubuntu_download_manager.h'
--- src/downloads/qml/ubuntu_download_manager.h 2014-06-25 08:46:25 +0000
+++ src/downloads/qml/ubuntu_download_manager.h 2015-11-26 12:58:55 +0000
@@ -45,27 +45,31 @@
4545
46 Q_INVOKABLE void download(QString url);46 Q_INVOKABLE void download(QString url);
4747
48 QVariantList downloads() { return m_downloads; }48 QVariantList downloads();
49 QString errorMessage() const { return m_errorMessage; }49 QString errorMessage() const { return m_errorMessage; }
50 bool autoStart() const { return m_autoStart; }50 bool autoStart() const { return m_autoStart; }
51 bool cleanDownloads() const { return m_cleanDownloads; }51 bool cleanDownloads() const;
52 void setCleanDownloads(bool value);52 void setCleanDownloads(bool value);
53 void setAutoStart(bool value) { m_autoStart = value; }53 void setAutoStart(bool value) { m_autoStart = value; }
5454
55signals:55signals:
56 void errorChanged();56 void errorChanged();
57 void downloadsChanged();57 void downloadsChanged();
58 void downloadFinished(SingleDownload *download, const QString& path);
59 void errorFound(SingleDownload *download);
60 void downloadPaused(SingleDownload *download);
61 void downloadResumed(SingleDownload *download);
62 void downloadCanceled(SingleDownload *download);
5863
59private slots:64private slots:
60 void registerError(DownloadError& error);65 void registerError(DownloadError& error);
61 void downloadFileCreated(Download* download);66 void downloadFileCreated(Download* download);
62 void downloadGroupCreated(GroupDownload* group);67 void downloadGroupCreated(GroupDownload* group);
63 void downloadCompleted();68 void downloadsFound(DownloadsList* downloads);
6469
65private:70private:
66 bool m_autoStart;71 bool m_autoStart;
67 bool m_cleanDownloads;72 bool m_cleanDownloads;
68 QVariantList m_downloads;
69 QString m_errorMessage;73 QString m_errorMessage;
70 Manager* m_manager;74 Manager* m_manager;
71};75};
7276
=== modified file 'tests/downloads/daemon/download.h'
--- tests/downloads/daemon/download.h 2014-07-03 09:01:01 +0000
+++ tests/downloads/daemon/download.h 2015-11-26 12:58:55 +0000
@@ -84,8 +84,8 @@
84 MOCK_METHOD0(pauseTransfer, void());84 MOCK_METHOD0(pauseTransfer, void());
85 MOCK_METHOD0(resumeTransfer, void());85 MOCK_METHOD0(resumeTransfer, void());
86 MOCK_METHOD0(startTransfer, void());86 MOCK_METHOD0(startTransfer, void());
87 MOCK_METHOD0(filePath, QString());
87 MOCK_CONST_METHOD0(isValid, bool());88 MOCK_CONST_METHOD0(isValid, bool());
88 MOCK_CONST_METHOD0(filePath, QString());
89 MOCK_CONST_METHOD0(state, Transfer::State());89 MOCK_CONST_METHOD0(state, Transfer::State());
90 MOCK_CONST_METHOD0(path, QString());90 MOCK_CONST_METHOD0(path, QString());
91 MOCK_CONST_METHOD0(metadata, QVariantMap());91 MOCK_CONST_METHOD0(metadata, QVariantMap());
9292
=== modified file 'tests/downloads/daemon/test_download.cpp'
--- tests/downloads/daemon/test_download.cpp 2015-02-25 16:24:24 +0000
+++ tests/downloads/daemon/test_download.cpp 2015-11-26 12:58:55 +0000
@@ -1301,7 +1301,7 @@
1301 QVERIFY(spy.ensureSignalEmitted());1301 QVERIFY(spy.ensureSignalEmitted());
1302 QTRY_COMPARE(spy.count(), 1);1302 QTRY_COMPARE(spy.count(), 1);
1303 QTRY_COMPARE(processingSpy.count(), 0);1303 QTRY_COMPARE(processingSpy.count(), 0);
1304 QCOMPARE(download->state(), Download::FINISH);1304 QCOMPARE(download->state(), Download::UNCOLLECTED);
13051305
1306 delete download;1306 delete download;
13071307
@@ -1481,7 +1481,7 @@
1481 QVERIFY(spy.ensureSignalEmitted());1481 QVERIFY(spy.ensureSignalEmitted());
1482 QTRY_COMPARE(spy.count(), 1);1482 QTRY_COMPARE(spy.count(), 1);
1483 QTRY_COMPARE(processingSpy.count(), 1);1483 QTRY_COMPARE(processingSpy.count(), 1);
1484 QCOMPARE(download->state(), Download::FINISH);1484 QCOMPARE(download->state(), Download::UNCOLLECTED);
14851485
1486 delete download;1486 delete download;
14871487
@@ -2196,7 +2196,7 @@
21962196
2197 QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 20000);2197 QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 20000);
2198 QTRY_COMPARE_WITH_TIMEOUT(processingSpy.count(), 1, 20000);2198 QTRY_COMPARE_WITH_TIMEOUT(processingSpy.count(), 1, 20000);
2199 QCOMPARE(download->state(), Download::FINISH);2199 QCOMPARE(download->state(), Download::UNCOLLECTED);
22002200
2201 delete download;2201 delete download;
22022202
@@ -2309,7 +2309,7 @@
23092309
2310 QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 20000);2310 QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 20000);
2311 QTRY_COMPARE_WITH_TIMEOUT(processingSpy.count(), 1, 20000);2311 QTRY_COMPARE_WITH_TIMEOUT(processingSpy.count(), 1, 20000);
2312 QCOMPARE(download->state(), Download::FINISH);2312 QCOMPARE(download->state(), Download::UNCOLLECTED);
23132313
2314 delete download;2314 delete download;
23152315
@@ -2431,7 +2431,7 @@
2431 QVERIFY(spy.ensureSignalEmitted());2431 QVERIFY(spy.ensureSignalEmitted());
2432 QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 20000);2432 QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 20000);
2433 QTRY_COMPARE_WITH_TIMEOUT(processingSpy.count(), 1, 20000);2433 QTRY_COMPARE_WITH_TIMEOUT(processingSpy.count(), 1, 20000);
2434 QCOMPARE(download->state(), Download::FINISH);2434 QCOMPARE(download->state(), Download::UNCOLLECTED);
24352435
2436 delete download;2436 delete download;
24372437
@@ -3735,7 +3735,7 @@
3735 QVERIFY(spy.ensureSignalEmitted());3735 QVERIFY(spy.ensureSignalEmitted());
3736 QCOMPARE(spy.count(), 1);3736 QCOMPARE(spy.count(), 1);
3737 QCOMPARE(processingSpy.count(), 1);3737 QCOMPARE(processingSpy.count(), 1);
3738 QCOMPARE(download->state(), Download::FINISH);3738 QCOMPARE(download->state(), Download::UNCOLLECTED);
37393739
3740 delete download;3740 delete download;
37413741
@@ -4167,7 +4167,7 @@
41674167
4168 QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 20000);4168 QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 20000);
4169 QTRY_COMPARE_WITH_TIMEOUT(processingSpy.count(), 1, 20000);4169 QTRY_COMPARE_WITH_TIMEOUT(processingSpy.count(), 1, 20000);
4170 QCOMPARE(download->state(), Download::FINISH);4170 QCOMPARE(download->state(), Download::UNCOLLECTED);
41714171
4172 delete download;4172 delete download;
41734173
41744174
=== modified file 'tests/downloads/daemon/test_downloads_db.cpp'
--- tests/downloads/daemon/test_downloads_db.cpp 2014-11-17 20:34:24 +0000
+++ tests/downloads/daemon/test_downloads_db.cpp 2015-11-26 12:58:55 +0000
@@ -351,4 +351,77 @@
351 QTRY_COMPARE(1, spy.count()); 351 QTRY_COMPARE(1, spy.count());
352}352}
353353
354void
355TestDownloadsDb::testGetStateMissingDownload() {
356 _db->init();
357 auto result = _db->getDownloadState("random uuid");
358 QVERIFY(!result.isValid());
359}
360
361void
362TestDownloadsDb::testGetStateDownload_data() {
363 QTest::addColumn<QString>("id");
364 QTest::addColumn<QString>("appId");
365 QTest::addColumn<QString>("path");
366 QTest::addColumn<QUrl>("url");
367 QTest::addColumn<QString>("hash");
368 QTest::addColumn<QString>("hashAlgoString");
369 QTest::addColumn<QVariantMap>("metadata");
370 QTest::addColumn<QMap<QString, QString> >("headers");
371
372 QTest::newRow("First Row") << UuidUtils::getDBusString(QUuid::createUuid())
373 << "FIRST APP" << "first path" << QUrl("http://ubuntu.com") << ""
374 << "md5" << QVariantMap() << QMap<QString, QString>();
375
376 QVariantMap secondMetadata;
377 secondMetadata["test"] = 1;
378 secondMetadata["command"] = "cd";
379 secondMetadata["hello"] = 23;
380
381 QTest::newRow("Second Row") << UuidUtils::getDBusString(QUuid::createUuid())
382 << "SECOND APP" << "second path" << QUrl("http://ubuntu.com/phone")
383 << "" << "sha512" << secondMetadata << QMap<QString, QString>();
384
385 QVariantMap thirdMetadata;
386 secondMetadata["test"] = 3;
387 secondMetadata["command"] = "return";
388 secondMetadata["hello"] = 500;
389
390 QMap<QString, QString> thirdHeaders;
391 thirdHeaders["my-header"] = "I do something cool";
392
393 QTest::newRow("Third Row") << UuidUtils::getDBusString(QUuid::createUuid())
394 << "THIRD APP" << "third path" << QUrl("http://ubuntu.com/tablet")
395 << "" << "sha384" << thirdMetadata << thirdHeaders;
396}
397
398void
399TestDownloadsDb::testGetStateDownload() {
400 _db->init();
401 QFETCH(QString, id);
402 QFETCH(QString, appId);
403 QFETCH(QString, path);
404 QFETCH(QUrl, url);
405 QFETCH(QString, hash);
406 QFETCH(QString, hashAlgoString);
407 QFETCH(QVariantMap, metadata);
408 QFETCH(StringMap, headers);
409
410 QScopedPointer<FileDownload> download(new FileDownload(id, appId, path, true, "", url, hash,
411 hashAlgoString, metadata, headers));
412
413 _db->storeSingleDownload(download.data());
414
415 // create a second download with same id but a diff path to test is update
416 QString newPath = path + path;
417 QScopedPointer<FileDownload> secondDownload(new FileDownload(id, appId,
418 newPath, true, "", url, hash, hashAlgoString, metadata, headers));
419
420 _db->storeSingleDownload(secondDownload.data());
421 auto state = _db->getDownloadState(id);
422 QVERIFY(state.isValid());
423 QCOMPARE(state.getUrl(), url.toString());
424 QCOMPARE(state.getHash(), state.getHash());
425}
426
354QTEST_MAIN(TestDownloadsDb)427QTEST_MAIN(TestDownloadsDb)
355428
=== modified file 'tests/downloads/daemon/test_downloads_db.h'
--- tests/downloads/daemon/test_downloads_db.h 2014-07-03 09:01:01 +0000
+++ tests/downloads/daemon/test_downloads_db.h 2015-11-26 12:58:55 +0000
@@ -15,8 +15,7 @@
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.16 * Boston, MA 02110-1301, USA.
17 */17 */
18#ifndef TEST_DOWNLOADS_DB_H18#pragma once
19#define TEST_DOWNLOADS_DB_H
2019
21#include <QDir>20#include <QDir>
22#include <QObject>21#include <QObject>
@@ -65,9 +64,10 @@
65 void testStoreSingleDownloadPresent();64 void testStoreSingleDownloadPresent();
66 void testConnectedToDownload();65 void testConnectedToDownload();
67 void testDisconnectedFromDownload();66 void testDisconnectedFromDownload();
67 void testGetStateMissingDownload();
68 void testGetStateDownload_data();
69 void testGetStateDownload();
6870
69 private:71 private:
70 DownloadsDb* _db;72 DownloadsDb* _db;
71};73};
72
73#endif // TEST_DOWNLOADS_DB_H

Subscribers

People subscribed via source and target branches