18
|
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 Qt wrapper for SmfContactFetcher
|
|
17 |
*
|
|
18 |
*/
|
|
19 |
|
|
20 |
#include <qdebug.h>
|
|
21 |
|
|
22 |
#include "smfcontactfetcher.h"
|
|
23 |
#include "smfcontactfetcher_p.h"
|
|
24 |
#ifdef Q_OS_SYMBIAN
|
|
25 |
#include "smfclientsymbian.h"
|
|
26 |
#else
|
|
27 |
#include "smfclientqt.h"
|
|
28 |
#endif
|
|
29 |
|
|
30 |
/**
|
|
31 |
* Constructor
|
|
32 |
* @param contactFetcher The SmfContactFetcher instance
|
|
33 |
*/
|
|
34 |
SmfContactFetcherPrivate::SmfContactFetcherPrivate ( SmfContactFetcher* contactFetcher )
|
|
35 |
: m_contactFetcher(contactFetcher)
|
|
36 |
{
|
|
37 |
#ifdef Q_OS_SYMBIAN
|
|
38 |
//private impl for symbian
|
|
39 |
m_SmfClientPrivate = CSmfClientSymbian::NewL(this);
|
|
40 |
#endif
|
|
41 |
}
|
|
42 |
|
|
43 |
/**
|
|
44 |
* Destructor
|
|
45 |
*/
|
|
46 |
SmfContactFetcherPrivate::~SmfContactFetcherPrivate()
|
|
47 |
{
|
|
48 |
if(m_SmfClientPrivate)
|
|
49 |
{
|
|
50 |
delete m_SmfClientPrivate;
|
|
51 |
m_SmfClientPrivate = NULL;
|
|
52 |
}
|
|
53 |
}
|
|
54 |
|
|
55 |
/**
|
|
56 |
* Get the friend listing asynchronously. The friendsListAvailable() signal
|
|
57 |
* is emitted with SmfContactList once data is arrived. When the list is big,
|
|
58 |
* user can specify the page number and per page item data. If not supplied
|
|
59 |
* by the user default values are used.
|
|
60 |
* @param pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query.
|
|
61 |
* @param perPage Item per page, default is SMF_ITEMS_PER_PAGE
|
|
62 |
* @return true if success, else false
|
|
63 |
*/
|
|
64 |
bool SmfContactFetcherPrivate::friends(int pageNum,int perPage)
|
|
65 |
{
|
|
66 |
//We need to pass Opcode and SmfProvider serialized into bytearray
|
|
67 |
m_argFlag = 1;
|
|
68 |
SmfProvider* m_baseProvider = m_contactFetcher->getProvider();
|
|
69 |
|
|
70 |
//serialize start
|
|
71 |
m_dataSerialized.clear();
|
|
72 |
QDataStream write(&m_dataSerialized,QIODevice::WriteOnly);
|
|
73 |
write<<*(m_baseProvider);
|
|
74 |
write<<m_argFlag;
|
|
75 |
write<<pageNum;
|
|
76 |
write<<m_argFlag;
|
|
77 |
write<<perPage;
|
|
78 |
|
|
79 |
QString intfName(contactFetcherInterface);
|
|
80 |
int maxAllocation = MaxSmfContactSize*perPage;
|
|
81 |
|
|
82 |
//call private impl's send method
|
|
83 |
m_SmfClientPrivate->sendRequest(m_dataSerialized, intfName,
|
|
84 |
SmfContactGetFriends, maxAllocation);
|
|
85 |
|
|
86 |
return true;
|
|
87 |
}
|
|
88 |
|
|
89 |
/**
|
|
90 |
* Get the list of followers asynchronously. The followersListAvailable() signal
|
|
91 |
* is emitted with SmfContactList once data is arrived. Please note that some
|
|
92 |
* service may not support followers/fans - FALSE is returned if not supported.
|
|
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 pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query.
|
|
96 |
* @param perPage Item per page, default is SMF_ITEMS_PER_PAGE
|
|
97 |
* @return true if success, else false
|
|
98 |
*/
|
|
99 |
bool SmfContactFetcherPrivate::followers(int pageNum,int perPage)
|
|
100 |
{
|
|
101 |
//We need to pass Opcode and SmfProvider serialized into bytearray
|
|
102 |
SmfProvider* m_baseProvider = m_contactFetcher->getProvider();
|
|
103 |
|
|
104 |
//serialize start
|
|
105 |
m_dataSerialized.clear();
|
|
106 |
QDataStream write(&m_dataSerialized,QIODevice::WriteOnly);
|
|
107 |
write<<*m_baseProvider;
|
|
108 |
m_argFlag = 1;
|
|
109 |
write<<m_argFlag;
|
|
110 |
write<<pageNum;
|
|
111 |
write<<m_argFlag;
|
|
112 |
write<<perPage;
|
|
113 |
|
|
114 |
QString intfName(contactFetcherInterface);
|
|
115 |
int maxAllocation = MaxSmfContactSize*perPage;
|
|
116 |
|
|
117 |
//call private impl's send method
|
|
118 |
m_SmfClientPrivate->sendRequest(m_dataSerialized, intfName,
|
|
119 |
SmfContactGetFollowers, maxAllocation);
|
|
120 |
|
|
121 |
return true;
|
|
122 |
}
|
|
123 |
|
|
124 |
/**
|
|
125 |
* Searches for a contact The searchContactFinished() signal
|
|
126 |
* is emitted with SmfContactList once data is arrived.
|
|
127 |
* When the list is big user can specify the page number and per page item data.
|
|
128 |
* If not supplied by the user default values are used.
|
|
129 |
* @param contact The contact to be searched. The serach criteria must be
|
|
130 |
* set as one of its fields.
|
|
131 |
* @param pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query.
|
|
132 |
* @param perPage Item per page, default is SMF_ITEMS_PER_PAGE
|
|
133 |
*/
|
|
134 |
void SmfContactFetcherPrivate::search(SmfContact* contact,int pageNum,int perPage)
|
|
135 |
{
|
|
136 |
//We need to pass Opcode and SmfProvider+SmfContact serialized into bytearray
|
|
137 |
SmfProvider* m_baseProvider = m_contactFetcher->getProvider();
|
|
138 |
m_dataSerialized.clear();
|
|
139 |
//serialize start
|
|
140 |
QDataStream write(&m_dataSerialized,QIODevice::WriteOnly);
|
|
141 |
write<<*m_baseProvider;
|
|
142 |
if(contact)
|
|
143 |
{
|
|
144 |
m_argFlag = 1;
|
|
145 |
write<<m_argFlag;
|
|
146 |
write<<*contact;
|
|
147 |
}
|
|
148 |
else
|
|
149 |
{
|
|
150 |
m_argFlag = 0;
|
|
151 |
write<<m_argFlag;
|
|
152 |
}
|
|
153 |
m_argFlag = 1;
|
|
154 |
write<<m_argFlag;
|
|
155 |
write<<pageNum;
|
|
156 |
write<<m_argFlag;
|
|
157 |
write<<pageNum;
|
|
158 |
|
|
159 |
QString intfName(contactFetcherInterface);
|
|
160 |
int maxAllocation = MaxSmfContactSize*perPage;
|
|
161 |
|
|
162 |
//call private impl's send method
|
|
163 |
m_SmfClientPrivate->sendRequest(m_dataSerialized, intfName,
|
|
164 |
SmfContactSearch, maxAllocation);
|
|
165 |
}
|
|
166 |
|
|
167 |
/**
|
|
168 |
* Searches for a contacts (friends) who are near the user. The signal
|
|
169 |
* searchNearFinished() is emitted with SmfContactList once data is arrived.
|
|
170 |
* Proximity defines accuracy level. When the list is big user can specify
|
|
171 |
* the page number and per page item data. If not supplied by the user
|
|
172 |
* default values are used.
|
|
173 |
* @param location The location information
|
|
174 |
* @param proximity The search boundary criteria
|
|
175 |
* @param pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query.
|
|
176 |
* @param perPage Item per page, default is SMF_ITEMS_PER_PAGE
|
|
177 |
*/
|
|
178 |
bool SmfContactFetcherPrivate::searchNear(SmfLocation* location,
|
|
179 |
SmfLocationSearchBoundary proximity,
|
|
180 |
int pageNum,int perPage)
|
|
181 |
{
|
|
182 |
SmfProvider* m_baseProvider = m_contactFetcher->getProvider();
|
|
183 |
m_dataSerialized.clear();
|
|
184 |
|
|
185 |
//serialize start
|
|
186 |
QDataStream write(&m_dataSerialized,QIODevice::WriteOnly);
|
|
187 |
write<<*m_baseProvider;
|
|
188 |
if(location)
|
|
189 |
{
|
|
190 |
m_argFlag = 1;
|
|
191 |
write<<m_argFlag;
|
|
192 |
write<<*location;
|
|
193 |
}
|
|
194 |
else
|
|
195 |
{
|
|
196 |
m_argFlag = 0;
|
|
197 |
write<<m_argFlag;
|
|
198 |
}
|
|
199 |
write<<m_argFlag;
|
|
200 |
write<<proximity;
|
|
201 |
write<<m_argFlag;
|
|
202 |
write<<pageNum;
|
|
203 |
write<<m_argFlag;
|
|
204 |
write<<perPage;
|
|
205 |
|
|
206 |
QString intfName(contactFetcherInterface);
|
|
207 |
int maxAllocation = MaxSmfContactSize*perPage;
|
|
208 |
|
|
209 |
//call private impl's send method
|
|
210 |
m_SmfClientPrivate->sendRequest(m_dataSerialized, intfName,
|
|
211 |
SmfContactSearchNear, maxAllocation);
|
|
212 |
|
|
213 |
return true;
|
|
214 |
}
|
|
215 |
|
|
216 |
/**
|
|
217 |
* Get the list of groups. The groupListAvailable() signal is emitted with
|
|
218 |
* SmfGroupList once data is arrived. False might be returned if this service
|
|
219 |
* doesn't support any mode of grouping (very rare). When the list is big,
|
|
220 |
* user can specify the page number and per page item data. If not supplied
|
|
221 |
* by the user default values are used.
|
|
222 |
* @param pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query.
|
|
223 |
* @param perPage Item per page, default is SMF_ITEMS_PER_PAGE
|
|
224 |
*/
|
|
225 |
bool SmfContactFetcherPrivate::groups(int pageNum,int perPage)
|
|
226 |
{
|
|
227 |
//We need to pass Opcode and SmfProvider serialized into bytearray
|
|
228 |
SmfProvider* m_baseProvider = m_contactFetcher->getProvider();
|
|
229 |
m_dataSerialized.clear();
|
|
230 |
|
|
231 |
//serialize start
|
|
232 |
QDataStream write(&m_dataSerialized,QIODevice::WriteOnly);
|
|
233 |
write<<*m_baseProvider;
|
|
234 |
m_argFlag = 1;
|
|
235 |
write<<m_argFlag;
|
|
236 |
write<<pageNum;
|
|
237 |
write<<m_argFlag;
|
|
238 |
write<<perPage;
|
|
239 |
|
|
240 |
QString intfName(contactFetcherInterface);
|
|
241 |
int maxAllocation = MaxSmfGroupSize*perPage;
|
|
242 |
|
|
243 |
//call private impl's send method
|
|
244 |
m_SmfClientPrivate->sendRequest(m_dataSerialized, intfName,
|
|
245 |
SmfContactGetGroups, maxAllocation);
|
|
246 |
|
|
247 |
return true;
|
|
248 |
}
|
|
249 |
|
|
250 |
/**
|
|
251 |
* Searches for Smf Contacts in an Smf group. The signal searchInGroupFinished()
|
|
252 |
* is emitted with SmfContactList once data is arrived. When the list is big user
|
|
253 |
* can specify the page number and per page item data. If not supplied by the
|
|
254 |
* user default values are used.
|
|
255 |
* @param group The group to be searched in
|
|
256 |
* @param pageNum Page number to download, SMF_FIRST_PAGE denotes fresh query.
|
|
257 |
* @param perPage Item per page, default is SMF_ITEMS_PER_PAGE
|
|
258 |
* @return true if success, else false
|
|
259 |
*/
|
|
260 |
bool SmfContactFetcherPrivate::searchInGroup(SmfGroup group,int pageNum,int perPage)
|
|
261 |
{
|
|
262 |
//We need to pass Opcode and SmfProvider+SmfGroup serialized into bytearray
|
|
263 |
SmfProvider* m_baseProvider = m_contactFetcher->getProvider();
|
|
264 |
|
|
265 |
//serialize start
|
|
266 |
m_dataSerialized.clear();
|
|
267 |
QDataStream write(&m_dataSerialized,QIODevice::WriteOnly);
|
|
268 |
write<<*m_baseProvider;
|
|
269 |
m_argFlag = 1;
|
|
270 |
write<<m_argFlag;
|
|
271 |
write<<group;
|
|
272 |
write<<m_argFlag;
|
|
273 |
write<<pageNum;
|
|
274 |
write<<m_argFlag;
|
|
275 |
write<<perPage;
|
|
276 |
|
|
277 |
QString intfName(contactFetcherInterface);
|
|
278 |
int maxAllocation = MaxSmfContactSize*perPage;
|
|
279 |
|
|
280 |
//call private impl's send method
|
|
281 |
m_SmfClientPrivate->sendRequest(m_dataSerialized, intfName,
|
|
282 |
SmfContactSearchInGroup, maxAllocation);
|
|
283 |
|
|
284 |
return true;
|
|
285 |
}
|
|
286 |
|
|
287 |
/**
|
|
288 |
* Request for a custom operation. The signal customDataAvailable() is emitted
|
|
289 |
* when the result is available.
|
|
290 |
* @param operationId OperationId
|
|
291 |
* @param customData Custom data to be sent
|
|
292 |
* Note:-Interpretation of operationId and customData is upto the concerned
|
|
293 |
* plugin and client application. service provider should provide some
|
|
294 |
* serializing-deserializing utilities for these custom data
|
|
295 |
*/
|
|
296 |
void SmfContactFetcherPrivate::customRequest ( const int& operationId, QByteArray* customData )
|
|
297 |
{
|
|
298 |
//We need to pass Opcode and SmfProvider+SmfGroup serialized into bytearray
|
|
299 |
SmfProvider* m_baseProvider = m_contactFetcher->getProvider();
|
|
300 |
|
|
301 |
//serialize start
|
|
302 |
m_dataSerialized.clear();
|
|
303 |
QDataStream write(&m_dataSerialized,QIODevice::WriteOnly);
|
|
304 |
write<<*m_baseProvider;
|
|
305 |
m_argFlag = 1;
|
|
306 |
write<<m_argFlag;
|
|
307 |
write<<operationId;
|
|
308 |
if(customData)
|
|
309 |
{
|
|
310 |
write<<m_argFlag;
|
|
311 |
write<<*customData;
|
|
312 |
}
|
|
313 |
else
|
|
314 |
{
|
|
315 |
m_argFlag = 0;
|
|
316 |
write<<m_argFlag;
|
|
317 |
}
|
|
318 |
|
|
319 |
QString intfName(contactFetcherInterface);
|
|
320 |
//ToDo:- How much size to allocate for custom data? keeping MaxSmfContactSize for now
|
|
321 |
int maxAllocation = MaxSmfContactSize;
|
|
322 |
|
|
323 |
//call private impl's send method
|
|
324 |
m_SmfClientPrivate->sendRequest(m_dataSerialized, intfName,
|
|
325 |
SmfContactCustomRequest, maxAllocation);
|
|
326 |
}
|
|
327 |
|
|
328 |
/**
|
|
329 |
* To notify availibility of asynchronous requests.
|
|
330 |
* @param result Requested result, before using must check error param.
|
|
331 |
* @param opcode Requested opcode, for which the result has arrived.
|
|
332 |
* @param error Error
|
|
333 |
*/
|
|
334 |
void SmfContactFetcherPrivate::resultsAvailable(QByteArray result,
|
|
335 |
SmfRequestTypeID opcode,SmfError error)
|
|
336 |
{
|
|
337 |
qDebug()<<"SmfContactFetcherPrivate::resultsAvailable";
|
|
338 |
|
|
339 |
QDataStream reader(&result,QIODevice::ReadOnly);
|
|
340 |
|
|
341 |
//Now de-serialize it based on opcode
|
|
342 |
switch(opcode)
|
|
343 |
{
|
|
344 |
case SmfContactGetFriends:
|
|
345 |
{
|
|
346 |
SmfContactList* m_contactList = new SmfContactList;
|
|
347 |
reader>>*m_contactList;
|
|
348 |
qDebug()<<"m_contactList.count = "<<m_contactList->count();
|
|
349 |
|
|
350 |
//TODO:-After consulting with PM owner decide page serialization
|
|
351 |
SmfResultPage page;
|
|
352 |
|
|
353 |
emit m_contactFetcher->friendsListAvailable(m_contactList,error,page);
|
|
354 |
}
|
|
355 |
break;
|
|
356 |
|
|
357 |
case SmfContactGetFollowers:
|
|
358 |
{
|
|
359 |
SmfContactList* m_contactList = new SmfContactList;
|
|
360 |
reader>>*(m_contactList);
|
|
361 |
qDebug()<<"m_contactList.count = "<<m_contactList->count();
|
|
362 |
|
|
363 |
//TODO:-After consulting with PM owner decide page serialization
|
|
364 |
SmfResultPage page;
|
|
365 |
|
|
366 |
emit m_contactFetcher->followersListAvailable(m_contactList,error,page);
|
|
367 |
}
|
|
368 |
break;
|
|
369 |
|
|
370 |
case SmfContactSearch:
|
|
371 |
{
|
|
372 |
SmfContactList* m_contactList = new SmfContactList;
|
|
373 |
reader>>*(m_contactList);
|
|
374 |
qDebug()<<"m_contactList.count = "<<m_contactList->count();
|
|
375 |
|
|
376 |
/** @TODO:-After consulting with PM owner decide page serialization */
|
|
377 |
SmfResultPage page;
|
|
378 |
|
|
379 |
emit m_contactFetcher->searchContactFinished(m_contactList,error,page);
|
|
380 |
}
|
|
381 |
break;
|
|
382 |
|
|
383 |
case SmfContactSearchNear:
|
|
384 |
{
|
|
385 |
SmfContactList* m_contactList = new SmfContactList;
|
|
386 |
reader>>*(m_contactList);
|
|
387 |
qDebug()<<"m_contactList.count = "<<m_contactList->count();
|
|
388 |
|
|
389 |
/** @TODO:-After consulting with PM owner decide page serialization*/
|
|
390 |
SmfResultPage page;
|
|
391 |
|
|
392 |
emit m_contactFetcher->searchNearFinished(m_contactList,error,page);
|
|
393 |
}
|
|
394 |
break;
|
|
395 |
|
|
396 |
case SmfContactGetGroups:
|
|
397 |
{
|
|
398 |
qDebug()<<"Before reader>>m_grpList";
|
|
399 |
SmfGroupList *m_grpList = new SmfGroupList;
|
|
400 |
reader>>*(m_grpList);
|
|
401 |
|
|
402 |
/** @TODO:-After consulting with PM owner decide page serialization */
|
|
403 |
SmfResultPage page;
|
|
404 |
|
|
405 |
qDebug()<<"m_grpList.count = "<<m_grpList->count();
|
|
406 |
emit m_contactFetcher->groupListAvailable(m_grpList,error,page);
|
|
407 |
}
|
|
408 |
break;
|
|
409 |
|
|
410 |
case SmfContactSearchInGroup:
|
|
411 |
{
|
|
412 |
SmfContactList* m_contactList = new SmfContactList;
|
|
413 |
reader>>*(m_contactList);
|
|
414 |
|
|
415 |
//TODO:-After consulting with PM owner decide page serialization
|
|
416 |
SmfResultPage page;
|
|
417 |
|
|
418 |
qDebug()<<"m_contactList.count = "<<m_contactList->count();
|
|
419 |
|
|
420 |
emit m_contactFetcher->searchInGroupFinished(m_contactList,error,page);
|
|
421 |
}
|
|
422 |
break;
|
|
423 |
|
|
424 |
case SmfContactCustomRequest:
|
|
425 |
{
|
|
426 |
int operationId;
|
|
427 |
QByteArray *data = new QByteArray;
|
|
428 |
reader>>operationId;
|
|
429 |
reader>>*data;
|
|
430 |
|
|
431 |
qDebug()<<"operationId = "<<operationId;
|
|
432 |
qDebug()<<"data size = "<<data->size();
|
|
433 |
emit m_contactFetcher->customDataAvailable(operationId, data);
|
|
434 |
}
|
|
435 |
break;
|
|
436 |
|
|
437 |
default:
|
|
438 |
qDebug()<<"default - Contact Private Unknown opcode";
|
|
439 |
User::Panic(_L("Contact Private Unknown opcode = "),opcode);
|
|
440 |
}
|
|
441 |
}
|
|
442 |
|
|
443 |
QDataStream &operator<<( QDataStream &aDataStream, const SmfError &err )
|
|
444 |
{
|
|
445 |
quint32 errInt = (quint32)err;
|
|
446 |
aDataStream<<errInt;
|
|
447 |
return aDataStream;
|
|
448 |
}
|
|
449 |
|
|
450 |
|
|
451 |
QDataStream &operator>>( QDataStream &aDataStream, SmfError &err )
|
|
452 |
{
|
|
453 |
quint32 errInt;
|
|
454 |
aDataStream>>errInt;
|
|
455 |
err = (SmfError)errInt;
|
|
456 |
return aDataStream;
|
|
457 |
}
|