example/fbactivityfetcherplugin/fbactivityfetcherplugin.cpp
changeset 17 106a4bfcb866
child 26 83d6a149c755
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  * Nalina Hariharan
       
    14  * 
       
    15  * Description:
       
    16  * The Plugin that fetches activities from the logged in user's facebook account
       
    17  *
       
    18  */
       
    19 
       
    20 // Include files
       
    21 #include <QtPlugin>
       
    22 #include <QDebug>
       
    23 #include <QCryptographicHash>
       
    24 #include <QFile>
       
    25 #include <QMap>
       
    26 #include <QXmlStreamReader>
       
    27 #include <QSettings>
       
    28 #include <smfactions.h>
       
    29 #include <smfpluginutil.h>
       
    30 
       
    31 #include "fbactivityfetcherplugin.h"
       
    32 
       
    33 // Global and static global variables
       
    34 static int chance = 0;
       
    35 QString currentUserId;
       
    36 SmfActivityEntry myEntry;
       
    37 SmfContact currentAuthor;
       
    38 QList<SmfActivityObject> currentObjectList;
       
    39 SmfActivityObject currentObject;
       
    40 bool forEntryXmlTag;
       
    41 bool forActivityObjectXmlTag;
       
    42 
       
    43 /**
       
    44  * Destructor
       
    45  */
       
    46 FBActivityFetcherPlugin::~FBActivityFetcherPlugin( )
       
    47 	{
       
    48 	if(m_provider)
       
    49 		delete m_provider;
       
    50 	}
       
    51 
       
    52 
       
    53 /**
       
    54  * Method called by plugins to generate a signature string from a base string
       
    55  * @param aBaseString The base string
       
    56  * @return The md5 hash of the base string
       
    57  */
       
    58 QString FBActivityFetcherPlugin::generateSignature(const QString aBaseString)
       
    59 	{
       
    60 	qDebug()<<"Inside FBActivityFetcherPlugin::generateSignature()";
       
    61 	
       
    62 	// Create md5 hash of the signature string
       
    63     QByteArray byteArray;
       
    64     byteArray.insert(0, aBaseString.toAscii());
       
    65 
       
    66     QByteArray md5Hash = QCryptographicHash::hash(byteArray,QCryptographicHash::Md5 ).toHex();
       
    67     QString returnString (md5Hash);
       
    68     return returnString;
       
    69 	}
       
    70 
       
    71 
       
    72 /**
       
    73  * Method to interpret the key sets obtained from credential manager 
       
    74  * @param aApiKey [out] The api key
       
    75  * @param aApiSecret [out] The api secret
       
    76  * @param aSessionKey [out] The session key
       
    77  * @param aSessionSecret [out] The session secret
       
    78  * @param aAppId [out] The application ID
       
    79  */
       
    80 void FBActivityFetcherPlugin::fetchKeys( QString &aApiKey, 
       
    81 		QString &aApiSecret, 
       
    82 		QString &aSessionKey, 
       
    83 		QString &aSessionSecret, 
       
    84 		QString &aAppId)
       
    85 	{
       
    86 	qDebug()<<"Inside FBActivityFetcherPlugin::fetchKeys()";
       
    87 
       
    88 	qDebug()<<"Reg Token = "<<m_provider->m_smfRegToken;
       
    89 	qDebug()<<"Expiry Date as int = "<<m_provider->m_validity.toTime_t();
       
    90 	
       
    91 	SmfAuthParams keys;
       
    92 	SmfPluginUtil util;
       
    93 	util.getAuthKeys(keys, m_provider->m_smfRegToken, 
       
    94 			m_provider->m_validity, m_provider->m_pluginId);
       
    95 	
       
    96 	qDebug()<<"Number of key-value pairs = "<<keys.count();
       
    97 	
       
    98     QByteArray keyName;
       
    99     keyName.append("ApiKey");
       
   100 	aApiKey.append(keys.value(keyName));
       
   101 	
       
   102     keyName.clear();
       
   103     keyName.append("ApiSecret");
       
   104 	aApiSecret.append(keys.value(keyName));
       
   105 	
       
   106 	keyName.clear();
       
   107     keyName.append("SessionKey");
       
   108 	aSessionKey.append(keys.value(keyName));
       
   109 	
       
   110 	keyName.clear();
       
   111     keyName.append("SessionSecret");
       
   112 	aSessionSecret.append(keys.value(keyName));
       
   113 	
       
   114 	keyName.clear();
       
   115     keyName.append("AppId");
       
   116 	aAppId.append(keys.value(keyName));
       
   117 	
       
   118 	qDebug()<<"Api Key = "<<aApiKey;
       
   119 	qDebug()<<"Api Secret = "<<aApiSecret;
       
   120 	qDebug()<<"session Key = "<<aSessionKey;
       
   121 	qDebug()<<"session Secret = "<<aSessionSecret;
       
   122 	qDebug()<<"App Id Secret = "<<aAppId;
       
   123 	}
       
   124 
       
   125 
       
   126 /**
       
   127  * Method to get the list of self activities, e.g. shown in own wall
       
   128  * @param aRequest [out] The request data that plugin generates (to be sent to network)
       
   129  * @param aPageNum[in] The page to be extracted
       
   130  * @param aItemsPerPage[in] Number of items per page
       
   131  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
   132  */
       
   133 SmfPluginError FBActivityFetcherPlugin::selfActivities( SmfPluginRequestData &aRequest,
       
   134 		const int aPageNum, 
       
   135 		const int aItemsPerPage )
       
   136 	{
       
   137 	qDebug()<<"Inside FBActivityFetcherPlugin::selfActivities()";
       
   138 		
       
   139 	//// Currently considering for self contact , ie, omitting aUser
       
   140 	if(0 == chance)
       
   141 		return getFacebookUserId(aRequest);
       
   142 	else
       
   143 		return getSelfActivities(aRequest, aPageNum, aItemsPerPage);
       
   144 	}
       
   145 
       
   146 
       
   147 /**
       
   148  * Method to get the user's facebook ID
       
   149  * @param aRequest [out] The request data to be sent to network
       
   150  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
   151  */
       
   152 SmfPluginError FBActivityFetcherPlugin::getFacebookUserId( 
       
   153 		SmfPluginRequestData &aRequest )
       
   154 	{
       
   155 	qDebug()<<"Inside FBActivityFetcherPlugin::getFacebookUserId()";
       
   156 	
       
   157 	SmfPluginError error = SmfPluginErrUserNotLoggedIn;
       
   158 	
       
   159 	// Get the key sets from SMF Plugin Utility class.
       
   160 	QString apiKey;
       
   161 	QString apiSecret;
       
   162 	QString sessionKey;
       
   163 	QString sessionSecret;
       
   164 	QString appId;
       
   165 	fetchKeys(apiKey, apiSecret, sessionKey, sessionSecret, appId);
       
   166 	
       
   167 	// Get the current date and time and convert it to sec as a string
       
   168 	QString call_id = QString::number(QDateTime::currentDateTime().toTime_t(), 10);
       
   169 	
       
   170 	// Create the API signature string
       
   171 	QString baseString;
       
   172 	baseString.append("api_key="+apiKey);
       
   173 	baseString.append("call_id="+call_id);
       
   174 	baseString.append("format=JSON");
       
   175 	baseString.append("method=users.getLoggedInUser");
       
   176 	baseString.append("session_key="+sessionKey);
       
   177 	baseString.append("ss=1");
       
   178 	baseString.append("v=1.0");
       
   179 	baseString.append(sessionSecret);
       
   180 
       
   181 	// Create the url
       
   182 	QUrl url("http://api.facebook.com/restserver.php?");
       
   183 	url.addQueryItem("api_key", apiKey);
       
   184 	url.addQueryItem("call_id", call_id);
       
   185 	url.addQueryItem("format", "JSON");
       
   186 	url.addQueryItem("method", "users.getLoggedInUser");
       
   187 	url.addQueryItem("session_key", sessionKey);
       
   188 	url.addQueryItem("ss", "1");
       
   189 	url.addQueryItem("v", "1.0");	
       
   190 	url.addQueryItem("sig", generateSignature(baseString));
       
   191 			
       
   192 	// Create the request, set the url
       
   193 	aRequest.iNetworkRequest.setUrl(url);
       
   194 	aRequest.iRequestType = SmfActivitySelfActivity;
       
   195 	aRequest.iPostData = NULL;
       
   196 	aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
       
   197 	error = SmfPluginErrNone;
       
   198 
       
   199 	qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString();
       
   200 	return error;
       
   201 	}
       
   202 
       
   203 /**
       
   204  * Method to get the list of self activities, e.g. shown in own wall
       
   205  * @param aRequest [out] The request data that plugin generates (to be sent to network)
       
   206  * @param aPageNum[in] The page to be extracted
       
   207  * @param aItemsPerPage[in] Number of items per page
       
   208  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
   209  */
       
   210 SmfPluginError FBActivityFetcherPlugin::getSelfActivities( SmfPluginRequestData &aRequest,
       
   211 		const int aPageNum, 
       
   212 		const int aItemsPerPage )
       
   213 	{
       
   214 	qDebug()<<"Inside FBActivityFetcherPlugin::getSelfActivities()";
       
   215 		
       
   216 	SmfPluginError error = SmfPluginErrInvalidArguments;
       
   217 
       
   218 	// invalid arguments
       
   219 	if( aPageNum < 0 || aItemsPerPage < 0 )
       
   220 		{
       
   221 		qDebug()<<"Invalid arguments";
       
   222 		return error;
       
   223 		}
       
   224 	
       
   225 	qDebug()<<"Valid arguments";
       
   226 	
       
   227 	// Get the key sets from SMF Plugin Utility class.
       
   228 	QString apiKey;
       
   229 	QString apiSecret;
       
   230 	QString sessionKey;
       
   231 	QString sessionSecret;
       
   232 	QString applicationId;
       
   233 	fetchKeys(apiKey, apiSecret, sessionKey, sessionSecret, applicationId);
       
   234 	
       
   235 	// Create the API signature string
       
   236 	QString baseString;
       
   237 	baseString.append("app_id="+applicationId);
       
   238 	baseString.append("session_key="+sessionKey);
       
   239 	baseString.append("source_id="+currentUserId);
       
   240 	baseString.append(sessionSecret);
       
   241 
       
   242 	// Create the url
       
   243 	QUrl url("http://www.facebook.com/activitystreams/feed.php?");
       
   244 	url.addQueryItem("app_id", applicationId);
       
   245 	url.addQueryItem("session_key", sessionKey);
       
   246 	url.addQueryItem("source_id", currentUserId);
       
   247 	url.addQueryItem("sig", generateSignature(baseString));
       
   248 	url.addQueryItem("v", "0.7");
       
   249 	QString str(url.toString());
       
   250 	str.append("&read");
       
   251 			
       
   252 	// Create the request, set the url
       
   253 	aRequest.iNetworkRequest.setUrl(QUrl(str));
       
   254 	aRequest.iRequestType = SmfActivitySelfActivity;
       
   255 	aRequest.iPostData = NULL;
       
   256 	aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
       
   257 	error = SmfPluginErrNone;
       
   258 
       
   259 	qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString();
       
   260 	return error;
       
   261 	}
       
   262 
       
   263 /**
       
   264  * Method to get the list of activities for other, e.g. shown in a friends wall
       
   265  * @param aRequest [out] The request data plugin generated (to be sent to network)
       
   266  * @param aContact [in] The contact containing the URI, name or id of the user 
       
   267  * @param aPageNum[in] The page to be extracted
       
   268  * @param aItemsPerPage[in] Number of items per page
       
   269  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
   270  */
       
   271 SmfPluginError FBActivityFetcherPlugin::friendsActivities( SmfPluginRequestData &aRequest,
       
   272 		const SmfContact &aContact,			
       
   273 		const int aPageNum, 
       
   274 		const int aItemsPerPage )
       
   275 	{
       
   276 	qDebug()<<"Inside FBActivityFetcherPlugin::friendsActivities()";
       
   277 		
       
   278 	SmfPluginError error = SmfPluginErrInvalidArguments;
       
   279 	chance = 1;
       
   280 
       
   281 	// invalid arguments
       
   282 	if( aPageNum < 0 || aItemsPerPage < 0 )
       
   283 		{
       
   284 		qDebug()<<"Invalid arguments";
       
   285 		return error;
       
   286 		}
       
   287 	
       
   288 	qDebug()<<"Valid arguments";
       
   289 	
       
   290 	// Get the key sets from SMF Plugin Utility class.
       
   291 	QString apiKey;
       
   292 	QString apiSecret;
       
   293 	QString sessionKey;
       
   294 	QString sessionSecret;
       
   295 	QString applicationId;
       
   296 	fetchKeys(apiKey, apiSecret, sessionKey, sessionSecret, applicationId);
       
   297 	
       
   298 	// ToDo :- Taking QContactGuid for the time being
       
   299 	QString sourceId = aContact.value("Guid").value<QContactGuid>().guid();
       
   300 	qDebug()<<"Friends facebook ID = "<<sourceId;
       
   301 	
       
   302 	// Create the API signature string
       
   303 	QString baseString;
       
   304 	baseString.append("app_id="+applicationId);
       
   305 	baseString.append("session_key="+sessionKey);
       
   306 	baseString.append("source_id="+sourceId);
       
   307 	baseString.append(sessionSecret);
       
   308 
       
   309 	// Create the url
       
   310 	QUrl url("http://www.facebook.com/activitystreams/feed.php?");
       
   311 	url.addQueryItem("app_id", applicationId);
       
   312 	url.addQueryItem("session_key", sessionKey);
       
   313 	url.addQueryItem("source_id", sourceId);
       
   314 	url.addQueryItem("sig", generateSignature(baseString));
       
   315 	url.addQueryItem("v", "0.7");
       
   316 	QString str(url.toString());
       
   317 	str.append("&read");
       
   318 			
       
   319 	// Create the request, set the url
       
   320 	aRequest.iNetworkRequest.setUrl(QUrl(str));
       
   321 	aRequest.iRequestType = SmfActivityFriendsActivities;
       
   322 	aRequest.iPostData = NULL;
       
   323 	aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
       
   324 	error = SmfPluginErrNone;
       
   325 
       
   326 	qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString();
       
   327 	return error;
       
   328 	}
       
   329 
       
   330 /**
       
   331  * Method to get list of self activities filtered by activity type, e.g. only photo updates in own wall
       
   332  * @param aRequest [out] The request data plugin generated (to be sent to network)
       
   333  * @param aFilters [in] The list of activity types to be included in result
       
   334  * @param aPageNum[in] The page to be extracted
       
   335  * @param aItemsPerPage[in] Number of items per page
       
   336  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
   337  */
       
   338 SmfPluginError FBActivityFetcherPlugin::filtered( SmfPluginRequestData &aRequest,
       
   339 		QList<SmfActivityObjectType> &aFilters,
       
   340 		const int aPageNum, 
       
   341 		const int aItemsPerPage )
       
   342 	{
       
   343 	qDebug()<<"Inside FBActivityFetcherPlugin::filtered()";
       
   344 		
       
   345 	Q_UNUSED(aRequest)
       
   346 	Q_UNUSED(aFilters)
       
   347 	Q_UNUSED(aPageNum)
       
   348 	Q_UNUSED(aItemsPerPage)
       
   349 	return SmfPluginErrServiceNotSupported; 
       
   350 	}
       
   351 
       
   352 /**
       
   353  * Customised method for SmfActivityFetcherPlugin interface
       
   354  * @param aRequest [out] The request data to be sent to network
       
   355  * @param aOperation The operation type (should be known between 
       
   356  * the client interface and the plugin)
       
   357  * @param aData The data required to form the request (The type 
       
   358  * of data should be known between client and the plugin)
       
   359  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
   360  */
       
   361 SmfPluginError FBActivityFetcherPlugin::customRequest( SmfPluginRequestData &aRequest, 
       
   362 		const int &aOperation, QByteArray *aData )
       
   363 	{
       
   364 	Q_UNUSED(aRequest)
       
   365 	Q_UNUSED(aOperation)
       
   366 	Q_UNUSED(aData)
       
   367 	qDebug()<<"Inside FBActivityFetcherPlugin::customRequest()";
       
   368 	return SmfPluginErrServiceNotSupported; 
       
   369 	}
       
   370 
       
   371 
       
   372 /**
       
   373  * The first method to be called in the plugin that implements this interface.
       
   374  * If this method is not called, plugin may not behave as expected.
       
   375  */
       
   376 void FBActivityFetcherPlugin::initialize( )
       
   377 	{
       
   378 	// Set the global value
       
   379 	forActivityObjectXmlTag = false;
       
   380 	forEntryXmlTag = false;
       
   381 	
       
   382 	// Create an instance of FBActivityProviderBase
       
   383 	m_provider = new FBActivityProviderBase;
       
   384 	m_provider->initialize();
       
   385 	}
       
   386 
       
   387 
       
   388 /**
       
   389  * Method to get the provider information
       
   390  * @return Instance of SmfProviderBase
       
   391  */
       
   392 SmfProviderBase* FBActivityFetcherPlugin::getProviderInfo( )
       
   393 	{
       
   394 	return m_provider;
       
   395 	}
       
   396 
       
   397 
       
   398 /**
       
   399  * Method to get the result for a network request.
       
   400  * @param aOperation The type of operation to be requested
       
   401  * @param aTransportResult The result of transport operation
       
   402  * @param aResponse The QByteArray instance containing the network response.
       
   403  * The plugins should delete this instance once they have read the 
       
   404  * data from it.
       
   405  * @param aResult [out] An output parameter to the plugin manager.If the 
       
   406  * return value is SmfSendRequestAgain, QVariant will be of type 
       
   407  * SmfPluginRequestData.
       
   408  * For SmfActivityFetcherPlugin: If last operation was selfActivities() or 
       
   409  * friendsActivities() or filtered(), aResult will be of type 
       
   410  * QList<SmfActivityEntry>. 
       
   411  * @param aRetType [out] SmfPluginRetType
       
   412  * @param aPageResult [out] The SmfResultPage structure variable
       
   413  */
       
   414 SmfPluginError FBActivityFetcherPlugin::responseAvailable( 
       
   415 		const SmfRequestTypeID aOperation,
       
   416 		const SmfTransportResult &aTransportResult, 
       
   417 		QByteArray *aResponse, 
       
   418 		QVariant* aResult, 
       
   419 		SmfPluginRetType &aRetType,
       
   420 		SmfResultPage &aPageResult )
       
   421 	{
       
   422 	Q_UNUSED(aPageResult)
       
   423 	qDebug()<<"Inside FBActivityFetcherPlugin::responseAvailable()";
       
   424 	
       
   425 	SmfPluginError error = SmfPluginErrNetworkError;
       
   426 	
       
   427 	if( !aResponse || (0 == aResponse->size()) )
       
   428 		{
       
   429 		qDebug()<<"Response is NULL or empty";
       
   430 		aRetType = SmfRequestError;
       
   431 		return error;
       
   432 		}
       
   433 	
       
   434 	QByteArray response(*aResponse);
       
   435 	delete aResponse;
       
   436 	
       
   437 	QFile respFile("c://data//SmfPluginActivityResponse.txt");
       
   438 	if(!respFile.open(QIODevice::WriteOnly))
       
   439 		qDebug()<<"File to write the response could not be opened";
       
   440 	else
       
   441 		{
       
   442 		respFile.write(response);
       
   443 		respFile.close();
       
   444 		qDebug()<<"Writing FB response to a file named 'SmfPluginActivityResponse.txt'";
       
   445 		}
       
   446 	qDebug()<<"FB response size = "<<response.size();
       
   447 	
       
   448 	
       
   449 	if(SmfTransportOpNoError == aTransportResult)
       
   450 		{
       
   451 		qDebug()<<"No transport error";
       
   452 		
       
   453 		if((SmfActivitySelfActivity == aOperation) ||
       
   454 				(SmfActivityFriendsActivities == aOperation))
       
   455 			{
       
   456 			qDebug()<<"Response for retrieving self/friends activities";
       
   457 			if(0 == chance)
       
   458 				{
       
   459 				chance = 1;
       
   460 				qDebug()<<"For Getting Current logged in User for self activity";
       
   461 				
       
   462 				QString errStr;
       
   463 				errStr.clear();
       
   464 				currentUserId.clear();
       
   465 
       
   466 				if(response.contains(QByteArray("error_msg")))
       
   467 					{
       
   468 					qDebug()<<"Response contains error, so parse and get the error code";
       
   469 					
       
   470 					bool ok;
       
   471 					SmfPluginUtil util;
       
   472 					QVariant result = util.parse(response, &ok);
       
   473 					if (!ok) 
       
   474 						{
       
   475 						qDebug()<<"An error occurred during json parsing, error = "<<util.errorString();
       
   476 						aRetType = SmfRequestError;
       
   477 						return SmfPluginErrParsingFailed;
       
   478 						}
       
   479 					else
       
   480 						{
       
   481 						QVariantMap map = result.toMap();
       
   482 						errStr.append(map["error_msg"].toString());
       
   483 						}
       
   484 					}
       
   485 				else
       
   486 					{
       
   487 					qDebug()<<"Response is ok, so don't parse";
       
   488 					currentUserId.append(response);
       
   489 					}
       
   490 				
       
   491 				if(errStr.size())
       
   492 					{
       
   493 					qDebug()<<"Response error found = "<<errStr;
       
   494 					error = SmfPluginErrInvalidRequest;
       
   495 					aRetType = SmfRequestError;
       
   496 					aResult->setValue(errStr);
       
   497 					}
       
   498 				else
       
   499 					{
       
   500 					qDebug()<<"current logged in uid  = "<<currentUserId;
       
   501 					aRetType = SmfSendRequestAgain;
       
   502 					error = SmfPluginErrNone;
       
   503 					}
       
   504 				}
       
   505 			else // chance == 1
       
   506 				{
       
   507 				qDebug()<<"For Fetching self/friends activities";
       
   508 				chance = 0;
       
   509 		
       
   510 				QList<SmfActivityEntry> list;
       
   511 				QString errStr;
       
   512 				errStr.clear();
       
   513 			
       
   514 				qDebug()<<"Xml parsing";
       
   515 				
       
   516 				// For getting contacts from xml response
       
   517 				QXmlStreamReader xml(response);
       
   518 				while (!xml.atEnd())
       
   519 					{
       
   520 					xml.readNext();
       
   521 					
       
   522 					if (xml.tokenType() == QXmlStreamReader::StartElement)
       
   523 						{
       
   524 						if (xml.qualifiedName().toString() == "entry")
       
   525 							{
       
   526 							currentObjectList.clear();
       
   527 							forEntryXmlTag = true;
       
   528 							}
       
   529 						else if (xml.qualifiedName().toString() == "title")
       
   530 							{
       
   531 							if(forEntryXmlTag)
       
   532 								{
       
   533 								SmfPost post;
       
   534 								post.setTitle(xml.readElementText());
       
   535 								myEntry.setTitle(post);
       
   536 								qDebug()<<"entry title = "<<myEntry.title().title();
       
   537 								}
       
   538 							}
       
   539 						else if (xml.qualifiedName().toString() == "fb:id")
       
   540 							{
       
   541 							if(forEntryXmlTag)
       
   542 								{
       
   543 								myEntry.setId(xml.readElementText());
       
   544 								qDebug()<<"entry id = "<<myEntry.id();
       
   545 								}
       
   546 							}
       
   547 						else if (xml.qualifiedName().toString() == "name") // author name
       
   548 							{
       
   549 							if(forEntryXmlTag)
       
   550 								{
       
   551 								QContactName name;
       
   552 								name.setFirstName(xml.readElementText());
       
   553 								QVariant var = QVariant::fromValue<QContactName>(name);
       
   554 								currentAuthor.setValue("Name", var);
       
   555 								}
       
   556 							}
       
   557 						else if(xml.qualifiedName().toString() == "uri")
       
   558 							{
       
   559 							if(forEntryXmlTag)
       
   560 								{
       
   561 								QContactUrl url;
       
   562 								url.setUrl(xml.readElementText());
       
   563 								QVariant var = QVariant::fromValue<QContactUrl>(url);
       
   564 								currentAuthor.setValue("Url", var);
       
   565 								myEntry.setAuthor(currentAuthor);
       
   566 								qDebug()<<"entry author name = "<<myEntry.author().value("Name").value<QContactName>().firstName();
       
   567 								//qDebug()<<"entry author uri = "<<myEntry.author().value("Url").value<QContactUrl>().url();
       
   568 								}
       
   569 							}
       
   570 						else if(xml.qualifiedName().toString() == "activity:verb")
       
   571 							{
       
   572 							if(forEntryXmlTag)
       
   573 								{
       
   574 								QString str(xml.readElementText());
       
   575 								str.remove(' ');
       
   576 								str.remove('\n');
       
   577 								SmfActivityVerb verb = convertActivityverb(str);
       
   578 								myEntry.setActionName(verb);
       
   579 								//qDebug()<<"entry actionname = "<<myEntry.actionName();
       
   580 								}
       
   581 							}
       
   582 						else if(xml.qualifiedName().toString() == "category")
       
   583 							{
       
   584 							if(forEntryXmlTag)
       
   585 								{
       
   586 								QStringRef str = xml.attributes().value("term");
       
   587 								SmfPost post;
       
   588 								post.setDescription(str.toString());
       
   589 								myEntry.setDetails(post);
       
   590 								qDebug()<<"entry details = "<<myEntry.details().description();
       
   591 								}
       
   592 							}
       
   593 						else if(xml.qualifiedName().toString() == "activity:object")
       
   594 							{
       
   595 							forActivityObjectXmlTag = true;
       
   596 							}
       
   597 						else if(xml.qualifiedName().toString() == "id")
       
   598 							{
       
   599 							if(forActivityObjectXmlTag)
       
   600 								currentObject.setId(xml.readElementText());
       
   601 							}
       
   602 						else if(xml.qualifiedName().toString() == "caption")
       
   603 							{
       
   604 							if(forActivityObjectXmlTag)
       
   605 								currentObject.setCaption(xml.readElementText());
       
   606 							}
       
   607 						else if(xml.qualifiedName().toString() == "link")
       
   608 							{
       
   609 							if(forActivityObjectXmlTag)
       
   610 								{
       
   611 								QStringRef str = xml.attributes().value("href");
       
   612 								currentObject.setLink(str.toString());
       
   613 								}
       
   614 							}
       
   615 						else if(xml.qualifiedName().toString() == "activity:object-type")
       
   616 							{
       
   617 							if(forActivityObjectXmlTag)
       
   618 								{
       
   619 								QString str(xml.readElementText());
       
   620 								str.remove(' ');
       
   621 								str.remove('\n');
       
   622 								SmfActivityObjectType type = convertActivityObjectType(str);
       
   623 								currentObject.setType(type);
       
   624 								}
       
   625 							}
       
   626 						else if(xml.qualifiedName().toString() == "published")
       
   627 							{
       
   628 							if(forActivityObjectXmlTag)
       
   629 								{
       
   630 								QDateTime dateTime = QDateTime::fromString(xml.readElementText(), Qt::ISODate);
       
   631 								currentObject.setTime(dateTime);
       
   632 								}
       
   633 							}
       
   634 						else if(xml.qualifiedName().toString() == "content")
       
   635 							{
       
   636 							if(forActivityObjectXmlTag)
       
   637 								{
       
   638 								currentObject.setContent(xml.readElementText());
       
   639 								}
       
   640 							}
       
   641 						else if("error_msg" == xml.qualifiedName().toString())
       
   642 							{
       
   643 							qDebug()<<"error_msg tag found";
       
   644 							errStr.append(xml.readElementText());
       
   645 							break;
       
   646 							}
       
   647 						}
       
   648 					if (xml.tokenType() == QXmlStreamReader::EndElement)
       
   649 						{
       
   650 						if (xml.qualifiedName().toString() == "entry")
       
   651 							{
       
   652 							forEntryXmlTag = false;
       
   653 							myEntry.setTargetObj(currentObjectList[0]);
       
   654 							myEntry.setActivities(currentObjectList);
       
   655 							list.append(myEntry);
       
   656 							if(list.count() == 5)
       
   657 								break;
       
   658 							}
       
   659 						else if(xml.qualifiedName().toString() == "activity:object")
       
   660 							{
       
   661 							forActivityObjectXmlTag = false;
       
   662 							
       
   663 							//qDebug()<<"object id = "<<currentObject.id();
       
   664 							//qDebug()<<"object caption = "<<currentObject.caption();
       
   665 							//qDebug()<<"object type = "<<currentObject.type();
       
   666 							//qDebug()<<"object link = "<<currentObject.link();
       
   667 							//qDebug()<<"object time = "<<currentObject.time().toString(Qt::TextDate);
       
   668 							//qDebug()<<"object content = "<<currentObject.content();
       
   669 							
       
   670 							currentObjectList.append(currentObject);
       
   671 							}
       
   672 						}
       
   673 					}
       
   674 				if(errStr.size())
       
   675 					{
       
   676 					qDebug()<<"Response error found = "<<errStr;
       
   677 					error = SmfPluginErrInvalidRequest;
       
   678 					aRetType = SmfRequestError;
       
   679 					aResult->setValue(errStr);
       
   680 					}
       
   681 				else
       
   682 					{
       
   683 					qDebug()<<"list count = "<<list.count();
       
   684 					aResult->setValue(list);
       
   685 					aRetType = SmfRequestComplete;
       
   686 					error = SmfPluginErrNone;
       
   687 					}
       
   688 				}
       
   689 			}
       
   690 		else
       
   691 			{
       
   692 			qDebug()<<"Service unsupported, currently only SmfActivitySelfActivity and SmfActivityFriendsActivities!!!";
       
   693 			aRetType = SmfRequestError;
       
   694 			error = SmfPluginErrServiceNotSupported;
       
   695 			}
       
   696 		}
       
   697 
       
   698 	else if(SmfTransportOpOperationCanceledError == aTransportResult)
       
   699 		{
       
   700 		qDebug()<<"Operation Cancelled !!!";
       
   701 		error = SmfPluginErrCancelComplete;
       
   702 		aRetType = SmfRequestComplete;
       
   703 		}
       
   704 
       
   705 	else
       
   706 		{
       
   707 		qDebug()<<"Transport Error !!!";
       
   708 		error = SmfPluginErrNetworkError;
       
   709 		aRetType = SmfRequestError;
       
   710 		}
       
   711 	
       
   712 	return error;
       
   713 	}
       
   714 
       
   715 
       
   716 /**
       
   717  * Method to convert the Activity verb string obtained from facebook to the 
       
   718  * enum SmfActivityVerb
       
   719  * @param verbStr The activity verb as a string
       
   720  * @return The corresponding enum SmfActivityVerb
       
   721  */
       
   722 SmfActivityVerb FBActivityFetcherPlugin::convertActivityverb( const QString& verbStr )
       
   723 	{
       
   724 	//qDebug()<<"verb as a string = "<<verbStr;
       
   725 	
       
   726 	SmfActivityVerb verb = (SmfActivityVerb)-1;
       
   727 	
       
   728 	if(QString("http://activitystrea.ms/schema/1.0/favorite/") == verbStr)	//0
       
   729 		verb = SmfActivityMarkAsFavorite;
       
   730 		
       
   731 	else if(QString("http://activitystrea.ms/schema/1.0/follow/") == verbStr)	//1
       
   732 		verb = SmfActivityStartFollowing;
       
   733 
       
   734 	else if(QString("http://activitystrea.ms/schema/1.0/like/") == verbStr)	//2
       
   735 		verb = SmfActivityMarkLiked;
       
   736 
       
   737 	else if(QString("http://activitystrea.ms/schema/1.0/make-friend/") == verbStr)	//3
       
   738 		verb = SmfActivityMakeFriend;
       
   739 
       
   740 	else if(QString("http://activitystrea.ms/schema/1.0/join/") == verbStr)	//4
       
   741 		verb = SmfActivityJoin;
       
   742 
       
   743 	else if(QString("http://activitystrea.ms/schema/1.0/play/") == verbStr)	//5
       
   744 		verb = SmfActivityPlay;
       
   745 
       
   746 	else if(QString("http://activitystrea.ms/schema/1.0/post/") == verbStr)	//6
       
   747 		verb = SmfActivityPost;
       
   748 
       
   749 	else if(QString("http://activitystrea.ms/schema/1.0/save/") == verbStr)	//7
       
   750 		verb = SmfActivitySave;
       
   751 
       
   752 	else if(QString("http://activitystrea.ms/schema/1.0/share/") == verbStr)	//8
       
   753 		verb = SmfActivityShare;
       
   754 
       
   755 	else if(QString("http://activitystrea.ms/schema/1.0/tag/") == verbStr)	//9
       
   756 		verb = SmfActivityTag;
       
   757 
       
   758 	else if(QString("http://activitystrea.ms/schema/1.0/update/") == verbStr)	//10
       
   759 		verb = SmfActivityUpdate;
       
   760 
       
   761 	//qDebug()<<"returned verb enum = "<<verb;
       
   762 	return verb;
       
   763 	}
       
   764 
       
   765 
       
   766 /**
       
   767  * Method to convert the Activity object type string obtained from 
       
   768  * facebook to the enum SmfActivityObjectType
       
   769  * @param objType The activity object type as a string
       
   770  * @return The corresponding enum SmfActivityObjectType
       
   771  */
       
   772 SmfActivityObjectType FBActivityFetcherPlugin::convertActivityObjectType( const QString& objType )
       
   773 	{
       
   774 	//qDebug()<<"type as a string = "<<objType;
       
   775 	
       
   776 	SmfActivityObjectType type = (SmfActivityObjectType)-1;
       
   777 	
       
   778 	if(QString("http://activitystrea.ms/schema/1.0/article/") == objType)	//0
       
   779 		type = SmfActivityObjTypeArticle;
       
   780 
       
   781 	else if(QString("http://activitystrea.ms/schema/1.0/audio/") == objType)	//1
       
   782 		type = SmfActivityObjTypeAudio;
       
   783 
       
   784 	else if(QString("http://activitystrea.ms/schema/1.0/bookmark/") == objType)	//2
       
   785 		type = SmfActivityObjTypeBookmark;
       
   786 
       
   787 	else if(QString("http://activitystrea.ms/schema/1.0/comment/") == objType)	//3
       
   788 		type = SmfActivityObjTypeComment;
       
   789 
       
   790 	else if(QString("http://activitystrea.ms/schema/1.0/file/") == objType)	//4
       
   791 		type = SmfActivityObjTypeFile;
       
   792 
       
   793 	else if(QString("http://activitystrea.ms/schema/1.0/folder/") == objType)	//5
       
   794 		type = SmfActivityObjTypeFolder;
       
   795 
       
   796 	else if(QString("http://activitystrea.ms/schema/1.0/group/") == objType)	//6
       
   797 		type = SmfActivityObjTypeGroup;
       
   798 
       
   799 	else if(QString("http://activitystrea.ms/schema/1.0/list/") == objType)  // 7, ToDo :- Note sure about this string
       
   800 		type = SmfActivityObjTypeList;
       
   801 
       
   802 	else if(QString("http://activitystrea.ms/schema/1.0/note/") == objType)	//8
       
   803 		type = SmfActivityObjTypeNote;
       
   804 
       
   805 	else if(QString("http://activitystrea.ms/schema/1.0/person/") == objType)	//9
       
   806 		type = SmfActivityObjTypePerson;
       
   807 
       
   808 	else if(QString("http://activitystrea.ms/schema/1.0/photo/") == objType)	//10
       
   809 		type = SmfActivityObjTypePhoto;
       
   810 
       
   811 	else if(QString("http://activitystrea.ms/schema/1.0/photo-album/") == objType)	//11
       
   812 		type = SmfActivityObjTypePhotoAlbum;
       
   813 
       
   814 	else if(QString("http://activitystrea.ms/schema/1.0/place/") == objType)	//12
       
   815 		type = SmfActivityObjTypePlace;
       
   816 
       
   817 	else if(QString("http://activitystrea.ms/schema/1.0/playlist/") == objType)	//13
       
   818 		type = SmfActivityObjTypePlaylist;
       
   819 
       
   820 	else if(QString("http://activitystrea.ms/schema/1.0/product/") == objType)	//14
       
   821 		type = SmfActivityObjTypeProduct;
       
   822 
       
   823 	else if(QString("http://activitystrea.ms/schema/1.0/review/") == objType)	//15
       
   824 		type = SmfActivityObjTypeReview;
       
   825 
       
   826 	else if(QString("http://activitystrea.ms/schema/1.0/service/") == objType)	//16
       
   827 		type = SmfActivityObjTypeService;
       
   828 
       
   829 	else if(QString("http://activitystrea.ms/schema/1.0/status/") == objType)	//17
       
   830 		type = SmfActivityObjTypeStatus;
       
   831 
       
   832 	else if(QString("http://activitystrea.ms/schema/1.0/video/") == objType)	//18
       
   833 		type = SmfActivityObjTypeVideo;
       
   834 
       
   835 	else if(QString("http://activitystrea.ms/schema/1.0/song/") == objType)	//19
       
   836 		type = SmfActivityObjTypeMusic;
       
   837 
       
   838 	else if(QString("http://activitystrea.ms/schema/1.0/event/") == objType)	//20
       
   839 		type = SmfActivityObjTypeEvent;
       
   840 
       
   841 	// ToDo :- No strings found for 'SmfActivityObjTypeAdvanced" in 
       
   842 	// http://activitystrea.ms/schema/1.0/activity-schema-01.html
       
   843 	// So setting it as default when no standard string is found
       
   844 	else
       
   845 		type = SmfActivityObjTypeAdvanced;									//21
       
   846 			
       
   847 	//qDebug()<<"returned type enum = "<<type;
       
   848 	return type;
       
   849 	}
       
   850 
       
   851 /**
       
   852  * Destructor
       
   853  */
       
   854 FBActivityProviderBase::~FBActivityProviderBase( )
       
   855 	{
       
   856 	}
       
   857 
       
   858 
       
   859 /**
       
   860  * Method to get the Localisable name of the service.
       
   861  * @return The Localisable name of the service.
       
   862  */
       
   863 QString FBActivityProviderBase::serviceName( ) const
       
   864 	{
       
   865 	return m_serviceName;
       
   866 	}
       
   867 
       
   868 
       
   869 /**
       
   870  * Method to get the Logo of the service
       
   871  * @return The Logo of the service
       
   872  */
       
   873 QImage FBActivityProviderBase::serviceIcon( ) const
       
   874 	{
       
   875 	return m_serviceIcon;
       
   876 	}
       
   877 
       
   878 
       
   879 /**
       
   880  * Method to get the Readable service description
       
   881  * @return The Readable service description
       
   882  */
       
   883 QString FBActivityProviderBase::description( ) const
       
   884 	{
       
   885 	return m_description;
       
   886 	}
       
   887 
       
   888 
       
   889 /**
       
   890  * Method to get the Website of the service
       
   891  * @return The Website of the service
       
   892  */
       
   893 QUrl FBActivityProviderBase::serviceUrl( ) const
       
   894 	{
       
   895 	return m_serviceUrl;
       
   896 	}
       
   897 
       
   898 
       
   899 /**
       
   900  * Method to get the URL of the Application providing this service
       
   901  * @return The URL of the Application providing this service
       
   902  */
       
   903 QUrl FBActivityProviderBase::applicationUrl( ) const
       
   904 	{
       
   905 	return m_applicationUrl;
       
   906 	}
       
   907 
       
   908 
       
   909 /**
       
   910  * Method to get the Icon of the application
       
   911  * @return The Icon of the application
       
   912  */
       
   913 QImage FBActivityProviderBase::applicationIcon( ) const
       
   914 	{
       
   915 	return m_applicationIcon;
       
   916 	}
       
   917 
       
   918 /**
       
   919 * Method to get the list of interfaces that this provider support
       
   920 * @return List of supported Interafces
       
   921 */
       
   922 QList<QString> FBActivityProviderBase::supportedInterfaces( ) const
       
   923 	{
       
   924 	return m_supportedInterfaces;
       
   925 	}
       
   926 
       
   927 /**
       
   928 * Method to get the list of languages supported by this service provider
       
   929 * @return a QStringList of languages supported by this service 
       
   930 * provider in 2 letter ISO 639-1 format.
       
   931 */
       
   932 QStringList FBActivityProviderBase::supportedLanguages( ) const
       
   933 	{
       
   934 	return m_supportedLangs;
       
   935 	}
       
   936 
       
   937 /**
       
   938  * Method to get the Plugin specific ID
       
   939  * @return The Plugin specific ID
       
   940  */
       
   941 QString FBActivityProviderBase::pluginId( ) const
       
   942 	{
       
   943 	return m_pluginId;
       
   944 	}
       
   945 
       
   946 
       
   947 /**
       
   948  * Method to get the ID of the authentication application 
       
   949  * for this service
       
   950  * @param aProgram The authentication application name
       
   951  * @param aArguments List of arguments required for authentication app
       
   952  * @param aMode Strting mode for authentication application
       
   953  * @return The ID of the authentication application 
       
   954  */
       
   955 QString FBActivityProviderBase::authenticationApp( QString &aProgram, 
       
   956 		QStringList & aArguments, 
       
   957 		QIODevice::OpenModeFlag aMode ) const
       
   958 	{
       
   959 	Q_UNUSED(aProgram)
       
   960 	Q_UNUSED(aArguments)
       
   961 	Q_UNUSED(aMode)
       
   962 	return m_authAppId;
       
   963 	}
       
   964 
       
   965 
       
   966 /**
       
   967  * Method to get the unique registration ID provided by the 
       
   968  * Smf for authorised plugins
       
   969  * @return The unique registration ID/token provided by the Smf for 
       
   970  * authorised plugins
       
   971  */
       
   972 QString FBActivityProviderBase::smfRegistrationId( ) const
       
   973 	{
       
   974 	return m_smfRegToken;
       
   975 	}
       
   976 
       
   977 
       
   978 /**
       
   979  * Method that initializes this class. This method should be called 
       
   980  * from the initialize() method of the FBActivityFetcherPlugin class
       
   981  */
       
   982 void FBActivityProviderBase::initialize()
       
   983 	{
       
   984 	m_serviceName = "Facebook";
       
   985 	m_description = "Facebook activity fetcher plugin description";
       
   986 	m_serviceUrl = QUrl(QString("http://www.facebook.com"));
       
   987 	m_pluginId = "fbactivityfetcherplugin.qtplugin";
       
   988 	m_authAppId = "0xEFE2FD23";
       
   989 	m_supportedInterfaces.append("org.symbian.smf.plugin.activity.fetcher/v0.2");
       
   990 	QSettings iSettings;
       
   991 	m_smfRegToken = iSettings.value("FBCMRegToken").toString();
       
   992 	m_validity = iSettings.value("FBExpiryTime").toDateTime();
       
   993 	}
       
   994 
       
   995 
       
   996 /*
       
   997  * Export Macro
       
   998  * plugin name : fbactivityfetcherplugin
       
   999  * plugin class : FBActivityFetcherPlugin
       
  1000  */
       
  1001 Q_EXPORT_PLUGIN2( fbactivityfetcherplugin, FBActivityFetcherPlugin )
       
  1002