|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 |
|
43 #include "qcontactchangeset.h" |
|
44 #include "qcontactchangeset_p.h" |
|
45 #include "qcontactmanagerengine.h" |
|
46 |
|
47 QTM_BEGIN_NAMESPACE |
|
48 |
|
49 /*! |
|
50 \class QContactChangeSet |
|
51 |
|
52 \brief The QContactChangeSet class provides a simple API to |
|
53 simplify the emission of state-change signals from |
|
54 QContactManagerEngine implementations. |
|
55 |
|
56 This class can be utilised by backend implementations to ensure |
|
57 correct emission of the \l QContactManagerEngine::dataChanged(), \l |
|
58 QContactManagerEngine::contactsAdded(), \l |
|
59 QContactManagerEngine::contactsChanged() and \l |
|
60 QContactManagerEngine::contactsRemoved(). |
|
61 |
|
62 \sa QContactManagerEngine |
|
63 */ |
|
64 |
|
65 /*! |
|
66 Constructs a new change set |
|
67 */ |
|
68 QContactChangeSet::QContactChangeSet() |
|
69 : d(new QContactChangeSetData) |
|
70 { |
|
71 } |
|
72 |
|
73 /*! |
|
74 Constructs a copy of the \a other change set |
|
75 */ |
|
76 QContactChangeSet::QContactChangeSet(const QContactChangeSet& other) |
|
77 : d(other.d) |
|
78 { |
|
79 } |
|
80 |
|
81 /*! |
|
82 Frees the memory used by this change set |
|
83 */ |
|
84 QContactChangeSet::~QContactChangeSet() |
|
85 { |
|
86 } |
|
87 |
|
88 /*! |
|
89 Assigns this change set to be equal to \a other |
|
90 */ |
|
91 QContactChangeSet& QContactChangeSet::operator=(const QContactChangeSet& other) |
|
92 { |
|
93 d = other.d; |
|
94 return *this; |
|
95 } |
|
96 |
|
97 /*! |
|
98 Sets the data changed flag to \a dataChanged. If this is set to true prior to calling \l emitSignals(), |
|
99 only the \l QContactManagerEngine::dataChanged() signal will be emitted; otherwise, the appropriate |
|
100 finer-grained signals will be emitted. |
|
101 */ |
|
102 void QContactChangeSet::setDataChanged(bool dataChanged) |
|
103 { |
|
104 d->m_dataChanged = dataChanged; |
|
105 } |
|
106 |
|
107 /*! |
|
108 Returns the value of the data changed flag |
|
109 */ |
|
110 bool QContactChangeSet::dataChanged() |
|
111 { |
|
112 return d->m_dataChanged; |
|
113 } |
|
114 |
|
115 /*! |
|
116 Returns the set of ids of contacts which have been added to |
|
117 the database. |
|
118 */ |
|
119 QSet<QContactLocalId> QContactChangeSet::addedContacts() const |
|
120 { |
|
121 return d->m_addedContacts; |
|
122 } |
|
123 |
|
124 /*! |
|
125 Inserts the given contact id \a addedContactId into the set of ids of contacts |
|
126 which have been added to the database. |
|
127 */ |
|
128 void QContactChangeSet::insertAddedContact(QContactLocalId addedContactId) |
|
129 { |
|
130 d->m_addedContacts.insert(addedContactId); |
|
131 } |
|
132 |
|
133 /*! |
|
134 Inserts each of the given contact ids \a addedContactIds into the set of ids of contacts |
|
135 which have been added to the database. |
|
136 */ |
|
137 void QContactChangeSet::insertAddedContacts(const QList<QContactLocalId>& addedContactIds) |
|
138 { |
|
139 foreach (const QContactLocalId& id, addedContactIds) |
|
140 d->m_addedContacts.insert(id); |
|
141 } |
|
142 |
|
143 /*! |
|
144 Clears the set of ids of contacts which have been added to the database |
|
145 */ |
|
146 void QContactChangeSet::clearAddedContacts() |
|
147 { |
|
148 d->m_addedContacts.clear(); |
|
149 } |
|
150 |
|
151 /*! |
|
152 Returns the set of ids of contacts which have been changed in |
|
153 the database. |
|
154 */ |
|
155 QSet<QContactLocalId> QContactChangeSet::changedContacts() const |
|
156 { |
|
157 return d->m_changedContacts; |
|
158 } |
|
159 |
|
160 /*! |
|
161 Inserts the given contact id \a changedContactId into the set of ids of contacts |
|
162 which have been changed to the database. |
|
163 */ |
|
164 void QContactChangeSet::insertChangedContact(QContactLocalId changedContactId) |
|
165 { |
|
166 d->m_changedContacts.insert(changedContactId); |
|
167 } |
|
168 |
|
169 /*! |
|
170 Inserts each of the given contact ids \a changedContactIds into the set of ids of contacts |
|
171 which have been changed to the database. |
|
172 */ |
|
173 void QContactChangeSet::insertChangedContacts(const QList<QContactLocalId>& changedContactIds) |
|
174 { |
|
175 foreach (const QContactLocalId& id, changedContactIds) |
|
176 d->m_changedContacts.insert(id); |
|
177 } |
|
178 |
|
179 /*! |
|
180 Clears the set of ids of contacts which have been changed to the database |
|
181 */ |
|
182 void QContactChangeSet::clearChangedContacts() |
|
183 { |
|
184 d->m_changedContacts.clear(); |
|
185 } |
|
186 |
|
187 /*! |
|
188 Returns the set of ids of contacts which have been removed from |
|
189 the database. |
|
190 */ |
|
191 QSet<QContactLocalId> QContactChangeSet::removedContacts() const |
|
192 { |
|
193 return d->m_removedContacts; |
|
194 } |
|
195 |
|
196 /*! |
|
197 Inserts the given contact id \a removedContactId into the set of ids of contacts |
|
198 which have been removed to the database. |
|
199 */ |
|
200 void QContactChangeSet::insertRemovedContact(QContactLocalId removedContactId) |
|
201 { |
|
202 d->m_removedContacts.insert(removedContactId); |
|
203 } |
|
204 |
|
205 /*! |
|
206 Inserts each of the given contact ids \a removedContactIds into the set of ids of contacts |
|
207 which have been removed to the database. |
|
208 */ |
|
209 void QContactChangeSet::insertRemovedContacts(const QList<QContactLocalId>& removedContactIds) |
|
210 { |
|
211 foreach (const QContactLocalId& id, removedContactIds) |
|
212 d->m_removedContacts.insert(id); |
|
213 } |
|
214 |
|
215 /*! |
|
216 Clears the set of ids of contacts which have been removed to the database |
|
217 */ |
|
218 void QContactChangeSet::clearRemovedContacts() |
|
219 { |
|
220 d->m_removedContacts.clear(); |
|
221 } |
|
222 |
|
223 /*! |
|
224 Returns the set of ids of contacts which have been affected |
|
225 by the addition of relationships to the database. |
|
226 */ |
|
227 QSet<QContactLocalId> QContactChangeSet::addedRelationshipsContacts() const |
|
228 { |
|
229 return d->m_addedRelationships; |
|
230 } |
|
231 |
|
232 /*! |
|
233 Inserts the given contact id \a affectedContactId into the set of ids of contacts |
|
234 which have been affected by the addition of a relationship to the database. |
|
235 */ |
|
236 void QContactChangeSet::insertAddedRelationshipsContact(QContactLocalId affectedContactId) |
|
237 { |
|
238 d->m_addedRelationships.insert(affectedContactId); |
|
239 } |
|
240 |
|
241 /*! |
|
242 Inserts each of the given contact ids \a affectedContactIds into the set of ids of contacts |
|
243 which have been affected by the addition of a relationship to the database. |
|
244 */ |
|
245 void QContactChangeSet::insertAddedRelationshipsContacts(const QList<QContactLocalId>& affectedContactIds) |
|
246 { |
|
247 foreach (const QContactLocalId& id, affectedContactIds) |
|
248 d->m_addedRelationships.insert(id); |
|
249 } |
|
250 |
|
251 /*! |
|
252 Clears the set of ids of contacts which have been affected by the addition of a relationship to the database. |
|
253 */ |
|
254 void QContactChangeSet::clearAddedRelationshipsContacts() |
|
255 { |
|
256 d->m_addedRelationships.clear(); |
|
257 } |
|
258 |
|
259 /*! |
|
260 Returns the set of ids of contacts which have been affected |
|
261 by the removal of relationships from the database. |
|
262 */ |
|
263 QSet<QContactLocalId> QContactChangeSet::removedRelationshipsContacts() const |
|
264 { |
|
265 return d->m_removedRelationships; |
|
266 } |
|
267 |
|
268 /*! |
|
269 Inserts the given contact id \a affectedContactId into the set of ids of contacts |
|
270 which have been affected by the removal of a relationship to the database. |
|
271 */ |
|
272 void QContactChangeSet::insertRemovedRelationshipsContact(QContactLocalId affectedContactId) |
|
273 { |
|
274 d->m_removedRelationships.insert(affectedContactId); |
|
275 } |
|
276 |
|
277 /*! |
|
278 Inserts each of the given contact ids \a affectedContactIds into the set of ids of contacts |
|
279 which have been affected by the removal of a relationship to the database. |
|
280 */ |
|
281 void QContactChangeSet::insertRemovedRelationshipsContacts(const QList<QContactLocalId>& affectedContactIds) |
|
282 { |
|
283 foreach (const QContactLocalId& id, affectedContactIds) |
|
284 d->m_removedRelationships.insert(id); |
|
285 } |
|
286 |
|
287 /*! |
|
288 Clears the set of ids of contacts which have been affected by the removal of a relationship to the database. |
|
289 */ |
|
290 void QContactChangeSet::clearRemovedRelationshipsContacts() |
|
291 { |
|
292 d->m_removedRelationships.clear(); |
|
293 } |
|
294 |
|
295 /*! |
|
296 Sets the pair of ids which represent the old and new self contact ids |
|
297 to the given pair of ids \a oldAndNewContactId. |
|
298 The first id in the pair is the old self contact id, while the second |
|
299 id in the pair is the new self contact id. If the new id is different |
|
300 to the old id at the point in time when emitSignals() is called, |
|
301 the QContactManagerEngine::selfContactIdChanged signal will be emitted. |
|
302 */ |
|
303 void QContactChangeSet::setOldAndNewSelfContactId(const QPair<QContactLocalId, QContactLocalId> &oldAndNewContactId) |
|
304 { |
|
305 d->m_oldAndNewSelfContactId = oldAndNewContactId; |
|
306 } |
|
307 |
|
308 /*! |
|
309 Returns the pair of ids which represents the |
|
310 old and new self contact ids. The first id in the pair is the |
|
311 old self contact id, while the second id in the pair is the |
|
312 new self contact id. If the new id is different to the old id |
|
313 at the point in time when emitSignals() is called, |
|
314 the QContactManagerEngine::selfContactIdChanged() signal will be emitted. |
|
315 */ |
|
316 QPair<QContactLocalId, QContactLocalId> QContactChangeSet::oldAndNewSelfContactId() const |
|
317 { |
|
318 return d->m_oldAndNewSelfContactId; |
|
319 } |
|
320 |
|
321 /*! |
|
322 Clears all flags and sets of ids in this change set |
|
323 */ |
|
324 void QContactChangeSet::clearAll() |
|
325 { |
|
326 d->m_dataChanged = false; |
|
327 d->m_addedContacts.clear(); |
|
328 d->m_changedContacts.clear(); |
|
329 d->m_removedContacts.clear(); |
|
330 d->m_addedRelationships.clear(); |
|
331 d->m_removedRelationships.clear(); |
|
332 d->m_oldAndNewSelfContactId = QPair<QContactLocalId, QContactLocalId>(); |
|
333 } |
|
334 |
|
335 /*! |
|
336 Emits the appropriate signals from the given \a engine given the state of the change set |
|
337 */ |
|
338 void QContactChangeSet::emitSignals(QContactManagerEngine *engine) |
|
339 { |
|
340 if (!engine) |
|
341 return; |
|
342 |
|
343 if (d->m_dataChanged) { |
|
344 emit engine->dataChanged(); |
|
345 } else { |
|
346 if (!d->m_addedContacts.isEmpty()) |
|
347 emit engine->contactsAdded(d->m_addedContacts.toList()); |
|
348 if (!d->m_changedContacts.isEmpty()) |
|
349 emit engine->contactsChanged(d->m_changedContacts.toList()); |
|
350 if (!d->m_removedContacts.isEmpty()) |
|
351 emit engine->contactsRemoved(d->m_removedContacts.toList()); |
|
352 if (!d->m_addedRelationships.isEmpty()) |
|
353 emit engine->relationshipsAdded(d->m_addedRelationships.toList()); |
|
354 if (!d->m_removedRelationships.isEmpty()) |
|
355 emit engine->relationshipsRemoved(d->m_removedRelationships.toList()); |
|
356 if (d->m_oldAndNewSelfContactId.first != d->m_oldAndNewSelfContactId.second) |
|
357 emit engine->selfContactIdChanged(d->m_oldAndNewSelfContactId.first, d->m_oldAndNewSelfContactId.second); |
|
358 } |
|
359 } |
|
360 |
|
361 QTM_END_NAMESPACE |