example/flickrcontactfetcherplugin/flickrcontactfetcherplugin.cpp
changeset 14 a469c0e6e7fb
parent 6 c39a6cfd1fb9
child 17 106a4bfcb866
equal deleted inserted replaced
13:b5d63d5fc252 14:a469c0e6e7fb
       
     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  * Nalina Hariharan
       
    14  * 
       
    15  * Description:
       
    16  * The Plugin that fetches contacts from the logged in user's flickr account
       
    17  *
       
    18  */
     1 
    19 
     2 // Include files
    20 // Include files
     3 #include <QtPlugin>
    21 #include <QtPlugin>
     4 #include <QCryptographicHash>
    22 #include <QCryptographicHash>
     5 #include <QDataStream>
       
     6 #include <QTextStream>
    23 #include <QTextStream>
     7 #include <QFile>
    24 #include <QFile>
     8 #include <QNetworkReply>
       
     9 #include <QXmlStreamReader>
       
    10 #include <parser.h>
       
    11 #include <QMap>
    25 #include <QMap>
    12 #include <QListIterator>
    26 #include <QListIterator>
       
    27 #include <QDebug>
       
    28 #ifdef SMF_XMLPARSING
       
    29 #include <QXmlStreamReader>
       
    30 #endif
    13 
    31 
    14 #include "flickrcontactfetcherplugin.h"
    32 #include "flickrcontactfetcherplugin.h"
    15 
       
    16 // HARD CODED AS CSM IS NOT AVAILABLE - START - use your rigistered app's keys here
       
    17 static const QString apiKey = "";
       
    18 static const QString apiSecret = "";
       
    19 static const QString miniToken = "";
       
    20 QString fullToken = "";
       
    21 // HARD CODED AS CSM IS NOT AVAILABLE - END
       
    22 
       
    23 
       
    24 /**
       
    25  * Method called by plugins for logging
       
    26  * @param log string to be logged
       
    27  */
       
    28 void FlickrContactFetcherPlugin::writeLog(QString log) const
       
    29 	{
       
    30 	QFile file("c:\\data\\PluginLogs.txt");
       
    31     if (!file.open(QIODevice::Append | QIODevice::Text))
       
    32 	         ;
       
    33     QTextStream out(&file);
       
    34     out << log << "\n";
       
    35     file.close();
       
    36 	}
       
    37 
    33 
    38 /**
    34 /**
    39  * Destructor
    35  * Destructor
    40  */
    36  */
    41 FlickrContactFetcherPlugin::~FlickrContactFetcherPlugin( )
    37 FlickrContactFetcherPlugin::~FlickrContactFetcherPlugin( )
    50  * @param aPageNum The page to be extracted
    46  * @param aPageNum The page to be extracted
    51  * @param aItemsPerPage Number of items per page
    47  * @param aItemsPerPage Number of items per page
    52  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
    48  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
    53  */
    49  */
    54 SmfPluginError FlickrContactFetcherPlugin::friends( SmfPluginRequestData &aRequest,
    50 SmfPluginError FlickrContactFetcherPlugin::friends( SmfPluginRequestData &aRequest,
    55 		const int aPageNum,
    51 		const int aPageNum, 
    56 		const int aItemsPerPage )
    52 		const int aItemsPerPage )
    57 	{
    53 	{
    58 	writeLog("FlickrContactFetcherPlugin::friends");
    54 	qDebug()<<"Inside FlickrContactFetcherPlugin::friends()";
    59 
    55 	
    60 	SmfPluginError error = SmfPluginErrInvalidRequest;
    56 	SmfPluginError error = SmfPluginErrInvalidArguments;
    61 
    57 
    62 	// invalid arguments
    58 	// invalid arguments
    63 	if( aPageNum < 0 || aItemsPerPage < 0 )
    59 	if( aPageNum < 0 || aItemsPerPage < 0 )
       
    60 		{
       
    61 		qDebug()<<"Invalid arguments";
    64 		return error;
    62 		return error;
    65 	else
    63 		}
       
    64 	
       
    65 	qDebug()<<"Valid arguments";
       
    66 	
       
    67 #if 1
       
    68 // Reading the keys, CSM Stubbed - START
       
    69 	QFile file("c:\\data\\FlickrKeys.txt");
       
    70 	if (!file.open(QIODevice::ReadOnly))
    66 		{
    71 		{
    67 		// Create the API signature string
    72 		qDebug()<<"File to read the keys could not be opened";
    68 		QString baseString;
    73 		return SmfPluginErrUserNotLoggedIn;
    69 		baseString.append(apiSecret);
       
    70 		baseString.append("api_key"+apiKey);
       
    71 		baseString.append("auth_token"+fullToken);
       
    72 		baseString.append("filterfriends");
       
    73 		baseString.append("formatjson");
       
    74 		baseString.append("methodflickr.contacts.getList");
       
    75 		baseString.append("page"+QString::number(aPageNum));
       
    76 		baseString.append("per_page"+QString::number(aItemsPerPage));
       
    77 
       
    78 		// Create the url
       
    79 		QUrl url("http://api.flickr.com/services/rest/?");
       
    80 		url.addQueryItem("method", "flickr.contacts.getList");
       
    81 		url.addQueryItem("api_key", apiKey);
       
    82 		url.addQueryItem("filter", "friends");
       
    83 		url.addQueryItem("format", "json");
       
    84 		url.addQueryItem("page", QString::number(aPageNum));
       
    85 		url.addQueryItem("per_page", QString::number(aItemsPerPage));
       
    86 		url.addQueryItem("auth_token", fullToken);
       
    87 		url.addQueryItem("api_sig", generateSignature(baseString));
       
    88 
       
    89 		// Create the request, set the url
       
    90 		writeLog("final url = "+url.toString());
       
    91 		aRequest.iNetworkRequest.setUrl(url);
       
    92 		aRequest.iRequestType = SmfContactGetFriends;
       
    93 		aRequest.iPostData = NULL;
       
    94 		aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
       
    95 		error = SmfPluginErrNone;
       
    96 		}
    74 		}
    97 	writeLog("Url string is : "+aRequest.iNetworkRequest.url().toString());
    75 	
    98 	return error;
    76 	qDebug()<<"Key file read, going to parse the key values from file";
       
    77 	
       
    78 	QByteArray arr = file.readAll();
       
    79 	QList<QByteArray> list = arr.split('\n');
       
    80 	file.close();
       
    81 	
       
    82 	QString apiKey(list[0]);
       
    83 	QString apiSecret(list[1]);
       
    84 	QString authToken(list[2]);
       
    85 	
       
    86 	qDebug()<<"Api Key = "<<apiKey;
       
    87 	qDebug()<<"Api Secret = "<<apiSecret;
       
    88 	qDebug()<<"Auth Token = "<<authToken;
       
    89 // Reading the keys, CSM Stubbed - END
       
    90 #endif
       
    91 	
       
    92 	// Create the API signature string
       
    93 	QString baseString;
       
    94 	baseString.append(apiSecret);
       
    95 	baseString.append("api_key"+apiKey);
       
    96 	baseString.append("auth_token"+authToken);
       
    97 	baseString.append("filterfriends");
       
    98 #ifdef SMF_XMLPARSING
       
    99 	baseString.append("formatxml");
       
   100 #else
       
   101 	baseString.append("formatjson");
       
   102 #endif
       
   103 	baseString.append("methodflickr.contacts.getList");
       
   104 	baseString.append("page"+QString::number(aPageNum));
       
   105 	baseString.append("per_page"+QString::number(aItemsPerPage));
       
   106 	
       
   107 	// Create the url
       
   108 	QUrl url("http://api.flickr.com/services/rest/?");
       
   109 	url.addQueryItem("api_key", apiKey);
       
   110 	url.addQueryItem("auth_token", authToken);
       
   111 	url.addQueryItem("filter", "friends");
       
   112 #ifdef SMF_XMLPARSING
       
   113 	url.addQueryItem("format", "x");
       
   114 #else
       
   115 	url.addQueryItem("format", "json");
       
   116 #endif
       
   117 	url.addQueryItem("method", "flickr.contacts.getList");
       
   118 	url.addQueryItem("page", QString::number(aPageNum));
       
   119 	url.addQueryItem("per_page", QString::number(aItemsPerPage));
       
   120 	url.addQueryItem("api_sig", generateSignature(baseString));
       
   121 	
       
   122 	// Create the request, set the url
       
   123 	aRequest.iNetworkRequest.setUrl(url);
       
   124 	aRequest.iRequestType = SmfContactGetFriends;
       
   125 	aRequest.iPostData = NULL;
       
   126 	aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
       
   127 	error = SmfPluginErrNone;
       
   128 
       
   129 	qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString();
       
   130 	return error; 
    99 	}
   131 	}
   100 
   132 
   101 /**
   133 /**
   102  * Method called by plugins to generate a signature string from a base string
   134  * Method called by plugins to generate a signature string from a base string
   103  * @param aBaseString The base string
   135  * @param aBaseString The base string
   104  * @return The md5 hash of the base string
   136  * @return The md5 hash of the base string
   105  */
   137  */
   106 QString FlickrContactFetcherPlugin::generateSignature(const QString aBaseString)
   138 QString FlickrContactFetcherPlugin::generateSignature(const QString aBaseString)
   107 	{
   139 	{
   108 	writeLog("FlickrContactFetcherPlugin::generateSignature");
   140 	qDebug()<<"Inside FlickrContactFetcherPlugin::generateSignature()";
   109 
   141 	
   110 	// Create md5 hash of the signature string
   142 	// Create md5 hash of the signature string
   111     QByteArray byteArray;
   143     QByteArray byteArray;
   112     byteArray.insert(0, aBaseString.toAscii());
   144     byteArray.insert(0, aBaseString.toAscii());
   113 
   145 
   114     QByteArray md5Hash = QCryptographicHash::hash(byteArray,QCryptographicHash::Md5 ).toHex();
   146     QByteArray md5Hash = QCryptographicHash::hash(byteArray,QCryptographicHash::Md5 ).toHex();
   115     QString returnString (md5Hash);
   147     QString returnString (md5Hash);
   116     writeLog("generated signature = "+QString(returnString));
   148     qDebug()<<"generated signature = "<<QString(returnString);
   117     return returnString;
   149     return returnString;
   118 	}
   150 	}
   119 
   151 
   120 /**
   152 /**
   121  * Method to get the list of followers
   153  * Method to get the list of followers
   123  * @param aPageNum The page to be extracted
   155  * @param aPageNum The page to be extracted
   124  * @param aItemsPerPage Number of items per page
   156  * @param aItemsPerPage Number of items per page
   125  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
   157  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
   126  */
   158  */
   127 SmfPluginError FlickrContactFetcherPlugin::followers( SmfPluginRequestData &aRequest,
   159 SmfPluginError FlickrContactFetcherPlugin::followers( SmfPluginRequestData &aRequest,
   128 		const int aPageNum ,
   160 		const int aPageNum , 
   129 		const int aItemsPerPage  )
   161 		const int aItemsPerPage  )
   130 	{
   162 	{
   131 	Q_UNUSED(aRequest)
   163 	Q_UNUSED(aRequest)
   132 Q_UNUSED(aPageNum)
   164 	Q_UNUSED(aPageNum)
   133 Q_UNUSED(aItemsPerPage)
   165 	Q_UNUSED(aItemsPerPage)
   134 	SmfPluginError error = SmfPluginErrInvalidRequest;
   166 	qDebug()<<"Inside FlickrContactFetcherPlugin::followers()";
   135 	return error;
   167 	return SmfPluginErrServiceNotSupported; 
   136 	}
   168 	}
   137 
   169 
   138 /**
   170 /**
   139  * Method to search for a contact
   171  * Method to search for a contact
   140  * @param aRequest [out] The request data to be sent to network
   172  * @param aRequest [out] The request data to be sent to network
   143  * @param aItemsPerPage Number of items per page
   175  * @param aItemsPerPage Number of items per page
   144  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
   176  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
   145  */
   177  */
   146 SmfPluginError FlickrContactFetcherPlugin::search( SmfPluginRequestData &aRequest,
   178 SmfPluginError FlickrContactFetcherPlugin::search( SmfPluginRequestData &aRequest,
   147 		const SmfContact &aContact,
   179 		const SmfContact &aContact,
   148 		const int aPageNum ,
   180 		const int aPageNum , 
   149 		const int aItemsPerPage  )
   181 		const int aItemsPerPage  )
   150 	{
   182 	{
   151 	Q_UNUSED(aRequest)
   183 	Q_UNUSED(aRequest)
   152 Q_UNUSED(aContact)
   184 	Q_UNUSED(aContact)
   153 Q_UNUSED(aPageNum)
   185 	Q_UNUSED(aPageNum)
   154 Q_UNUSED(aItemsPerPage)
   186 	Q_UNUSED(aItemsPerPage)
   155 	SmfPluginError error = SmfPluginErrInvalidRequest;
   187 	qDebug()<<"Inside FlickrContactFetcherPlugin::search()";
   156 	return error;
   188 	return SmfPluginErrServiceNotSupported; 
   157 	}
   189 	}
   158 
   190 
   159 /**
   191 /**
   160  * Method to search for contacts (friends) who are near the user.
   192  * Method to search for contacts (friends) who are near the user.
   161  * Proximity defines accuracy level
   193  * Proximity defines accuracy level
   167  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
   199  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
   168  */
   200  */
   169 SmfPluginError FlickrContactFetcherPlugin::searchNear( SmfPluginRequestData &aRequest,
   201 SmfPluginError FlickrContactFetcherPlugin::searchNear( SmfPluginRequestData &aRequest,
   170 		const SmfLocation &aLocation,
   202 		const SmfLocation &aLocation,
   171 		const SmfLocationSearchBoundary &aProximity,
   203 		const SmfLocationSearchBoundary &aProximity,
   172 		const int aPageNum ,
   204 		const int aPageNum , 
   173 		const int aItemsPerPage  )
   205 		const int aItemsPerPage  )
   174 	{
   206 	{
   175 	Q_UNUSED(aRequest)
   207 	Q_UNUSED(aRequest)
   176 Q_UNUSED(aLocation)
   208 	Q_UNUSED(aLocation)
   177 Q_UNUSED(aProximity)
   209 	Q_UNUSED(aProximity)
   178 Q_UNUSED(aPageNum)
   210 	Q_UNUSED(aPageNum)
   179 Q_UNUSED(aItemsPerPage)
   211 	Q_UNUSED(aItemsPerPage)
   180 	SmfPluginError error = SmfPluginErrInvalidRequest;
   212 	qDebug()<<"Inside FlickrContactFetcherPlugin::searchNear()";
   181 	return error;
   213 	return SmfPluginErrServiceNotSupported; 
   182 	}
   214 	}
   183 
   215 
   184 /**
   216 /**
   185  * Method to get the list of groups
   217  * Method to get the list of groups
   186  * @param aRequest [out] The request data to be sent to network
   218  * @param aRequest [out] The request data to be sent to network
   187  * @param aPageNum The page to be extracted
   219  * @param aPageNum The page to be extracted
   188  * @param aItemsPerPage Number of items per page
   220  * @param aItemsPerPage Number of items per page
   189  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
   221  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
   190  */
   222  */
   191 SmfPluginError FlickrContactFetcherPlugin::groups( SmfPluginRequestData &aRequest,
   223 SmfPluginError FlickrContactFetcherPlugin::groups( SmfPluginRequestData &aRequest,
   192 		const int aPageNum ,
   224 		const int aPageNum , 
   193 		const int aItemsPerPage  )
   225 		const int aItemsPerPage  )
   194 	{
   226 	{
   195 	Q_UNUSED(aRequest)
   227 	Q_UNUSED(aRequest)
   196 Q_UNUSED(aPageNum)
   228 	Q_UNUSED(aPageNum)
   197 Q_UNUSED(aItemsPerPage)
   229 	Q_UNUSED(aItemsPerPage)
   198 	SmfPluginError error = SmfPluginErrInvalidRequest;
   230 	qDebug()<<"Inside FlickrContactFetcherPlugin::groups()";
   199 	return error;
   231 	return SmfPluginErrServiceNotSupported; 
   200 	}
   232 	}
   201 
   233 
   202 /**
   234 /**
   203  * Method to search for a contact in a group
   235  * Method to search for a contact in a group
   204  * @param aRequest [out] The request data to be sent to network
   236  * @param aRequest [out] The request data to be sent to network
   207  * @param aItemsPerPage Number of items per page
   239  * @param aItemsPerPage Number of items per page
   208  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
   240  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
   209  */
   241  */
   210 SmfPluginError FlickrContactFetcherPlugin::searchInGroup( SmfPluginRequestData &aRequest,
   242 SmfPluginError FlickrContactFetcherPlugin::searchInGroup( SmfPluginRequestData &aRequest,
   211 		const SmfGroup &aGroup,
   243 		const SmfGroup &aGroup,
   212 		const int aPageNum ,
   244 		const int aPageNum , 
   213 		const int aItemsPerPage  )
   245 		const int aItemsPerPage  )
   214 	{
   246 	{
   215 	Q_UNUSED(aRequest)
   247 	Q_UNUSED(aRequest)
   216 Q_UNUSED(aGroup)
   248 	Q_UNUSED(aGroup)
   217 Q_UNUSED(aPageNum)
   249 	Q_UNUSED(aPageNum)
   218 Q_UNUSED(aItemsPerPage)
   250 	Q_UNUSED(aItemsPerPage)
   219 	SmfPluginError error = SmfPluginErrInvalidRequest;
   251 	qDebug()<<"Inside FlickrContactFetcherPlugin::searchInGroup()";
   220 	return error;
   252 	return SmfPluginErrServiceNotSupported; 
   221 	}
   253 	}
   222 
   254 
   223 /**
   255 /**
   224  * Customised method for SmfContactFetcherPlugin interface
   256  * Customised method for SmfContactFetcherPlugin interface
   225  * @param aRequest [out] The request data to be sent to network
   257  * @param aRequest [out] The request data to be sent to network
   226  * @param aOperation The operation type (should be known between
   258  * @param aOperation The operation type (should be known between 
   227  * the client interface and the plugin)
   259  * the client interface and the plugin)
   228  * @param aData The data required to form the request (The type
   260  * @param aData The data required to form the request (The type 
   229  * of data should be known between client and the plugin)
   261  * of data should be known between client and the plugin)
   230  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
   262  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
   231  */
   263  */
   232 SmfPluginError FlickrContactFetcherPlugin::customRequest( SmfPluginRequestData &aRequest,
   264 SmfPluginError FlickrContactFetcherPlugin::customRequest( SmfPluginRequestData &aRequest, 
   233 		const int &aOperation, QByteArray *aData )
   265 		const int &aOperation, QByteArray *aData )
   234 	{
   266 	{
   235 	Q_UNUSED(aRequest)
   267 	Q_UNUSED(aRequest)
   236 Q_UNUSED(aOperation)
   268 	Q_UNUSED(aOperation)
   237 Q_UNUSED(aData)
   269 	Q_UNUSED(aData)
   238 	SmfPluginError error = SmfPluginErrInvalidRequest;
   270 	qDebug()<<"Inside FlickrContactFetcherPlugin::customRequest()";
   239 	return error;
   271 	return SmfPluginErrServiceNotSupported; 
   240 	}
   272 	}
   241 
   273 
   242 /**
   274 /**
   243  * The first method to be called in the plugin that implements this interface.
   275  * The first method to be called in the plugin that implements this interface.
   244  * If this method is not called, plugin may not behave as expected.
   276  * If this method is not called, plugin may not behave as expected.
   247  */
   279  */
   248 void FlickrContactFetcherPlugin::initialize( SmfPluginUtil *aUtil )
   280 void FlickrContactFetcherPlugin::initialize( SmfPluginUtil *aUtil )
   249 	{
   281 	{
   250 	// Save the SmfPluginUtil handle
   282 	// Save the SmfPluginUtil handle
   251 	m_util = aUtil;
   283 	m_util = aUtil;
   252 
   284 	
   253 	// Create an instance of FlickrProviderBase
   285 	// Create an instance of FlickrProviderBase
   254 	m_provider = new FlickrProviderBase;
   286 	m_provider = new FlickrProviderBase;
   255 	m_provider->initialize();
   287 	m_provider->initialize();
   256 	}
   288 	}
   257 
   289 
   264 	return m_provider;
   296 	return m_provider;
   265 	}
   297 	}
   266 
   298 
   267 /**
   299 /**
   268  * Method to get the result for a network request.
   300  * Method to get the result for a network request.
       
   301  * @param aOperation The type of operation to be requested
   269  * @param aTransportResult The result of transport operation
   302  * @param aTransportResult The result of transport operation
   270  * @param aResponse The QByteArray instance containing the network response.
   303  * @param aResponse The QByteArray instance containing the network response.
   271  * The plugins should delete this instance once they have read the
   304  * The plugins should delete this instance once they have read the 
   272  * data from it.
   305  * data from it.
   273  * @param aResult [out] An output parameter to the plugin manager.If the
   306  * @param aResult [out] An output parameter to the plugin manager.If the 
   274  * return value is SmfSendRequestAgain, QVariant will be of type
   307  * return value is SmfSendRequestAgain, QVariant will be of type 
   275  * SmfPluginRequestData.
   308  * SmfPluginRequestData.
   276  * For SmfGalleryPlugin: If last operation was pictures(), aResult will
   309  * For SmfGalleryPlugin: If last operation was pictures(), aResult will 
   277  * be of type QList<SmfPicture>. If last operation was description(),
   310  * be of type QList<SmfPicture>. If last operation was description(), 
   278  * aResult will be of type QString. If last operation was upload() or
   311  * aResult will be of type QString. If last operation was upload() or 
   279  * postComment(), aResult will be of type bool.
   312  * postComment(), aResult will be of type bool.
   280  * @param aRetType [out] SmfPluginRetType
   313  * @param aRetType [out] SmfPluginRetType
   281  * @param aPageResult [out] The SmfResultPage structure variable
   314  * @param aPageResult [out] The SmfResultPage structure variable
   282  */
   315  */
   283 SmfPluginError FlickrContactFetcherPlugin::responseAvailable(
   316 SmfPluginError FlickrContactFetcherPlugin::responseAvailable( 
   284 		const SmfTransportResult &aTransportResult,
   317 		const SmfRequestTypeID aOperation,
   285 		QByteArray *aResponse,
   318 		const SmfTransportResult &aTransportResult, 
   286 		QVariant* aResult,
   319 		QByteArray *aResponse, 
       
   320 		QVariant* aResult, 
   287 		SmfPluginRetType &aRetType,
   321 		SmfPluginRetType &aRetType,
   288 		SmfResultPage &aPageResult )
   322 		SmfResultPage &aPageResult )
   289 	{
   323 	{
   290 	writeLog("FlickrContactFetcherPlugin::responseAvailable");
       
   291 	Q_UNUSED(aPageResult)
   324 	Q_UNUSED(aPageResult)
   292 	SmfPluginError error;
   325 	qDebug()<<"Inside FlickrContactFetcherPlugin::responseAvailable()";
   293 	QList<SmfContact> list;
   326 	
   294 
   327 	SmfPluginError error = SmfPluginErrNetworkError;
       
   328 	
       
   329 	if( !aResponse || (0 == aResponse->size()) )
       
   330 		{
       
   331 		qDebug()<<"Response is NULL or empty";
       
   332 		aRetType = SmfRequestError;
       
   333 		return error;
       
   334 		}
       
   335 	
       
   336 	QByteArray response(*aResponse);
       
   337 	delete aResponse;
       
   338 	qDebug()<<"FB response = "<<QString(response);
       
   339 	qDebug()<<"FB response size = "<<response.size();
       
   340 	
   295 	if(SmfTransportOpNoError == aTransportResult)
   341 	if(SmfTransportOpNoError == aTransportResult)
   296 		{
   342 		{
   297 		writeLog("No transport error");
   343 		qDebug()<<"No transport error";
   298 
   344 		
   299 		QByteArray response(aResponse->data());
   345 		if(SmfContactGetFriends == aOperation)
   300 		delete aResponse;
       
   301 		writeLog("Flickr response = "+QString(response));
       
   302 
       
   303 #if 1
       
   304 		// For getting contacts from json response
       
   305 		QJson::Parser parser;
       
   306 		bool ok;
       
   307 
       
   308 		// To remove the "jsonFlickrApi(" and also remove the last ")" from the response,
       
   309 		// as these gives a Json parsing error
       
   310 		response.remove(0, 14);
       
   311 		response.chop(1);
       
   312 
       
   313 		QVariantMap result = parser.parse(response, &ok).toMap();
       
   314 		if (!ok) {
       
   315 			writeLog("An error occurred during json parsing");
       
   316 			aResult->setValue(list);
       
   317 			error = SmfPluginErrParsingFailed;
       
   318 			return error;
       
   319 		}
       
   320 
       
   321 		QVariantMap map1 = result["contacts"].toMap();
       
   322 		writeLog("page = "+map1["page"].toString());
       
   323 		writeLog("pages = "+map1["pages"].toString());
       
   324 		writeLog("per_page = "+map1["per_page"].toString());
       
   325 		writeLog("perpage = "+map1["perpage"].toString());
       
   326 		writeLog("total = "+map1["perpage"].toString());
       
   327 
       
   328 		QList<QVariant> list1 = map1["contact"].toList();
       
   329 
       
   330 		QListIterator<QVariant> i(list1);
       
   331 		while(i.hasNext())
       
   332 			{
   346 			{
   333 			SmfContact contact;
   347 			qDebug()<<"For getting friends response";
   334 			QVariantMap map2 = i.next().toMap();
   348 			
   335 			writeLog("nsid = "+map2["nsid"].toString());
   349 			QList<SmfContact> list;
   336 			writeLog("username = "+map2["username"].toString());
   350 			
   337 			writeLog("iconserver = "+map2["iconserver"].toString());
   351 #ifdef SMF_XMLPARSING // Xml parsing
   338 			writeLog("iconfarm = "+map2["iconfarm"].toString());
   352 			// For getting contacts from xml response
   339 			writeLog("ignored = "+map2["ignored"].toString());
   353 			QXmlStreamReader xml(response);
   340 			writeLog("realname = "+map2["realname"].toString());
   354 			while (!xml.atEnd())
   341 			writeLog("friend = "+map2["friend"].toString());
       
   342 			writeLog("family = "+map2["family"].toString());
       
   343 			writeLog("path_alias = "+map2["path_alias"].toString());
       
   344 			writeLog("location = "+map2["location"].toString());
       
   345 
       
   346 			QContactName contactname;
       
   347 			QString username = map2["username"].toString();
       
   348 			writeLog("Username = "+username);
       
   349 			contactname.setFirstName(username);
       
   350 			contactname.setLastName(username);
       
   351 			QVariant nameVar = QVariant::fromValue(contactname);
       
   352 			contact.setValue("Name",nameVar);
       
   353 			list.append(contact);
       
   354 			}
       
   355 #endif
       
   356 
       
   357 #if 0
       
   358 		// For getting contacts from xml response
       
   359 		QXmlStreamReader xml(response);
       
   360 		while (!xml.atEnd())
       
   361 			{
       
   362 			xml.readNext();
       
   363 			if (xml.tokenType() == QXmlStreamReader::StartElement)
       
   364 				{
   355 				{
   365 				// If the tag is contact
   356 				xml.readNext();
   366 				if (xml.name() == "contact")
   357 				if (xml.tokenType() == QXmlStreamReader::StartElement)
   367 					{
   358 					{
   368 					writeLog("Contact tag found");
   359 					// If the tag is contact
   369 					SmfContact contact;
   360 					if (xml.name() == "contact")
   370 					QStringRef str;
   361 						{
   371 					QContactName contactname;
   362 						qDebug()<<"Contact tag found";
   372 					QString username = xml.attributes().value("username").toString();
   363 						SmfContact contact;
   373 					writeLog("Username = ");
   364 						QStringRef str;
   374 					writeLog(username);
   365 						QContactName contactname;
   375 					contactname.setFirstName(username);
   366 						QString username = xml.attributes().value("username").toString();
   376 					contactname.setLastName(username);
   367 						qDebug()<<"Username = "<<username;
   377 					QVariant namevar1 = QVariant::fromValue(contactname);
   368 						contactname.setFirstName(username);
   378 					contact.setValue("Name",namevar1);
   369 						contactname.setLastName(username);
   379                     list.append(contact);
   370 						QVariant namevar1 = QVariant::fromValue(contactname);
       
   371 						contact.setValue("Name",namevar1);
       
   372 						list.append(contact);
       
   373 						}
   380 					}
   374 					}
   381 				}
   375 				}
       
   376 #else
       
   377 			// To remove the "jsonFlickrApi(" and also remove the last ")" from the response,
       
   378 			// as these gives a Json parsing error
       
   379 			response.remove(0, 14);
       
   380 			response.chop(1);
       
   381 			
       
   382 			// For getting contacts from json response
       
   383 			bool ok;
       
   384 			QVariantMap result = m_util->parse(response, &ok).toMap();
       
   385 			if (!ok) {
       
   386 				qDebug()<<"An error occurred during json parsing";
       
   387 				aResult->setValue(list);
       
   388 				aRetType = SmfRequestError;
       
   389 				return SmfPluginErrParsingFailed;
   382 			}
   390 			}
       
   391 			
       
   392 			QVariantMap map1 = result["contacts"].toMap();
       
   393 			qDebug()<<"page = "<<map1["page"].toString();
       
   394 			qDebug()<<"pages = "<<map1["pages"].toString();
       
   395 			qDebug()<<"per_page = "<<map1["per_page"].toString();
       
   396 			qDebug()<<"perpage = "<<map1["perpage"].toString();
       
   397 			qDebug()<<"total = "<<map1["perpage"].toString();
       
   398 			
       
   399 			QList<QVariant> list1 = map1["contact"].toList();
       
   400 			
       
   401 			QListIterator<QVariant> i(list1);
       
   402 			while(i.hasNext())
       
   403 				{
       
   404 				SmfContact contact;
       
   405 				QVariantMap map2 = i.next().toMap();
       
   406 				qDebug()<<"nsid = "<<map2["nsid"].toString();
       
   407 				qDebug()<<"username = "<<map2["username"].toString();
       
   408 				qDebug()<<"iconserver = "<<map2["iconserver"].toString();
       
   409 				qDebug()<<"iconfarm = "<<map2["iconfarm"].toString();
       
   410 				qDebug()<<"ignored = "<<map2["ignored"].toString();
       
   411 				qDebug()<<"realname = "<<map2["realname"].toString();
       
   412 				qDebug()<<"friend = "<<map2["friend"].toString();
       
   413 				qDebug()<<"family = "<<map2["family"].toString();
       
   414 				qDebug()<<"path_alias = "<<map2["path_alias"].toString();
       
   415 				qDebug()<<"location = "<<map2["location"].toString();
       
   416 				
       
   417 				QContactName contactname;
       
   418 				QString username = map2["username"].toString();
       
   419 				qDebug()<<"Username = "<<username;
       
   420 				contactname.setFirstName(username);
       
   421 				contactname.setLastName(username);
       
   422 				QVariant nameVar = QVariant::fromValue(contactname);
       
   423 				contact.setValue("Name",nameVar);
       
   424 				list.append(contact);
       
   425 				}
   383 #endif
   426 #endif
   384 
   427 			
   385 		writeLog("list count = "+QString::number(list.count(),10));
   428 			qDebug()<<"list count = "<<list.count();
       
   429 			aResult->setValue(list);
       
   430 			aRetType = SmfRequestComplete;
       
   431 			error = SmfPluginErrNone;
       
   432 			}
       
   433 		else
       
   434 			{
       
   435 			qDebug()<<"Service unsupported, currently only SmfContactGetFriends !!!";
       
   436 			aRetType = SmfRequestError;
       
   437 			error = SmfPluginErrServiceNotSupported;
       
   438 			}
       
   439 		}
       
   440 
       
   441 	else if(SmfTransportOpOperationCanceledError == aTransportResult)
       
   442 		{
       
   443 		qDebug()<<"Operation Cancelled !!!";
       
   444 		error = SmfPluginErrCancelComplete;
   386 		aRetType = SmfRequestComplete;
   445 		aRetType = SmfRequestComplete;
   387 		error = SmfPluginErrNone;
       
   388 		}
   446 		}
   389 
   447 
   390 	else
   448 	else
   391 		{
   449 		{
   392 		error = SmfPluginErrInvalidRequest;
   450 		qDebug()<<"Transport Error !!!";
       
   451 		error = SmfPluginErrNetworkError;
   393 		aRetType = SmfRequestError;
   452 		aRetType = SmfRequestError;
   394 		}
   453 		}
   395 
   454 	
   396 	aResult->setValue(list);
       
   397 	return error;
   455 	return error;
   398 	}
   456 	}
   399 
   457 
   400 
   458 
   401 /**
   459 /**
   458 	{
   516 	{
   459 	return m_applicationIcon;
   517 	return m_applicationIcon;
   460 	}
   518 	}
   461 
   519 
   462 /**
   520 /**
       
   521 * Method to get the list of interfaces that this provider support
       
   522 * @return List of supported Interafces
       
   523 */
       
   524 QList<QString> FlickrProviderBase::supportedInterfaces( ) const
       
   525 	{
       
   526 	return m_supportedInterfaces;
       
   527 	}
       
   528 
       
   529 /**
       
   530 * Method to get the list of languages supported by this service provider
       
   531 * @return a QStringList of languages supported by this service 
       
   532 * provider in 2 letter ISO 639-1 format.
       
   533 */
       
   534 QStringList FlickrProviderBase::supportedLanguages( ) const
       
   535 	{
       
   536 	return m_supportedLangs;
       
   537 	}
       
   538 
       
   539 /**
   463  * Method to get the Plugin specific ID
   540  * Method to get the Plugin specific ID
   464  * @return The Plugin specific ID
   541  * @return The Plugin specific ID
   465  */
   542  */
   466 QString FlickrProviderBase::pluginId( ) const
   543 QString FlickrProviderBase::pluginId( ) const
   467 	{
   544 	{
   468 	return m_pluginId;
   545 	return m_pluginId;
   469 	}
   546 	}
   470 
   547 
   471 /**
   548 /**
   472  * Method to get the ID of the authentication application
   549  * Method to get the ID of the authentication application 
   473  * for this service
   550  * for this service
   474  * @param aProgram The authentication application name
   551  * @param aProgram The authentication application name
   475  * @param aArguments List of arguments required for authentication app
   552  * @param aArguments List of arguments required for authentication app
   476  * @param aMode Strting mode for authentication application
   553  * @param aMode Strting mode for authentication application
   477  * @return The ID of the authentication application
   554  * @return The ID of the authentication application 
   478  */
   555  */
   479 QString FlickrProviderBase::authenticationApp( QString &aProgram,
   556 QString FlickrProviderBase::authenticationApp( QString &aProgram, 
   480 		QStringList & aArguments,
   557 		QStringList & aArguments, 
   481 		QIODevice::OpenModeFlag aMode ) const
   558 		QIODevice::OpenModeFlag aMode ) const
   482 	{
   559 	{
   483 	Q_UNUSED(aProgram)
   560 	Q_UNUSED(aProgram)
   484 Q_UNUSED(aArguments)
   561 	Q_UNUSED(aArguments)
   485 Q_UNUSED(aMode)
   562 	Q_UNUSED(aMode)
   486 	return m_authAppId;
   563 	return m_authAppId;
   487 	}
   564 	}
   488 
   565 
   489 /**
   566 /**
   490  * Method to get the unique registration ID provided by the
   567  * Method to get the unique registration ID provided by the 
   491  * Smf for authorised plugins
   568  * Smf for authorised plugins
   492  * @return The unique registration ID/token provided by the Smf for
   569  * @return The unique registration ID/token provided by the Smf for 
   493  * authorised plugins
   570  * authorised plugins
   494  */
   571  */
   495 QString FlickrProviderBase::smfRegistrationId( ) const
   572 QString FlickrProviderBase::smfRegistrationId( ) const
   496 	{
   573 	{
   497 	return m_smfRegToken;
   574 	return m_smfRegToken;
   498 	}
   575 	}
   499 
   576 
   500 void FlickrProviderBase::initialize()
   577 void FlickrProviderBase::initialize()
   501 	{
   578 	{
   502 	m_serviceName = "Flickr";
   579 	m_serviceName = "Flickr";
   503 	m_description = "Flickr plugin description";
   580 	m_description = "Flickr contact fetcher plugin description";
   504 	m_serviceUrl = QUrl(QString("http://api.flickr.com"));
   581 	m_serviceUrl = QUrl(QString("http://api.flickr.com"));
   505 	m_pluginId = "flickrcontactfetcherplugin.qtplugin";
   582 	m_pluginId = "flickrcontactfetcherplugin.qtplugin";
   506 	m_authAppId = "Flickr AuthAppId";
   583 	m_authAppId = "Flickr AuthAppId";
   507 	m_smfRegToken = "Flickr RegToken";
   584 	m_smfRegToken = "Flickr RegToken";
       
   585 	m_supportedInterfaces.append("org.symbian.smf.plugin.contact.fetcher/v0.2");
   508 	}
   586 	}
   509 
   587 
   510 
   588 
   511 /*
   589 /*
   512  * Export Macro
   590  * Export Macro