smf/smfservermodule/smfclient/client/smfcontactfetcher_p.cpp
changeset 18 013a02bf2bb0
parent 17 106a4bfcb866
child 19 c412f0526c34
--- a/smf/smfservermodule/smfclient/client/smfcontactfetcher_p.cpp	Thu Aug 05 16:46:37 2010 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,388 +0,0 @@
-/**
- * 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:
- * Manasij Roy, Nalina Hariharan
- */
-#include "smfcontactfetcher_p.h"
-#ifdef WRITE_LOG
-#include <QFile>
-#include <QTextstream>
-#endif
-#ifdef Q_OS_SYMBIAN
-#include "SmfClientSymbian.h"
-#else
-#include "SmfClientQt.h"
-#endif
- /**
-   * Constructs the SmfContactFetcher.
-   * @param parent base provider info
-   * @param contact Used for searching friends of the given contact
-   * Seeing as this is a plug-in implementation, these will realistically
-   * be generated by SMF factory of some kind
-   */
-  SmfContactFetcherPrivate::SmfContactFetcherPrivate(SmfContactFetcher* contactFetcher)
-  : m_contactFetcher(contactFetcher),m_contactList(0)
-	  {
-		//private impl for symbian
-		#ifdef Q_OS_SYMBIAN
-		m_SmfClientPrivate = CSmfClientSymbian::NewL(this);
-		#endif
-	  }
-  SmfContactFetcherPrivate::~SmfContactFetcherPrivate()
-	  {
-	  if(m_SmfClientPrivate)
-		  {
-		  delete m_SmfClientPrivate;
-		  m_SmfClientPrivate = NULL;
-		  }
-	  }
-
-  /**
-   * Get the friend listing asynchronously. The friendsListAvailable() signal
-   * is emitted with SmfContactList once data is arrived.
-   * When the list is big user can specify the page number and per page item data.
-   * If not supplied by the user default values are used.
-   * @param pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query.
-   * @param perPage Item per page, default is SMF_ITEMS_PER_PAGE
-   */
-  bool  SmfContactFetcherPrivate::friends(int pageNum,int perPage)
-	  {
-	  m_providerSerialized.clear();
-	  //We need to pass Opcode and SmfProvider serialized into bytearray 
-	  m_xtraInfoFlag = 0;
-	  m_pageInfoFlag = 1;
-	  m_baseProvider = m_contactFetcher->getProvider();
-	  //serialize start
-	  QDataStream write(&m_providerSerialized,QIODevice::WriteOnly);
-	  write<<*(m_baseProvider);
-	  write<<m_pageInfoFlag;
-	  write<<pageNum;
-	  write<<perPage;
-	  write<<m_xtraInfoFlag;
-	  //serialize end
-	  QString intfName(contactFetcherInterface);
-	  int maxAllocation = MaxSmfContactSize*perPage;
-	  //call private impl's send method
-	  m_SmfClientPrivate->sendRequest(m_providerSerialized,intfName,SmfContactGetFriends,maxAllocation,QByteArray());
-	  }
-
-  /**
-   * Get the list of followers asynchronously. The followersListAvailable() signal
-   * is emitted with SmfContactList once data is arrived. Please note that some
-   * service may not support followers/fans - FALSE is returned if not supported.
-   * When the list is big user can specify the page number and per page item data.
-   * If not supplied by the user default values are used.
-   * @param pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query.
-   * @param perPage Item per page, default is SMF_ITEMS_PER_PAGE
-   */
-  bool SmfContactFetcherPrivate::followers(int pageNum,int perPage)
-	  {
-	  //We need to pass Opcode and SmfProvider serialized into bytearray 
-	  
-	  m_baseProvider = m_contactFetcher->getProvider();
-	  //serialize start
-	  QDataStream write(&m_providerSerialized,QIODevice::WriteOnly);
-	  write<<*(m_baseProvider);
-	  m_pageInfoFlag = 1;
-	  write<<m_pageInfoFlag;
-	  write<<pageNum;
-	  write<<perPage;
-	  m_xtraInfoFlag = 0;
-	  write<<m_xtraInfoFlag;
-	  //serialize end
-	  
-	  
-	  QString intfName(contactFetcherInterface);
-	  int maxAllocation = MaxSmfContactSize*perPage;
-	  //call private impl's send method
-	  m_SmfClientPrivate->sendRequest(m_providerSerialized,intfName,SmfContactGetFollowers,maxAllocation);
-	  }
-  /**
-   * Searches for a contact The searchContactFinished() signal
-   * is emitted with SmfContactList once data is arrived.
-   * When the list is big user can specify the page number and per page item data.
-   * If not supplied by the user default values are used.
-   * @param pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query.
-   * @param perPage Item per page, default is SMF_ITEMS_PER_PAGE
-   */
-  void  SmfContactFetcherPrivate::search(SmfContact* contact,int pageNum,int perPage) 
-	  {
-	  //We need to pass Opcode and SmfProvider+SmfContact serialized into bytearray 
-	  
-	  m_baseProvider = m_contactFetcher->getProvider();
-	  m_xtraInfoSerialized.clear();
-	  m_contact = contact;
-	  //serialize start
-	  QDataStream write(&m_providerSerialized,QIODevice::WriteOnly);
-	  write<<*(m_baseProvider);
-	  m_pageInfoFlag = 1;
-	  write<<m_pageInfoFlag;
-	  write<<pageNum;
-	  write<<pageNum;
-
-	  
-	  //serialize xtra info
-	  QDataStream writeXtra(&m_xtraInfoSerialized,QIODevice::WriteOnly);
-	  writeXtra<<*(m_contact);
-	  
-	  m_xtraInfoFlag = m_xtraInfoSerialized.size();
-	  write<<m_xtraInfoFlag;
-	  
-	  QString intfName(contactFetcherInterface);
-	  int maxAllocation = MaxSmfContactSize*perPage;
-	  //call private impl's send method
-	  m_SmfClientPrivate->sendRequest(m_providerSerialized,intfName,SmfContactSearch,maxAllocation,m_xtraInfoSerialized);
-	  }
-
-  /**
-   * Searches for a contacts (friends) who are near the user.
-   * Signal searchNearFinished() is emitted with SmfContactList once data is arrived.
-   * Proximity defines accuracy level
-   * When the list is big user can specify the page number and per page item data.
-   * If not supplied by the user default values are used.
-   * @param pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query.
-   * @param perPage Item per page, default is SMF_ITEMS_PER_PAGE
-   */
-   bool  SmfContactFetcherPrivate::searchNear(SmfLocation* location,SmfLocationSearchBoundary proximity,int pageNum,int perPage) 
-	   {
-		  m_baseProvider = m_contactFetcher->getProvider();
-		  m_xtraInfoSerialized.clear();
-		  //serialize start
-		  QDataStream write(&m_providerSerialized,QIODevice::WriteOnly);
-		  write<<*(m_baseProvider);
-		  m_pageInfoFlag = 1;
-		  write<<m_pageInfoFlag;
-		  write<<pageNum;
-		  write<<pageNum;
-		  //m_xtraInfoFlag = 1;
-		  //write<<m_xtraInfoFlag;
-		  
-		  //serialize xtra info
-		  QDataStream writeXtra(&m_xtraInfoSerialized,QIODevice::WriteOnly);
-		  writeXtra<<*(location);
-		  writeXtra<<proximity;
-		  m_xtraInfoFlag = m_xtraInfoSerialized.size();
-		  write<<m_xtraInfoFlag;
-		  QString intfName(contactFetcherInterface);
-		  int maxAllocation = MaxSmfContactSize*perPage;
-		  //call private impl's send method
-		  m_SmfClientPrivate->sendRequest(m_providerSerialized,intfName,SmfContactSearchNear,maxAllocation,m_xtraInfoSerialized);
-	   }
-
-
-  /**
-   * Get the list of groups. The groupListAvailable() signal
-   * is emitted with SmfGroupList once data is arrived. False might be returned
-   * if this service doesn't support any mode of grouping (very rare).
-   * When the list is big user can specify the page number and per page item data.
-   * If not supplied by the user default values are used.
-   * @param pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query.
-   * @param perPage Item per page, default is SMF_ITEMS_PER_PAGE
-   */
-   bool SmfContactFetcherPrivate::groups(int pageNum,int perPage) 
-	   {
-		  //We need to pass Opcode and SmfProvider serialized into bytearray 
-		  
-		  m_baseProvider = m_contactFetcher->getProvider();
-		  //serialize start
-		  QDataStream write(&m_providerSerialized,QIODevice::WriteOnly);
-		  write<<*(m_baseProvider);
-		  m_pageInfoFlag = 1;
-		  write<<m_pageInfoFlag;
-		  write<<pageNum;
-		  write<<perPage;
-		  m_xtraInfoFlag = 0;
-		  write<<m_xtraInfoFlag;
-		  //serialize end
-		  
-		  
-		  QString intfName(contactFetcherInterface);
-		  int maxAllocation = MaxSmfGroupSize*perPage;
-		  //call private impl's send method
-		  m_SmfClientPrivate->sendRequest(m_providerSerialized,intfName,SmfContactGetGroups,maxAllocation);
-	   }
-
-  /**
-   * Searches for Smf Contacts in an Smf group.
-   * When the list is big user can specify the page number and per page item data.
-   * If not supplied by the user default values are used.
-   * @param pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query.
-   * @param perPage Item per page, default is SMF_ITEMS_PER_PAGE
-   * @param  group The group to be searcged in
-   */
-bool  SmfContactFetcherPrivate::searchInGroup(SmfGroup group,int pageNum,int perPage) 
-   {
-	  //We need to pass Opcode and SmfProvider+SmfGroup serialized into bytearray 
-	  
-	  m_baseProvider = m_contactFetcher->getProvider();
-	  m_grp = group;
-	  //serialize start
-	  QDataStream write(&m_providerSerialized,QIODevice::WriteOnly);
-	  write<<*(m_baseProvider);
-	  m_pageInfoFlag = 1;
-	  write<<m_pageInfoFlag;
-	  write<<pageNum;
-	  write<<perPage;
-	  //m_xtraInfoFlag = 1;
-	  //write<<m_xtraInfoFlag;
-	  
-	  //serialize xtra info
-	  QDataStream writeXtra(&m_xtraInfoSerialized,QIODevice::WriteOnly);
-	  writeXtra<<m_grp;
-	  m_xtraInfoFlag = m_xtraInfoSerialized.size();
-	  write<<m_xtraInfoFlag;
-	  //serialize end
-	  
-	  
-	  QString intfName(contactFetcherInterface);
-	  int maxAllocation = MaxSmfContactSize*perPage;
-	  //call private impl's send method
-	  m_SmfClientPrivate->sendRequest(m_providerSerialized,intfName,SmfContactSearchInGroup,maxAllocation);
-	  return 0;
-   }
-void SmfContactFetcherPrivate::resultsAvailable(QByteArray result,SmfRequestTypeID opcode,SmfError error)
-   	{
-	writeLog("SmfContactFetcherPrivate::resultsAvailable");
-	
-   	QDataStream reader(&result,QIODevice::ReadOnly);
-   	
-   	//Now de-serialize it based on opcode
-   	switch(opcode)
-   		{
-   		case SmfContactGetFriends:
-   			{
-
-   			if(m_contactList)
-   				{
-				delete m_contactList;
-				m_contactList = NULL;
-   				}
-   			m_contactList = new SmfContactList;
-   			m_frndist.clear();
-   			reader>>m_frndist;
-   			writeLog("m_frndist.count=");
-   			writeLog(QString::number(m_frndist.count()));
-   			//TODO:-After consulting with PM owner decide page serialization
-   			SmfResultPage page;
-
-   			emit m_contactFetcher->friendsListAvailable(&m_frndist,error,page);
-   			
-   			}
-   			break;
-   		case SmfContactGetFollowers:
-   			{
-   			if(m_contactList)
-   				{
-				delete m_contactList;
-				m_contactList = NULL;
-   				}
-   			m_contactList = new SmfContactList;
-   			reader>>*(m_contactList);
-   			//TODO:-After consulting with PM owner decide page serialization
-   			SmfResultPage page;
-
-   			emit m_contactFetcher->followersListAvailable(m_contactList,error,page);
-			
-   			}
-   			break;
-   		case SmfContactGetGroups:
-   			{
-   			writeLog("Before m_grpList.clear=");
-   			m_grpList.clear();
-   			writeLog("Before reader>>m_grpList=");
-   			reader>>m_grpList ;
-   			/** @TODO:-After consulting with PM owner decide page serialization */
-   			SmfResultPage page;
-   			writeLog("m_grpList.count=");
-   			writeLog(QString::number(m_grpList.count()));
-   			emit m_contactFetcher->groupListAvailable(&m_grpList,error,page);
-   			
-   			}
-   			break;
-   		case SmfContactSearch:
-   			{
-   			if(m_contactList)
-   				{
-				delete m_contactList;
-				m_contactList = NULL;
-   				}
-   			m_contactList = new SmfContactList;
-   			reader>>*(m_contactList);
-   			/** @TODO:-After consulting with PM owner decide page serialization */
-   			SmfResultPage page;
-   			//searchContactFinished
-   			emit m_contactFetcher->searchContactFinished(m_contactList,error,page);
-   			}
-   			break;
-   		case SmfContactSearchNear:
-   			{
-   			if(m_contactList)
-   				{
-				delete m_contactList;
-				m_contactList = NULL;
-   				}
-   			m_contactList = new SmfContactList;
-   			reader>>*(m_contactList);
-   			/** @TODO:-After consulting with PM owner decide page serialization*/
-   			SmfResultPage page;
-   			//searchContactFinished
-   			emit m_contactFetcher->searchNearFinished(m_contactList,error,page);
-   			}
-   			break;
-   		case SmfContactSearchInGroup:
-   			{
-   			if(m_contactList)
-   				{
-				delete m_contactList;
-				m_contactList = NULL;
-   				}
-   			m_contactList = new SmfContactList;
-   			reader>>*(m_contactList);
-   			//TODO:-After consulting with PM owner decide page serialization
-   			SmfResultPage page;
-   			//searchContactFinished
-   			emit m_contactFetcher->searchInGroupFinished(m_contactList,error,page);
-   			}
-   			break;
-   		default:
-   			writeLog("!!!!!!!!!!default!!!!!!!!!!!!!!");
-   		}
-   	
-   	}
-void SmfContactFetcherPrivate::writeLog(QString log) const
-	{
-#ifdef WRITE_LOG
-	QFile file("c:\\data\\SmfClientLogs.txt");
-    if (!file.open(QIODevice::Append | QIODevice::Text))
-	         return;
-    QTextStream out(&file);
-    out << log << "\n";
-    file.close();
-#endif
-	}
-QDataStream &operator<<( QDataStream &aDataStream, 
-		const SmfError &err )
-	{
-	quint32 errInt = (quint32)err;
-	aDataStream<<errInt;
-	return aDataStream;
-	}
-
-
-QDataStream &operator>>( QDataStream &aDataStream, 
-		SmfError &err )
-	{
-	quint32 errInt;
-	aDataStream>>errInt;
-	err = (SmfError)errInt;
-	return aDataStream;
-	}