Merge lp:~mandel/ubuntu-download-manager/abstract-classes into lp:ubuntu-download-manager

Proposed by Manuel de la Peña
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 239
Merged at revision: 245
Proposed branch: lp:~mandel/ubuntu-download-manager/abstract-classes
Merge into: lp:ubuntu-download-manager
Diff against target: 3548 lines (+1635/-809)
53 files modified
debian/libubuntu-download-manager-common-dev.install (+1/-0)
docs/com.canonical.applications.download.xml (+5/-0)
docs/com.canonical.applications.group_download.xml (+24/-0)
docs/com.canonical.applications.testing.download_manager.xml (+5/-0)
ubuntu-download-manager-client-tests/test_download.cpp (+35/-0)
ubuntu-download-manager-client-tests/test_download.h (+2/-0)
ubuntu-download-manager-client/ubuntu-download-manager-client.pro (+4/-1)
ubuntu-download-manager-client/ubuntu/download_manager/download.h (+74/-0)
ubuntu-download-manager-client/ubuntu/download_manager/download_impl.cpp (+218/-330)
ubuntu-download-manager-client/ubuntu/download_manager/download_impl.h (+36/-34)
ubuntu-download-manager-client/ubuntu/download_manager/download_interface.h (+3/-2)
ubuntu-download-manager-client/ubuntu/download_manager/error.cpp (+69/-1)
ubuntu-download-manager-client/ubuntu/download_manager/error.h (+33/-5)
ubuntu-download-manager-client/ubuntu/download_manager/manager.cpp (+52/-0)
ubuntu-download-manager-client/ubuntu/download_manager/manager.h (+87/-0)
ubuntu-download-manager-client/ubuntu/download_manager/manager_impl.cpp (+203/-342)
ubuntu-download-manager-client/ubuntu/download_manager/manager_impl.h (+27/-30)
ubuntu-download-manager-client/ubuntu/download_manager/manager_pendingcall_watcher.cpp (+3/-3)
ubuntu-download-manager-common/ubuntu-download-manager-common.pro (+4/-2)
ubuntu-download-manager-common/ubuntu/download_manager/auth_error_struct.cpp (+92/-0)
ubuntu-download-manager-common/ubuntu/download_manager/auth_error_struct.h (+62/-0)
ubuntu-download-manager-common/ubuntu/download_manager/metatypes.h (+2/-1)
ubuntu-download-manager-priv/downloads/download_adaptor.h (+7/-2)
ubuntu-download-manager-priv/downloads/file_download.cpp (+22/-8)
ubuntu-download-manager-priv/downloads/file_download.h (+2/-0)
ubuntu-download-manager-priv/downloads/group_download.cpp (+54/-2)
ubuntu-download-manager-priv/downloads/group_download.h (+13/-2)
ubuntu-download-manager-priv/downloads/group_download_adaptor.cpp (+11/-11)
ubuntu-download-manager-priv/downloads/group_download_adaptor.h (+27/-3)
ubuntu-download-manager-priv/downloads/manager.cpp (+1/-0)
ubuntu-download-manager-priv/system/network_reply.cpp (+7/-2)
ubuntu-download-manager-priv/system/network_reply.h (+2/-1)
ubuntu-download-manager-test-lib/ubuntu-download-manager-test-lib.pro (+4/-2)
ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/daemon_testcase.cpp (+21/-0)
ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/daemon_testcase.h (+1/-0)
ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_daemon.cpp (+7/-0)
ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_daemon.h (+1/-0)
ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_file_download.cpp (+21/-4)
ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_file_download.h (+3/-0)
ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_interface.h (+9/-2)
ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_manager.cpp (+12/-0)
ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_manager.h (+1/-0)
ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_manager_adaptor.cpp (+6/-0)
ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_manager_adaptor.h (+8/-2)
ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/download.cpp (+21/-0)
ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/download.h (+4/-0)
ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/group_download.cpp (+81/-0)
ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/group_download.h (+50/-0)
ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/network_reply.cpp (+1/-1)
ubuntu-download-manager-tests/downloads/test_download.cpp (+72/-16)
ubuntu-download-manager-tests/downloads/test_download.h (+2/-0)
ubuntu-download-manager-tests/downloads/test_group_download.cpp (+113/-0)
ubuntu-download-manager-tests/downloads/test_group_download.h (+10/-0)
To merge this branch: bzr merge lp:~mandel/ubuntu-download-manager/abstract-classes
Reviewer Review Type Date Requested Status
Diego Sarmentero (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+205943@code.launchpad.net

Commit message

Provide pure abstract classes to simplify testing.

Description of the change

Provide pure abstract classes to simplify testing.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve
240. By Manuel de la Peña

Merged with auth signals to fix conflict.s

241. By Manuel de la Peña

Fixed compiling errors.

242. By Manuel de la Peña

Registered missing types.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/libubuntu-download-manager-common-dev.install'
2--- debian/libubuntu-download-manager-common-dev.install 2014-02-10 18:04:03 +0000
3+++ debian/libubuntu-download-manager-common-dev.install 2014-02-19 18:29:41 +0000
4@@ -2,6 +2,7 @@
5 usr/include/ubuntu/download_manager/metatypes.h
6 usr/include/ubuntu/download_manager/download_struct.h
7 usr/include/ubuntu/download_manager/group_download_struct.h
8+usr/include/ubuntu/download_manager/auth_error_struct.h
9 usr/include/ubuntu/download_manager/http_error_struct.h
10 usr/include/ubuntu/download_manager/network_error_struct.h
11 usr/include/ubuntu/download_manager/process_error_struct.h
12
13=== modified file 'docs/com.canonical.applications.download.xml'
14--- docs/com.canonical.applications.download.xml 2014-01-27 16:36:44 +0000
15+++ docs/com.canonical.applications.download.xml 2014-02-19 18:29:41 +0000
16@@ -59,6 +59,11 @@
17 <arg name="error" type="s" direction="out"/>
18 </signal>
19
20+ <signal name="authError">
21+ <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="AuthErrorStruct"/>
22+ <arg name="error" type="(is)" direction="out"/>
23+ </signal>
24+
25 <signal name="httpError">
26 <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="HttpErrorStruct"/>
27 <arg name="error" type="(is)" direction="out"/>
28
29=== modified file 'docs/com.canonical.applications.group_download.xml'
30--- docs/com.canonical.applications.group_download.xml 2013-12-03 13:03:53 +0000
31+++ docs/com.canonical.applications.group_download.xml 2014-02-19 18:29:41 +0000
32@@ -62,6 +62,30 @@
33 <arg name="error" type="s" direction="out"/>
34 </signal>
35
36+ <signal name="authError">
37+ <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="AuthErrorStruct"/>
38+ <arg name="url" type="s" direction="out"/>
39+ <arg name="error" type="(is)" direction="out"/>
40+ </signal>
41+
42+ <signal name="httpError">
43+ <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="HttpErrorStruct"/>
44+ <arg name="url" type="s" direction="out"/>
45+ <arg name="error" type="(is)" direction="out"/>
46+ </signal>
47+
48+ <signal name="networkError">
49+ <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="NetworkErrorStruct"/>
50+ <arg name="url" type="s" direction="out"/>
51+ <arg name="error" type="(is)" direction="out"/>
52+ </signal>
53+
54+ <signal name="processError">
55+ <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="ProcessErrorStruct"/>
56+ <arg name="url" type="s" direction="out"/>
57+ <arg name="error" type="(isiss)" direction="out"/>
58+ </signal>
59+
60 <signal name="progress">
61 <arg name="received" type="t" direction="out"/>
62 <arg name="total" type="t" direction="out"/>
63
64=== modified file 'docs/com.canonical.applications.testing.download_manager.xml'
65--- docs/com.canonical.applications.testing.download_manager.xml 2014-02-03 17:48:28 +0000
66+++ docs/com.canonical.applications.testing.download_manager.xml 2014-02-19 18:29:41 +0000
67@@ -23,5 +23,10 @@
68 <arg name="error" type="(isiss)" direction="in"/>
69 </method>
70
71+ <method name="returnAuthError">
72+ <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="AuthErrorStruct"/>
73+ <arg name="download" type="s" direction="in"/>
74+ <arg name="error" type="(is)" direction="in"/>
75+ </method>
76 </interface>
77 </node>
78
79=== modified file 'ubuntu-download-manager-client-tests/test_download.cpp'
80--- ubuntu-download-manager-client-tests/test_download.cpp 2014-02-05 12:58:09 +0000
81+++ ubuntu-download-manager-client-tests/test_download.cpp 2014-02-19 18:29:41 +0000
82@@ -16,6 +16,7 @@
83 * Boston, MA 02110-1301, USA.
84 */
85
86+#include <QNetworkReply>
87 #include <QSignalSpy>
88 #include <ubuntu/download_manager/error.h>
89 #include "test_download.h"
90@@ -137,6 +138,40 @@
91 }
92
93 void
94+TestDownload::testAuthErrorRaised_data() {
95+ QTest::addColumn<QNetworkReply::NetworkError>("code");
96+ QTest::addColumn<QString>("msg");
97+
98+ QTest::newRow("Server Authentication")
99+ << QNetworkReply::AuthenticationRequiredError
100+ << "Server rejected request";
101+ QTest::newRow("Proxy Authentication")
102+ << QNetworkReply::ProxyAuthenticationRequiredError
103+ << "Proxy rejected request";
104+}
105+
106+void
107+TestDownload::testAuthErrorRaised() {
108+ QFETCH(QNetworkReply::NetworkError, code);
109+ QFETCH(QString, msg);
110+
111+ AuthErrorStruct err(code, msg);
112+ returnAuthError(_url, err);
113+
114+ QSignalSpy spy(_down, SIGNAL(error(Error*)));
115+ _down->start();
116+
117+ QTRY_COMPARE(1, spy.count());
118+ auto error = spy.takeFirst().at(0).value<Error*>();
119+ QVERIFY(_down->isError());
120+ QVERIFY(_down->error() != nullptr);
121+ QCOMPARE(Error::Auth, error->type());
122+
123+ auto authError = qobject_cast<AuthError*>(error);
124+ QCOMPARE(msg, authError->phrase());
125+}
126+
127+void
128 TestDownload::testHttpErrorRaised_data() {
129 QTest::addColumn<int>("code");
130 QTest::addColumn<QString>("msg");
131
132=== modified file 'ubuntu-download-manager-client-tests/test_download.h'
133--- ubuntu-download-manager-client-tests/test_download.h 2014-02-05 11:01:12 +0000
134+++ ubuntu-download-manager-client-tests/test_download.h 2014-02-19 18:29:41 +0000
135@@ -47,6 +47,8 @@
136 void testMetadataError();
137 void testProgressError();
138 void testTotalSizeError();
139+ void testAuthErrorRaised_data();
140+ void testAuthErrorRaised();
141 void testHttpErrorRaised_data();
142 void testHttpErrorRaised();
143 void testNetworkErroRaised_data();
144
145=== modified file 'ubuntu-download-manager-client/ubuntu-download-manager-client.pro'
146--- ubuntu-download-manager-client/ubuntu-download-manager-client.pro 2014-02-07 10:06:24 +0000
147+++ ubuntu-download-manager-client/ubuntu-download-manager-client.pro 2014-02-19 18:29:41 +0000
148@@ -10,9 +10,10 @@
149 DEFINES += UBUNTUDOWNLOADMANAGERCLIENT_LIBRARY
150
151 SOURCES += ubuntu/download_manager/manager.cpp \
152+ ubuntu/download_manager/manager_impl.cpp \
153 ubuntu/download_manager/download_interface.cpp \
154 ubuntu/download_manager/manager_interface.cpp \
155- ubuntu/download_manager/download.cpp \
156+ ubuntu/download_manager/download_impl.cpp \
157 ubuntu/download_manager/group_download.cpp \
158 ubuntu/download_manager/manager_pendingcall_watcher.cpp \
159 ubuntu/download_manager/error.cpp \
160@@ -26,6 +27,8 @@
161 ubuntu/download_manager/error.h
162
163 private_headers = \
164+ ubuntu/download_manager/manager_impl.h \
165+ ubuntu/download_manager/download_impl.h \
166 ubuntu/download_manager/download_interface.h \
167 ubuntu/download_manager/manager_interface.h \
168 ubuntu/download_manager/manager_pendingcall_watcher.h \
169
170=== added file 'ubuntu-download-manager-client/ubuntu/download_manager/download.h'
171--- ubuntu-download-manager-client/ubuntu/download_manager/download.h 1970-01-01 00:00:00 +0000
172+++ ubuntu-download-manager-client/ubuntu/download_manager/download.h 2014-02-19 18:29:41 +0000
173@@ -0,0 +1,74 @@
174+/*
175+ * Copyright 2013-2014 Canonical Ltd.
176+ *
177+ * This library is free software; you can redistribute it and/or
178+ * modify it under the terms of version 3 of the GNU Lesser General Public
179+ * License as published by the Free Software Foundation.
180+ *
181+ * This program is distributed in the hope that it will be useful,
182+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
183+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
184+ * General Public License for more details.
185+ *
186+ * You should have received a copy of the GNU Lesser General Public
187+ * License along with this library; if not, write to the
188+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
189+ * Boston, MA 02110-1301, USA.
190+ */
191+
192+#ifndef UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_H
193+#define UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_H
194+
195+#include <QObject>
196+#include <QVariantMap>
197+#include <QString>
198+#include <ubuntu/download_manager/common.h>
199+
200+namespace Ubuntu {
201+
202+namespace DownloadManager {
203+
204+class Error;
205+class DOWNLOAD_MANAGER_EXPORT Download : public QObject {
206+ Q_OBJECT
207+
208+ public:
209+ explicit Download(QObject* parent = 0)
210+ : QObject(parent) {}
211+
212+ virtual void start() = 0;
213+ virtual void pause() = 0;
214+ virtual void resume() = 0;
215+ virtual void cancel() = 0;
216+
217+ virtual void allowMobileDownload(bool allowed) = 0;
218+ virtual bool isMobileDownloadAllowed() = 0;
219+
220+ virtual void setThrottle(qulonglong speed) = 0;
221+ virtual qulonglong throttle() = 0;
222+
223+ virtual QString id() const = 0;
224+ virtual QVariantMap metadata() = 0;
225+ virtual qulonglong progress() = 0;
226+ virtual qulonglong totalSize() = 0;
227+
228+ virtual bool isError() const = 0;
229+ virtual Error* error() const = 0;
230+
231+ signals:
232+ void canceled(bool success);
233+ void error(Error* error);
234+ void finished(const QString& path);
235+ void paused(bool success);
236+ void processing(const QString &path);
237+ void progress(qulonglong received, qulonglong total);
238+ void resumed(bool success);
239+ void started(bool success);
240+
241+};
242+
243+} // Ubuntu
244+
245+} // DownloadManager
246+
247+#endif // UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_H
248
249=== renamed file 'ubuntu-download-manager-client/ubuntu/download_manager/download.cpp' => 'ubuntu-download-manager-client/ubuntu/download_manager/download_impl.cpp'
250--- ubuntu-download-manager-client/ubuntu/download_manager/download.cpp 2014-02-05 11:01:12 +0000
251+++ ubuntu-download-manager-client/ubuntu/download_manager/download_impl.cpp 2014-02-19 18:29:41 +0000
252@@ -16,365 +16,253 @@
253 * Boston, MA 02110-1301, USA.
254 */
255
256-#include <QDebug>
257-#include <QDBusConnection>
258-#include <QDBusObjectPath>
259-#include <ubuntu/download_manager/metatypes.h>
260-#include "download_pendingcall_watcher.h"
261-#include "download_interface.h"
262-#include "error.h"
263-#include "download.h"
264+#include "download_impl.h"
265
266 namespace Ubuntu {
267
268 namespace DownloadManager {
269
270-/*
271- * PRIVATE IMPLEMENTATION
272- */
273-
274-class DownloadPrivate {
275- Q_DECLARE_PUBLIC(Download)
276-
277- public:
278- DownloadPrivate(const QDBusConnection& conn,
279- const QString& servicePath,
280- const QDBusObjectPath& objectPath,
281- Download* parent)
282- : _id(objectPath.path()),
283- _conn(conn),
284- _servicePath(servicePath),
285- q_ptr(parent) {
286- Q_Q(Download);
287- _dbusInterface = new DownloadInterface(servicePath,
288- _id, conn);
289-
290- // fwd all the signals but the error one
291- q->connect(_dbusInterface, &DownloadInterface::canceled,
292- q, &Download::canceled);
293- q->connect(_dbusInterface, &DownloadInterface::finished,
294- q, &Download::finished);
295- q->connect(_dbusInterface, &DownloadInterface::paused,
296- q, &Download::paused);
297- q->connect(_dbusInterface, &DownloadInterface::processing,
298- q, &Download::processing);
299- q->connect(_dbusInterface, static_cast<void(DownloadInterface::*)
300- (qulonglong, qulonglong)>(&DownloadInterface::progress),
301- q, static_cast<void(Download::*)
302- (qulonglong, qulonglong)>(&Download::progress));
303- q->connect(_dbusInterface, &DownloadInterface::resumed,
304- q, &Download::resumed);
305- q->connect(_dbusInterface, &DownloadInterface::started,
306- q, &Download::started);
307-
308- // connect to the different type of errors that will later be converted to
309- // the error type to be used by the client. With a pimpl implementation we
310- // cannot use the new stype connections :(
311- q->connect(_dbusInterface, SIGNAL(httpError(HttpErrorStruct)),
312- q, SLOT(onHttpError(HttpErrorStruct)));
313- q->connect(_dbusInterface, SIGNAL(networkError(NetworkErrorStruct)),
314- q, SLOT(onNetworkError(NetworkErrorStruct)));
315- q->connect(_dbusInterface, SIGNAL(processError(ProcessErrorStruct)),
316- q, SLOT(onProcessError(ProcessErrorStruct)));
317- }
318-
319- DownloadPrivate(const QDBusConnection& conn, Error* err, Download* parent)
320- : _isError(true),
321- _lastError(err),
322- _conn(conn),
323- q_ptr(parent) {
324- }
325-
326- ~DownloadPrivate() {
327+DownloadImpl::DownloadImpl(const QDBusConnection& conn,
328+ const QString& servicePath,
329+ const QDBusObjectPath& objectPath,
330+ QObject* parent)
331+ : Download(parent),
332+ _id(objectPath.path()),
333+ _conn(conn),
334+ _servicePath(servicePath) {
335+ _dbusInterface = new DownloadInterface(servicePath,
336+ _id, conn);
337+
338+ // fwd all the signals but the error one
339+ connect(_dbusInterface, &DownloadInterface::canceled,
340+ this, &Download::canceled);
341+ connect(_dbusInterface, &DownloadInterface::finished,
342+ this, &Download::finished);
343+ connect(_dbusInterface, &DownloadInterface::paused,
344+ this, &Download::paused);
345+ connect(_dbusInterface, &DownloadInterface::processing,
346+ this, &Download::processing);
347+ connect(_dbusInterface, static_cast<void(DownloadInterface::*)
348+ (qulonglong, qulonglong)>(&DownloadInterface::progress),
349+ this, static_cast<void(Download::*)
350+ (qulonglong, qulonglong)>(&Download::progress));
351+ connect(_dbusInterface, &DownloadInterface::resumed,
352+ this, &Download::resumed);
353+ connect(_dbusInterface, &DownloadInterface::started,
354+ this, &Download::started);
355+
356+ // connect to the different type of errors that will later be converted to
357+ // the error type to be used by the client.
358+ connect(_dbusInterface, &DownloadInterface::httpError,
359+ this, &DownloadImpl::onHttpError);
360+ connect(_dbusInterface, &DownloadInterface::networkError,
361+ this, &DownloadImpl::onNetworkError);
362+ connect(_dbusInterface, &DownloadInterface::processError,
363+ this, &DownloadImpl::onProcessError);
364+ connect(_dbusInterface, &DownloadInterface::authError,
365+ this, &DownloadImpl::onAuthError);
366+}
367+
368+DownloadImpl::DownloadImpl(const QDBusConnection& conn, Error* err, QObject* parent)
369+ : Download(parent),
370+ _isError(true),
371+ _lastError(err),
372+ _conn(conn) {
373+}
374+
375+DownloadImpl::~DownloadImpl() {
376+ delete _lastError;
377+ delete _dbusInterface;
378+}
379+
380+void
381+DownloadImpl::setLastError(Error* err) {
382+ if (_lastError != nullptr) {
383 delete _lastError;
384- delete _dbusInterface;
385- }
386-
387- void setLastError(Error* err) {
388- Q_Q(Download);
389- if (_lastError != nullptr) {
390- delete _lastError;
391- }
392- _lastError = err;
393- _isError = true;
394- emit q->error(err);
395- }
396-
397- void setLastError(const QDBusError& err) {
398- Q_Q(Download);
399- setLastError(new DBusError(err, q));
400- }
401-
402- void start() {
403- Q_Q(Download);
404- QDBusPendingCall call =
405- _dbusInterface->start();
406- auto watcher = new DownloadPendingCallWatcher(_conn, _servicePath,
407- call, q);
408- Q_UNUSED(watcher);
409- }
410-
411- void pause() {
412- Q_Q(Download);
413- QDBusPendingCall call =
414- _dbusInterface->pause();
415- auto watcher = new DownloadPendingCallWatcher(_conn, _servicePath,
416- call, q);
417- Q_UNUSED(watcher);
418- }
419-
420- void resume() {
421- Q_Q(Download);
422- QDBusPendingCall call =
423- _dbusInterface->resume();
424- auto watcher = new DownloadPendingCallWatcher(_conn, _servicePath,
425- call, q);
426- Q_UNUSED(watcher);
427- }
428-
429- void cancel() {
430- Q_Q(Download);
431- QDBusPendingCall call =
432- _dbusInterface->cancel();
433- auto watcher = new DownloadPendingCallWatcher(_conn, _servicePath,
434- call, q);
435- Q_UNUSED(watcher);
436- }
437-
438- void allowMobileDownload(bool allowed) {
439- QDBusPendingReply<> reply =
440- _dbusInterface->allowGSMDownload(allowed);
441- // block, the call should be fast enough
442- reply.waitForFinished();
443- if (reply.isError()) {
444- setLastError(reply.error());
445- }
446- }
447-
448- bool isMobileDownloadAllowed() {
449- QDBusPendingReply<bool> reply =
450- _dbusInterface->isGSMDownloadAllowed();
451- // block, the call should be fast enough
452- reply.waitForFinished();
453- if (reply.isError()) {
454- setLastError(reply.error());
455- return false;
456- } else {
457- auto result = reply.value();
458- return result;
459- }
460- }
461-
462- void setThrottle(qulonglong speed) {
463- QDBusPendingReply<> reply =
464- _dbusInterface->setThrottle(speed);
465- // block, the call should be fast enough
466- reply.waitForFinished();
467- if (reply.isError()) {
468- setLastError(reply.error());
469- }
470- }
471-
472- qulonglong throttle() {
473- QDBusPendingReply<qulonglong> reply =
474- _dbusInterface->throttle();
475- // block, the call is fast enough
476- reply.waitForFinished();
477- if (reply.isError()) {
478- setLastError(reply.error());
479- return 0;
480- } else {
481- auto result = reply.value();
482- return result;
483- }
484- }
485-
486- QString id() {
487- return _id;
488- }
489-
490- QVariantMap metadata() {
491- QDBusPendingReply<QVariantMap> reply =
492- _dbusInterface->metadata();
493- // block the call is fast enough
494- reply.waitForFinished();
495- if (reply.isError()) {
496- QVariantMap emptyResult;
497- setLastError(reply.error());
498- return emptyResult;
499- } else {
500- auto result = reply.value();
501- return result;
502- }
503- }
504-
505- qulonglong progress() {
506- QDBusPendingReply<qulonglong> reply =
507- _dbusInterface->progress();
508- // block call should be fast enough
509- reply.waitForFinished();
510- if (reply.isError()) {
511- setLastError(reply.error());
512- return 0;
513- } else {
514- auto result = reply.value();
515- return result;
516- }
517- }
518-
519- qulonglong totalSize() {
520- QDBusPendingReply<qulonglong> reply =
521- _dbusInterface->totalSize();
522- // block call should b fast enough
523- reply.waitForFinished();
524- if (reply.isError()) {
525- setLastError(reply.error());
526- return 0;
527- } else {
528- auto result = reply.value();
529- return result;
530- }
531- }
532-
533- bool isError() {
534- return _isError;
535- }
536-
537- Error* error() {
538- return _lastError;
539- }
540-
541- void onHttpError(HttpErrorStruct errStruct) {
542- Q_Q(Download);
543- auto err = new HttpError(errStruct, q);
544- setLastError(err);
545- }
546-
547- void onNetworkError(NetworkErrorStruct errStruct) {
548- Q_Q(Download);
549- auto err = new NetworkError(errStruct, q);
550- setLastError(err);
551- }
552-
553- void onProcessError(ProcessErrorStruct errStruct) {
554- Q_Q(Download);
555- auto err = new ProcessError(errStruct, q);
556- setLastError(err);
557- }
558-
559- private:
560- QString _id;
561- bool _isError = false;
562- Error* _lastError = nullptr;
563- DownloadInterface* _dbusInterface = nullptr;
564- QDBusConnection _conn;
565- QString _servicePath;
566- Download* q_ptr;
567-};
568-
569-Download::Download(const QDBusConnection& conn, Error* err, QObject* parent)
570- : QObject(parent),
571- d_ptr(new DownloadPrivate(conn, err, this)) {
572-}
573-
574-Download::Download(const QDBusConnection& conn,
575- const QString& servicePath,
576- const QDBusObjectPath& objectPath,
577- QObject* parent)
578- : QObject(parent),
579- d_ptr(new DownloadPrivate(conn, servicePath, objectPath, this)) {
580-}
581-
582-Download::~Download() {
583- delete d_ptr;
584-}
585-
586-void
587-Download::start(){
588- Q_D(Download);
589- d->start();
590-}
591-
592-void
593-Download::pause(){
594- Q_D(Download);
595- d->pause();
596-}
597-
598-void
599-Download::resume(){
600- Q_D(Download);
601- d->resume();
602-}
603-
604-void
605-Download::cancel(){
606- Q_D(Download);
607- d->cancel();
608-}
609-
610-void
611-Download::allowMobileDownload(bool allowed){
612- Q_D(Download);
613- d->allowMobileDownload(allowed);
614+ }
615+ _lastError = err;
616+ _isError = true;
617+ emit Download::error(err);
618+}
619+
620+void
621+DownloadImpl::setLastError(const QDBusError& err) {
622+ setLastError(new DBusError(err, this));
623+}
624+
625+void
626+DownloadImpl::start() {
627+ QDBusPendingCall call =
628+ _dbusInterface->start();
629+ auto watcher = new DownloadPendingCallWatcher(_conn, _servicePath,
630+ call, this);
631+ Q_UNUSED(watcher);
632+}
633+
634+void
635+DownloadImpl::pause() {
636+ QDBusPendingCall call =
637+ _dbusInterface->pause();
638+ auto watcher = new DownloadPendingCallWatcher(_conn, _servicePath,
639+ call, this);
640+ Q_UNUSED(watcher);
641+}
642+
643+void
644+DownloadImpl::resume() {
645+ QDBusPendingCall call =
646+ _dbusInterface->resume();
647+ auto watcher = new DownloadPendingCallWatcher(_conn, _servicePath,
648+ call, this);
649+ Q_UNUSED(watcher);
650+}
651+
652+void
653+DownloadImpl::cancel() {
654+ QDBusPendingCall call =
655+ _dbusInterface->cancel();
656+ auto watcher = new DownloadPendingCallWatcher(_conn, _servicePath,
657+ call, this);
658+ Q_UNUSED(watcher);
659+}
660+
661+void
662+DownloadImpl::allowMobileDownload(bool allowed) {
663+ QDBusPendingReply<> reply =
664+ _dbusInterface->allowGSMDownload(allowed);
665+ // block, the call should be fast enough
666+ reply.waitForFinished();
667+ if (reply.isError()) {
668+ setLastError(reply.error());
669+ }
670 }
671
672 bool
673-Download::isMobileDownloadAllowed(){
674- Q_D(Download);
675- return d->isMobileDownloadAllowed();
676+DownloadImpl::isMobileDownloadAllowed() {
677+ QDBusPendingReply<bool> reply =
678+ _dbusInterface->isGSMDownloadAllowed();
679+ // block, the call should be fast enough
680+ reply.waitForFinished();
681+ if (reply.isError()) {
682+ setLastError(reply.error());
683+ return false;
684+ } else {
685+ auto result = reply.value();
686+ return result;
687+ }
688 }
689
690 void
691-Download::setThrottle(qulonglong speed){
692- Q_D(Download);
693- d->setThrottle(speed);
694+DownloadImpl::setThrottle(qulonglong speed) {
695+ QDBusPendingReply<> reply =
696+ _dbusInterface->setThrottle(speed);
697+ // block, the call should be fast enough
698+ reply.waitForFinished();
699+ if (reply.isError()) {
700+ setLastError(reply.error());
701+ }
702 }
703
704 qulonglong
705-Download::throttle(){
706- Q_D(Download);
707- return d->throttle();
708+DownloadImpl::throttle() {
709+ QDBusPendingReply<qulonglong> reply =
710+ _dbusInterface->throttle();
711+ // block, the call is fast enough
712+ reply.waitForFinished();
713+ if (reply.isError()) {
714+ setLastError(reply.error());
715+ return 0;
716+ } else {
717+ auto result = reply.value();
718+ return result;
719+ }
720 }
721
722 QString
723-Download::id() {
724- Q_D(Download);
725- return d->id();
726+DownloadImpl::id() const {
727+ return _id;
728 }
729
730 QVariantMap
731-Download::metadata(){
732- Q_D(Download);
733- return d->metadata();
734-}
735-
736-qulonglong
737-Download::progress(){
738- Q_D(Download);
739- return d->progress();
740-}
741-
742-qulonglong
743-Download::totalSize(){
744- Q_D(Download);
745- return d->totalSize();
746+DownloadImpl::metadata() {
747+ QDBusPendingReply<QVariantMap> reply =
748+ _dbusInterface->metadata();
749+ // block the call is fast enough
750+ reply.waitForFinished();
751+ if (reply.isError()) {
752+ QVariantMap emptyResult;
753+ setLastError(reply.error());
754+ return emptyResult;
755+ } else {
756+ auto result = reply.value();
757+ return result;
758+ }
759+}
760+
761+qulonglong
762+DownloadImpl::progress() {
763+ QDBusPendingReply<qulonglong> reply =
764+ _dbusInterface->progress();
765+ // block call should be fast enough
766+ reply.waitForFinished();
767+ if (reply.isError()) {
768+ setLastError(reply.error());
769+ return 0;
770+ } else {
771+ auto result = reply.value();
772+ return result;
773+ }
774+}
775+
776+qulonglong
777+DownloadImpl::totalSize() {
778+ QDBusPendingReply<qulonglong> reply =
779+ _dbusInterface->totalSize();
780+ // block call should b fast enough
781+ reply.waitForFinished();
782+ if (reply.isError()) {
783+ setLastError(reply.error());
784+ return 0;
785+ } else {
786+ auto result = reply.value();
787+ return result;
788+ }
789 }
790
791 bool
792-Download::isError() {
793- Q_D(Download);
794- return d->isError();
795+DownloadImpl::isError() const {
796+ return _isError;
797 }
798
799 Error*
800-Download::error() {
801- Q_D(Download);
802- return d->error();
803+DownloadImpl::error() const {
804+ return _lastError;
805+}
806+
807+void
808+DownloadImpl::onHttpError(HttpErrorStruct errStruct) {
809+ auto err = new HttpError(errStruct, this);
810+ setLastError(err);
811+}
812+
813+void
814+DownloadImpl::onNetworkError(NetworkErrorStruct errStruct) {
815+ auto err = new NetworkError(errStruct, this);
816+ setLastError(err);
817+}
818+
819+void
820+DownloadImpl::onProcessError(ProcessErrorStruct errStruct) {
821+ auto err = new ProcessError(errStruct, this);
822+ setLastError(err);
823+}
824+
825+void
826+DownloadImpl::onAuthError(AuthErrorStruct errStruct) {
827+ auto err = new AuthError(errStruct, this);
828+ setLastError(err);
829 }
830
831 } // DownloadManager
832
833 } // Ubuntu
834-
835-#include "moc_download.cpp"
836
837=== renamed file 'ubuntu-download-manager-client/ubuntu/download_manager/download.h' => 'ubuntu-download-manager-client/ubuntu/download_manager/download_impl.h'
838--- ubuntu-download-manager-client/ubuntu/download_manager/download.h 2014-02-07 10:06:24 +0000
839+++ ubuntu-download-manager-client/ubuntu/download_manager/download_impl.h 2014-02-19 18:29:41 +0000
840@@ -16,13 +16,20 @@
841 * Boston, MA 02110-1301, USA.
842 */
843
844-#ifndef UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_H
845-#define UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_H
846+#ifndef UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_IMPL_H
847+#define UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_IMPL_H
848
849+#include <QDBusConnection>
850+#include <QDBusObjectPath>
851 #include <QObject>
852 #include <QVariantMap>
853 #include <QString>
854 #include <ubuntu/download_manager/common.h>
855+#include <ubuntu/download_manager/metatypes.h>
856+#include "download_interface.h"
857+#include "download_pendingcall_watcher.h"
858+#include "error.h"
859+#include "download.h"
860
861 class QDBusConnection;
862 class QDBusObjectPath;
863@@ -36,10 +43,8 @@
864 class NetworkErrorStruct;
865 class ProcessErrorStruct;
866 class ManagerPrivate;
867-class DownloadPrivate;
868-class DOWNLOAD_MANAGER_EXPORT Download : public QObject {
869+class DownloadImpl : public Download {
870 Q_OBJECT
871- Q_DECLARE_PRIVATE(Download)
872
873 // allow the manager to create downloads
874 friend class ManagerPrivate;
875@@ -47,7 +52,7 @@
876 friend class DownloadManagerPendingCallWatcher;
877
878 public:
879- virtual ~Download();
880+ virtual ~DownloadImpl();
881
882 void start();
883 void pause();
884@@ -60,39 +65,36 @@
885 void setThrottle(qulonglong speed);
886 qulonglong throttle();
887
888- QString id();
889+ QString id() const;
890 QVariantMap metadata();
891 qulonglong progress();
892 qulonglong totalSize();
893
894- bool isError();
895- Error* error();
896+ bool isError() const;
897+ Error* error() const;
898
899 protected:
900- Download(const QDBusConnection& conn, Error* err, QObject* parent = 0);
901- Download(const QDBusConnection& conn,
902- const QString& servicePath,
903- const QDBusObjectPath& objectPath,
904- QObject* parent = 0);
905-
906- private:
907- Q_PRIVATE_SLOT(d_func(), void onHttpError(HttpErrorStruct))
908- Q_PRIVATE_SLOT(d_func(), void onNetworkError(NetworkErrorStruct))
909- Q_PRIVATE_SLOT(d_func(), void onProcessError(ProcessErrorStruct))
910-
911- signals:
912- void canceled(bool success);
913- void error(Error* error);
914- void finished(const QString& path);
915- void paused(bool success);
916- void processing(const QString &path);
917- void progress(qulonglong received, qulonglong total);
918- void resumed(bool success);
919- void started(bool success);
920-
921- private:
922- // use pimpl pattern so that users do not have to be recompiled
923- DownloadPrivate* d_ptr;
924+ DownloadImpl(const QDBusConnection& conn, Error* err, QObject* parent = 0);
925+ DownloadImpl(const QDBusConnection& conn,
926+ const QString& servicePath,
927+ const QDBusObjectPath& objectPath,
928+ QObject* parent = 0);
929+
930+ private:
931+ void setLastError(Error* err);
932+ void setLastError(const QDBusError& err);
933+ void onHttpError(HttpErrorStruct);
934+ void onNetworkError(NetworkErrorStruct);
935+ void onProcessError(ProcessErrorStruct);
936+ void onAuthError(AuthErrorStruct);
937+
938+ private:
939+ QString _id;
940+ bool _isError = false;
941+ Error* _lastError = nullptr;
942+ DownloadInterface* _dbusInterface = nullptr;
943+ QDBusConnection _conn;
944+ QString _servicePath;
945
946 };
947
948@@ -100,4 +102,4 @@
949
950 } // DownloadManager
951
952-#endif // UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_H
953+#endif // UBUNTU_DOWNLOADMANAGER_CLIENT_DOWNLOAD_IMPL_H
954
955=== modified file 'ubuntu-download-manager-client/ubuntu/download_manager/download_interface.h'
956--- ubuntu-download-manager-client/ubuntu/download_manager/download_interface.h 2014-02-03 17:48:28 +0000
957+++ ubuntu-download-manager-client/ubuntu/download_manager/download_interface.h 2014-02-19 18:29:41 +0000
958@@ -8,8 +8,8 @@
959 * Do not edit! All changes made to it will be lost.
960 */
961
962-#ifndef DOWNLOAD_INTERFACE_H_1391245617
963-#define DOWNLOAD_INTERFACE_H_1391245617
964+#ifndef DOWNLOAD_INTERFACE_H_1392136772
965+#define DOWNLOAD_INTERFACE_H_1392136772
966
967 #include <QtCore/QObject>
968 #include <QtCore/QByteArray>
969@@ -106,6 +106,7 @@
970 }
971
972 Q_SIGNALS: // SIGNALS
973+ void authError(AuthErrorStruct error);
974 void canceled(bool success);
975 void error(const QString &error);
976 void finished(const QString &path);
977
978=== modified file 'ubuntu-download-manager-client/ubuntu/download_manager/error.cpp'
979--- ubuntu-download-manager-client/ubuntu/download_manager/error.cpp 2014-02-10 17:05:14 +0000
980+++ ubuntu-download-manager-client/ubuntu/download_manager/error.cpp 2014-02-19 18:29:41 +0000
981@@ -22,6 +22,7 @@
982
983 namespace {
984 const QString DBUS_ERROR_STRING = "DBusError: %1 - %2";
985+ const QString AUTH_ERROR_STRING = "AuthError: %1 - %2";
986 const QString HTTP_ERROR_STRING = "HttpError: %1 - %2";
987 const QString NETWORK_ERROR_STRING = "NetworkError: %1 - %2";
988 const QString PROCESS_ERROR_STRING = "ProcessError: %1 - %2\nExit code: %3\nStdout: %4\nStderr:%5";
989@@ -94,6 +95,46 @@
990 DBusError* q_ptr;
991 };
992
993+class AuthErrorPrivate {
994+ Q_DECLARE_PUBLIC(AuthError)
995+
996+ public:
997+ AuthErrorPrivate(AuthErrorStruct err, AuthError* parent)
998+ : _err(err),
999+ q_ptr(parent) {
1000+ }
1001+
1002+ inline AuthError::Type type() {
1003+ switch(_err.getType()) {
1004+ case AuthErrorStruct::Proxy:
1005+ return AuthError::Proxy;
1006+ default:
1007+ return AuthError::Server;
1008+ }
1009+ }
1010+
1011+ inline QString getTypeString() {
1012+ switch(_err.getType()) {
1013+ case AuthErrorStruct::Proxy:
1014+ return "Proxy";
1015+ default:
1016+ return "Server";
1017+ }
1018+ }
1019+
1020+ inline QString phrase() {
1021+ return _err.getPhrase();
1022+ }
1023+
1024+ inline QString errorString() {
1025+ return AUTH_ERROR_STRING.arg(getTypeString(), _err.getPhrase());
1026+ }
1027+
1028+ private:
1029+ AuthErrorStruct _err;
1030+ AuthError* q_ptr;
1031+};
1032+
1033 class HttpErrorPrivate {
1034 Q_DECLARE_PUBLIC(HttpError)
1035
1036@@ -138,7 +179,7 @@
1037 inline QString phrase() {
1038 return _err.getPhrase();
1039 }
1040-
1041+
1042 inline QString errorString() {
1043 return NETWORK_ERROR_STRING.arg(QString::number(_err.getCode()),
1044 _err.getPhrase());
1045@@ -242,6 +283,33 @@
1046 return d->errorString();
1047 }
1048
1049+AuthError::AuthError(AuthErrorStruct err, QObject* parent)
1050+ : Error(Error::Auth, parent),
1051+ d_ptr(new AuthErrorPrivate(err, this)) {
1052+}
1053+
1054+AuthError::~AuthError() {
1055+ delete d_ptr;
1056+}
1057+
1058+AuthError::Type
1059+AuthError::type() {
1060+ Q_D(AuthError);
1061+ return d->type();
1062+}
1063+
1064+QString
1065+AuthError::phrase() {
1066+ Q_D(AuthError);
1067+ return d->phrase();
1068+}
1069+
1070+QString
1071+AuthError::errorString() {
1072+ Q_D(AuthError);
1073+ return d->errorString();
1074+}
1075+
1076 HttpError::HttpError(HttpErrorStruct err, QObject* parent)
1077 : Error(Error::Http, parent),
1078 d_ptr(new HttpErrorPrivate(err, this)) {
1079
1080=== modified file 'ubuntu-download-manager-client/ubuntu/download_manager/error.h'
1081--- ubuntu-download-manager-client/ubuntu/download_manager/error.h 2014-02-10 21:56:42 +0000
1082+++ ubuntu-download-manager-client/ubuntu/download_manager/error.h 2014-02-19 18:29:41 +0000
1083@@ -29,6 +29,7 @@
1084
1085 namespace DownloadManager {
1086
1087+class AuthErrorStruct;
1088 class HttpErrorStruct;
1089 class NetworkErrorStruct;
1090 class ProcessErrorStruct;
1091@@ -39,6 +40,7 @@
1092
1093 public:
1094 enum Type {
1095+ Auth,
1096 DBus,
1097 Http,
1098 Network,
1099@@ -64,8 +66,8 @@
1100 Q_OBJECT
1101 Q_DECLARE_PRIVATE(DBusError)
1102
1103- friend class ManagerPrivate;
1104- friend class DownloadPrivate;
1105+ friend class ManagerImpl;
1106+ friend class DownloadImpl;
1107 friend class DownloadManagerPendingCallWatcher;
1108 friend class DownloadPendingCallWatcher;
1109 friend class GroupManagerPendingCallWatcher;
1110@@ -83,12 +85,38 @@
1111 DBusErrorPrivate* d_ptr;
1112 };
1113
1114+class AuthErrorPrivate;
1115+class DOWNLOAD_MANAGER_EXPORT AuthError : public Error {
1116+ Q_OBJECT
1117+ Q_DECLARE_PRIVATE(AuthError)
1118+
1119+ friend class DownloadImpl;
1120+
1121+ public:
1122+ enum Type {
1123+ Server,
1124+ Proxy
1125+ };
1126+
1127+ virtual ~AuthError();
1128+ Type type();
1129+ QString phrase();
1130+ QString errorString() override;
1131+
1132+ protected:
1133+ AuthError(AuthErrorStruct err, QObject* parent);
1134+
1135+ private:
1136+ // use pimpl pattern so that users do not have to be recompiled
1137+ AuthErrorPrivate* d_ptr;
1138+};
1139+
1140 class HttpErrorPrivate;
1141 class DOWNLOAD_MANAGER_EXPORT HttpError : public Error {
1142 Q_OBJECT
1143 Q_DECLARE_PRIVATE(HttpError)
1144
1145- friend class DownloadPrivate;
1146+ friend class DownloadImpl;
1147
1148 public:
1149 virtual ~HttpError();
1150@@ -109,7 +137,7 @@
1151 Q_OBJECT
1152 Q_DECLARE_PRIVATE(NetworkError)
1153
1154- friend class DownloadPrivate;
1155+ friend class DownloadImpl;
1156
1157 public:
1158 enum ErrorCode {
1159@@ -158,7 +186,7 @@
1160 Q_OBJECT
1161 Q_DECLARE_PRIVATE(ProcessError)
1162
1163- friend class DownloadPrivate;
1164+ friend class DownloadImpl;
1165
1166 public:
1167 virtual ~ProcessError();
1168
1169=== added file 'ubuntu-download-manager-client/ubuntu/download_manager/manager.cpp'
1170--- ubuntu-download-manager-client/ubuntu/download_manager/manager.cpp 1970-01-01 00:00:00 +0000
1171+++ ubuntu-download-manager-client/ubuntu/download_manager/manager.cpp 2014-02-19 18:29:41 +0000
1172@@ -0,0 +1,52 @@
1173+/*
1174+ * Copyright 2013-2014 Canonical Ltd.
1175+ *
1176+ * This library is free software; you can redistribute it and/or
1177+ * modify it under the terms of version 3 of the GNU Lesser General Public
1178+ * License as published by the Free Software Foundation.
1179+ *
1180+ * This program is distributed in the hope that it will be useful,
1181+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1182+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1183+ * General Public License for more details.
1184+ *
1185+ * You should have received a copy of the GNU Lesser General Public
1186+ * License along with this library; if not, write to the
1187+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
1188+ * Boston, MA 02110-1301, USA.
1189+ */
1190+
1191+#include <QDebug>
1192+#include "manager_impl.h"
1193+#include "manager.h"
1194+
1195+namespace {
1196+ const QString DOWNLOAD_SERVICE = "com.canonical.applications.Downloader";
1197+}
1198+
1199+namespace Ubuntu {
1200+
1201+namespace DownloadManager {
1202+
1203+Manager*
1204+Manager::createSessionManager(const QString& path, QObject* parent) {
1205+ if (path.isEmpty()) {
1206+ return new ManagerImpl(QDBusConnection::sessionBus(), DOWNLOAD_SERVICE, parent);
1207+ } else {
1208+ return new ManagerImpl(QDBusConnection::sessionBus(), path, parent);
1209+ }
1210+}
1211+
1212+Manager*
1213+Manager::createSystemManager(const QString& path, QObject* parent) {
1214+ if (path.isEmpty()) {
1215+ return new ManagerImpl(QDBusConnection::systemBus(), DOWNLOAD_SERVICE, parent);
1216+ } else {
1217+ return new ManagerImpl(QDBusConnection::systemBus(), path, parent);
1218+ }
1219+}
1220+
1221+
1222+} // DownloadManager
1223+
1224+} // Ubuntu
1225
1226=== added file 'ubuntu-download-manager-client/ubuntu/download_manager/manager.h'
1227--- ubuntu-download-manager-client/ubuntu/download_manager/manager.h 1970-01-01 00:00:00 +0000
1228+++ ubuntu-download-manager-client/ubuntu/download_manager/manager.h 2014-02-19 18:29:41 +0000
1229@@ -0,0 +1,87 @@
1230+/*
1231+ * Copyright 2013-2014 Canonical Ltd.
1232+ *
1233+ * This library is free software; you can redistribute it and/or
1234+ * modify it under the terms of version 3 of the GNU Lesser General Public
1235+ * License as published by the Free Software Foundation.
1236+ *
1237+ * This program is distributed in the hope that it will be useful,
1238+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1239+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1240+ * General Public License for more details.
1241+ *
1242+ * You should have received a copy of the GNU Lesser General Public
1243+ * License along with this library; if not, write to the
1244+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
1245+ * Boston, MA 02110-1301, USA.
1246+ */
1247+
1248+#ifndef UBUNTU_DOWNLOADMANAGER_CLIENT_MANAGER_H
1249+#define UBUNTU_DOWNLOADMANAGER_CLIENT_MANAGER_H
1250+
1251+#include <functional>
1252+#include <QList>
1253+#include <QObject>
1254+#include <ubuntu/download_manager/metatypes.h>
1255+#include <ubuntu/download_manager/common.h>
1256+#include <ubuntu/download_manager/download_struct.h>
1257+#include <ubuntu/download_manager/group_download_struct.h>
1258+
1259+
1260+namespace Ubuntu {
1261+
1262+namespace DownloadManager {
1263+
1264+class Download;
1265+class Error;
1266+class GroupDownload;
1267+
1268+typedef std::function<void(Download*)> DownloadCb;
1269+typedef std::function<void(GroupDownload*)> GroupCb;
1270+
1271+class DOWNLOAD_MANAGER_EXPORT Manager : public QObject {
1272+ Q_OBJECT
1273+
1274+ public:
1275+ explicit Manager(QObject* parent = 0)
1276+ : QObject(parent) {}
1277+
1278+ virtual void createDownload(DownloadStruct downStruct) = 0;
1279+ virtual void createDownload(DownloadStruct downStruct,
1280+ DownloadCb cb,
1281+ DownloadCb errCb) = 0;
1282+ virtual void createDownload(StructList downs,
1283+ const QString &algorithm,
1284+ bool allowed3G,
1285+ const QVariantMap &metadata,
1286+ StringMap headers) = 0;
1287+ virtual void createDownload(StructList downs,
1288+ const QString &algorithm,
1289+ bool allowed3G,
1290+ const QVariantMap &metadata,
1291+ StringMap headers,
1292+ GroupCb cb,
1293+ GroupCb errCb) = 0;
1294+
1295+ virtual bool isError() const = 0;
1296+ virtual Error* lastError() const = 0;
1297+ virtual void allowMobileDataDownload(bool allowed) = 0;
1298+ virtual bool isMobileDataDownload() = 0;
1299+ virtual qulonglong defaultThrottle() = 0;
1300+ virtual void setDefaultThrottle(qulonglong speed) = 0;
1301+ virtual void exit() = 0;
1302+
1303+ static Manager* createSessionManager(const QString& path = "", QObject* parent=0);
1304+ static Manager* createSystemManager(const QString& path = "", QObject* parent=0);
1305+
1306+ signals:
1307+ void downloadCreated(Download* down);
1308+ void groupCreated(GroupDownload* down);
1309+
1310+};
1311+
1312+} // DownloadManager
1313+
1314+} // Ubuntu
1315+
1316+#endif // UBUNTU_DOWNLOADMANAGER_CLIENT_MANAGER_H
1317
1318=== renamed file 'ubuntu-download-manager-client/ubuntu/download_manager/manager.cpp' => 'ubuntu-download-manager-client/ubuntu/download_manager/manager_impl.cpp'
1319--- ubuntu-download-manager-client/ubuntu/download_manager/manager.cpp 2014-02-05 12:58:09 +0000
1320+++ ubuntu-download-manager-client/ubuntu/download_manager/manager_impl.cpp 2014-02-19 18:29:41 +0000
1321@@ -17,359 +17,220 @@
1322 */
1323
1324 #include <QDebug>
1325-#include <QDBusConnection>
1326-#include <QDBusObjectPath>
1327-#include <ubuntu/download_manager/system/dbus_connection.h>
1328-#include "download.h"
1329-#include "error.h"
1330-#include "group_download.h"
1331-#include "manager_interface.h"
1332-#include "manager_pendingcall_watcher.h"
1333-#include "manager.h"
1334-
1335-
1336-#define DOWNLOAD_SERVICE "com.canonical.applications.Downloader"
1337-#define MANAGER_PATH "/"
1338-
1339+#include "manager_impl.h"
1340+
1341+namespace {
1342+ const QString MANAGER_PATH = "/";
1343+}
1344
1345 namespace Ubuntu {
1346
1347 namespace DownloadManager {
1348
1349-/*
1350- * PRIVATE IMPLEMENTATION
1351- */
1352-
1353-class ManagerPrivate {
1354- Q_DECLARE_PUBLIC(Manager)
1355-
1356- public:
1357- ManagerPrivate(const QDBusConnection& conn,
1358- const QString& path,
1359- Manager* parent)
1360- : _conn(conn),
1361- _servicePath(path),
1362- q_ptr(parent) {
1363- _dbusInterface = new ManagerInterface(path, MANAGER_PATH, conn);
1364- init();
1365- }
1366-
1367- // used for testing purposes
1368- ManagerPrivate(const QDBusConnection& conn,
1369- const QString& path,
1370- ManagerInterface* interface,
1371- Manager* parent)
1372- : _conn(conn),
1373- _servicePath(path),
1374- _dbusInterface(interface),
1375- q_ptr(parent) {
1376- init();
1377- }
1378-
1379- ~ManagerPrivate() {
1380+ManagerImpl::ManagerImpl(const QDBusConnection& conn,
1381+ const QString& path,
1382+ QObject* parent)
1383+ : Manager(parent),
1384+ _conn(conn),
1385+ _servicePath(path) {
1386+ _dbusInterface = new ManagerInterface(path, MANAGER_PATH, conn);
1387+ init();
1388+}
1389+
1390+// used for testing purposes
1391+ManagerImpl::ManagerImpl(const QDBusConnection& conn,
1392+ const QString& path,
1393+ ManagerInterface* interface,
1394+ QObject* parent)
1395+ : Manager(parent),
1396+ _conn(conn),
1397+ _servicePath(path),
1398+ _dbusInterface(interface) {
1399+ init();
1400+}
1401+
1402+ManagerImpl::~ManagerImpl() {
1403+ delete _lastError;
1404+ delete _dbusInterface;
1405+}
1406+
1407+void
1408+ManagerImpl::init() {
1409+ qRegisterMetaType<Download*>("Download*");
1410+ qRegisterMetaType<GroupDownload*>("GroupDownload*");
1411+ qRegisterMetaType<Error*>("Error*");
1412+ qRegisterMetaType<DBusError*>("DBusError*");
1413+ qRegisterMetaType<HttpError*>("HttpError*");
1414+ qRegisterMetaType<NetworkError*>("NetworkError*");
1415+ qRegisterMetaType<AuthError*>("AuthError*");
1416+ qRegisterMetaType<ProcessError*>("ProcessError*");
1417+ qDBusRegisterMetaType<StringMap>();
1418+ qDBusRegisterMetaType<DownloadStruct>();
1419+ qDBusRegisterMetaType<GroupDownloadStruct>();
1420+ qDBusRegisterMetaType<StructList>();
1421+ qDBusRegisterMetaType<AuthErrorStruct>();
1422+ qDBusRegisterMetaType<HttpErrorStruct>();
1423+ qDBusRegisterMetaType<NetworkErrorStruct>();
1424+ qDBusRegisterMetaType<ProcessErrorStruct>();
1425+}
1426+
1427+void
1428+ManagerImpl::createDownload(DownloadStruct downStruct) {
1429+ QDBusPendingCall call =
1430+ _dbusInterface->createDownload(downStruct);
1431+ DownloadCb cb = [](Download*) {};
1432+
1433+ auto watcher = new DownloadManagerPendingCallWatcher(_conn,
1434+ _servicePath, call, cb, cb, this);
1435+ connect(watcher, &DownloadManagerPendingCallWatcher::callbackExecuted,
1436+ this, &ManagerImpl::onWatcherDone);
1437+}
1438+
1439+void
1440+ManagerImpl::createDownload(DownloadStruct downStruct,
1441+ DownloadCb cb,
1442+ DownloadCb errCb) {
1443+ QDBusPendingCall call =
1444+ _dbusInterface->createDownload(downStruct);
1445+ auto watcher = new DownloadManagerPendingCallWatcher(_conn,
1446+ _servicePath, call, cb, errCb, this);
1447+ connect(watcher, &DownloadManagerPendingCallWatcher::callbackExecuted,
1448+ this, &ManagerImpl::onWatcherDone);
1449+}
1450+
1451+void
1452+ManagerImpl::createDownload(StructList downs,
1453+ const QString& algorithm,
1454+ bool allowed3G,
1455+ const QVariantMap& metadata,
1456+ StringMap headers) {
1457+ QDBusPendingCall call =
1458+ _dbusInterface->createDownloadGroup(downs,
1459+ algorithm, allowed3G, metadata, headers);
1460+
1461+ GroupCb cb = [](GroupDownload*) {};
1462+
1463+ auto watcher = new GroupManagerPendingCallWatcher(_conn, _servicePath,
1464+ call, cb, cb, this);
1465+ connect(watcher, &GroupManagerPendingCallWatcher::callbackExecuted,
1466+ this, &ManagerImpl::onWatcherDone);
1467+}
1468+
1469+void
1470+ManagerImpl::createDownload(StructList downs,
1471+ const QString& algorithm,
1472+ bool allowed3G,
1473+ const QVariantMap& metadata,
1474+ StringMap headers,
1475+ GroupCb cb,
1476+ GroupCb errCb) {
1477+ QDBusPendingCall call =
1478+ _dbusInterface->createDownloadGroup(downs,
1479+ algorithm, allowed3G, metadata, headers);
1480+ auto watcher = new GroupManagerPendingCallWatcher(_conn, _servicePath,
1481+ call, cb, errCb, this);
1482+ connect(watcher, &GroupManagerPendingCallWatcher::callbackExecuted,
1483+ this, &ManagerImpl::onWatcherDone);
1484+}
1485+
1486+bool
1487+ManagerImpl::isError() const {
1488+ return _isError;
1489+}
1490+
1491+Error*
1492+ManagerImpl::lastError() const {
1493+ return _lastError;
1494+}
1495+
1496+void
1497+ManagerImpl::setLastError(const QDBusError& err) {
1498+ // delete the last if error if present to keep mem to a minimum
1499+ if (_lastError != nullptr) {
1500 delete _lastError;
1501- delete _dbusInterface;
1502- }
1503-
1504- void init() {
1505- qRegisterMetaType<Download*>("Download*");
1506- qRegisterMetaType<GroupDownload*>("GroupDownload*");
1507- qRegisterMetaType<Error*>("Error*");
1508- qRegisterMetaType<DBusError*>("DBusError*");
1509- qRegisterMetaType<HttpError*>("HttpError*");
1510- qRegisterMetaType<NetworkError*>("NetworkError*");
1511- qRegisterMetaType<ProcessError*>("ProcessError*");
1512- qDBusRegisterMetaType<StringMap>();
1513- qDBusRegisterMetaType<DownloadStruct>();
1514- qDBusRegisterMetaType<GroupDownloadStruct>();
1515- qDBusRegisterMetaType<StructList>();
1516- qDBusRegisterMetaType<HttpErrorStruct>();
1517- qDBusRegisterMetaType<NetworkErrorStruct>();
1518- qDBusRegisterMetaType<ProcessErrorStruct>();
1519- }
1520-
1521- void createDownload(DownloadStruct downStruct) {
1522- Q_Q(Manager);
1523- QDBusPendingCall call =
1524- _dbusInterface->createDownload(downStruct);
1525- DownloadCb cb = [](Download*) {};
1526-
1527- auto watcher = new DownloadManagerPendingCallWatcher(_conn,
1528- _servicePath, call, cb, cb,
1529- static_cast<QObject*>(q));
1530- q->connect(watcher, SIGNAL(callbackExecuted()),
1531- q, SLOT(onWatcherDone()));
1532- }
1533-
1534- void createDownload(DownloadStruct downStruct,
1535- DownloadCb cb,
1536- DownloadCb errCb) {
1537- Q_Q(Manager);
1538- QDBusPendingCall call =
1539- _dbusInterface->createDownload(downStruct);
1540- auto watcher = new DownloadManagerPendingCallWatcher(_conn,
1541- _servicePath, call, cb, errCb,
1542- static_cast<QObject*>(q));
1543- q->connect(watcher, SIGNAL(callbackExecuted()),
1544- q, SLOT(onWatcherDone()));
1545- }
1546-
1547- void createDownload(StructList downs,
1548- const QString& algorithm,
1549- bool allowed3G,
1550- const QVariantMap& metadata,
1551- StringMap headers) {
1552- Q_Q(Manager);
1553- QDBusPendingCall call =
1554- _dbusInterface->createDownloadGroup(downs,
1555- algorithm, allowed3G, metadata, headers);
1556-
1557- GroupCb cb = [](GroupDownload*) {};
1558-
1559- auto watcher = new GroupManagerPendingCallWatcher(_conn, _servicePath,
1560- call, cb, cb, static_cast<QObject*>(q));
1561- q->connect(watcher, SIGNAL(callbackExecuted()),
1562- q, SLOT(onWatcherDone()));
1563- }
1564-
1565- void createDownload(StructList downs,
1566- const QString& algorithm,
1567- bool allowed3G,
1568- const QVariantMap& metadata,
1569- StringMap headers,
1570- GroupCb cb,
1571- GroupCb errCb) {
1572- Q_Q(Manager);
1573- QDBusPendingCall call =
1574- _dbusInterface->createDownloadGroup(downs,
1575- algorithm, allowed3G, metadata, headers);
1576- auto watcher = new GroupManagerPendingCallWatcher(_conn, _servicePath,
1577- call, cb, errCb, static_cast<QObject*>(q));
1578- q->connect(watcher, SIGNAL(callbackExecuted()),
1579- q, SLOT(onWatcherDone()));
1580- }
1581-
1582- bool isError() {
1583- return _isError;
1584- }
1585-
1586- Error* lastError() {
1587- return _lastError;
1588- }
1589-
1590- void setLastError(const QDBusError& err) {
1591- // delete the last if error if present to keep mem to a minimum
1592- if (_lastError != nullptr) {
1593- delete _lastError;
1594- }
1595- _lastError = new DBusError(err);
1596- _isError = true;
1597- }
1598-
1599- void allowMobileDataDownload(bool allowed) {
1600- QDBusPendingReply<> reply =
1601- _dbusInterface->allowGSMDownload(allowed);
1602- // we block but because we expect it to be fast
1603- reply.waitForFinished();
1604- if (reply.isError()) {
1605- auto err = reply.error();
1606- qCritical() << "Error setting mobile data" << err;
1607- setLastError(err);
1608- }
1609- }
1610-
1611- bool isMobileDataDownload() {
1612- QDBusPendingReply<bool> reply =
1613- _dbusInterface->isGSMDownloadAllowed();
1614- // we block but because we expect it to be fast
1615- reply.waitForFinished();
1616- if (reply.isError()) {
1617- auto err = reply.error();
1618- qCritical() << "Error getting if mobile data is enabled"
1619- << err;
1620- setLastError(err);
1621- return false;
1622- } else {
1623- return reply.value();
1624- }
1625- }
1626-
1627- qulonglong defaultThrottle() {
1628- QDBusPendingReply<qulonglong> reply =
1629- _dbusInterface->defaultThrottle();
1630- // we block but because we expect it to be fast
1631- reply.waitForFinished();
1632- if (reply.isError()) {
1633- auto err = reply.error();
1634- qCritical() << "Error getting the default throttle" << err;
1635- setLastError(err);
1636- return 0;
1637- } else {
1638- return reply.value();
1639- }
1640- }
1641-
1642- void setDefaultThrottle(qulonglong speed) {
1643- QDBusPendingReply<> reply =
1644- _dbusInterface->setDefaultThrottle(speed);
1645- // we block but because we expect it to be fast
1646- reply.waitForFinished();
1647- if (reply.isError()) {
1648- auto err = reply.error();
1649- qCritical() << "Error setting default throttle" << err;
1650- setLastError(err);
1651- }
1652- }
1653-
1654- void exit() {
1655- QDBusPendingReply<> reply =
1656- _dbusInterface->exit();
1657- // we block but because we expect it to be fast
1658- reply.waitForFinished();
1659- if (reply.isError()) {
1660- auto err = reply.error();
1661- qCritical() << "Error setting killing the daemon" << err;
1662- setLastError(err);
1663- }
1664- }
1665-
1666- void onWatcherDone() {
1667- Q_Q(Manager);
1668- auto senderObj = q->sender();
1669- senderObj->deleteLater();
1670- }
1671-
1672- private:
1673- bool _isError = false;
1674- QDBusConnection _conn;
1675- QString _servicePath;
1676- Error* _lastError = nullptr;
1677- ManagerInterface* _dbusInterface = nullptr;
1678- Manager* q_ptr;
1679-};
1680-
1681-/*
1682- * PUBLIC IMPLEMENTATION
1683- */
1684-
1685-Manager::Manager(const QDBusConnection& conn,
1686- const QString& path,
1687- QObject* parent)
1688- : QObject(parent),
1689- d_ptr(new ManagerPrivate(conn, path, this)){
1690-}
1691-
1692-Manager::Manager(const QDBusConnection& conn,
1693- const QString& path,
1694- ManagerInterface* interface,
1695- QObject* parent)
1696- : QObject(parent),
1697- d_ptr(new ManagerPrivate(conn, path, interface, this)) {
1698-}
1699-
1700-Manager::~Manager() {
1701- delete d_ptr;
1702-}
1703-
1704-Manager*
1705-Manager::createSessionManager(const QString& path, QObject* parent) {
1706- if (path.isEmpty()) {
1707- return new Manager(QDBusConnection::sessionBus(), DOWNLOAD_SERVICE, parent);
1708- } else {
1709- return new Manager(QDBusConnection::sessionBus(), path, parent);
1710- }
1711-}
1712-
1713-Manager*
1714-Manager::createSystemManager(const QString& path, QObject* parent) {
1715- if (path.isEmpty()) {
1716- return new Manager(QDBusConnection::systemBus(), DOWNLOAD_SERVICE, parent);
1717- } else {
1718- return new Manager(QDBusConnection::systemBus(), path, parent);
1719- }
1720-}
1721-
1722-void
1723-Manager::createDownload(DownloadStruct downStruct) {
1724- Q_D(Manager);
1725- d->createDownload(downStruct);
1726-}
1727-
1728-void
1729-Manager::createDownload(DownloadStruct downStruct,
1730- DownloadCb cb,
1731- DownloadCb errCb) {
1732- Q_D(Manager);
1733- d->createDownload(downStruct, cb, errCb);
1734-}
1735-
1736-void
1737-Manager::createDownload(StructList downs,
1738- const QString &algorithm,
1739- bool allowed3G,
1740- const QVariantMap &metadata,
1741- StringMap headers) {
1742- Q_D(Manager);
1743- d->createDownload(downs, algorithm, allowed3G, metadata, headers);
1744-}
1745-
1746-void
1747-Manager::createDownload(StructList downs,
1748- const QString& algorithm,
1749- bool allowed3G,
1750- const QVariantMap& metadata,
1751- StringMap headers,
1752- GroupCb cb,
1753- GroupCb errCb) {
1754- Q_D(Manager);
1755- d->createDownload(downs, algorithm, allowed3G, metadata, headers, cb,
1756- errCb);
1757-}
1758-
1759-bool
1760-Manager::isError() {
1761- Q_D(Manager);
1762- return d->isError();
1763-}
1764-
1765-Error*
1766-Manager::lastError() {
1767- Q_D(Manager);
1768- return d->lastError();
1769-}
1770-
1771-void
1772-Manager::allowMobileDataDownload(bool allowed) {
1773- Q_D(Manager);
1774- d->allowMobileDataDownload(allowed);
1775-}
1776-
1777-bool
1778-Manager::isMobileDataDownload() {
1779- Q_D(Manager);
1780- return d->isMobileDataDownload();
1781+ }
1782+ _lastError = new DBusError(err);
1783+ _isError = true;
1784+}
1785+
1786+void
1787+ManagerImpl::allowMobileDataDownload(bool allowed) {
1788+ QDBusPendingReply<> reply =
1789+ _dbusInterface->allowGSMDownload(allowed);
1790+ // we block but because we expect it to be fast
1791+ reply.waitForFinished();
1792+ if (reply.isError()) {
1793+ auto err = reply.error();
1794+ qCritical() << "Error setting mobile data" << err;
1795+ setLastError(err);
1796+ }
1797+}
1798+
1799+bool
1800+ManagerImpl::isMobileDataDownload() {
1801+ QDBusPendingReply<bool> reply =
1802+ _dbusInterface->isGSMDownloadAllowed();
1803+ // we block but because we expect it to be fast
1804+ reply.waitForFinished();
1805+ if (reply.isError()) {
1806+ auto err = reply.error();
1807+ qCritical() << "Error getting if mobile data is enabled"
1808+ << err;
1809+ setLastError(err);
1810+ return false;
1811+ } else {
1812+ return reply.value();
1813+ }
1814 }
1815
1816 qulonglong
1817-Manager::defaultThrottle() {
1818- Q_D(Manager);
1819- return d->defaultThrottle();
1820-}
1821-
1822-void
1823-Manager::setDefaultThrottle(qulonglong speed) {
1824- Q_D(Manager);
1825- d->setDefaultThrottle(speed);
1826-}
1827-
1828-void
1829-Manager::exit() {
1830- Q_D(Manager);
1831- d->exit();
1832+ManagerImpl::defaultThrottle() {
1833+ QDBusPendingReply<qulonglong> reply =
1834+ _dbusInterface->defaultThrottle();
1835+ // we block but because we expect it to be fast
1836+ reply.waitForFinished();
1837+ if (reply.isError()) {
1838+ auto err = reply.error();
1839+ qCritical() << "Error getting the default throttle" << err;
1840+ setLastError(err);
1841+ return 0;
1842+ } else {
1843+ return reply.value();
1844+ }
1845+}
1846+
1847+void
1848+ManagerImpl::setDefaultThrottle(qulonglong speed) {
1849+ QDBusPendingReply<> reply =
1850+ _dbusInterface->setDefaultThrottle(speed);
1851+ // we block but because we expect it to be fast
1852+ reply.waitForFinished();
1853+ if (reply.isError()) {
1854+ auto err = reply.error();
1855+ qCritical() << "Error setting default throttle" << err;
1856+ setLastError(err);
1857+ }
1858+}
1859+
1860+void
1861+ManagerImpl::exit() {
1862+ QDBusPendingReply<> reply =
1863+ _dbusInterface->exit();
1864+ // we block but because we expect it to be fast
1865+ reply.waitForFinished();
1866+ if (reply.isError()) {
1867+ auto err = reply.error();
1868+ qCritical() << "Error setting killing the daemon" << err;
1869+ setLastError(err);
1870+ }
1871+}
1872+
1873+void
1874+ManagerImpl::onWatcherDone() {
1875+ auto senderObj = sender();
1876+ senderObj->deleteLater();
1877 }
1878
1879 } // DownloadManager
1880
1881 } // Ubuntu
1882-
1883-#include "moc_manager.cpp"
1884
1885=== renamed file 'ubuntu-download-manager-client/ubuntu/download_manager/manager.h' => 'ubuntu-download-manager-client/ubuntu/download_manager/manager_impl.h'
1886--- ubuntu-download-manager-client/ubuntu/download_manager/manager.h 2014-02-07 10:06:24 +0000
1887+++ ubuntu-download-manager-client/ubuntu/download_manager/manager_impl.h 2014-02-19 18:29:41 +0000
1888@@ -16,16 +16,18 @@
1889 * Boston, MA 02110-1301, USA.
1890 */
1891
1892-#ifndef UBUNTU_DOWNLOADMANAGER_CLIENT_MANAGER_H
1893-#define UBUNTU_DOWNLOADMANAGER_CLIENT_MANAGER_H
1894+#ifndef UBUNTU_DOWNLOADMANAGER_CLIENT_MANAGER_IMPL_H
1895+#define UBUNTU_DOWNLOADMANAGER_CLIENT_MANAGER_IMPL_H
1896
1897-#include <functional>
1898-#include <QList>
1899-#include <QObject>
1900-#include <ubuntu/download_manager/metatypes.h>
1901-#include <ubuntu/download_manager/common.h>
1902-#include <ubuntu/download_manager/download_struct.h>
1903-#include <ubuntu/download_manager/group_download_struct.h>
1904+#include <QDBusConnection>
1905+#include <QDBusObjectPath>
1906+#include <ubuntu/download_manager/system/dbus_connection.h>
1907+#include "download.h"
1908+#include "error.h"
1909+#include "group_download.h"
1910+#include "manager_interface.h"
1911+#include "manager_pendingcall_watcher.h"
1912+#include "manager.h"
1913
1914
1915 class QDBusConnection;
1916@@ -39,20 +41,16 @@
1917 class GroupDownload;
1918 class ManagerInterface;
1919
1920-typedef std::function<void(Download*)> DownloadCb;
1921-typedef std::function<void(GroupDownload*)> GroupCb;
1922-
1923-class ManagerPrivate;
1924-class DOWNLOAD_MANAGER_EXPORT Manager : public QObject {
1925- Q_DECLARE_PRIVATE(Manager)
1926+class ManagerImpl : public Manager {
1927 Q_OBJECT
1928
1929 // allow watchers to emit the signals
1930+ friend class Manager;
1931 friend class DownloadManagerPendingCallWatcher;
1932 friend class GroupManagerPendingCallWatcher;
1933
1934 public:
1935- virtual ~Manager();
1936+ virtual ~ManagerImpl();
1937 virtual void createDownload(DownloadStruct downStruct);
1938 virtual void createDownload(DownloadStruct downStruct,
1939 DownloadCb cb,
1940@@ -70,37 +68,36 @@
1941 GroupCb cb,
1942 GroupCb errCb);
1943
1944- bool isError();
1945- Error* lastError();
1946+ bool isError() const;
1947+ Error* lastError() const;
1948 void allowMobileDataDownload(bool allowed);
1949 bool isMobileDataDownload();
1950 qulonglong defaultThrottle();
1951 void setDefaultThrottle(qulonglong speed);
1952 void exit();
1953
1954- static Manager* createSessionManager(const QString& path = "", QObject* parent=0);
1955- static Manager* createSystemManager(const QString& path = "", QObject* parent=0);
1956-
1957- signals:
1958- void downloadCreated(Download* down);
1959- void groupCreated(GroupDownload* down);
1960-
1961 protected:
1962- Manager(const QDBusConnection& conn,
1963+ ManagerImpl(const QDBusConnection& conn,
1964 const QString& path = "",
1965 QObject* parent= 0);
1966 // used for testing purposes
1967- Manager(const QDBusConnection& conn,
1968+ ManagerImpl(const QDBusConnection& conn,
1969 const QString& path,
1970 ManagerInterface* interface,
1971 QObject* parent);
1972
1973 private:
1974- Q_PRIVATE_SLOT(d_func(), void onWatcherDone())
1975+ void init();
1976+ void onWatcherDone();
1977+ void setLastError(const QDBusError& err);
1978
1979 private:
1980- // use pimpl pattern so that users do not have to be recompiled
1981- ManagerPrivate* d_ptr;
1982+ bool _isError = false;
1983+ QDBusConnection _conn;
1984+ QString _servicePath;
1985+ Error* _lastError = nullptr;
1986+ ManagerInterface* _dbusInterface = nullptr;
1987+
1988 };
1989
1990 } // DownloadManager
1991
1992=== modified file 'ubuntu-download-manager-client/ubuntu/download_manager/manager_pendingcall_watcher.cpp'
1993--- ubuntu-download-manager-client/ubuntu/download_manager/manager_pendingcall_watcher.cpp 2014-02-03 17:48:28 +0000
1994+++ ubuntu-download-manager-client/ubuntu/download_manager/manager_pendingcall_watcher.cpp 2014-02-19 18:29:41 +0000
1995@@ -19,7 +19,7 @@
1996 #include <QDebug>
1997 #include <QDBusPendingReply>
1998 #include <QDBusObjectPath>
1999-#include "download.h"
2000+#include "download_impl.h"
2001 #include "error.h"
2002 #include "group_download.h"
2003 #include "manager.h"
2004@@ -51,13 +51,13 @@
2005 qDebug() << "ERROR" << reply.error() << reply.error().type();
2006 // creater error and deal with it
2007 auto err = new DBusError(reply.error());
2008- auto down = new Download(_conn, err);
2009+ auto down = new DownloadImpl(_conn, err);
2010 _errCb(down);
2011 emit man->downloadCreated(down);
2012 } else {
2013 qDebug() << "Success!";
2014 auto path = reply.value();
2015- auto down = new Download(_conn, _servicePath, path);
2016+ auto down = new DownloadImpl(_conn, _servicePath, path);
2017 emit man->downloadCreated(down);
2018 _cb(down);
2019 }
2020
2021=== modified file 'ubuntu-download-manager-common/ubuntu-download-manager-common.pro'
2022--- ubuntu-download-manager-common/ubuntu-download-manager-common.pro 2014-02-07 10:06:24 +0000
2023+++ ubuntu-download-manager-common/ubuntu-download-manager-common.pro 2014-02-19 18:29:41 +0000
2024@@ -16,7 +16,8 @@
2025 ubuntu/download_manager/system/hash_algorithm.cpp \
2026 ubuntu/download_manager/http_error_struct.cpp \
2027 ubuntu/download_manager/network_error_struct.cpp \
2028- ubuntu/download_manager/process_error_struct.cpp
2029+ ubuntu/download_manager/process_error_struct.cpp \
2030+ ubuntu/download_manager/auth_error_struct.cpp
2031
2032 public_headers = \
2033 ubuntu/download_manager/common.h \
2034@@ -25,7 +26,8 @@
2035 ubuntu/download_manager/group_download_struct.h \
2036 ubuntu/download_manager/http_error_struct.h \
2037 ubuntu/download_manager/network_error_struct.h \
2038- ubuntu/download_manager/process_error_struct.h
2039+ ubuntu/download_manager/process_error_struct.h \
2040+ ubuntu/download_manager/auth_error_struct.h
2041
2042 private_headers = \
2043 ubuntu/download_manager/system/dbus_connection.h \
2044
2045=== added file 'ubuntu-download-manager-common/ubuntu/download_manager/auth_error_struct.cpp'
2046--- ubuntu-download-manager-common/ubuntu/download_manager/auth_error_struct.cpp 1970-01-01 00:00:00 +0000
2047+++ ubuntu-download-manager-common/ubuntu/download_manager/auth_error_struct.cpp 2014-02-19 18:29:41 +0000
2048@@ -0,0 +1,92 @@
2049+/*
2050+ * Copyright 2014 Canonical Ltd.
2051+ *
2052+ * This library is free software; you can redistribute it and/or
2053+ * modify it under the terms of version 3 of the GNU Lesser General Public
2054+ * License as published by the Free Software Foundation.
2055+ *
2056+ * This program is distributed in the hope that it will be useful,
2057+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2058+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2059+ * General Public License for more details.
2060+ *
2061+ * You should have received a copy of the GNU Lesser General Public
2062+ * License along with this library; if not, write to the
2063+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
2064+ * Boston, MA 02110-1301, USA.
2065+ */
2066+
2067+#include <QDBusArgument>
2068+#include "auth_error_struct.h"
2069+
2070+namespace Ubuntu {
2071+
2072+namespace DownloadManager {
2073+
2074+AuthErrorStruct::AuthErrorStruct()
2075+ : _type(),
2076+ _phrase("") {
2077+}
2078+
2079+AuthErrorStruct::AuthErrorStruct(AuthErrorStruct::Type type, QString phrase)
2080+ : _type(type),
2081+ _phrase(phrase) {
2082+}
2083+
2084+AuthErrorStruct::AuthErrorStruct(int type, QString phrase)
2085+ : _type(static_cast<AuthErrorStruct::Type>(type)),
2086+ _phrase(phrase) {
2087+}
2088+
2089+AuthErrorStruct::AuthErrorStruct(const AuthErrorStruct& other)
2090+ : _type(other._type),
2091+ _phrase(other._phrase){
2092+}
2093+
2094+AuthErrorStruct&
2095+AuthErrorStruct::operator=(const AuthErrorStruct& other) {
2096+ _type = other._type;
2097+ _phrase = other._phrase;
2098+
2099+ return *this;
2100+}
2101+
2102+QDBusArgument&
2103+operator<<(QDBusArgument &argument,
2104+ const AuthErrorStruct& error) {
2105+ argument.beginStructure();
2106+ argument << static_cast<int>(error._type);
2107+ argument << error._phrase;
2108+ argument.endStructure();
2109+
2110+ return argument;
2111+}
2112+
2113+const QDBusArgument&
2114+operator>>(const QDBusArgument &argument,
2115+ AuthErrorStruct& error) {
2116+ int tempType;
2117+ argument.beginStructure();
2118+ argument >> tempType;
2119+ argument >> error._phrase;
2120+ argument.endStructure();
2121+
2122+ error._type = static_cast<AuthErrorStruct::Type>(tempType);
2123+
2124+ return argument;
2125+}
2126+
2127+
2128+AuthErrorStruct::Type
2129+AuthErrorStruct::getType() {
2130+ return _type;
2131+}
2132+
2133+QString
2134+AuthErrorStruct::getPhrase() {
2135+ return _phrase;
2136+}
2137+
2138+} // DownloadManager
2139+
2140+} // Ubuntu
2141
2142=== added file 'ubuntu-download-manager-common/ubuntu/download_manager/auth_error_struct.h'
2143--- ubuntu-download-manager-common/ubuntu/download_manager/auth_error_struct.h 1970-01-01 00:00:00 +0000
2144+++ ubuntu-download-manager-common/ubuntu/download_manager/auth_error_struct.h 2014-02-19 18:29:41 +0000
2145@@ -0,0 +1,62 @@
2146+/*
2147+ * Copyright 2014 Canonical Ltd.
2148+ *
2149+ * This library is free software; you can redistribute it and/or
2150+ * modify it under the terms of version 3 of the GNU Lesser General Public
2151+ * License as published by the Free Software Foundation.
2152+ *
2153+ * This program is distributed in the hope that it will be useful,
2154+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2155+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2156+ * General Public License for more details.
2157+ *
2158+ * You should have received a copy of the GNU Lesser General Public
2159+ * License along with this library; if not, write to the
2160+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
2161+ * Boston, MA 02110-1301, USA.
2162+ */
2163+
2164+#ifndef DOWNLOADER_LIB_AUTH_ERROR_STRUCT_H
2165+#define DOWNLOADER_LIB_AUTH_ERROR_STRUCT_H
2166+
2167+#include "common.h"
2168+
2169+class QDBusArgument;
2170+
2171+namespace Ubuntu {
2172+
2173+namespace DownloadManager {
2174+
2175+class AuthErrorStruct {
2176+ Q_PROPERTY(AuthErrorStruct::Type type READ getType)
2177+ Q_PROPERTY(QString phrase READ getPhrase)
2178+ public:
2179+ enum Type {
2180+ Server,
2181+ Proxy
2182+ };
2183+
2184+ AuthErrorStruct();
2185+ AuthErrorStruct(AuthErrorStruct::Type type, QString phrase);
2186+ AuthErrorStruct(int type, QString phrase);
2187+ AuthErrorStruct(const AuthErrorStruct& other);
2188+ AuthErrorStruct& operator=(const AuthErrorStruct& other);
2189+
2190+ friend QDBusArgument &operator<<(QDBusArgument &argument,
2191+ const AuthErrorStruct& error);
2192+ friend const QDBusArgument &operator>>(const QDBusArgument &argument,
2193+ AuthErrorStruct& error);
2194+
2195+ // properties getters
2196+ AuthErrorStruct::Type getType();
2197+ QString getPhrase();
2198+
2199+ private:
2200+ AuthErrorStruct::Type _type;
2201+ QString _phrase;
2202+};
2203+
2204+} // DownloadManager
2205+
2206+} // Ubuntu
2207+#endif // AUTH_ERROR_STRUCT_H
2208
2209=== modified file 'ubuntu-download-manager-common/ubuntu/download_manager/metatypes.h'
2210--- ubuntu-download-manager-common/ubuntu/download_manager/metatypes.h 2014-01-31 15:13:08 +0000
2211+++ ubuntu-download-manager-common/ubuntu/download_manager/metatypes.h 2014-02-19 18:29:41 +0000
2212@@ -21,6 +21,7 @@
2213
2214 #include <QMap>
2215 #include <QList>
2216+#include "auth_error_struct.h"
2217 #include "http_error_struct.h"
2218 #include "network_error_struct.h"
2219 #include "process_error_struct.h"
2220@@ -32,7 +33,7 @@
2221 typedef QMap<QString, QString> StringMap;
2222 typedef QList<GroupDownloadStruct> StructList;
2223
2224-
2225+Q_DECLARE_METATYPE(AuthErrorStruct)
2226 Q_DECLARE_METATYPE(HttpErrorStruct)
2227 Q_DECLARE_METATYPE(NetworkErrorStruct)
2228 Q_DECLARE_METATYPE(ProcessErrorStruct)
2229
2230=== modified file 'ubuntu-download-manager-priv/downloads/download_adaptor.h'
2231--- ubuntu-download-manager-priv/downloads/download_adaptor.h 2014-01-27 16:36:44 +0000
2232+++ ubuntu-download-manager-priv/downloads/download_adaptor.h 2014-02-19 18:29:41 +0000
2233@@ -9,8 +9,8 @@
2234 * before re-generating it.
2235 */
2236
2237-#ifndef DOWNLOAD_ADAPTOR_H_1390825398
2238-#define DOWNLOAD_ADAPTOR_H_1390825398
2239+#ifndef DOWNLOAD_ADAPTOR_H_1392117488
2240+#define DOWNLOAD_ADAPTOR_H_1392117488
2241
2242 #include <QtCore/QObject>
2243 #include <QtDBus/QtDBus>
2244@@ -78,6 +78,10 @@
2245 " <signal name=\"error\">\n"
2246 " <arg direction=\"out\" type=\"s\" name=\"error\"/>\n"
2247 " </signal>\n"
2248+" <signal name=\"authError\">\n"
2249+" <annotation value=\"AuthErrorStruct\" name=\"org.qtproject.QtDBus.QtTypeName.In0\"/>\n"
2250+" <arg direction=\"out\" type=\"(is)\" name=\"error\"/>\n"
2251+" </signal>\n"
2252 " <signal name=\"httpError\">\n"
2253 " <annotation value=\"HttpErrorStruct\" name=\"org.qtproject.QtDBus.QtTypeName.In0\"/>\n"
2254 " <arg direction=\"out\" type=\"(is)\" name=\"error\"/>\n"
2255@@ -117,6 +121,7 @@
2256 qulonglong throttle();
2257 qulonglong totalSize();
2258 Q_SIGNALS: // SIGNALS
2259+ void authError(AuthErrorStruct error);
2260 void canceled(bool success);
2261 void error(const QString &error);
2262 void finished(const QString &path);
2263
2264=== modified file 'ubuntu-download-manager-priv/downloads/file_download.cpp'
2265--- ubuntu-download-manager-priv/downloads/file_download.cpp 2014-02-04 16:23:10 +0000
2266+++ ubuntu-download-manager-priv/downloads/file_download.cpp 2014-02-19 18:29:41 +0000
2267@@ -40,6 +40,9 @@
2268 const QString COMMAND_ERROR = "COMMAND ERROR";
2269 const QString SSL_ERROR = "SSL ERROR";
2270 const QString FILE_SYSTEM_ERROR = "FILE SYSTEM ERROR: %1";
2271+ const QString AUTH_ERROR = "AUTHENTICATION ERROR";
2272+ const QString PROXY_AUTH_ERROR = "PROXY_AUTHENTICATION ERROR";
2273+ const QString UNEXPECTED_ERROR = "UNEXPECTED_ERROR";
2274
2275 }
2276
2277@@ -81,7 +84,7 @@
2278 _hash(hash) {
2279 init();
2280 _algo = HashAlgorithm::getHashAlgo(algo);
2281- // check that the algorithm is correct if the hash is not emtpy
2282+ // check that the algorithm is correct if the hash is not empty
2283 if (!_hash.isEmpty() && !HashAlgorithm::isValidAlgo(algo)) {
2284 setIsValid(false);
2285 setLastError(QString("Invalid hash algorithm: '%1'").arg(algo));
2286@@ -190,7 +193,7 @@
2287 return;
2288 }
2289
2290- // create file that will be used to mantain the state of the
2291+ // create file that will be used to maintain the state of the
2292 // download when resumed.
2293 _currentData = FileManager::instance()->createFile(_filePath);
2294 bool canWrite = _currentData->open(QIODevice::ReadWrite | QFile::Append);
2295@@ -265,6 +268,7 @@
2296 LOG(ERROR) << _url << " ERROR:" << ":" << code;
2297 _downloading = false;
2298 QString msg;
2299+ QString errStr;
2300
2301 // decide if we are talking about an http error or no
2302 auto statusCode = _reply->attribute(
2303@@ -281,13 +285,23 @@
2304 }
2305 HttpErrorStruct err(status, msg);
2306 emit httpError(err);
2307+ errStr = NETWORK_ERROR;
2308 }
2309 } else {
2310- NetworkErrorStruct err(code);
2311- emit networkError(err);
2312+ if (code == QNetworkReply::AuthenticationRequiredError) {
2313+ AuthErrorStruct err(AuthErrorStruct::Server, _reply->errorString());
2314+ emit authError(err);
2315+ errStr = AUTH_ERROR;
2316+ } else if (code == QNetworkReply::ProxyAuthenticationRequiredError) {
2317+ AuthErrorStruct err(AuthErrorStruct::Proxy, _reply->errorString());
2318+ emit authError(err);
2319+ errStr = PROXY_AUTH_ERROR;
2320+ } else {
2321+ NetworkErrorStruct err(code, _reply->errorString());
2322+ emit networkError(err);
2323+ }
2324 }
2325-
2326- emitError(NETWORK_ERROR);
2327+ emitError(errStr);
2328 }
2329
2330 void
2331@@ -351,7 +365,7 @@
2332 // there are two possible cases, the first, we do not have the metadata
2333 // info to execute a command once the download was finished and that
2334 // means we are done here else we execute the command AND raise the
2335- // finish signals once the command was done (or an error ocurred in
2336+ // finish signals once the command was done (or an error occurred in
2337 // the command execution.
2338 if (metadata().contains(METADATA_COMMAND_KEY)) {
2339 // just emit processing if we DO NOT have a hash because else we
2340@@ -367,7 +381,7 @@
2341 emitError(COMMAND_ERROR);
2342 return;
2343 } else {
2344- // first item of the string list is the commnad
2345+ // first item of the string list is the command
2346 // the rest is the arguments
2347 QString command = commandData.at(0);
2348 commandData.removeAt(0);
2349
2350=== modified file 'ubuntu-download-manager-priv/downloads/file_download.h'
2351--- ubuntu-download-manager-priv/downloads/file_download.h 2014-02-07 10:06:24 +0000
2352+++ ubuntu-download-manager-priv/downloads/file_download.h 2014-02-19 18:29:41 +0000
2353@@ -24,6 +24,7 @@
2354 #include <QProcess>
2355 #include <QSharedPointer>
2356 #include <QUrl>
2357+#include <ubuntu/download_manager/auth_error_struct.h>
2358 #include <ubuntu/download_manager/http_error_struct.h>
2359 #include <ubuntu/download_manager/network_error_struct.h>
2360 #include <ubuntu/download_manager/process_error_struct.h>
2361@@ -92,6 +93,7 @@
2362
2363 signals:
2364 void finished(const QString& path);
2365+ void authError(AuthErrorStruct error);
2366 void httpError(HttpErrorStruct error);
2367 void networkError(NetworkErrorStruct error);
2368 void processError(ProcessErrorStruct error);
2369
2370=== modified file 'ubuntu-download-manager-priv/downloads/group_download.cpp'
2371--- ubuntu-download-manager-priv/downloads/group_download.cpp 2014-01-28 16:03:24 +0000
2372+++ ubuntu-download-manager-priv/downloads/group_download.cpp 2014-02-19 18:29:41 +0000
2373@@ -55,8 +55,6 @@
2374
2375 void
2376 GroupDownload::connectToDownloadSignals(FileDownload* singleDownload) {
2377- connect(singleDownload, &Download::error,
2378- this, &GroupDownload::onError);
2379 connect(singleDownload, static_cast<void(Download::*)
2380 (qulonglong, qulonglong)>(&Download::progress),
2381 this, &GroupDownload::onProgress);
2382@@ -64,6 +62,18 @@
2383 this, &GroupDownload::onFinished);
2384 connect(singleDownload, &FileDownload::processing,
2385 this, &GroupDownload::processing);
2386+
2387+ // connect to the error signals
2388+ connect(singleDownload, &Download::error,
2389+ this, &GroupDownload::onError);
2390+ connect(singleDownload, &FileDownload::authError,
2391+ this, &GroupDownload::onAuthError);
2392+ connect(singleDownload, &FileDownload::httpError,
2393+ this, &GroupDownload::onHttpError);
2394+ connect(singleDownload, &FileDownload::networkError,
2395+ this, &GroupDownload::onNetworkError);
2396+ connect(singleDownload, &FileDownload::processError,
2397+ this, &GroupDownload::onProcessError);
2398 }
2399
2400 void
2401@@ -246,6 +256,48 @@
2402 emitError(errorMsg);
2403 }
2404
2405+QString
2406+GroupDownload::getUrlFromSender(QObject* sender) {
2407+ auto down = qobject_cast<FileDownload*>(sender);
2408+ if (down != nullptr) {
2409+ return down->url().toString();
2410+ } else {
2411+ return "";
2412+ }
2413+}
2414+
2415+void
2416+GroupDownload::onAuthError(AuthErrorStruct err) {
2417+ auto url = getUrlFromSender(sender());
2418+ if (!url.isEmpty()) {
2419+ emit authError(url, err);
2420+ }
2421+}
2422+
2423+void
2424+GroupDownload::onHttpError(HttpErrorStruct err) {
2425+ auto url = getUrlFromSender(sender());
2426+ if (!url.isEmpty()) {
2427+ emit httpError(url, err);
2428+ }
2429+}
2430+
2431+void
2432+GroupDownload::onNetworkError(NetworkErrorStruct err) {
2433+ auto url = getUrlFromSender(sender());
2434+ if (!url.isEmpty()) {
2435+ emit networkError(url, err);
2436+ }
2437+}
2438+
2439+void
2440+GroupDownload::onProcessError(ProcessErrorStruct err) {
2441+ auto url = getUrlFromSender(sender());
2442+ if (!url.isEmpty()) {
2443+ emit processError(url, err);
2444+ }
2445+}
2446+
2447 void
2448 GroupDownload::onProgress(qulonglong received, qulonglong total) {
2449 FileDownload* down = qobject_cast<FileDownload*>(sender());
2450
2451=== modified file 'ubuntu-download-manager-priv/downloads/group_download.h'
2452--- ubuntu-download-manager-priv/downloads/group_download.h 2014-02-01 09:01:47 +0000
2453+++ ubuntu-download-manager-priv/downloads/group_download.h 2014-02-19 18:29:41 +0000
2454@@ -65,6 +65,10 @@
2455
2456 signals:
2457 void finished(const QStringList &path);
2458+ void authError(const QString &url, AuthErrorStruct error);
2459+ void httpError(const QString &url, HttpErrorStruct error);
2460+ void networkError(const QString &url, NetworkErrorStruct error);
2461+ void processError(const QString &url, ProcessErrorStruct error);
2462
2463 private:
2464 void cancelAllDownloads();
2465@@ -72,12 +76,19 @@
2466 void init(QList<GroupDownloadStruct> downloads,
2467 const QString& algo,
2468 bool isGSMDownloadAllowed);
2469- void onError(const QString& error);
2470+ QString getUrlFromSender(QObject* sender);
2471 void onProgress(qulonglong received, qulonglong total);
2472 void onFinished(const QString& file);
2473+ void onError(const QString& error);
2474+ void onAuthError(AuthErrorStruct err);
2475+ void onHttpError(HttpErrorStruct err);
2476+ void onNetworkError(NetworkErrorStruct err);
2477+ void onProcessError(ProcessErrorStruct err);
2478
2479- private:
2480+ protected:
2481 QList<FileDownload*> _downloads;
2482+
2483+ private:
2484 QStringList _finishedDownloads;
2485 QMap<QUrl, QPair<qulonglong, qulonglong> > _downloadsProgress;
2486 Factory* _downFactory = nullptr;
2487
2488=== modified file 'ubuntu-download-manager-priv/downloads/group_download_adaptor.cpp'
2489--- ubuntu-download-manager-priv/downloads/group_download_adaptor.cpp 2013-12-11 13:55:36 +0000
2490+++ ubuntu-download-manager-priv/downloads/group_download_adaptor.cpp 2014-02-19 18:29:41 +0000
2491@@ -42,19 +42,19 @@
2492
2493 void GroupDownloadAdaptor::allowGSMDownload(bool allowed)
2494 {
2495- // handle method call com.canonical.applications.Download.allowGSMDownload
2496+ // handle method call com.canonical.applications.GroupDownload.allowGSMDownload
2497 QMetaObject::invokeMethod(parent(), "allowGSMDownload", Q_ARG(bool, allowed));
2498 }
2499
2500 void GroupDownloadAdaptor::cancel()
2501 {
2502- // handle method call com.canonical.applications.Download.cancel
2503+ // handle method call com.canonical.applications.GroupDownload.cancel
2504 QMetaObject::invokeMethod(parent(), "cancel");
2505 }
2506
2507 bool GroupDownloadAdaptor::isGSMDownloadAllowed()
2508 {
2509- // handle method call com.canonical.applications.Download.isGSMDownloadAllowed
2510+ // handle method call com.canonical.applications.GroupDownload.isGSMDownloadAllowed
2511 bool allowed;
2512 QMetaObject::invokeMethod(parent(), "isGSMDownloadAllowed", Q_RETURN_ARG(bool, allowed));
2513 return allowed;
2514@@ -62,7 +62,7 @@
2515
2516 QVariantMap GroupDownloadAdaptor::metadata()
2517 {
2518- // handle method call com.canonical.applications.Download.metadata
2519+ // handle method call com.canonical.applications.GroupDownload.metadata
2520 QVariantMap data;
2521 QMetaObject::invokeMethod(parent(), "metadata", Q_RETURN_ARG(QVariantMap, data));
2522 return data;
2523@@ -70,37 +70,37 @@
2524
2525 void GroupDownloadAdaptor::pause()
2526 {
2527- // handle method call com.canonical.applications.Download.pause
2528+ // handle method call com.canonical.applications.GroupDownload.pause
2529 QMetaObject::invokeMethod(parent(), "pause");
2530 }
2531
2532 qulonglong GroupDownloadAdaptor::progress(qulonglong &started, qulonglong &paused, qulonglong &finished)
2533 {
2534- // handle method call com.canonical.applications.Download.progress
2535+ // handle method call com.canonical.applications.GroupDownload.progress
2536 return static_cast<GroupDownload*>(parent())->progress(started, paused, finished);
2537 }
2538
2539 void GroupDownloadAdaptor::resume()
2540 {
2541- // handle method call com.canonical.applications.Download.resume
2542+ // handle method call com.canonical.applications.GroupDownload.resume
2543 QMetaObject::invokeMethod(parent(), "resume");
2544 }
2545
2546 void GroupDownloadAdaptor::setThrottle(qulonglong speed)
2547 {
2548- // handle method call com.canonical.applications.Download.setThrottle
2549+ // handle method call com.canonical.applications.GroupDownload.setThrottle
2550 QMetaObject::invokeMethod(parent(), "setThrottle", Q_ARG(qulonglong, speed));
2551 }
2552
2553 void GroupDownloadAdaptor::start()
2554 {
2555- // handle method call com.canonical.applications.Download.start
2556+ // handle method call com.canonical.applications.GroupDownload.start
2557 QMetaObject::invokeMethod(parent(), "start");
2558 }
2559
2560 qulonglong GroupDownloadAdaptor::throttle()
2561 {
2562- // handle method call com.canonical.applications.Download.throttle
2563+ // handle method call com.canonical.applications.GroupDownload.throttle
2564 qulonglong speed;
2565 QMetaObject::invokeMethod(parent(), "throttle", Q_RETURN_ARG(qulonglong, speed));
2566 return speed;
2567@@ -108,7 +108,7 @@
2568
2569 qulonglong GroupDownloadAdaptor::totalSize()
2570 {
2571- // handle method call com.canonical.applications.Download.totalSize
2572+ // handle method call com.canonical.applications.GroupDownload.totalSize
2573 qulonglong total;
2574 QMetaObject::invokeMethod(parent(), "totalSize", Q_RETURN_ARG(qulonglong, total));
2575 return total;
2576
2577=== modified file 'ubuntu-download-manager-priv/downloads/group_download_adaptor.h'
2578--- ubuntu-download-manager-priv/downloads/group_download_adaptor.h 2013-12-11 13:55:36 +0000
2579+++ ubuntu-download-manager-priv/downloads/group_download_adaptor.h 2014-02-19 18:29:41 +0000
2580@@ -9,8 +9,8 @@
2581 * before re-generating it.
2582 */
2583
2584-#ifndef GROUP_DOWNLOAD_ADAPTOR_H_1377511556
2585-#define GROUP_DOWNLOAD_ADAPTOR_H_1377511556
2586+#ifndef GROUP_DOWNLOAD_ADAPTOR_H_1392149243
2587+#define GROUP_DOWNLOAD_ADAPTOR_H_1392149243
2588
2589 #include <QtCore/QObject>
2590 #include <QtDBus/QtDBus>
2591@@ -31,7 +31,7 @@
2592 namespace Daemon {
2593
2594 /*
2595- * Adaptor class for interface com.canonical.applications.Download
2596+ * Adaptor class for interface com.canonical.applications.GroupDownload
2597 */
2598 class GroupDownloadAdaptor: public QDBusAbstractAdaptor
2599 {
2600@@ -86,6 +86,26 @@
2601 " <signal name=\"error\">\n"
2602 " <arg direction=\"out\" type=\"s\" name=\"error\"/>\n"
2603 " </signal>\n"
2604+" <signal name=\"authError\">\n"
2605+" <annotation value=\"AuthErrorStruct\" name=\"org.qtproject.QtDBus.QtTypeName.In1\"/>\n"
2606+" <arg direction=\"out\" type=\"s\" name=\"url\"/>\n"
2607+" <arg direction=\"out\" type=\"(is)\" name=\"error\"/>\n"
2608+" </signal>\n"
2609+" <signal name=\"httpError\">\n"
2610+" <annotation value=\"HttpErrorStruct\" name=\"org.qtproject.QtDBus.QtTypeName.In1\"/>\n"
2611+" <arg direction=\"out\" type=\"s\" name=\"url\"/>\n"
2612+" <arg direction=\"out\" type=\"(is)\" name=\"error\"/>\n"
2613+" </signal>\n"
2614+" <signal name=\"networkError\">\n"
2615+" <annotation value=\"NetworkErrorStruct\" name=\"org.qtproject.QtDBus.QtTypeName.In1\"/>\n"
2616+" <arg direction=\"out\" type=\"s\" name=\"url\"/>\n"
2617+" <arg direction=\"out\" type=\"(is)\" name=\"error\"/>\n"
2618+" </signal>\n"
2619+" <signal name=\"processError\">\n"
2620+" <annotation value=\"ProcessErrorStruct\" name=\"org.qtproject.QtDBus.QtTypeName.In1\"/>\n"
2621+" <arg direction=\"out\" type=\"s\" name=\"url\"/>\n"
2622+" <arg direction=\"out\" type=\"(isiss)\" name=\"error\"/>\n"
2623+" </signal>\n"
2624 " <signal name=\"progress\">\n"
2625 " <arg direction=\"out\" type=\"t\" name=\"received\"/>\n"
2626 " <arg direction=\"out\" type=\"t\" name=\"total\"/>\n"
2627@@ -113,10 +133,14 @@
2628 qulonglong throttle();
2629 qulonglong totalSize();
2630 Q_SIGNALS: // SIGNALS
2631+ void authError(const QString &url, AuthErrorStruct error);
2632 void canceled(bool success);
2633 void error(const QString &error);
2634 void finished(const QStringList &path);
2635+ void httpError(const QString &url, HttpErrorStruct error);
2636+ void networkError(const QString &url, NetworkErrorStruct error);
2637 void paused(bool success);
2638+ void processError(const QString &url, ProcessErrorStruct error);
2639 void processing(const QString &path);
2640 void progress(qulonglong received, qulonglong total);
2641 void resumed(bool success);
2642
2643=== modified file 'ubuntu-download-manager-priv/downloads/manager.cpp'
2644--- ubuntu-download-manager-priv/downloads/manager.cpp 2014-02-10 09:51:58 +0000
2645+++ ubuntu-download-manager-priv/downloads/manager.cpp 2014-02-19 18:29:41 +0000
2646@@ -76,6 +76,7 @@
2647 qDBusRegisterMetaType<DownloadStruct>();
2648 qDBusRegisterMetaType<GroupDownloadStruct>();
2649 qDBusRegisterMetaType<StructList>();
2650+ qDBusRegisterMetaType<AuthErrorStruct>();
2651 qDBusRegisterMetaType<HttpErrorStruct>();
2652 qDBusRegisterMetaType<NetworkErrorStruct>();
2653 qDBusRegisterMetaType<ProcessErrorStruct>();
2654
2655=== modified file 'ubuntu-download-manager-priv/system/network_reply.cpp'
2656--- ubuntu-download-manager-priv/system/network_reply.cpp 2014-02-03 13:34:10 +0000
2657+++ ubuntu-download-manager-priv/system/network_reply.cpp 2014-02-19 18:29:41 +0000
2658@@ -28,7 +28,7 @@
2659 NetworkReply::NetworkReply(QNetworkReply* reply, QObject* parent)
2660 : QObject(parent),
2661 _reply(reply) {
2662- // connect to all the signals so that we foward them
2663+ // connect to all the signals so that we forward them
2664 if (_reply != nullptr) {
2665 connect(_reply, &QNetworkReply::downloadProgress,
2666 this, &NetworkReply::downloadProgress);
2667@@ -36,7 +36,7 @@
2668 this, &NetworkReply::finished);
2669 connect(_reply, &QNetworkReply::sslErrors,
2670 this, &NetworkReply::sslErrors);
2671- // becuase error is overloaded we need to help the compiler
2672+ // because error is overloaded we need to help the compiler
2673 connect(_reply, static_cast<void(QNetworkReply::*)
2674 (QNetworkReply::NetworkError)>(&QNetworkReply::error),
2675 this, &NetworkReply::error);
2676@@ -106,6 +106,11 @@
2677 return _reply->attribute(code);
2678 }
2679
2680+QString
2681+NetworkReply::errorString() const {
2682+ return _reply->errorString();
2683+}
2684+
2685 } // System
2686
2687 } // DownloadManager
2688
2689=== modified file 'ubuntu-download-manager-priv/system/network_reply.h'
2690--- ubuntu-download-manager-priv/system/network_reply.h 2014-01-27 16:36:44 +0000
2691+++ ubuntu-download-manager-priv/system/network_reply.h 2014-02-19 18:29:41 +0000
2692@@ -44,9 +44,10 @@
2693 virtual void setAcceptedCertificates(const QList<QSslCertificate>& certs);
2694 virtual bool canIgnoreSslErrors(const QList<QSslError>& errors);
2695 virtual QVariant attribute(QNetworkRequest::Attribute code) const;
2696+ virtual QString errorString() const;
2697
2698 signals:
2699- // signals fowarded from the real reply object
2700+ // signals forwarded from the real reply object
2701 void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
2702 void error(QNetworkReply::NetworkError code);
2703 void finished();
2704
2705=== modified file 'ubuntu-download-manager-test-lib/ubuntu-download-manager-test-lib.pro'
2706--- ubuntu-download-manager-test-lib/ubuntu-download-manager-test-lib.pro 2014-02-03 17:50:07 +0000
2707+++ ubuntu-download-manager-test-lib/ubuntu-download-manager-test-lib.pro 2014-02-19 18:29:41 +0000
2708@@ -34,7 +34,8 @@
2709 ubuntu/download_manager/tests/client/testing_manager_adaptor.cpp \
2710 ubuntu/download_manager/tests/client/testing_interface.cpp \
2711 ubuntu/download_manager/tests/client/testing_file_download.cpp \
2712- ubuntu/download_manager/tests/server/apn_request_factory.cpp
2713+ ubuntu/download_manager/tests/server/apn_request_factory.cpp \
2714+ ubuntu/download_manager/tests/server/group_download.cpp
2715
2716 HEADERS += ubuntu/download_manager/tests/base_testcase.h \
2717 ubuntu/download_manager/tests/fake.h\
2718@@ -62,7 +63,8 @@
2719 ubuntu/download_manager/tests/client/testing_manager_adaptor.h \
2720 ubuntu/download_manager/tests/client/testing_interface.h \
2721 ubuntu/download_manager/tests/client/testing_file_download.h \
2722- ubuntu/download_manager/tests/server/apn_request_factory.h
2723+ ubuntu/download_manager/tests/server/apn_request_factory.h \
2724+ ubuntu/download_manager/tests/server/group_download.h
2725
2726 LIBS += -L$$OUT_PWD/../ubuntu-download-manager-common/ -lubuntu-download-manager-common
2727
2728
2729=== modified file 'ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/daemon_testcase.cpp'
2730--- ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/daemon_testcase.cpp 2014-02-04 16:08:36 +0000
2731+++ ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/daemon_testcase.cpp 2014-02-19 18:29:41 +0000
2732@@ -89,6 +89,27 @@
2733 }
2734
2735 void
2736+DaemonTestCase::returnAuthError(const QString &download, AuthErrorStruct error) {
2737+ if (_daemonProcess != nullptr) {
2738+ auto conn = QDBusConnection::sessionBus();
2739+ QScopedPointer<TestingInterface> testingInterface(new TestingInterface(
2740+ _daemonPath, "/", conn));
2741+ QDBusPendingReply<> reply =
2742+ testingInterface->returnAuthError(download, error);
2743+ reply.waitForFinished();
2744+
2745+ if (reply.isError()) {
2746+ auto error = reply.error();
2747+ QString msg = "Could not tell the daemon to return Auth errors: "
2748+ + error.name() + ":" + error.message();
2749+ QFAIL(msg.toUtf8());
2750+ }
2751+ } else {
2752+ QFAIL("returnHttpError must be used after init has been executed.");
2753+ }
2754+}
2755+
2756+void
2757 DaemonTestCase::returnHttpError(const QString &download, HttpErrorStruct error) {
2758 if (_daemonProcess != nullptr) {
2759 auto conn = QDBusConnection::sessionBus();
2760
2761=== modified file 'ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/daemon_testcase.h'
2762--- ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/daemon_testcase.h 2014-02-04 16:08:36 +0000
2763+++ ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/daemon_testcase.h 2014-02-19 18:29:41 +0000
2764@@ -43,6 +43,7 @@
2765 QUrl serverUrl();
2766 void addFileToHttpServer(const QString& absolutePath);
2767 void returnDBusErrors(bool errors);
2768+ void returnAuthError(const QString &download, AuthErrorStruct error);
2769 void returnHttpError(const QString &download, HttpErrorStruct error);
2770 void returnNetworkError(const QString &download, NetworkErrorStruct error);
2771 void returnProcessError(const QString &download, ProcessErrorStruct error);
2772
2773=== modified file 'ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_daemon.cpp'
2774--- ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_daemon.cpp 2014-02-03 17:48:28 +0000
2775+++ ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_daemon.cpp 2014-02-19 18:29:41 +0000
2776@@ -40,6 +40,13 @@
2777 }
2778
2779 void
2780+TestingDaemon::returnAuthError(const QString &download,
2781+ AuthErrorStruct error) {
2782+ auto man = qobject_cast<TestingManager*>(manager());
2783+ man->returnAuthError(download, error);
2784+}
2785+
2786+void
2787 TestingDaemon::returnHttpError(const QString &download,
2788 HttpErrorStruct error) {
2789 auto man = qobject_cast<TestingManager*>(manager());
2790
2791=== modified file 'ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_daemon.h'
2792--- ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_daemon.h 2014-02-03 17:52:16 +0000
2793+++ ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_daemon.h 2014-02-19 18:29:41 +0000
2794@@ -32,6 +32,7 @@
2795
2796 // let the client test to tell the manager to return dbus errors
2797 void returnDBusErrors(bool errors);
2798+ void returnAuthError(const QString &download, AuthErrorStruct error);
2799 void returnHttpError(const QString &download, HttpErrorStruct error);
2800 void returnNetworkError(const QString &download, NetworkErrorStruct error);
2801 void returnProcessError(const QString &download, ProcessErrorStruct error);
2802
2803=== modified file 'ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_file_download.cpp'
2804--- ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_file_download.cpp 2014-02-04 16:08:36 +0000
2805+++ ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_file_download.cpp 2014-02-19 18:29:41 +0000
2806@@ -62,6 +62,7 @@
2807
2808 void
2809 TestingFileDownload::returnHttpError(HttpErrorStruct error) {
2810+ _returnAuthError = false;
2811 _returnHttpError = true;
2812 _returnNetworkError = false;
2813 _returnProcessError = false;
2814@@ -70,6 +71,7 @@
2815
2816 void
2817 TestingFileDownload::returnNetworkError(NetworkErrorStruct error) {
2818+ _returnAuthError = false;
2819 _returnHttpError = false;
2820 _returnNetworkError = true;
2821 _returnProcessError = false;
2822@@ -78,10 +80,20 @@
2823
2824 void
2825 TestingFileDownload::returnProcessError(ProcessErrorStruct error) {
2826- _returnHttpError = false;
2827- _returnNetworkError = false;
2828- _returnProcessError = true;
2829- _processErr = error;
2830+ _returnAuthError = false;
2831+ _returnHttpError = false;
2832+ _returnNetworkError = false;
2833+ _returnProcessError = true;
2834+ _processErr = error;
2835+}
2836+
2837+void
2838+TestingFileDownload::returnAuthError(AuthErrorStruct error) {
2839+ _returnAuthError = true;
2840+ _returnHttpError = false;
2841+ _returnNetworkError = false;
2842+ _returnProcessError = false;
2843+ _authErr = error;
2844 }
2845
2846 qulonglong
2847@@ -186,6 +198,11 @@
2848
2849 _down->start();
2850
2851+ if (_returnAuthError) {
2852+ emit authError(_authErr);
2853+ emitError("Forced http error");
2854+ }
2855+
2856 if (_returnHttpError) {
2857 emit httpError(_httpErr);
2858 emitError("Forced http error");
2859
2860=== modified file 'ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_file_download.h'
2861--- ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_file_download.h 2014-02-04 16:08:36 +0000
2862+++ ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_file_download.h 2014-02-19 18:29:41 +0000
2863@@ -37,6 +37,7 @@
2864 void returnHttpError(HttpErrorStruct error);
2865 void returnNetworkError(NetworkErrorStruct error);
2866 void returnProcessError(ProcessErrorStruct error);
2867+ void returnAuthError(AuthErrorStruct error);
2868
2869 public slots: // NOLINT(whitespace/indent)
2870 qulonglong progress() override;
2871@@ -64,9 +65,11 @@
2872
2873 private:
2874 bool _returnErrors = false;
2875+ bool _returnAuthError = false;
2876 bool _returnHttpError = false;
2877 bool _returnNetworkError = false;
2878 bool _returnProcessError = false;
2879+ AuthErrorStruct _authErr;
2880 HttpErrorStruct _httpErr;
2881 NetworkErrorStruct _networkErr;
2882 ProcessErrorStruct _processErr;
2883
2884=== modified file 'ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_interface.h'
2885--- ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_interface.h 2014-02-03 17:48:28 +0000
2886+++ ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_interface.h 2014-02-19 18:29:41 +0000
2887@@ -8,8 +8,8 @@
2888 * Do not edit! All changes made to it will be lost.
2889 */
2890
2891-#ifndef TESTING_INTERFACE_H_1391440734
2892-#define TESTING_INTERFACE_H_1391440734
2893+#ifndef TESTING_INTERFACE_H_1392137146
2894+#define TESTING_INTERFACE_H_1392137146
2895
2896 #include <QtCore/QObject>
2897 #include <QtCore/QByteArray>
2898@@ -37,6 +37,13 @@
2899 ~TestingInterface();
2900
2901 public Q_SLOTS: // METHODS
2902+ inline QDBusPendingReply<> returnAuthError(const QString &download, AuthErrorStruct error)
2903+ {
2904+ QList<QVariant> argumentList;
2905+ argumentList << QVariant::fromValue(download) << QVariant::fromValue(error);
2906+ return asyncCallWithArgumentList(QLatin1String("returnAuthError"), argumentList);
2907+ }
2908+
2909 inline QDBusPendingReply<> returnDBusErrors(bool returnErrors)
2910 {
2911 QList<QVariant> argumentList;
2912
2913=== modified file 'ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_manager.cpp'
2914--- ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_manager.cpp 2014-02-04 16:08:36 +0000
2915+++ ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_manager.cpp 2014-02-19 18:29:41 +0000
2916@@ -74,6 +74,18 @@
2917 }
2918 }
2919
2920+void
2921+TestingManager::returnAuthError(const QString &download,
2922+ AuthErrorStruct error) {
2923+ auto q = queue();
2924+ foreach(Download* down, q->downloads().values()) {
2925+ auto testDown = qobject_cast<TestingFileDownload*>(down);
2926+ if (testDown != nullptr && testDown->url() == download) {
2927+ testDown->returnAuthError(error);
2928+ }
2929+ }
2930+}
2931+
2932 QDBusObjectPath
2933 TestingManager::registerDownload(Download* download) {
2934 QDBusObjectPath path;
2935
2936=== modified file 'ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_manager.h'
2937--- ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_manager.h 2014-02-03 17:48:28 +0000
2938+++ ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_manager.h 2014-02-19 18:29:41 +0000
2939@@ -58,6 +58,7 @@
2940 void returnHttpError(const QString &download, HttpErrorStruct error);
2941 void returnNetworkError(const QString &download, NetworkErrorStruct error);
2942 void returnProcessError(const QString &download, ProcessErrorStruct error);
2943+ void returnAuthError(const QString &download, AuthErrorStruct error);
2944
2945 protected:
2946 QDBusObjectPath registerDownload(Download* download) override;
2947
2948=== modified file 'ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_manager_adaptor.cpp'
2949--- ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_manager_adaptor.cpp 2014-02-05 11:01:12 +0000
2950+++ ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_manager_adaptor.cpp 2014-02-19 18:29:41 +0000
2951@@ -33,6 +33,12 @@
2952 // destructor
2953 }
2954
2955+void TestingManagerAdaptor::returnAuthError(const QString &download, AuthErrorStruct error)
2956+{
2957+ // handle method call com.canonical.applications.testing.DownloadManager.returnAuthError
2958+ QMetaObject::invokeMethod(parent(), "returnAuthError", Q_ARG(QString, download), Q_ARG(AuthErrorStruct, error));
2959+}
2960+
2961 void TestingManagerAdaptor::returnDBusErrors(bool returnErrors)
2962 {
2963 // handle method call com.canonical.applications.testing.DownloadManager.returnDBusErrors
2964
2965=== modified file 'ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_manager_adaptor.h'
2966--- ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_manager_adaptor.h 2014-02-05 11:01:12 +0000
2967+++ ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/client/testing_manager_adaptor.h 2014-02-19 18:29:41 +0000
2968@@ -9,8 +9,8 @@
2969 * before re-generating it.
2970 */
2971
2972-#ifndef TESTING_MANAGER_ADAPTOR_H_1391594312
2973-#define TESTING_MANAGER_ADAPTOR_H_1391594312
2974+#ifndef TESTING_MANAGER_ADAPTOR_H_1392305003
2975+#define TESTING_MANAGER_ADAPTOR_H_1392305003
2976
2977 #include <QtCore/QObject>
2978 #include <QtDBus/QtDBus>
2979@@ -52,6 +52,11 @@
2980 " <arg direction=\"in\" type=\"s\" name=\"download\"/>\n"
2981 " <arg direction=\"in\" type=\"(isiss)\" name=\"error\"/>\n"
2982 " </method>\n"
2983+" <method name=\"returnAuthError\">\n"
2984+" <annotation value=\"AuthErrorStruct\" name=\"org.qtproject.QtDBus.QtTypeName.In1\"/>\n"
2985+" <arg direction=\"in\" type=\"s\" name=\"download\"/>\n"
2986+" <arg direction=\"in\" type=\"(is)\" name=\"error\"/>\n"
2987+" </method>\n"
2988 " </interface>\n"
2989 "")
2990 public:
2991@@ -60,6 +65,7 @@
2992
2993 public: // PROPERTIES
2994 public Q_SLOTS: // METHODS
2995+ void returnAuthError(const QString &download, AuthErrorStruct error);
2996 void returnDBusErrors(bool returnErrors);
2997 void returnHttpError(const QString &download, HttpErrorStruct error);
2998 void returnNetworkError(const QString &download, NetworkErrorStruct error);
2999
3000=== modified file 'ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/download.cpp'
3001--- ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/download.cpp 2014-01-24 11:54:24 +0000
3002+++ ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/download.cpp 2014-02-19 18:29:41 +0000
3003@@ -135,3 +135,24 @@
3004 setState(Download::ERROR);
3005 emit error(errorMsg);
3006 }
3007+
3008+void
3009+FakeDownload::emitAuthError(AuthErrorStruct error) {
3010+ emit authError(error);
3011+}
3012+
3013+void
3014+FakeDownload::emitHttpError(HttpErrorStruct error) {
3015+ emit httpError(error);
3016+}
3017+
3018+void
3019+FakeDownload::emitNetworkError(NetworkErrorStruct error) {
3020+ emit networkError(error);
3021+}
3022+
3023+void
3024+FakeDownload::emitProcessError(ProcessErrorStruct error) {
3025+ emit processError(error);
3026+}
3027+
3028
3029=== modified file 'ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/download.h'
3030--- ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/download.h 2014-01-28 18:51:12 +0000
3031+++ ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/download.h 2014-02-19 18:29:41 +0000
3032@@ -62,6 +62,10 @@
3033 // useful methods to emit signals
3034 void emitFinished(const QString& path);
3035 void emitError(const QString& error);
3036+ void emitAuthError(AuthErrorStruct error);
3037+ void emitHttpError(HttpErrorStruct error);
3038+ void emitNetworkError(NetworkErrorStruct error);
3039+ void emitProcessError(ProcessErrorStruct error);
3040
3041 using Download::setAddToQueue;
3042
3043
3044=== added file 'ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/group_download.cpp'
3045--- ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/group_download.cpp 1970-01-01 00:00:00 +0000
3046+++ ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/group_download.cpp 2014-02-19 18:29:41 +0000
3047@@ -0,0 +1,81 @@
3048+/*
3049+ * Copyright 2014 Canonical Ltd.
3050+ *
3051+ * This library is free software; you can redistribute it and/or
3052+ * modify it under the terms of version 3 of the GNU Lesser General Public
3053+ * License as published by the Free Software Foundation.
3054+ *
3055+ * This program is distributed in the hope that it will be useful,
3056+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
3057+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3058+ * General Public License for more details.
3059+ *
3060+ * You should have received a copy of the GNU Lesser General Public
3061+ * License along with this library; if not, write to the
3062+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
3063+ * Boston, MA 02110-1301, USA.
3064+ */
3065+
3066+#include "group_download.h"
3067+
3068+FakeGroupDownload::FakeGroupDownload(const QString& id,
3069+ const QString& path,
3070+ bool isConfined,
3071+ const QString& rootPath,
3072+ QList<GroupDownloadStruct> downloads,
3073+ const QString& algo,
3074+ bool isGSMDownloadAllowed,
3075+ const QVariantMap& metadata,
3076+ const QMap<QString, QString>& headers,
3077+ Factory* downFactory,
3078+ QObject* parent)
3079+ : GroupDownload(id, path, isConfined, rootPath, downloads, algo,
3080+ isGSMDownloadAllowed, metadata, headers, downFactory, parent) {
3081+}
3082+
3083+FakeDownload*
3084+FakeGroupDownload::downloadForUrl(const QString& url) {
3085+ // loop in the downloads and return a fake download if possible
3086+ // null otherwise
3087+ foreach(FileDownload* down, _downloads) {
3088+ if (down->url() == url) {
3089+ auto result = qobject_cast<FakeDownload*>(down);
3090+ return result;
3091+ }
3092+ }
3093+ return nullptr;
3094+}
3095+
3096+void
3097+FakeGroupDownload::emitAuthError(const QString& url, AuthErrorStruct error) {
3098+ auto down = downloadForUrl(url);
3099+ if (down != nullptr) {
3100+ down->emitAuthError(error);
3101+ }
3102+}
3103+
3104+void
3105+FakeGroupDownload::emitHttpError(const QString& url, HttpErrorStruct error) {
3106+ auto down = downloadForUrl(url);
3107+ if (down != nullptr) {
3108+ down->emitHttpError(error);
3109+ }
3110+}
3111+
3112+void
3113+FakeGroupDownload::emitNetworkError(const QString& url,
3114+ NetworkErrorStruct error) {
3115+ auto down = downloadForUrl(url);
3116+ if (down != nullptr) {
3117+ down->emitNetworkError(error);
3118+ }
3119+}
3120+
3121+void
3122+FakeGroupDownload::emitProcessError(const QString& url,
3123+ ProcessErrorStruct error) {
3124+ auto down = downloadForUrl(url);
3125+ if (down != nullptr) {
3126+ down->emitProcessError(error);
3127+ }
3128+}
3129
3130=== added file 'ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/group_download.h'
3131--- ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/group_download.h 1970-01-01 00:00:00 +0000
3132+++ ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/group_download.h 2014-02-19 18:29:41 +0000
3133@@ -0,0 +1,50 @@
3134+/*
3135+ * Copyright 2014 Canonical Ltd.
3136+ *
3137+ * This library is free software; you can redistribute it and/or
3138+ * modify it under the terms of version 3 of the GNU Lesser General Public
3139+ * License as published by the Free Software Foundation.
3140+ *
3141+ * This program is distributed in the hope that it will be useful,
3142+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
3143+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3144+ * General Public License for more details.
3145+ *
3146+ * You should have received a copy of the GNU Lesser General Public
3147+ * License along with this library; if not, write to the
3148+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
3149+ * Boston, MA 02110-1301, USA.
3150+ */
3151+
3152+#ifndef FAKE_GROUP_DOWNLOAD_H
3153+#define FAKE_GROUP_DOWNLOAD_H
3154+
3155+#include <downloads/group_download.h>
3156+#include "download.h"
3157+
3158+class FakeGroupDownload : public GroupDownload {
3159+ Q_OBJECT
3160+
3161+ public:
3162+ FakeGroupDownload(const QString& id,
3163+ const QString& path,
3164+ bool isConfined,
3165+ const QString& rootPath,
3166+ QList<GroupDownloadStruct> downloads,
3167+ const QString& algo,
3168+ bool isGSMDownloadAllowed,
3169+ const QVariantMap& metadata,
3170+ const QMap<QString, QString>& headers,
3171+ Factory* downFactory,
3172+ QObject* parent = 0);
3173+
3174+ void emitAuthError(const QString& url, AuthErrorStruct error);
3175+ void emitHttpError(const QString& url, HttpErrorStruct error);
3176+ void emitNetworkError(const QString& url, NetworkErrorStruct error);
3177+ void emitProcessError(const QString& url, ProcessErrorStruct error);
3178+
3179+ private:
3180+ FakeDownload* downloadForUrl(const QString& url);
3181+};
3182+
3183+#endif // GROUP_DOWNLOAD_H
3184
3185=== modified file 'ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/network_reply.cpp'
3186--- ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/network_reply.cpp 2014-02-04 12:13:02 +0000
3187+++ ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/network_reply.cpp 2014-02-19 18:29:41 +0000
3188@@ -127,7 +127,7 @@
3189
3190 void
3191 FakeNetworkReply::emitHttpError(QNetworkReply::NetworkError code) {
3192- emit error(code);
3193+ emit error(code);
3194 }
3195
3196 QVariant
3197
3198=== modified file 'ubuntu-download-manager-tests/downloads/test_download.cpp'
3199--- ubuntu-download-manager-tests/downloads/test_download.cpp 2014-02-07 15:24:55 +0000
3200+++ ubuntu-download-manager-tests/downloads/test_download.cpp 2014-02-19 18:29:41 +0000
3201@@ -87,7 +87,7 @@
3202 QScopedPointer<FileDownload> download(new FileDownload(id, path, _isConfined,
3203 _rootPath, url, _metadata, _headers));
3204
3205- // assert that we did set the intial state correctly
3206+ // assert that we did set the initial state correctly
3207 // gets for internal state
3208
3209 QCOMPARE(download->downloadId(), id);
3210@@ -144,7 +144,7 @@
3211 void
3212 TestDownload::testPath_data() {
3213 // create a number of rows with a diff path to ensure that
3214- // the accesor does return the correct one
3215+ // the accessor does return the correct one
3216 QTest::addColumn<QString>("path");
3217 QTest::newRow("First row") << "/first/random/path";
3218 QTest::newRow("Second row") << "/second/random/path";
3219@@ -164,7 +164,7 @@
3220 void
3221 TestDownload::testUrl_data() {
3222 // create a number of rows with a diff url to ensure that
3223- // the accesor does return the correct one
3224+ // the accessor does return the correct one
3225 QTest::addColumn<QUrl>("url");
3226 QTest::newRow("First row") << QUrl("http://ubuntu.com");
3227 QTest::newRow("Second row") << QUrl("http://one.ubuntu.com");
3228@@ -214,7 +214,7 @@
3229 reply->setData(fileData);
3230 emit reply->downloadProgress(received, total);
3231
3232- // assert that the total is set and that the signals is emited
3233+ // assert that the total is set and that the signals is emitted
3234 QCOMPARE(download->totalSize(), total);
3235 QCOMPARE(spy.count(), 1);
3236
3237@@ -899,8 +899,8 @@
3238 // set the attrs in the reply so that we do raise two signals
3239 reply->setAttribute(QNetworkRequest::HttpStatusCodeAttribute, code);
3240 reply->setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, message);
3241-
3242- // emit the error and esure that the signals are raised
3243+
3244+ // emit the error and ensure that the signals are raised
3245 reply->emitHttpError(QNetworkReply::ContentAccessDenied);
3246 QCOMPARE(httpErrorSpy.count(), 1);
3247 QCOMPARE(errorSpy.count(), 1);
3248@@ -960,14 +960,70 @@
3249
3250 // set the attrs in the reply so that we do raise two signals
3251 reply->clearAttribute(QNetworkRequest::HttpStatusCodeAttribute);
3252-
3253- // emit the error and esure that the signals are raised
3254+
3255+ // emit the error and ensure that the signals are raised
3256 reply->emitHttpError((QNetworkReply::NetworkError)code);
3257 QCOMPARE(networkErrorSpy.count(), 1);
3258 QCOMPARE(errorSpy.count(), 1);
3259 }
3260
3261 void
3262+TestDownload::testOnAuthError() {
3263+ _reqFactory->record();
3264+ QScopedPointer<FileDownload> download(new FileDownload(_id, _path, _isConfined,
3265+ _rootPath, _url, _metadata, _headers));
3266+ QSignalSpy errorSpy(download.data(), SIGNAL(error(QString)));
3267+ QSignalSpy authErrorSpy(download.data(),
3268+ SIGNAL(authError(AuthErrorStruct)));
3269+ QSignalSpy networkErrorSpy(download.data(),
3270+ SIGNAL(networkError(NetworkErrorStruct)));
3271+
3272+ download->start(); // change state
3273+ download->startDownload();
3274+
3275+ // we need to set the data before we pause!!!
3276+ QList<MethodData> calledMethods = _reqFactory->calledMethods();
3277+ QCOMPARE(1, calledMethods.count());
3278+ FakeNetworkReply* reply = reinterpret_cast<FakeNetworkReply*>(
3279+ calledMethods[0].params().outParams()[0]);
3280+
3281+ // emit the error and ensure that the signals are raised
3282+ reply->emitHttpError(QNetworkReply::AuthenticationRequiredError);
3283+ QCOMPARE(networkErrorSpy.count(), 0);
3284+ QCOMPARE(authErrorSpy.count(), 1);
3285+ auto error = authErrorSpy.takeFirst().at(0).value<AuthErrorStruct>();
3286+ QVERIFY(error.getType() == AuthErrorStruct::Server);
3287+ QCOMPARE(errorSpy.count(), 1);
3288+}
3289+
3290+void
3291+TestDownload::testOnProxyAuthError() {
3292+ _reqFactory->record();
3293+ QScopedPointer<FileDownload> download(new FileDownload(_id, _path, _isConfined,
3294+ _rootPath, _url, _metadata, _headers));
3295+ QSignalSpy errorSpy(download.data(), SIGNAL(error(QString)));
3296+ QSignalSpy authErrorSpy(download.data(),
3297+ SIGNAL(authError(AuthErrorStruct)));
3298+ QSignalSpy networkErrorSpy(download.data(),
3299+ SIGNAL(networkError(NetworkErrorStruct)));
3300+
3301+ download->start(); // change state
3302+ download->startDownload();
3303+
3304+ // we need to set the data before we pause!!!
3305+ QList<MethodData> calledMethods = _reqFactory->calledMethods();
3306+ QCOMPARE(1, calledMethods.count());
3307+ FakeNetworkReply* reply = reinterpret_cast<FakeNetworkReply*>(
3308+ calledMethods[0].params().outParams()[0]);
3309+
3310+ // emit the error and ensure that the signals are raised
3311+ reply->emitHttpError(QNetworkReply::ProxyAuthenticationRequiredError);
3312+ QCOMPARE(networkErrorSpy.count(), 0);
3313+ QCOMPARE(authErrorSpy.count(), 1);
3314+ QCOMPARE(errorSpy.count(), 1);
3315+}
3316+
3317+void
3318 TestDownload::testSetRawHeadersStart_data() {
3319 QTest::addColumn<QMap<QString, QString> >("headers");
3320
3321@@ -1612,7 +1668,7 @@
3322
3323 // emit the finished signal with a result > 0 and ensure error is emitted
3324 process->emitFinished(0, QProcess::NormalExit);
3325- // asser that the file does not longer exist in the system
3326+ // assert that the file does not longer exist in the system
3327 QVERIFY(!QFile::exists(fileName));
3328 }
3329
3330@@ -2014,7 +2070,7 @@
3331 reply->setAttribute(QNetworkRequest::RedirectionTargetAttribute,
3332 redirectUrl);
3333 QSignalSpy replySpy(_reqFactory, SIGNAL(requestCreated(NetworkReply*)));
3334-
3335+
3336 // use a spy to wait for the second reply
3337 reply->emitFinished();
3338
3339@@ -2024,7 +2080,7 @@
3340 replySpy.takeFirst().at(0).value<NetworkReply*>());
3341
3342 download->pause();
3343-
3344+
3345 // set the attr to be a loop
3346 reply->setAttribute(QNetworkRequest::RedirectionTargetAttribute,
3347 _url);
3348@@ -2062,7 +2118,7 @@
3349 reply->setAttribute(QNetworkRequest::RedirectionTargetAttribute,
3350 redirectUrl);
3351 QSignalSpy replySpy(_reqFactory, SIGNAL(requestCreated(NetworkReply*)));
3352-
3353+
3354 // use a spy to wait for the second reply
3355 reply->emitFinished();
3356
3357@@ -2073,7 +2129,7 @@
3358 replySpy.takeFirst().at(0).value<NetworkReply*>());
3359
3360 download->pause();
3361-
3362+
3363 QSignalSpy errorSpy(download.data(), SIGNAL(error(QString)));
3364 QSignalSpy networkErrorSpy(download.data(),
3365 SIGNAL(networkError(NetworkErrorStruct)));
3366@@ -2138,7 +2194,7 @@
3367 reply->setAttribute(QNetworkRequest::RedirectionTargetAttribute,
3368 url);
3369 QSignalSpy replySpy(_reqFactory, SIGNAL(requestCreated(NetworkReply*)));
3370-
3371+
3372 // use a spy to wait for the second reply
3373 reply->emitFinished();
3374
3375@@ -2149,9 +2205,9 @@
3376 replySpy.takeFirst().at(0).value<NetworkReply*>());
3377 redirectCount++;
3378 }
3379-
3380+
3381 download->pause();
3382-
3383+
3384 QSignalSpy errorSpy(download.data(), SIGNAL(error(QString)));
3385 QSignalSpy networkErrorSpy(download.data(),
3386 SIGNAL(networkError(NetworkErrorStruct)));
3387
3388=== modified file 'ubuntu-download-manager-tests/downloads/test_download.h'
3389--- ubuntu-download-manager-tests/downloads/test_download.h 2014-02-04 12:13:02 +0000
3390+++ ubuntu-download-manager-tests/downloads/test_download.h 2014-02-19 18:29:41 +0000
3391@@ -104,6 +104,8 @@
3392 void testOnSslError();
3393 void testOnNetworkError_data();
3394 void testOnNetworkError();
3395+ void testOnAuthError();
3396+ void testOnProxyAuthError();
3397 void testSetRawHeadersStart();
3398 void testSetRawHeadersWithRangeStart();
3399 void testSetRawHeadersResume();
3400
3401=== modified file 'ubuntu-download-manager-tests/downloads/test_group_download.cpp'
3402--- ubuntu-download-manager-tests/downloads/test_group_download.cpp 2014-01-10 16:38:56 +0000
3403+++ ubuntu-download-manager-tests/downloads/test_group_download.cpp 2014-02-19 18:29:41 +0000
3404@@ -21,6 +21,7 @@
3405 #include <downloads/group_download.h>
3406 #include <system/uuid_utils.h>
3407 #include <ubuntu/download_manager/tests/server/download.h>
3408+#include <ubuntu/download_manager/tests/server/group_download.h>
3409 #include "test_group_download.h"
3410
3411 TestGroupDownload::TestGroupDownload(QObject *parent)
3412@@ -870,3 +871,115 @@
3413
3414 QVERIFY(!group->isValid());
3415 }
3416+
3417+void
3418+TestGroupDownload::testAuthErrorEmitted_data() {
3419+ QTest::addColumn<QString>("url");
3420+
3421+ QTest::newRow("First url") << "http://www.one.ubuntu.com";
3422+ QTest::newRow("Second url") << "http://ubuntu.com/file";
3423+}
3424+
3425+void
3426+TestGroupDownload::testAuthErrorEmitted() {
3427+ QFETCH(QString, url);
3428+ QList<GroupDownloadStruct> downloadsStruct;
3429+ downloadsStruct.append(GroupDownloadStruct(url,
3430+ "first path", ""));
3431+ downloadsStruct.append(GroupDownloadStruct("http://ubuntu.com",
3432+ "second path", ""));
3433+ downloadsStruct.append(GroupDownloadStruct("http://reddit.com",
3434+ "other_reddit_local_file", ""));
3435+
3436+ QScopedPointer<FakeGroupDownload> group(new FakeGroupDownload(_id, _path,
3437+ false, _rootPath, downloadsStruct, "md5", _isGSMDownloadAllowed,
3438+ _metadata, _headers, _downloadFactory, _fileManager));
3439+
3440+ QSignalSpy spy(group.data(), SIGNAL(authError(QString, AuthErrorStruct)));
3441+ group->emitAuthError(url, AuthErrorStruct());
3442+ QCOMPARE(1, spy.count());
3443+}
3444+
3445+void
3446+TestGroupDownload::testHttpErrorEmitted_data() {
3447+ QTest::addColumn<QString>("url");
3448+
3449+ QTest::newRow("First url") << "http://www.one.ubuntu.com";
3450+ QTest::newRow("Second url") << "http://ubuntu.com/file";
3451+}
3452+
3453+void
3454+TestGroupDownload::testHttpErrorEmitted() {
3455+ QFETCH(QString, url);
3456+ QList<GroupDownloadStruct> downloadsStruct;
3457+ downloadsStruct.append(GroupDownloadStruct(url,
3458+ "first path", ""));
3459+ downloadsStruct.append(GroupDownloadStruct("http://ubuntu.com",
3460+ "second path", ""));
3461+ downloadsStruct.append(GroupDownloadStruct("http://reddit.com",
3462+ "other_reddit_local_file", ""));
3463+
3464+ QScopedPointer<FakeGroupDownload> group(new FakeGroupDownload(_id, _path,
3465+ false, _rootPath, downloadsStruct, "md5", _isGSMDownloadAllowed,
3466+ _metadata, _headers, _downloadFactory, _fileManager));
3467+
3468+ QSignalSpy spy(group.data(), SIGNAL(httpError(QString, HttpErrorStruct)));
3469+ group->emitHttpError(url, HttpErrorStruct());
3470+ QCOMPARE(1, spy.count());
3471+}
3472+
3473+void
3474+TestGroupDownload::testNetworkErrorEmitted_data() {
3475+ QTest::addColumn<QString>("url");
3476+
3477+ QTest::newRow("First url") << "http://www.one.ubuntu.com";
3478+ QTest::newRow("Second url") << "http://ubuntu.com/file";
3479+}
3480+
3481+void
3482+TestGroupDownload::testNetworkErrorEmitted() {
3483+ QFETCH(QString, url);
3484+ QList<GroupDownloadStruct> downloadsStruct;
3485+ downloadsStruct.append(GroupDownloadStruct(url,
3486+ "first path", ""));
3487+ downloadsStruct.append(GroupDownloadStruct("http://ubuntu.com",
3488+ "second path", ""));
3489+ downloadsStruct.append(GroupDownloadStruct("http://reddit.com",
3490+ "other_reddit_local_file", ""));
3491+
3492+ QScopedPointer<FakeGroupDownload> group(new FakeGroupDownload(_id, _path,
3493+ false, _rootPath, downloadsStruct, "md5", _isGSMDownloadAllowed,
3494+ _metadata, _headers, _downloadFactory, _fileManager));
3495+
3496+ QSignalSpy spy(group.data(), SIGNAL(networkError(QString, NetworkErrorStruct)));
3497+ group->emitNetworkError(url, NetworkErrorStruct());
3498+ QCOMPARE(1, spy.count());
3499+}
3500+
3501+void
3502+TestGroupDownload::testProcessErrorEmitted_data() {
3503+ QTest::addColumn<QString>("url");
3504+
3505+ QTest::newRow("First url") << "http://www.one.ubuntu.com";
3506+ QTest::newRow("Second url") << "http://ubuntu.com/file";
3507+}
3508+
3509+void
3510+TestGroupDownload::testProcessErrorEmitted() {
3511+ QFETCH(QString, url);
3512+ QList<GroupDownloadStruct> downloadsStruct;
3513+ downloadsStruct.append(GroupDownloadStruct(url,
3514+ "first path", ""));
3515+ downloadsStruct.append(GroupDownloadStruct("http://ubuntu.com",
3516+ "second path", ""));
3517+ downloadsStruct.append(GroupDownloadStruct("http://reddit.com",
3518+ "other_reddit_local_file", ""));
3519+
3520+ QScopedPointer<FakeGroupDownload> group(new FakeGroupDownload(_id, _path,
3521+ false, _rootPath, downloadsStruct, "md5", _isGSMDownloadAllowed,
3522+ _metadata, _headers, _downloadFactory, _fileManager));
3523+
3524+ QSignalSpy spy(group.data(), SIGNAL(processError(QString, ProcessErrorStruct)));
3525+ group->emitProcessError(url, ProcessErrorStruct());
3526+ QCOMPARE(1, spy.count());
3527+}
3528
3529=== modified file 'ubuntu-download-manager-tests/downloads/test_group_download.h'
3530--- ubuntu-download-manager-tests/downloads/test_group_download.h 2014-01-10 16:38:56 +0000
3531+++ ubuntu-download-manager-tests/downloads/test_group_download.h 2014-02-19 18:29:41 +0000
3532@@ -87,6 +87,16 @@
3533 // ensure that local paths are just used once
3534 void testDuplicatedLocalPath();
3535
3536+ // tests that ensure that the signals are raised
3537+ void testAuthErrorEmitted_data();
3538+ void testAuthErrorEmitted();
3539+ void testHttpErrorEmitted_data();
3540+ void testHttpErrorEmitted();
3541+ void testNetworkErrorEmitted_data();
3542+ void testNetworkErrorEmitted();
3543+ void testProcessErrorEmitted_data();
3544+ void testProcessErrorEmitted();
3545+
3546 private:
3547 QString _id;
3548 QString _path;

Subscribers

People subscribed via source and target branches