90
|
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.h
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#ifndef CASERVICE_H
|
|
19 |
#define CASERVICE_H
|
|
20 |
|
|
21 |
#include <QObject>
|
|
22 |
#include <QSharedPointer>
|
|
23 |
#include <QMetaType>
|
|
24 |
#include <QCoreApplication>
|
|
25 |
#include <QString>
|
|
26 |
#include <QDebug>
|
|
27 |
|
|
28 |
#include "caservice.h"
|
|
29 |
#include "caquery.h"
|
|
30 |
#include "caentry.h"
|
|
31 |
#include "canotifier.h"
|
|
32 |
#include "canotifierfilter.h"
|
|
33 |
#include "cadefs.h"
|
|
34 |
|
|
35 |
typedef QList< QSharedPointer<CaEntry> > CaEntryList;
|
|
36 |
|
|
37 |
// mocks Content Storage's CaService
|
|
38 |
class CaService: public QObject
|
|
39 |
{
|
|
40 |
Q_OBJECT
|
|
41 |
|
|
42 |
explicit CaService(QObject *parent = 0);
|
|
43 |
|
|
44 |
~CaService();
|
|
45 |
public:
|
|
46 |
|
|
47 |
|
|
48 |
static QSharedPointer<CaService> instance();
|
|
49 |
|
|
50 |
// mock only those methods of original CaService that are used in the module
|
|
51 |
QSharedPointer<CaEntry> getEntry(int entryId) const;
|
|
52 |
QList< QSharedPointer<CaEntry> > getEntries(const CaQuery &query) const;
|
|
53 |
QList<int> getEntryIds(const CaQuery &query) const;
|
|
54 |
|
|
55 |
QSharedPointer<CaEntry> createEntry(const CaEntry &entry) const;
|
|
56 |
|
|
57 |
bool removeEntry(int entryId) const;
|
|
58 |
bool updateEntry(const CaEntry &entry) const;
|
|
59 |
bool touch(const CaEntry &entry) const;
|
|
60 |
bool removeEntryFromGroup(int groupId, int entryId) const;
|
|
61 |
bool appendEntryToGroup(int groupId, int entryId) const;
|
|
62 |
bool appendEntriesToGroup(int groupId,
|
|
63 |
const QList<int> &entryIdList) const;
|
|
64 |
|
|
65 |
int executeCommand(int entryId, const QString &command =
|
|
66 |
caCmdOpen, QObject* receiver = NULL, const char* member = NULL) const;
|
|
67 |
int executeCommand(const CaEntry &entry, const QString &command =
|
|
68 |
caCmdOpen, QObject* receiver = NULL, const char* member = NULL) const;
|
|
69 |
|
|
70 |
|
|
71 |
bool customSort(int groupId, QList<int> &entryIdList) const;
|
|
72 |
|
|
73 |
CaNotifier * createNotifier(const CaNotifierFilter &filter) const;
|
|
74 |
|
|
75 |
mutable int mGetEntryId;
|
|
76 |
mutable QSharedPointer<CaEntry> mGetEntryResult;
|
|
77 |
mutable CaQuery mGetEntriesQuery;
|
|
78 |
mutable QList< QSharedPointer<CaEntry> > mGetEntriesResult;
|
|
79 |
mutable CaQuery mGetEntryIdQuery;
|
|
80 |
mutable QList<int> mGetEntryIdsResult;
|
|
81 |
mutable CaEntry mCreatedEntry;
|
|
82 |
mutable QSharedPointer<CaEntry>mCreateEntryResult;
|
|
83 |
|
|
84 |
mutable int mRemoveEntryId;
|
|
85 |
mutable bool mRemoveEntryForIdResult;
|
|
86 |
|
|
87 |
mutable CaEntry mUpdateEntry;
|
|
88 |
mutable bool mUpdateEntryResult;
|
|
89 |
|
|
90 |
mutable CaEntry mTouchEntry;
|
|
91 |
mutable QList<int> mTouchEntriesId;
|
|
92 |
mutable bool mTouchResult;
|
|
93 |
|
|
94 |
mutable int mRemoveGroupId;
|
|
95 |
mutable int mRemoveEntryFromGroupId;
|
|
96 |
mutable bool mRemoveEntryFromGroupResult;
|
|
97 |
|
|
98 |
mutable int mAppendGroupId;
|
|
99 |
mutable int mAppenEntryId;
|
|
100 |
mutable bool mAppendEntryToGroupResult;
|
|
101 |
|
|
102 |
mutable int mAppendListGroupId;
|
|
103 |
mutable QList<int> mAppendEntryIdList;
|
|
104 |
mutable bool mAppendEntriesToGroupResult;
|
|
105 |
|
|
106 |
mutable int mExecuteEntryId;
|
|
107 |
mutable QString mExecuteCommand;
|
|
108 |
mutable int mExecuteCommandResult;
|
|
109 |
|
|
110 |
mutable CaEntry mExecuteEntry;
|
|
111 |
|
|
112 |
mutable int mCustomSortGroupId;
|
|
113 |
mutable QList<int> mCustomSortEntryIdList;
|
|
114 |
mutable bool mCustomSortResult;
|
|
115 |
|
|
116 |
mutable CaNotifierFilter mCreateNotifierFilter;
|
|
117 |
mutable CaNotifier *mCreateNotifierResult;
|
|
118 |
|
|
119 |
// helper for tests, not belonging to CaService
|
|
120 |
void clear()
|
|
121 |
{
|
|
122 |
mGetEntryId = 0;
|
|
123 |
mGetEntryResult.clear();
|
|
124 |
mGetEntriesQuery.clear();
|
|
125 |
mGetEntriesResult.clear();
|
|
126 |
mGetEntryIdQuery.clear();
|
|
127 |
mGetEntryIdsResult.clear();
|
|
128 |
mCreatedEntry.clear();
|
|
129 |
mCreateEntryResult.clear();
|
|
130 |
mRemoveEntryId = 0;
|
|
131 |
mRemoveEntryForIdResult = false;
|
|
132 |
|
|
133 |
mUpdateEntry.clear();
|
|
134 |
mUpdateEntryResult = false;
|
|
135 |
|
|
136 |
mTouchEntry.clear();
|
|
137 |
mTouchEntriesId.clear();
|
|
138 |
mTouchResult = false;
|
|
139 |
|
|
140 |
mRemoveGroupId = 0;
|
|
141 |
mRemoveEntryFromGroupId = 0;
|
|
142 |
mRemoveEntryFromGroupResult = false;
|
|
143 |
|
|
144 |
mAppendGroupId = 0;
|
|
145 |
mAppenEntryId = 0;
|
|
146 |
mAppendEntryToGroupResult = false;
|
|
147 |
|
|
148 |
mAppendListGroupId = 0;
|
|
149 |
mAppendEntryIdList.clear();
|
|
150 |
mAppendEntriesToGroupResult = false;
|
|
151 |
|
|
152 |
mExecuteEntryId = 0;
|
|
153 |
mExecuteCommand.clear();
|
|
154 |
mExecuteCommandResult = -333;
|
|
155 |
|
|
156 |
mCustomSortGroupId = 0;
|
|
157 |
mCustomSortEntryIdList.clear();
|
|
158 |
mCustomSortResult = false;
|
|
159 |
|
|
160 |
mCreateNotifierFilter = CaNotifierFilter();
|
|
161 |
mCreateNotifierResult = 0;
|
|
162 |
}
|
|
163 |
private:
|
|
164 |
Q_DISABLE_COPY(CaService)
|
|
165 |
friend class QtSharedPointer::ExternalRefCount<CaService>;
|
|
166 |
};
|
|
167 |
|
|
168 |
inline CaService::CaService(QObject *parent) :
|
|
169 |
QObject(parent),
|
|
170 |
mGetEntryId(0),
|
|
171 |
mRemoveEntryId(0),
|
|
172 |
mRemoveEntryForIdResult(false),
|
|
173 |
mUpdateEntryResult(false),
|
|
174 |
mTouchResult(false),
|
|
175 |
mRemoveGroupId(0),
|
|
176 |
mRemoveEntryFromGroupId(0),
|
|
177 |
mRemoveEntryFromGroupResult(false),
|
|
178 |
mAppendGroupId(0),
|
|
179 |
mAppenEntryId(0),
|
|
180 |
mAppendEntryToGroupResult(false),
|
|
181 |
mAppendListGroupId(0),
|
|
182 |
mAppendEntriesToGroupResult(false),
|
|
183 |
mExecuteEntryId(0),
|
|
184 |
mExecuteCommandResult(false),
|
|
185 |
mCustomSortGroupId(0),
|
|
186 |
mCustomSortResult(false),
|
|
187 |
mCreateNotifierResult(0)
|
|
188 |
{
|
|
189 |
}
|
|
190 |
|
|
191 |
inline QSharedPointer<CaService> CaService::instance()
|
|
192 |
{
|
|
193 |
static QSharedPointer<CaService> service(new CaService);
|
|
194 |
return service;
|
|
195 |
}
|
|
196 |
|
|
197 |
inline CaService::~CaService()
|
|
198 |
{
|
|
199 |
}
|
|
200 |
|
|
201 |
inline QSharedPointer<CaEntry> CaService::getEntry(int entryId) const
|
|
202 |
{
|
|
203 |
mGetEntryId = entryId;
|
|
204 |
if (!mGetEntryResult.isNull()) {
|
|
205 |
mGetEntryResult->mIdResult = entryId;
|
|
206 |
}
|
|
207 |
return mGetEntryResult;
|
|
208 |
}
|
|
209 |
|
|
210 |
|
|
211 |
inline QList< QSharedPointer<CaEntry> > CaService::getEntries(const CaQuery &query) const
|
|
212 |
{
|
|
213 |
mGetEntriesQuery = query;
|
|
214 |
return mGetEntriesResult;
|
|
215 |
}
|
|
216 |
|
|
217 |
inline QList<int> CaService::getEntryIds(const CaQuery &query) const
|
|
218 |
{
|
|
219 |
mGetEntryIdQuery = query;
|
|
220 |
return mGetEntryIdsResult;
|
|
221 |
}
|
|
222 |
|
|
223 |
inline QSharedPointer<CaEntry> CaService::createEntry(const CaEntry &entry) const
|
|
224 |
{
|
|
225 |
mCreatedEntry = entry;
|
|
226 |
return mCreateEntryResult;
|
|
227 |
}
|
|
228 |
|
|
229 |
inline bool CaService::removeEntry(int entryId) const
|
|
230 |
{
|
|
231 |
mRemoveEntryId = entryId;
|
|
232 |
return mRemoveEntryForIdResult;
|
|
233 |
}
|
|
234 |
|
|
235 |
|
|
236 |
inline bool CaService::updateEntry(const CaEntry &entry) const
|
|
237 |
{
|
|
238 |
mUpdateEntry = entry;
|
|
239 |
return mUpdateEntryResult;
|
|
240 |
}
|
|
241 |
|
|
242 |
inline bool CaService::touch(const CaEntry &entry) const
|
|
243 |
{
|
|
244 |
if (entry.flags() & RemovableEntryFlag &&
|
|
245 |
(entry.flags() & UsedEntryFlag) == 0 &&
|
|
246 |
entry.role() == ItemEntryRole &&
|
|
247 |
entry.entryTypeName() != QString("package")) { //packageTypeName
|
|
248 |
mTouchEntry = entry;
|
|
249 |
mTouchEntriesId.append(entry.id());
|
|
250 |
return mTouchResult;
|
|
251 |
} else {
|
|
252 |
return true;
|
|
253 |
}
|
|
254 |
}
|
|
255 |
|
|
256 |
inline bool CaService::removeEntryFromGroup(int groupId, int entryId) const
|
|
257 |
{
|
|
258 |
mRemoveGroupId = groupId;
|
|
259 |
mRemoveEntryFromGroupId = entryId;
|
|
260 |
return mRemoveEntryFromGroupResult;
|
|
261 |
}
|
|
262 |
|
|
263 |
inline bool CaService::appendEntryToGroup(int groupId, int entryId) const
|
|
264 |
{
|
|
265 |
mAppendGroupId = groupId;
|
|
266 |
mAppenEntryId = entryId;
|
|
267 |
return mAppendEntryToGroupResult;
|
|
268 |
}
|
|
269 |
|
|
270 |
inline bool CaService::appendEntriesToGroup(int groupId,
|
|
271 |
const QList<int> &entryIdList) const
|
|
272 |
{
|
|
273 |
mAppendListGroupId = groupId;
|
|
274 |
mAppendEntryIdList = entryIdList;
|
|
275 |
return mAppendEntriesToGroupResult;
|
|
276 |
}
|
|
277 |
|
|
278 |
inline int CaService::executeCommand(int entryId, const QString &command,
|
|
279 |
QObject* receiver, const char* member) const
|
|
280 |
{
|
|
281 |
Q_UNUSED(receiver);
|
|
282 |
Q_UNUSED(member);
|
|
283 |
mExecuteEntryId = entryId;
|
|
284 |
mExecuteCommand = command;
|
|
285 |
return mExecuteCommandResult;
|
|
286 |
}
|
|
287 |
|
|
288 |
inline int CaService::executeCommand(const CaEntry &entry, const QString &command,
|
|
289 |
QObject* receiver, const char* member) const
|
|
290 |
{
|
|
291 |
Q_UNUSED(receiver);
|
|
292 |
Q_UNUSED(member);
|
|
293 |
mExecuteEntry = entry;
|
|
294 |
mExecuteCommand = command;
|
|
295 |
return mExecuteCommandResult;
|
|
296 |
}
|
|
297 |
|
|
298 |
inline bool CaService::customSort(int groupId, QList<int> &entryIdList) const
|
|
299 |
{
|
|
300 |
mCustomSortGroupId = groupId;
|
|
301 |
mCustomSortEntryIdList = entryIdList;
|
|
302 |
return mCustomSortResult;
|
|
303 |
}
|
|
304 |
|
|
305 |
inline CaNotifier * CaService::createNotifier(const CaNotifierFilter &filter) const
|
|
306 |
{
|
|
307 |
mCreateNotifierFilter = filter;
|
|
308 |
return mCreateNotifierResult;
|
|
309 |
}
|
|
310 |
|
|
311 |
|
|
312 |
#endif // CASERVICE_H
|