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: canotifierfilter.cpp
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "canotifierfilter.h"
|
|
19 |
#include "canotifierfilter_p.h"
|
|
20 |
#include "caquery.h"
|
|
21 |
|
|
22 |
/*!
|
93
|
23 |
\var CaNotifierFilterPrivate::m_q
|
|
24 |
Points to the CaNotifierFilter instance that uses
|
|
25 |
this private implementation.
|
|
26 |
*/
|
|
27 |
|
|
28 |
/*!
|
85
|
29 |
Constructor.
|
|
30 |
\param pointer to CaNotifierFilter - public notifier implementation class.
|
|
31 |
*/
|
|
32 |
CaNotifierFilterPrivate::CaNotifierFilterPrivate(
|
|
33 |
CaNotifierFilter *notifierfilterPublic) :
|
|
34 |
mParentId(0), m_q(notifierfilterPublic)
|
|
35 |
{
|
|
36 |
|
|
37 |
}
|
|
38 |
|
|
39 |
/*!
|
|
40 |
Copy assignment operator.
|
|
41 |
\param notifierFilterPrivate reference to CaNotifierFilterPrivate.
|
|
42 |
*/
|
|
43 |
|
|
44 |
CaNotifierFilterPrivate &CaNotifierFilterPrivate::operator=(
|
|
45 |
const CaNotifierFilterPrivate ¬ifierFilterPrivate)
|
|
46 |
{
|
|
47 |
/*m_q is not changed*/
|
|
48 |
mParentId = notifierFilterPrivate.mParentId;
|
|
49 |
mIds = notifierFilterPrivate.mIds;
|
|
50 |
mEntryRoles = notifierFilterPrivate.mEntryRoles;
|
|
51 |
mTypeNames = notifierFilterPrivate.mTypeNames;
|
|
52 |
return *this;
|
|
53 |
}
|
|
54 |
/*!
|
|
55 |
Destructor.
|
|
56 |
*/
|
|
57 |
CaNotifierFilterPrivate::~CaNotifierFilterPrivate()
|
|
58 |
{
|
|
59 |
}
|
|
60 |
/*!
|
|
61 |
Returns parent id.
|
|
62 |
\retval parent id.
|
|
63 |
*/
|
|
64 |
int CaNotifierFilterPrivate::getParentId() const
|
|
65 |
{
|
|
66 |
return mParentId;
|
|
67 |
}
|
|
68 |
|
|
69 |
/*!
|
|
70 |
Sets parent id.
|
|
71 |
\param parentId parent id.
|
|
72 |
*/
|
|
73 |
void CaNotifierFilterPrivate::setParentId(int parentId)
|
|
74 |
{
|
|
75 |
mParentId = parentId;
|
|
76 |
}
|
|
77 |
|
|
78 |
/*!
|
|
79 |
Returns a list of ids.
|
|
80 |
\retval list of ids.
|
|
81 |
*/
|
|
82 |
QList<int> CaNotifierFilterPrivate::getIds() const
|
|
83 |
{
|
|
84 |
return mIds;
|
|
85 |
}
|
|
86 |
|
|
87 |
/*!
|
|
88 |
Sets a list of ids.
|
|
89 |
\param ids reference to a list of ids.
|
|
90 |
*/
|
|
91 |
void CaNotifierFilterPrivate::setIds(const QList<int> &ids)
|
|
92 |
{
|
|
93 |
mIds = ids;
|
|
94 |
}
|
|
95 |
|
|
96 |
/*!
|
|
97 |
Returns entry role.
|
|
98 |
\retval entry role.
|
|
99 |
*/
|
|
100 |
EntryRoles CaNotifierFilterPrivate::getEntryRole() const
|
|
101 |
{
|
|
102 |
return mEntryRoles;
|
|
103 |
}
|
|
104 |
|
|
105 |
/*!
|
|
106 |
Sets an entry role.
|
|
107 |
\param entry role.
|
|
108 |
*/
|
|
109 |
void CaNotifierFilterPrivate::setEntryRole(EntryRoles entryRole)
|
|
110 |
{
|
|
111 |
mEntryRoles = entryRole;
|
|
112 |
}
|
|
113 |
|
|
114 |
/*!
|
|
115 |
Returns a list of type names.
|
|
116 |
\retval list of type names (strings).
|
|
117 |
*/
|
|
118 |
QStringList CaNotifierFilterPrivate::getTypeNames() const
|
|
119 |
{
|
|
120 |
return mTypeNames;
|
|
121 |
}
|
|
122 |
|
|
123 |
/*!
|
|
124 |
Sets a list of type names.
|
|
125 |
\retval list of type names (strings).
|
|
126 |
*/
|
|
127 |
void CaNotifierFilterPrivate::setTypeNames(const QStringList &typeNames)
|
|
128 |
{
|
|
129 |
mTypeNames = typeNames;
|
|
130 |
}
|
|
131 |
|
|
132 |
/*!
|
|
133 |
\class CaNotifierFilter.
|
|
134 |
\brief This class describes notifier filter.
|
|
135 |
|
|
136 |
\example
|
|
137 |
It's example how client can be notified about changes on data specified by client's filter
|
|
138 |
|
|
139 |
\code
|
|
140 |
// example Client class which wants to be notified about changes
|
|
141 |
class Client: public QObject
|
|
142 |
{
|
|
143 |
Q_OBJECT
|
|
144 |
...
|
|
145 |
public slots:
|
|
146 |
|
|
147 |
updateModelForEntryChanged(int,ChangeType);
|
|
148 |
...
|
|
149 |
};
|
|
150 |
\endcode
|
|
151 |
|
|
152 |
\code
|
|
153 |
// example code showed how to create notifier filter
|
|
154 |
// to specify interested data
|
|
155 |
|
|
156 |
// Client which will be wait for notifications
|
|
157 |
Client * client = new Client();
|
|
158 |
...
|
|
159 |
QSharedPointer<CaService> service = CaService::instance();
|
|
160 |
// create new entry
|
|
161 |
CaEntry entry;
|
|
162 |
entry.setText( "Text" );
|
|
163 |
entry.setTypeName( "TypeName" );
|
|
164 |
CaEntry * newEntry = service->createEntry( entry );
|
|
165 |
|
|
166 |
// create notifier filter and specify entry's id is interested by client
|
|
167 |
CaNotifierFilter notifierFilter();
|
|
168 |
QList<int> idsList;
|
|
169 |
idsList.append( newEntry->Id() );
|
|
170 |
notifierFilter.setIds( idsList );
|
|
171 |
// create notifier with prepared notifier filter
|
|
172 |
CaNotifier * notifier = service->createNotifier( notifierfilter );
|
|
173 |
|
|
174 |
// Connections cause that notifier is registered to server distributed
|
|
175 |
// notifications during data changes.
|
|
176 |
if( notifier )
|
|
177 |
{
|
|
178 |
connect( notifier, SIGNAL(entryChanged(int,ChangeType)),
|
|
179 |
client, SLOT(updateModelForEntryChanged(int,ChangeType)) );
|
|
180 |
...
|
|
181 |
}
|
|
182 |
|
|
183 |
// updating newEntry causes sent notification to the client
|
|
184 |
newEntry->setAttribute( "attrName", "attrValue" );
|
|
185 |
service->updateEntry( *newEntry );
|
|
186 |
...
|
|
187 |
\endcode
|
|
188 |
|
|
189 |
\code
|
|
190 |
\b Output:
|
|
191 |
|
|
192 |
// here client is being got notifications newEntry was updated
|
|
193 |
Client::updateModelForEntryChanged(int entryId ,ChangeType changeType)
|
|
194 |
{
|
|
195 |
entryId == newEntry->id();
|
|
196 |
changeType == UpdateChangeType;
|
|
197 |
...
|
|
198 |
}
|
|
199 |
|
|
200 |
\endcode
|
|
201 |
|
|
202 |
It's possible creating CaNotifierFilter object using CaQuery object.
|
|
203 |
|
|
204 |
\code
|
|
205 |
...
|
|
206 |
CaQuery query;
|
|
207 |
query.setEntryRoles( ItemEntryRole );
|
|
208 |
query.setEntryTypeNames( QStringList() << "Query1" << "TypeName");
|
|
209 |
CaNotifierFilter notifierFilter( query );
|
|
210 |
notifierFilter.setIds( QList<int>() << newEntry->id() );
|
|
211 |
// create notifier with prepared notifier filter
|
|
212 |
CaNotifier * notifier = service->createNotifier( notifierfilter );
|
|
213 |
...
|
|
214 |
\endcode
|
|
215 |
|
|
216 |
*/
|
|
217 |
|
|
218 |
/*!
|
|
219 |
Default constructor.
|
|
220 |
*/
|
|
221 |
CaNotifierFilter::CaNotifierFilter() :
|
|
222 |
m_d(new CaNotifierFilterPrivate(this))
|
|
223 |
{
|
|
224 |
}
|
|
225 |
/*!
|
|
226 |
Copy constructor.
|
|
227 |
\param notifierFilter pointer to CaNotifierFilter.
|
|
228 |
*/
|
|
229 |
CaNotifierFilter::CaNotifierFilter(const CaNotifierFilter ¬ifierFilter) :
|
|
230 |
m_d(new CaNotifierFilterPrivate(this))
|
|
231 |
{
|
|
232 |
*m_d = *(notifierFilter.m_d);
|
|
233 |
}
|
|
234 |
|
|
235 |
/*!
|
|
236 |
Constructor. It constructs notifier filter of query.
|
|
237 |
\param query query.
|
|
238 |
*/
|
|
239 |
CaNotifierFilter::CaNotifierFilter(const CaQuery &query) :
|
|
240 |
m_d(new CaNotifierFilterPrivate(this))
|
|
241 |
{
|
|
242 |
m_d->setParentId(query.parentId());
|
|
243 |
m_d->setEntryRole(query.entryRoles());
|
|
244 |
m_d->setTypeNames(query.entryTypeNames());
|
|
245 |
}
|
|
246 |
|
|
247 |
/*!
|
|
248 |
Copy assignment operator.
|
|
249 |
\param notifierFilter const reference to CaNotifierFilter.
|
|
250 |
\retval reference to CaNotifierFilter.
|
|
251 |
*/
|
|
252 |
CaNotifierFilter &CaNotifierFilter::operator=(
|
|
253 |
const CaNotifierFilter ¬ifierFilter)
|
|
254 |
{
|
|
255 |
if (this != ¬ifierFilter) {
|
|
256 |
*m_d = *(notifierFilter.m_d);
|
|
257 |
}
|
|
258 |
return *this;
|
|
259 |
}
|
|
260 |
|
|
261 |
/*!
|
|
262 |
Destructor.
|
|
263 |
*/
|
|
264 |
CaNotifierFilter::~CaNotifierFilter()
|
|
265 |
{
|
|
266 |
delete m_d;
|
|
267 |
}
|
|
268 |
|
|
269 |
/*!
|
|
270 |
Returns parent id.
|
|
271 |
\retval parent id.
|
|
272 |
*/
|
|
273 |
int CaNotifierFilter::getParentId() const
|
|
274 |
{
|
|
275 |
return m_d->getParentId();
|
|
276 |
}
|
|
277 |
|
|
278 |
/*!
|
|
279 |
Sets parent id.
|
|
280 |
\param parent id.
|
|
281 |
*/
|
|
282 |
void CaNotifierFilter::setParentId(int parentId)
|
|
283 |
{
|
|
284 |
m_d->setParentId(parentId);
|
|
285 |
}
|
|
286 |
|
|
287 |
/*!
|
|
288 |
Returns a list of ids.
|
|
289 |
\retval list of ids.
|
|
290 |
*/
|
|
291 |
QList<int> CaNotifierFilter::getIds() const
|
|
292 |
{
|
|
293 |
return m_d->getIds();
|
|
294 |
}
|
|
295 |
|
|
296 |
/*!
|
|
297 |
Sets a list of ids.
|
|
298 |
\param list of ids.
|
|
299 |
*/
|
|
300 |
void CaNotifierFilter::setIds(const QList<int> &ids)
|
|
301 |
{
|
|
302 |
m_d->setIds(ids);
|
|
303 |
}
|
|
304 |
|
|
305 |
/*!
|
|
306 |
Returns entry role.
|
|
307 |
\retval entry role.
|
|
308 |
*/
|
|
309 |
EntryRoles CaNotifierFilter::getEntryRole() const
|
|
310 |
{
|
|
311 |
return m_d->getEntryRole();
|
|
312 |
}
|
|
313 |
|
|
314 |
/*!
|
|
315 |
Sets entry role.
|
|
316 |
\param entry role to be set.
|
|
317 |
*/
|
|
318 |
void CaNotifierFilter::setEntryRole(EntryRoles entryRole)
|
|
319 |
{
|
|
320 |
m_d->setEntryRole(entryRole);
|
|
321 |
}
|
|
322 |
|
|
323 |
/*!
|
|
324 |
Returns a list of type names.
|
|
325 |
\retval list of type names (strings).
|
|
326 |
*/
|
|
327 |
QStringList CaNotifierFilter::getTypeNames() const
|
|
328 |
{
|
|
329 |
return m_d->getTypeNames();
|
|
330 |
}
|
|
331 |
|
|
332 |
/*!
|
|
333 |
Sets a list of type names.
|
|
334 |
\param reference to a list of type names.
|
|
335 |
*/
|
|
336 |
void CaNotifierFilter::setTypeNames(const QStringList &typeNames)
|
|
337 |
{
|
|
338 |
m_d->setTypeNames(typeNames);
|
|
339 |
}
|