85
|
1 |
/*
|
|
2 |
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "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 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <e32std.h>
|
|
19 |
#include <QList>
|
|
20 |
#include <QDebug>
|
86
|
21 |
#include <utf.h> // charconv.lib
|
85
|
22 |
#include <QMutexLocker>
|
|
23 |
|
|
24 |
#include "caclientproxy.h"
|
|
25 |
#include "cainnerentry.h"
|
|
26 |
#include "cainnerquery.h"
|
|
27 |
#include "caobjectadapter.h"
|
|
28 |
#include "caentriesarray.h"
|
|
29 |
#include "caidsarray.h"
|
|
30 |
#include "caarraycleanup.inl"
|
|
31 |
|
|
32 |
#include "caentry.h"
|
|
33 |
#include "caquery.h"
|
|
34 |
#include "cadefs.h"
|
88
|
35 |
#include "cahandlerproxy.h"
|
|
36 |
#include "caqtsfhandlerloader.h"
|
85
|
37 |
|
|
38 |
//----------------------------------------------------------------------------
|
|
39 |
//
|
|
40 |
//----------------------------------------------------------------------------
|
96
|
41 |
CaClientProxy::CaClientProxy()
|
85
|
42 |
{
|
|
43 |
}
|
|
44 |
|
|
45 |
//----------------------------------------------------------------------------
|
|
46 |
//
|
|
47 |
//----------------------------------------------------------------------------
|
|
48 |
CaClientProxy::~CaClientProxy()
|
|
49 |
{
|
|
50 |
mSession.Close();
|
88
|
51 |
|
85
|
52 |
}
|
|
53 |
|
|
54 |
//----------------------------------------------------------------------------
|
|
55 |
//
|
|
56 |
//----------------------------------------------------------------------------
|
|
57 |
ErrorCode CaClientProxy::connect()
|
|
58 |
{
|
|
59 |
int error = mSession.StartServer();
|
|
60 |
if (!error) {
|
|
61 |
error = mSession.Connect();
|
|
62 |
}
|
|
63 |
if (error) {
|
|
64 |
mSession.Close();
|
|
65 |
qWarning("CaClientProxy::connect: error (%d)", error);
|
|
66 |
}
|
|
67 |
return CaObjectAdapter::convertErrorCode(error);
|
|
68 |
}
|
|
69 |
|
|
70 |
//----------------------------------------------------------------------------
|
|
71 |
//
|
|
72 |
//----------------------------------------------------------------------------
|
|
73 |
ErrorCode CaClientProxy::addData(const CaEntry &entryToAdd,
|
87
|
74 |
CaEntry &targetEntry)
|
85
|
75 |
{
|
|
76 |
TRAPD(error, addDataL(entryToAdd, targetEntry));
|
|
77 |
|
|
78 |
USE_QDEBUG_IF(error) << "CaClientProxy::addData - Error ("
|
87
|
79 |
<< error << ")";
|
85
|
80 |
|
|
81 |
return CaObjectAdapter::convertErrorCode(error);
|
|
82 |
}
|
|
83 |
|
|
84 |
//----------------------------------------------------------------------------
|
|
85 |
//
|
|
86 |
//----------------------------------------------------------------------------
|
|
87 |
ErrorCode CaClientProxy::removeData(const QList<int> &entryIdList)
|
|
88 |
{
|
|
89 |
TRAPD(error, removeDataL(entryIdList));
|
|
90 |
|
|
91 |
USE_QDEBUG_IF(error) << "CaClientProxy::removeData - Error ("
|
87
|
92 |
<< error << ")";
|
85
|
93 |
|
|
94 |
return CaObjectAdapter::convertErrorCode(error);
|
|
95 |
}
|
|
96 |
|
|
97 |
//----------------------------------------------------------------------------
|
|
98 |
//
|
|
99 |
//----------------------------------------------------------------------------
|
|
100 |
ErrorCode CaClientProxy::insertEntriesIntoGroup(int groupId,
|
87
|
101 |
const QList<int> &entryIdList, int beforeEntryId)
|
85
|
102 |
{
|
|
103 |
TRAPD(error,
|
87
|
104 |
insertEntriesIntoGroupL(groupId, entryIdList, beforeEntryId));
|
85
|
105 |
|
|
106 |
USE_QDEBUG_IF(error)<< "CaClientProxy::insertEntriesIntoGroup - Error ("
|
87
|
107 |
<< error << ")";
|
85
|
108 |
|
|
109 |
return CaObjectAdapter::convertErrorCode(error);
|
|
110 |
}
|
|
111 |
|
|
112 |
//----------------------------------------------------------------------------
|
|
113 |
//
|
|
114 |
//----------------------------------------------------------------------------
|
|
115 |
ErrorCode CaClientProxy::removeEntriesFromGroup(int groupId,
|
87
|
116 |
const QList<int> &entryIdList)
|
85
|
117 |
{
|
|
118 |
TRAPD(error, removeEntriesFromGroupL(groupId, entryIdList));
|
|
119 |
|
|
120 |
USE_QDEBUG_IF(error)<< "CaClientProxy::removeEntriesFromGroup - Error ("
|
87
|
121 |
<< error << ")";
|
85
|
122 |
|
|
123 |
return CaObjectAdapter::convertErrorCode(error);
|
|
124 |
}
|
|
125 |
|
|
126 |
//----------------------------------------------------------------------------
|
|
127 |
//
|
|
128 |
//----------------------------------------------------------------------------
|
|
129 |
ErrorCode CaClientProxy::getData(const QList<int> &entryIdList,
|
92
|
130 |
QList< QSharedPointer<CaEntry> > &sourceList)
|
85
|
131 |
{
|
|
132 |
TRAPD(error, getDataL(entryIdList, sourceList));
|
|
133 |
|
|
134 |
USE_QDEBUG_IF(error) << "CaClientProxy::getData - Error ("
|
87
|
135 |
<< error << ")";
|
85
|
136 |
|
|
137 |
return CaObjectAdapter::convertErrorCode(error);
|
|
138 |
}
|
|
139 |
|
|
140 |
//----------------------------------------------------------------------------
|
|
141 |
//
|
|
142 |
//----------------------------------------------------------------------------
|
|
143 |
ErrorCode CaClientProxy::getData(const CaQuery &query,
|
92
|
144 |
QList< QSharedPointer<CaEntry> > &sourceList)
|
85
|
145 |
{
|
|
146 |
TRAPD(error, getDataL(query, sourceList));
|
|
147 |
|
|
148 |
USE_QDEBUG_IF(error) << "CaClientProxy::getData - Error ("
|
87
|
149 |
<< error << ")";
|
85
|
150 |
|
|
151 |
return CaObjectAdapter::convertErrorCode(error);
|
|
152 |
}
|
|
153 |
|
|
154 |
//----------------------------------------------------------------------------
|
|
155 |
//
|
|
156 |
//----------------------------------------------------------------------------
|
|
157 |
ErrorCode CaClientProxy::getEntryIds(const CaQuery &query,
|
87
|
158 |
QList<int> &sourceIdList)
|
85
|
159 |
{
|
|
160 |
TRAPD(error, getEntryIdsL(query, sourceIdList));
|
|
161 |
|
|
162 |
USE_QDEBUG_IF(error) << "CaClientProxy::getEntryIds - Error ("
|
87
|
163 |
<< error << ")";
|
85
|
164 |
|
|
165 |
return CaObjectAdapter::convertErrorCode(error);
|
|
166 |
}
|
|
167 |
|
|
168 |
//----------------------------------------------------------------------------
|
|
169 |
//
|
|
170 |
//----------------------------------------------------------------------------
|
87
|
171 |
ErrorCode CaClientProxy::touch(const CaEntry &aEntry)
|
85
|
172 |
{
|
|
173 |
TRAPD(error, touchL(aEntry));
|
|
174 |
|
|
175 |
USE_QDEBUG_IF(error) << "CaClientProxy::touch - Error ("
|
87
|
176 |
<< error << ")";
|
85
|
177 |
|
|
178 |
return CaObjectAdapter::convertErrorCode(error);
|
|
179 |
}
|
|
180 |
|
|
181 |
//----------------------------------------------------------------------------
|
|
182 |
//
|
|
183 |
//----------------------------------------------------------------------------
|
|
184 |
ErrorCode CaClientProxy::customSort(const QList<int> &entryIdList,
|
87
|
185 |
int groupId)
|
85
|
186 |
{
|
|
187 |
TRAPD(error, customSortL(entryIdList, groupId));
|
|
188 |
|
|
189 |
USE_QDEBUG_IF(error)<< "CaClientProxy::customSort - Error ("
|
87
|
190 |
<< error << ")";
|
85
|
191 |
|
|
192 |
return CaObjectAdapter::convertErrorCode(error);
|
|
193 |
}
|
|
194 |
|
|
195 |
//----------------------------------------------------------------------------
|
|
196 |
//
|
|
197 |
//----------------------------------------------------------------------------
|
|
198 |
void CaClientProxy::addDataL(const CaEntry &entryToAdd,
|
87
|
199 |
CaEntry &targetEntry)
|
85
|
200 |
{
|
|
201 |
CCaInnerEntry *newEntryToAdd = CCaInnerEntry::NewLC();
|
|
202 |
|
|
203 |
CaObjectAdapter::convertL(entryToAdd, *newEntryToAdd);
|
|
204 |
mSession.AddL(*newEntryToAdd);
|
|
205 |
CaObjectAdapter::convert(*newEntryToAdd, targetEntry);
|
|
206 |
|
|
207 |
CleanupStack::PopAndDestroy(newEntryToAdd);
|
|
208 |
}
|
|
209 |
|
|
210 |
//----------------------------------------------------------------------------
|
|
211 |
//
|
|
212 |
//----------------------------------------------------------------------------
|
|
213 |
void CaClientProxy::removeDataL(const QList<int> &entryIdList)
|
|
214 |
{
|
|
215 |
RCaIdsArray array;
|
|
216 |
CleanupClosePushL(array);
|
|
217 |
CaObjectAdapter::convertL(entryIdList, array);
|
|
218 |
mSession.RemoveL(array);
|
|
219 |
CleanupStack::PopAndDestroy(&array);
|
|
220 |
}
|
|
221 |
|
|
222 |
void CaClientProxy::insertEntriesIntoGroupL(int groupId,
|
87
|
223 |
const QList<int> &entryIdList, int beforeEntryId)
|
85
|
224 |
{
|
|
225 |
RCaIdsArray array;
|
|
226 |
CleanupClosePushL(array);
|
|
227 |
CaObjectAdapter::convertL(entryIdList, array);
|
|
228 |
TCaOperationParams::OperationType operationType;
|
|
229 |
switch (beforeEntryId) {
|
|
230 |
case AfterTheLastEntry:
|
|
231 |
operationType = TCaOperationParams::EAppend;
|
|
232 |
break;
|
|
233 |
case BeforeTheFirstEntry:
|
|
234 |
operationType = TCaOperationParams::EPrepend;
|
|
235 |
break;
|
|
236 |
default:
|
|
237 |
if (beforeEntryId < 1) {
|
|
238 |
qWarning("CaClientProxy::insertEntriesIntoGroupL"
|
87
|
239 |
"- wrong beforeEntryId: (%d)", beforeEntryId);
|
85
|
240 |
}
|
|
241 |
operationType = TCaOperationParams::EInsert;
|
|
242 |
break;
|
|
243 |
}
|
|
244 |
TCaOperationParams params = { operationType, groupId, beforeEntryId };
|
|
245 |
mSession.OrganizeL(array, params);
|
|
246 |
CleanupStack::PopAndDestroy(&array);
|
|
247 |
}
|
|
248 |
|
|
249 |
//----------------------------------------------------------------------------
|
|
250 |
//
|
|
251 |
//----------------------------------------------------------------------------
|
|
252 |
void CaClientProxy::removeEntriesFromGroupL(int groupId,
|
87
|
253 |
const QList<int> &entryIdList)
|
85
|
254 |
{
|
|
255 |
RCaIdsArray array;
|
|
256 |
CleanupClosePushL(array);
|
|
257 |
CaObjectAdapter::convertL(entryIdList, array);
|
|
258 |
TCaOperationParams params = { TCaOperationParams::ERemove,
|
87
|
259 |
groupId, 0 /*not used*/
|
|
260 |
};
|
85
|
261 |
mSession.OrganizeL(array, params);
|
|
262 |
CleanupStack::PopAndDestroy(&array);
|
|
263 |
}
|
|
264 |
|
|
265 |
//----------------------------------------------------------------------------
|
|
266 |
//
|
|
267 |
//----------------------------------------------------------------------------
|
|
268 |
void CaClientProxy::getDataL(const QList<int> &entryIdList,
|
92
|
269 |
QList< QSharedPointer<CaEntry> > &sourceList)
|
85
|
270 |
{
|
|
271 |
CCaInnerQuery *query = CCaInnerQuery::NewLC();
|
|
272 |
RArray<TInt> array;
|
|
273 |
CleanupClosePushL(array);
|
|
274 |
CaObjectAdapter::convertL(entryIdList, array);
|
|
275 |
query->SetIdsL(array);
|
|
276 |
RCaEntriesArray results;
|
|
277 |
CleanupResetAndDestroyPushL(results);
|
|
278 |
mSession.GetListL(*query, results);
|
|
279 |
CaObjectAdapter::convertL(results, sourceList);
|
|
280 |
CleanupStack::PopAndDestroy(&results);
|
|
281 |
CleanupStack::PopAndDestroy(&array);
|
|
282 |
CleanupStack::PopAndDestroy(query);
|
|
283 |
}
|
|
284 |
|
|
285 |
//----------------------------------------------------------------------------
|
|
286 |
//
|
|
287 |
//----------------------------------------------------------------------------
|
|
288 |
void CaClientProxy::getDataL(const CaQuery &query,
|
92
|
289 |
QList< QSharedPointer<CaEntry> > &sourceList)
|
85
|
290 |
{
|
|
291 |
CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC();
|
|
292 |
CaObjectAdapter::convertL(query, *innerQuery);
|
|
293 |
RCaEntriesArray results;
|
|
294 |
CleanupResetAndDestroyPushL(results);
|
|
295 |
mSession.GetListL(*innerQuery, results);
|
|
296 |
CaObjectAdapter::convertL(results, sourceList);
|
|
297 |
CleanupStack::PopAndDestroy(&results);
|
|
298 |
CleanupStack::PopAndDestroy(innerQuery);
|
|
299 |
}
|
|
300 |
|
|
301 |
//----------------------------------------------------------------------------
|
|
302 |
//
|
|
303 |
//----------------------------------------------------------------------------
|
|
304 |
void CaClientProxy::getEntryIdsL(const CaQuery &query,
|
87
|
305 |
QList<int> &sourceIdList)
|
85
|
306 |
{
|
|
307 |
CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC();
|
|
308 |
CaObjectAdapter::convertL(query, *innerQuery);
|
|
309 |
RCaIdsArray results;
|
|
310 |
CleanupClosePushL(results);
|
|
311 |
mSession.GetEntryIdsL(*innerQuery, results);
|
|
312 |
CaObjectAdapter::convertL(results, sourceIdList);
|
|
313 |
CleanupStack::PopAndDestroy(&results);
|
|
314 |
CleanupStack::PopAndDestroy(innerQuery);
|
|
315 |
}
|
|
316 |
|
|
317 |
|
|
318 |
//----------------------------------------------------------------------------
|
|
319 |
//
|
|
320 |
//----------------------------------------------------------------------------
|
87
|
321 |
void CaClientProxy::touchL(const CaEntry &entry)
|
85
|
322 |
{
|
87
|
323 |
CCaInnerEntry *innerEntry = CCaInnerEntry::NewLC();
|
85
|
324 |
|
87
|
325 |
CaObjectAdapter::convertL(entry, *innerEntry);
|
|
326 |
|
85
|
327 |
mSession.TouchL(*innerEntry);
|
87
|
328 |
|
85
|
329 |
CleanupStack::PopAndDestroy(innerEntry);
|
|
330 |
}
|
|
331 |
|
|
332 |
//----------------------------------------------------------------------------
|
|
333 |
//
|
|
334 |
//----------------------------------------------------------------------------
|
|
335 |
void CaClientProxy::customSortL(const QList<int> &entryIdList, int groupId)
|
|
336 |
{
|
|
337 |
RCaIdsArray array;
|
|
338 |
CleanupClosePushL(array);
|
|
339 |
CaObjectAdapter::convertL(entryIdList, array);
|
87
|
340 |
|
85
|
341 |
mSession.CustomSortL(array, groupId);
|
|
342 |
CleanupStack::PopAndDestroy(&array);
|
|
343 |
}
|
|
344 |
|