Merge lp:~mandel/ubuntu-download-manager/add-mng-class into lp:ubuntu-download-manager

Proposed by Manuel de la Peña
Status: Merged
Merged at revision: 276
Proposed branch: lp:~mandel/ubuntu-download-manager/add-mng-class
Merge into: lp:ubuntu-download-manager
Prerequisite: lp:~mandel/ubuntu-download-manager/add-factory
Diff against target: 364 lines (+178/-47)
5 files modified
ubuntu-upload-manager-priv/ubuntu/uploads/daemon.cpp (+4/-4)
ubuntu-upload-manager-priv/ubuntu/uploads/daemon.h (+4/-4)
ubuntu-upload-manager-priv/ubuntu/uploads/file_upload.cpp (+10/-2)
ubuntu-upload-manager-priv/ubuntu/uploads/manager.cpp (+131/-35)
ubuntu-upload-manager-priv/ubuntu/uploads/manager.h (+29/-2)
To merge this branch: bzr merge lp:~mandel/ubuntu-download-manager/add-mng-class
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Ubuntu One hackers Pending
Review via email: mp+213477@code.launchpad.net

Commit message

Add uploads manager implementation.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
318. By Manuel de la Peña

Merged add-factory into add-mng-class.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
319. By Manuel de la Peña

Merged add-factory into add-mng-class.

320. By Manuel de la Peña

Merged add-factory into add-mng-class.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
321. By Manuel de la Peña

Merged add-factory into add-mng-class.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
322. By Manuel de la Peña

Merged add-factory into add-mng-class.

323. By Manuel de la Peña

Merged add-factory into add-mng-class.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
324. By Manuel de la Peña

Merged add-factory into add-mng-class.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
325. By Manuel de la Peña

Merged add-factory into add-mng-class.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
326. By Manuel de la Peña

Merged add-factory into add-mng-class.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
327. By Manuel de la Peña

Merged add-factory into add-mng-class.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
328. By Manuel de la Peña

Merged add-factory into add-mng-class.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
329. By Manuel de la Peña

Merged add-factory into add-mng-class.

330. By Manuel de la Peña

Merged add-factory into add-mng-class.

331. By Manuel de la Peña

Merged add-factory into add-mng-class.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
332. By Manuel de la Peña

Merged add-factory into add-mng-class.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
333. By Manuel de la Peña

Merged add-factory into add-mng-class.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
334. By Manuel de la Peña

Merged add-factory into add-mng-class.

335. By Manuel de la Peña

Merged add-factory into add-mng-class.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
336. By Manuel de la Peña

Merged add-factory into add-mng-class.

337. By Manuel de la Peña

Merged add-factory into add-mng-class.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
338. By Manuel de la Peña

Merged add-factory into add-mng-class.

339. By Manuel de la Peña

