example/fbpostproviderplugin/fbpostproviderplugin.cpp
changeset 17 106a4bfcb866
parent 14 a469c0e6e7fb
child 26 83d6a149c755
equal deleted inserted replaced
16:b78fa4cdbf2b 17:106a4bfcb866
    23 #include <QTextFormat>
    23 #include <QTextFormat>
    24 #include <QFile>
    24 #include <QFile>
    25 #include <QVariant>
    25 #include <QVariant>
    26 #include <QListIterator>
    26 #include <QListIterator>
    27 #include <QDebug>
    27 #include <QDebug>
       
    28 #include <QSettings>
       
    29 #include <smfpluginutil.h>
    28 #ifdef SMF_XMLPARSING
    30 #ifdef SMF_XMLPARSING
    29 #include <QXmlStreamReader>
    31 #include <QXmlStreamReader>
    30 #endif
    32 #endif
    31 
    33 
    32 #include "fbpostproviderplugin.h"
    34 #include "fbpostproviderplugin.h"
    37 SmfPost mypost;
    39 SmfPost mypost;
    38 SmfContact contact;
    40 SmfContact contact;
    39 QString currentId;
    41 QString currentId;
    40 #endif
    42 #endif
    41 QMap<QString, QString> idNameMap;
    43 QMap<QString, QString> idNameMap;
       
    44 QMap<QString, QString> idPicMap;
       
    45 
       
    46 
       
    47 // Todo:- Macro added for limiting items fetched to recent 5
       
    48 // Remove after demo
       
    49 #define SETLIMITOFFIVEFORSMFDEMO 1
    42 
    50 
    43 /**
    51 /**
    44  * Method called by plugins to generate a signature string from a base string
    52  * Method called by plugins to generate a signature string from a base string
    45  * @param aBaseString The base string
    53  * @param aBaseString The base string
    46  * @return The md5 hash of the base string
    54  * @return The md5 hash of the base string
    55 
    63 
    56     QByteArray md5Hash = QCryptographicHash::hash(byteArray,QCryptographicHash::Md5 ).toHex();
    64     QByteArray md5Hash = QCryptographicHash::hash(byteArray,QCryptographicHash::Md5 ).toHex();
    57     QString returnString (md5Hash);
    65     QString returnString (md5Hash);
    58     return returnString;
    66     return returnString;
    59 	}
    67 	}
       
    68 
       
    69 
       
    70 /**
       
    71  * Method to interpret the key sets obtained from credential manager 
       
    72  * @param aApiKey [out] The api key
       
    73  * @param aApiSecret [out] The api secret
       
    74  * @param aSessionKey [out] The session key
       
    75  * @param aSessionSecret [out] The session secret
       
    76  */
       
    77 void FBPostProviderPlugin::fetchKeys( QString &aApiKey, 
       
    78 		QString &aApiSecret, 
       
    79 		QString &aSessionKey, 
       
    80 		QString &aSessionSecret )
       
    81 	{
       
    82 	qDebug()<<"Inside FBPostProviderPlugin::fetchKeys()";
       
    83 
       
    84 	qDebug()<<"Reg Token = "<<m_provider->m_smfRegToken;
       
    85 	qDebug()<<"Expiry Date as int = "<<m_provider->m_validity.toTime_t();
       
    86 	
       
    87 	SmfAuthParams keys;
       
    88 	SmfPluginUtil util;
       
    89 	util.getAuthKeys(keys, m_provider->m_smfRegToken, 
       
    90 			m_provider->m_validity, m_provider->m_pluginId);
       
    91 	
       
    92 	qDebug()<<"Number of key-value pairs = "<<keys.count();
       
    93 	
       
    94     QByteArray keyName;
       
    95     keyName.append("ApiKey");
       
    96 	aApiKey.append(keys.value(keyName));
       
    97 	
       
    98     keyName.clear();
       
    99     keyName.append("ApiSecret");
       
   100 	aApiSecret.append(keys.value(keyName));
       
   101 	
       
   102 	keyName.clear();
       
   103     keyName.append("SessionKey");
       
   104 	aSessionKey.append(keys.value(keyName));
       
   105 	
       
   106 	keyName.clear();
       
   107     keyName.append("SessionSecret");
       
   108 	aSessionSecret.append(keys.value(keyName));
       
   109 	
       
   110 	qDebug()<<"Api Key = "<<aApiKey;
       
   111 	qDebug()<<"Api Secret = "<<aApiSecret;
       
   112 	qDebug()<<"session Key = "<<aSessionKey;
       
   113 	qDebug()<<"session Secret = "<<aSessionSecret;
       
   114 	}
       
   115 
    60 
   116 
    61 /**
   117 /**
    62  * Destructor
   118  * Destructor
    63  */
   119  */
    64 FBPostProviderPlugin::~FBPostProviderPlugin( )
   120 FBPostProviderPlugin::~FBPostProviderPlugin( )
    99  * @return Supported formats of posts
   155  * @return Supported formats of posts
   100  */
   156  */
   101 QVector<QTextFormat> FBPostProviderPlugin::supportedFormats ( ) const
   157 QVector<QTextFormat> FBPostProviderPlugin::supportedFormats ( ) const
   102 	{
   158 	{
   103 	qDebug()<<"Inside FBPostProviderPlugin::supportedFormats()";
   159 	qDebug()<<"Inside FBPostProviderPlugin::supportedFormats()";
       
   160 	QTextFormat f1, f2;
   104 	QVector<QTextFormat> data;
   161 	QVector<QTextFormat> data;
       
   162 	data.append(f1);
       
   163 	data.append(f2);
   105 	return data;
   164 	return data;
   106 	}
   165 	}
   107 
   166 
   108 /**
   167 /**
   109  * Method that returns whether this SP supports Appearence
   168  * Method that returns whether this SP supports Appearence
   111  * @see SmfAppearenceInfo
   170  * @see SmfAppearenceInfo
   112  */
   171  */
   113 bool FBPostProviderPlugin::supportsAppearence ( ) const
   172 bool FBPostProviderPlugin::supportsAppearence ( ) const
   114 	{
   173 	{
   115 	qDebug()<<"Inside FBPostProviderPlugin::supportsAppearence()";
   174 	qDebug()<<"Inside FBPostProviderPlugin::supportsAppearence()";
   116 	return false;
   175 	return true;
   117 	}
   176 	}
   118 
   177 
   119 /**
   178 /**
   120  * Method to get the latest posts
   179  * Method to get the latest posts
   121  * @param aRequest [out] The request data to be sent to network
   180  * @param aRequest [out] The request data to be sent to network
   127 SmfPluginError FBPostProviderPlugin::retrieve( SmfPluginRequestData &aRequest,
   186 SmfPluginError FBPostProviderPlugin::retrieve( SmfPluginRequestData &aRequest,
   128 		const SmfContact *aUser,
   187 		const SmfContact *aUser,
   129 		const int aPageNum , 
   188 		const int aPageNum , 
   130 		const int aItemsPerPage  )
   189 		const int aItemsPerPage  )
   131 	{
   190 	{
   132 	Q_UNUSED(aUser)
       
   133 	qDebug()<<"Inside FBPostProviderPlugin::retrieve()";
   191 	qDebug()<<"Inside FBPostProviderPlugin::retrieve()";
       
   192 	
       
   193 	if(0 != aUser->value("Guid").value<QContactGuid>().guid().size())
       
   194 		chance = 1;
   134 	
   195 	
   135 	//// Currently considering for self contact , ie, omitting aUser
   196 	//// Currently considering for self contact , ie, omitting aUser
   136 	if(0 == chance)
   197 	if(0 == chance)
   137 		return getFacebookUserId(aRequest);
   198 		return getFacebookUserId(aRequest);
   138 	else
   199 	else
   139 		return getPosts(aRequest, aPageNum , aItemsPerPage);
   200 		return getPosts(aRequest, aUser, aPageNum , aItemsPerPage);
   140 	}
   201 	}
   141 
   202 
   142 
   203 
   143 /**
   204 /**
   144  * Method to get the user's facebook ID
   205  * Method to get the user's facebook ID
   150 	{
   211 	{
   151 	qDebug()<<"Inside FBPostProviderPlugin::getFacebookUserId()";
   212 	qDebug()<<"Inside FBPostProviderPlugin::getFacebookUserId()";
   152 	
   213 	
   153 	SmfPluginError error = SmfPluginErrUserNotLoggedIn;
   214 	SmfPluginError error = SmfPluginErrUserNotLoggedIn;
   154 	
   215 	
   155 #if 1
   216 	// Get the key sets from SMF Plugin Utility class.
   156 // Reading the keys, CSM Stubbed - START
   217 	QString apiKey;
   157 	QFile file("c:\\data\\FacebookKeys.txt");
   218 	QString apiSecret;
   158 	if (!file.open(QIODevice::ReadOnly))
   219 	QString sessionKey;
   159 		{
   220 	QString sessionSecret;
   160 		qDebug()<<"File to read the keys could not be opened";
   221 	fetchKeys(apiKey, apiSecret, sessionKey, sessionSecret);
   161 		return error;
       
   162 		}
       
   163 	
       
   164 	qDebug()<<"Key file read, going to parse the key values from file";
       
   165 	
       
   166 	QByteArray arr = file.readAll();
       
   167 	QList<QByteArray> list = arr.split('\n');
       
   168 	file.close();
       
   169 
       
   170 	QString apiKey(list[0]);
       
   171 	QString apiSecret(list[1]);
       
   172 	QString sessionKey(list[2]);
       
   173 	QString sessionSecret(list[3]);
       
   174 	
       
   175 	qDebug()<<"Api Key = "+apiKey;
       
   176 	qDebug()<<"Api Secret = "+apiSecret;
       
   177 	qDebug()<<"session Key = "+sessionKey;
       
   178 	qDebug()<<"session Secret = "+sessionSecret;
       
   179 // Reading the keys, CSM Stubbed - END
       
   180 #endif
       
   181 	
   222 	
   182 	// Get the current date and time and convert it to sec as a string
   223 	// Get the current date and time and convert it to sec as a string
   183 	QString call_id = QString::number(QDateTime::currentDateTime().toTime_t(), 10);
   224 	QString call_id = QString::number(QDateTime::currentDateTime().toTime_t(), 10);
   184 	
   225 	
   185 	// Create the API signature string
   226 	// Create the API signature string
   224 	}
   265 	}
   225 
   266 
   226 /**
   267 /**
   227  * Method to get the user's posts
   268  * Method to get the user's posts
   228  * @param aRequest [out] The request data to be sent to network
   269  * @param aRequest [out] The request data to be sent to network
       
   270  * @param aUser The user's contact in this SP, omit for self contact
   229  * @param aPageNum The page to be extracted
   271  * @param aPageNum The page to be extracted
   230  * @param aItemsPerPage Number of items per page
   272  * @param aItemsPerPage Number of items per page
   231  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
   273  * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
   232  */
   274  */
   233 SmfPluginError FBPostProviderPlugin::getPosts( 
   275 SmfPluginError FBPostProviderPlugin::getPosts( 
   234 		SmfPluginRequestData &aRequest,
   276 		SmfPluginRequestData &aRequest,
       
   277 		const SmfContact *aUser, 
   235 		const int aPageNum , 
   278 		const int aPageNum , 
   236 		const int aItemsPerPage  )
   279 		const int aItemsPerPage  )
   237 	{
   280 	{
   238 	qDebug()<<"Inside FBPostProviderPlugin::getPosts()";
   281 	qDebug()<<"Inside FBPostProviderPlugin::getPosts()";
       
   282 	qDebug()<<"Required guid = "<<aUser->value("Guid").value<QContactGuid>().guid();
   239 	qDebug()<<"aPageNum = "<<aPageNum;
   283 	qDebug()<<"aPageNum = "<<aPageNum;
   240 	qDebug()<<"aItemsPerPage = "<<aItemsPerPage;
   284 	qDebug()<<"aItemsPerPage = "<<aItemsPerPage;
   241 	
   285 	
   242 	SmfPluginError error = SmfPluginErrInvalidArguments;
   286 	SmfPluginError error = SmfPluginErrInvalidArguments;
   243 	
   287 	
   248 		return error;
   292 		return error;
   249 		}
   293 		}
   250 	
   294 	
   251 	qDebug()<<"Valid arguments";
   295 	qDebug()<<"Valid arguments";
   252 	
   296 	
   253 #if 1
   297 	// Get the key sets from SMF Plugin Utility class.
   254 // Reading the keys, CSM Stubbed - START
   298 	QString apiKey;
   255 	QFile file("c:\\data\\FacebookKeys.txt");
   299 	QString apiSecret;
   256 	if (!file.open(QIODevice::ReadOnly))
   300 	QString sessionKey;
   257 		{
   301 	QString sessionSecret;
   258 		qDebug()<<"File to read the keys could not be opened";
   302 	fetchKeys(apiKey, apiSecret, sessionKey, sessionSecret);
   259 		return SmfPluginErrUserNotLoggedIn;
       
   260 		}
       
   261 	
       
   262 	qDebug()<<"Key file read, going to parse the key values from file";
       
   263 	
       
   264 	QByteArray arr = file.readAll();
       
   265 	QList<QByteArray> list = arr.split('\n');
       
   266 	file.close();
       
   267 	
       
   268 	QString apiKey(list[0]);
       
   269 	QString apiSecret(list[1]);
       
   270 	QString sessionKey(list[2]);
       
   271 	QString sessionSecret(list[3]);
       
   272 	
       
   273 	qDebug()<<"Api Key = "+apiKey;
       
   274 	qDebug()<<"Api Secret = "+apiSecret;
       
   275 	qDebug()<<"session Key = "+sessionKey;
       
   276 	qDebug()<<"session Secret = "+sessionSecret;
       
   277 // Reading the keys, CSM Stubbed - END
       
   278 #endif
       
   279 	
   303 	
   280 	// Get the current date and time and convert it to sec as a string
   304 	// Get the current date and time and convert it to sec as a string
   281 	QString call_id = QString::number(QDateTime::currentDateTime().toTime_t(), 10);
   305 	QString call_id = QString::number(QDateTime::currentDateTime().toTime_t(), 10);
   282 	
   306 	
   283 	// Create the API signature string
   307 	// Create the API signature string
   287 #ifdef SMF_XMLPARSING
   311 #ifdef SMF_XMLPARSING
   288 	baseString.append("format=XML");
   312 	baseString.append("format=XML");
   289 #else
   313 #else
   290 	baseString.append("format=JSON");
   314 	baseString.append("format=JSON");
   291 #endif
   315 #endif
       
   316 	
       
   317 #ifdef SETLIMITOFFIVEFORSMFDEMO  // Hard coding the number of posts fetched as recent 5
       
   318 	qDebug()<<"Hardcoding pagenumber and itemperpage to fetch 5 recent posts";
       
   319 	int val = 5;
       
   320 	baseString.append("limit="+QString::number(val));
       
   321 #else
   292 	if(0 == aPageNum)
   322 	if(0 == aPageNum)
   293 		{
   323 		baseString.append("limit="+QString::number((aItemsPerPage*(aPageNum+1)), 10));
   294 		//baseString.append("limit="+QString::number((aItemsPerPage*(aPageNum+1)), 10));
       
   295 		qDebug()<<"Hardcoding pagenumber and itemperpage to fetch 5 posts";
       
   296 		int val = 5;
       
   297 		baseString.append("limit="+QString::number(val));
       
   298 		}
       
   299 	else
   324 	else
   300 		baseString.append("limit="+QString::number((aItemsPerPage*aPageNum), 10));
   325 		baseString.append("limit="+QString::number((aItemsPerPage*aPageNum), 10));
       
   326 #endif
       
   327 
   301 	baseString.append("method=stream.get");
   328 	baseString.append("method=stream.get");
   302 	baseString.append("session_key="+sessionKey);
   329 	baseString.append("session_key="+sessionKey);
       
   330 	if(0 != aUser->value("Guid").value<QContactGuid>().guid().size())
       
   331 		baseString.append("source_ids="+aUser->value("Guid").value<QContactGuid>().guid());
       
   332 	else
   303 	baseString.append("source_ids="+uid);
   333 	baseString.append("source_ids="+uid);
   304 	baseString.append("ss=1");
   334 	baseString.append("ss=1");
   305 	baseString.append("v=1.0");
   335 	baseString.append("v=1.0");
   306 	baseString.append(sessionSecret);
   336 	baseString.append(sessionSecret);
   307 
   337 
   312 #ifdef SMF_XMLPARSING
   342 #ifdef SMF_XMLPARSING
   313 	url.addQueryItem("format", "XML");
   343 	url.addQueryItem("format", "XML");
   314 #else
   344 #else
   315 	url.addQueryItem("format", "JSON");
   345 	url.addQueryItem("format", "JSON");
   316 #endif
   346 #endif
       
   347 		
       
   348 #ifdef SETLIMITOFFIVEFORSMFDEMO  // Hard coding the number of posts fetched as recent 5
       
   349 	qDebug()<<"Hardcoding pagenumber and itemperpage to fetch 5 recent posts";
       
   350 	val = 5;
       
   351 	url.addQueryItem("limit", QString::number(val));
       
   352 #else
   317 	if(0 == aPageNum)
   353 	if(0 == aPageNum)
   318 		{
   354 		url.addQueryItem("limit", QString::number((aItemsPerPage*(aPageNum+1)), 10));
   319 //		url.addQueryItem("limit", QString::number((aItemsPerPage*(aPageNum+1)), 10));
       
   320 		qDebug()<<"Hardcoding pagenumber and itemperpage to fetch 5 posts";
       
   321 		int val = 5;
       
   322 		url.addQueryItem("limit", QString::number(val));
       
   323 		}
       
   324 	else
   355 	else
   325 		url.addQueryItem("limit", QString::number((aItemsPerPage*aPageNum), 10));
   356 		url.addQueryItem("limit", QString::number((aItemsPerPage*aPageNum), 10));
       
   357 #endif
       
   358 
   326 	url.addQueryItem("method", "stream.get");
   359 	url.addQueryItem("method", "stream.get");
   327 	url.addQueryItem("session_key", sessionKey);
   360 	url.addQueryItem("session_key", sessionKey);
       
   361 	if(0 != aUser->value("Guid").value<QContactGuid>().guid().size())
       
   362 		url.addQueryItem("source_ids",aUser->value("Guid").value<QContactGuid>().guid());
       
   363 	else
   328 	url.addQueryItem("source_ids",uid);
   364 	url.addQueryItem("source_ids",uid);
   329 	url.addQueryItem("ss", "1");
   365 	url.addQueryItem("ss", "1");
   330 	url.addQueryItem("v", "1.0");	
   366 	url.addQueryItem("v", "1.0");	
   331 	url.addQueryItem("sig", generateSignature(baseString));
   367 	url.addQueryItem("sig", generateSignature(baseString));
   332 	
   368 	
   404 		return error;
   440 		return error;
   405 		}
   441 		}
   406 	
   442 	
   407 	qDebug()<<"Valid arguments";
   443 	qDebug()<<"Valid arguments";
   408 			
   444 			
   409 #if 1
   445 	// Get the key sets from SMF Plugin Utility class.
   410 // Reading the keys, CSM Stubbed - START
   446 	QString apiKey;
   411 	QFile file("c:\\data\\FacebookKeys.txt");
   447 	QString apiSecret;
   412 	if (!file.open(QIODevice::ReadOnly))
   448 	QString sessionKey;
   413 		{
   449 	QString sessionSecret;
   414 		qDebug()<<"File to read the keys could not be opened";
   450 	fetchKeys(apiKey, apiSecret, sessionKey, sessionSecret);
   415 		return SmfPluginErrUserNotLoggedIn;
       
   416 		}
       
   417 	
       
   418 	qDebug()<<"Key file read, going to parse the key values from file";
       
   419 	
       
   420 	QByteArray arr = file.readAll();
       
   421 	QList<QByteArray> list = arr.split('\n');
       
   422 	file.close();
       
   423 	
       
   424 	QString apiKey(list[0]);
       
   425 	QString apiSecret(list[1]);
       
   426 	QString sessionKey(list[2]);
       
   427 	QString sessionSecret(list[3]);
       
   428 	
       
   429 	qDebug()<<"Api Key = "<<apiKey;
       
   430 	qDebug()<<"Api Secret = "<<apiSecret;
       
   431 	qDebug()<<"session Key = "<<sessionKey;
       
   432 	qDebug()<<"session Secret = "<<sessionSecret;
       
   433 // Reading the keys, CSM Stubbed - END
       
   434 #endif
       
   435 			
   451 			
   436 	// Get the current date and time and convert it to sec as a string
   452 	// Get the current date and time and convert it to sec as a string
   437 	QString call_id = QString::number(QDateTime::currentDateTime().toTime_t(), 10);
   453 	QString call_id = QString::number(QDateTime::currentDateTime().toTime_t(), 10);
   438 	
   454 	
   439 	// Create the API signature string
   455 	// Create the API signature string
   568 
   584 
   569 
   585 
   570 /**
   586 /**
   571  * The first method to be called in the plugin that implements this interface.
   587  * The first method to be called in the plugin that implements this interface.
   572  * If this method is not called, plugin may not behave as expected.
   588  * If this method is not called, plugin may not behave as expected.
   573  * Plugins are expected to save the aUtil handle and use and when required.
   589  */
   574  * @param aUtil The instance of SmfPluginUtil
   590 void FBPostProviderPlugin::initialize( )
   575  */
   591 	{
   576 void FBPostProviderPlugin::initialize( SmfPluginUtil *aUtil )
       
   577 	{
       
   578 	// Save the SmfPluginUtil handle
       
   579 	m_util = aUtil;
       
   580 	
       
   581 	// Create an instance of FlickrProviderBase
   592 	// Create an instance of FlickrProviderBase
   582 	m_provider = new FBProviderBase;
   593 	m_provider = new FBProviderBase;
   583 	m_provider->initialize();
   594 	m_provider->initialize();
   584 	}
   595 	}
   585 
   596 
   628 		return error;
   639 		return error;
   629 		}
   640 		}
   630 	
   641 	
   631 	QByteArray response(*aResponse);
   642 	QByteArray response(*aResponse);
   632 	delete aResponse;
   643 	delete aResponse;
   633 	qDebug()<<"FB response = "<<QString(response);
   644 	
       
   645 	QFile respFile("c://data//SmfPluginFBPostResponse.txt");
       
   646 	if(!respFile.open(QIODevice::WriteOnly))
       
   647 		{
       
   648 		qDebug()<<"File to write the response could not be opened, so writing to this file";
       
   649 		qDebug()<<"Flickr response = "<<QString(response);
       
   650 		}
       
   651 	else
       
   652 		{
       
   653 		respFile.write(response);
       
   654 		respFile.close();
       
   655 		qDebug()<<"Writing FB response to a file named 'SmfPluginFBPostResponse.txt'";
       
   656 		}
       
   657 	
   634 	qDebug()<<"FB response size = "<<response.size();
   658 	qDebug()<<"FB response size = "<<response.size();
   635 	
   659 	
   636 	if(SmfTransportOpNoError == aTransportResult)
   660 	if(SmfTransportOpNoError == aTransportResult)
   637 		{
   661 		{
   638 		qDebug()<<"No transport error";
   662 		qDebug()<<"No transport error";
   677 				if(response.contains(QByteArray("error_msg")))
   701 				if(response.contains(QByteArray("error_msg")))
   678 					{
   702 					{
   679 					qDebug()<<"Response contains error, so parse and get the error code";
   703 					qDebug()<<"Response contains error, so parse and get the error code";
   680 					
   704 					
   681 					bool ok;
   705 					bool ok;
   682 					QVariant result = m_util->parse(response, &ok);
   706 					SmfPluginUtil util;
       
   707 					QVariant result = util.parse(response, &ok);
   683 					if (!ok) 
   708 					if (!ok) 
   684 						{
   709 						{
   685 						qDebug()<<"An error occurred during json parsing, error = "<<m_util->errorString();
   710 						qDebug()<<"An error occurred during json parsing, error = "<<util.errorString();
   686 						aRetType = SmfRequestError;
   711 						aRetType = SmfRequestError;
   687 						return SmfPluginErrParsingFailed;
   712 						return SmfPluginErrParsingFailed;
   688 						}
   713 						}
   689 					else
   714 					else
   690 						{
   715 						{
   811 					}
   836 					}
   812 #else
   837 #else
   813 				qDebug()<<"Json parsing";
   838 				qDebug()<<"Json parsing";
   814 				
   839 				
   815 				bool ok;
   840 				bool ok;
   816 				QVariantMap result = m_util->parse(response, &ok).toMap();
   841 				SmfPluginUtil util;
       
   842 				QVariantMap result = util.parse(response, &ok).toMap();
   817 				if (!ok) 
   843 				if (!ok) 
   818 					{
   844 					{
   819 					qDebug()<<"An error occurred during json parsing";
   845 					qDebug()<<"An error occurred during json parsing";
   820 					aRetType = SmfRequestError;
   846 					aRetType = SmfRequestError;
   821 					return SmfPluginErrParsingFailed;
   847 					return SmfPluginErrParsingFailed;
   871 					while(iter2.hasNext())
   897 					while(iter2.hasNext())
   872 						{
   898 						{
   873 						QVariantMap map2 = iter2.next().toMap();
   899 						QVariantMap map2 = iter2.next().toMap();
   874 						qDebug()<<"owner's id = "<<map2["id"].toString();
   900 						qDebug()<<"owner's id = "<<map2["id"].toString();
   875 						qDebug()<<"owner's name = "<<map2["name"].toString();
   901 						qDebug()<<"owner's name = "<<map2["name"].toString();
       
   902 						qDebug()<<"owner's profile image url = "<<map2["pic_square"].toString();
   876 						idNameMap.insert(map2["id"].toString(), map2["name"].toString());
   903 						idNameMap.insert(map2["id"].toString(), map2["name"].toString());
       
   904 						idPicMap.insert(map2["id"].toString(), map2["pic_square"].toString());
   877 						}
   905 						}
   878 					
   906 					
   879 					// Loop for setting the "Name" of actor_id
   907 					// Loop for setting the "Name" of actor_id
   880 					for (int i=0 ; i <list.count() ; i++)
   908 					for (int i=0 ; i <list.count() ; i++)
   881 						{
   909 						{
   884 						QContactName contactName;
   912 						QContactName contactName;
   885 						contactName.setFirstName(idNameMap.value(contact.value("Guid").value<QContactGuid>().guid()));
   913 						contactName.setFirstName(idNameMap.value(contact.value("Guid").value<QContactGuid>().guid()));
   886 						qDebug()<<"Name = "<<contactName.firstName();
   914 						qDebug()<<"Name = "<<contactName.firstName();
   887 						QVariant nameVar = QVariant::fromValue(contactName);
   915 						QVariant nameVar = QVariant::fromValue(contactName);
   888 						contact.setValue("Name", nameVar);
   916 						contact.setValue("Name", nameVar);
       
   917 						
       
   918 						QContactAvatar avatar;
       
   919 						QUrl url(idPicMap.value(contact.value("Guid").value<QContactGuid>().guid()));
       
   920 						avatar.setImageUrl(url);
       
   921 						qDebug()<<"Profile Image Url = "<<url.toString();
       
   922 						QVariant urlVar = QVariant::fromValue<QContactAvatar>(avatar);
       
   923 						contact.setValue("Avatar", urlVar);
   889 						
   924 						
   890 						list[i].setOwner(contact);
   925 						list[i].setOwner(contact);
   891 						}
   926 						}
   892 					}
   927 					}
   893 #endif
   928 #endif
   934 							}
   969 							}
   935 						}
   970 						}
   936 					}
   971 					}
   937 #else
   972 #else
   938 				bool ok;
   973 				bool ok;
   939 				QVariantMap result = m_util->parse(response, &ok).toMap();
   974 				SmfPluginUtil util;
       
   975 				QVariantMap result = util.parse(response, &ok).toMap();
   940 				if (!ok) 
   976 				if (!ok) 
   941 					{
   977 					{
   942 					qDebug()<<"Response cannot be parsed";
   978 					qDebug()<<"Response cannot be parsed";
   943 					posted = true;
   979 					posted = true;
   944 					aRetType = SmfRequestComplete;
   980 					aRetType = SmfRequestComplete;
  1104  * from the initialize() method of the FBPostProviderPlugin class
  1140  * from the initialize() method of the FBPostProviderPlugin class
  1105  */
  1141  */
  1106 void FBProviderBase::initialize()
  1142 void FBProviderBase::initialize()
  1107 	{
  1143 	{
  1108 	m_serviceName = "Facebook";
  1144 	m_serviceName = "Facebook";
  1109 	m_description = "Facebook plugin description";
  1145 	m_description = "Facebook post plugin description";
  1110 	m_serviceUrl = QUrl(QString("http://api.facebook.com"));
  1146 	m_serviceUrl = QUrl(QString("http://api.facebook.com"));
  1111 	m_pluginId = "fbpostproviderplugin.qtplugin";
  1147 	m_pluginId = "fbpostproviderplugin.qtplugin";
  1112 	m_authAppId = "Facebook AuthAppId";
  1148 	m_authAppId = "0xEFE2FD23";
  1113 	m_smfRegToken = "Facebook RegToken";
       
  1114 	m_supportedInterfaces.append("org.symbian.smf.plugin.contact.posts/v0.2");
  1149 	m_supportedInterfaces.append("org.symbian.smf.plugin.contact.posts/v0.2");
       
  1150 	QSettings iSettings;
       
  1151 	m_smfRegToken = iSettings.value("FBCMRegToken").toString();
       
  1152 	m_validity = iSettings.value("FBExpiryTime").toDateTime();
  1115 	}
  1153 	}
  1116 
  1154 
  1117 
  1155 
  1118 /*
  1156 /*
  1119  * Export Macro
  1157  * Export Macro