Merge lp:~diegosarmentero/ubuntuone-credentials/cover-download into lp:ubuntuone-credentials

Proposed by Diego Sarmentero
Status: Merged
Approved by: dobey
Approved revision: 28
Merged at revision: 21
Proposed branch: lp:~diegosarmentero/ubuntuone-credentials/cover-download
Merge into: lp:ubuntuone-credentials
Prerequisite: lp:~diegosarmentero/ubuntuone-credentials/error-handling
Diff against target: 226 lines (+109/-8)
6 files modified
music-login/CMakeLists.txt (+3/-2)
music-login/downloader.cpp (+51/-0)
music-login/downloader.h (+32/-0)
music-login/header.ui (+7/-1)
music-login/ssowizard.cpp (+12/-4)
music-login/ssowizard.h (+4/-1)
To merge this branch: bzr merge lp:~diegosarmentero/ubuntuone-credentials/cover-download
Reviewer Review Type Date Requested Status
dobey (community) Approve
Alejandro J. Cura (community) Approve
Review via email: mp+163132@code.launchpad.net

Commit message

- Support urls in the --picture argument, to handle download of the image from this application

Description of the change

Changing arguments to receive the url of the album cover and download it from this application.

To post a comment you must log in.
22. By Diego Sarmentero

removing qdebug message

23. By Diego Sarmentero

changing Downloader slot to private

24. By Diego Sarmentero

merge

Revision history for this message
dobey (dobey) wrote :

What's the rationale for this? Wasn't this not needed, because the dash already downloaded the image, and we just pass that local file path to ubuntuone-music-login for display, so we don't have to download it from the server again?

124 - <string>img</string>
125 + <string> </string>

Also, why is this changed to be white space for the string, rather than just empty?

25. By Diego Sarmentero

merge

Revision history for this message
dobey (dobey) :
review: Needs Information
26. By Diego Sarmentero

merge

Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

> What's the rationale for this? Wasn't this not needed, because the dash
> already downloaded the image, and we just pass that local file path to
> ubuntuone-music-login for display, so we don't have to download it from the
> server again?

No, we need to download the image in this app, also we had some complains about the scope downloading the image, so we need to do it here.

>
> 124 - <string>img</string>
> 125 + <string> </string>
>
> Also, why is this changed to be white space for the string, rather than just
> empty?

The image being downloaded can take a couple of seconds to appear in the app, so it's better to show an empty space until the image is loaded, instead of something that says "img" and then gets replaced by the actual image.

27. By Diego Sarmentero

merge

Revision history for this message
Alejandro J. Cura (alecu) wrote :

+1

review: Approve
28. By Diego Sarmentero

changing label image to have a fixed width

