|
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 * The SmfEvent class represents an event |
|
17 * |
|
18 */ |
|
19 |
|
20 #include "smfpostprovider_p.h" |
|
21 //logging headers |
|
22 #ifdef WRITE_LOG |
|
23 #include <QTextStream> |
|
24 #include <QFile> |
|
25 #endif |
|
26 #ifdef Q_OS_SYMBIAN |
|
27 #include "smfclientsymbian.h" |
|
28 #else |
|
29 #include "SmfClientQt.h" |
|
30 #endif |
|
31 SmfPostProviderPrivate::SmfPostProviderPrivate(SmfPostProvider* postProvider) |
|
32 : m_postProvider(postProvider),m_postList(NULL) |
|
33 { |
|
34 //private impl for symbian |
|
35 #ifdef Q_OS_SYMBIAN |
|
36 m_SmfClientPrivate = CSmfClientSymbian::NewL(this); |
|
37 #endif |
|
38 } |
|
39 SmfPostProviderPrivate::~SmfPostProviderPrivate() |
|
40 { |
|
41 if(m_SmfClientPrivate) |
|
42 { |
|
43 delete m_SmfClientPrivate; |
|
44 m_SmfClientPrivate = NULL; |
|
45 } |
|
46 } |
|
47 /** |
|
48 * Gets the posts asynchronously. The signal postsAvailable()with SmfPostList is emitted |
|
49 * once the post lists are available |
|
50 * @param user user's contact in this SP, omit for self contact |
|
51 * @param pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query. |
|
52 * @param perPage Item per page, default is SMF_ITEMS_PER_PAGE |
|
53 * @see postsAvailable() |
|
54 */ |
|
55 void SmfPostProviderPrivate::posts(SmfContact* user ,int pageNum,int perPage) |
|
56 { |
|
57 //We need to pass Opcode and SmfProvider+SmfContact |
|
58 // (when user is not NULL) serialized into bytearray |
|
59 |
|
60 m_baseProvider = m_postProvider->getProvider(); |
|
61 //serialize start |
|
62 QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly); |
|
63 write<<*(m_baseProvider); |
|
64 //TODO:- use different opcode incase post retreival is for other user |
|
65 //serialize SmfContact if post retrieval is for other user |
|
66 if(user) |
|
67 { |
|
68 //now serialize SmfContact |
|
69 write<<*(user); |
|
70 } |
|
71 //serialize end |
|
72 QString intfName(postProviderInterface); |
|
73 |
|
74 //call private impl's send method |
|
75 m_SmfClientPrivate->sendRequest(m_serializedDataToServer,intfName,SmfContactRetrievePosts); |
|
76 |
|
77 } |
|
78 |
|
79 /** |
|
80 * Updates a post to own area, the success of the post can be checked with signal |
|
81 * updatePostFinished() signal |
|
82 * @param postData data to be posted |
|
83 * @param location location data |
|
84 */ |
|
85 void SmfPostProviderPrivate::post(SmfPost& postData,SmfLocation& location) |
|
86 { |
|
87 m_baseProvider = m_postProvider->getProvider(); |
|
88 //serialize start |
|
89 QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly); |
|
90 //SmfProvider |
|
91 write<<*(m_baseProvider); |
|
92 //SmfPost |
|
93 write<<postData; |
|
94 //SmfPlace |
|
95 write<<location; |
|
96 |
|
97 //serialize end |
|
98 QString intfName(postProviderInterface); |
|
99 |
|
100 //call private impl's send method |
|
101 m_SmfClientPrivate->sendRequest(m_serializedDataToServer,intfName,SmfContactPost); |
|
102 } |
|
103 /** |
|
104 * Updates the last post to own area with new data, the success of the post can be checked with signal |
|
105 * updatePostFinished() signal |
|
106 * @param postData edited/new data to be posted |
|
107 * @param location location data |
|
108 */ |
|
109 void SmfPostProviderPrivate::updatePost(SmfPost& postData) |
|
110 { |
|
111 m_baseProvider = m_postProvider->getProvider(); |
|
112 //serialize start |
|
113 QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly); |
|
114 //SmfProvider |
|
115 write<<*(m_baseProvider); |
|
116 //SmfPost |
|
117 write<<postData; |
|
118 |
|
119 //serialize end |
|
120 QString intfName(postProviderInterface); |
|
121 |
|
122 //call private impl's send method |
|
123 m_SmfClientPrivate->sendRequest(m_serializedDataToServer,intfName,SmfContactUpdatePost); |
|
124 } |
|
125 |
|
126 /** |
|
127 * Updates a post to a particular Smf contact. the success of the post can be checked with signal |
|
128 * updatePostFinished() signal. |
|
129 * @param postData data to be posted |
|
130 * @param contact contact to which the post is to be directed |
|
131 * @param location location data |
|
132 */ |
|
133 void SmfPostProviderPrivate::postDirected(SmfPost& postData,SmfContact& contact,SmfLocation* location) |
|
134 { |
|
135 m_baseProvider = m_postProvider->getProvider(); |
|
136 //serialize start |
|
137 QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly); |
|
138 //SmfProvider |
|
139 write<<*(m_baseProvider); |
|
140 //SmfPost |
|
141 write<<postData; |
|
142 //SmfContact |
|
143 write<<contact; |
|
144 //SmfPlace |
|
145 write<<location; |
|
146 //serialize end |
|
147 |
|
148 QString intfName(postProviderInterface); |
|
149 |
|
150 //call private impl's send method |
|
151 m_SmfClientPrivate->sendRequest(m_serializedDataToServer,intfName,SmfContactPostDirected); |
|
152 } |
|
153 |
|
154 /** |
|
155 * Posts appearance info of the user.e.g. appear offline, busy, do-not-disturb |
|
156 * @param appearence user appearance |
|
157 * @see SmfPresenceInfo |
|
158 * @return False on Failure/Not supported |
|
159 */ |
|
160 //TODO:-How to return "supported" value? should it be synchronous? |
|
161 //Currently doing it asynchronously with the assumption of always supported |
|
162 //TODO:- implement some signal completion API |
|
163 bool SmfPostProviderPrivate::postAppearence(SmfAppearenceInfo appearence) |
|
164 { |
|
165 m_baseProvider = m_postProvider->getProvider(); |
|
166 //serialize start |
|
167 QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly); |
|
168 write<<*(m_baseProvider); |
|
169 write<<appearence; |
|
170 QString intfName(postProviderInterface); |
|
171 |
|
172 //call private impl's send method |
|
173 m_SmfClientPrivate->sendRequest(m_serializedDataToServer,intfName,SmfContactPostAppearence); |
|
174 } |
|
175 /** |
|
176 * Share /a contact's post to user's friends and followers (e.g. retweet in twitter, share on facebook) |
|
177 * emits updatePostFinished() signal when done. |
|
178 * @param postData data to be posted |
|
179 * @param contact contact to which the post belonged |
|
180 * @param bool whether user changed items within the post |
|
181 */ |
|
182 void SmfPostProviderPrivate::sharePost(SmfPost& postData,SmfContact& contact,bool edited) |
|
183 { |
|
184 m_baseProvider = m_postProvider->getProvider(); |
|
185 //serialize start |
|
186 QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly); |
|
187 write<<*(m_baseProvider); |
|
188 write<<postData; |
|
189 write<<contact; |
|
190 write<<edited; |
|
191 QString intfName(postProviderInterface); |
|
192 |
|
193 //call private impl's send method |
|
194 m_SmfClientPrivate->sendRequest(m_serializedDataToServer,intfName,SmfContactSharePost); |
|
195 } |
|
196 /** |
|
197 * From smfobserver |
|
198 */ |
|
199 void SmfPostProviderPrivate::resultsAvailable(QByteArray result,SmfRequestTypeID opcode,SmfError error) |
|
200 { |
|
201 writeLog("SmfPostProviderPrivate::resultsAvailable"); |
|
202 |
|
203 //note:- "result" is serialized and we need to de-serialize it as per opcode |
|
204 //TODO:- order of serialization Error value followed by data |
|
205 |
|
206 QDataStream reader(&result,QIODevice::ReadOnly); |
|
207 |
|
208 //Now de-serialize it based on opcode |
|
209 switch(opcode) |
|
210 { |
|
211 case SmfContactRetrievePostsComplete: |
|
212 { |
|
213 if(m_postList) |
|
214 { |
|
215 delete m_postList; |
|
216 m_postList = NULL; |
|
217 } |
|
218 |
|
219 m_postList = new SmfPostList; |
|
220 //TODO |
|
221 // SmfError error; |
|
222 // reader>>error; |
|
223 // writeLog("Error="); |
|
224 // writeLog(QString::number(error)); |
|
225 // SmfError err = (SmfError)error; |
|
226 reader>>*(m_postList); |
|
227 writeLog("postList.count="); |
|
228 writeLog(QString::number(m_postList->count())); |
|
229 foreach(SmfPost post,*m_postList) |
|
230 { |
|
231 writeLog(post.description()); |
|
232 } |
|
233 //not incorporating paging now |
|
234 SmfResultPage page; |
|
235 |
|
236 emit m_postProvider->postsAvailable(m_postList,error,page); |
|
237 |
|
238 } |
|
239 break; |
|
240 case SmfContactPostComplete: |
|
241 { |
|
242 bool success; |
|
243 reader>>success; |
|
244 writeLog("success="); |
|
245 if(success) |
|
246 writeLog("true"); |
|
247 emit m_postProvider->postFinished(success); |
|
248 |
|
249 } |
|
250 break; |
|
251 case SmfContactUpdatePostComplete: |
|
252 case SmfContactPostDirectedComplete: |
|
253 case SmfContactSharePostComplete: |
|
254 { |
|
255 bool success; |
|
256 reader>>success; |
|
257 writeLog("success="); |
|
258 if(success) |
|
259 writeLog("true"); |
|
260 emit m_postProvider->postFinished(success); |
|
261 } |
|
262 // default: |
|
263 // //should panic? |
|
264 // |
|
265 } |
|
266 } |
|
267 void SmfPostProviderPrivate::writeLog(QString log) const |
|
268 { |
|
269 #ifdef WRITE_LOG |
|
270 QFile file("c:\\data\\SmfClientLogs.txt"); |
|
271 if (!file.open(QIODevice::Append | QIODevice::Text)) |
|
272 return; |
|
273 QTextStream out(&file); |
|
274 out << log << "\n"; |
|
275 file.close(); |
|
276 #endif |
|
277 } |