85
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 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: caservice.cpp
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <QMetaType>
|
|
19 |
#include <QCoreApplication>
|
|
20 |
#include <QString>
|
|
21 |
#include <QDebug>
|
|
22 |
|
|
23 |
#include "caservice.h"
|
|
24 |
#include "caservice_p.h"
|
|
25 |
#include "caquery.h"
|
|
26 |
#include "caentry.h"
|
|
27 |
#include "canotifier.h"
|
|
28 |
#include "canotifier_p.h"
|
|
29 |
#include "cadefs.h"
|
|
30 |
|
|
31 |
#include "caclientproxy.h"
|
93
|
32 |
#include "caclientnotifierproxy.h"
|
96
|
33 |
#include "cahandlerproxy.h"
|
|
34 |
#include "caqtsfhandlerloader.h"
|
85
|
35 |
#include "caobjectadapter.h"
|
87
|
36 |
#include "caclienttest_global.h"
|
85
|
37 |
|
|
38 |
// ======== MEMBER FUNCTIONS ========
|
|
39 |
|
|
40 |
/*!
|
|
41 |
|
|
42 |
\class CaService.
|
94
|
43 |
\brief This class operates on data, enables creating and inserting new entry
|
85
|
44 |
to DB, removing entry from DB, update entry or get entry from DB, execute
|
94
|
45 |
command on entry and create notifier to notify a client about changes onto DB.
|
85
|
46 |
|
|
47 |
CaService class uses singleton design pattern, so that it contains static
|
|
48 |
method called instance() to get instance of a class.
|
|
49 |
|
94
|
50 |
References to CaService instance are counted. When the number of references
|
|
51 |
drops to zero the instance is deleted to save memory.
|
|
52 |
CaNotifier class contains a member referencing to the CaService instance so
|
|
53 |
it is not deleted unless all CaNotifier instances are deleted (and there are
|
|
54 |
no variables referencing CaService).
|
|
55 |
|
85
|
56 |
\code
|
|
57 |
QSharedPointer<CaService> service = CaService::instance();
|
|
58 |
\endcode
|
|
59 |
|
94
|
60 |
For every operations on data is used always one instantiation of the class.
|
|
61 |
Below, there are examples how to create data and work on those ones.
|
85
|
62 |
|
|
63 |
*/
|
|
64 |
|
93
|
65 |
/*!
|
|
66 |
\var CaServicePrivate::m_q
|
|
67 |
Points to the CaService instance that uses this private implementation.
|
|
68 |
*/
|
|
69 |
|
|
70 |
/*!
|
|
71 |
\var CaServicePrivate::mProxy
|
|
72 |
Proxy to communicate with Symbian server.
|
|
73 |
*/
|
|
74 |
|
|
75 |
/*!
|
|
76 |
\var CaServicePrivate::mErrorCode
|
|
77 |
code of error caused by last operation.
|
|
78 |
*/
|
|
79 |
|
|
80 |
/*!
|
|
81 |
\var CaServicePrivate::mNotifierProxy
|
|
82 |
Proxy to client notifier.
|
|
83 |
*/
|
|
84 |
|
85
|
85 |
// Initialization of a static member variable.
|
|
86 |
QWeakPointer<CaService> CaService::m_instance = QWeakPointer<CaService>();
|
|
87 |
/*!
|
|
88 |
Constructor.
|
|
89 |
\param parent pointer to a parent. It defaults to NULL.
|
|
90 |
*/
|
|
91 |
CaService::CaService(QObject *parent) :
|
|
92 |
QObject(parent), m_d(new CaServicePrivate(this))
|
|
93 |
{
|
|
94 |
}
|
|
95 |
|
|
96 |
/*!
|
|
97 |
Returns a pointer to the instance of the CaService class.
|
|
98 |
\retval A pointer to the instance of the CaService class.
|
|
99 |
*/
|
|
100 |
QSharedPointer<CaService> CaService::instance()
|
|
101 |
{
|
|
102 |
QSharedPointer<CaService> service(m_instance);
|
|
103 |
if (!service) {
|
|
104 |
// Register custom types used as types of signal parameters.
|
|
105 |
qRegisterMetaType<ChangeType> ("ChangeType");
|
|
106 |
qRegisterMetaType<CaEntry> ("CaEntry");
|
|
107 |
|
|
108 |
service = QSharedPointer<CaService>(new CaService);
|
|
109 |
m_instance = service.toWeakRef();
|
|
110 |
}
|
|
111 |
return service;
|
|
112 |
}
|
|
113 |
|
|
114 |
/*!
|
|
115 |
Destructor.
|
|
116 |
*/
|
|
117 |
CaService::~CaService()
|
|
118 |
{
|
|
119 |
delete m_d;
|
|
120 |
}
|
|
121 |
|
|
122 |
/*!
|
|
123 |
Search for an entry
|
|
124 |
\param entryId id of the entry to find.
|
|
125 |
\retval pointer to the found entry.
|
|
126 |
|
|
127 |
\example
|
|
128 |
\code
|
|
129 |
...
|
|
130 |
CaEntry * entryFromDB = service->getEntry( newItem->id() );
|
|
131 |
|
|
132 |
\endcode
|
|
133 |
*/
|
92
|
134 |
QSharedPointer<CaEntry> CaService::getEntry(int entryId) const
|
85
|
135 |
{
|
92
|
136 |
QList< QSharedPointer<CaEntry> > entries = getEntries(QList<int> () << entryId);
|
85
|
137 |
if (entries.count()) {
|
|
138 |
// there should be exactly one entry with specified ID if present
|
|
139 |
Q_ASSERT(entries.count() == 1);
|
|
140 |
return entries[0];
|
87
|
141 |
} else {
|
92
|
142 |
return QSharedPointer<CaEntry>();
|
85
|
143 |
}
|
|
144 |
}
|
|
145 |
|
|
146 |
/*!
|
|
147 |
Search for entries.
|
|
148 |
\param entryIdList list of ids.
|
|
149 |
\return list of found entries.
|
|
150 |
|
|
151 |
\example
|
|
152 |
\code
|
|
153 |
...
|
|
154 |
QList<CaEntry *> entriesFromDB = service->getEntries(
|
|
155 |
QList<int>() << newItem->id() << newGroup->id() );
|
|
156 |
QList<int> idsList;
|
|
157 |
QStringList textEntry;
|
|
158 |
CaEntry *entry(NULL);
|
|
159 |
foreach( entry, entriesFromDB ) {
|
|
160 |
idsList << entry->id();
|
|
161 |
textEntry << entry->text();
|
|
162 |
}
|
|
163 |
|
|
164 |
\endcode
|
|
165 |
*/
|
92
|
166 |
QList< QSharedPointer<CaEntry> > CaService::getEntries(const QList<int> &entryIdList) const
|
85
|
167 |
{
|
|
168 |
return m_d->getEntries(entryIdList);
|
|
169 |
}
|
|
170 |
|
|
171 |
/*!
|
|
172 |
Search for entries.
|
|
173 |
\param query query
|
|
174 |
\retval list of entries
|
|
175 |
|
|
176 |
\example
|
|
177 |
\code
|
|
178 |
...
|
|
179 |
CaQuery query;
|
|
180 |
query.setEntryRoles( ItemEntryRole | GroupEntryRole );
|
|
181 |
query.setEntryTypeNames( QStringList() << "TypeNameGroup" << "ItemNameGroup" );
|
|
182 |
QList<CaEntry *> entriesFromDB = service->getEntries( query );
|
|
183 |
QList<int> idsList;
|
|
184 |
QStringList typeNames;
|
|
185 |
CaEntry *entry(NULL);
|
|
186 |
foreach( entry, entriesFromDB ) {
|
|
187 |
idsList << entry->id();
|
|
188 |
typeNames << entry->entryTypeName();
|
|
189 |
}
|
|
190 |
|
|
191 |
\endcode
|
|
192 |
*/
|
92
|
193 |
QList< QSharedPointer<CaEntry> > CaService::getEntries(const CaQuery &query) const
|
85
|
194 |
{
|
|
195 |
return m_d->getEntries(query);
|
|
196 |
}
|
|
197 |
|
|
198 |
/*!
|
|
199 |
Search for entries and return their ids.
|
|
200 |
\param query query
|
|
201 |
\retval list of ids
|
|
202 |
|
|
203 |
\example
|
|
204 |
\code
|
|
205 |
...
|
|
206 |
CaQuery query;
|
|
207 |
query.setEntryRoles( ItemEntryRole | GroupEntryRole );
|
|
208 |
query.setEntryTypeNames( QStringList() << "TypeNameGroup" << "ItemNameGroup" );
|
|
209 |
QList<int> entriesIdsFromDB = service->getEntryIds( query );
|
|
210 |
QList<int> idsList;
|
|
211 |
QStringList typeNames;
|
|
212 |
int id( -1 );
|
|
213 |
foreach( id, entriesIdsFromDB ) {
|
|
214 |
idsList << id
|
|
215 |
typeNames << entry->entryTypeName();
|
|
216 |
}
|
|
217 |
|
|
218 |
\endcode
|
|
219 |
*/
|
|
220 |
QList<int> CaService::getEntryIds(const CaQuery &query) const
|
|
221 |
{
|
|
222 |
return m_d->getEntryIds(query);
|
|
223 |
}
|
|
224 |
|
|
225 |
/*!
|
|
226 |
Create copy of entry.
|
|
227 |
\param entry entry to copy
|
|
228 |
\retval pointer to newely created copy
|
|
229 |
|
|
230 |
\example
|
|
231 |
\code
|
|
232 |
...
|
|
233 |
// creating new entry and add to DB
|
|
234 |
CaEntry group( GroupEntryRole );
|
|
235 |
group.setText( "TextGroup" );
|
|
236 |
group.setTypeName( "TypeNameGroup" );
|
|
237 |
|
|
238 |
CaEntry item( ItemEntryRole );
|
|
239 |
item.setText( "TextItem" );
|
|
240 |
item.setTypeName( "TypeNameItem" );
|
|
241 |
|
|
242 |
CaEntry * newGroup = service->createEntry( group );
|
|
243 |
CaEntry * newItem = service->createEntry( item );
|
|
244 |
...
|
|
245 |
\endcode
|
|
246 |
*/
|
92
|
247 |
QSharedPointer<CaEntry> CaService::createEntry(const CaEntry &entry) const
|
85
|
248 |
{
|
|
249 |
return m_d->createEntry(entry);
|
|
250 |
}
|
|
251 |
|
|
252 |
/*!
|
|
253 |
Remove entry.
|
|
254 |
\param entryId id of an entry to remove
|
|
255 |
\retval true if operation was successful
|
|
256 |
|
|
257 |
\example
|
|
258 |
\code
|
|
259 |
...
|
|
260 |
bool result = service->removeEntry( newItem->id() );
|
|
261 |
\b Output:
|
|
262 |
result == true
|
|
263 |
\endcode
|
|
264 |
*/
|
|
265 |
bool CaService::removeEntry(int entryId) const
|
|
266 |
{
|
|
267 |
return removeEntries(QList<int> () << entryId);
|
|
268 |
}
|
|
269 |
|
|
270 |
/*!
|
|
271 |
Remove entries.
|
|
272 |
\param entry entry to remove
|
|
273 |
\retval true if operation was successful
|
|
274 |
|
|
275 |
\example
|
|
276 |
\code
|
|
277 |
...
|
|
278 |
bool result = service->removeEntry( *newItem );
|
|
279 |
\b Output:
|
|
280 |
result == true
|
|
281 |
\endcode
|
|
282 |
*/
|
|
283 |
bool CaService::removeEntry(const CaEntry &entry) const
|
|
284 |
{
|
|
285 |
return removeEntry(entry.id());
|
|
286 |
}
|
|
287 |
|
|
288 |
/*!
|
|
289 |
Remove entries.
|
|
290 |
All others are convenience methods implemented in terms of this one.
|
|
291 |
\param entryIdList list of ids of entries to remove
|
|
292 |
\retval true if operation was successful
|
|
293 |
|
|
294 |
\example
|
|
295 |
\code
|
|
296 |
...
|
|
297 |
bool result = service->removeEntries( QList<int>() << newItem->id() );
|
|
298 |
\b Output:
|
|
299 |
result == true
|
|
300 |
\endcode
|
|
301 |
*/
|
|
302 |
bool CaService::removeEntries(const QList<int> &entryIdList) const
|
|
303 |
{
|
|
304 |
return m_d->removeEntries(entryIdList);
|
|
305 |
}
|
|
306 |
|
|
307 |
/*!
|
|
308 |
Remove entries.
|
|
309 |
\param entryList list of entries to remove
|
|
310 |
\retval true if operation was successful
|
|
311 |
|
|
312 |
\example
|
|
313 |
\code
|
|
314 |
...
|
92
|
315 |
bool result = service->removeEntries( QList< QSharedPointer<CaEntry> >() << newItem );
|
85
|
316 |
\b Output:
|
|
317 |
result == true
|
|
318 |
\endcode
|
|
319 |
*/
|
92
|
320 |
bool CaService::removeEntries(const QList< QSharedPointer<CaEntry> > &entryList) const
|
85
|
321 |
{
|
|
322 |
QList<int> idList;
|
92
|
323 |
QSharedPointer<CaEntry> entry;
|
85
|
324 |
foreach(entry, entryList) {
|
87
|
325 |
idList << entry->id();
|
|
326 |
}
|
85
|
327 |
return removeEntries(idList);
|
|
328 |
}
|
|
329 |
|
|
330 |
/*!
|
|
331 |
Update entry.
|
|
332 |
\param entry entry to update
|
|
333 |
\retval true if operation was successful
|
|
334 |
|
|
335 |
\example
|
|
336 |
\code
|
|
337 |
...
|
|
338 |
newItem->setAttribute( "attrName", "attrValue" );
|
|
339 |
bool result = service->updateEntry( *newItem );
|
|
340 |
\b Output:
|
|
341 |
result == true
|
|
342 |
\endcode
|
|
343 |
*/
|
|
344 |
bool CaService::updateEntry(const CaEntry &entry) const
|
|
345 |
{
|
|
346 |
return m_d->updateEntry(entry);
|
|
347 |
}
|
|
348 |
|
|
349 |
/*!
|
|
350 |
Performs touch operation on entry.
|
|
351 |
\param entry of entry to be touched
|
|
352 |
\retval boolean with result of operation
|
|
353 |
|
|
354 |
\example
|
|
355 |
\code
|
|
356 |
...
|
|
357 |
bool result = service->touch( newItem );
|
|
358 |
\b Output:
|
|
359 |
result == true
|
|
360 |
\endcode
|
|
361 |
*/
|
|
362 |
bool CaService::touch(const CaEntry &entry) const
|
|
363 |
{
|
|
364 |
return m_d->touch(entry);
|
|
365 |
}
|
|
366 |
|
|
367 |
/*!
|
|
368 |
Insert entry into a given group.
|
|
369 |
\param groupId id of a group.
|
|
370 |
\param entryId id of an entry to insert.
|
|
371 |
\param beforeEntryId id of an entry before which the given entry is inserted.
|
|
372 |
\retval true if operation was successful.
|
|
373 |
|
|
374 |
\example
|
|
375 |
\code
|
|
376 |
...
|
|
377 |
CaEntry itemToAdd;
|
|
378 |
itemToAdd.setText( "TextAdd" );
|
|
379 |
itemToAdd.setTypeName( "TypeNameAdd" );
|
|
380 |
CaEntry * entryToAdd = service->createEntry( itemToAdd );
|
|
381 |
...
|
|
382 |
bool result = service->insertEntryIntoGroup(
|
|
383 |
newGroup->id(), entryToAdd->id(), newItem->id());
|
|
384 |
\b Output:
|
|
385 |
result == true
|
|
386 |
\endcode
|
|
387 |
*/
|
|
388 |
bool CaService::insertEntryIntoGroup(int groupId, int entryId,
|
87
|
389 |
int beforeEntryId) const
|
85
|
390 |
{
|
|
391 |
return insertEntriesIntoGroup(groupId, QList<int> () << entryId,
|
87
|
392 |
beforeEntryId);
|
85
|
393 |
}
|
|
394 |
|
|
395 |
/*!
|
|
396 |
Insert entry into a given group.
|
|
397 |
\param group group.
|
|
398 |
\param entry entry to insert.
|
|
399 |
\param beforeEntryId id of an entry before which the given entry is inserted.
|
|
400 |
\retval true if operation was successful.
|
|
401 |
|
|
402 |
\example
|
|
403 |
\code
|
|
404 |
...
|
|
405 |
CaEntry itemToAdd;
|
|
406 |
itemToAdd.setText( "TextAdd" );
|
|
407 |
itemToAdd.setTypeName( "TypeNameAdd" );
|
|
408 |
CaEntry * entryToAdd = service->createEntry( itemToAdd );
|
|
409 |
...
|
|
410 |
bool result = service->insertEntryIntoGroup(
|
|
411 |
*newGroup, *entryToAdd, newItem->id());
|
|
412 |
\b Output:
|
|
413 |
result == true
|
|
414 |
\endcode
|
|
415 |
*/
|
|
416 |
bool CaService::insertEntryIntoGroup(const CaEntry &group,
|
87
|
417 |
const CaEntry &entry, int beforeEntryId) const
|
85
|
418 |
{
|
|
419 |
return insertEntryIntoGroup(group.id(), entry.id(), beforeEntryId);
|
|
420 |
}
|
|
421 |
|
|
422 |
/*!
|
|
423 |
Insert entries into a given group.
|
|
424 |
All others are convenience methods implemented in terms of this one.
|
|
425 |
\param groupId id of a group.
|
|
426 |
\param entryIdList list of ids of entries to insert.
|
|
427 |
\param beforeEntryId id of an entry before which the given entry is inserted.
|
|
428 |
\retval true if operation was successful.
|
|
429 |
|
|
430 |
\example
|
|
431 |
\code
|
|
432 |
...
|
|
433 |
CaEntry itemToAdd;
|
|
434 |
itemToAdd.setText( "TextAdd" );
|
|
435 |
itemToAdd.setTypeName( "TypeNameAdd" );
|
|
436 |
CaEntry * entryToAdd = service->createEntry( itemToAdd );
|
|
437 |
...
|
|
438 |
bool result = service->insertEntriesIntoGroup(
|
|
439 |
newGroup->id(), QList<int>() << entryToAdd->id(), newItem->id());
|
|
440 |
\b Output:
|
|
441 |
result == true
|
|
442 |
\endcode
|
|
443 |
*/
|
|
444 |
bool CaService::insertEntriesIntoGroup(int groupId,
|
87
|
445 |
const QList<int> &entryIdList, int beforeEntryId) const
|
85
|
446 |
{
|
|
447 |
if (beforeEntryId < 0) {
|
|
448 |
qWarning(
|
|
449 |
"CaService::insertEntriesIntoGroup: beforeEntryId cannot be negative: %d",
|
|
450 |
beforeEntryId);
|
|
451 |
return false;
|
87
|
452 |
} else {
|
85
|
453 |
return m_d->insertEntriesIntoGroup(groupId, entryIdList,
|
87
|
454 |
beforeEntryId);
|
85
|
455 |
}
|
|
456 |
}
|
|
457 |
|
|
458 |
/*!
|
|
459 |
Insert entry into a given group.
|
|
460 |
\param group group.
|
|
461 |
\param entryList list of entries (pointers) to insert.
|
|
462 |
\param beforeEntryId id of an entry before which the given entry is inserted.
|
|
463 |
\retval true if operation was successful.
|
|
464 |
|
|
465 |
\example
|
|
466 |
\code
|
|
467 |
...
|
|
468 |
CaEntry itemToAdd;
|
|
469 |
itemToAdd.setText( "TextAdd" );
|
|
470 |
itemToAdd.setTypeName( "TypeNameAdd" );
|
|
471 |
CaEntry * entryToAdd = service->createEntry( itemToAdd );
|
|
472 |
...
|
|
473 |
bool result = service->insertEntriesIntoGroup(
|
|
474 |
*newGroup, QList<CaEntry *>() << entryToAdd, newItem->id());
|
|
475 |
\b Output:
|
|
476 |
result == true
|
|
477 |
\endcode
|
|
478 |
*/
|
|
479 |
bool CaService::insertEntriesIntoGroup(const CaEntry &group,
|
92
|
480 |
const QList< QSharedPointer<CaEntry> > &entryList, int beforeEntryId) const
|
85
|
481 |
{
|
|
482 |
QList<int> idList;
|
92
|
483 |
QSharedPointer<CaEntry> entry;
|
85
|
484 |
foreach(entry, entryList) {
|
87
|
485 |
idList << entry->id();
|
|
486 |
}
|
85
|
487 |
return insertEntriesIntoGroup(group.id(), idList, beforeEntryId);
|
|
488 |
}
|
|
489 |
|
|
490 |
/*!
|
|
491 |
Remove entry from a given group.
|
|
492 |
\param groupId id of a group.
|
|
493 |
\param entryId id of entry to remove.
|
|
494 |
\retval true if operation was successful.
|
|
495 |
|
|
496 |
\example
|
|
497 |
\code
|
|
498 |
...
|
|
499 |
CaEntry itemToAddRemove;
|
|
500 |
itemToAddRemove.setText( "TextAddRemove" );
|
|
501 |
itemToAddRemove.setTypeName( "TypeNameAddRemove" );
|
|
502 |
CaEntry * entryToAddRemove = service->createEntry( itemToAddRemove );
|
|
503 |
service->prependEntryToGroup( *newGroup, *entryToAddRemove );
|
|
504 |
...
|
|
505 |
bool result = service->removeEntryFromGroup(
|
|
506 |
newGroup->id(), entryToAddRemove->id());
|
|
507 |
\b Output:
|
|
508 |
result == true
|
|
509 |
\endcode
|
|
510 |
*/
|
|
511 |
bool CaService::removeEntryFromGroup(int groupId, int entryId) const
|
|
512 |
{
|
|
513 |
return removeEntriesFromGroup(groupId, QList<int> () << entryId);
|
|
514 |
}
|
|
515 |
|
|
516 |
/*!
|
|
517 |
Remove entry from a given group.
|
|
518 |
\param group group.
|
|
519 |
\param entryId id of entry to remove.
|
|
520 |
\retval true if operation was successful.
|
|
521 |
|
|
522 |
\example
|
|
523 |
\code
|
|
524 |
...
|
|
525 |
CaEntry itemToAddRemove;
|
|
526 |
itemToAddRemove.setText( "TextAddRemove" );
|
|
527 |
itemToAddRemove.setTypeName( "TypeNameAddRemove" );
|
|
528 |
CaEntry * entryToAddRemove = service->createEntry( itemToAddRemove );
|
|
529 |
service->prependEntryToGroup( *newGroup, *entryToAddRemove );
|
|
530 |
...
|
|
531 |
bool result = service->removeEntryFromGroup(
|
|
532 |
*newGroup, *entryToAddRemove );
|
|
533 |
\b Output:
|
|
534 |
result == true
|
|
535 |
\endcode
|
|
536 |
*/
|
|
537 |
bool CaService::removeEntryFromGroup(const CaEntry &group,
|
87
|
538 |
const CaEntry &entry) const
|
85
|
539 |
{
|
|
540 |
return removeEntryFromGroup(group.id(), entry.id());
|
|
541 |
}
|
|
542 |
|
|
543 |
/*!
|
|
544 |
Remove entries from a given group.
|
|
545 |
All others are convenience methods implemented in terms of this one.
|
|
546 |
\param groupId id of a group.
|
|
547 |
\param entryIdList list of ids of entries to remove.
|
|
548 |
\retval true if operation was successful.
|
|
549 |
|
|
550 |
\example
|
|
551 |
\code
|
|
552 |
...
|
|
553 |
CaEntry itemToAddRemove;
|
|
554 |
itemToAddRemove.setText( "TextAddRemove" );
|
|
555 |
itemToAddRemove.setTypeName( "TypeNameAddRemove" );
|
|
556 |
CaEntry * entryToAddRemove = service->createEntry( itemToAddRemove );
|
|
557 |
service->prependEntryToGroup( *newGroup, *entryToAddRemove );
|
|
558 |
...
|
|
559 |
bool result = service->removeEntriesFromGroup(
|
|
560 |
newGroup->id(), QList<int>() << entryToAddRemove->id() );
|
|
561 |
\b Output:
|
|
562 |
result == true
|
|
563 |
\endcode
|
|
564 |
*/
|
|
565 |
bool CaService::removeEntriesFromGroup(int groupId,
|
87
|
566 |
const QList<int> &entryIdList) const
|
85
|
567 |
{
|
|
568 |
return m_d->removeEntriesFromGroup(groupId, entryIdList);
|
|
569 |
}
|
|
570 |
|
|
571 |
/*!
|
|
572 |
Remove entries from a given group.
|
|
573 |
All others are convenience methods implemented in terms of this one.
|
|
574 |
\param group group.
|
|
575 |
\param entryList list of entries (pointers) to remove.
|
|
576 |
\retval true if operation was successful.
|
|
577 |
|
|
578 |
\example
|
|
579 |
\code
|
|
580 |
...
|
|
581 |
CaEntry itemToAddRemove;
|
|
582 |
itemToAddRemove.setText( "TextAddRemove" );
|
|
583 |
itemToAddRemove.setTypeName( "TypeNameAddRemove" );
|
|
584 |
CaEntry * entryToAddRemove = service->createEntry( itemToAddRemove );
|
|
585 |
service->prependEntryToGroup( *newGroup, *entryToAddRemove );
|
|
586 |
...
|
|
587 |
bool result = service->removeEntriesFromGroup(
|
|
588 |
*newGroup, QList<CaEntry *>() << entryToAddRemove );
|
|
589 |
\b Output:
|
|
590 |
result == true
|
|
591 |
\endcode
|
|
592 |
*/
|
|
593 |
bool CaService::removeEntriesFromGroup(const CaEntry &group,
|
92
|
594 |
const QList< QSharedPointer<CaEntry> > &entryList) const
|
85
|
595 |
{
|
|
596 |
QList<int> idList;
|
92
|
597 |
QSharedPointer<CaEntry> entry;
|
85
|
598 |
foreach(entry, entryList) {
|
87
|
599 |
idList << entry->id();
|
|
600 |
}
|
85
|
601 |
return removeEntriesFromGroup(group.id(), idList);
|
|
602 |
}
|
|
603 |
|
|
604 |
/*!
|
|
605 |
Place entries in a given group at the end.
|
|
606 |
\param groupId id of a group.
|
|
607 |
\param entryId id of entry to append.
|
|
608 |
\retval true if operation was successful.
|
|
609 |
|
|
610 |
\example
|
|
611 |
\code
|
|
612 |
...
|
|
613 |
CaEntry itemToAppend;
|
|
614 |
itemToAppend.setText( "TextAppend" );
|
|
615 |
itemToAppend.setTypeName( "TypeNameAppend" );
|
|
616 |
CaEntry * entryToAppend = service->createEntry( itemToAppend );
|
|
617 |
bool result = service->appendEntryToGroup(
|
|
618 |
newGroup->id(), entryToAppend->id() );
|
|
619 |
...
|
|
620 |
\b Output:
|
|
621 |
result == true
|
|
622 |
\endcode
|
|
623 |
*/
|
|
624 |
bool CaService::appendEntryToGroup(int groupId, int entryId) const
|
|
625 |
{
|
|
626 |
return appendEntriesToGroup(groupId, QList<int> () << entryId);
|
|
627 |
}
|
|
628 |
|
|
629 |
/*!
|
|
630 |
Place entries in a given group at the end.
|
|
631 |
\param group group.
|
|
632 |
\param entry entry to append.
|
|
633 |
\retval true if operation was successful.
|
|
634 |
|
|
635 |
\example
|
|
636 |
\code
|
|
637 |
...
|
|
638 |
CaEntry itemToAppend;
|
|
639 |
itemToAppend.setText( "TextAppend" );
|
|
640 |
itemToAppend.setTypeName( "TypeNameAppend" );
|
|
641 |
CaEntry * entryToAppend = service->createEntry( itemToAppend );
|
|
642 |
bool result = service->appendEntryToGroup(
|
|
643 |
*newGroup, *entryToAppend );
|
|
644 |
...
|
|
645 |
\b Output:
|
|
646 |
result == true
|
|
647 |
\endcode
|
|
648 |
*/
|
|
649 |
bool CaService::appendEntryToGroup(const CaEntry &group,
|
87
|
650 |
const CaEntry &entry) const
|
85
|
651 |
{
|
|
652 |
return appendEntryToGroup(group.id(), entry.id());
|
|
653 |
}
|
|
654 |
|
|
655 |
/*!
|
|
656 |
Place entries in a given group at the end.
|
|
657 |
All others are convenience methods implemented in terms of this one.
|
|
658 |
\param groupId group.
|
|
659 |
\param entryIdList list of ids of entries to append.
|
|
660 |
\retval true if operation was successful.
|
|
661 |
|
|
662 |
\example
|
|
663 |
\code
|
|
664 |
...
|
|
665 |
CaEntry itemToAppend;
|
|
666 |
itemToAppend.setText( "TextAppend" );
|
|
667 |
itemToAppend.setTypeName( "TypeNameAppend" );
|
|
668 |
CaEntry * entryToAppend = service->createEntry( itemToAppend );
|
|
669 |
bool result = service->appendEntriesToGroup(
|
|
670 |
newGroup->id(), QList<int>() << entryToAppend->id() );
|
|
671 |
...
|
|
672 |
\b Output:
|
|
673 |
result == true
|
|
674 |
\endcode
|
|
675 |
*/
|
|
676 |
bool CaService::appendEntriesToGroup(int groupId,
|
87
|
677 |
const QList<int> &entryIdList) const
|
85
|
678 |
{
|
|
679 |
return m_d->appendEntriesToGroup(groupId, entryIdList);
|
|
680 |
}
|
|
681 |
|
|
682 |
/*!
|
|
683 |
Place entries in a given group at the end.
|
|
684 |
\param group group.
|
|
685 |
\param entryList list of entries to append.
|
|
686 |
\retval true if operation was successful.
|
|
687 |
|
|
688 |
\example
|
|
689 |
\code
|
|
690 |
...
|
|
691 |
CaEntry itemToAppend;
|
|
692 |
itemToAppend.setText( "TextAppend" );
|
|
693 |
itemToAppend.setTypeName( "TypeNameAppend" );
|
|
694 |
CaEntry * entryToAppend = service->createEntry( itemToAppend );
|
|
695 |
bool result = service->appendEntriesToGroup(
|
92
|
696 |
*newGroup, QList< QSharedPointer<CaEntry> >() << entryToAppend );
|
85
|
697 |
...
|
|
698 |
\b Output:
|
|
699 |
result == true
|
|
700 |
\endcode
|
|
701 |
*/
|
|
702 |
bool CaService::appendEntriesToGroup(const CaEntry &group,
|
92
|
703 |
const QList< QSharedPointer<CaEntry> > &entryList) const
|
85
|
704 |
{
|
|
705 |
QList<int> idList;
|
92
|
706 |
QSharedPointer<CaEntry> entry;
|
85
|
707 |
foreach(entry, entryList) {
|
87
|
708 |
idList << entry->id();
|
|
709 |
}
|
85
|
710 |
return appendEntriesToGroup(group.id(), idList);
|
|
711 |
}
|
|
712 |
|
|
713 |
/*!
|
|
714 |
Place entries in a given group at the beginning.
|
|
715 |
\param groupId id of a group.
|
|
716 |
\param entryId id of entry to prepend.
|
|
717 |
\retval true if operation was successful.
|
|
718 |
|
|
719 |
\example
|
|
720 |
\code
|
|
721 |
...
|
|
722 |
CaEntry itemToPrepend;
|
|
723 |
itemToPrepend.setText( "TextPrepend" );
|
|
724 |
itemToPrepend.setTypeName( "TypeNamePrepend" );
|
|
725 |
CaEntry * entryToPrepend = service->createEntry( itemToPrepend );
|
|
726 |
bool result = service->prependEntryToGroup(
|
|
727 |
newGroup->id(), entryToPrepend->id() );
|
|
728 |
...
|
|
729 |
\b Output:
|
|
730 |
result == true
|
|
731 |
\endcode
|
|
732 |
*/
|
|
733 |
bool CaService::prependEntryToGroup(int groupId, int entryId) const
|
|
734 |
{
|
|
735 |
return prependEntriesToGroup(groupId, QList<int> () << entryId);
|
|
736 |
}
|
|
737 |
|
|
738 |
/*!
|
|
739 |
Place entries in a given group at the beginning.
|
|
740 |
\param group group.
|
|
741 |
\param entry entry to prepend.
|
|
742 |
\retval true if operation was successful.
|
|
743 |
|
|
744 |
\example
|
|
745 |
\code
|
|
746 |
...
|
|
747 |
CaEntry itemToPrepend;
|
|
748 |
itemToPrepend.setText( "TextPrepend" );
|
|
749 |
itemToPrepend.setTypeName( "TypeNamePrepend" );
|
|
750 |
CaEntry * entryToPrepend = service->createEntry( itemToPrepend );
|
|
751 |
bool result = service->prependEntryToGroup(
|
|
752 |
*newGroup, *entryToPrepend );
|
|
753 |
...
|
|
754 |
\b Output:
|
|
755 |
result == true
|
|
756 |
\endcode
|
|
757 |
*/
|
|
758 |
bool CaService::prependEntryToGroup(const CaEntry &group,
|
87
|
759 |
const CaEntry &entry) const
|
85
|
760 |
{
|
|
761 |
return prependEntryToGroup(group.id(), entry.id());
|
|
762 |
}
|
|
763 |
|
|
764 |
/*!
|
|
765 |
Place entries in a given group at the beginning.
|
|
766 |
All others are convenience methods implemented in terms of this one.
|
|
767 |
\param groupId group.
|
|
768 |
\param entryIdList list of ids of entries to prepend.
|
|
769 |
\retval true if operation was successful.
|
|
770 |
|
|
771 |
\example
|
|
772 |
\code
|
|
773 |
...
|
|
774 |
CaEntry itemToPrepend;
|
|
775 |
itemToPrepend.setText( "TextPrepend" );
|
|
776 |
itemToPrepend.setTypeName( "TypeNamePrepend" );
|
|
777 |
CaEntry * entryToPrepend = service->createEntry( itemToPrepend );
|
|
778 |
bool result = service->prependEntriesToGroup(
|
|
779 |
newGroup->id(), QList<int>() << entryToPrepend->id() );
|
|
780 |
...
|
|
781 |
\b Output:
|
|
782 |
result == true
|
|
783 |
\endcode
|
|
784 |
*/
|
|
785 |
bool CaService::prependEntriesToGroup(int groupId,
|
87
|
786 |
const QList<int> &entryIdList) const
|
85
|
787 |
{
|
|
788 |
return m_d->prependEntriesToGroup(groupId, entryIdList);
|
|
789 |
}
|
|
790 |
|
|
791 |
/*!
|
|
792 |
Place entries in a given group at the begin.
|
|
793 |
\param group group.
|
|
794 |
\param entryList list of entries to prepend.
|
|
795 |
\retval true if operation was successful.
|
|
796 |
|
|
797 |
\example
|
|
798 |
\code
|
|
799 |
...
|
|
800 |
CaEntry itemToPrepend;
|
|
801 |
itemToPrepend.setText( "TextPrepend" );
|
|
802 |
itemToPrepend.setTypeName( "TypeNamePrepend" );
|
|
803 |
CaEntry * entryToPrepend = service->createEntry( itemToPrepend );
|
|
804 |
bool result = service->prependEntriesToGroup(
|
|
805 |
*newGroup, QList<CaEntry *>() << entryToPrepend );
|
|
806 |
...
|
|
807 |
\b Output:
|
|
808 |
result == true
|
|
809 |
\endcode
|
|
810 |
*/
|
|
811 |
bool CaService::prependEntriesToGroup(const CaEntry &group,
|
92
|
812 |
const QList< QSharedPointer<CaEntry> > &entryList) const
|
85
|
813 |
{
|
|
814 |
QList<int> idList;
|
92
|
815 |
QSharedPointer<CaEntry> entry;
|
85
|
816 |
foreach(entry, entryList) {
|
87
|
817 |
idList << entry->id();
|
|
818 |
}
|
85
|
819 |
return prependEntriesToGroup(group.id(), idList);
|
|
820 |
}
|
|
821 |
|
|
822 |
/*!
|
|
823 |
Execute command.
|
|
824 |
\param entryId id of an entry.
|
|
825 |
\param command command.
|
|
826 |
\retval true if operation was successful.
|
|
827 |
|
|
828 |
\example
|
|
829 |
\code
|
|
830 |
...
|
|
831 |
CaEntry itemExecute;
|
|
832 |
itemExecute.setText("Application");
|
|
833 |
itemExecute.setTypeName("application");
|
|
834 |
itemExecute.setAttribute("application:uid", "0x12345678");
|
|
835 |
CaEntry * entryExecute = service->createEntry(itemExecute->id());
|
|
836 |
bool result = service->executeCommand(entryExecute->id(), "remove");
|
|
837 |
...
|
|
838 |
\b Output:
|
|
839 |
result == true
|
|
840 |
\endcode
|
|
841 |
*/
|
|
842 |
bool CaService::executeCommand(int entryId, const QString &command) const
|
|
843 |
{
|
|
844 |
bool result = false;
|
88
|
845 |
|
92
|
846 |
const QSharedPointer<CaEntry> temporaryEntry = getEntry(entryId);
|
88
|
847 |
|
92
|
848 |
if (!temporaryEntry.isNull()) {
|
85
|
849 |
result = executeCommand(*temporaryEntry, command);
|
|
850 |
}
|
|
851 |
return result;
|
|
852 |
}
|
|
853 |
|
|
854 |
/*!
|
|
855 |
Execute command.
|
|
856 |
\param entry entry.
|
|
857 |
\param command command.
|
|
858 |
\retval true if operation was successful.
|
|
859 |
|
|
860 |
\example
|
|
861 |
\code
|
|
862 |
...
|
|
863 |
CaEntry itemExecute;
|
|
864 |
itemExecute.setText("URL");
|
|
865 |
itemExecute.setTypeName("url");
|
|
866 |
itemExecute.setAttribute("url", "http://www.nokia.com");
|
|
867 |
CaEntry * entryExecute = service->createEntry(itemExecute->id());
|
|
868 |
bool result = service->executeCommand(*entryExecute, "open");
|
|
869 |
...
|
|
870 |
\b Output:
|
|
871 |
result == true
|
|
872 |
\endcode
|
|
873 |
*/
|
|
874 |
bool CaService::executeCommand(const CaEntry &entry, const QString &command) const
|
|
875 |
{
|
|
876 |
return m_d->executeCommand(entry, command);
|
|
877 |
}
|
|
878 |
|
|
879 |
/*!
|
|
880 |
Creates notifier.
|
|
881 |
\param const reference to CaNotifierFilter.
|
|
882 |
\retval pointer to created CaNotifier instance.
|
|
883 |
|
|
884 |
\code
|
|
885 |
...
|
|
886 |
// creating notifier with specified notifier filter
|
|
887 |
CaNotifierFilter notifierFilter;
|
|
888 |
notifierFilter.setIds( QList<int>() << newGroup->id() << newItem->id() );
|
|
889 |
notifierFilter.setEntryRole( ItemEntryRole | GroupEntryRole );
|
|
890 |
CaNotifier * notifier = service->createNotifier( notifierFilter );
|
|
891 |
...
|
|
892 |
\endcode
|
|
893 |
*/
|
87
|
894 |
CaNotifier *CaService::createNotifier(const CaNotifierFilter &filter) const
|
85
|
895 |
{
|
|
896 |
return m_d->createNotifier(filter);
|
|
897 |
}
|
|
898 |
|
|
899 |
/*!
|
|
900 |
Set new order of collection's items set by user.
|
|
901 |
\groupId Group id.
|
86
|
902 |
\param entryIdList consists of new order of items.
|
85
|
903 |
\retval true if new order of collection's items is set correctly,
|
|
904 |
otherwise return false.
|
|
905 |
*/
|
|
906 |
|
|
907 |
bool CaService::customSort(int groupId, QList<int> &entryIdList) const
|
|
908 |
{
|
|
909 |
return m_d->customSort(groupId, entryIdList);
|
|
910 |
}
|
|
911 |
|
|
912 |
/*!
|
|
913 |
Returns code of an error caused by the last executed operation.
|
|
914 |
\retval code of error, zero means no error.
|
|
915 |
|
|
916 |
\example
|
|
917 |
\code
|
|
918 |
...
|
|
919 |
CaEntry itemExecute;
|
|
920 |
itemExecute.setText("URL");
|
|
921 |
itemExecute.setTypeName("url");
|
|
922 |
itemExecute.setAttribute("url", "http://www.nokia.com");
|
|
923 |
CaEntry * entryExecute = service->createEntry(itemExecute->id());
|
|
924 |
bool result = service->executeCommand(*entryExecute, "open");
|
|
925 |
|
|
926 |
ErrorCode errorCode = lastError();
|
|
927 |
switch (errorCode) {
|
|
928 |
case NoErrorCode:
|
|
929 |
...
|
|
930 |
case BadArgumentErrorCode:
|
|
931 |
...
|
|
932 |
}
|
|
933 |
...
|
|
934 |
|
|
935 |
\endcode
|
|
936 |
*/
|
|
937 |
ErrorCode CaService::lastError() const
|
|
938 |
{
|
|
939 |
return m_d->lastError();
|
|
940 |
}
|
|
941 |
|
|
942 |
|
|
943 |
/*!
|
|
944 |
Constructor
|
|
945 |
\param servicePublic pointer to public service
|
|
946 |
*/
|
|
947 |
CaServicePrivate::CaServicePrivate(CaService *servicePublic) :
|
96
|
948 |
m_q(servicePublic),
|
|
949 |
mCommandHandler(new CaHandlerProxy(QSharedPointer<CaHandlerLoader>
|
|
950 |
(new CaQtSfHandlerLoader()))),
|
|
951 |
mProxy(new CaClientProxy()),
|
93
|
952 |
mNotifierProxy(NULL)
|
85
|
953 |
{
|
|
954 |
const ErrorCode connectionResult = mProxy->connect();
|
|
955 |
|
|
956 |
USE_QWARNING_IF(connectionResult)
|
87
|
957 |
<< "CaServicePrivate::CaServicePrivate - unable to connect proxy";
|
85
|
958 |
|
|
959 |
mErrorCode = connectionResult;
|
|
960 |
}
|
|
961 |
|
|
962 |
/*!
|
|
963 |
destructor
|
|
964 |
*/
|
|
965 |
CaServicePrivate::~CaServicePrivate()
|
|
966 |
{
|
|
967 |
delete mProxy;
|
93
|
968 |
delete mNotifierProxy;
|
85
|
969 |
}
|
|
970 |
|
|
971 |
/*!
|
|
972 |
Search for entries.
|
|
973 |
\param entryIdList list of entry ids
|
|
974 |
\retval list of entries (pointers)
|
|
975 |
*/
|
98
|
976 |
QList< QSharedPointer<CaEntry> > CaServicePrivate::getEntries(
|
|
977 |
const QList<int> &entryIdList) const
|
85
|
978 |
{
|
|
979 |
qDebug() << "CaServicePrivate::getEntries"
|
87
|
980 |
<< "entryIdList:" << entryIdList;
|
85
|
981 |
|
87
|
982 |
CACLIENTTEST_FUNC_ENTRY("CaServicePrivate::getEntries");
|
|
983 |
|
92
|
984 |
QList< QSharedPointer<CaEntry> > resultList;
|
85
|
985 |
|
|
986 |
mErrorCode = mProxy->getData(entryIdList, resultList);
|
|
987 |
|
|
988 |
// figure out whether all entries have been retrieved and
|
|
989 |
// store the operation status
|
|
990 |
if (mErrorCode == NoErrorCode
|
87
|
991 |
&& entryIdList.count() != resultList.count()) {
|
85
|
992 |
mErrorCode = NotFoundErrorCode;
|
93
|
993 |
}//one line with else if
|
|
994 |
else if (mErrorCode == ServerTerminated) {
|
|
995 |
if (!mProxy->connect()) {
|
|
996 |
if (mNotifierProxy) {
|
|
997 |
mNotifierProxy->connectSessions();
|
|
998 |
}
|
|
999 |
resultList.clear();
|
|
1000 |
mErrorCode = mProxy->getData(entryIdList, resultList);
|
|
1001 |
}
|
85
|
1002 |
}
|
87
|
1003 |
CACLIENTTEST_FUNC_EXIT("CaServicePrivate::getEntries");
|
85
|
1004 |
|
|
1005 |
qDebug() << "CaServicePrivate::getEntries mErrorCode:"
|
87
|
1006 |
<< mErrorCode;
|
85
|
1007 |
|
|
1008 |
return resultList;
|
|
1009 |
}
|
|
1010 |
|
|
1011 |
/*!
|
|
1012 |
Fetches data from database.
|
|
1013 |
\param query the query information to select specific entries.
|
|
1014 |
\param placeholder list of entries for a specific select.
|
|
1015 |
*/
|
92
|
1016 |
QList< QSharedPointer<CaEntry> > CaServicePrivate::getEntries(const CaQuery &query) const
|
85
|
1017 |
{
|
92
|
1018 |
QList< QSharedPointer<CaEntry> > resultList;
|
85
|
1019 |
|
|
1020 |
mErrorCode = mProxy->getData(query, resultList);
|
93
|
1021 |
if (mErrorCode == ServerTerminated) {
|
|
1022 |
if (!mProxy->connect()) {
|
|
1023 |
if (mNotifierProxy) {
|
|
1024 |
mNotifierProxy->connectSessions();
|
|
1025 |
}
|
|
1026 |
resultList.clear();
|
|
1027 |
mErrorCode = mProxy->getData(query, resultList);
|
|
1028 |
}
|
|
1029 |
}
|
85
|
1030 |
qDebug() << "CaServicePrivate::getEntries mErrorCode:" << mErrorCode;
|
|
1031 |
|
|
1032 |
return resultList;
|
|
1033 |
}
|
|
1034 |
|
|
1035 |
/*!
|
|
1036 |
Search for entries and return their ids.
|
|
1037 |
\param query query
|
|
1038 |
\retval list of ids
|
|
1039 |
*/
|
|
1040 |
QList<int> CaServicePrivate::getEntryIds(const CaQuery &query) const
|
|
1041 |
{
|
87
|
1042 |
CACLIENTTEST_FUNC_ENTRY("CaItemModelList::getEntryIds");
|
|
1043 |
|
85
|
1044 |
QList<int> resultList;
|
|
1045 |
mErrorCode = mProxy->getEntryIds(query, resultList);
|
93
|
1046 |
if (mErrorCode == ServerTerminated) {
|
|
1047 |
if (!mProxy->connect()) {
|
|
1048 |
if (mNotifierProxy) {
|
|
1049 |
mNotifierProxy->connectSessions();
|
|
1050 |
}
|
|
1051 |
resultList.clear();
|
|
1052 |
mErrorCode = mProxy->getEntryIds(query, resultList);
|
|
1053 |
}
|
|
1054 |
}
|
87
|
1055 |
CACLIENTTEST_FUNC_EXIT("CaItemModelList::getEntryIds");
|
85
|
1056 |
qDebug() << "CaServicePrivate::getEntryIds mErrorCode:" << mErrorCode;
|
|
1057 |
return resultList;
|
|
1058 |
}
|
|
1059 |
|
|
1060 |
/*!
|
|
1061 |
Create copy of entry.
|
|
1062 |
\param query const reference to entry to copy
|
|
1063 |
\retval pointer to newely created copy
|
|
1064 |
*/
|
92
|
1065 |
QSharedPointer<CaEntry> CaServicePrivate::createEntry(const CaEntry &entry)
|
85
|
1066 |
{
|
|
1067 |
qDebug() << "CaServicePrivate::createEntry"
|
87
|
1068 |
<< "entry id:" << entry.id();
|
85
|
1069 |
|
87
|
1070 |
CACLIENTTEST_FUNC_ENTRY("CaServicePrivate::createEntry");
|
|
1071 |
|
85
|
1072 |
ErrorCode addDataResult = NoErrorCode;
|
|
1073 |
|
92
|
1074 |
QSharedPointer<CaEntry> newEntry (new CaEntry(entry.role()));
|
85
|
1075 |
|
92
|
1076 |
QScopedPointer<CaEntry> entryClone(new CaEntry(entry));
|
|
1077 |
const int nonExistingObjectId = 0;
|
|
1078 |
CaObjectAdapter::setId(*entryClone, nonExistingObjectId);
|
85
|
1079 |
|
92
|
1080 |
addDataResult =
|
|
1081 |
mProxy->addData(*entryClone, *newEntry);
|
93
|
1082 |
if (addDataResult == ServerTerminated) {
|
|
1083 |
if (!mProxy->connect()) {
|
|
1084 |
if (mNotifierProxy) {
|
|
1085 |
mNotifierProxy->connectSessions();
|
|
1086 |
}
|
|
1087 |
addDataResult =
|
|
1088 |
mProxy->addData(*entryClone, *newEntry);
|
|
1089 |
}
|
|
1090 |
}
|
85
|
1091 |
|
92
|
1092 |
// return empty pointer if nothing was added
|
85
|
1093 |
if (addDataResult != NoErrorCode) {
|
92
|
1094 |
newEntry.clear();
|
85
|
1095 |
}
|
92
|
1096 |
|
85
|
1097 |
mErrorCode = addDataResult;
|
|
1098 |
|
|
1099 |
qDebug() << "CaServicePrivate::createEntry mErrorCode:" << mErrorCode;
|
|
1100 |
|
87
|
1101 |
CACLIENTTEST_FUNC_EXIT("CaServicePrivate::createEntry");
|
|
1102 |
|
85
|
1103 |
return newEntry;
|
|
1104 |
}
|
|
1105 |
|
|
1106 |
/*!
|
93
|
1107 |
Performs touch operation on entry.
|
|
1108 |
\param entry to be touched
|
|
1109 |
\retval boolean with result of operation
|
|
1110 |
*/
|
|
1111 |
bool CaServicePrivate::touch(const CaEntry &entry)
|
|
1112 |
{
|
|
1113 |
qDebug() << "CaServicePrivate::touch" << "entryId: " << entry.id();
|
|
1114 |
|
|
1115 |
mErrorCode = mProxy->touch(entry);
|
|
1116 |
if (mErrorCode == ServerTerminated) {
|
|
1117 |
if (!mProxy->connect()) {
|
|
1118 |
if (mNotifierProxy) {
|
|
1119 |
mNotifierProxy->connectSessions();
|
|
1120 |
}
|
|
1121 |
mErrorCode = mProxy->touch(entry);
|
|
1122 |
}
|
|
1123 |
}
|
|
1124 |
|
|
1125 |
qDebug() << "CaServicePrivate::touch mErrorCode:" << mErrorCode;
|
|
1126 |
|
|
1127 |
return (mErrorCode == NoErrorCode);
|
|
1128 |
}
|
|
1129 |
|
|
1130 |
/*!
|
85
|
1131 |
Update entry.
|
|
1132 |
\param entry entry const reference of entry to update
|
|
1133 |
\retval true if operation was successful
|
|
1134 |
*/
|
|
1135 |
bool CaServicePrivate::updateEntry(const CaEntry &entry)
|
|
1136 |
{
|
|
1137 |
qDebug() << "CaServicePrivate::updateEntry"
|
87
|
1138 |
<< "entry id:" << entry.id();
|
|
1139 |
|
|
1140 |
CACLIENTTEST_FUNC_ENTRY("CaServicePrivate::updateEntry");
|
85
|
1141 |
|
|
1142 |
ErrorCode updateEntryResult = UnknownErrorCode;
|
|
1143 |
|
|
1144 |
if (entry.id() != 0) {
|
|
1145 |
try {
|
|
1146 |
QScopedPointer<CaEntry> updatedEntry(new CaEntry(entry.role()));
|
|
1147 |
|
|
1148 |
updateEntryResult = mProxy->addData(entry, *updatedEntry);
|
93
|
1149 |
if (updateEntryResult == ServerTerminated) {
|
|
1150 |
if (!mProxy->connect()) {
|
|
1151 |
if (mNotifierProxy) {
|
|
1152 |
mNotifierProxy->connectSessions();
|
|
1153 |
}
|
|
1154 |
updateEntryResult = mProxy->addData(entry, *updatedEntry);
|
|
1155 |
}
|
|
1156 |
}
|
85
|
1157 |
|
87
|
1158 |
} catch (const std::bad_alloc &) {
|
85
|
1159 |
updateEntryResult = OutOfMemoryErrorCode;
|
|
1160 |
}
|
|
1161 |
}
|
|
1162 |
|
|
1163 |
mErrorCode = updateEntryResult;
|
|
1164 |
|
|
1165 |
qDebug() << "CaServicePrivate::updateEntry mErrorCode on return:"
|
87
|
1166 |
<< mErrorCode;
|
|
1167 |
CACLIENTTEST_FUNC_EXIT("CaServicePrivate::updateEntry");
|
85
|
1168 |
|
|
1169 |
return (updateEntryResult == NoErrorCode);
|
|
1170 |
}
|
|
1171 |
|
|
1172 |
/*!
|
|
1173 |
Remove entries.
|
|
1174 |
\param entryIdList list of entries ids to remove
|
|
1175 |
\retval true if operation was successful
|
|
1176 |
*/
|
|
1177 |
bool CaServicePrivate::removeEntries(const QList<int> &entryIdList)
|
|
1178 |
{
|
|
1179 |
qDebug() << "CaServicePrivate::removeEntries"
|
87
|
1180 |
<< "entryIdList: " << entryIdList;
|
|
1181 |
|
|
1182 |
CACLIENTTEST_FUNC_ENTRY("CaServicePrivate::removeEntries");
|
85
|
1183 |
|
|
1184 |
mErrorCode = mProxy->removeData(entryIdList);
|
93
|
1185 |
if (mErrorCode == ServerTerminated) {
|
|
1186 |
if (!mProxy->connect()) {
|
|
1187 |
if (mNotifierProxy) {
|
|
1188 |
mNotifierProxy->connectSessions();
|
|
1189 |
}
|
|
1190 |
mErrorCode = mProxy->removeData(entryIdList);
|
|
1191 |
}
|
|
1192 |
}
|
85
|
1193 |
|
|
1194 |
qDebug() << "CaServicePrivate::removeEntries mErrorCode:" << mErrorCode;
|
|
1195 |
|
87
|
1196 |
CACLIENTTEST_FUNC_EXIT("CaServicePrivate::removeEntries");
|
|
1197 |
|
85
|
1198 |
return (mErrorCode == NoErrorCode);
|
|
1199 |
}
|
|
1200 |
|
|
1201 |
/*!
|
|
1202 |
Insert entry into a given group.
|
|
1203 |
\param groupId groupId.
|
|
1204 |
\param entryIdList list of entries ids to insert.
|
|
1205 |
\param beforeEntryId id of an entry before which the given entry is inserted.
|
|
1206 |
\retval true if operation was successful.
|
|
1207 |
*/
|
|
1208 |
bool CaServicePrivate::insertEntriesIntoGroup(
|
|
1209 |
int groupId,
|
|
1210 |
const QList<int> &entryIdList,
|
|
1211 |
int beforeEntryId) // all others are convenience methods implemented in terms of this one
|
|
1212 |
{
|
|
1213 |
qDebug() << "CaServicePrivate::insertEntriesIntoGroup"
|
87
|
1214 |
<< "groupId: " << groupId << " beforeEntryId: " << beforeEntryId
|
|
1215 |
<< "entryIdList: " << entryIdList;
|
|
1216 |
|
|
1217 |
CACLIENTTEST_FUNC_ENTRY("CaServicePrivate::insertEntriesIntoGroup");
|
85
|
1218 |
|
93
|
1219 |
mErrorCode = mProxy->insertEntriesIntoGroup(groupId,
|
|
1220 |
entryIdList, beforeEntryId);
|
|
1221 |
if (mErrorCode == ServerTerminated) {
|
|
1222 |
if (!mProxy->connect()) {
|
|
1223 |
if (mNotifierProxy) {
|
|
1224 |
mNotifierProxy->connectSessions();
|
|
1225 |
}
|
|
1226 |
mErrorCode = mProxy->insertEntriesIntoGroup(groupId,
|
|
1227 |
entryIdList, beforeEntryId);
|
|
1228 |
}
|
|
1229 |
}
|
85
|
1230 |
qDebug() << "CaServicePrivate::insertEntriesIntoGroup mErrorCode:"
|
87
|
1231 |
<< mErrorCode;
|
|
1232 |
|
|
1233 |
CACLIENTTEST_FUNC_EXIT("CaServicePrivate::insertEntriesIntoGroup");
|
85
|
1234 |
|
|
1235 |
return (mErrorCode == NoErrorCode);
|
|
1236 |
}
|
|
1237 |
|
|
1238 |
/*!
|
|
1239 |
Remove entries from a given group.
|
|
1240 |
|
|
1241 |
\param groupId groupId.
|
|
1242 |
\param entryIDList list of entries ids to remove.
|
|
1243 |
\retval true if operation was successful.
|
|
1244 |
*/
|
|
1245 |
bool CaServicePrivate::removeEntriesFromGroup(
|
|
1246 |
int groupId,
|
|
1247 |
const QList<int> &entryIdList)
|
|
1248 |
{
|
|
1249 |
qDebug() << "CaServicePrivate::removeEntriesFromGroup"
|
87
|
1250 |
<< "groupId: " << groupId << "entryIdList" << entryIdList;
|
|
1251 |
|
|
1252 |
CACLIENTTEST_FUNC_ENTRY("CaServicePrivate::removeEntriesFromGroup");
|
85
|
1253 |
|
|
1254 |
mErrorCode = mProxy->removeEntriesFromGroup(groupId, entryIdList);
|
93
|
1255 |
if (mErrorCode == ServerTerminated) {
|
|
1256 |
if (!mProxy->connect()) {
|
|
1257 |
if (mNotifierProxy) {
|
|
1258 |
mNotifierProxy->connectSessions();
|
|
1259 |
}
|
|
1260 |
mErrorCode = mProxy->removeEntriesFromGroup(groupId, entryIdList);
|
|
1261 |
}
|
|
1262 |
}
|
85
|
1263 |
|
|
1264 |
qDebug() << "CaServicePrivate::removeEntriesFromGroup mErrorCode:"
|
87
|
1265 |
<< mErrorCode;
|
|
1266 |
|
|
1267 |
CACLIENTTEST_FUNC_EXIT("CaServicePrivate::removeEntriesFromGroup");
|
85
|
1268 |
|
|
1269 |
return (mErrorCode == NoErrorCode);
|
|
1270 |
}
|
|
1271 |
|
|
1272 |
/*!
|
|
1273 |
Place entries in a given group at the end.
|
|
1274 |
\param groupId groupId.
|
|
1275 |
\param entryIdList list of entries ids to prepend.
|
|
1276 |
\retval true if operation was successful.
|
|
1277 |
*/
|
|
1278 |
bool CaServicePrivate::appendEntriesToGroup(
|
|
1279 |
int groupId,
|
|
1280 |
const QList<int> &entryIdList)
|
|
1281 |
{
|
|
1282 |
qDebug() << "CaServicePrivate::appendEntriesToGroup"
|
87
|
1283 |
<< "groupId: " << groupId << "entryIdList: " << entryIdList;
|
|
1284 |
|
|
1285 |
CACLIENTTEST_FUNC_ENTRY("CaServicePrivate::appendEntriesToGroup");
|
85
|
1286 |
|
|
1287 |
const bool result = insertEntriesIntoGroup(
|
87
|
1288 |
groupId,
|
|
1289 |
entryIdList,
|
|
1290 |
CaClientProxy::AfterTheLastEntry);
|
85
|
1291 |
|
|
1292 |
qDebug() << "CaServicePrivate::appendEntriesToGroup result:"
|
87
|
1293 |
<< QString(result ? "true" : "false");
|
|
1294 |
|
|
1295 |
CACLIENTTEST_FUNC_EXIT("CaServicePrivate::appendEntriesToGroup");
|
85
|
1296 |
|
|
1297 |
return result;
|
|
1298 |
}
|
|
1299 |
|
|
1300 |
/*!
|
|
1301 |
Place entries in a given group at the begin.
|
|
1302 |
\param groupId groupId.
|
|
1303 |
\param entryIdList list of entries ids to prepend.
|
|
1304 |
\retval true if operation was successful.
|
|
1305 |
*/
|
|
1306 |
bool CaServicePrivate::prependEntriesToGroup(int groupId,
|
87
|
1307 |
const QList<int> &entryIdList)
|
85
|
1308 |
{
|
|
1309 |
qDebug() << "CaServicePrivate::prependEntriesToGroup"
|
87
|
1310 |
<< "groupId: " << groupId << "entryIdList: " << entryIdList;
|
|
1311 |
|
|
1312 |
CACLIENTTEST_FUNC_ENTRY("CaServicePrivate::prependEntriesToGroup");
|
85
|
1313 |
|
|
1314 |
const bool result =
|
87
|
1315 |
insertEntriesIntoGroup(
|
|
1316 |
groupId,
|
|
1317 |
entryIdList,
|
|
1318 |
CaClientProxy::BeforeTheFirstEntry);
|
85
|
1319 |
|
|
1320 |
qDebug() << "CaServicePrivate::prependEntriesToGroup result:"
|
87
|
1321 |
<< QString(result ? "PASS" : "FAIL");
|
|
1322 |
|
|
1323 |
CACLIENTTEST_FUNC_EXIT("CaServicePrivate::prependEntriesToGroup");
|
85
|
1324 |
|
|
1325 |
return result;
|
|
1326 |
}
|
|
1327 |
|
|
1328 |
/*!
|
|
1329 |
Executes command on entry (fe. "open", "remove")
|
|
1330 |
\param const reference to an entry on which command will be issued
|
|
1331 |
\param string containing a command
|
|
1332 |
\retval boolean which is used as an error code return value, true means positive result
|
|
1333 |
*/
|
|
1334 |
bool CaServicePrivate::executeCommand(const CaEntry &entry,
|
87
|
1335 |
const QString &command)
|
85
|
1336 |
{
|
|
1337 |
qDebug() << "CaServicePrivate::executeCommand"
|
87
|
1338 |
<< "entry id:" << entry.id() << "command:" << command;
|
|
1339 |
|
|
1340 |
CACLIENTTEST_FUNC_ENTRY("CaServicePrivate::executeCommand");
|
85
|
1341 |
|
98
|
1342 |
if (entry.flags() & UninstallEntryFlag) {
|
|
1343 |
return false;
|
|
1344 |
}
|
|
1345 |
|
87
|
1346 |
if (command == caCmdOpen) {
|
|
1347 |
touch(entry);
|
|
1348 |
}
|
85
|
1349 |
|
96
|
1350 |
mErrorCode = mCommandHandler->execute(entry, command);
|
85
|
1351 |
|
|
1352 |
qDebug() << "CaServicePrivate::executeCommand mErrorCode on return:"
|
87
|
1353 |
<< mErrorCode;
|
|
1354 |
|
|
1355 |
CACLIENTTEST_FUNC_EXIT("CaServicePrivate::executeCommand");
|
85
|
1356 |
|
|
1357 |
return (mErrorCode == NoErrorCode);
|
|
1358 |
}
|
|
1359 |
|
|
1360 |
/*!
|
|
1361 |
Creates new notifier. Factory class
|
|
1362 |
\param CaNotifierFilter which is used be new notifier
|
|
1363 |
\retval pointer to new Notifier
|
|
1364 |
*/
|
87
|
1365 |
CaNotifier *CaServicePrivate::createNotifier(const CaNotifierFilter &filter)
|
85
|
1366 |
{
|
93
|
1367 |
if (!mNotifierProxy) {
|
|
1368 |
mNotifierProxy = new CaClientNotifierProxy();
|
|
1369 |
}
|
|
1370 |
return new CaNotifier(new CaNotifierPrivate(filter, mNotifierProxy));
|
85
|
1371 |
}
|
|
1372 |
|
|
1373 |
/*!
|
|
1374 |
Set new order of collection's items set by user.
|
|
1375 |
\param groupId Group id.
|
|
1376 |
\param entryIdList consists of new order of items.
|
|
1377 |
\retval true if new order of collection's items is set correctly,
|
|
1378 |
otherwise return false.
|
|
1379 |
*/
|
|
1380 |
bool CaServicePrivate::customSort(int groupId, QList<int> &entryIdList)
|
|
1381 |
{
|
87
|
1382 |
CACLIENTTEST_FUNC_ENTRY("CaServicePrivate::customSort");
|
|
1383 |
|
85
|
1384 |
mErrorCode = mProxy->customSort(entryIdList, groupId);
|
93
|
1385 |
if (mErrorCode == ServerTerminated) {
|
|
1386 |
if (!mProxy->connect()) {
|
|
1387 |
if (mNotifierProxy) {
|
|
1388 |
mNotifierProxy->connectSessions();
|
|
1389 |
}
|
|
1390 |
mErrorCode = mProxy->customSort(entryIdList, groupId);
|
|
1391 |
}
|
|
1392 |
}
|
87
|
1393 |
CACLIENTTEST_FUNC_EXIT("CaServicePrivate::customSort");
|
|
1394 |
|
85
|
1395 |
return (mErrorCode == NoErrorCode);
|
|
1396 |
}
|
|
1397 |
|
|
1398 |
/*!
|
|
1399 |
Returns code of an error caused by the last executed operation.
|
|
1400 |
\retval code of error, zero means no error.
|
|
1401 |
*/
|
|
1402 |
ErrorCode CaServicePrivate::lastError() const
|
|
1403 |
{
|
|
1404 |
return mErrorCode;
|
|
1405 |
}
|