|
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 picture listing asynchronously. |
|
50 * The picturesAvailable() signal is emitted with SmfPictureList once the pictures 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 pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query. |
|
54 * @param perPage Item per page, default is SMF_ITEMS_PER_PAGE |
|
55 */ |
|
56 void SmfGalleryPrivate::pictures(int pageNum,int perPage) |
|
57 { |
|
58 //We need to pass Opcode and SmfProvider serialized into bytearray |
|
59 |
|
60 m_baseProvider = m_gallery->getProvider(); |
|
61 //serialize start |
|
62 QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly); |
|
63 write<<*(m_baseProvider); |
|
64 //serialize end |
|
65 QString intfName(galleryInterface); |
|
66 |
|
67 //call private impl's send method |
|
68 m_SmfClientPrivate->sendRequest(m_serializedDataToServer,intfName,SmfPictureGetPictures); |
|
69 } |
|
70 |
|
71 /** |
|
72 * Returns a user title/caption for the picture |
|
73 */ |
|
74 QString SmfGalleryPrivate::description(SmfPicture& picture) |
|
75 { |
|
76 //We need to pass Opcode and SmfProvider+SmfPicture serialized into bytearray |
|
77 |
|
78 m_baseProvider = m_gallery->getProvider(); |
|
79 //serialize start |
|
80 QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly); |
|
81 write<<*(m_baseProvider); |
|
82 write<<picture; |
|
83 //serialize end |
|
84 QString intfName(galleryInterface); |
|
85 |
|
86 //call private impl's send method |
|
87 m_SmfClientPrivate->sendRequest(m_serializedDataToServer,intfName,SmfPictureDescription); |
|
88 //TODO:-to be implemented |
|
89 return QString(); |
|
90 } |
|
91 /** |
|
92 * 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 |
|
94 * @param image the image to be uploaded |
|
95 */ |
|
96 void SmfGalleryPrivate::upload(SmfPicture* image) |
|
97 { |
|
98 //We need to pass Opcode and SmfProvider+SmfPicture serialized into bytearray |
|
99 |
|
100 m_baseProvider = m_gallery->getProvider(); |
|
101 //serialize start |
|
102 QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly); |
|
103 write<<*(m_baseProvider); |
|
104 write<<*(image); |
|
105 //serialize end |
|
106 QString intfName(galleryInterface); |
|
107 |
|
108 //call private impl's send method |
|
109 m_SmfClientPrivate->sendRequest(m_serializedDataToServer,intfName,SmfPictureUpload); |
|
110 } |
|
111 |
|
112 /** |
|
113 * 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 |
|
115 * @param images the list image to be uploaded |
|
116 */ |
|
117 void SmfGalleryPrivate::upload(SmfPictureList* images) |
|
118 { |
|
119 //We need to pass Opcode and SmfProvider+SmfPictureList serialized into bytearray |
|
120 |
|
121 m_baseProvider = m_gallery->getProvider(); |
|
122 //serialize start |
|
123 QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly); |
|
124 write<<*(m_baseProvider); |
|
125 write<<*(images); |
|
126 //serialize end |
|
127 QString intfName(galleryInterface); |
|
128 |
|
129 //call private impl's send method |
|
130 m_SmfClientPrivate->sendRequest(m_serializedDataToServer,intfName,SmfPictureMultiUpload); |
|
131 } |
|
132 |
|
133 /** |
|
134 * Posts a comment for an image. uploadFinished() signal is emitted |
|
135 * with success of the post once comment is posted. |
|
136 * @param image Image to comment on |
|
137 * @param comment Comment to post |
|
138 */ |
|
139 void SmfGalleryPrivate::postComment(SmfPicture image, SmfComment comment) |
|
140 { |
|
141 //We need to pass Opcode and SmfProvider+SmfPicture+SmfComment serialized into bytearray |
|
142 |
|
143 m_baseProvider = m_gallery->getProvider(); |
|
144 //serialize start |
|
145 QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly); |
|
146 write<<*(m_baseProvider); |
|
147 write<<image; |
|
148 write<<comment; |
|
149 //serialize end |
|
150 QString intfName(galleryInterface); |
|
151 |
|
152 //call private impl's send method |
|
153 m_SmfClientPrivate->sendRequest(m_serializedDataToServer,intfName,SmfPicturePostComment); |
|
154 } |
|
155 //from smfobserver |
|
156 void SmfGalleryPrivate::resultsAvailable(QByteArray result,SmfRequestTypeID opcode,SmfError error) |
|
157 { |
|
158 writeLog("SmfPostProviderPrivate::resultsAvailable"); |
|
159 |
|
160 //note:- "result" is serialized and we need to de-serialize it as per opcode |
|
161 //TODO:- order of serialization Error value followed by data |
|
162 |
|
163 QDataStream reader(&result,QIODevice::ReadOnly); |
|
164 |
|
165 //Now de-serialize it based on opcode |
|
166 switch(opcode) |
|
167 { |
|
168 case SmfPictureGetPicturesComplete: |
|
169 { |
|
170 if(m_picList) |
|
171 { |
|
172 delete m_picList; |
|
173 m_picList = NULL; |
|
174 } |
|
175 |
|
176 m_picList = new SmfPictureList; |
|
177 reader>>*(m_picList); |
|
178 writeLog("m_picList.count="); |
|
179 writeLog(QString::number(m_picList->count())); |
|
180 // foreach(SmfPicture pic,*m_picList) |
|
181 // { |
|
182 |
|
183 // } |
|
184 //not incorporating paging now |
|
185 SmfResultPage page; |
|
186 |
|
187 emit m_gallery->picturesAvailable(m_picList,error,page); |
|
188 |
|
189 } |
|
190 break; |
|
191 case SmfPictureUploadComplete: |
|
192 case SmfPicturePostCommentComplete: |
|
193 { |
|
194 bool success; |
|
195 reader>>success; |
|
196 writeLog("success="); |
|
197 if(success) |
|
198 writeLog("true"); |
|
199 QList<bool> successList; |
|
200 successList.append(success); |
|
201 emit m_gallery->uploadFinished(successList); |
|
202 |
|
203 } |
|
204 break; |
|
205 case SmfPictureMultiUpload: |
|
206 { |
|
207 QList<bool> successList; |
|
208 reader>>successList; |
|
209 emit m_gallery->uploadFinished(successList); |
|
210 |
|
211 } |
|
212 break; |
|
213 // default: |
|
214 // //should panic? |
|
215 // |
|
216 } |
|
217 } |
|
218 |