diff -r b78fa4cdbf2b -r 106a4bfcb866 example/fbactivityfetcherplugin/fbactivityfetcherplugin.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/fbactivityfetcherplugin/fbactivityfetcherplugin.cpp Thu Aug 05 16:46:37 2010 +0530 @@ -0,0 +1,1002 @@ +/** + * Copyright (c) 2010 Sasken Communication Technologies Ltd. + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of the "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html" + * + * Initial Contributors: + * Chandradeep Gandhi, Sasken Communication Technologies Ltd - Initial contribution + * + * Contributors: + * Nalina Hariharan + * + * Description: + * The Plugin that fetches activities from the logged in user's facebook account + * + */ + +// Include files +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "fbactivityfetcherplugin.h" + +// Global and static global variables +static int chance = 0; +QString currentUserId; +SmfActivityEntry myEntry; +SmfContact currentAuthor; +QList currentObjectList; +SmfActivityObject currentObject; +bool forEntryXmlTag; +bool forActivityObjectXmlTag; + +/** + * Destructor + */ +FBActivityFetcherPlugin::~FBActivityFetcherPlugin( ) + { + if(m_provider) + delete m_provider; + } + + +/** + * Method called by plugins to generate a signature string from a base string + * @param aBaseString The base string + * @return The md5 hash of the base string + */ +QString FBActivityFetcherPlugin::generateSignature(const QString aBaseString) + { + qDebug()<<"Inside FBActivityFetcherPlugin::generateSignature()"; + + // Create md5 hash of the signature string + QByteArray byteArray; + byteArray.insert(0, aBaseString.toAscii()); + + QByteArray md5Hash = QCryptographicHash::hash(byteArray,QCryptographicHash::Md5 ).toHex(); + QString returnString (md5Hash); + return returnString; + } + + +/** + * Method to interpret the key sets obtained from credential manager + * @param aApiKey [out] The api key + * @param aApiSecret [out] The api secret + * @param aSessionKey [out] The session key + * @param aSessionSecret [out] The session secret + * @param aAppId [out] The application ID + */ +void FBActivityFetcherPlugin::fetchKeys( QString &aApiKey, + QString &aApiSecret, + QString &aSessionKey, + QString &aSessionSecret, + QString &aAppId) + { + qDebug()<<"Inside FBActivityFetcherPlugin::fetchKeys()"; + + qDebug()<<"Reg Token = "<m_smfRegToken; + qDebug()<<"Expiry Date as int = "<m_validity.toTime_t(); + + SmfAuthParams keys; + SmfPluginUtil util; + util.getAuthKeys(keys, m_provider->m_smfRegToken, + m_provider->m_validity, m_provider->m_pluginId); + + qDebug()<<"Number of key-value pairs = "<().guid(); + qDebug()<<"Friends facebook ID = "< &aFilters, + const int aPageNum, + const int aItemsPerPage ) + { + qDebug()<<"Inside FBActivityFetcherPlugin::filtered()"; + + Q_UNUSED(aRequest) + Q_UNUSED(aFilters) + Q_UNUSED(aPageNum) + Q_UNUSED(aItemsPerPage) + return SmfPluginErrServiceNotSupported; + } + +/** + * Customised method for SmfActivityFetcherPlugin interface + * @param aRequest [out] The request data to be sent to network + * @param aOperation The operation type (should be known between + * the client interface and the plugin) + * @param aData The data required to form the request (The type + * of data should be known between client and the plugin) + * @return SmfPluginError Plugin error if any, else SmfPluginErrNone + */ +SmfPluginError FBActivityFetcherPlugin::customRequest( SmfPluginRequestData &aRequest, + const int &aOperation, QByteArray *aData ) + { + Q_UNUSED(aRequest) + Q_UNUSED(aOperation) + Q_UNUSED(aData) + qDebug()<<"Inside FBActivityFetcherPlugin::customRequest()"; + return SmfPluginErrServiceNotSupported; + } + + +/** + * The first method to be called in the plugin that implements this interface. + * If this method is not called, plugin may not behave as expected. + */ +void FBActivityFetcherPlugin::initialize( ) + { + // Set the global value + forActivityObjectXmlTag = false; + forEntryXmlTag = false; + + // Create an instance of FBActivityProviderBase + m_provider = new FBActivityProviderBase; + m_provider->initialize(); + } + + +/** + * Method to get the provider information + * @return Instance of SmfProviderBase + */ +SmfProviderBase* FBActivityFetcherPlugin::getProviderInfo( ) + { + return m_provider; + } + + +/** + * Method to get the result for a network request. + * @param aOperation The type of operation to be requested + * @param aTransportResult The result of transport operation + * @param aResponse The QByteArray instance containing the network response. + * The plugins should delete this instance once they have read the + * data from it. + * @param aResult [out] An output parameter to the plugin manager.If the + * return value is SmfSendRequestAgain, QVariant will be of type + * SmfPluginRequestData. + * For SmfActivityFetcherPlugin: If last operation was selfActivities() or + * friendsActivities() or filtered(), aResult will be of type + * QList. + * @param aRetType [out] SmfPluginRetType + * @param aPageResult [out] The SmfResultPage structure variable + */ +SmfPluginError FBActivityFetcherPlugin::responseAvailable( + const SmfRequestTypeID aOperation, + const SmfTransportResult &aTransportResult, + QByteArray *aResponse, + QVariant* aResult, + SmfPluginRetType &aRetType, + SmfResultPage &aPageResult ) + { + Q_UNUSED(aPageResult) + qDebug()<<"Inside FBActivityFetcherPlugin::responseAvailable()"; + + SmfPluginError error = SmfPluginErrNetworkError; + + if( !aResponse || (0 == aResponse->size()) ) + { + qDebug()<<"Response is NULL or empty"; + aRetType = SmfRequestError; + return error; + } + + QByteArray response(*aResponse); + delete aResponse; + + QFile respFile("c://data//SmfPluginActivityResponse.txt"); + if(!respFile.open(QIODevice::WriteOnly)) + qDebug()<<"File to write the response could not be opened"; + else + { + respFile.write(response); + respFile.close(); + qDebug()<<"Writing FB response to a file named 'SmfPluginActivityResponse.txt'"; + } + qDebug()<<"FB response size = "< list; + QString errStr; + errStr.clear(); + + qDebug()<<"Xml parsing"; + + // For getting contacts from xml response + QXmlStreamReader xml(response); + while (!xml.atEnd()) + { + xml.readNext(); + + if (xml.tokenType() == QXmlStreamReader::StartElement) + { + if (xml.qualifiedName().toString() == "entry") + { + currentObjectList.clear(); + forEntryXmlTag = true; + } + else if (xml.qualifiedName().toString() == "title") + { + if(forEntryXmlTag) + { + SmfPost post; + post.setTitle(xml.readElementText()); + myEntry.setTitle(post); + qDebug()<<"entry title = "<(name); + currentAuthor.setValue("Name", var); + } + } + else if(xml.qualifiedName().toString() == "uri") + { + if(forEntryXmlTag) + { + QContactUrl url; + url.setUrl(xml.readElementText()); + QVariant var = QVariant::fromValue(url); + currentAuthor.setValue("Url", var); + myEntry.setAuthor(currentAuthor); + qDebug()<<"entry author name = "<().firstName(); + //qDebug()<<"entry author uri = "<().url(); + } + } + else if(xml.qualifiedName().toString() == "activity:verb") + { + if(forEntryXmlTag) + { + QString str(xml.readElementText()); + str.remove(' '); + str.remove('\n'); + SmfActivityVerb verb = convertActivityverb(str); + myEntry.setActionName(verb); + //qDebug()<<"entry actionname = "<