|
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 |
|
20 #include <qdebug.h> |
|
21 #include <smfprovider.h> |
|
22 #include <smfcontact.h> |
|
23 #include <smfcomment.h> |
|
24 |
|
25 #include "smfgallery.h" |
|
26 #include "smfgallery_p.h" |
|
27 #ifdef Q_OS_SYMBIAN |
|
28 #include "smfclientsymbian.h" |
|
29 #else |
|
30 #include "SmfClientQt.h" |
|
31 #endif |
|
32 |
|
33 SmfGalleryPrivate::SmfGalleryPrivate(SmfGallery* gallery) |
|
34 : m_gallery(gallery) |
|
35 { |
|
36 #ifdef Q_OS_SYMBIAN |
|
37 //private impl for symbian |
|
38 m_SmfClientPrivate = CSmfClientSymbian::NewL(this); |
|
39 #endif |
|
40 } |
|
41 |
|
42 SmfGalleryPrivate::~SmfGalleryPrivate() |
|
43 { |
|
44 if(m_SmfClientPrivate) |
|
45 { |
|
46 delete m_SmfClientPrivate; |
|
47 m_SmfClientPrivate = NULL; |
|
48 } |
|
49 } |
|
50 |
|
51 /** |
|
52 * Get the album listing asynchronously. The albumsAvailable() signal is |
|
53 * emitted with SmfPictureAlbumList once the albums have arrived. |
|
54 * When the list is big user can specify the page number and per page item data. |
|
55 * If not supplied by the user default values are used. |
|
56 * @param names the subject or any keywords to be used to filter albums with that name |
|
57 * @param user the user whose albums are requested |
|
58 * @param pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query. |
|
59 * @param perPage Item per page, default is SMF_ITEMS_PER_PAGE |
|
60 */ |
|
61 void SmfGalleryPrivate::albums(QStringList names, SmfContact* user, int pageNum, int perPage) |
|
62 { |
|
63 //We need to pass Opcode and SmfProvider serialized into bytearray |
|
64 SmfProvider* m_baseProvider = m_gallery->getProvider(); |
|
65 m_serializedDataToServer.clear(); |
|
66 QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly); |
|
67 write<<*m_baseProvider; |
|
68 m_argFlag = 1; |
|
69 write<<m_argFlag; |
|
70 write<<names; |
|
71 if(user) |
|
72 { |
|
73 write<<m_argFlag; |
|
74 write<<*user; |
|
75 } |
|
76 else |
|
77 { |
|
78 m_argFlag = 0; |
|
79 write<<m_argFlag; |
|
80 } |
|
81 m_argFlag = 1; |
|
82 write<<m_argFlag; |
|
83 write<<pageNum; |
|
84 write<<m_argFlag; |
|
85 write<<perPage; |
|
86 |
|
87 QString intfName(galleryInterface); |
|
88 int maxalloc = MaxSmfPictureAlbumSize*perPage; |
|
89 |
|
90 //call private impl's send method |
|
91 m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName, |
|
92 SmfPictureGetAlbums, maxalloc); |
|
93 } |
|
94 |
|
95 |
|
96 /** |
|
97 * Get the picture listing asynchronously. The picturesAvailable() signal is |
|
98 * emitted with SmfPictureList once the pictures have 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 albums album(s) whose pictures are being requested |
|
102 * @param pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query. |
|
103 * @param perPage Item per page, default is SMF_ITEMS_PER_PAGE |
|
104 */ |
|
105 void SmfGalleryPrivate::pictures(SmfPictureAlbumList &albums,int pageNum,int perPage) |
|
106 { |
|
107 //We need to pass Opcode and SmfProvider serialized into bytearray |
|
108 SmfProvider* m_baseProvider = m_gallery->getProvider(); |
|
109 m_serializedDataToServer.clear(); |
|
110 QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly); |
|
111 write<<*m_baseProvider; |
|
112 m_argFlag = 1; |
|
113 write<<m_argFlag; |
|
114 write<<albums; |
|
115 write<<m_argFlag; |
|
116 write<<pageNum; |
|
117 write<<m_argFlag; |
|
118 write<<perPage; |
|
119 |
|
120 QString intfName(galleryInterface); |
|
121 int maxalloc = MaxSmfPictureSize*perPage; |
|
122 |
|
123 //call private impl's send method |
|
124 m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName, |
|
125 SmfPictureGetPictures, maxalloc); |
|
126 } |
|
127 |
|
128 /** |
|
129 * Returns a user title/caption for the picture |
|
130 */ |
|
131 void SmfGalleryPrivate::description ( SmfPicture& picture ) |
|
132 { |
|
133 //We need to pass Opcode and SmfProvider serialized into bytearray |
|
134 SmfProvider* m_baseProvider = m_gallery->getProvider(); |
|
135 m_serializedDataToServer.clear(); |
|
136 QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly); |
|
137 write<<*m_baseProvider; |
|
138 m_argFlag = 1; |
|
139 write<<m_argFlag; |
|
140 write<<picture; |
|
141 |
|
142 QString intfName(galleryInterface); |
|
143 // ToDo :- Setting max limit of description string as 1000 |
|
144 int maxalloc = 1000; |
|
145 |
|
146 //call private impl's send method |
|
147 m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName, |
|
148 SmfPictureDescription, maxalloc); |
|
149 } |
|
150 |
|
151 /** |
|
152 * Upload an image.Implemented as slot to connect to UI controls more easily |
|
153 * uploadFinished() signal is emitted with the success value of the upload |
|
154 * @param image the image to be uploaded |
|
155 * @param album the optional destination album name |
|
156 */ |
|
157 void SmfGalleryPrivate::upload(SmfPicture* image, SmfPictureAlbum* album) |
|
158 { |
|
159 //We need to pass Opcode and SmfProvider serialized into bytearray |
|
160 SmfProvider* m_baseProvider = m_gallery->getProvider(); |
|
161 m_serializedDataToServer.clear(); |
|
162 QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly); |
|
163 write<<*m_baseProvider; |
|
164 if(image) |
|
165 { |
|
166 m_argFlag = 1; |
|
167 write<<m_argFlag; |
|
168 write<<*image; |
|
169 } |
|
170 else |
|
171 { |
|
172 m_argFlag = 0; |
|
173 write<<m_argFlag; |
|
174 } |
|
175 |
|
176 if(album) |
|
177 { |
|
178 m_argFlag = 1; |
|
179 write<<m_argFlag; |
|
180 write<<*album; |
|
181 } |
|
182 else |
|
183 { |
|
184 m_argFlag = 0; |
|
185 write<<m_argFlag; |
|
186 } |
|
187 |
|
188 QString intfName(galleryInterface); |
|
189 int maxalloc = 100; // ToDo:- limit set as 100 |
|
190 |
|
191 //call private impl's send method |
|
192 m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName, |
|
193 SmfPictureUpload, maxalloc); |
|
194 } |
|
195 |
|
196 /** |
|
197 * Upload an list image.Implemented as slot to connect to UI controls more easily |
|
198 * uploadFinished() signal is emitted with the success value of the upload |
|
199 * @param images the list image to be uploaded |
|
200 * @param album the optional destination album name |
|
201 */ |
|
202 void SmfGalleryPrivate::upload(SmfPictureList* images, SmfPictureAlbum* album) |
|
203 { |
|
204 //We need to pass Opcode and SmfProvider serialized into bytearray |
|
205 m_serializedDataToServer.clear(); |
|
206 SmfProvider* m_baseProvider = m_gallery->getProvider(); |
|
207 QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly); |
|
208 write<<*m_baseProvider; |
|
209 if(images) |
|
210 { |
|
211 m_argFlag = 1; |
|
212 write<<m_argFlag; |
|
213 write<<*images; |
|
214 } |
|
215 else |
|
216 { |
|
217 m_argFlag = 0; |
|
218 write<<m_argFlag; |
|
219 } |
|
220 |
|
221 if(album) |
|
222 { |
|
223 m_argFlag = 1; |
|
224 write<<m_argFlag; |
|
225 write<<*album; |
|
226 } |
|
227 else |
|
228 { |
|
229 m_argFlag = 0; |
|
230 write<<m_argFlag; |
|
231 } |
|
232 |
|
233 QString intfName(galleryInterface); |
|
234 int maxalloc = 1000; // ToDo:- limit set as 1000 |
|
235 |
|
236 //call private impl's send method |
|
237 m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName, |
|
238 SmfPictureMultiUpload, maxalloc); |
|
239 } |
|
240 |
|
241 /** |
|
242 * Posts a comment for an image. uploadFinished() signal is emitted |
|
243 * with success of the post once comment is posted. |
|
244 * @param image Image to comment on |
|
245 * @param comment Comment to post |
|
246 */ |
|
247 void SmfGalleryPrivate::postComment(SmfPicture image, SmfComment comment) |
|
248 { |
|
249 //We need to pass Opcode and SmfProvider serialized into bytearray |
|
250 SmfProvider* m_baseProvider = m_gallery->getProvider(); |
|
251 m_serializedDataToServer.clear(); |
|
252 QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly); |
|
253 write<<*m_baseProvider; |
|
254 m_argFlag = 1; |
|
255 write<<m_argFlag; |
|
256 write<<image; |
|
257 write<<m_argFlag; |
|
258 write<<comment; |
|
259 |
|
260 QString intfName(galleryInterface); |
|
261 int maxalloc = 100; // ToDo:- limit set as 100 |
|
262 //call private impl's send method |
|
263 m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName, |
|
264 SmfPicturePostComment, maxalloc); |
|
265 } |
|
266 |
|
267 /** |
|
268 * Request for a custom operation. |
|
269 * @param operationId OperationId |
|
270 * @param customData Custom data to be sent |
|
271 * Note:-Interpretation of operationId and customData is upto the concerned |
|
272 * plugin and client application. service provider should provide some |
|
273 * serializing-deserializing utilities for these custom data |
|
274 */ |
|
275 void SmfGalleryPrivate::customRequest ( const int& operationId, QByteArray* customData ) |
|
276 { |
|
277 //We need to pass Opcode and SmfProvider serialized into bytearray |
|
278 SmfProvider* m_baseProvider = m_gallery->getProvider(); |
|
279 m_serializedDataToServer.clear(); |
|
280 QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly); |
|
281 write<<*m_baseProvider; |
|
282 m_argFlag = 1; |
|
283 write<<m_argFlag; |
|
284 write<<operationId; |
|
285 if(customData) |
|
286 { |
|
287 write<<m_argFlag; |
|
288 write<<*customData; |
|
289 } |
|
290 else |
|
291 { |
|
292 m_argFlag = 0; |
|
293 write<<m_argFlag; |
|
294 } |
|
295 |
|
296 QString intfName(galleryInterface); |
|
297 //ToDo:- How much size to allocate for custo data? keeping MaxSmfPictureSize for now |
|
298 int maxAlloc = MaxSmfPictureSize; |
|
299 |
|
300 //call private impl's send method |
|
301 m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName, |
|
302 SmfPictureCustomRequest, maxAlloc); |
|
303 } |
|
304 |
|
305 |
|
306 /** |
|
307 * To notify availibility of asynchronous requests. |
|
308 * @param result Requested result, before using must check error param. |
|
309 * @param opcode Requested opcode, for which the result has arrived. |
|
310 * @param error Error |
|
311 */ |
|
312 void SmfGalleryPrivate::resultsAvailable(QByteArray result,SmfRequestTypeID opcode,SmfError error) |
|
313 { |
|
314 qDebug()<<"SmfGalleryPrivate::resultsAvailable"; |
|
315 qDebug()<<"opcode = "<<opcode; |
|
316 |
|
317 //note:- "result" is serialized and we need to de-serialize it as per opcode |
|
318 //Order of serialization Error value followed by data |
|
319 |
|
320 QDataStream reader(&result,QIODevice::ReadOnly); |
|
321 |
|
322 //Now de-serialize it based on opcode |
|
323 switch(opcode) |
|
324 { |
|
325 case SmfPictureGetAlbums: |
|
326 { |
|
327 qDebug()<<"fOR ALBUMS LIST"; |
|
328 SmfPictureAlbumList* m_albums = new SmfPictureAlbumList; |
|
329 reader>>*(m_albums); |
|
330 qDebug()<<" Albums count = "<<m_albums->count(); |
|
331 |
|
332 SmfResultPage page; // ToDo :- |
|
333 |
|
334 emit m_gallery->albumsAvailable(m_albums,error,page); |
|
335 break; |
|
336 } |
|
337 |
|
338 case SmfPictureGetPictures: |
|
339 { |
|
340 SmfPictureList* m_picList = new SmfPictureList; |
|
341 reader>>*(m_picList); |
|
342 qDebug()<<"m_picList.count = "<<m_picList->count(); |
|
343 |
|
344 //ToDo:- not incorporating paging now |
|
345 SmfResultPage page; |
|
346 |
|
347 emit m_gallery->picturesAvailable(m_picList,error,page); |
|
348 break; |
|
349 } |
|
350 |
|
351 case SmfPictureDescription: |
|
352 { |
|
353 QString str; |
|
354 reader>>str; |
|
355 qDebug()<<"Pic desc = "<<str; |
|
356 |
|
357 emit m_gallery->descriptionAvailable(str,error); |
|
358 break; |
|
359 } |
|
360 |
|
361 case SmfPictureUpload: |
|
362 case SmfPicturePostComment: |
|
363 { |
|
364 int errInt; |
|
365 reader>>errInt; |
|
366 qDebug()<<"success = "<<errInt; |
|
367 QList<SmfError> successList; |
|
368 SmfError success = (SmfError)errInt; |
|
369 successList.append(success); |
|
370 emit m_gallery->uploadFinished(successList); |
|
371 break; |
|
372 } |
|
373 |
|
374 case SmfPictureMultiUpload: |
|
375 { |
|
376 QList<int> successListInt; |
|
377 QList<SmfError> successList; |
|
378 reader>>successListInt; |
|
379 foreach(int success,successListInt) |
|
380 successList.append((SmfError)success); |
|
381 |
|
382 emit m_gallery->uploadFinished(successList); |
|
383 break; |
|
384 } |
|
385 |
|
386 case SmfPictureCustomRequest: |
|
387 { |
|
388 int operationId; |
|
389 QByteArray *data = new QByteArray; |
|
390 reader>>operationId; |
|
391 reader>>*data; |
|
392 qDebug()<<"operationId = "<<operationId; |
|
393 qDebug()<<"data size = "<<data->size(); |
|
394 emit m_gallery->customDataAvailable(operationId, data); |
|
395 break; |
|
396 } |
|
397 |
|
398 default: |
|
399 User::Panic(_L("Gallery Private = "),opcode); |
|
400 } |
|
401 } |
|
402 |