example/flickrgalleryplugin/flickrgalleryplugin.cpp
changeset 17 106a4bfcb866
child 23 574948b60dab
equal deleted inserted replaced
16:b78fa4cdbf2b 17:106a4bfcb866
       
     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 
       
    34 static int count = 1;
       
    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 			}
       
  1011 		else if (SmfPicturePostComment == aOperation)
       
  1012 			{
       
  1013 			qDebug()<<"Response for adding comment on a photo";
       
  1014 	
       
  1015 			bool commentPosted = false;
       
  1016 			QString errStr;
       
  1017 			errStr.clear();
       
  1018 			
       
  1019 			// Remove the "jsonFlickrApi(" from starting of the response and ")" from its end
       
  1020 			response.remove(0, 14);
       
  1021 			response.chop(1);
       
  1022 			
       
  1023 			bool ok;
       
  1024 			SmfPluginUtil util;
       
  1025 			QVariantMap result = util.parse(response, &ok).toMap();
       
  1026 			if (!ok) 
       
  1027 				{
       
  1028 				qDebug()<<"An error occurred during json parsing";
       
  1029 				aRetType = SmfRequestError;
       
  1030 				return SmfPluginErrParsingFailed;
       
  1031 				}
       
  1032 	
       
  1033 			if(response.contains(QByteArray("fail")))
       
  1034 				{
       
  1035 				errStr.append(result["message"].toString());
       
  1036 				}
       
  1037 			else
       
  1038 				{
       
  1039 				qDebug()<<"Comment posted on the photo";
       
  1040 				commentPosted = true;
       
  1041 				}
       
  1042 			
       
  1043 			if(errStr.size())
       
  1044 				{
       
  1045 				qDebug()<<"Response error found = "<<errStr;
       
  1046 				error = SmfPluginErrInvalidRequest;
       
  1047 				aRetType = SmfRequestError;
       
  1048 				aResult->setValue(errStr);
       
  1049 				}
       
  1050 			else
       
  1051 				{
       
  1052 				qDebug()<<"comment posted ? "<<commentPosted;
       
  1053 				aResult->setValue(commentPosted);
       
  1054 				aRetType = SmfRequestComplete;
       
  1055 				error = SmfPluginErrNone;
       
  1056 				}
       
  1057 			}
       
  1058 		else
       
  1059 			{
       
  1060 			qDebug()<<"Service unsupported, currently only SmfContactRetrievePosts and SmfContactPostDirected!!!";
       
  1061 			aRetType = SmfRequestError;
       
  1062 			error = SmfPluginErrServiceNotSupported;
       
  1063 			}
       
  1064 		}
       
  1065 
       
  1066 	else if(SmfTransportOpOperationCanceledError == aTransportResult)
       
  1067 		{
       
  1068 		qDebug()<<"Operation Cancelled !!!";
       
  1069 		error = SmfPluginErrCancelComplete;
       
  1070 		aRetType = SmfRequestComplete;
       
  1071 		}
       
  1072 
       
  1073 	else
       
  1074 		{
       
  1075 		qDebug()<<"Transport Error !!!";
       
  1076 		error = SmfPluginErrNetworkError;
       
  1077 		aRetType = SmfRequestError;
       
  1078 		}
       
  1079 	
       
  1080 	return error;
       
  1081 	
       
  1082 	
       
  1083 	
       
  1084 	
       
  1085 	
       
  1086 	
       
  1087 	
       
  1088 	
       
  1089 	
       
  1090 	
       
  1091 	
       
  1092 	
       
  1093 	
       
  1094 	
       
  1095 	
       
  1096 	
       
  1097 	
       
  1098 #if 0
       
  1099 	qDebug()<<("FlickrGalleryPlugin::responseAvailable");
       
  1100 	Q_UNUSED(aPageResult)
       
  1101 	SmfPluginError error = SmfPluginErrNetworkError;
       
  1102 
       
  1103 	if( !aResponse || (0 == aResponse->size()) )
       
  1104 		{
       
  1105 		qDebug()<<("Response is NULL or empty");
       
  1106 		aRetType = SmfRequestError;
       
  1107 		return error;
       
  1108 		}
       
  1109 	
       
  1110 	QByteArray response(*aResponse);
       
  1111 	delete aResponse;
       
  1112 	
       
  1113 	//Write the response to a file
       
  1114 	QFile file("c:\\data\\flickrresponse.txt");
       
  1115 	qDebug()<<("response data written to c:\\data\\flickrresponse.txt");
       
  1116 			
       
  1117 	if (!file.open(QIODevice::Append | QIODevice::Text));
       
  1118 	file.write(response);
       
  1119 	file.close();
       
  1120 	
       
  1121 	qDebug()<<("Gallery response size = "+QString::number(response.size(), 10));
       
  1122 	
       
  1123 	QList<SmfPicture> list;
       
  1124 	
       
  1125 	if(SmfTransportOpNoError == aTransportResult)
       
  1126 		{
       
  1127 		  qDebug()<<("No transport error");
       
  1128 		  QVariantMap map1;
       
  1129 		  bool resType=response.startsWith("<?xml");
       
  1130 		  if(resType) //XML REsponse
       
  1131 			{
       
  1132 		       qDebug()<<("Before XML Parser--");
       
  1133 			  
       
  1134 		  }
       
  1135 		  else //JSON RESPONSE
       
  1136 		  {
       
  1137 			  response.remove(0, 14);
       
  1138 			  response.chop(1);
       
  1139 			  bool ok;
       
  1140 			  qDebug()<<("Before JSON Parser--");
       
  1141 	
       
  1142 			  SmfPluginUtil util;
       
  1143 			  QVariant result= util.parse(response, &ok);
       
  1144 			  if (!ok) 
       
  1145 			   {
       
  1146 					qDebug()<<("An error occurred during json parsing");
       
  1147 					aRetType = SmfRequestError;
       
  1148 					return SmfPluginErrParsingFailed;
       
  1149 			   }
       
  1150 												
       
  1151 			   QVariantMap map1 = result.toMap();
       
  1152 		  }
       
  1153 		  if( SmfPictureGetAlbums == aOperation )
       
  1154 			  {}
       
  1155  
       
  1156 			  }
       
  1157 		  else if(SmfPictureGetPictures == aOperation)
       
  1158 		  {}//end of   if(SmfPictureGetPictures == aOperation)
       
  1159 		 else if(SmfPicturePostComment == aOperation)
       
  1160 			 {}
       
  1161 		 else if(SmfPictureDescription == aOperation)
       
  1162 			 {}
       
  1163 		 else if(SmfPictureUpload == aOperation)
       
  1164 		    {
       
  1165 		      bool result;
       
  1166 		      qDebug()<<("SmfPictureUpload");
       
  1167 		       QXmlStreamReader xml(response);
       
  1168 		 	   while (!xml.atEnd())
       
  1169 		 	   {
       
  1170 		 		 xml.readNext();
       
  1171 		 		 if (xml.tokenType() == QXmlStreamReader::StartElement)
       
  1172 		 		  {
       
  1173 		 		    
       
  1174 		 		    qDebug()<<("inside tag");
       
  1175 		 				//If the tag is contact
       
  1176 		 				if (xml.name() == "photoid")
       
  1177 		 					{
       
  1178 		 					qDebug()<<("photoid tag found");
       
  1179 		 					result=TRUE;
       
  1180                             }
       
  1181 		 				else
       
  1182 		 					result=FALSE;
       
  1183 		 				}
       
  1184 		 			}
       
  1185 		 		
       
  1186 		 		aResult->setValue(result);
       
  1187 				aRetType = SmfRequestComplete;
       
  1188 				error = SmfPluginErrNone;
       
  1189 						
       
  1190 			}
       
  1191 		 else if (SmfPictureMultiUpload == aOperation)
       
  1192 			{
       
  1193 		       bool result;
       
  1194 			   qDebug()<<("SmfPictureUpload");
       
  1195 			   QXmlStreamReader xml(response);
       
  1196 			   while (!xml.atEnd())
       
  1197 			   {
       
  1198 				 xml.readNext();
       
  1199 				 if (xml.tokenType() == QXmlStreamReader::StartElement)
       
  1200 				 {
       
  1201 				 	qDebug()<<("inside tag");
       
  1202 				 	//If the tag is contact
       
  1203 				 	if (xml.name() == "photoid")
       
  1204 				 	{
       
  1205 				 		qDebug()<<("photoid tag found");
       
  1206 				 		result=TRUE;
       
  1207 		             }
       
  1208 				 	 else
       
  1209 				 		result=FALSE;
       
  1210 				 	}//end If
       
  1211 				 }//endWhile;
       
  1212 				 		
       
  1213 				 aResult->setValue(result);
       
  1214 				 if (listIndex < count)
       
  1215 					{
       
  1216 				
       
  1217 				      listIndex=listIndex+1;
       
  1218 				      error = SmfPluginErrNone;
       
  1219 					  aRetType = SmfSendRequestAgain;
       
  1220 					  
       
  1221 				     
       
  1222 					}
       
  1223 				 else
       
  1224 					{
       
  1225 				      //Final result sent 
       
  1226 				      count=1; //clear counter 
       
  1227 				      aRetType = SmfRequestComplete;
       
  1228 		 		      error = SmfPluginErrNone;
       
  1229 					}
       
  1230 		 
       
  1231 			}
       
  1232 		 else
       
  1233 			{
       
  1234 			qDebug()<<("Service unsupported!!!");
       
  1235 			aRetType = SmfRequestError;
       
  1236 			error = SmfPluginErrServiceNotSupported;
       
  1237 			}
       
  1238 		}//end if of if(SmfTransportOpNoError == aTransportResult)
       
  1239 
       
  1240 	else if(SmfTransportOpOperationCanceledError == aTransportResult)
       
  1241 		{
       
  1242 		qDebug()<<("Operation Cancelled !!!");
       
  1243 		error = SmfPluginErrCancelComplete;
       
  1244 		aRetType = SmfRequestComplete;
       
  1245 		}
       
  1246 
       
  1247 	else
       
  1248 		{
       
  1249 		qDebug()<<("Transport Error !!!");
       
  1250 		error = SmfPluginErrNetworkError;
       
  1251 		aRetType = SmfRequestError;
       
  1252 		}
       
  1253 	return error;
       
  1254 #endif
       
  1255 	
       
  1256 	}
       
  1257 
       
  1258 
       
  1259 /**
       
  1260  * Destructor
       
  1261  */
       
  1262 FlickrProviderBase::~FlickrProviderBase( )
       
  1263 	{
       
  1264 	}
       
  1265 
       
  1266 /**
       
  1267  * Method to get the Localisable name of the service.
       
  1268  * @return The Localisable name of the service.
       
  1269  */
       
  1270 QString FlickrProviderBase::serviceName( ) const
       
  1271 	{
       
  1272 	return m_serviceName;
       
  1273 	}
       
  1274 
       
  1275 /**
       
  1276  * Method to get the Logo of the service
       
  1277  * @return The Logo of the service
       
  1278  */
       
  1279 QImage FlickrProviderBase::serviceIcon( ) const
       
  1280 	{
       
  1281 	return m_serviceIcon;
       
  1282 	}
       
  1283 
       
  1284 /**
       
  1285  * Method to get the Readable service description
       
  1286  * @return The Readable service description
       
  1287  */
       
  1288 QString FlickrProviderBase::description( ) const
       
  1289 	{
       
  1290 	return m_description;
       
  1291 	}
       
  1292 
       
  1293 /**
       
  1294  * Method to get the Website of the service
       
  1295  * @return The Website of the service
       
  1296  */
       
  1297 QUrl FlickrProviderBase::serviceUrl( ) const
       
  1298 	{
       
  1299 	return m_serviceUrl;
       
  1300 	}
       
  1301 
       
  1302 /**
       
  1303  * Method to get the URL of the Application providing this service
       
  1304  * @return The URL of the Application providing this service
       
  1305  */
       
  1306 QUrl FlickrProviderBase::applicationUrl( ) const
       
  1307 	{
       
  1308 	return m_applicationUrl;
       
  1309 	}
       
  1310 
       
  1311 /**
       
  1312  * Method to get the Icon of the application
       
  1313  * @return The Icon of the application
       
  1314  */
       
  1315 QImage FlickrProviderBase::applicationIcon( ) const
       
  1316 	{
       
  1317 	return m_applicationIcon;
       
  1318 	}
       
  1319 
       
  1320 /**
       
  1321 * Method to get the list of interfaces that this provider support
       
  1322 * @return List of supported Interafces
       
  1323 */
       
  1324 QList<QString> FlickrProviderBase::supportedInterfaces( ) const
       
  1325 	{
       
  1326 	return m_supportedInterfaces;
       
  1327 	}
       
  1328 
       
  1329 /**
       
  1330 * Method to get the list of languages supported by this service provider
       
  1331 * @return a QStringList of languages supported by this service 
       
  1332 * provider in 2 letter ISO 639-1 format.
       
  1333 */
       
  1334 QStringList FlickrProviderBase::supportedLanguages( ) const
       
  1335 	{
       
  1336 	return m_supportedLangs;
       
  1337 	}
       
  1338 
       
  1339 /**
       
  1340  * Method to get the Plugin specific ID
       
  1341  * @return The Plugin specific ID
       
  1342  */
       
  1343 QString FlickrProviderBase::pluginId( ) const
       
  1344 	{
       
  1345 	return m_pluginId;
       
  1346 	}
       
  1347 
       
  1348 /**
       
  1349  * Method to get the ID of the authentication application 
       
  1350  * for this service
       
  1351  * @param aProgram The authentication application name
       
  1352  * @param aArguments List of arguments required for authentication app
       
  1353  * @param aMode Strting mode for authentication application
       
  1354  * @return The ID of the authentication application 
       
  1355  */
       
  1356 QString FlickrProviderBase::authenticationApp( QString &aProgram, 
       
  1357 		QStringList & aArguments, 
       
  1358 		QIODevice::OpenModeFlag aMode ) const
       
  1359 	{
       
  1360 	Q_UNUSED(aProgram)
       
  1361 	Q_UNUSED(aArguments)
       
  1362 	Q_UNUSED(aMode)
       
  1363 	return m_authAppId;
       
  1364 	}
       
  1365 
       
  1366 /**
       
  1367  * Method to get the unique registration ID provided by the 
       
  1368  * Smf for authorised plugins
       
  1369  * @return The unique registration ID/token provided by the Smf for 
       
  1370  * authorised plugins
       
  1371  */
       
  1372 QString FlickrProviderBase::smfRegistrationId( ) const
       
  1373 	{
       
  1374 	return m_smfRegToken;
       
  1375 	}
       
  1376 
       
  1377 void FlickrProviderBase::initialize()
       
  1378 	{
       
  1379 	m_serviceName = "Flickr";
       
  1380 	m_description = "Flickr gallery plugin description";
       
  1381 	m_serviceUrl = QUrl(QString("http://api.flickr.com"));
       
  1382 	m_pluginId = "flickrgalleryplugin.qtplugin";
       
  1383 	m_authAppId = "0xE1D8C7D7";
       
  1384 	m_supportedInterfaces.append("org.symbian.smf.plugin.gallery/v0.2");
       
  1385 	QSettings iSettings;
       
  1386 	m_smfRegToken = iSettings.value("CMFlickrRegToken").toString();
       
  1387 	m_validity = iSettings.value("FlckrExpiryTime").toDateTime();
       
  1388 	}
       
  1389 
       
  1390 
       
  1391 /*
       
  1392  * Export Macro
       
  1393  * plugin name : flickrGalleryplugin
       
  1394  * plugin class : FlickrGalleryPlugin
       
  1395  */
       
  1396 Q_EXPORT_PLUGIN2( flickrgalleryplugin, FlickrGalleryPlugin )