smf/smfservermodule/smfclient/client/smfcontactfetcher_p.cpp
changeset 10 1d94eb8df9c2
parent 9 b85b0c039c14
equal deleted inserted replaced
9:b85b0c039c14 10:1d94eb8df9c2
     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  * Manasij Roy, Nalina Hariharan
       
    14  */
       
    15 #include "smfcontactfetcher_p.h"
       
    16 #ifdef WRITE_LOG
       
    17 #include <QFile>
       
    18 #include <QTextstream>
       
    19 #endif
       
    20 #ifdef Q_OS_SYMBIAN
       
    21 #include "SmfClientSymbian.h"
       
    22 #else
       
    23 #include "SmfClientQt.h"
       
    24 #endif
       
    25  /**
       
    26    * Constructs the SmfContactFetcher.
       
    27    * @param parent base provider info
       
    28    * @param contact Used for searching friends of the given contact
       
    29    * Seeing as this is a plug-in implementation, these will realistically
       
    30    * be generated by SMF factory of some kind
       
    31    */
       
    32   SmfContactFetcherPrivate::SmfContactFetcherPrivate(SmfContactFetcher* contactFetcher)
       
    33   : m_contactFetcher(contactFetcher),m_contactList(0)
       
    34 	  {
       
    35 	  //private impl for symbian
       
    36 	#ifdef Q_OS_SYMBIAN
       
    37 	m_SmfClientPrivate = CSmfClientSymbian::NewL(this);
       
    38 	#endif
       
    39 	  }
       
    40   SmfContactFetcherPrivate::~SmfContactFetcherPrivate()
       
    41 	  {
       
    42 
       
    43 	  }
       
    44 
       
    45   /**
       
    46    * Get the friend listing asynchronously. The friendsListAvailable() signal
       
    47    * is emitted with SmfContactList once data is arrived.
       
    48    * When the list is big user can specify the page number and per page item data.
       
    49    * If not supplied by the user default values are used.
       
    50    * @param pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query.
       
    51    * @param perPage Item per page, default is SMF_ITEMS_PER_PAGE
       
    52    */
       
    53   bool  SmfContactFetcherPrivate::friends(int pageNum,int perPage)
       
    54 	  {
       
    55 	  m_providerSerialized.clear();
       
    56 	  //We need to pass Opcode and SmfProvider serialized into bytearray 
       
    57 	  
       
    58 	  m_baseProvider = m_contactFetcher->getProvider();
       
    59 	  //serialize start
       
    60 	  QDataStream write(&m_providerSerialized,QIODevice::WriteOnly);
       
    61 	  write<<*(m_baseProvider);
       
    62 	  //serialize end
       
    63 	  
       
    64 	  
       
    65 	  QString intfName(contactFetcherInterface);
       
    66 	  
       
    67 	  //call private impl's send method
       
    68 	  m_SmfClientPrivate->sendRequest(m_providerSerialized,intfName,SmfContactGetFriends);
       
    69 	  }
       
    70 
       
    71   /**
       
    72    * Get the list of followers asynchronously. The followersListAvailable() signal
       
    73    * is emitted with SmfContactList once data is arrived. Please note that some
       
    74    * service may not support followers/fans - FALSE is returned if not supported.
       
    75    * When the list is big user can specify the page number and per page item data.
       
    76    * If not supplied by the user default values are used.
       
    77    * @param pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query.
       
    78    * @param perPage Item per page, default is SMF_ITEMS_PER_PAGE
       
    79    */
       
    80   bool SmfContactFetcherPrivate::followers(int pageNum,int perPage)
       
    81 	  {
       
    82 	  //We need to pass Opcode and SmfProvider serialized into bytearray 
       
    83 	  
       
    84 	  m_baseProvider = m_contactFetcher->getProvider();
       
    85 	  //serialize start
       
    86 	  QDataStream write(&m_providerSerialized,QIODevice::WriteOnly);
       
    87 	  write<<*(m_baseProvider);
       
    88 	  //serialize end
       
    89 	  
       
    90 	  
       
    91 	  QString intfName(contactFetcherInterface);
       
    92 	  
       
    93 	  //call private impl's send method
       
    94 	  m_SmfClientPrivate->sendRequest(m_providerSerialized,intfName,SmfContactGetFollowers);
       
    95 	  }
       
    96   /**
       
    97    * Searches for a contact The searchContactFinished() signal
       
    98    * is emitted with SmfContactList once data is arrived.
       
    99    * When the list is big user can specify the page number and per page item data.
       
   100    * If not supplied by the user default values are used.
       
   101    * @param pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query.
       
   102    * @param perPage Item per page, default is SMF_ITEMS_PER_PAGE
       
   103    */
       
   104   void  SmfContactFetcherPrivate::search(SmfContact* contact,int pageNum,int perPage) 
       
   105 	  {
       
   106 	  //We need to pass Opcode and SmfProvider+SmfContact serialized into bytearray 
       
   107 	  
       
   108 	  m_baseProvider = m_contactFetcher->getProvider();
       
   109 	  m_contact = contact;
       
   110 	  //serialize start
       
   111 	  QDataStream write(&m_providerSerialized,QIODevice::WriteOnly);
       
   112 	  write<<*(m_baseProvider);
       
   113 	  //now serialize SmfContact 
       
   114 	  write<<*(m_contact);
       
   115 	  //serialize end
       
   116 	  
       
   117 	  
       
   118 	  QString intfName(contactFetcherInterface);
       
   119 	  
       
   120 	  //call private impl's send method
       
   121 	  m_SmfClientPrivate->sendRequest(m_providerSerialized,intfName,SmfContactSearch);
       
   122 	  }
       
   123 
       
   124   /**
       
   125    * Searches for a contacts (friends) who are near the user.
       
   126    * Signal searchNearFinished() is emitted with SmfContactList once data is arrived.
       
   127    * Proximity defines accuracy level
       
   128    * When the list is big user can specify the page number and per page item data.
       
   129    * If not supplied by the user default values are used.
       
   130    * @param pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query.
       
   131    * @param perPage Item per page, default is SMF_ITEMS_PER_PAGE
       
   132    */
       
   133   //TODO:-implement
       
   134 //   bool  SmfContactFetcherPrivate::searchNear(SmfPlace* location,SmfLocationSearchBoundary proximity,int pageNum,int perPage) 
       
   135 //	   {
       
   136 //	   
       
   137 //	   }
       
   138 
       
   139 
       
   140   /**
       
   141    * Get the list of groups. The groupListAvailable() signal
       
   142    * is emitted with SmfGroupList once data is arrived. False might be returned
       
   143    * if this service doesn't support any mode of grouping (very rare).
       
   144    * When the list is big user can specify the page number and per page item data.
       
   145    * If not supplied by the user default values are used.
       
   146    * @param pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query.
       
   147    * @param perPage Item per page, default is SMF_ITEMS_PER_PAGE
       
   148    */
       
   149    bool SmfContactFetcherPrivate::groups(int pageNum,int perPage) 
       
   150 	   {
       
   151 		  //We need to pass Opcode and SmfProvider serialized into bytearray 
       
   152 		  
       
   153 		  m_baseProvider = m_contactFetcher->getProvider();
       
   154 		  //serialize start
       
   155 		  QDataStream write(&m_providerSerialized,QIODevice::WriteOnly);
       
   156 		  write<<*(m_baseProvider);
       
   157 		  //serialize end
       
   158 		  
       
   159 		  
       
   160 		  QString intfName(contactFetcherInterface);
       
   161 		  
       
   162 		  //call private impl's send method
       
   163 		  m_SmfClientPrivate->sendRequest(m_providerSerialized,intfName,SmfContactGetGroups);
       
   164 	   }
       
   165 
       
   166   /**
       
   167    * Searches for Smf Contacts in an Smf group.
       
   168    * When the list is big user can specify the page number and per page item data.
       
   169    * If not supplied by the user default values are used.
       
   170    * @param pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query.
       
   171    * @param perPage Item per page, default is SMF_ITEMS_PER_PAGE
       
   172    * @param  group The group to be searcged in
       
   173    */
       
   174 bool  SmfContactFetcherPrivate::searchInGroup(SmfGroup group,int pageNum,int perPage) 
       
   175    {
       
   176 	  //We need to pass Opcode and SmfProvider+SmfGroup serialized into bytearray 
       
   177 	  
       
   178 	  m_baseProvider = m_contactFetcher->getProvider();
       
   179 	  m_grp = group;
       
   180 	  //serialize start
       
   181 	  QDataStream write(&m_providerSerialized,QIODevice::WriteOnly);
       
   182 	  write<<*(m_baseProvider);
       
   183 	  //now serialize SmfGroup 
       
   184 	  write<<m_grp;
       
   185 	  //serialize end
       
   186 	  
       
   187 	  
       
   188 	  QString intfName(contactFetcherInterface);
       
   189 	  
       
   190 	  //call private impl's send method
       
   191 	  m_SmfClientPrivate->sendRequest(m_providerSerialized,intfName,SmfContactSearch);
       
   192    }
       
   193 
       
   194 
       
   195 void SmfContactFetcherPrivate::resultsAvailable(QByteArray result,SmfRequestTypeID opcode,SmfError error)
       
   196    	{
       
   197 	writeLog("SmfContactFetcherPrivate::resultsAvailable");
       
   198 	
       
   199 	//note:- "result" is serialized and we need to de-serialize it as per opcode
       
   200 	//TODO:- order of serialization Error value followed by data
       
   201 	
       
   202    	QDataStream reader(&result,QIODevice::ReadOnly);
       
   203    	
       
   204    	//Now de-serialize it based on opcode
       
   205    	switch(opcode)
       
   206    		{
       
   207    		case SmfContactGetFriendsComplete:
       
   208    			{
       
   209 
       
   210    			if(m_contactList)
       
   211    				{
       
   212 				delete m_contactList;
       
   213 				m_contactList = NULL;
       
   214    				}
       
   215    			m_contactList = new SmfContactList;
       
   216    			//TODO
       
   217 //   			SmfError error;
       
   218 //   			reader>>error;
       
   219 //   			writeLog("Error=");
       
   220 //   			writeLog(QString::number(error));
       
   221 //   			SmfError err = (SmfError)error;
       
   222    			m_frndist.clear();
       
   223    			reader>>m_frndist;
       
   224    			writeLog("m_frndist.count=");
       
   225    			writeLog(QString::number(m_frndist.count()));
       
   226    			//not incorporating paging now
       
   227    			SmfResultPage page;
       
   228 
       
   229    			emit m_contactFetcher->friendsListAvailable(&m_frndist,SmfNoError,page);
       
   230    			
       
   231    			}
       
   232    			break;
       
   233    		case SmfContactGetFollowersComplete:
       
   234    			{
       
   235    			if(m_contactList)
       
   236    				{
       
   237 				delete m_contactList;
       
   238 				m_contactList = NULL;
       
   239    				}
       
   240    			m_contactList = new SmfContactList;
       
   241    			quint32 error;
       
   242    			reader>>error;
       
   243    			SmfError err = (SmfError)error;
       
   244    			reader>>*(m_contactList);
       
   245    			//not incorporating paging now
       
   246    			SmfResultPage page;
       
   247 
       
   248    			emit m_contactFetcher->followersListAvailable(m_contactList,err,page);
       
   249 			
       
   250    			}
       
   251    			break;
       
   252    		case SmfContactGetGroupsComplete:
       
   253    			{
       
   254    			writeLog("Before m_grpList.clear=");
       
   255    			m_grpList.clear();
       
   256    			writeLog("Before reader>>m_grpList=");
       
   257    			reader>>m_grpList ;
       
   258    			//not incorporating paging now
       
   259    			SmfResultPage page;
       
   260    			writeLog("m_grpList.count=");
       
   261    			writeLog(QString::number(m_grpList.count()));
       
   262    			emit m_contactFetcher->groupListAvailable(&m_grpList,SmfNoError,page);
       
   263    			
       
   264    			}
       
   265    			break;
       
   266    		case SmfContactSearchComplete:
       
   267    			{
       
   268    			if(m_contactList)
       
   269    				{
       
   270 				delete m_contactList;
       
   271 				m_contactList = NULL;
       
   272    				}
       
   273    			m_contactList = new SmfContactList;
       
   274    			quint32 error;
       
   275    			reader>>error;
       
   276    			SmfError err = (SmfError)error;
       
   277    			reader>>*(m_contactList);
       
   278    			//not incorporating paging now
       
   279    			SmfResultPage page;
       
   280    			//searchContactFinished
       
   281    			emit m_contactFetcher->searchContactFinished(m_contactList,err,page);
       
   282    			}
       
   283    			break;
       
   284    		default:
       
   285    			writeLog("Before m_grpList.clear=");
       
   286    			m_grpList.clear();
       
   287    			writeLog("Before reader>>m_grpList=");
       
   288    			reader>>m_grpList ;
       
   289    			//not incorporating paging now
       
   290    			SmfResultPage page;
       
   291    			writeLog("m_grpList.count=");
       
   292    			writeLog(QString::number(m_grpList.count()));
       
   293    			emit m_contactFetcher->groupListAvailable(&m_grpList,SmfNoError,page);
       
   294    		}
       
   295    	
       
   296    	}
       
   297 void SmfContactFetcherPrivate::writeLog(QString log) const
       
   298 	{
       
   299 	QFile file("c:\\data\\SmfClientLogs.txt");
       
   300     if (!file.open(QIODevice::Append | QIODevice::Text))
       
   301 	         return;
       
   302     QTextStream out(&file);
       
   303     out << log << "\n";
       
   304     file.close();
       
   305 
       
   306 	}
       
   307 QDataStream &operator<<( QDataStream &aDataStream, 
       
   308 		const SmfError &err )
       
   309 	{
       
   310 	quint32 errInt = (quint32)err;
       
   311 	aDataStream<<errInt;
       
   312 	return aDataStream;
       
   313 	}
       
   314 
       
   315 
       
   316 QDataStream &operator>>( QDataStream &aDataStream, 
       
   317 		SmfError &err )
       
   318 	{
       
   319 	quint32 errInt;
       
   320 	aDataStream>>errInt;
       
   321 	err = (SmfError)errInt;
       
   322 	return aDataStream;
       
   323 	}