Merged add-factory into add-mng-class.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ubuntu-upload-manager-priv/ubuntu/uploads/daemon.cpp'
--- ubuntu-upload-manager-priv/ubuntu/uploads/daemon.cpp 2014-04-15 15:31:31 +0000
+++ ubuntu-upload-manager-priv/ubuntu/uploads/daemon.cpp 2014-04-15 15:31:32 +0000
@@ -36,10 +36,10 @@
36}36}
3737
38UploadDaemon::UploadDaemon(ManagerFactory* managerFactory,38UploadDaemon::UploadDaemon(ManagerFactory* managerFactory,
39 System::Application* app,39 System::Application* app,
40 System::DBusConnection* conn,40 System::DBusConnection* conn,
41 System::Timer* timer,41 System::Timer* timer,
42 QObject *parent)42 QObject *parent)
43 : BaseDaemon(managerFactory,43 : BaseDaemon(managerFactory,
44 new UploadAdaptorFactory(),44 new UploadAdaptorFactory(),
45 app, conn, timer, parent) {45 app, conn, timer, parent) {
4646
=== modified file 'ubuntu-upload-manager-priv/ubuntu/uploads/daemon.h'
--- ubuntu-upload-manager-priv/ubuntu/uploads/daemon.h 2014-04-15 15:31:31 +0000
+++ ubuntu-upload-manager-priv/ubuntu/uploads/daemon.h 2014-04-15 15:31:32 +0000
@@ -35,10 +35,10 @@
35 public:35 public:
36 UploadDaemon(QObject *parent = 0);36 UploadDaemon(QObject *parent = 0);
37 UploadDaemon(ManagerFactory* managerFactory,37 UploadDaemon(ManagerFactory* managerFactory,
38 System::Application* app,38 System::Application* app,
39 System::DBusConnection* conn,39 System::DBusConnection* conn,
40 System::Timer* timer,40 System::Timer* timer,
41 QObject *parent = 0);41 QObject *parent = 0);
4242
43 public slots:43 public slots:
44 virtual void start();44 virtual void start();
4545
=== modified file 'ubuntu-upload-manager-priv/ubuntu/uploads/file_upload.cpp'
--- ubuntu-upload-manager-priv/ubuntu/uploads/file_upload.cpp 2014-04-15 15:31:31 +0000
+++ ubuntu-upload-manager-priv/ubuntu/uploads/file_upload.cpp 2014-04-15 15:31:32 +0000
@@ -56,10 +56,18 @@
56 // we must make sure that the path is absolute56 // we must make sure that the path is absolute
57 QFileInfo info(filePath);57 QFileInfo info(filePath);
58 if (!info.isAbsolute()) {58 if (!info.isAbsolute()) {
59 UP_LOG(INFO) << "Path is not absolute: " << filePath;
59 setIsValid(false);60 setIsValid(false);
60 setLastError(QString("Path is not absolute: '%1'").arg(filePath));61 setLastError(QString("Path is not absolute: '%1'").arg(filePath));
61 }62 }
62 _currentData = FileManager::instance()->copyToTempFile(filePath);63
64 if (!info.exists()) {
65 UP_LOG(INFO) << "Path does not exist: " << filePath;
66 setIsValid(false);
67 setLastError(QString("Path does not exist: '%1'").arg(filePath));
68 } else {
69 _currentData = FileManager::instance()->createFile(filePath);
70 }
63 _requestFactory = RequestFactory::instance();71 _requestFactory = RequestFactory::instance();
64}72}
6573
@@ -181,7 +189,7 @@
181 request.setHeader(QNetworkRequest::ContentTypeHeader,189 request.setHeader(QNetworkRequest::ContentTypeHeader,
182 CONTENT_TYPE_HEADER);190 CONTENT_TYPE_HEADER);
183 request.setHeader(QNetworkRequest::ContentLengthHeader,191 request.setHeader(QNetworkRequest::ContentLengthHeader,
184 QString::number(_currentData->size()));192 _currentData->size());
185193
186 return request;194 return request;
187}195}
188196
=== modified file 'ubuntu-upload-manager-priv/ubuntu/uploads/manager.cpp'
--- ubuntu-upload-manager-priv/ubuntu/uploads/manager.cpp 2014-04-15 15:31:31 +0000
+++ ubuntu-upload-manager-priv/ubuntu/uploads/manager.cpp 2014-04-15 15:31:32 +0000
@@ -16,6 +16,12 @@
16 * Boston, MA 02110-1301, USA.16 * Boston, MA 02110-1301, USA.
17 */17 */
1818
19#include <functional>
20#include <QRegExp>
21#include <ubuntu/transfers/system/apparmor.h>
22#include <ubuntu/transfers/system/logger.h>
23#include <ubuntu/transfers/system/request_factory.h>
24#include <ubuntu/upload_manager/metatypes.h>
19#include "manager.h"25#include "manager.h"
2026
21namespace Ubuntu {27namespace Ubuntu {
@@ -33,40 +39,89 @@
33 DBusConnection* connection,39 DBusConnection* connection,
34 bool stoppable,40 bool stoppable,
35 QObject *parent)41 QObject *parent)
36 : BaseManager(app, stoppable, parent) {42 : BaseManager(app, stoppable, parent),
37 Q_UNUSED(connection);43 _throttle(0) {
44 _conn = connection;
45 RequestFactory::setStoppable(_stoppable);
46 _factory = new Factory(this);
47 _queue = new Queue(this);
48 init();
38}49}
3950
40/*
41UploadManager::UploadManager(Application* app,51UploadManager::UploadManager(Application* app,
42 DBusConnection* connection,52 DBusConnection* connection,
43 Factory* downloadFactory,53 Factory* uploadFactory,
44 Queue* queue,54 Queue* queue,
45 bool stoppable,55 bool stoppable,
46 QObject *parent) {56 QObject *parent)
47}57 : BaseManager(app, stoppable, parent),
48*/58 _throttle(0),
59 _factory(uploadFactory),
60 _queue(queue) {
61 _conn = connection;
62 init();
63}
64
65void
66UploadManager::init() {
67 // register the required types
68 qDBusRegisterMetaType<StringMap>();
69 qDBusRegisterMetaType<UploadStruct>();
70 qDBusRegisterMetaType<AuthErrorStruct>();
71 qDBusRegisterMetaType<HttpErrorStruct>();
72 qDBusRegisterMetaType<NetworkErrorStruct>();
73 qDBusRegisterMetaType<ProcessErrorStruct>();
74
75 connect(_queue, &Queue::transferRemoved,
76 this, &UploadManager::onUploadsChanged);
77 connect(_queue, &Queue::transferAdded,
78 this, &UploadManager::onUploadsChanged);
79}
4980
50UploadManager::~UploadManager() {81UploadManager::~UploadManager() {
82 delete _queue;
83 delete _factory;
51}84}
5285
53QList<QSslCertificate>86QList<QSslCertificate>
54UploadManager::acceptedCertificates() {87UploadManager::acceptedCertificates() {
55 // TODO: Most be implemented88 return _factory->acceptedCertificates();
56 QList<QSslCertificate> certs;
57 return certs;
58}89}
5990
60void91void
61UploadManager::setAcceptedCertificates(const QList<QSslCertificate>& certs) {92UploadManager::setAcceptedCertificates(const QList<QSslCertificate>& certs) {
62 // TODO: Most be implemented93 LOG(INFO) << __PRETTY_FUNCTION__;
63 Q_UNUSED(certs);94 _factory->setAcceptedCertificates(certs);
64}95}
6596
66void97void
67UploadManager::allowMobileUpload(bool allowed) {98UploadManager::allowMobileUpload(bool allowed) {
68 // TODO: Most be implemented99 _allowMobileData = allowed;
69 Q_UNUSED(allowed);100 QHash<QString, Transfer*> uploads = _queue->transfers();
101 foreach(const QString& path, uploads.keys()) {
102 uploads[path]->allowGSMData(allowed);
103 }
104}
105
106QDBusObjectPath
107UploadManager::createUpload(UploadCreationFunc createUploadFunc) {
108 QString owner = "";
109
110 auto wasCalledFromDBus = calledFromDBus();
111 if (wasCalledFromDBus) {
112 owner = connection().interface()->serviceOwner(
113 message().service());
114 LOG(INFO) << "Owner is: " << owner;
115 }
116
117 auto upload = createUploadFunc(owner);
118
119 if (wasCalledFromDBus && !upload->isValid()) {
120 sendErrorReply(QDBusError::InvalidArgs, upload->lastError());
121 // the result will be ignored thanks to the sendErrorReply
122 return QDBusObjectPath();
123 }
124 return registerUpload(upload);
70}125}
71126
72QDBusObjectPath127QDBusObjectPath
@@ -76,27 +131,45 @@
76 int port,131 int port,
77 const QString& username,132 const QString& username,
78 const QString& password) {133 const QString& password) {
79 // TODO: Most be implemented134 LOG(INFO) << "Create MMS upload == {url:" << url << " filePath: "
80 Q_UNUSED(url);135 << file << " hostname:" << hostname << " port:"
81 Q_UNUSED(file);136 << port << " username:" << username << " pwd: " << password << "}";
82 Q_UNUSED(hostname);137 UploadCreationFunc createUploadFunc =
83 Q_UNUSED(port);138 [this, url, file, hostname, port, username, password](QString owner) {
84 Q_UNUSED(username);139 auto upload = _factory->createMmsUpload(owner, url, file, hostname,
85 Q_UNUSED(password);140 port, username, password);
86 return QDBusObjectPath();141 return upload;
87}142 };
88143 return createUpload(createUploadFunc);
89QDBusObjectPath144}
90UploadManager::createUpload(UploadStruct upload) {145
91 // TODO: Most be implemented146QDBusObjectPath
92 Q_UNUSED(upload);147UploadManager::createUpload(const QString& url,
93 return QDBusObjectPath();148 const QString& filePath,
149 const QVariantMap& metadata,
150 StringMap headers) {
151
152 LOG(INFO) << "Create upload == {url:" << url << " filePath: "
153 << filePath << " metadata: " << metadata << " headers: "
154 << headers << "}";
155 UploadCreationFunc createUploadFunc =
156 [this, url, filePath, metadata, headers](QString owner) {
157 return _factory->createUpload(owner, url, filePath,
158 metadata, headers);
159 };
160 return createUpload(createUploadFunc);
161}
162
163QDBusObjectPath
164UploadManager::createUpload(UploadStruct uploadStruct) {
165 return createUpload(uploadStruct.getUrl(),
166 uploadStruct.getFilePath(), uploadStruct.getMetadata(),
167 uploadStruct.getHeaders());
94}168}
95169
96qulonglong170qulonglong
97UploadManager::defaultThrottle() {171UploadManager::defaultThrottle() {
98 // TODO: Most be implemented172 return _throttle;
99 return 0;
100}173}
101174
102QList<QDBusObjectPath>175QList<QDBusObjectPath>
@@ -118,14 +191,37 @@
118191
119bool192bool
120UploadManager::isMobileUploadAllowed() {193UploadManager::isMobileUploadAllowed() {
121 // TODO: Most be implemented194 return _allowMobileData;
122 return false;
123}195}
124196
125void197void
126UploadManager::setDefaultThrottle(qulonglong speed) {198UploadManager::setDefaultThrottle(qulonglong speed) {
127 // TODO: Most be implemented199 _throttle = speed;
128 Q_UNUSED(speed);200 QHash<QString, Transfer*> uploads = _queue->transfers();
201 foreach(const QString& path, uploads.keys()) {
202 uploads[path]->setThrottle(speed);
203 }
204}
205
206void
207UploadManager::onUploadsChanged(QString path) {
208 LOG(INFO) << __PRETTY_FUNCTION__ << path;
209 emit sizeChanged(_queue->size());
210}
211
212QDBusObjectPath
213UploadManager::registerUpload(FileUpload* upload) {
214 LOG(INFO) << "Registering upload to path " << upload->path();
215 upload->setThrottle(_throttle);
216 upload->allowMobileUpload(_allowMobileData);
217 _queue->add(upload);
218 _conn->registerObject(upload->path(), upload);
219 QDBusObjectPath objectPath = QDBusObjectPath(upload->path());
220
221 // emit that the upload was created. Useful in case other
222 // processes are interested in them
223 emit uploadCreated(objectPath);
224 return objectPath;
129}225}
130226
131} // Daemon227} // Daemon
132228
=== modified file 'ubuntu-upload-manager-priv/ubuntu/uploads/manager.h'
--- ubuntu-upload-manager-priv/ubuntu/uploads/manager.h 2014-04-15 15:31:31 +0000
+++ ubuntu-upload-manager-priv/ubuntu/uploads/manager.h 2014-04-15 15:31:32 +0000
@@ -28,6 +28,7 @@
28#include <ubuntu/transfers/system/dbus_connection.h>28#include <ubuntu/transfers/system/dbus_connection.h>
29#include <ubuntu/transfers/queue.h>29#include <ubuntu/transfers/queue.h>
30#include <ubuntu/transfers/base_manager.h>30#include <ubuntu/transfers/base_manager.h>
31#include "factory.h"
3132
32namespace Ubuntu {33namespace Ubuntu {
3334
@@ -45,13 +46,13 @@
45 DBusConnection* connection,46 DBusConnection* connection,
46 bool stoppable = false,47 bool stoppable = false,
47 QObject *parent = 0);48 QObject *parent = 0);
48/* UploadManager(Application* app,49 UploadManager(Application* app,
49 DBusConnection* connection,50 DBusConnection* connection,
50 Factory* downloadFactory,51 Factory* downloadFactory,
51 Queue* queue,52 Queue* queue,
52 bool stoppable = false,53 bool stoppable = false,
53 QObject *parent = 0);54 QObject *parent = 0);
54*/55
55 virtual ~UploadManager();56 virtual ~UploadManager();
5657
57 virtual QList<QSslCertificate> acceptedCertificates();58 virtual QList<QSslCertificate> acceptedCertificates();
@@ -66,6 +67,10 @@
66 int port,67 int port,
67 const QString& username,68 const QString& username,
68 const QString& password);69 const QString& password);
70 QDBusObjectPath createUpload(const QString& url,
71 const QString& filePath,
72 const QVariantMap& metadata,
73 StringMap headers);
69 QDBusObjectPath createUpload(UploadStruct upload);74 QDBusObjectPath createUpload(UploadStruct upload);
70 qulonglong defaultThrottle();75 qulonglong defaultThrottle();
71 QList<QDBusObjectPath> getAllUploads();76 QList<QDBusObjectPath> getAllUploads();
@@ -75,6 +80,28 @@
75 bool isMobileUploadAllowed();80 bool isMobileUploadAllowed();
76 void setDefaultThrottle(qulonglong speed);81 void setDefaultThrottle(qulonglong speed);
7782
83 signals:
84 void uploadCreated(const QDBusObjectPath& path);
85 void sizeChanged(int size);
86
87 private:
88 typedef std::function<FileUpload*(QString)> UploadCreationFunc;
89
90 QDBusObjectPath createUpload(UploadCreationFunc createUploadFunc);
91 void onUploadsChanged(QString);
92 QDBusObjectPath registerUpload(FileUpload* upload);
93
94 void init();
95
96
97 private:
98 Application* _app = nullptr;
99 qulonglong _throttle;
100 Factory* _factory = nullptr;
101 Queue* _queue = nullptr;
102 DBusConnection* _conn = nullptr;
103 bool _stoppable = false;
104 bool _allowMobileData = true;
78};105};
79106
80} // Daemon107} // Daemon

Subscribers

People subscribed via source and target branches