smf/smfservermodule/smfclient/client/smfgallery_p.cpp
changeset 18 013a02bf2bb0
parent 17 106a4bfcb866
child 19 c412f0526c34
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 for SmfGallery class 
       
    17  *
       
    18  */
       
    19 #include "smfgallery_p.h"
       
    20 //logging headers
       
    21 #ifdef WRITE_LOG
       
    22 #include <QTextStream>
       
    23 #include <QFile>
       
    24 #endif
       
    25 #ifdef Q_OS_SYMBIAN
       
    26 #include "smfclientsymbian.h"
       
    27 #else
       
    28 #include "SmfClientQt.h"
       
    29 #endif
       
    30 
       
    31   SmfGalleryPrivate::SmfGalleryPrivate(SmfGallery* gallery)
       
    32   : m_gallery(gallery)
       
    33   	{
       
    34   	  //private impl for symbian
       
    35   	#ifdef Q_OS_SYMBIAN
       
    36   	m_SmfClientPrivate = CSmfClientSymbian::NewL(this);
       
    37   	#endif
       
    38   	}
       
    39   SmfGalleryPrivate::~SmfGalleryPrivate()
       
    40 	  {
       
    41 	  if(m_SmfClientPrivate)
       
    42 		  {
       
    43 		  delete m_SmfClientPrivate;
       
    44 		  m_SmfClientPrivate = NULL;
       
    45 		  }
       
    46 	  }
       
    47   
       
    48   /**
       
    49  * Get the album listing asynchronously.
       
    50  * The albumsAvailable() signal is emitted with SmfPictureAlbumList once the albums have arrived.
       
    51    * When the list is big user can specify the page number and per page item data.
       
    52    * If not supplied by the user default values are used.
       
    53  * @param names the subject or any keywords to be used to filter albums with that name
       
    54  * @param user the user whose albums are requested 
       
    55    * @param pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query.
       
    56    * @param perPage Item per page, default is SMF_ITEMS_PER_PAGE
       
    57    */
       
    58 void SmfGalleryPrivate::albums(QStringList names, SmfContact* user, int pageNum, int perPage)
       
    59 	  {
       
    60 	  //We need to pass Opcode and SmfProvider serialized into bytearray 
       
    61 	  m_baseProvider = m_gallery->getProvider();
       
    62 	  QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
       
    63 	  write<<*(m_baseProvider);
       
    64 	  m_pageInfoFlag = 1;
       
    65 	  write<<m_pageInfoFlag;
       
    66 	  write<<pageNum;
       
    67 	  write<<perPage;
       
    68 	  //TODO:- use different opcode incase post retreival is for other user
       
    69 	  //serialize SmfContact if post retrieval is for other user
       
    70 	  if(user)
       
    71 		  {
       
    72 		  //now serialize SmfContact 
       
    73 		  m_xtraInfoSerialized.clear();
       
    74 		  QDataStream Xtrawrite(&m_xtraInfoSerialized,QIODevice::WriteOnly);
       
    75 		  Xtrawrite<<*(user);
       
    76 		  m_xtraInfoFlag = m_xtraInfoSerialized.size();
       
    77 		  write<<m_xtraInfoFlag;
       
    78 		  }
       
    79 	  else
       
    80 		  {
       
    81 		  m_xtraInfoFlag = 0;
       
    82 		  write<<m_xtraInfoFlag;
       
    83 		  }	
       
    84 	  QString intfName(galleryInterface);
       
    85 	  int maxalloc = MaxSmfPictureAlbumSize*perPage;
       
    86 	  //call private impl's send method
       
    87 	  m_SmfClientPrivate->sendRequest(m_serializedDataToServer,intfName,SmfPictureGetAlbums,maxalloc,m_xtraInfoSerialized);
       
    88 	  }
       
    89 
       
    90   /**
       
    91  * Get the picture listing asynchronously.
       
    92  * The picturesAvailable() signal is emitted with SmfPictureList once the pictures have arrived.
       
    93  * When the list is big user can specify the page number and per page item data.
       
    94  * If not supplied by the user default values are used.
       
    95  * @param albums album(s) whose pictures are being requested
       
    96  * @param pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query.
       
    97  * @param perPage Item per page, default is SMF_ITEMS_PER_PAGE
       
    98    */
       
    99 void SmfGalleryPrivate::pictures(SmfPictureAlbumList albums,int pageNum,int perPage)
       
   100 	  {
       
   101 	  //We need to pass Opcode and SmfProvider serialized into bytearray 
       
   102 	  m_baseProvider = m_gallery->getProvider();
       
   103 	  QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
       
   104 	  write<<*(m_baseProvider);
       
   105 	  m_pageInfoFlag = 1;
       
   106 	  write<<m_pageInfoFlag;
       
   107 	  write<<pageNum;
       
   108 	  write<<perPage;
       
   109 	  m_xtraInfoSerialized.clear();
       
   110 	  QDataStream Xtrawrite(&m_xtraInfoSerialized,QIODevice::WriteOnly);
       
   111 	  Xtrawrite<<albums;
       
   112 	  m_xtraInfoFlag = m_xtraInfoSerialized.size();
       
   113 	  write<<m_xtraInfoFlag;
       
   114 
       
   115 	  QString intfName(galleryInterface);
       
   116 	  int maxalloc = MaxSmfPictureSize*perPage;
       
   117 	  //call private impl's send method
       
   118 	  m_SmfClientPrivate->sendRequest(m_serializedDataToServer,intfName,SmfPictureGetPictures,maxalloc,m_xtraInfoSerialized);
       
   119 	  }
       
   120 
       
   121   /**
       
   122 	 * Upload an image.Implemented as slot to connect to UI controls more easily
       
   123 	 * uploadFinished() signal is emitted with the success value of the upload
       
   124 	 * @param image the image to be uploaded
       
   125 	 */
       
   126 void SmfGalleryPrivate::upload(SmfPicture* image, SmfPictureAlbum* album)
       
   127 	   {
       
   128 	  //We need to pass Opcode and SmfProvider serialized into bytearray 
       
   129 	  m_baseProvider = m_gallery->getProvider();
       
   130 	  QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
       
   131 	  write<<*(m_baseProvider);
       
   132 	  m_pageInfoFlag = 0;
       
   133 	  write<<m_pageInfoFlag;
       
   134 
       
   135 	  m_xtraInfoSerialized.clear();
       
   136 	  QDataStream Xtrawrite(&m_xtraInfoSerialized,QIODevice::WriteOnly);
       
   137 	  Xtrawrite<<image;
       
   138 	  Xtrawrite<<album;
       
   139 	  m_xtraInfoFlag = m_xtraInfoSerialized.size();
       
   140 	  write<<m_xtraInfoFlag;
       
   141 
       
   142 	  QString intfName(galleryInterface);
       
   143 	  int maxalloc = 100;
       
   144 	  //call private impl's send method
       
   145 	  m_SmfClientPrivate->sendRequest(m_serializedDataToServer,intfName,SmfPictureUpload,maxalloc,m_xtraInfoSerialized);
       
   146 	  }
       
   147 
       
   148 	/**
       
   149 	 * Upload an list image.Implemented as slot to connect to UI controls more easily
       
   150 	 * uploadFinished() signal is emitted with the success value of the upload
       
   151 	 * @param images the list image to be uploaded
       
   152 	 */
       
   153 void SmfGalleryPrivate::upload(SmfPictureList* images, SmfPictureAlbum* album)
       
   154 	{
       
   155 
       
   156 	  //We need to pass Opcode and SmfProvider serialized into bytearray 
       
   157 	  m_baseProvider = m_gallery->getProvider();
       
   158 	  QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
       
   159 	  write<<*(m_baseProvider);
       
   160 	  m_pageInfoFlag = 0;
       
   161 	  write<<m_pageInfoFlag;
       
   162 
       
   163 	  m_xtraInfoSerialized.clear();
       
   164 	  QDataStream Xtrawrite(&m_xtraInfoSerialized,QIODevice::WriteOnly);
       
   165 	  Xtrawrite<<images;
       
   166 	  Xtrawrite<<album;
       
   167 	  m_xtraInfoFlag = m_xtraInfoSerialized.size();
       
   168 	  write<<m_xtraInfoFlag;
       
   169 
       
   170 	  QString intfName(galleryInterface);
       
   171 	  int maxalloc = 1000;
       
   172 	  //call private impl's send method
       
   173 	  m_SmfClientPrivate->sendRequest(m_serializedDataToServer,intfName,SmfPictureMultiUpload,maxalloc,m_xtraInfoSerialized);
       
   174 	  
       
   175 	}
       
   176 
       
   177   /**
       
   178    * Posts a comment for an image. uploadFinished() signal is emitted
       
   179    * with success of the post once comment is posted.
       
   180    * @param image Image to comment on
       
   181    * @param comment Comment to post
       
   182    */
       
   183    void SmfGalleryPrivate::postComment(SmfPicture image, SmfComment comment)
       
   184 	   {
       
   185 
       
   186 		  //We need to pass Opcode and SmfProvider serialized into bytearray 
       
   187 		  m_baseProvider = m_gallery->getProvider();
       
   188 		  QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
       
   189 		  write<<*(m_baseProvider);
       
   190 		  m_pageInfoFlag = 0;
       
   191 		  write<<m_pageInfoFlag;
       
   192 
       
   193 		  m_xtraInfoSerialized.clear();
       
   194 		  QDataStream Xtrawrite(&m_xtraInfoSerialized,QIODevice::WriteOnly);
       
   195 		  Xtrawrite<<image;
       
   196 		  Xtrawrite<<comment;
       
   197 		  m_xtraInfoFlag = m_xtraInfoSerialized.size();
       
   198 		  write<<m_xtraInfoFlag;
       
   199 
       
   200 		  QString intfName(galleryInterface);
       
   201 		  int maxalloc = 100;
       
   202 		  //call private impl's send method
       
   203 		  m_SmfClientPrivate->sendRequest(m_serializedDataToServer,intfName,SmfPicturePostComment,maxalloc,m_xtraInfoSerialized);
       
   204 		  
       
   205 		}
       
   206    //from smfobserver
       
   207    void SmfGalleryPrivate::resultsAvailable(QByteArray result,SmfRequestTypeID opcode,SmfError error)
       
   208 	   {
       
   209 	writeLog("SmfPostProviderPrivate::resultsAvailable");
       
   210 	
       
   211 	//note:- "result" is serialized and we need to de-serialize it as per opcode
       
   212 	//Order of serialization Error value followed by data
       
   213 	
       
   214 	QDataStream reader(&result,QIODevice::ReadOnly);
       
   215 	
       
   216 	//Now de-serialize it based on opcode
       
   217 	switch(opcode)
       
   218 		{
       
   219 		case SmfPictureGetPicturesComplete:
       
   220 				{
       
   221 					if(m_picList)
       
   222 						{
       
   223 						delete m_picList;
       
   224 						m_picList = NULL;
       
   225 						}
       
   226 		
       
   227 					m_picList = new SmfPictureList;
       
   228 					reader>>*(m_picList);
       
   229 					writeLog("m_picList.count=");
       
   230 					writeLog(QString::number(m_picList->count()));
       
   231 					//not incorporating paging now
       
   232 					SmfResultPage page;
       
   233 		
       
   234 					emit m_gallery->picturesAvailable(m_picList,error,page);
       
   235 				
       
   236 				}
       
   237 				break;
       
   238 			case SmfPictureUpload:
       
   239 			case SmfPicturePostComment:
       
   240 				{
       
   241 					
       
   242 					int errInt;
       
   243 					reader>>errInt;
       
   244 					writeLog("success=");
       
   245 					QList<SmfError> successList;
       
   246 					SmfError success = (SmfError)errInt; 
       
   247 					successList.append(success);
       
   248 					emit m_gallery->uploadFinished(successList);
       
   249 				
       
   250 				}
       
   251 				break;
       
   252 			case SmfPictureMultiUpload:
       
   253 				{
       
   254 				QList<int> successListInt;
       
   255 				QList<SmfError> successList;
       
   256 				reader>>successListInt;
       
   257 				foreach(int success,successListInt)
       
   258 					{
       
   259 					successList.append((SmfError)success);
       
   260 					}
       
   261 				emit m_gallery->uploadFinished(successList);
       
   262 			
       
   263 				}
       
   264 				break;
       
   265 				default:
       
   266 					User::Panic(_L("Gallerprivate="),opcode);
       
   267 					
       
   268 		}
       
   269 }
       
   270