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 <cadefs.h> |
|
29 |
|
30 #include "hsapp_defs.h" |
|
31 #include "t_hsmenuclientplugin.h" |
|
32 #include "hsmenuclient.h" |
|
33 |
|
34 |
|
35 // ======== MEMBER FUNCTIONS ======== |
|
36 |
|
37 /*! |
|
38 |
|
39 \class CaService. |
|
40 \brief This class operates on data, anable creating and inserting new entry |
|
41 to DB, removing entry from DB, update entry or get entry from DB, executeC |
|
42 command on entry and create notifier to notify client about changes onto DB. |
|
43 |
|
44 CaService class uses singleton design pattern, so that it contains static |
|
45 method called instance() to get instance of a class. |
|
46 |
|
47 \code |
|
48 QSharedPointer<CaService> service = CaService::instance(); |
|
49 \endcode |
|
50 |
|
51 For every operations on data is used always one instantiation of a class. |
|
52 Below are examples how to create data and work on those ones. |
|
53 |
|
54 */ |
|
55 |
|
56 // Initialization of a static member variable. |
|
57 //QWeakPointer<CaService> CaService::m_instance = QWeakPointer<CaService>(); |
|
58 |
|
59 /*! |
|
60 Constructor. |
|
61 \param parent pointer to a parent. It defaults to NULL. |
|
62 */ |
|
63 CaService::CaService(QObject *parent) : |
|
64 QObject(parent), m_d(&CaServicePrivate::instance()) |
|
65 { |
|
66 |
|
67 } |
|
68 |
|
69 /*! |
|
70 Returns a pointer to the instance of the CaService class. |
|
71 \retval A pointer to the instance of the CaService class. |
|
72 */ |
|
73 QSharedPointer<CaService> CaService::instance() |
|
74 { |
|
75 static QSharedPointer<CaService> instance (new CaService); |
|
76 return instance; |
|
77 } |
|
78 |
|
79 /*! |
|
80 Destructor. |
|
81 */ |
|
82 CaService::~CaService() |
|
83 { |
|
84 |
|
85 } |
|
86 |
|
87 // HELP METHODS |
|
88 |
|
89 void CaServicePrivate::clearAll() |
|
90 { |
|
91 mEntryToRemove = -1; |
|
92 |
|
93 mUpdatedEntry.clear(); |
|
94 |
|
95 delete mQueryPassedToGetList; |
|
96 mQueryPassedToGetList = NULL; |
|
97 |
|
98 mCreatedEntries.clear(); |
|
99 mReturnedEntries.clear(); |
|
100 } |
|
101 |
|
102 void CaServicePrivate::AddEntriesForUpdate() |
|
103 { |
|
104 QSharedPointer<CaEntry> item0 (new CaEntry()); |
|
105 |
|
106 // this will be updated: |
|
107 QSharedPointer<CaEntry> item1 (new CaEntry()); |
|
108 item1->setText("ModuleTestTApp"); |
|
109 item1->setDescription("Unit test app for HsClientPlugin"); |
|
110 |
|
111 item1->setAttribute(hsitemLaunchUri, "appto://2002DCEC?"); |
|
112 item1->setAttribute(hsitemPublisherId, "tappModuleTest"); |
|
113 item1->setAttribute(hsitemLaunchUri, "hsclockwidgetplugin"); |
|
114 |
|
115 item1->setEntryTypeName(Hs::templatedApplicationTypeName); |
|
116 item1->setFlags(VisibleEntryFlag); |
|
117 |
|
118 CaIconDescription iconDescription1; |
|
119 iconDescription1.setFilename("iconFileName"); |
|
120 iconDescription1.setSkinId("iconSkinId"); |
|
121 iconDescription1.setApplicationId("268458321"); //Bluetouth app UID |
|
122 item1->setIconDescription(iconDescription1); |
|
123 |
|
124 mCreatedEntries << item0; |
|
125 mCreatedEntries << item1; |
|
126 } |
|
127 QSharedPointer<CaEntry> CaService::getEntry(int entryId) const |
|
128 { |
|
129 return m_d->mCreatedEntries.at(entryId); |
|
130 } |
|
131 |
|
132 |
|
133 bool CaService::updateEntry(const CaEntry &entry) const |
|
134 { |
|
135 m_d->mUpdatedEntry.clear(); |
|
136 m_d->mUpdatedEntry = QSharedPointer<CaEntry>(new CaEntry(entry)); |
|
137 return true; |
|
138 } |
|
139 |
|
140 QSharedPointer<CaEntry> CaService::createEntry(const CaEntry &entry) const |
|
141 { |
|
142 QSharedPointer<CaEntry> newEntry(new CaEntry(entry)); |
|
143 m_d->mCreatedEntries << newEntry; |
|
144 return newEntry; |
|
145 } |
|
146 |
|
147 |
|
148 bool CaService::removeEntry(int entryId) const |
|
149 { |
|
150 m_d->mEntryToRemove = entryId; |
|
151 |
|
152 return true; |
|
153 } |
|
154 |
|
155 |
|
156 QList< QSharedPointer<CaEntry> > CaService::getEntries( |
|
157 const QList<int> &entryIdList) const |
|
158 { |
|
159 Q_UNUSED(entryIdList); |
|
160 QList< QSharedPointer<CaEntry> > result; |
|
161 return result; |
|
162 |
|
163 } |
|
164 |
|
165 QList< QSharedPointer<CaEntry> > CaService::getEntries(const CaQuery &query) const |
|
166 { |
|
167 // store the query for verification |
|
168 m_d->mQueryPassedToGetList = new CaQuery (query); |
|
169 |
|
170 // return mock list of 2 entires |
|
171 QSharedPointer<CaEntry> item1 (new CaEntry()); |
|
172 item1->setText("ModuleTestTApp1"); |
|
173 item1->setDescription("Unit test app for HsClientPlugin1"); |
|
174 item1->setAttribute(hsitemLaunchUri, "appto://1002DCEC?"); |
|
175 item1->setAttribute(hsitemPublisherId, "tappModuleTest1"); |
|
176 item1->setAttribute(hsitemLaunchUri, "hsclockwidgetplugin1"); |
|
177 item1->setEntryTypeName(Hs::templatedApplicationTypeName); |
|
178 item1->setFlags(VisibleEntryFlag); |
|
179 CaIconDescription iconDescription1; |
|
180 iconDescription1.setFilename("iconFileName1"); |
|
181 iconDescription1.setSkinId("iconSkinId1"); |
|
182 iconDescription1.setApplicationId("168458321"); |
|
183 item1->setIconDescription(iconDescription1); |
|
184 |
|
185 QSharedPointer<CaEntry> item2 (new CaEntry()); |
|
186 item2->setText("ModuleTestTApp2"); |
|
187 item2->setDescription("Unit test app for HsClientPlugin2"); |
|
188 item2->setAttribute(hsitemLaunchUri, "appto://2002DCEC?"); |
|
189 item2->setAttribute(hsitemPublisherId, "tappModuleTest2"); |
|
190 item2->setAttribute(hsitemLaunchUri, "hsclockwidgetplugin2"); |
|
191 item2->setEntryTypeName(Hs::templatedApplicationTypeName); |
|
192 item2->setFlags(VisibleEntryFlag); |
|
193 CaIconDescription iconDescription2; |
|
194 iconDescription2.setFilename("iconFileName2"); |
|
195 iconDescription2.setSkinId("iconSkinId2"); |
|
196 iconDescription2.setApplicationId("268458321"); |
|
197 item2->setIconDescription(iconDescription2); |
|
198 |
|
199 // store items for verification |
|
200 m_d->mReturnedEntries << item1 << item2; |
|
201 |
|
202 // return copies to caller |
|
203 QList< QSharedPointer<CaEntry> > resultList; |
|
204 resultList << item1; |
|
205 resultList << item2; |
|
206 |
|
207 return resultList; |
|
208 } |
|
209 |
|
210 QList<int> CaService::getEntryIds(const CaQuery &query) const |
|
211 { |
|
212 Q_UNUSED(query); |
|
213 QList<int> result; |
|
214 return result; |
|
215 |
|
216 } |
|
217 |
|
218 |
|
219 |
|
220 bool CaService::removeEntry(const CaEntry &entry) const |
|
221 { |
|
222 return removeEntry(entry.id()); |
|
223 } |
|
224 |
|
225 |
|
226 bool CaService::removeEntries(const QList<int> &entryIdList) const |
|
227 { |
|
228 Q_UNUSED(entryIdList); |
|
229 return true; |
|
230 } |
|
231 |
|
232 |
|
233 bool CaService::removeEntries( |
|
234 const QList< QSharedPointer<CaEntry> > &entryList) const |
|
235 { |
|
236 Q_UNUSED(entryList); |
|
237 return true; |
|
238 } |
|
239 |
|
240 bool CaService::touch(const CaEntry &entry) const |
|
241 { |
|
242 Q_UNUSED(entry); |
|
243 return true; |
|
244 } |
|
245 |
|
246 |
|
247 bool CaService::insertEntryIntoGroup(int groupId, int entryId, |
|
248 int beforeEntryId) const |
|
249 { |
|
250 Q_UNUSED(groupId); |
|
251 Q_UNUSED(entryId); |
|
252 Q_UNUSED(beforeEntryId); |
|
253 return true; |
|
254 } |
|
255 |
|
256 |
|
257 bool CaService::insertEntryIntoGroup( |
|
258 const CaEntry &group, const CaEntry &entry, int beforeEntryId) const |
|
259 { |
|
260 Q_UNUSED(group); |
|
261 Q_UNUSED(entry); |
|
262 Q_UNUSED(beforeEntryId); |
|
263 return true; |
|
264 } |
|
265 |
|
266 |
|
267 bool CaService::insertEntriesIntoGroup(int groupId, |
|
268 const QList<int> &entryIdList, int beforeEntryId) const |
|
269 { |
|
270 Q_UNUSED(groupId); |
|
271 Q_UNUSED(entryIdList); |
|
272 Q_UNUSED(beforeEntryId); |
|
273 return true; |
|
274 } |
|
275 |
|
276 |
|
277 bool CaService::insertEntriesIntoGroup(const CaEntry &group, |
|
278 const QList< QSharedPointer<CaEntry> > &entryList, |
|
279 int beforeEntryId) const |
|
280 { |
|
281 Q_UNUSED(group); |
|
282 Q_UNUSED(entryList); |
|
283 Q_UNUSED(beforeEntryId); |
|
284 return true; |
|
285 } |
|
286 |
|
287 |
|
288 bool CaService::removeEntryFromGroup(int groupId, int entryId) const |
|
289 { |
|
290 Q_UNUSED(groupId); |
|
291 Q_UNUSED(entryId); |
|
292 return true; |
|
293 } |
|
294 |
|
295 |
|
296 bool CaService::removeEntryFromGroup(const CaEntry &group, |
|
297 const CaEntry &entry) const |
|
298 { |
|
299 Q_UNUSED(group); |
|
300 Q_UNUSED(entry); |
|
301 return true; |
|
302 } |
|
303 |
|
304 |
|
305 bool CaService::removeEntriesFromGroup(int groupId, |
|
306 const QList<int> &entryIdList) const |
|
307 { |
|
308 Q_UNUSED(groupId); |
|
309 Q_UNUSED(entryIdList); |
|
310 return true; |
|
311 } |
|
312 |
|
313 |
|
314 bool CaService::removeEntriesFromGroup(const CaEntry &group, |
|
315 const QList< QSharedPointer<CaEntry> > &entryList) const |
|
316 { |
|
317 Q_UNUSED(group); |
|
318 Q_UNUSED(entryList); |
|
319 return true; |
|
320 } |
|
321 |
|
322 |
|
323 bool CaService::appendEntryToGroup(int groupId, int entryId) const |
|
324 { |
|
325 Q_UNUSED(groupId); |
|
326 Q_UNUSED(entryId); |
|
327 return true; |
|
328 } |
|
329 |
|
330 |
|
331 bool CaService::appendEntryToGroup(const CaEntry &group, |
|
332 const CaEntry &entry) const |
|
333 { |
|
334 Q_UNUSED(group); |
|
335 Q_UNUSED(entry); |
|
336 return true; |
|
337 } |
|
338 |
|
339 |
|
340 bool CaService::appendEntriesToGroup(int groupId, |
|
341 const QList<int> &entryIdList) const |
|
342 { |
|
343 Q_UNUSED(groupId); |
|
344 Q_UNUSED(entryIdList); |
|
345 return true; |
|
346 } |
|
347 |
|
348 |
|
349 bool CaService::appendEntriesToGroup(const CaEntry &group, |
|
350 const QList< QSharedPointer<CaEntry> > &entryList) const |
|
351 { |
|
352 Q_UNUSED(group); |
|
353 Q_UNUSED(entryList); |
|
354 return true; |
|
355 } |
|
356 |
|
357 |
|
358 bool CaService::prependEntryToGroup(int groupId, int entryId) const |
|
359 { |
|
360 Q_UNUSED(groupId); |
|
361 Q_UNUSED(entryId); |
|
362 return true; |
|
363 } |
|
364 |
|
365 |
|
366 bool CaService::prependEntryToGroup(const CaEntry &group, |
|
367 const CaEntry &entry) const |
|
368 { |
|
369 Q_UNUSED(group); |
|
370 Q_UNUSED(entry); |
|
371 return true; |
|
372 } |
|
373 |
|
374 bool CaService::prependEntriesToGroup(int groupId, |
|
375 const QList<int> &entryIdList) const |
|
376 { |
|
377 Q_UNUSED(groupId); |
|
378 Q_UNUSED(entryIdList); |
|
379 return true; |
|
380 } |
|
381 |
|
382 bool CaService::prependEntriesToGroup(const CaEntry &group, |
|
383 const QList< QSharedPointer<CaEntry> > &entryList) const |
|
384 { |
|
385 Q_UNUSED(group); |
|
386 Q_UNUSED(entryList); |
|
387 return true; |
|
388 } |
|
389 |
|
390 int CaService::executeCommand(int entryId, const QString &command, |
|
391 QObject* receiver, const char* member) const |
|
392 { |
|
393 Q_UNUSED(entryId); |
|
394 Q_UNUSED(command); |
|
395 Q_UNUSED(receiver); |
|
396 Q_UNUSED(member); |
|
397 return 0; |
|
398 } |
|
399 |
|
400 int CaService::executeCommand(const CaEntry &entry, const QString &command, |
|
401 QObject* receiver, const char* member) const |
|
402 { |
|
403 Q_UNUSED(entry); |
|
404 Q_UNUSED(command); |
|
405 Q_UNUSED(receiver); |
|
406 Q_UNUSED(member); |
|
407 return 0; |
|
408 } |
|
409 |
|
410 CaNotifier *CaService::createNotifier(const CaNotifierFilter &filter) const |
|
411 { |
|
412 Q_UNUSED(filter); |
|
413 return NULL; |
|
414 } |
|
415 |
|
416 |
|
417 bool CaService::customSort(int groupId, QList<int> &entryIdList) const |
|
418 { |
|
419 Q_UNUSED(entryIdList); |
|
420 return true; |
|
421 } |
|
422 |
|
423 ErrorCode CaService::lastError() const |
|
424 { |
|
425 return NoErrorCode; |
|
426 } |
|