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