|
1 /* |
|
2 * Copyright (c) 2005 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: Contact list model implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef __CPENGCONTACTLISTMODBASE_H__ |
|
19 #define __CPENGCONTACTLISTMODBASE_H__ |
|
20 |
|
21 // INCLUDES |
|
22 #include "MPEngContactListAdvance.h" |
|
23 #include "CPEngStoreEntry.h" |
|
24 #include "MPEngContactListSettingsObserver.h" |
|
25 #include "MPEngContactListModStore.h" |
|
26 #include "TPEngContactListBaseSettings.h" |
|
27 #include <e32base.h> |
|
28 |
|
29 |
|
30 // FORWARD DECLARATIONS |
|
31 class CPEngContactListModItemContainer; |
|
32 class CPEngContactListModChangeMonitor; |
|
33 class CPEngContactListSettings; |
|
34 class MPEngContactListSettingsManager; |
|
35 |
|
36 |
|
37 // HELP CLASS DECLARATION |
|
38 |
|
39 /** |
|
40 * Reference owning pointer array. |
|
41 */ |
|
42 template<class T> |
|
43 class RReffArray : public RPointerArray<T> |
|
44 { |
|
45 public: |
|
46 |
|
47 /** |
|
48 * Overwritten Close() behaviour. |
|
49 * Closes access to items. |
|
50 */ |
|
51 inline void Close() |
|
52 { |
|
53 TInt count( RPointerArray<T>::Count() ); |
|
54 for ( TInt x( 0 ) ; x < count ; ++x ) |
|
55 { |
|
56 RPointerArray<T>::operator[]( x )->Close(); |
|
57 } |
|
58 RPointerArray<T>::Reset(); |
|
59 } |
|
60 }; |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 // CLASS DECLARATION |
|
66 /** |
|
67 * Contact list model |
|
68 * Main implementation of the Contact List model. |
|
69 * |
|
70 * @lib PEngListLib2 |
|
71 * @since 3.0 |
|
72 */ |
|
73 NONSHARABLE_CLASS( CPEngContactListModBase ) : |
|
74 public CPEngStoreEntry, |
|
75 public MPEngContactListAdvance, |
|
76 public MPEngContactListSettingsObserver, |
|
77 public MPEngContactListModStore |
|
78 { |
|
79 public: // Constructors, destructor |
|
80 /** |
|
81 * Two-phased constructor. |
|
82 */ |
|
83 static CPEngContactListModBase* NewL( |
|
84 CPEngContactListSettings& aListSetting, |
|
85 MPEngStorageManager& aStorageManager, |
|
86 MPEngContactListSettingsManager& aCntLstSettingsManager ); |
|
87 |
|
88 /** |
|
89 * Two-phased constructor. |
|
90 */ |
|
91 static CPEngContactListModBase* NewLC( |
|
92 CPEngContactListSettings& aListSetting, |
|
93 MPEngStorageManager& aStorageManager, |
|
94 MPEngContactListSettingsManager& aCntLstSettingsManager ); |
|
95 |
|
96 |
|
97 /** |
|
98 * Destructor |
|
99 */ |
|
100 ~CPEngContactListModBase(); |
|
101 |
|
102 |
|
103 |
|
104 protected: // Constructors |
|
105 |
|
106 /** |
|
107 * C++ constructor. |
|
108 */ |
|
109 CPEngContactListModBase( |
|
110 CPEngContactListSettings& aListSettings, |
|
111 MPEngContactListSettingsManager& aCntLstSettingsManager ); |
|
112 |
|
113 /** |
|
114 * Symbian constructor. |
|
115 */ |
|
116 void ConstructL( MPEngStorageManager& aStorageManager ); |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 public: // From MPEngContactListAdvance |
|
123 |
|
124 /** |
|
125 * Gets Reference to the once item of the contact lists |
|
126 * @see <MPEngContactListAdvance.h> |
|
127 */ |
|
128 MPEngContactItemAdvance& ContactItemAdvance( |
|
129 TInt aIndex, |
|
130 TPEngContactListView aView = EPEngCntListLocalView ); |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 public: // From MPEngContactList2 |
|
136 |
|
137 /** |
|
138 * Inserts a Contact into the Contact list. |
|
139 * @see <MPEngContactList2> |
|
140 */ |
|
141 TInt AddContactL( const TDesC& aContact, |
|
142 const TDesC& aNickName = KNullDesC ); |
|
143 |
|
144 /** |
|
145 * Removes Contact from the Contact list |
|
146 * @see <MPEngContactList2> |
|
147 */ |
|
148 void RemoveContactL( const TDesC& aContact ); |
|
149 |
|
150 |
|
151 |
|
152 /** |
|
153 * Find Contact in the contact list |
|
154 * @see <MPEngContactList2> |
|
155 */ |
|
156 TInt FindContact( const TDesC& aContact, |
|
157 TPEngContactListView aView = EPEngCntListLocalView ) const; |
|
158 |
|
159 |
|
160 |
|
161 /** |
|
162 * Count of the Contacts of the Contact list view |
|
163 * @see <MPEngContactList2> |
|
164 */ |
|
165 TInt Count( TPEngContactListView aView = EPEngCntListLocalView ) const; |
|
166 |
|
167 |
|
168 /** |
|
169 * Contact Item of the Contact list |
|
170 * @see <MPEngContactList2> |
|
171 */ |
|
172 MPEngContactItem& ContactItem( |
|
173 TInt aIndex, |
|
174 TPEngContactListView aView = EPEngCntListLocalView ); |
|
175 |
|
176 const MPEngContactItem& ContactItem( |
|
177 TInt aIndex, |
|
178 TPEngContactListView aView = EPEngCntListLocalView ) const; |
|
179 |
|
180 |
|
181 /** |
|
182 * Contacts which were removed from the contact list |
|
183 * @see <MPEngContactList2> |
|
184 */ |
|
185 const MDesCArray& RemovedContacts( ) const; |
|
186 |
|
187 |
|
188 /** |
|
189 * Contacts which were added to the contact list |
|
190 * @see <MPEngContactList2> |
|
191 */ |
|
192 const MDesCArray& AddedContacts( ) const; |
|
193 |
|
194 |
|
195 /** |
|
196 * Contact list Settings |
|
197 * @see <MPEngContactList2> |
|
198 */ |
|
199 MPEngContactListProperties& ListProperties(); |
|
200 |
|
201 |
|
202 /** |
|
203 * Remove all contacts from the contact list |
|
204 * @see <MPEngContactList2> |
|
205 */ |
|
206 void RemoveAllContactsL( ); |
|
207 |
|
208 |
|
209 /** |
|
210 * Suspend contact list update notifications |
|
211 * @see <MPEngContactList2> |
|
212 */ |
|
213 void SuspendUpdateNotification( ); |
|
214 |
|
215 |
|
216 /** |
|
217 * Release sending of the contact list update notifications |
|
218 * @see <MPEngContactList2> |
|
219 */ |
|
220 void ReleaseUpdateNotification( ); |
|
221 |
|
222 |
|
223 /** |
|
224 * Roll back all changes |
|
225 * @see <MPEngContactList2> |
|
226 */ |
|
227 TInt RollBackAllChangesL( ); |
|
228 |
|
229 |
|
230 /** |
|
231 * Contact list locked by other client |
|
232 * @see <MPEngContactList2> |
|
233 */ |
|
234 TBool UpdateInProgress( ) const; |
|
235 |
|
236 |
|
237 /** |
|
238 * Update of the contact list required |
|
239 * @see <MPEngContactList2> |
|
240 */ |
|
241 TBool UpdateRequired() const; |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 public: // Functions from CPEngStoreEntry |
|
247 |
|
248 /** |
|
249 * ExternalizeL provides way to externalize data from store entry. |
|
250 * @see <MPEngStoreEntry.h> |
|
251 */ |
|
252 void ExternalizeL( RWriteStream& aStream, |
|
253 TPEngStorageType aStorageType ) const; |
|
254 |
|
255 /** |
|
256 * InternalizeL provides way to internalise data to store entry. |
|
257 * @see <MPEngStoreEntry.h> |
|
258 */ |
|
259 void InternalizeL( RReadStream& aStream, |
|
260 TPEngStorageType aStorageType ); |
|
261 |
|
262 /** |
|
263 * Store Id of the contact list |
|
264 * @see <MPEngStoreEntry.h> |
|
265 */ |
|
266 virtual const TDesC& StorageId() const; |
|
267 |
|
268 /** |
|
269 * Store size of the contact list |
|
270 * @see <MPEngStoreEntry.h> |
|
271 */ |
|
272 virtual TUint32 EntrySize() const; |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 public: // CPEngStoreEntry / MPEngSIDChangeObserver |
|
278 |
|
279 /** |
|
280 * Handle change of the Storage IDs |
|
281 * @see <MPEngSIDChangeObserver.h> |
|
282 */ |
|
283 void HandleSIDsChangeL( CPtrCArray& aChangedSIDs ); |
|
284 |
|
285 /** |
|
286 * Called when SIDs notifier fails |
|
287 * @see <MPEngSIDChangeObserver.h> |
|
288 */ |
|
289 void HandleSIDNotifyError( TInt aError ); |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 public: // MPEngContactListModStore |
|
295 |
|
296 /** |
|
297 * Gets reference to the store entry size |
|
298 * Size can be modified through this reference |
|
299 * |
|
300 * @see <MPEngContactListModStore.h> |
|
301 */ |
|
302 TInt& StoreSizeCount( ); |
|
303 |
|
304 /** |
|
305 * Stores entry to the store |
|
306 * @see <MPEngContactListModStore.h> |
|
307 */ |
|
308 void StoreEntryL(); |
|
309 |
|
310 |
|
311 |
|
312 public: // function of the MPEngContactListSettingsObserver |
|
313 |
|
314 /** |
|
315 * Refresh contact list settings reference |
|
316 * @see <MPEngContactListSettingsObserver.h> |
|
317 */ |
|
318 void RefreshSettingsReference( ); |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 public: // New functions used for ListLib private use |
|
324 |
|
325 |
|
326 /** |
|
327 * Maps contact list type to storage type. |
|
328 * |
|
329 * @since 3.0 |
|
330 */ |
|
331 static TPEngStorageType StoreTypeForListType( TPEngContactListType aListType ); |
|
332 |
|
333 |
|
334 /** |
|
335 * Reference count support |
|
336 * |
|
337 * @since 3.0 |
|
338 */ |
|
339 void Open(); |
|
340 |
|
341 |
|
342 /** |
|
343 * Reference count support |
|
344 * |
|
345 * @since 3.0 |
|
346 */ |
|
347 void Close(); |
|
348 |
|
349 |
|
350 /** |
|
351 * Stores contact list content to the store |
|
352 * @since 3.0 |
|
353 */ |
|
354 void StoreContactListL( ); |
|
355 |
|
356 |
|
357 /** |
|
358 * Fill give array with contacts need to be updated. |
|
359 * |
|
360 * Depends on the function, either contacts which need to be updated |
|
361 * are added. Or contacts which needs to be deleted are added. |
|
362 * |
|
363 * Ownership of appended contact items is not returned. |
|
364 * |
|
365 * @since 3.0 |
|
366 * @param array to be filled with contacts |
|
367 */ |
|
368 void FillAddNickListL( |
|
369 RPointerArray<CPEngContactListModItemContainer>& aAddNickList ); |
|
370 void FillRemoveNickListL( |
|
371 RPointerArray<CPEngContactListModItemContainer>& aRemoveNickList ); |
|
372 |
|
373 |
|
374 /** |
|
375 * Commit changes after successful update request |
|
376 * Request can either update new or edited contacts |
|
377 * "CommitAddContactsL" or removed contacts "CommitRemoveContactsL" |
|
378 * |
|
379 * @since 3.0 |
|
380 */ |
|
381 void CommitAddContactsL(); |
|
382 void CommitRemoveContactsL(); |
|
383 |
|
384 |
|
385 /** |
|
386 * Roll back all changes |
|
387 * Content of the local view is set same as network one |
|
388 * |
|
389 * @since 3.0 |
|
390 */ |
|
391 void RollbackL(); |
|
392 |
|
393 |
|
394 /** |
|
395 * Look for contact among all contact views. |
|
396 * |
|
397 * @since 3.0 |
|
398 * @param aContact to loook for |
|
399 * @return contact item if found, or NULL pointer |
|
400 */ |
|
401 CPEngContactListModItemContainer* FindContactInAll( const TDesC& aContact ); |
|
402 |
|
403 |
|
404 /** |
|
405 * Check if Contact is valid on the Network server |
|
406 * |
|
407 * @since 3.0 |
|
408 * @param aContact contact to check |
|
409 * @return ETrue if contact exist on network server |
|
410 */ |
|
411 TBool ContactExistsOnServer( CPEngContactListModItemContainer& aContact ); |
|
412 |
|
413 |
|
414 /** |
|
415 * Adopt new set of contacts. |
|
416 * Contacts are either adopted for both views ( Local, network) |
|
417 * "AdoptNewContactsL" |
|
418 * or only for network view "AddoptNetworkViewL" which leaves |
|
419 * contact list in state needed for update |
|
420 * Passed array owns reference to the member items. |
|
421 * Once item is adopted it is removed from passed array |
|
422 * |
|
423 * @since 3.0 |
|
424 * @param aContacts list of contacts to be adopted |
|
425 */ |
|
426 void AdoptNewContactsL( |
|
427 RPointerArray<CPEngContactListModItemContainer>& aContacts ); |
|
428 void AdoptNetworkViewL( |
|
429 RPointerArray<CPEngContactListModItemContainer>& aContacts ); |
|
430 |
|
431 |
|
432 /** |
|
433 * Remove bad contact from the contact list |
|
434 * |
|
435 * @since 3.0 |
|
436 * @param aContact contact Id |
|
437 */ |
|
438 void RemoveBadContactL( const TDesC& aContact ); |
|
439 |
|
440 |
|
441 |
|
442 /** |
|
443 * Reset content of the contact list |
|
444 * |
|
445 * @since 3.0 |
|
446 */ |
|
447 virtual void Reset(); |
|
448 |
|
449 |
|
450 /** |
|
451 * Reset Local/Network view List |
|
452 * |
|
453 * @since 3.0 |
|
454 */ |
|
455 void ResetLocalView(); |
|
456 void ResetNetworkView(); |
|
457 |
|
458 |
|
459 /** |
|
460 * Leaves with KErrInUse if the contact list |
|
461 * update is progress. |
|
462 * |
|
463 * @since 3.0 |
|
464 */ |
|
465 void LeaveIfListUpdateInProgressL() const; |
|
466 |
|
467 |
|
468 /** |
|
469 * Get ChangeMonitor reference. |
|
470 * |
|
471 * @since 3.0 |
|
472 * @return change monitor |
|
473 */ |
|
474 CPEngContactListModChangeMonitor& ChangeMonitor(); |
|
475 |
|
476 |
|
477 /** |
|
478 * Get Contact List Settings |
|
479 * |
|
480 * @since 3.0 |
|
481 * @return contact list settings |
|
482 */ |
|
483 CPEngContactListSettings& Settings( ); |
|
484 |
|
485 |
|
486 /** |
|
487 * Server Ordered Contacts |
|
488 * |
|
489 * @since 3.0 |
|
490 * @return List of server ordered contacts |
|
491 */ |
|
492 const RPointerArray<CPEngContactListModItemContainer>& ServerOrderedContacts() const; |
|
493 |
|
494 |
|
495 /** |
|
496 * Find contact in the array |
|
497 * |
|
498 * @since 3.0 |
|
499 * @param aContact contact name |
|
500 * @return index in the array, or KErrNotFound |
|
501 */ |
|
502 TInt DoFindContact( |
|
503 const RPointerArray<CPEngContactListModItemContainer>& aArray, |
|
504 const TDesC& aContact, |
|
505 TInt& aIndex, |
|
506 TBool aFirstPrefered = EFalse ) const; |
|
507 |
|
508 TInt DoFindContact( |
|
509 const RPointerArray<CPEngContactListModItemContainer>& aArray, |
|
510 const TDesC& aContact ) const; |
|
511 |
|
512 |
|
513 |
|
514 private: // Helpers |
|
515 |
|
516 |
|
517 /** |
|
518 * Externalize all contacts |
|
519 * |
|
520 * @since 3.0 |
|
521 * @param aStream stream to externalize to |
|
522 * @param aType storage type of externalize |
|
523 */ |
|
524 void ExternalizeContactsL( RWriteStream& aStream, |
|
525 TPEngStorageType aStorageType ) const; |
|
526 |
|
527 /** |
|
528 * Internalize all contacts |
|
529 * |
|
530 * @since 3.0 |
|
531 * @param aStream stream to store internalize from |
|
532 * @param aType storage type of internalize |
|
533 */ |
|
534 void InternalizePermanentContactsL( RReadStream& aStream ); |
|
535 |
|
536 |
|
537 /** |
|
538 * Internalize all contacts |
|
539 * |
|
540 * @since 3.0 |
|
541 * @param aStream stream to store internalize from |
|
542 * @param aType storage type of internalize |
|
543 */ |
|
544 void InternalizeCachedContactsL( RReadStream& aStream ); |
|
545 |
|
546 |
|
547 /** |
|
548 * Restore server ordered array |
|
549 */ |
|
550 void RestoreServerOrderedArray(); |
|
551 |
|
552 |
|
553 /** |
|
554 * Reorganizes network view's server order indexes |
|
555 */ |
|
556 void ReorganizeServerIndexOrder( TInt aIndex ); |
|
557 |
|
558 |
|
559 |
|
560 private: // Data |
|
561 |
|
562 |
|
563 /// OWN: Local view of the contacts |
|
564 /// Elements OWNed |
|
565 RReffArray<CPEngContactListModItemContainer> iLocalView; |
|
566 |
|
567 /// OWN: Network view of the contacts |
|
568 /// Elements OWNed |
|
569 RReffArray<CPEngContactListModItemContainer> iNetworkView; |
|
570 |
|
571 |
|
572 /// OWN: Contacts ordered in the order as network server sent it |
|
573 /// Elements references, same content as iNetworkView |
|
574 RPointerArray<CPEngContactListModItemContainer> iServerOrder; |
|
575 |
|
576 /// OWN: Monitor of the changes |
|
577 CPEngContactListModChangeMonitor* iChangesMonitor; |
|
578 |
|
579 |
|
580 /// OWN: Access count of the model |
|
581 TInt iAccessCount; |
|
582 |
|
583 /// REF: Setting of the contact list |
|
584 CPEngContactListSettings* iSettings; |
|
585 |
|
586 /// REF: Contact List settings manager |
|
587 MPEngContactListSettingsManager& iCntLstSettingsManager; |
|
588 |
|
589 /// OWN: Storage Id of the contact list |
|
590 HBufC* iStorageId; |
|
591 }; |
|
592 |
|
593 #endif // __CPENGCONTACTLISTMODBASE_H__ |
|
594 |
|
595 |
|
596 // End of File |
|
597 |
|
598 |
|
599 |