smf/smfservermodule/smfclient/smfpostprovider_p.cpp
changeset 18 013a02bf2bb0
child 25 a180113055cb
equal deleted inserted replaced
17:106a4bfcb866 18:013a02bf2bb0
       
     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  * Description:
       
    16  * Private implementation of SmfPostProvider
       
    17  *
       
    18  */
       
    19 
       
    20 #include <qdebug.h>
       
    21 
       
    22 #include "smfpostprovider.h"
       
    23 #include "smfpostprovider_p.h"
       
    24 #ifdef Q_OS_SYMBIAN
       
    25 	#include "smfclientsymbian.h"
       
    26 #else
       
    27 	#include "SmfClientQt.h"
       
    28 #endif
       
    29 
       
    30 
       
    31 SmfPostProviderPrivate::SmfPostProviderPrivate(SmfPostProvider* postProvider)
       
    32 		: m_postProvider(postProvider)
       
    33 	{
       
    34 #ifdef Q_OS_SYMBIAN
       
    35 	//private impl for symbian
       
    36 	m_SmfClientPrivate = CSmfClientSymbian::NewL(this);
       
    37 #endif
       
    38 	}
       
    39 
       
    40 
       
    41 SmfPostProviderPrivate::~SmfPostProviderPrivate()
       
    42 	{
       
    43 	if(m_SmfClientPrivate)
       
    44 		{
       
    45 		delete m_SmfClientPrivate;
       
    46 		m_SmfClientPrivate = NULL;
       
    47 		}
       
    48 	}
       
    49 
       
    50 
       
    51 /**
       
    52  * returns maximum no of chars (unicode) that service provider can post without truncation
       
    53  * negative value means no limit
       
    54  */
       
    55 qint32 SmfPostProviderPrivate::maxCharsInPost()
       
    56 	{ 
       
    57 	SmfProvider* m_baseProvider = m_postProvider->getProvider();
       
    58 	
       
    59 	//serialize start
       
    60 	m_serializedDataToServer.clear();
       
    61 	QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
       
    62 	
       
    63 	//SmfProvider
       
    64 	write<<*m_baseProvider;
       
    65 	
       
    66 	QString intfName(postProviderInterface);
       
    67 	//setting max size to 10
       
    68 	//call private impl's send method
       
    69 	QByteArray data = m_SmfClientPrivate->sendSyncRequest(intfName,	
       
    70 			SmfPostGetMaxCharsInPost, 10, m_serializedDataToServer);
       
    71 	
       
    72 	//De-serialize it into qint32
       
    73 	QDataStream reader(&data,QIODevice::ReadOnly);
       
    74 	qint32 val;
       
    75 	reader>>val;
       
    76 	return val;
       
    77 	}
       
    78 
       
    79 /**
       
    80  * returns maximum no of items that can be returned in a single query to getPosts
       
    81  * negative value means feature not supported.
       
    82  */
       
    83 qint32 SmfPostProviderPrivate::maxItems()
       
    84 	{ 
       
    85 	SmfProvider* m_baseProvider = m_postProvider->getProvider();
       
    86 	
       
    87 	//serialize start
       
    88 	m_serializedDataToServer.clear();
       
    89 	QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
       
    90 	
       
    91 	//SmfProvider
       
    92 	write<<*m_baseProvider;
       
    93 	
       
    94 	QString intfName(postProviderInterface);
       
    95 	//setting max size to 10
       
    96 	//call private impl's send method
       
    97 	QByteArray data = m_SmfClientPrivate->sendSyncRequest(intfName,
       
    98 			SmfPostGetMaxItems, 10, m_serializedDataToServer);
       
    99 	
       
   100 	//De-serialize it into qint32
       
   101 	QDataStream reader(&data,QIODevice::ReadOnly);
       
   102 	qint32 val;
       
   103 	reader>>val;
       
   104 	return val;
       
   105 	}
       
   106 
       
   107 /**
       
   108  * returns all the formatting of posts that this service provider supports.
       
   109  * May return 0 items to mean only QString is supported.
       
   110  */
       
   111 QVector<QTextFormat> SmfPostProviderPrivate::supportedFormats ()
       
   112 	{
       
   113 	SmfProvider* m_baseProvider = m_postProvider->getProvider();
       
   114 	
       
   115 	//serialize start
       
   116 	m_serializedDataToServer.clear();
       
   117 	QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
       
   118 	
       
   119 	//SmfProvider
       
   120 	write<<*m_baseProvider;
       
   121 	
       
   122 	QString intfName(postProviderInterface);
       
   123 	//ToDo :- Setting maxsize to 1000
       
   124 	
       
   125 	//call private impl's send method
       
   126 	QByteArray data = m_SmfClientPrivate->sendSyncRequest(intfName,
       
   127 			SmfPostGetSupportedFormats, 1000, m_serializedDataToServer);
       
   128 	
       
   129 	//De-serialize it into QVector<QTextFormat>
       
   130 	QDataStream reader(&data,QIODevice::ReadOnly);
       
   131 	QVector<QTextFormat> val;
       
   132 	reader>>val;
       
   133 	return val;
       
   134 	}
       
   135 
       
   136 /**
       
   137  * returns whether this SP supports Appearence @see SmfAppearenceInfo
       
   138  */
       
   139 bool SmfPostProviderPrivate::supportsAppearence ()
       
   140 	{ 
       
   141 	SmfProvider* m_baseProvider = m_postProvider->getProvider();
       
   142 	
       
   143 	//serialize start
       
   144 	m_serializedDataToServer.clear();
       
   145 	QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
       
   146 	
       
   147 	//SmfProvider
       
   148 	write<<*m_baseProvider;
       
   149 	
       
   150 	QString intfName(postProviderInterface);
       
   151 	//we are not mentioning the max size, as we'll receive only bool
       
   152 	//call private impl's send method
       
   153 	QByteArray data = m_SmfClientPrivate->sendSyncRequest(intfName,
       
   154 			SmfPostGetAppearanceSupport, 10, m_serializedDataToServer);
       
   155 	
       
   156 	//De-serialize it into bool
       
   157 	QDataStream reader(&data,QIODevice::ReadOnly);
       
   158 	bool val;
       
   159 	reader>>val;
       
   160 	return val;
       
   161 	}
       
   162 
       
   163 /**
       
   164  * Gets the posts asynchronously. The signal postsAvailable()with SmfPostList is emitted
       
   165  * once the post lists are available
       
   166  * @param user user's contact in this SP, omit for self contact
       
   167  * @param pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query.
       
   168  * @param perPage Item per page, default is SMF_ITEMS_PER_PAGE 
       
   169  * @see postsAvailable()
       
   170  */
       
   171 void SmfPostProviderPrivate::posts(SmfContact* user ,int pageNum,int perPage)
       
   172 	{
       
   173 	//We need to pass Opcode and SmfProvider+SmfContact (when user is not NULL) serialized into bytearray 
       
   174 	SmfProvider* m_baseProvider = m_postProvider->getProvider();
       
   175 	
       
   176 	//serialize start
       
   177 	m_serializedDataToServer.clear();
       
   178 	QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
       
   179 	write<<*m_baseProvider;
       
   180 	m_argFlag = 1;
       
   181 	if(user)
       
   182 		{
       
   183 		write<<m_argFlag;
       
   184 		write<<*user;
       
   185 		}
       
   186 	else
       
   187 		{
       
   188 		m_argFlag = 0;
       
   189 		write<<m_argFlag;
       
   190 		}
       
   191 	m_argFlag = 1;
       
   192 	write<<m_argFlag;
       
   193 	write<<pageNum;
       
   194 	write<<m_argFlag;
       
   195 	write<<perPage;
       
   196 	
       
   197 	QString intfName(postProviderInterface);
       
   198 	int maxAllocation = MaxSmfPostSize*perPage;
       
   199 	
       
   200 	//call private impl's send method
       
   201 	m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName,
       
   202 			SmfContactRetrievePosts, maxAllocation);
       
   203 	}
       
   204 	
       
   205 /**
       
   206  * Updates a post to own area, the success of the post can be checked with signal
       
   207  * updatePostFinished() signal
       
   208  * @param postData data to be posted
       
   209  * @param location location data
       
   210  */
       
   211 void SmfPostProviderPrivate::post(SmfPost& postData,SmfLocation& location) 
       
   212 	{
       
   213 	m_serializedDataToServer.clear();
       
   214 	SmfProvider* m_baseProvider = m_postProvider->getProvider();
       
   215 	
       
   216 	//serialize start
       
   217 	QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
       
   218 	
       
   219 	//SmfProvider
       
   220 	write<<*m_baseProvider;
       
   221 	m_argFlag = 1;
       
   222 	write<<m_argFlag;
       
   223 	write<<postData;
       
   224 	write<<m_argFlag;
       
   225 	write<<location;
       
   226 	
       
   227 	QString intfName(postProviderInterface);
       
   228 	
       
   229 	//we are not mentioning the max size, as we'll receive only bool
       
   230 	//call private impl's send method
       
   231 	m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName,
       
   232 			SmfContactPost, 10);
       
   233 	}
       
   234 
       
   235 /**
       
   236  * Updates the last post to own area with new data, the success of the post can be checked with signal
       
   237  * updatePostFinished() signal
       
   238  * @param postData edited/new data to be posted
       
   239  * @param location location data
       
   240  */
       
   241 void SmfPostProviderPrivate::updatePost(SmfPost& postData)
       
   242 	{
       
   243 	SmfProvider* m_baseProvider = m_postProvider->getProvider();
       
   244 	
       
   245 	//serialize start
       
   246 	m_serializedDataToServer.clear();
       
   247 	QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
       
   248 	//SmfProvider
       
   249 	write<<*m_baseProvider;
       
   250 	m_argFlag = 1;
       
   251 	write<<m_argFlag;
       
   252 	write<<postData;
       
   253 	
       
   254 	QString intfName(postProviderInterface);
       
   255 	//we are not mentioning the max size, as we'll receive only bool
       
   256 	//call private impl's send method
       
   257 	m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName,
       
   258 			SmfContactUpdatePost, 10);
       
   259 	}
       
   260 
       
   261 /**
       
   262  * Updates a post to a particular Smf contact. the success of the post can be checked with signal
       
   263  * updatePostFinished() signal.
       
   264  * @param postData data to be posted
       
   265  * @param contact contact to which the post is to be directed
       
   266  * @param location location data
       
   267  */
       
   268 void SmfPostProviderPrivate::postDirected(SmfPost& postData,SmfContact& contact,SmfLocation* location)
       
   269 	{
       
   270 	SmfProvider* m_baseProvider = m_postProvider->getProvider();
       
   271 	
       
   272 	//serialize start
       
   273 	m_serializedDataToServer.clear();
       
   274 	QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
       
   275 	
       
   276 	//SmfProvider
       
   277 	write<<*m_baseProvider;
       
   278 	m_argFlag = 1;
       
   279 	write<<m_argFlag;
       
   280 	write<<postData;
       
   281 	write<<m_argFlag;
       
   282 	write<<contact;
       
   283 	if(location)
       
   284 		{
       
   285 		write<<m_argFlag;
       
   286 		write<<*location;
       
   287 		}
       
   288 	else
       
   289 		{
       
   290 		m_argFlag = 0;
       
   291 		write<<m_argFlag;
       
   292 		}
       
   293 	
       
   294 	QString intfName(postProviderInterface);
       
   295 	//we are not mentioning the max size, as we'll receive only bool
       
   296 	//call private impl's send method
       
   297 	m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName,
       
   298 			SmfContactPostDirected, 10);
       
   299 	}
       
   300 
       
   301 /**
       
   302  * Method to post a comment on a post.
       
   303  * @param aTarget Post on which comment has to be posted
       
   304  * @param aComment comment to be posted
       
   305  * @param aLocation location data
       
   306  */
       
   307 void SmfPostProviderPrivate::commentOnAPost( SmfPost &aTarget, SmfPost &aComment, 
       
   308 		SmfLocation *aLocation)
       
   309 	{
       
   310 	SmfProvider* m_baseProvider = m_postProvider->getProvider();
       
   311 	
       
   312 	//serialize start
       
   313 	m_serializedDataToServer.clear();
       
   314 	QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
       
   315 	
       
   316 	//SmfProvider
       
   317 	write<<*m_baseProvider;
       
   318 	m_argFlag = 1;
       
   319 	write<<m_argFlag;
       
   320 	write<<aTarget;
       
   321 	write<<m_argFlag;
       
   322 	write<<aComment;
       
   323 	
       
   324 	if(aLocation)
       
   325 		{
       
   326 		write<<m_argFlag;
       
   327 		write<<*aLocation;
       
   328 		}
       
   329 	else
       
   330 		{
       
   331 		m_argFlag = 0;
       
   332 		write<<m_argFlag;
       
   333 		}
       
   334 	
       
   335 	QString intfName(postProviderInterface);
       
   336 	//we are not mentioning the max size, as we'll receive only bool
       
   337 	//call private impl's send method
       
   338 	m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName,
       
   339 			SmfContactCommentOnAPost, 10);
       
   340 	}
       
   341 
       
   342 /**
       
   343  * Posts appearance info of the user.e.g. appear offline, busy, do-not-disturb
       
   344  * @param appearence user appearance
       
   345  * @see SmfPresenceInfo
       
   346  * @return False on Failure/Not supported 
       
   347  */
       
   348 bool SmfPostProviderPrivate::postAppearence(SmfAppearenceInfo appearence,
       
   349 		const QString &status)
       
   350 	{
       
   351 	//TODO:-How to return "supported" value? should it be synchronous?
       
   352 	//Currently doing it asynchronously with the assumption of always supported
       
   353 	//TODO:- implement some signal completion API
       
   354 	m_serializedDataToServer.clear();
       
   355 	SmfProvider* m_baseProvider = m_postProvider->getProvider();
       
   356 	
       
   357 	//serialize start
       
   358 	QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
       
   359 	write<<*m_baseProvider;
       
   360 	m_argFlag = 1;
       
   361 	write<<m_argFlag;
       
   362 	write<<appearence;
       
   363 	write<<m_argFlag;
       
   364 	write<<status;
       
   365 		
       
   366 	QString intfName(postProviderInterface);
       
   367 	//we are not mentioning the max size, as we'll receive only bool
       
   368 	//call private impl's send method
       
   369 	m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName,
       
   370 			SmfContactPostAppearence, 10);
       
   371 	
       
   372 	return true;
       
   373 	}
       
   374 
       
   375 /**
       
   376  * Share a contact's post to user's friends and followers (e.g. retweet in twitter, share on facebook)
       
   377  * emits updatePostFinished() signal when done.
       
   378  * @param postData data to be posted
       
   379  * @param contact contact to which the post belonged
       
   380  * @param bool whether user changed items within the post
       
   381  */
       
   382 void SmfPostProviderPrivate::sharePost(SmfPost& postData,SmfContact& contact,bool edited)
       
   383 	{
       
   384 	SmfProvider* m_baseProvider = m_postProvider->getProvider();
       
   385 	
       
   386 	//serialize start
       
   387 	m_serializedDataToServer.clear();
       
   388 	QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
       
   389 	write<<*m_baseProvider;
       
   390 	m_argFlag = 1;
       
   391 	write<<m_argFlag;
       
   392 	write<<postData;
       
   393 	write<<m_argFlag;
       
   394 	write<<contact;
       
   395 	write<<m_argFlag;
       
   396 	write<<edited;
       
   397 	
       
   398 	QString intfName(postProviderInterface);
       
   399 	//we are not mentioning the max size, as we'll receive only bool
       
   400 	//call private impl's send method
       
   401 	m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName,
       
   402 			SmfContactSharePost, 10);
       
   403 	}
       
   404 
       
   405 /**
       
   406  * Request for a custom operation. The signal customDataAvailable() is emitted 
       
   407  * when the result is available.
       
   408  * @param operationId OperationId
       
   409  * @param customData Custom data to be sent
       
   410  * Note:-Interpretation of operationId and customData is upto the concerned
       
   411  * plugin and client application. service provider should provide some
       
   412  * serializing-deserializing utilities for these custom data
       
   413  */
       
   414 void SmfPostProviderPrivate::customRequest ( const int& operationId, QByteArray* customData )
       
   415 	{
       
   416 	SmfProvider* m_baseProvider = m_postProvider->getProvider();
       
   417 	
       
   418 	//serialize start
       
   419 	m_serializedDataToServer.clear();
       
   420 	QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
       
   421 	write<<*m_baseProvider;
       
   422 	m_argFlag = 1;
       
   423 	write<<m_argFlag;
       
   424 	write<<operationId;
       
   425 	if(customData)
       
   426 		{
       
   427 		write<<m_argFlag;
       
   428 		write<<*customData;
       
   429 		}
       
   430 	else
       
   431 		{
       
   432 		m_argFlag = 0;
       
   433 		write<<m_argFlag;
       
   434 		}
       
   435 	
       
   436 	QString intfName(postProviderInterface);
       
   437 	//ToDo:- How much size to allocate for custo data? keeping MaxSmfPostSize for now
       
   438 	int maxAllocation = MaxSmfPostSize;
       
   439 	
       
   440 	//call private impl's send method
       
   441 	m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName,
       
   442 			SmfContactPostCustomRequest, maxAllocation);
       
   443 	}
       
   444 
       
   445 /**
       
   446 * From smfobserver
       
   447 */
       
   448 void SmfPostProviderPrivate::resultsAvailable(QByteArray result,SmfRequestTypeID opcode,SmfError error)
       
   449    {
       
   450 	qDebug()<<"Inside SmfPostProviderPrivate::resultsAvailable()";
       
   451 	qDebug()<<"opcode = "<<opcode;
       
   452 
       
   453 	QDataStream reader(&result,QIODevice::ReadOnly);
       
   454 	
       
   455 	//Now de-serialize it based on opcode
       
   456 	switch(opcode)
       
   457 		{
       
   458 		case SmfContactRetrievePosts:
       
   459 			{
       
   460 			SmfPostList* m_postList = new SmfPostList;
       
   461 			reader>>*(m_postList);
       
   462 			
       
   463 			qDebug()<<"postList.count="<<m_postList->count();
       
   464 			
       
   465 			//not incorporating paging now
       
   466 			SmfResultPage page;
       
   467 
       
   468 			emit m_postProvider->postsAvailable(m_postList,error,page);
       
   469 			}
       
   470 			break;
       
   471 			
       
   472 		case SmfContactPost:	
       
   473 		case SmfContactUpdatePost:
       
   474 		case SmfContactPostDirected:
       
   475 		case SmfContactCommentOnAPost:
       
   476 		case SmfContactPostAppearence:
       
   477 		case SmfContactSharePost:
       
   478 			{
       
   479 			int errInt;
       
   480 			reader>>errInt;
       
   481 			qDebug()<<"success = "<<errInt;
       
   482 			SmfError success = (SmfError)errInt;
       
   483 			emit m_postProvider->postFinished(success);
       
   484 			}
       
   485 			break;
       
   486 			
       
   487 		case SmfContactPostCustomRequest:
       
   488    			{
       
   489    			int operationId;
       
   490    			QByteArray *data = new QByteArray;
       
   491    			reader>>operationId;
       
   492    			reader>>*data;
       
   493    			qDebug()<<"operationId = "<<operationId;
       
   494    			qDebug()<<"data size = "<<data->size();
       
   495    			emit m_postProvider->customDataAvailable(operationId, data);
       
   496    			}
       
   497    			break;
       
   498 			
       
   499 		default:
       
   500 			Q_ASSERT_X(1,"PostProvider Private Unknown opcode","default case");
       
   501 		}
       
   502    }