|
1 /* |
|
2 * Copyright (c) 2002-2007 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: Contacts Model store contact store implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef VPBKCNTMODEL_CCONTACTSTORE_H |
|
20 #define VPBKCNTMODEL_CCONTACTSTORE_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32base.h> |
|
24 #include <MVPbkContactStore.h> |
|
25 #include <MVPbkContactStore2.h> |
|
26 #include <MVPbkContactOperationFactory.h> |
|
27 #include <VPbkFieldType.hrh> |
|
28 #include <MVPbkContactStoreObserver.h> |
|
29 #include <cntdb.h> |
|
30 #include <cntviewbase.h> |
|
31 #include "CContactStoreDomain.h" |
|
32 |
|
33 // FORWARD DECLARATIONS |
|
34 class MVPbkFieldType; |
|
35 class CVPbkContactStoreUri; |
|
36 class MVPbkContactLink; |
|
37 class MVPbkContactObserver; |
|
38 class CVPbkContactStoreProperties; |
|
39 class MVPbkContactBookmark; |
|
40 template<typename MVPbkContactStoreObserver> class CVPbkAsyncObjectOperation; |
|
41 |
|
42 namespace VPbkEngUtils { |
|
43 class CVPbkDiskSpaceCheck; |
|
44 } /// namespace |
|
45 |
|
46 namespace VPbkCntModel { |
|
47 |
|
48 // FORWARD DECLARATIONS |
|
49 class CFieldTypeMap; |
|
50 class CContact; |
|
51 class CFieldFactory; |
|
52 class CAsyncContactOperation; |
|
53 class CFieldsInfo; |
|
54 class CContactStoreInfo; |
|
55 class CNamedRemoteViewHandle; |
|
56 |
|
57 #ifdef _DEBUG |
|
58 enum TContactStorePanic |
|
59 { |
|
60 EPreCond_NativeDatabase, |
|
61 EPreCond_ContactDestroyed, |
|
62 EPreCond_CreateNewContactGroupLC, |
|
63 EPreCond_ContactGroupsLC, |
|
64 EPreCond_OwnContactLinkL |
|
65 }; |
|
66 |
|
67 void ContactStorePanic( TContactStorePanic aPanic ); |
|
68 #endif // _DEBUG |
|
69 |
|
70 |
|
71 // CLASS DECLARATIONS |
|
72 |
|
73 /** |
|
74 * Maps a Contact Model database to a virtual Phonebook contact store. |
|
75 */ |
|
76 NONSHARABLE_CLASS( CContactStore ): public CBase, |
|
77 public MVPbkContactStore, |
|
78 public MVPbkContactStore2, |
|
79 private MContactDbObserver |
|
80 { |
|
81 public: // Constructor and destructor |
|
82 /** |
|
83 * Creates a new instance of this class. |
|
84 * |
|
85 * @param aURI Filename URI of the Contacts Model |
|
86 * database to map. |
|
87 * @param aStoreDomain Contact store domain. |
|
88 * @return A new instance of this class. |
|
89 */ |
|
90 static CContactStore* NewL( |
|
91 const TVPbkContactStoreUriPtr& aURI, |
|
92 CContactStoreDomain& aStoreDomain ); |
|
93 |
|
94 /** |
|
95 * Destructor. |
|
96 */ |
|
97 ~CContactStore(); |
|
98 |
|
99 public: // Interface |
|
100 /** |
|
101 * Returns the field type map to use for mapping Contact Model field |
|
102 * types to Virtual Phonebook field types. |
|
103 * |
|
104 * @return Field type map. |
|
105 */ |
|
106 const CFieldTypeMap& FieldTypeMap() const; |
|
107 |
|
108 /** |
|
109 * Returns the field factory. |
|
110 * |
|
111 * @return Field factory. |
|
112 */ |
|
113 const CFieldFactory& FieldFactory() const; |
|
114 |
|
115 /** |
|
116 * Returns the master field type list of Virtual Phonebook. |
|
117 * |
|
118 * @return Master field type list. |
|
119 */ |
|
120 const MVPbkFieldTypeList& MasterFieldTypeList() const; |
|
121 |
|
122 /** |
|
123 * Creates and returns a new Contacts Model field based on Virtual |
|
124 * Phonebook generic field type. |
|
125 * |
|
126 * @param aFieldType Field type. |
|
127 * @return Contacts Model field. |
|
128 */ |
|
129 CContactItemField* CreateFieldLC( |
|
130 const MVPbkFieldType& aFieldType ) const; |
|
131 |
|
132 /** |
|
133 * Reads a contact from the database. |
|
134 * |
|
135 * @param aContactId Id of the contact to read. |
|
136 * @param aObserver Observer. |
|
137 */ |
|
138 void ReadContactL( |
|
139 TContactItemId aContactId, |
|
140 MVPbkContactObserver& aObserver ); |
|
141 |
|
142 /** |
|
143 * Locks a contact in the database. |
|
144 * |
|
145 * @param aClient The contact to lock. |
|
146 * @param aObserver Observer. |
|
147 */ |
|
148 void LockContactL( |
|
149 const CContact& aClient, |
|
150 MVPbkContactObserver& aObserver ); |
|
151 |
|
152 /** |
|
153 * Reads and locks a contact in the database. |
|
154 * |
|
155 * @param aContactId Id of the contact to read and lock. |
|
156 * @param aObserver Observer. |
|
157 */ |
|
158 void ReadAndLockContactL( |
|
159 TContactItemId aContactId, |
|
160 MVPbkContactObserver& aObserver ); |
|
161 |
|
162 /** |
|
163 * Deletes a contact from the database. |
|
164 * |
|
165 * @param aContactId Id of the contact to delete. |
|
166 * @param aObserver Observer. |
|
167 */ |
|
168 void DeleteContactL( |
|
169 TContactItemId aContactId, |
|
170 MVPbkContactObserver& aObserver ); |
|
171 |
|
172 /** |
|
173 * Commits changes to a contact to the database. |
|
174 * |
|
175 * @param aContactItem The contact to commit. |
|
176 * @param aObserver Observer. |
|
177 */ |
|
178 void CommitContactL( |
|
179 const CContact& aContactItem, |
|
180 MVPbkContactObserver& aObserver ); |
|
181 |
|
182 /** |
|
183 * Creates a contact link. |
|
184 * |
|
185 * @param aContactId Id of the contact to link. |
|
186 * @return Contact link. |
|
187 */ |
|
188 MVPbkContactLink* CreateLinkLC( |
|
189 TContactItemId aContactId ) const; |
|
190 |
|
191 /** |
|
192 * Called from CContact destructor. aCloseContact should be |
|
193 * set for contacts that were locked. Read-only contacts |
|
194 * should provide EFalse for aCloseContact in order to avoid |
|
195 * resetting lock of another CContact instance for the same |
|
196 * contact model item. |
|
197 * |
|
198 * @param aContactItem The destroyed contact. |
|
199 * @param aCloseContact Indicates that contact should be closed, |
|
200 * necessary for locked contacts. |
|
201 */ |
|
202 void ContactDestroyed( |
|
203 CContactItem* aContactItem, TBool aCloseContact ); |
|
204 |
|
205 /** |
|
206 * Returns the native contacts database that |
|
207 * this store is connected to. |
|
208 * |
|
209 * @return Contact database. |
|
210 */ |
|
211 CContactDatabase& NativeDatabase() const; |
|
212 |
|
213 /** |
|
214 * Compares contact stores. |
|
215 * |
|
216 * @param aContactStoreUri The URI to compare. |
|
217 * @return ETrue if this is the same store. |
|
218 */ |
|
219 TBool MatchContactStore( |
|
220 const TDesC& aContactStoreUri ) const; |
|
221 |
|
222 /** |
|
223 * Compares contact store domains. |
|
224 * |
|
225 * @param aContactStoreDomain The domain to compare. |
|
226 * @return ETrue if this store is in the same domain. |
|
227 */ |
|
228 TBool MatchContactStoreDomain( |
|
229 const TDesC& aContactStoreDomain ) const; |
|
230 |
|
231 /** |
|
232 * Creates a contact bookmark |
|
233 * |
|
234 * @param aContactId Id of the contact to bookmark. |
|
235 * @return Contact bookmark. |
|
236 */ |
|
237 MVPbkContactBookmark* CreateBookmarkLC( |
|
238 TContactItemId aContactId ) const; |
|
239 |
|
240 /** |
|
241 * Set contact as the store's current own contact. |
|
242 * |
|
243 * @param aContactItem The contact to set as own. |
|
244 * @param aObserver Observer. |
|
245 */ |
|
246 void SetAsOwnL( |
|
247 const CContact& aContactItem, |
|
248 MVPbkContactObserver& aObserver ); |
|
249 |
|
250 public: // From MVPbkContactStore |
|
251 const MVPbkContactStoreProperties& StoreProperties() const; |
|
252 void OpenL( |
|
253 MVPbkContactStoreObserver& aObserver ); |
|
254 void ReplaceL( |
|
255 MVPbkContactStoreObserver& aObserver ); |
|
256 void Close( |
|
257 MVPbkContactStoreObserver& aObserver ); |
|
258 MVPbkStoreContact* CreateNewContactLC(); |
|
259 MVPbkContactGroup* CreateNewContactGroupLC(); |
|
260 MVPbkContactView* CreateViewLC( |
|
261 const CVPbkContactViewDefinition& aViewDefinition, |
|
262 MVPbkContactViewObserver& aObserver, |
|
263 const MVPbkFieldTypeList& aSortOrder ); |
|
264 MVPbkContactLinkArray* ContactGroupsLC() const; |
|
265 const MVPbkContactStoreInfo& StoreInfo() const; |
|
266 MVPbkContactLink* CreateLinkFromInternalsLC( |
|
267 RReadStream& aStream ) const; |
|
268 TAny* ContactStoreExtension( TUid aExtensionUid ); |
|
269 |
|
270 public: // From MVPbkContactStore2 |
|
271 MVPbkContactOperationBase* OwnContactLinkL( |
|
272 MVPbkSingleContactLinkOperationObserver& aObserver) const; |
|
273 |
|
274 public: // Contact operations (MVPbkContactOperationFactory) |
|
275 MVPbkContactOperation* CreateContactRetrieverL( |
|
276 const MVPbkContactLink& aLink, |
|
277 MVPbkSingleContactOperationObserver& aObserver ); |
|
278 MVPbkContactOperation* CreateDeleteContactsOperationL( |
|
279 const MVPbkContactLinkArray& aContactLinks, |
|
280 MVPbkBatchOperationObserver& aObserver ); |
|
281 MVPbkContactOperation* CreateCommitContactsOperationL( |
|
282 const TArray<MVPbkStoreContact*>& aContacts, |
|
283 MVPbkBatchOperationObserver& aObserver ); |
|
284 MVPbkContactOperation* CreateMatchPhoneNumberOperationL( |
|
285 const TDesC& aPhoneNumber, |
|
286 TInt aMaxMatchDigits, |
|
287 MVPbkContactFindObserver& aObserver ); |
|
288 MVPbkContactOperation* CreateFindOperationL( |
|
289 const TDesC& aSearchString, |
|
290 const MVPbkFieldTypeList& aFieldTypes, |
|
291 MVPbkContactFindObserver& aObserver ); |
|
292 MVPbkContactOperation* CreateFindOperationL( |
|
293 const MDesC16Array& aSearchStrings, |
|
294 const MVPbkFieldTypeList& aFieldTypes, |
|
295 MVPbkContactFindFromStoresObserver& aObserver, |
|
296 const TCallBack& aWordParserCallBack ); |
|
297 MVPbkContactOperation* CreateCompressStoresOperationL( |
|
298 MVPbkBatchOperationObserver& aObserver ); |
|
299 |
|
300 |
|
301 public: // Interface for VPbkCntModel component |
|
302 void AddObserverL( |
|
303 MVPbkContactStoreObserver& aObserver ); |
|
304 void RemoveObserver( |
|
305 MVPbkContactStoreObserver& aObserver ); |
|
306 TBool IsOpened() const; |
|
307 RFs& ContactStoreDomainFsSession(); |
|
308 |
|
309 private: // From MContactDbObserver |
|
310 void HandleDatabaseEventL( |
|
311 TContactDbObserverEvent aEvent ); |
|
312 |
|
313 private: // Implementation |
|
314 CContactStore( |
|
315 CContactStoreDomain& aStoreDomain ); |
|
316 void ConstructL( |
|
317 const TVPbkContactStoreUriPtr& aURI ); |
|
318 void DoOpenL( |
|
319 MVPbkContactStoreObserver& aObserver, |
|
320 TBool aReplace ); |
|
321 void OpenError( |
|
322 MVPbkContactStoreObserver& aObserver, |
|
323 TInt aError ); |
|
324 void SetStaticPropertiesL(); |
|
325 void DoAddFieldTypesL(); |
|
326 void CloseSystemTemplate( |
|
327 CContactDatabase* aContactDb ); |
|
328 CContactDatabase* OpenInternalL(); |
|
329 void DoActivateRemoteViewsL(); |
|
330 RContactViewSortOrder CreateSortOrderL( |
|
331 const MVPbkFieldTypeList& aSortOrder) const; |
|
332 TContactViewPreferences ConvertViewPrefsL(const TDesC8& aData); |
|
333 |
|
334 private: // Data |
|
335 /// Ref: Store domain |
|
336 CContactStoreDomain& iStoreDomain; |
|
337 /// Own: URI of this store |
|
338 CVPbkContactStoreUri* iStoreURI; |
|
339 /// Own: Store properties |
|
340 CVPbkContactStoreProperties* iProperties; |
|
341 /// Own: Stores asynchronous operation |
|
342 CVPbkAsyncObjectOperation<MVPbkContactStoreObserver>* iAsyncOpenOp; |
|
343 /// Own: Store observers |
|
344 RPointerArray<MVPbkContactStoreObserver> iObservers; |
|
345 /// Own: Contact database for this store |
|
346 CContactDatabase* iContactDb; |
|
347 /// Own: Contact database change notifier |
|
348 CContactChangeNotifier* iDbNotifier; |
|
349 /// Own: Virtual Phonebook to contact model field type mapping |
|
350 CFieldFactory* iFieldFactory; |
|
351 /// Own: Asynchronous operation |
|
352 CAsyncContactOperation* iAsyncContactOperation; |
|
353 /// Own: Field info of Contacts Model fields |
|
354 CFieldsInfo* iFieldsInfo; |
|
355 /// Own: the store info |
|
356 CContactStoreInfo* iStoreInfo; |
|
357 /// Own: Golden template contact item |
|
358 CContactItem* iSysTemplate; |
|
359 /// Own: Disk space checker |
|
360 VPbkEngUtils::CVPbkDiskSpaceCheck* iDiskSpaceCheck; |
|
361 /// Own: named remote view container |
|
362 RPointerArray<CNamedRemoteViewHandle> iNamedViewContainer; |
|
363 }; |
|
364 |
|
365 |
|
366 // INLINE FUNCTIONS |
|
367 |
|
368 inline CContactDatabase& CContactStore::NativeDatabase() const |
|
369 { |
|
370 __ASSERT_DEBUG( iContactDb, ContactStorePanic( EPreCond_NativeDatabase ) ); |
|
371 return *iContactDb; |
|
372 } |
|
373 |
|
374 } /// namespace VPbkCntModel |
|
375 |
|
376 #endif // VPBKCNTMODEL_CCONTACTSTORE_H |
|
377 |
|
378 //End of File |
|
379 |
|
380 |