189 break; |
190 break; |
190 case EContactDbObserverEventGroupChanged: |
191 case EContactDbObserverEventGroupChanged: |
191 if(m_contactsEmitted.contains(id)) |
192 if(m_contactsEmitted.contains(id)) |
192 m_contactsEmitted.removeOne(id); |
193 m_contactsEmitted.removeOne(id); |
193 else { |
194 else { |
194 #ifndef SYMBIAN_BACKEND_USE_SQLITE |
|
195 // Contact DB observer API does not give information of contacts |
|
196 // possibly added to or removed from the group |
|
197 QSet<QContactLocalId> added; |
|
198 QSet<QContactLocalId> removed; |
|
199 TRAPD(err, updateGroupMembershipsL(id, added, removed)); |
|
200 if(err != KErrNone){ |
|
201 changeSet.setDataChanged(true); |
|
202 } else if(removed.count()) { |
|
203 // The group changed event was caused by removing contacts |
|
204 // from the group |
|
205 changeSet.insertRemovedRelationshipsContact(id); |
|
206 changeSet.insertRemovedRelationshipsContacts(removed.toList()); |
|
207 } else if(added.count()) { |
|
208 // The group changed event was caused by adding contacts |
|
209 // to the group |
|
210 changeSet.insertAddedRelationshipsContact(id); |
|
211 changeSet.insertAddedRelationshipsContacts(added.toList()); |
|
212 } else { |
|
213 // The group changed event was caused by modifying the group |
|
214 changeSet.insertChangedContact(id); |
|
215 } |
|
216 #else |
|
217 // Currently the group membership check is only used in pre-10.1 |
195 // Currently the group membership check is only used in pre-10.1 |
218 // platforms. In 10.1 we need to check the performance penalty |
196 // platforms. In 10.1 we need to check the performance penalty |
219 // caused in the instantiation of QContactManager. If the |
197 // caused in the instantiation of QContactManager. If the |
220 // performance is too bad, then the MContactDbObserver API needs to |
198 // performance is too bad, then the MContactDbObserver API needs to |
221 // be changed in 10.1 so that we don't need the group membership |
199 // be changed in 10.1 so that we don't need the group membership |
222 // buffer in the engine level. In other words events like |
200 // buffer in the engine level. In other words events like |
223 // EContactDbObserverEventGroupMembersAdded and |
201 // EContactDbObserverEventGroupMembersAdded and |
224 // EContactDbObserverEventGroupMembersRemoved need to be added to |
202 // EContactDbObserverEventGroupMembersRemoved need to be added to |
225 // MContactDbObserver. |
203 // MContactDbObserver. |
226 changeSet.insertChangedContact(id); //group is a contact |
204 changeSet.insertChangedContact(id); //group is a contact |
227 #endif |
|
228 } |
205 } |
229 break; |
206 break; |
230 case EContactDbObserverEventOwnCardChanged: |
207 case EContactDbObserverEventOwnCardChanged: |
231 if (m_contactsEmitted.contains(id)) { |
208 if (m_contactsEmitted.contains(id)) { |
232 m_contactsEmitted.removeOne(id); |
209 m_contactsEmitted.removeOne(id); |
233 } else { |
210 } |
234 QOwnCardPair ownCard(m_currentOwnCardId, QContactLocalId(id)); |
211 else { |
235 changeSet.setOldAndNewSelfContactId(ownCard); |
212 if (m_currentOwnCardId == QContactLocalId(id)) { |
236 m_currentOwnCardId = QContactLocalId(id); |
213 //own card content was changed |
|
214 changeSet.insertChangedContact(m_currentOwnCardId); |
|
215 } |
237 } |
216 } |
238 break; |
217 break; |
239 default: |
218 default: |
240 break; // ignore other events |
219 break; // ignore other events |
241 } |
220 } |
242 |
221 #else // SYMBIAN_BACKEND_SIGNAL_EMISSION_TWEAK |
|
222 switch (aEvent.iType) |
|
223 { |
|
224 case EContactDbObserverEventContactAdded: |
|
225 changeSet.insertAddedContact(id); |
|
226 break; |
|
227 case EContactDbObserverEventOwnCardDeleted: |
|
228 { |
|
229 // signal selfContactIdChanged (from id to zero) |
|
230 QOwnCardPair ownCard(m_currentOwnCardId, QContactLocalId(0)); |
|
231 changeSet.setOldAndNewSelfContactId(ownCard); |
|
232 // signal contactsRemoved (the self contact was deleted) |
|
233 changeSet.insertRemovedContact(id); |
|
234 // reset own card id |
|
235 m_currentOwnCardId = QContactLocalId(0); |
|
236 } |
|
237 break; |
|
238 case EContactDbObserverEventContactDeleted: |
|
239 { |
|
240 changeSet.insertRemovedContact(id); |
|
241 |
|
242 // Check if contact was part of some group. |
|
243 // This check is needed because CContactDatabase will NOT |
|
244 // provide EContactDbObserverEventGroupChanged event in this case!!! |
|
245 QMap<QContactLocalId, QSet<QContactLocalId> >::iterator i; |
|
246 for (i=m_groupContents.begin(); i!=m_groupContents.end(); i++ ) { |
|
247 if (i->contains(id)) { |
|
248 changeSet.insertRemovedRelationshipsContact(i.key()); |
|
249 changeSet.insertRemovedRelationshipsContacts(i->toList()); |
|
250 i->remove(id); |
|
251 } |
|
252 } |
|
253 } |
|
254 break; |
|
255 case EContactDbObserverEventContactChanged: |
|
256 changeSet.insertChangedContact(id); |
|
257 break; |
|
258 case EContactDbObserverEventGroupAdded: |
|
259 // Creating a group will cause two events. |
|
260 // Emitting addedContact from EContactDbObserverEventGroupChanged. |
|
261 changeSet.insertAddedContact(id); |
|
262 break; |
|
263 case EContactDbObserverEventGroupDeleted: |
|
264 { |
|
265 changeSet.insertRemovedContact(id); |
|
266 |
|
267 // Check if there was any contacts in the group |
|
268 if (m_groupContents.value(id).count()) { |
|
269 changeSet.insertRemovedRelationshipsContact(id); |
|
270 changeSet.insertRemovedRelationshipsContacts(m_groupContents.value(id).toList()); |
|
271 } |
|
272 m_groupContents.remove(id); |
|
273 } |
|
274 break; |
|
275 case EContactDbObserverEventGroupChanged: |
|
276 { |
|
277 bool isOldGroup = m_groupContents.contains(id); |
|
278 |
|
279 // Contact DB observer API does not give information of contacts |
|
280 // possibly added to or removed from the group |
|
281 QSet<QContactLocalId> added; |
|
282 QSet<QContactLocalId> removed; |
|
283 TRAPD(err, updateGroupMembershipsL(id, added, removed)); |
|
284 if(err != KErrNone) |
|
285 changeSet.setDataChanged(true); |
|
286 |
|
287 if (removed.count()) { |
|
288 // The group changed event was caused by removing contacts |
|
289 // from the group |
|
290 changeSet.insertRemovedRelationshipsContact(id); |
|
291 changeSet.insertRemovedRelationshipsContacts(removed.toList()); |
|
292 } |
|
293 if (added.count()) { |
|
294 // The group changed event was caused by adding contacts |
|
295 // to the group |
|
296 changeSet.insertAddedRelationshipsContact(id); |
|
297 changeSet.insertAddedRelationshipsContacts(added.toList()); |
|
298 } |
|
299 if (added.count() == 0 && removed.count() == 0) { |
|
300 // The group changed event was caused by modifying the group |
|
301 // NOTE: Do not emit this for a new group. Creating a group |
|
302 // through the backend causes two events GroupAdded and |
|
303 // GroupChanged. |
|
304 if (isOldGroup) |
|
305 changeSet.insertChangedContact(id); |
|
306 } |
|
307 } |
|
308 break; |
|
309 case EContactDbObserverEventOwnCardChanged: |
|
310 if (m_currentOwnCardId == QContactLocalId(id)) |
|
311 changeSet.insertChangedContact(m_currentOwnCardId); |
|
312 else |
|
313 changeSet.setOldAndNewSelfContactId(QOwnCardPair(m_currentOwnCardId, QContactLocalId(id))); |
|
314 m_currentOwnCardId = QContactLocalId(id); |
|
315 break; |
|
316 default: |
|
317 break; // ignore other events |
|
318 } |
|
319 #endif // SYMBIAN_BACKEND_SIGNAL_EMISSION_TWEAK |
|
320 |
243 changeSet.emitSignals(m_engine); |
321 changeSet.emitSignals(m_engine); |
244 } |
322 } |
245 |
323 |
246 /* |
324 /* |
247 * Private implementation for updating the buffer containing the members of all |
325 * Private implementation for updating the buffer containing the members of all |