author | cgandhi |
Thu, 23 Sep 2010 17:15:03 +0530 | |
changeset 23 | 574948b60dab |
parent 17 | 106a4bfcb866 |
child 26 | 83d6a149c755 |
permissions | -rw-r--r-- |
17 | 1 |
/** |
2 |
* Copyright (c) 2010 Sasken Communication Technologies Ltd. |
|
3 |
* All rights reserved. |
|
4 |
* This component and the accompanying materials are made available |
|
5 |
* under the terms of the "Eclipse Public License v1.0" |
|
6 |
* which accompanies this distribution, and is available |
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html" |
|
8 |
* |
|
9 |
* Initial Contributors: |
|
10 |
* Chandradeep Gandhi, Sasken Communication Technologies Ltd - Initial contribution |
|
11 |
* |
|
12 |
* Contributors: |
|
13 |
* Sangeetha Prasad, Nalina Hariharan |
|
14 |
* |
|
15 |
* Description: |
|
16 |
* The Plugin that fetches gallery related items from the logged in user's flickr account |
|
17 |
* |
|
18 |
*/ |
|
19 |
||
20 |
// Include files |
|
21 |
#include <QtPlugin> |
|
22 |
#include <QCryptographicHash> |
|
23 |
#include <QDataStream> |
|
24 |
#include <QFile> |
|
25 |
#include <QDebug> |
|
26 |
#include <QMap> |
|
27 |
#include <QListIterator> |
|
28 |
#include <QXmlStreamReader> |
|
29 |
#include <QSettings> |
|
30 |
#include <smfpluginutil.h> |
|
31 |
||
32 |
#include "flickrgalleryplugin.h" |
|
33 |
||
23
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
34 |
static int count = 0; |
17 | 35 |
static int chance = 0; // 0 = for pics from album, 1 = pics not in any album |
36 |
static int listIndex = 0;// For Mutliple Load |
|
37 |
QByteArray payload; |
|
38 |
QByteArray boundary("---ThIsIsAsAmPleBouNDaRyStrInGFrOmNaliNa---"); |
|
39 |
||
40 |
// Todo:- Macro added for limiting items fetched to recent 5 |
|
41 |
// Remove after demo |
|
42 |
#define SETLIMITOFFIVEFORSMFDEMO 1 |
|
43 |
||
44 |
/** |
|
45 |
* Method to interpret the key sets obtained from credential manager |
|
46 |
* @param aApiKey [out] The api key |
|
47 |
* @param aApiSecret [out] The api secret |
|
48 |
* @param aAuthToken [out] The auth token provided by Flickr |
|
49 |
*/ |
|
50 |
void FlickrGalleryPlugin::fetchKeys( QString &aApiKey, |
|
51 |
QString &aApiSecret, |
|
52 |
QString &aAuthToken ) |
|
53 |
{ |
|
54 |
qDebug()<<"Inside FlickrGalleryPlugin::fetchKeys()"; |
|
55 |
||
56 |
qDebug()<<"Reg Token = "<<m_provider->m_smfRegToken; |
|
57 |
qDebug()<<"Expiry Date as int = "<<m_provider->m_validity.toTime_t(); |
|
58 |
||
59 |
SmfAuthParams keys; |
|
60 |
SmfPluginUtil util; |
|
61 |
util.getAuthKeys(keys, m_provider->m_smfRegToken, |
|
62 |
m_provider->m_validity, m_provider->m_pluginId); |
|
63 |
||
64 |
qDebug()<<"Number of key-value pairs = "<<keys.count(); |
|
65 |
||
66 |
QByteArray keyName; |
|
67 |
keyName.append("ApiKey"); |
|
68 |
aApiKey.append(keys.value(keyName)); |
|
69 |
||
70 |
keyName.clear(); |
|
71 |
keyName.append("ApiSecret"); |
|
72 |
aApiSecret.append(keys.value(keyName)); |
|
73 |
||
74 |
keyName.clear(); |
|
75 |
keyName.append("AuthToken"); |
|
76 |
aAuthToken.append(keys.value(keyName)); |
|
77 |
||
78 |
qDebug()<<"Api Key = "<<aApiKey; |
|
79 |
qDebug()<<"Api Secret = "<<aApiSecret; |
|
80 |
qDebug()<<"Auth Token = "<<aAuthToken; |
|
81 |
} |
|
82 |
||
83 |
/** |
|
84 |
* Destructor |
|
85 |
*/ |
|
86 |
FlickrGalleryPlugin::~FlickrGalleryPlugin( ) |
|
87 |
{ |
|
88 |
if(m_provider) |
|
89 |
delete m_provider; |
|
90 |
} |
|
91 |
||
92 |
/** |
|
93 |
* Method to get a list of albums |
|
94 |
* @param aRequest [out] The request data to be sent to network |
|
95 |
* @param aNames The subject or any keywords to be used to filter albums with that name |
|
96 |
* @param aUser The user whose albums are requested |
|
97 |
* @param aPageNum The page to be extracted |
|
98 |
* @param aItemsPerPage Number of items per page |
|
99 |
* @return SmfPluginError Plugin error if any, else SmfPluginErrNone |
|
100 |
*/ |
|
101 |
SmfPluginError FlickrGalleryPlugin::albums( SmfPluginRequestData &aRequest, |
|
102 |
const QStringList &aNames, |
|
103 |
const SmfContact *aUser, |
|
104 |
const int aPageNum, |
|
105 |
const int aItemsPerPage ) |
|
106 |
{ |
|
107 |
qDebug()<<"Inside FlickrGalleryPlugin::albums()"; |
|
108 |
Q_UNUSED(aNames) |
|
109 |
Q_UNUSED(aPageNum) |
|
110 |
Q_UNUSED(aItemsPerPage) |
|
111 |
||
112 |
SmfPluginError error = SmfPluginErrUserNotLoggedIn; |
|
113 |
||
114 |
// Get the key sets from SMF Plugin Utility class. |
|
115 |
QString apiKey; |
|
116 |
QString apiSecret; |
|
117 |
QString authToken; |
|
118 |
fetchKeys(apiKey, apiSecret, authToken ); |
|
119 |
||
120 |
QString userId = aUser->value("Guid").value<QContactGuid>().guid(); |
|
121 |
qDebug()<<"Flickr user's ID for fetching photos = "<<userId; |
|
122 |
||
123 |
// Create the API signature string |
|
124 |
QString baseString; |
|
125 |
baseString.append(apiSecret); |
|
126 |
baseString.append("api_key"+apiKey); |
|
127 |
baseString.append("auth_token"+authToken); |
|
128 |
baseString.append("formatjson"); |
|
129 |
baseString.append("methodflickr.photosets.getList"); |
|
130 |
#ifdef SETLIMITOFFIVEFORSMFDEMO |
|
131 |
baseString.append("page"+QString::number(1)); |
|
132 |
baseString.append("per_page"+QString::number(5)); |
|
133 |
#else |
|
134 |
baseString.append("page"+QString::number(aPageNum)); |
|
135 |
baseString.append("per_page"+QString::number(aItemsPerPage)); |
|
136 |
#endif |
|
137 |
if(userId.length()) |
|
138 |
baseString.append("user_id"+userId); |
|
139 |
||
140 |
// Create the url |
|
141 |
QUrl url("http://api.flickr.com/services/rest/?"); |
|
142 |
url.addQueryItem("api_key", apiKey); |
|
143 |
url.addQueryItem("auth_token", authToken); |
|
144 |
url.addQueryItem("format","json"); |
|
145 |
if(userId.length()) |
|
146 |
url.addQueryItem("user_id", userId); |
|
147 |
url.addQueryItem("method", "flickr.photosets.getList"); |
|
148 |
#ifdef SETLIMITOFFIVEFORSMFDEMO |
|
149 |
url.addQueryItem("page", QString::number(1)); |
|
150 |
url.addQueryItem("per_page", QString::number(5)); |
|
151 |
#else |
|
152 |
url.addQueryItem("page", QString::number(aPageNum)); |
|
153 |
url.addQueryItem("per_page", QString::number(aItemsPerPage)); |
|
154 |
#endif |
|
155 |
url.addQueryItem("api_sig", generateSignature(baseString)); |
|
156 |
||
157 |
// Create the request, set the url |
|
158 |
aRequest.iNetworkRequest.setUrl(url); |
|
159 |
aRequest.iRequestType = SmfPictureGetAlbums; |
|
160 |
aRequest.iPostData = NULL; |
|
161 |
aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation; |
|
162 |
error = SmfPluginErrNone; |
|
163 |
||
164 |
qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString(); |
|
165 |
return error; |
|
166 |
} |
|
167 |
||
168 |
/** |
|
169 |
* Method to get a list of pictures |
|
170 |
* @param aRequest [out] The request data to be sent to network |
|
171 |
* @param aAlbums The album(s) whose pictures are being requested |
|
172 |
* @param aPageNum The page to be extracted |
|
173 |
* @param aItemsPerPage Number of items per page |
|
174 |
* @return SmfPluginError Plugin error if any, else SmfPluginErrNone |
|
175 |
*/ |
|
176 |
SmfPluginError FlickrGalleryPlugin::pictures( SmfPluginRequestData &aRequest, |
|
177 |
const SmfPictureAlbumList &aAlbums, |
|
178 |
const int aPageNum, |
|
179 |
const int aItemsPerPage ) |
|
180 |
{ |
|
181 |
qDebug()<<"Inside FlickrGalleryPlugin::pictures()"; |
|
182 |
||
183 |
SmfPluginError error = SmfPluginErrInvalidArguments; |
|
184 |
||
185 |
if( (aPageNum < 0) || (aItemsPerPage < 0)) |
|
186 |
{ |
|
187 |
qDebug()<<"Invalid arguments"; |
|
188 |
return error; |
|
189 |
} |
|
190 |
||
191 |
// Get the key sets from SMF Plugin Utility class. |
|
192 |
QString apiKey; |
|
193 |
QString apiSecret; |
|
194 |
QString authToken; |
|
195 |
fetchKeys(apiKey, apiSecret, authToken ); |
|
196 |
||
197 |
QString albumId; |
|
198 |
albumId.clear(); |
|
199 |
if(aAlbums.count()) |
|
200 |
{ |
|
201 |
chance = 0; |
|
202 |
albumId = aAlbums.at(0).id(); |
|
203 |
qDebug()<<"Fetching photos from a photoset with its id = "<<albumId; |
|
204 |
} |
|
205 |
else |
|
206 |
{ |
|
207 |
qDebug()<<"Fetching photos which are not in any sets"; |
|
208 |
chance = 1; |
|
209 |
} |
|
210 |
||
211 |
QString extras("date_upload,description,owner_name,tags,url_sq,url_t,url_s,url_m,url_o"); |
|
212 |
||
213 |
// Create the API signature string |
|
214 |
QString baseString; |
|
215 |
baseString.append(apiSecret); |
|
216 |
baseString.append("api_key"+apiKey); |
|
217 |
baseString.append("auth_token"+authToken); |
|
218 |
baseString.append("extras"+extras); |
|
219 |
baseString.append("formatjson"); |
|
220 |
if(aAlbums.count()) |
|
221 |
baseString.append("methodflickr.photosets.getPhotos"); |
|
222 |
else |
|
223 |
baseString.append("methodflickr.photos.getNotInSet"); |
|
224 |
#ifdef SETLIMITOFFIVEFORSMFDEMO |
|
225 |
baseString.append("page"+QString::number(1)); |
|
226 |
baseString.append("per_page"+QString::number(5)); |
|
227 |
#else |
|
228 |
baseString.append("page"+QString::number(aPageNum)); |
|
229 |
baseString.append("per_page"+QString::number(aItemsPerPage)); |
|
230 |
#endif |
|
231 |
if(aAlbums.count()) |
|
232 |
baseString.append("photoset_id"+albumId); |
|
233 |
||
234 |
// Create the url |
|
235 |
QUrl url("http://api.flickr.com/services/rest/?"); |
|
236 |
url.addQueryItem("api_key", apiKey); |
|
237 |
url.addQueryItem("auth_token", authToken); |
|
238 |
url.addQueryItem("extras", extras); |
|
239 |
url.addQueryItem("format","json"); |
|
240 |
if(aAlbums.count()) |
|
241 |
url.addQueryItem("method", "flickr.photosets.getPhotos"); |
|
242 |
else |
|
243 |
url.addQueryItem("method", "flickr.photos.getNotInSet"); |
|
244 |
#ifdef SETLIMITOFFIVEFORSMFDEMO |
|
245 |
url.addQueryItem("page", QString::number(1)); |
|
246 |
url.addQueryItem("per_page", QString::number(5)); |
|
247 |
#else |
|
248 |
url.addQueryItem("page", QString::number(aPageNum)); |
|
249 |
url.addQueryItem("per_page", QString::number(aItemsPerPage)); |
|
250 |
#endif |
|
251 |
if(aAlbums.count()) |
|
252 |
url.addQueryItem("photoset_id", albumId); |
|
253 |
url.addQueryItem("api_sig", generateSignature(baseString)); |
|
254 |
||
255 |
// Create the request, set the url |
|
256 |
aRequest.iNetworkRequest.setUrl(url); |
|
257 |
aRequest.iRequestType = SmfPictureGetPictures; |
|
258 |
aRequest.iPostData = NULL; |
|
259 |
aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation; |
|
260 |
error = SmfPluginErrNone; |
|
261 |
||
262 |
qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString(); |
|
263 |
return error; |
|
264 |
} |
|
265 |
||
266 |
/** |
|
267 |
* Method to get a description |
|
268 |
* @param aRequest [out] The request data to be sent to network |
|
269 |
* @param aImage The image abot which the description is required |
|
270 |
* @return SmfPluginError Plugin error if any, else SmfPluginErrNone |
|
271 |
*/ |
|
272 |
SmfPluginError FlickrGalleryPlugin::description(SmfPluginRequestData &aRequest, |
|
273 |
const SmfPicture &aImage) |
|
274 |
{ |
|
275 |
qDebug()<<"Inside FlickrGalleryPlugin::description()"; |
|
276 |
||
277 |
SmfPluginError error = SmfPluginErrInvalidArguments; |
|
278 |
||
279 |
if( 0 == aImage.id().size()) |
|
280 |
{ |
|
281 |
qDebug()<<"Invalid arguments"; |
|
282 |
return error; |
|
283 |
} |
|
284 |
||
285 |
// Get the key sets from SMF Plugin Utility class. |
|
286 |
QString apiKey; |
|
287 |
QString apiSecret; |
|
288 |
QString authToken; |
|
289 |
fetchKeys(apiKey, apiSecret, authToken ); |
|
290 |
||
291 |
// Create the API signature string |
|
292 |
QString baseString; |
|
293 |
baseString.append(apiSecret); |
|
294 |
baseString.append("api_key"+apiKey); |
|
295 |
baseString.append("auth_token"+authToken); |
|
296 |
baseString.append("formatjson"); |
|
297 |
baseString.append("methodflickr.photos.getInfo"); |
|
298 |
baseString.append("photo_id"+aImage.id()); |
|
299 |
||
300 |
// Create the url |
|
301 |
QUrl url("http://api.flickr.com/services/rest/?"); |
|
302 |
url.addQueryItem("api_key", apiKey); |
|
303 |
url.addQueryItem("auth_token", authToken); |
|
304 |
url.addQueryItem("format","json"); |
|
305 |
url.addQueryItem("method", "flickr.photos.getInfo"); |
|
306 |
url.addQueryItem("photo_id",aImage.id()); |
|
307 |
url.addQueryItem("api_sig", generateSignature(baseString)); |
|
308 |
||
309 |
// Create the request, set the url |
|
310 |
aRequest.iNetworkRequest.setUrl(url); |
|
311 |
aRequest.iRequestType = SmfPictureDescription; |
|
312 |
aRequest.iPostData = NULL; |
|
313 |
aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation; |
|
314 |
error = SmfPluginErrNone; |
|
315 |
||
316 |
qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString(); |
|
317 |
return error; |
|
318 |
} |
|
319 |
||
320 |
||
321 |
/** |
|
322 |
* Method to upload a picture |
|
323 |
* @param aRequest [out] The request data to be sent to network |
|
324 |
* @param aImage The image to be uploaded |
|
325 |
* @param aAlbum the optional destination album name |
|
326 |
* @return SmfPluginError Plugin error if any, else SmfPluginErrNone |
|
327 |
*/ |
|
328 |
SmfPluginError FlickrGalleryPlugin::upload( SmfPluginRequestData &aRequest, |
|
329 |
const SmfPicture &aImage, |
|
330 |
const SmfPictureAlbum* aAlbum ) |
|
331 |
{ |
|
332 |
qDebug()<<"Inside FlickrGalleryPlugin::upload()"; |
|
333 |
Q_UNUSED(aAlbum) |
|
334 |
SmfPluginError error = SmfPluginErrInvalidArguments; |
|
335 |
||
336 |
if( 0 == aImage.picture().byteCount()) |
|
337 |
{ |
|
338 |
qDebug()<<"Invalid arguments"; |
|
339 |
return error; |
|
340 |
} |
|
341 |
||
342 |
// Get the key sets from SMF Plugin Utility class. |
|
343 |
QString apiKey; |
|
344 |
QString apiSecret; |
|
345 |
QString authToken; |
|
346 |
fetchKeys(apiKey, apiSecret, authToken ); |
|
347 |
||
348 |
// Create the Payload data |
|
349 |
QDataStream stream(&payload, QIODevice::WriteOnly); |
|
350 |
int bytes = 0; |
|
351 |
||
352 |
// Create the api_key field |
|
353 |
QByteArray keyField = constructField ( "api_key", apiKey, boundary ); |
|
354 |
bytes = stream.writeRawData(keyField.data(), keyField.length()); |
|
355 |
qDebug()<<"Bytes written for API key field = "<<QString::number(bytes, 10); |
|
356 |
||
357 |
// Create the auth_token field |
|
358 |
QByteArray tokenField = constructField ( "auth_token", authToken, boundary ); |
|
359 |
bytes = stream.writeRawData(tokenField.data(), tokenField.length()); |
|
360 |
qDebug()<<"Bytes written for Auth token field = "<<QString::number(bytes, 10); |
|
361 |
||
362 |
// Create the API signature string |
|
363 |
QString baseString; |
|
364 |
baseString.append(apiSecret); |
|
365 |
baseString.append("api_key"+apiKey); |
|
366 |
baseString.append("auth_token"+authToken); |
|
367 |
baseString = generateSignature(baseString); |
|
368 |
||
369 |
// Create the signature field |
|
370 |
QByteArray sigField = constructField ( "api_sig", baseString, boundary ); |
|
371 |
bytes = stream.writeRawData(sigField.data(), sigField.length()); |
|
372 |
qDebug()<<"Bytes written for API signature field = "<<QString::number(bytes, 10); |
|
373 |
||
374 |
// Create the file header field |
|
375 |
QByteArray fileField = constructField ( "photo", "", boundary, "c:\\data\\TestUploadPics\\BlueHills.jpg" ); |
|
376 |
bytes = stream.writeRawData(fileField.data(), fileField.length()); |
|
377 |
qDebug()<<"Bytes written for File header field = "<<QString::number(bytes, 10); |
|
378 |
||
379 |
// GEt the image data into a Bytearray |
|
380 |
QByteArray pic; |
|
381 |
QBuffer buffer(&pic); |
|
382 |
buffer.open(QIODevice::WriteOnly); |
|
383 |
aImage.picture().save(&buffer, "JPG"); |
|
384 |
||
385 |
qDebug()<<"Number of bytes in the pic = "<<QString::number(pic.size(), 10); |
|
386 |
||
387 |
// Add the file content to the stream |
|
388 |
if(pic.size()) |
|
389 |
{ |
|
390 |
bytes = stream.writeRawData ( pic.data(), pic.length() ); |
|
391 |
qDebug()<<"Bytes written for File content field = "<<QString::number(bytes, 10); |
|
392 |
} |
|
393 |
||
394 |
// Create the end field |
|
395 |
QByteArray endField; |
|
396 |
endField.append ( "\r\n--" ); |
|
397 |
endField.append ( boundary ); |
|
398 |
endField.append ( "--\r\n\r\n" ); |
|
399 |
bytes = stream.writeRawData(endField.data(), endField.length()); |
|
400 |
qDebug()<<"Bytes written for end field = "<<QString::number(bytes, 10); |
|
401 |
||
402 |
QUrl url("http://api.flickr.com/services/upload/"); |
|
403 |
||
404 |
// Create the request, set the url |
|
405 |
aRequest.iNetworkRequest.setUrl(url); |
|
406 |
aRequest.iNetworkRequest.setRawHeader("Content-Type", "multipart/form-data; boundary="+boundary); |
|
407 |
aRequest.iRequestType = SmfPictureUpload; |
|
408 |
aRequest.iPostData = new QBuffer(&payload); |
|
409 |
aRequest.iHttpOperationType = QNetworkAccessManager::PostOperation; |
|
410 |
error = SmfPluginErrNone; |
|
411 |
||
412 |
qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString(); |
|
413 |
return error; |
|
414 |
} |
|
415 |
||
416 |
||
417 |
/** |
|
418 |
* Method to construct individual fields for photo upload |
|
419 |
* @param aName The name argument |
|
420 |
* @param aContent The content of this field |
|
421 |
* @param aBoundary The boundary string (need to be unique in the payload data) |
|
422 |
* @param aFilename The filename if for photo field |
|
423 |
* @return The field data constructed by this method |
|
424 |
*/ |
|
425 |
QByteArray FlickrGalleryPlugin::constructField( const QString &aName, |
|
426 |
const QString &aContent, |
|
427 |
const QByteArray &aBoundary, |
|
428 |
const QString & aFilename ) |
|
429 |
{ |
|
430 |
QByteArray data; |
|
431 |
data.append ( "--" ); |
|
432 |
data.append ( aBoundary ); |
|
433 |
data.append ( "\r\n" ); |
|
434 |
data.append ( "Content-Disposition: form-data; name=\"" ); |
|
435 |
data.append ( aName.toAscii() ); |
|
436 |
if ( aFilename.isEmpty() ) |
|
437 |
{ |
|
438 |
data.append ( "\"\r\n\r\n" ); |
|
439 |
data.append ( aContent.toAscii() ); |
|
440 |
data.append ( "\r\n" ); |
|
441 |
} |
|
442 |
else |
|
443 |
{ |
|
444 |
data.append ( "\"; filename=\"" ); |
|
445 |
data.append ( aFilename.toAscii() ); |
|
446 |
data.append ( "\"\r\n" ); |
|
447 |
data.append ( "Content-Type: image/jpeg\r\n\r\n" ); |
|
448 |
} |
|
449 |
return data; |
|
450 |
} |
|
451 |
||
452 |
||
453 |
/** |
|
454 |
* Method to upload a list of pictures |
|
455 |
* @param aRequest [out] The request data to be sent to network |
|
456 |
* @param aImages The list of images to be uploaded |
|
457 |
* @return SmfPluginError Plugin error if any, else SmfPluginErrNone |
|
458 |
*/ |
|
459 |
SmfPluginError FlickrGalleryPlugin::upload( SmfPluginRequestData &aRequest, |
|
460 |
const QList<SmfPicture> &aImages, |
|
461 |
const SmfPictureAlbum* aAlbum ) |
|
462 |
{ |
|
463 |
SmfPluginError error = SmfPluginErrUserNotLoggedIn; |
|
464 |
qDebug()<<("\r\n multiple Uploaded Pictures.....= "+QString::number(aImages.count(),10)); |
|
465 |
Q_UNUSED(aAlbum) |
|
466 |
// Get the key sets from SMF Plugin Utility class. |
|
467 |
QString apiKey; |
|
468 |
QString apiSecret; |
|
469 |
QString authToken; |
|
470 |
fetchKeys(apiKey, apiSecret, authToken ); |
|
471 |
||
472 |
count =aImages.count(); |
|
473 |
||
474 |
||
475 |
QByteArray boundary("---ThIsIsAsAmPleBouNDaRyStrInGFrOmSaNgEeTa---"); |
|
476 |
QDataStream stream(&payload, QIODevice::WriteOnly); |
|
477 |
int bytes = 0; |
|
478 |
||
479 |
// Create the api_key field |
|
480 |
QByteArray keyField = constructField("api_key",apiKey,boundary,"");//,apiKey,boundary); |
|
481 |
bytes = stream.writeRawData(keyField.data(), keyField.length()); |
|
482 |
qDebug()<<("Bytes written for API key field = "+QString::number(bytes, 10)); |
|
483 |
||
484 |
// Create the auth_token field |
|
485 |
QByteArray tokenField = constructField ( "auth_token", authToken, boundary,""); |
|
486 |
bytes = stream.writeRawData(tokenField.data(), tokenField.length()); |
|
487 |
qDebug()<<("Bytes written for Auth token field = "+QString::number(bytes, 10)); |
|
488 |
||
489 |
//Create the API signature string |
|
490 |
QString baseString; |
|
491 |
baseString.append(apiSecret); |
|
492 |
baseString.append("api_key"+apiKey); |
|
493 |
baseString.append("auth_token"+authToken); |
|
494 |
//baseString.append("formatjson"); //not working this format |
|
495 |
baseString = generateSignature(baseString); |
|
496 |
||
497 |
//extract the smfpicture object |
|
498 |
SmfPicture aImage=aImages[listIndex]; |
|
499 |
||
500 |
//Create the signature field |
|
501 |
QByteArray sigField = constructField ("api_sig", baseString, boundary,"" ); |
|
502 |
bytes = stream.writeRawData(sigField.data(), sigField.length()); |
|
503 |
||
504 |
qDebug()<<("QImage String = "+aImage.url().toString()); |
|
505 |
||
506 |
//Create the file header field |
|
507 |
QByteArray fileField = constructField ( "photo", "", boundary, aImage.url().toString()); |
|
508 |
bytes = stream.writeRawData(fileField.data(), fileField.length()); |
|
509 |
||
510 |
||
511 |
//QByteArray pic ; |
|
512 |
QImage image=aImage.picture(); |
|
513 |
||
514 |
//for checking only |
|
515 |
int byte=image.numBytes(); |
|
516 |
qDebug()<<("Bytes written for QImage = "+QString::number(byte,10)); |
|
517 |
||
518 |
//For finding the format of Image file (eg. c:\\data\\image.jpg); |
|
519 |
QString fileName=aImage.url().toString(); |
|
520 |
int last = fileName.lastIndexOf(".",-1); |
|
521 |
qDebug()<<("last QImage = "+QString::number(last,10)); |
|
522 |
QString Format=fileName.right(fileName.size()-last-1); //-1 for removing "." from .jpg |
|
523 |
qDebug()<<("Format of QImage = "+Format); |
|
524 |
||
525 |
||
526 |
QByteArray pic; |
|
527 |
QBuffer buffer(&pic); |
|
528 |
buffer.open(QIODevice::WriteOnly); |
|
529 |
image.save(&buffer,Format.toLatin1(),-1); // writes image into format given by Format |
|
530 |
||
531 |
qDebug()<<("Number of bytes in the picture = "+QString::number(buffer.size(), 10)); |
|
532 |
||
533 |
// Add the file content to the stream |
|
534 |
if (pic.size()) |
|
535 |
{ |
|
536 |
bytes = stream.writeRawData ( pic.data(), pic.length() ); |
|
537 |
qDebug()<<("Bytes written for File content field = "+QString::number(bytes, 10)); |
|
538 |
} |
|
539 |
qDebug()<<("Before Url string is : "+QString(payload)); |
|
540 |
||
541 |
// Create the end field |
|
542 |
QByteArray endField; |
|
543 |
endField.append ( "\r\n--" ); |
|
544 |
endField.append ( boundary ); |
|
545 |
endField.append ( "--\r\n\r\n" ); |
|
546 |
bytes = stream.writeRawData(endField.data(), endField.length()); |
|
547 |
qDebug()<<("Bytes written for end field = "+QString::number(bytes, 10)); |
|
548 |
||
549 |
//Create the url |
|
550 |
QUrl url("http://api.flickr.com/services/upload/"); |
|
551 |
//url.addQueryItem("format","json"); //Not working |
|
552 |
||
553 |
||
554 |
//Create the request, set the url |
|
555 |
aRequest.iNetworkRequest.setUrl(url); |
|
556 |
||
557 |
aRequest.iNetworkRequest.setRawHeader("Content-Type", "multipart/form-data; boundary="+boundary); |
|
558 |
aRequest.iNetworkRequest.setRawHeader("Host", "api.flickr.com"); |
|
559 |
aRequest.iRequestType = SmfPictureUpload; |
|
560 |
aRequest.iPostData=new QBuffer(&payload); |
|
561 |
||
562 |
||
563 |
aRequest.iHttpOperationType = QNetworkAccessManager::PostOperation; |
|
564 |
error = SmfPluginErrNone; |
|
565 |
return error; |
|
566 |
} |
|
567 |
||
568 |
/** |
|
569 |
* Method to post comment on a picture is available |
|
570 |
* @param aRequest [out] The request data to be sent to network |
|
571 |
* @param aImage The image on which comment is to be posted |
|
572 |
* @param aComment The comment to be posted |
|
573 |
* @return SmfPluginError Plugin error if any, else SmfPluginErrNone |
|
574 |
*/ |
|
575 |
SmfPluginError FlickrGalleryPlugin::postComment( SmfPluginRequestData &aRequest, |
|
576 |
const SmfPicture &aImage, |
|
577 |
const SmfComment &aComment ) |
|
578 |
{ |
|
579 |
qDebug()<<"Inside FlickrGalleryPlugin::postComment()"; |
|
580 |
||
581 |
SmfPluginError error = SmfPluginErrInvalidArguments; |
|
582 |
||
583 |
if( 0 == aImage.id().size() || (0 == aComment.text().size()) ) |
|
584 |
{ |
|
585 |
qDebug()<<"Invalid arguments"; |
|
586 |
return error; |
|
587 |
} |
|
588 |
||
589 |
// Get the key sets from SMF Plugin Utility class. |
|
590 |
QString apiKey; |
|
591 |
QString apiSecret; |
|
592 |
QString authToken; |
|
593 |
fetchKeys(apiKey, apiSecret, authToken ); |
|
594 |
||
595 |
// Create the API signature string |
|
596 |
QString baseString; |
|
597 |
baseString.append(apiSecret); |
|
598 |
baseString.append("api_key"+apiKey); |
|
599 |
baseString.append("auth_token"+authToken); |
|
600 |
baseString.append("comment_text"+aComment.text()); |
|
601 |
baseString.append("formatjson"); |
|
602 |
baseString.append("methodflickr.photos.comments.addComment"); |
|
603 |
baseString.append("photo_id"+aImage.id()); |
|
604 |
||
605 |
// Create the url |
|
606 |
QUrl url("http://api.flickr.com/services/rest/?"); |
|
607 |
url.addQueryItem("api_key", apiKey); |
|
608 |
url.addQueryItem("auth_token", authToken); |
|
609 |
url.addQueryItem("comment_text", aComment.text()); |
|
610 |
url.addQueryItem("format","json"); |
|
611 |
url.addQueryItem("method", "flickr.photos.comments.addComment"); |
|
612 |
url.addQueryItem("photo_id",aImage.id()); |
|
613 |
url.addQueryItem("api_sig", generateSignature(baseString)); |
|
614 |
||
615 |
// Create the request, set the url |
|
616 |
aRequest.iNetworkRequest.setUrl(url); |
|
617 |
aRequest.iRequestType = SmfPicturePostComment; |
|
618 |
aRequest.iPostData = NULL; |
|
619 |
aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation; |
|
620 |
error = SmfPluginErrNone; |
|
621 |
||
622 |
qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString(); |
|
623 |
return error; |
|
624 |
} |
|
625 |
||
626 |
/** |
|
627 |
* Method called by plugins to generate a signature string from a base string |
|
628 |
* @param aBaseString The base string |
|
629 |
* @return The md5 hash of the base string |
|
630 |
*/ |
|
631 |
QString FlickrGalleryPlugin::generateSignature(const QString aBaseString) |
|
632 |
{ |
|
633 |
qDebug()<<("FlickrGalleryPlugin::generateSignature"); |
|
634 |
||
635 |
// Create md5 hash of the signature string |
|
636 |
QByteArray byteArray; |
|
637 |
byteArray.insert(0, aBaseString.toAscii()); |
|
638 |
||
639 |
QByteArray md5Hash = QCryptographicHash::hash(byteArray,QCryptographicHash::Md5 ).toHex(); |
|
640 |
QString returnString (md5Hash); |
|
641 |
return returnString; |
|
642 |
} |
|
643 |
||
644 |
/** |
|
645 |
* Customised method for SmfContactFetcherPlugin interface |
|
646 |
* @param aRequest [out] The request data to be sent to network |
|
647 |
* @param aOperation The operation type (should be known between |
|
648 |
* the client interface and the plugin) |
|
649 |
* @param aData The data required to form the request (The type |
|
650 |
* of data should be known between client and the plugin) |
|
651 |
* @return SmfPluginError Plugin error if any, else SmfPluginErrNone |
|
652 |
*/ |
|
653 |
SmfPluginError FlickrGalleryPlugin::customRequest( SmfPluginRequestData &aRequest, |
|
654 |
const int &aOperation, QByteArray *aData ) |
|
655 |
{ |
|
656 |
Q_UNUSED(aRequest) |
|
657 |
Q_UNUSED(aOperation) |
|
658 |
Q_UNUSED(aData) |
|
659 |
return SmfPluginErrServiceNotSupported; |
|
660 |
} |
|
661 |
||
662 |
/** |
|
663 |
* The first method to be called in the plugin that implements this interface. |
|
664 |
* If this method is not called, plugin may not behave as expected. |
|
665 |
*/ |
|
666 |
void FlickrGalleryPlugin::initialize( ) |
|
667 |
{ |
|
668 |
// Create an instance of FBContactProviderBase |
|
669 |
m_provider = new FlickrProviderBase; |
|
670 |
m_provider->initialize(); |
|
671 |
} |
|
672 |
||
673 |
/** |
|
674 |
* Method to get the provider information |
|
675 |
* @return Instance of SmfProviderBase |
|
676 |
*/ |
|
677 |
SmfProviderBase* FlickrGalleryPlugin::getProviderInfo( ) |
|
678 |
{ |
|
679 |
return m_provider; |
|
680 |
} |
|
681 |
||
682 |
/** |
|
683 |
* Method to get the result for a network request. |
|
684 |
* @param aOperation The type of operation to be requested |
|
685 |
* @param aTransportResult The result of transport operation |
|
686 |
* @param aResponse The QByteArray instance containing the network response. |
|
687 |
* The plugins should delete this instance once they have read the |
|
688 |
* data from it. |
|
689 |
* @param aResult [out] An output parameter to the plugin manager.If the |
|
690 |
* return value is SmfSendRequestAgain, QVariant will be of type |
|
691 |
* SmfPluginRequestData. |
|
692 |
* For SmfGalleryPlugin: If last operation was albums, aResult will be of |
|
693 |
* type QList<SmfPictureAlbum>. If the last operation was pictures(), aResult |
|
694 |
* will be of type QList<SmfPicture>. If last operation was description(), |
|
695 |
* aResult will be of type QString. If last operation was upload() or |
|
696 |
* postComment(), aResult will be of type bool. |
|
697 |
* @param aRetType [out] SmfPluginRetType |
|
698 |
* @param aPageResult [out] The SmfResultPage structure variable |
|
699 |
*/ |
|
700 |
SmfPluginError FlickrGalleryPlugin::responseAvailable( |
|
701 |
const SmfRequestTypeID aOperation, |
|
702 |
const SmfTransportResult &aTransportResult, |
|
703 |
QByteArray *aResponse, |
|
704 |
QVariant* aResult, |
|
705 |
SmfPluginRetType &aRetType, |
|
706 |
SmfResultPage &aPageResult ) |
|
707 |
{ |
|
708 |
||
709 |
qDebug()<<"Inside FlickrGalleryPlugin::responseAvailable()"; |
|
710 |
Q_UNUSED(aPageResult) |
|
711 |
SmfPluginError error = SmfPluginErrNetworkError; |
|
712 |
||
713 |
if( !aResponse || (0 == aResponse->size()) ) |
|
714 |
{ |
|
715 |
qDebug()<<"Response is NULL or empty"; |
|
716 |
aRetType = SmfRequestError; |
|
717 |
return error; |
|
718 |
} |
|
719 |
||
720 |
QByteArray response(*aResponse); |
|
721 |
delete aResponse; |
|
722 |
||
723 |
QFile respFile("c://data//SmfPluginFlickrResponse.txt"); |
|
724 |
if(!respFile.open(QIODevice::WriteOnly)) |
|
725 |
{ |
|
726 |
qDebug()<<"File to write the response could not be opened, so writing to this file"; |
|
727 |
qDebug()<<"Flickr response = "<<QString(response); |
|
728 |
} |
|
729 |
else |
|
730 |
{ |
|
731 |
respFile.write(response); |
|
732 |
respFile.close(); |
|
733 |
qDebug()<<"Writing FB response to a file named 'SmfPluginFlickrResponse.txt'"; |
|
734 |
} |
|
735 |
||
736 |
qDebug()<<"Response size = "<<response.size(); |
|
737 |
||
738 |
||
739 |
if(SmfTransportOpNoError == aTransportResult) |
|
740 |
{ |
|
741 |
qDebug()<<"No transport error"; |
|
742 |
||
743 |
if(SmfPictureGetAlbums == aOperation) |
|
744 |
{ |
|
745 |
qDebug()<<"Response for retrieving album lists"; |
|
746 |
||
747 |
QList<SmfPictureAlbum> albumList; |
|
748 |
QString errStr; |
|
749 |
errStr.clear(); |
|
750 |
||
751 |
// Remove the "jsonFlickrApi(" from starting of the response and ")" from its end |
|
752 |
response.remove(0, 14); |
|
753 |
response.chop(1); |
|
754 |
||
755 |
bool ok; |
|
756 |
SmfPluginUtil util; |
|
757 |
QVariantMap result = util.parse(response, &ok).toMap(); |
|
758 |
if (!ok) |
|
759 |
{ |
|
760 |
qDebug()<<"An error occurred during json parsing"; |
|
761 |
aRetType = SmfRequestError; |
|
762 |
return SmfPluginErrParsingFailed; |
|
763 |
} |
|
764 |
||
765 |
||
766 |
if(response.contains(QByteArray("fail"))) |
|
767 |
{ |
|
768 |
errStr.append(result["message"].toString()); |
|
769 |
} |
|
770 |
else |
|
771 |
{ |
|
772 |
QVariantMap map1 = result["photosets"].toMap(); |
|
773 |
||
774 |
QList<QVariant> list1 = map1["photoset"].toList(); |
|
775 |
QListIterator<QVariant> iter(list1); |
|
776 |
while(iter.hasNext()) |
|
777 |
{ |
|
778 |
SmfPictureAlbum album; |
|
779 |
||
780 |
QVariantMap map2 = iter.next().toMap(); |
|
781 |
||
782 |
// Set the album's title |
|
783 |
QVariantMap map3 = map2["title"].toMap(); |
|
784 |
album.setTitle(map3["_content"].toString()); |
|
785 |
qDebug()<<"title = "<<album.title(); |
|
786 |
||
787 |
// Set the album's description |
|
788 |
QVariantMap map4 = map2["description"].toMap(); |
|
789 |
album.setDescription(map4["_content"].toString()); |
|
790 |
qDebug()<<"desc = "<<album.description(); |
|
791 |
||
792 |
// Set the album's picture count |
|
793 |
album.setPictureCount(map2["photos"].toInt()); |
|
794 |
qDebug()<<"pic count = "<<album.pictureCount(); |
|
795 |
||
796 |
// Set the album's id |
|
797 |
album.setId(map2["id"].toString()); |
|
798 |
qDebug()<<"id = "<<album.id(); |
|
799 |
||
800 |
albumList.append(album); |
|
801 |
#ifdef SETLIMITOFFIVEFORSMFDEMO |
|
802 |
if(5 == albumList.count()) |
|
803 |
break; |
|
804 |
#endif |
|
805 |
} |
|
806 |
} |
|
807 |
||
808 |
if(errStr.size()) |
|
809 |
{ |
|
810 |
qDebug()<<"Response error found = "<<errStr; |
|
811 |
error = SmfPluginErrInvalidRequest; |
|
812 |
aRetType = SmfRequestError; |
|
813 |
aResult->setValue(errStr); |
|
814 |
} |
|
815 |
else |
|
816 |
{ |
|
817 |
qDebug()<<"list count = "<<albumList.count(); |
|
818 |
aResult->setValue(albumList); |
|
819 |
aRetType = SmfRequestComplete; |
|
820 |
error = SmfPluginErrNone; |
|
821 |
} |
|
822 |
} |
|
823 |
else if(SmfPictureGetPictures == aOperation) |
|
824 |
{ |
|
825 |
qDebug()<<"Response for retrieving photos"; |
|
826 |
||
827 |
QList<SmfPicture> picList; |
|
828 |
QString errStr; |
|
829 |
errStr.clear(); |
|
830 |
||
831 |
// Remove the "jsonFlickrApi(" from starting of the response and ")" from its end |
|
832 |
response.remove(0, 14); |
|
833 |
response.chop(1); |
|
834 |
||
835 |
bool ok; |
|
836 |
SmfPluginUtil util; |
|
837 |
QVariantMap result = util.parse(response, &ok).toMap(); |
|
838 |
if (!ok) |
|
839 |
{ |
|
840 |
qDebug()<<"An error occurred during json parsing"; |
|
841 |
aRetType = SmfRequestError; |
|
842 |
return SmfPluginErrParsingFailed; |
|
843 |
} |
|
844 |
||
845 |
||
846 |
if(response.contains(QByteArray("fail"))) |
|
847 |
{ |
|
848 |
errStr.append(result["message"].toString()); |
|
849 |
} |
|
850 |
else |
|
851 |
{ |
|
852 |
QVariantMap map1; |
|
853 |
if(0 == chance) |
|
854 |
map1 = result["photoset"].toMap(); |
|
855 |
else |
|
856 |
map1 = result["photos"].toMap(); |
|
857 |
||
858 |
QList<QVariant> list1 = map1["photo"].toList(); |
|
859 |
QListIterator<QVariant> iter(list1); |
|
860 |
while(iter.hasNext()) |
|
861 |
{ |
|
862 |
SmfPicture pic; |
|
863 |
||
864 |
QVariantMap map2 = iter.next().toMap(); |
|
865 |
||
866 |
// Set the pic's id |
|
867 |
pic.setId(map2["id"].toString()); |
|
868 |
||
869 |
// Set the pic's description |
|
870 |
QVariantMap map3 = map2["description"].toMap(); |
|
871 |
pic.setDescription(map3["_content"].toString()); |
|
872 |
||
873 |
// Set the pic's title |
|
874 |
pic.setTitle(map2["title"].toString()); |
|
875 |
qDebug()<<"title = "<<map2["title"].toString(); |
|
876 |
||
877 |
// Set the pic's owner |
|
878 |
pic.setOwner(map2["ownername"].toString()); |
|
879 |
||
880 |
// Set the pic's posted date |
|
881 |
QDateTime date = QDateTime::fromTime_t(map2["dateupload"].toUInt()); |
|
882 |
qDebug()<<"time = "<<date; |
|
883 |
pic.setPostedDate(date); |
|
884 |
||
885 |
// Set the pic's tags |
|
886 |
QString tags(map2["tags"].toString()); |
|
887 |
QStringList tagList = tags.split(' '); |
|
888 |
pic.addTags(tagList); |
|
889 |
||
890 |
// Set the pic's url |
|
891 |
// url_sq,url_t,url_s,url_m,url_o |
|
892 |
if(map2["url_o"].toString().size()) |
|
893 |
pic.setUrl(map2["url_o"].toString()); |
|
894 |
else if(map2["url_m"].toString().size()) |
|
895 |
pic.setUrl(map2["url_m"].toString()); |
|
896 |
else if(map2["url_sq"].toString().size()) |
|
897 |
pic.setUrl(map2["url_sq"].toString()); |
|
898 |
else if(map2["url_s"].toString().size()) |
|
899 |
pic.setUrl(map2["url_s"].toString()); |
|
900 |
else if(map2["url_t"].toString().size()) |
|
901 |
pic.setUrl(map2["url_t"].toString()); |
|
902 |
||
903 |
qDebug()<<"url = "<<pic.url(); |
|
904 |
picList.append(pic); |
|
905 |
} |
|
906 |
} |
|
907 |
||
908 |
if(errStr.size()) |
|
909 |
{ |
|
910 |
qDebug()<<"Response error found = "<<errStr; |
|
911 |
error = SmfPluginErrInvalidRequest; |
|
912 |
aRetType = SmfRequestError; |
|
913 |
aResult->setValue(errStr); |
|
914 |
} |
|
915 |
else |
|
916 |
{ |
|
917 |
qDebug()<<"list count = "<<picList.count(); |
|
918 |
aResult->setValue(picList); |
|
919 |
aRetType = SmfRequestComplete; |
|
920 |
error = SmfPluginErrNone; |
|
921 |
} |
|
922 |
} |
|
923 |
else if(SmfPictureDescription == aOperation) |
|
924 |
{ |
|
925 |
qDebug()<<"Response for photo decscription"; |
|
926 |
||
927 |
QString description; |
|
928 |
QString errStr; |
|
929 |
errStr.clear(); |
|
930 |
||
931 |
// Remove the "jsonFlickrApi(" from starting of the response and ")" from its end |
|
932 |
response.remove(0, 14); |
|
933 |
response.chop(1); |
|
934 |
||
935 |
bool ok; |
|
936 |
SmfPluginUtil util; |
|
937 |
QVariantMap result = util.parse(response, &ok).toMap(); |
|
938 |
if (!ok) |
|
939 |
{ |
|
940 |
qDebug()<<"An error occurred during json parsing"; |
|
941 |
aRetType = SmfRequestError; |
|
942 |
return SmfPluginErrParsingFailed; |
|
943 |
} |
|
944 |
||
945 |
if(response.contains(QByteArray("fail"))) |
|
946 |
{ |
|
947 |
errStr.append(result["message"].toString()); |
|
948 |
} |
|
949 |
else |
|
950 |
{ |
|
951 |
QVariantMap map1 = result["photo"].toMap(); |
|
952 |
QVariantMap map2 = map1["description"].toMap(); |
|
953 |
||
954 |
description = map2["_content"].toString(); |
|
955 |
} |
|
956 |
||
957 |
if(errStr.size()) |
|
958 |
{ |
|
959 |
qDebug()<<"Response error found = "<<errStr; |
|
960 |
error = SmfPluginErrInvalidRequest; |
|
961 |
aRetType = SmfRequestError; |
|
962 |
aResult->setValue(errStr); |
|
963 |
} |
|
964 |
else |
|
965 |
{ |
|
966 |
qDebug()<<"description = "<<description; |
|
967 |
aResult->setValue(description); |
|
968 |
aRetType = SmfRequestComplete; |
|
969 |
error = SmfPluginErrNone; |
|
970 |
} |
|
971 |
} |
|
972 |
else if (SmfPictureUpload == aOperation) |
|
973 |
{ |
|
974 |
#if 1 |
|
975 |
qDebug()<<"Response for single photo upload"; |
|
976 |
||
977 |
bool uploaded = false; |
|
978 |
QString errStr; |
|
979 |
errStr.clear(); |
|
980 |
||
981 |
if(response.contains(QByteArray("err code"))) |
|
982 |
{ |
|
983 |
QXmlStreamReader xml(response); |
|
984 |
while (!xml.atEnd()) |
|
985 |
{ |
|
986 |
xml.readNext(); |
|
987 |
if (xml.tokenType() == QXmlStreamReader::StartElement) |
|
988 |
if (xml.name() == "err") |
|
989 |
errStr.append(xml.attributes().value("msg")); |
|
990 |
} |
|
991 |
} |
|
992 |
else |
|
993 |
uploaded = true; |
|
994 |
||
995 |
if(errStr.size()) |
|
996 |
{ |
|
997 |
qDebug()<<"Response error found = "<<errStr; |
|
998 |
error = SmfPluginErrInvalidRequest; |
|
999 |
aRetType = SmfRequestError; |
|
1000 |
aResult->setValue(errStr); |
|
1001 |
} |
|
1002 |
else |
|
1003 |
{ |
|
1004 |
qDebug()<<"photo uploaded ? "<<uploaded; |
|
1005 |
aResult->setValue(uploaded); |
|
1006 |
aRetType = SmfRequestComplete; |
|
1007 |
error = SmfPluginErrNone; |
|
1008 |
} |
|
1009 |
#endif |
|
1010 |
} |
|
23
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1011 |
else if (SmfPictureMultiUpload == aOperation) |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1012 |
{ |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1013 |
bool result; |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1014 |
qDebug()<<("SmfMultiPictureUpload"); |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1015 |
QXmlStreamReader xml(response); |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1016 |
while (!xml.atEnd()) |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1017 |
{ |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1018 |
xml.readNext(); |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1019 |
if (xml.tokenType() == QXmlStreamReader::StartElement) |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1020 |
{ |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1021 |
qDebug()<<("inside tag"); |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1022 |
//If the tag is contact |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1023 |
if (xml.name() == "photoid") |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1024 |
{ |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1025 |
qDebug()<<("photoid tag found"); |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1026 |
result=TRUE; |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1027 |
} |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1028 |
else |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1029 |
result=FALSE; |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1030 |
}//end If |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1031 |
}//endWhile; |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1032 |
|
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1033 |
aResult->setValue(result); |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1034 |
if (listIndex < count) |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1035 |
{ |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1036 |
listIndex=listIndex+1; |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1037 |
error = SmfPluginErrNone; |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1038 |
aRetType = SmfSendRequestAgain; |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1039 |
|
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1040 |
} |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1041 |
else |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1042 |
{ |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1043 |
//Final result sent |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1044 |
count=1; //clear counter |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1045 |
aRetType = SmfRequestComplete; |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1046 |
error = SmfPluginErrNone; |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1047 |
} |
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1048 |
|
574948b60dab
updating the lastfm music plugins and adding the smfhelp.chm
cgandhi
parents:
17
diff
changeset
|
1049 |
} |
17 | 1050 |
else if (SmfPicturePostComment == aOperation) |
1051 |
{ |
|
1052 |
qDebug()<<"Response for adding comment on a photo"; |
|
1053 |
||
1054 |
bool commentPosted = false; |
|
1055 |
QString errStr; |
|
1056 |
errStr.clear(); |
|
1057 |
||
1058 |
// Remove the "jsonFlickrApi(" from starting of the response and ")" from its end |
|
1059 |
response.remove(0, 14); |
|
1060 |
response.chop(1); |
|
1061 |
||
1062 |
bool ok; |
|
1063 |
SmfPluginUtil util; |
|
1064 |
QVariantMap result = util.parse(response, &ok).toMap(); |
|
1065 |
if (!ok) |
|
1066 |
{ |
|
1067 |
qDebug()<<"An error occurred during json parsing"; |
|
1068 |
aRetType = SmfRequestError; |
|
1069 |
return SmfPluginErrParsingFailed; |
|
1070 |
} |
|
1071 |
||
1072 |
if(response.contains(QByteArray("fail"))) |
|
1073 |
{ |
|
1074 |
errStr.append(result["message"].toString()); |
|
1075 |
} |
|
1076 |
else |
|
1077 |
{ |
|
1078 |
qDebug()<<"Comment posted on the photo"; |
|
1079 |
commentPosted = true; |
|
1080 |
} |
|
1081 |
||
1082 |
if(errStr.size()) |
|
1083 |
{ |
|
1084 |
qDebug()<<"Response error found = "<<errStr; |
|
1085 |
error = SmfPluginErrInvalidRequest; |
|
1086 |
aRetType = SmfRequestError; |
|
1087 |
aResult->setValue(errStr); |
|
1088 |
} |
|
1089 |
else |
|
1090 |
{ |
|
1091 |
qDebug()<<"comment posted ? "<<commentPosted; |
|
1092 |
aResult->setValue(commentPosted); |
|
1093 |
aRetType = SmfRequestComplete; |
|
1094 |
error = SmfPluginErrNone; |
|
1095 |
} |
|
1096 |
} |
|
1097 |
else |
|
1098 |
{ |
|
1099 |
qDebug()<<"Service unsupported, currently only SmfContactRetrievePosts and SmfContactPostDirected!!!"; |
|
1100 |
aRetType = SmfRequestError; |
|
1101 |
error = SmfPluginErrServiceNotSupported; |
|
1102 |
} |
|
1103 |
} |
|
1104 |
||
1105 |
else if(SmfTransportOpOperationCanceledError == aTransportResult) |
|
1106 |
{ |
|
1107 |
qDebug()<<"Operation Cancelled !!!"; |
|
1108 |
error = SmfPluginErrCancelComplete; |
|
1109 |
aRetType = SmfRequestComplete; |
|
1110 |
} |
|
1111 |
||
1112 |
else |
|
1113 |
{ |
|
1114 |
qDebug()<<"Transport Error !!!"; |
|
1115 |
error = SmfPluginErrNetworkError; |
|
1116 |
aRetType = SmfRequestError; |
|
1117 |
} |
|
1118 |
||
1119 |
return error; |
|
1120 |
||
1121 |
||
1122 |
||
1123 |
||
1124 |
||
1125 |
||
1126 |
||
1127 |
||
1128 |
||
1129 |
||
1130 |
||
1131 |
||
1132 |
||
1133 |
||
1134 |
||
1135 |
||
1136 |
||
1137 |
#if 0 |
|
1138 |
qDebug()<<("FlickrGalleryPlugin::responseAvailable"); |
|
1139 |
Q_UNUSED(aPageResult) |
|
1140 |
SmfPluginError error = SmfPluginErrNetworkError; |
|
1141 |
||
1142 |
if( !aResponse || (0 == aResponse->size()) ) |
|
1143 |
{ |
|
1144 |
qDebug()<<("Response is NULL or empty"); |
|
1145 |
aRetType = SmfRequestError; |
|
1146 |
return error; |
|
1147 |
} |
|
1148 |
||
1149 |
QByteArray response(*aResponse); |
|
1150 |
delete aResponse; |
|
1151 |
||
1152 |
//Write the response to a file |
|
1153 |
QFile file("c:\\data\\flickrresponse.txt"); |
|
1154 |
qDebug()<<("response data written to c:\\data\\flickrresponse.txt"); |
|
1155 |
||
1156 |
if (!file.open(QIODevice::Append | QIODevice::Text)); |
|
1157 |
file.write(response); |
|
1158 |
file.close(); |
|
1159 |
||
1160 |
qDebug()<<("Gallery response size = "+QString::number(response.size(), 10)); |
|
1161 |
||
1162 |
QList<SmfPicture> list; |
|
1163 |
||
1164 |
if(SmfTransportOpNoError == aTransportResult) |
|
1165 |
{ |
|
1166 |
qDebug()<<("No transport error"); |
|
1167 |
QVariantMap map1; |
|
1168 |
bool resType=response.startsWith("<?xml"); |
|
1169 |
if(resType) //XML REsponse |
|
1170 |
{ |
|
1171 |
qDebug()<<("Before XML Parser--"); |
|
1172 |
||
1173 |
} |
|
1174 |
else //JSON RESPONSE |
|
1175 |
{ |
|
1176 |
response.remove(0, 14); |
|
1177 |
response.chop(1); |
|
1178 |
bool ok; |
|
1179 |
qDebug()<<("Before JSON Parser--"); |
|
1180 |
||
1181 |
SmfPluginUtil util; |
|
1182 |
QVariant result= util.parse(response, &ok); |
|
1183 |
if (!ok) |
|
1184 |
{ |
|
1185 |
qDebug()<<("An error occurred during json parsing"); |
|
1186 |
aRetType = SmfRequestError; |
|
1187 |
return SmfPluginErrParsingFailed; |
|
1188 |
} |
|
1189 |
||
1190 |
QVariantMap map1 = result.toMap(); |
|
1191 |
} |
|
1192 |
if( SmfPictureGetAlbums == aOperation ) |
|
1193 |
{} |
|
1194 |
||
1195 |
} |
|
1196 |
else if(SmfPictureGetPictures == aOperation) |
|
1197 |
{}//end of if(SmfPictureGetPictures == aOperation) |
|
1198 |
else if(SmfPicturePostComment == aOperation) |
|
1199 |
{} |
|
1200 |
else if(SmfPictureDescription == aOperation) |
|
1201 |
{} |
|
1202 |
else if(SmfPictureUpload == aOperation) |
|
1203 |
{ |
|
1204 |
bool result; |
|
1205 |
qDebug()<<("SmfPictureUpload"); |
|
1206 |
QXmlStreamReader xml(response); |
|
1207 |
while (!xml.atEnd()) |
|
1208 |
{ |
|
1209 |
xml.readNext(); |
|
1210 |
if (xml.tokenType() == QXmlStreamReader::StartElement) |
|
1211 |
{ |
|
1212 |
||
1213 |
qDebug()<<("inside tag"); |
|
1214 |
//If the tag is contact |
|
1215 |
if (xml.name() == "photoid") |
|
1216 |
{ |
|
1217 |
qDebug()<<("photoid tag found"); |
|
1218 |
result=TRUE; |
|
1219 |
} |
|
1220 |
else |
|
1221 |
result=FALSE; |
|
1222 |
} |
|
1223 |
} |
|
1224 |
||
1225 |
aResult->setValue(result); |
|
1226 |
aRetType = SmfRequestComplete; |
|
1227 |
error = SmfPluginErrNone; |
|
1228 |
||
1229 |
} |
|
1230 |
else if (SmfPictureMultiUpload == aOperation) |
|
1231 |
{ |
|
1232 |
bool result; |
|
1233 |
qDebug()<<("SmfPictureUpload"); |
|
1234 |
QXmlStreamReader xml(response); |
|
1235 |
while (!xml.atEnd()) |
|
1236 |
{ |
|
1237 |
xml.readNext(); |
|
1238 |
if (xml.tokenType() == QXmlStreamReader::StartElement) |
|
1239 |
{ |
|
1240 |
qDebug()<<("inside tag"); |
|
1241 |
//If the tag is contact |
|
1242 |
if (xml.name() == "photoid") |
|
1243 |
{ |
|
1244 |
qDebug()<<("photoid tag found"); |
|
1245 |
result=TRUE; |
|
1246 |
} |
|
1247 |
else |
|
1248 |
result=FALSE; |
|
1249 |
}//end If |
|
1250 |
}//endWhile; |
|
1251 |
||
1252 |
aResult->setValue(result); |
|
1253 |
if (listIndex < count) |
|
1254 |
{ |
|
1255 |
||
1256 |
listIndex=listIndex+1; |
|
1257 |
error = SmfPluginErrNone; |
|
1258 |
aRetType = SmfSendRequestAgain; |
|
1259 |
||
1260 |
||
1261 |
} |
|
1262 |
else |
|
1263 |
{ |
|
1264 |
//Final result sent |
|
1265 |
count=1; //clear counter |
|
1266 |
aRetType = SmfRequestComplete; |
|
1267 |
error = SmfPluginErrNone; |
|
1268 |
} |
|
1269 |
||
1270 |
} |
|
1271 |
else |
|
1272 |
{ |
|
1273 |
qDebug()<<("Service unsupported!!!"); |
|
1274 |
aRetType = SmfRequestError; |
|
1275 |
error = SmfPluginErrServiceNotSupported; |
|
1276 |
} |
|
1277 |
}//end if of if(SmfTransportOpNoError == aTransportResult) |
|
1278 |
||
1279 |
else if(SmfTransportOpOperationCanceledError == aTransportResult) |
|
1280 |
{ |
|
1281 |
qDebug()<<("Operation Cancelled !!!"); |
|
1282 |
error = SmfPluginErrCancelComplete; |
|
1283 |
aRetType = SmfRequestComplete; |
|
1284 |
} |
|
1285 |
||
1286 |
else |
|
1287 |
{ |
|
1288 |
qDebug()<<("Transport Error !!!"); |
|
1289 |
error = SmfPluginErrNetworkError; |
|
1290 |
aRetType = SmfRequestError; |
|
1291 |
} |
|
1292 |
return error; |
|
1293 |
#endif |
|
1294 |
||
1295 |
} |
|
1296 |
||
1297 |
||
1298 |
/** |
|
1299 |
* Destructor |
|
1300 |
*/ |
|
1301 |
FlickrProviderBase::~FlickrProviderBase( ) |
|
1302 |
{ |
|
1303 |
} |
|
1304 |
||
1305 |
/** |
|
1306 |
* Method to get the Localisable name of the service. |
|
1307 |
* @return The Localisable name of the service. |
|
1308 |
*/ |
|
1309 |
QString FlickrProviderBase::serviceName( ) const |
|
1310 |
{ |
|
1311 |
return m_serviceName; |
|
1312 |
} |
|
1313 |
||
1314 |
/** |
|
1315 |
* Method to get the Logo of the service |
|
1316 |
* @return The Logo of the service |
|
1317 |
*/ |
|
1318 |
QImage FlickrProviderBase::serviceIcon( ) const |
|
1319 |
{ |
|
1320 |
return m_serviceIcon; |
|
1321 |
} |
|
1322 |
||
1323 |
/** |
|
1324 |
* Method to get the Readable service description |
|
1325 |
* @return The Readable service description |
|
1326 |
*/ |
|
1327 |
QString FlickrProviderBase::description( ) const |
|
1328 |
{ |
|
1329 |
return m_description; |
|
1330 |
} |
|
1331 |
||
1332 |
/** |
|
1333 |
* Method to get the Website of the service |
|
1334 |
* @return The Website of the service |
|
1335 |
*/ |
|
1336 |
QUrl FlickrProviderBase::serviceUrl( ) const |
|
1337 |
{ |
|
1338 |
return m_serviceUrl; |
|
1339 |
} |
|
1340 |
||
1341 |
/** |
|
1342 |
* Method to get the URL of the Application providing this service |
|
1343 |
* @return The URL of the Application providing this service |
|
1344 |
*/ |
|
1345 |
QUrl FlickrProviderBase::applicationUrl( ) const |
|
1346 |
{ |
|
1347 |
return m_applicationUrl; |
|
1348 |
} |
|
1349 |
||
1350 |
/** |
|
1351 |
* Method to get the Icon of the application |
|
1352 |
* @return The Icon of the application |
|
1353 |
*/ |
|
1354 |
QImage FlickrProviderBase::applicationIcon( ) const |
|
1355 |
{ |
|
1356 |
return m_applicationIcon; |
|
1357 |
} |
|
1358 |
||
1359 |
/** |
|
1360 |
* Method to get the list of interfaces that this provider support |
|
1361 |
* @return List of supported Interafces |
|
1362 |
*/ |
|
1363 |
QList<QString> FlickrProviderBase::supportedInterfaces( ) const |
|
1364 |
{ |
|
1365 |
return m_supportedInterfaces; |
|
1366 |
} |
|
1367 |
||
1368 |
/** |
|
1369 |
* Method to get the list of languages supported by this service provider |
|
1370 |
* @return a QStringList of languages supported by this service |
|
1371 |
* provider in 2 letter ISO 639-1 format. |
|
1372 |
*/ |
|
1373 |
QStringList FlickrProviderBase::supportedLanguages( ) const |
|
1374 |
{ |
|
1375 |
return m_supportedLangs; |
|
1376 |
} |
|
1377 |
||
1378 |
/** |
|
1379 |
* Method to get the Plugin specific ID |
|
1380 |
* @return The Plugin specific ID |
|
1381 |
*/ |
|
1382 |
QString FlickrProviderBase::pluginId( ) const |
|
1383 |
{ |
|
1384 |
return m_pluginId; |
|
1385 |
} |
|
1386 |
||
1387 |
/** |
|
1388 |
* Method to get the ID of the authentication application |
|
1389 |
* for this service |
|
1390 |
* @param aProgram The authentication application name |
|
1391 |
* @param aArguments List of arguments required for authentication app |
|
1392 |
* @param aMode Strting mode for authentication application |
|
1393 |
* @return The ID of the authentication application |
|
1394 |
*/ |
|
1395 |
QString FlickrProviderBase::authenticationApp( QString &aProgram, |
|
1396 |
QStringList & aArguments, |
|
1397 |
QIODevice::OpenModeFlag aMode ) const |
|
1398 |
{ |
|
1399 |
Q_UNUSED(aProgram) |
|
1400 |
Q_UNUSED(aArguments) |
|
1401 |
Q_UNUSED(aMode) |
|
1402 |
return m_authAppId; |
|
1403 |
} |
|
1404 |
||
1405 |
/** |
|
1406 |
* Method to get the unique registration ID provided by the |
|
1407 |
* Smf for authorised plugins |
|
1408 |
* @return The unique registration ID/token provided by the Smf for |
|
1409 |
* authorised plugins |
|
1410 |
*/ |
|
1411 |
QString FlickrProviderBase::smfRegistrationId( ) const |
|
1412 |
{ |
|
1413 |
return m_smfRegToken; |
|
1414 |
} |
|
1415 |
||
1416 |
void FlickrProviderBase::initialize() |
|
1417 |
{ |
|
1418 |
m_serviceName = "Flickr"; |
|
1419 |
m_description = "Flickr gallery plugin description"; |
|
1420 |
m_serviceUrl = QUrl(QString("http://api.flickr.com")); |
|
1421 |
m_pluginId = "flickrgalleryplugin.qtplugin"; |
|
1422 |
m_authAppId = "0xE1D8C7D7"; |
|
1423 |
m_supportedInterfaces.append("org.symbian.smf.plugin.gallery/v0.2"); |
|
1424 |
QSettings iSettings; |
|
1425 |
m_smfRegToken = iSettings.value("CMFlickrRegToken").toString(); |
|
1426 |
m_validity = iSettings.value("FlckrExpiryTime").toDateTime(); |
|
1427 |
} |
|
1428 |
||
1429 |
||
1430 |
/* |
|
1431 |
* Export Macro |
|
1432 |
* plugin name : flickrGalleryplugin |
|
1433 |
* plugin class : FlickrGalleryPlugin |
|
1434 |
*/ |
|
1435 |
Q_EXPORT_PLUGIN2( flickrgalleryplugin, FlickrGalleryPlugin ) |