Revision history for this message
dobey (dobey) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'music-login/CMakeLists.txt'
2--- music-login/CMakeLists.txt 2013-03-26 14:10:42 +0000
3+++ music-login/CMakeLists.txt 2013-05-20 13:38:26 +0000
4@@ -14,6 +14,7 @@
5 FILE (GLOB LIB_SOURCES
6 header.cpp
7 footer.cpp
8+ downloader.cpp
9 loadingoverlay.cpp
10 loginform.cpp
11 mainwindow.cpp
12@@ -42,8 +43,8 @@
13 ${BUILT_RESOURCES}
14 )
15
16-qt5_use_modules (${MUSIC_LOGIN_LIB} Core DBus Gui Widgets)
17-qt5_use_modules (${MUSIC_LOGIN_EXE} DBus Widgets)
18+qt5_use_modules (${MUSIC_LOGIN_LIB} Core DBus Gui Widgets Network)
19+qt5_use_modules (${MUSIC_LOGIN_EXE} DBus Widgets Network)
20 target_link_libraries (${MUSIC_LOGIN_EXE}
21 -Wl,-rpath,${CMAKE_BINARY_DIR}/lib
22 -L${CMAKE_BINARY_DIR}/lib
23
24=== added file 'music-login/downloader.cpp'
25--- music-login/downloader.cpp 1970-01-01 00:00:00 +0000
26+++ music-login/downloader.cpp 2013-05-20 13:38:26 +0000
27@@ -0,0 +1,51 @@
28+#include "downloader.h"
29+#include <QUuid>
30+#include <QFile>
31+#include <QDebug>
32+
33+Downloader::Downloader(QObject *parent) :
34+ QObject(parent)
35+{
36+ this->_nam = new QNetworkAccessManager(this);
37+ this->_request = new QNetworkRequest();
38+ this->createDownloadDir();
39+
40+ QObject::connect(this->_nam, SIGNAL(finished(QNetworkReply*)),
41+ this, SLOT(onReply(QNetworkReply*)));
42+}
43+
44+void Downloader::onReply(QNetworkReply* reply)
45+{
46+ QVariant statusAttr = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
47+ if(!statusAttr.isValid()) {
48+ qDebug() << "No image resource available!";
49+ return;
50+ }
51+
52+ QByteArray payload = reply->readAll();
53+ if(!payload.isEmpty()) {
54+ QUuid uuid = QUuid::createUuid();
55+ QString imagePath = this->_downloadDir->filePath(uuid.toString());
56+ QFile file(imagePath);
57+ file.open(QIODevice::WriteOnly);
58+ file.write(payload.data(), payload.size());
59+ file.close();
60+
61+ emit fileDownloaded(imagePath);
62+ }
63+}
64+
65+void Downloader::startDownload(const QString& url)
66+{
67+ if(!url.isEmpty()){
68+ this->_request->setUrl(url);
69+ this->_nam->get(*this->_request);
70+ }
71+}
72+
73+void Downloader::createDownloadDir(){
74+ this->_downloadDir = new QDir(QDir::temp().filePath("u1credentials"));
75+ if(!this->_downloadDir->exists()){
76+ this->_downloadDir->mkpath(this->_downloadDir->absolutePath());
77+ }
78+}
79
80=== added file 'music-login/downloader.h'
81--- music-login/downloader.h 1970-01-01 00:00:00 +0000
82+++ music-login/downloader.h 2013-05-20 13:38:26 +0000
83@@ -0,0 +1,32 @@
84+#ifndef DOWNLOADER_H
85+#define DOWNLOADER_H
86+
87+#include <QObject>
88+#include <QtNetwork/QNetworkAccessManager>
89+#include <QtNetwork/QNetworkReply>
90+#include <QDir>
91+
92+class Downloader : public QObject
93+{
94+ Q_OBJECT
95+public:
96+ explicit Downloader(QObject *parent = 0);
97+
98+ void startDownload(const QString& url);
99+
100+private slots:
101+ void onReply(QNetworkReply*);
102+
103+signals:
104+ void fileDownloaded(QString&);
105+
106+private:
107+ QNetworkAccessManager* _nam;
108+ QNetworkRequest* _request;
109+ QDir* _downloadDir;
110+
111+ void createDownloadDir();
112+
113+};
114+
115+#endif // DOWNLOADER_H
116
117=== modified file 'music-login/header.ui'
118--- music-login/header.ui 2013-04-26 14:01:29 +0000
119+++ music-login/header.ui 2013-05-20 13:38:26 +0000
120@@ -28,6 +28,12 @@
121 <verstretch>0</verstretch>
122 </sizepolicy>
123 </property>
124+ <property name="minimumSize">
125+ <size>
126+ <width>75</width>
127+ <height>0</height>
128+ </size>
129+ </property>
130 <property name="maximumSize">
131 <size>
132 <width>75</width>
133@@ -35,7 +41,7 @@
134 </size>
135 </property>
136 <property name="text">
137- <string>img</string>
138+ <string/>
139 </property>
140 <property name="alignment">
141 <set>Qt::AlignCenter</set>
142
143=== modified file 'music-login/ssowizard.cpp'
144--- music-login/ssowizard.cpp 2013-05-16 14:28:36 +0000
145+++ music-login/ssowizard.cpp 2013-05-20 13:38:26 +0000
146@@ -72,11 +72,13 @@
147 }
148 }
149
150- this->setHeader(artist, album, price, picture);
151+ this->setHeader(artist, album, price);
152
153 // Connect signals
154+ QObject::connect(&(this->downloader), SIGNAL(fileDownloaded(QString&)),
155+ this, SLOT(imageDownloaded(QString&)));
156 QObject::connect(&(this->_service), SIGNAL(sessionActivated()), this, SLOT(sessionDetected()));
157- this->_service.init_service();
158+ this->_service.init_service();
159 QObject::connect(&(this->_service), SIGNAL(credentialsFound(QString,QString,QString,QString,QString)),
160 this, SLOT(accountAuthenticated()));
161 QObject::connect(&(this->_service), SIGNAL(requestFailed(const ErrorResponse&)),
162@@ -90,6 +92,8 @@
163 QObject::connect(this->ui->pageRegister, SIGNAL(registerCheckout(QString,QString,QString)),
164 this, SLOT(registerAndBuy(QString, QString, QString)));
165
166+ this->downloader.startDownload(picture);
167+
168 // Set the error messages depending the code.
169 this->_codeMessages[ErrorCodes::CODE_CAPTCHA_REQUIRED] = "A captcha challenge is required to complete the request.";
170 this->_codeMessages[ErrorCodes::CODE_INVALID_CREDENTIALS] = "That's not your password. Please try again.";
171@@ -179,12 +183,16 @@
172 this->ui->lblError->setEnabled(false);
173 }
174
175-void SSOWizard::setHeader(QString artist, QString album, QString price, QString picture_path)
176+void SSOWizard::setHeader(QString artist, QString album, QString price)
177 {
178 this->ui->header->setAlbum(album);
179 this->ui->header->setArtist(artist);
180 this->ui->header->setPrice(price);
181- this->ui->header->setPicture(picture_path);
182+}
183+
184+void SSOWizard::imageDownloaded(QString& path)
185+{
186+ this->ui->header->setPicture(path);
187 }
188
189 void SSOWizard::resizeEvent(QResizeEvent * event)
190
191=== modified file 'music-login/ssowizard.h'
192--- music-login/ssowizard.h 2013-05-16 14:28:36 +0000
193+++ music-login/ssowizard.h 2013-05-20 13:38:26 +0000
194@@ -34,6 +34,7 @@
195 #include <QHash>
196 #include <ssoservice.h>
197 #include "loadingoverlay.h"
198+#include "downloader.h"
199
200 using namespace SSO;
201
202@@ -60,6 +61,7 @@
203 virtual void resizeEvent(QResizeEvent *);
204
205 private slots:
206+ void imageDownloaded(QString& path);
207 void showRegisterPage(QString email, QString password);
208 void loginAndBuy(QString email, QString password);
209 void registerAndBuy(QString email, QString password, QString name);
210@@ -71,6 +73,7 @@
211
212 private:
213 Ui::SSOWizard *ui;
214+ Downloader downloader;
215 QString purchaseUrl;
216 SSOService _service;
217 LoadingOverlay* _overlay;
218@@ -79,7 +82,7 @@
219 QString cleanArgument(QString& arg);
220 void showError(const ErrorResponse& error);
221 void hideError();
222- void setHeader(QString artist, QString album, QString price, QString picture_path);
223+ void setHeader(QString artist, QString album, QString price);
224
225 #ifdef TESTS
226 friend class TestSSOWizard;

Subscribers

People subscribed via source and target branches