|
1 /* |
|
2 * Copyright (c) 2004-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: Maps a Contact Model databases to a virtual Phonebook contact. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 #include "CContactStoreDomain.h" |
|
21 |
|
22 #include "CFieldTypeMap.h" |
|
23 #include "CAsyncContactOperation.h" |
|
24 #include "CContact.h" |
|
25 #include "CContactLink.h" |
|
26 #include "CContactView.h" |
|
27 #include "CContactStore.h" |
|
28 |
|
29 #include <CVPbkContactStoreList.h> |
|
30 #include <cvpbkcontactoperationfactory.h> |
|
31 #include <CVPbkContactStoreUri.h> |
|
32 #include <CVPbkContactStoreUriArray.h> |
|
33 #include <CVPbkAsyncOperation.h> |
|
34 #include <MVPbkContactStoreObserver.h> |
|
35 #include <RLocalizedResourceFile.h> |
|
36 #include <VPbkUtil.h> |
|
37 #include <VPbkDataCaging.hrh> |
|
38 #include <VPbkCntModelRes.rsg> |
|
39 #include <VPbkStoreUriLiterals.h> |
|
40 |
|
41 #include <cntdb.h> |
|
42 #include <cntitem.h> |
|
43 #include <barsc.h> |
|
44 #include <barsread.h> |
|
45 #include <shareddataclient.h> |
|
46 |
|
47 namespace VPbkCntModel { |
|
48 |
|
49 // LOCAL |
|
50 namespace { |
|
51 |
|
52 // CONSTANTS |
|
53 _LIT(KVPbkCntModelResFile, "VPbkCntModelRes.rsc"); |
|
54 |
|
55 } // unnamed namespace |
|
56 |
|
57 CContactStoreDomain::CContactStoreDomain(const MVPbkFieldTypeList& aMasterFieldTypeList) : |
|
58 iMasterFieldTypeList(aMasterFieldTypeList) |
|
59 { |
|
60 } |
|
61 |
|
62 inline void CContactStoreDomain::ConstructL( |
|
63 const CVPbkContactStoreUriArray& aURIList, |
|
64 const TDesC& aURIDomain, |
|
65 CFieldTypeMap* aFieldTypeMap) |
|
66 { |
|
67 User::LeaveIfError(iFs.Connect()); |
|
68 |
|
69 RProcess process; |
|
70 if ( process.HasCapability(ECapabilityReadDeviceData, ECapabilityWriteDeviceData, |
|
71 __PLATSEC_DIAGNOSTIC_STRING("Virtual Phonebook client missing capabilities to \ |
|
72 free disk space during compress/delete operations")) ) |
|
73 { |
|
74 // Shared data objects have to created after connecting RFs, |
|
75 // but before reading resources |
|
76 iSharedDataClient = new (ELeave) RSharedDataClient; |
|
77 User::LeaveIfError( iSharedDataClient->Connect() ); |
|
78 } |
|
79 |
|
80 if (!aFieldTypeMap) |
|
81 { |
|
82 iTextStore = new(ELeave) VPbkEngUtils::CTextStore; |
|
83 |
|
84 // load Versit field type mappings |
|
85 VPbkEngUtils::RLocalizedResourceFile resFile; |
|
86 |
|
87 resFile.OpenLC(iFs, KVPbkRomFileDrive, KDC_RESOURCE_FILES_DIR, KVPbkCntModelResFile); |
|
88 |
|
89 iFieldTypeMap = VPbkCntModel::CFieldTypeMap::NewL(iMasterFieldTypeList, *iTextStore); |
|
90 TResourceReader resReader; |
|
91 // initialize the field type map with versit name mapping data |
|
92 resReader.SetBuffer(resFile.AllocReadLC(R_VERSIT_NAME_FIELD_TYPE_MAPPINGS)); |
|
93 iFieldTypeMap->InitVersitNameMappingsL(resReader); |
|
94 CleanupStack::PopAndDestroy(); // R_VERSIT_NAME_FIELD_TYPE_MAPPINGS buffer |
|
95 |
|
96 // initialize the field type map with versit parameter mapping data |
|
97 resReader.SetBuffer(resFile.AllocReadLC(R_VERSIT_PARAM_FIELD_TYPE_MAPPINGS)); |
|
98 iFieldTypeMap->InitVersitParameterMappingsL(resReader); |
|
99 CleanupStack::PopAndDestroy(); // R_VERSIT_PARAM_FIELD_TYPE_MAPPINGS buffer |
|
100 |
|
101 // initialize the field type map with non versit field type mapping data |
|
102 resReader.SetBuffer(resFile.AllocReadLC(R_NONVERSIT_FIELD_TYPE_MAPPINGS)); |
|
103 iFieldTypeMap->InitNonVersitMappingsL(resReader); |
|
104 CleanupStack::PopAndDestroy(2); |
|
105 } |
|
106 |
|
107 // Create the store list |
|
108 iContactStoreList = CVPbkContactStoreList::NewL(); |
|
109 // Load all Contacts Model stores |
|
110 TVPbkContactStoreUriPtr defaultDb( KVPbkDefaultCntDbURI ); |
|
111 const TPtrC domain = defaultDb.Component( |
|
112 TVPbkContactStoreUriPtr::EContactStoreUriStoreType ); |
|
113 const TInt uriCount = aURIList.Count(); |
|
114 for (TInt i = 0; i < uriCount; ++i) |
|
115 { |
|
116 if ( aURIList[i].Compare( domain, |
|
117 TVPbkContactStoreUriPtr::EContactStoreUriStoreType ) == 0 ) |
|
118 { |
|
119 LoadContactStoreL( aURIList[i] ); |
|
120 } |
|
121 } |
|
122 |
|
123 // Create multioperation factory |
|
124 iOperationFactory = CVPbkContactOperationFactory::NewL( |
|
125 *iContactStoreList ); |
|
126 |
|
127 iDomainDescriptor = aURIDomain.AllocL(); |
|
128 |
|
129 // Take ownership of aFieldTypeMap in the end as described in the header. |
|
130 if (aFieldTypeMap) |
|
131 { |
|
132 iFieldTypeMap = aFieldTypeMap; |
|
133 } |
|
134 } |
|
135 |
|
136 CContactStoreDomain* CContactStoreDomain::NewL |
|
137 (const CVPbkContactStoreUriArray& aURIList, |
|
138 const TDesC& aURIDomain, |
|
139 const MVPbkFieldTypeList& aMasterFieldTypeList, |
|
140 CFieldTypeMap* aFieldTypeMap) |
|
141 { |
|
142 CContactStoreDomain* self = new(ELeave) CContactStoreDomain(aMasterFieldTypeList); |
|
143 CleanupStack::PushL(self); |
|
144 self->ConstructL(aURIList, aURIDomain, aFieldTypeMap); |
|
145 CleanupStack::Pop(self); |
|
146 return self; |
|
147 } |
|
148 |
|
149 CContactStoreDomain* CContactStoreDomain::NewL( |
|
150 TAny* aParam) |
|
151 { |
|
152 TStoreDomainParam* param = static_cast<TStoreDomainParam*>(aParam); |
|
153 return NewL(param->iURIList, *param->iURIDomain, *param->iFieldTypeList, NULL); |
|
154 } |
|
155 |
|
156 CContactStoreDomain::~CContactStoreDomain() |
|
157 { |
|
158 delete iDomainDescriptor; |
|
159 delete iOperationFactory; |
|
160 delete iContactStoreList; |
|
161 delete iFieldTypeMap; |
|
162 delete iTextStore; |
|
163 |
|
164 if ( iSharedDataClient ) |
|
165 { |
|
166 iSharedDataClient->Close(); |
|
167 } |
|
168 delete iSharedDataClient; |
|
169 |
|
170 iFs.Close(); |
|
171 } |
|
172 |
|
173 const TDesC& CContactStoreDomain::UriDomain() const |
|
174 { |
|
175 return *iDomainDescriptor; |
|
176 } |
|
177 |
|
178 void CContactStoreDomain::LoadContactStoreL(const TVPbkContactStoreUriPtr& aUri) |
|
179 { |
|
180 if (!Find(aUri)) |
|
181 { |
|
182 CContactStore* store = CContactStore::NewL(aUri, *this); |
|
183 CleanupStack::PushL(store); |
|
184 iContactStoreList->AppendL(store); |
|
185 CleanupStack::Pop(store); |
|
186 } |
|
187 } |
|
188 |
|
189 TInt CContactStoreDomain::Count() const |
|
190 { |
|
191 return iContactStoreList->Count(); |
|
192 } |
|
193 |
|
194 MVPbkContactStore& CContactStoreDomain::At(TInt aIndex) const |
|
195 { |
|
196 return iContactStoreList->At(aIndex); |
|
197 } |
|
198 |
|
199 MVPbkContactStore* CContactStoreDomain::Find(const TVPbkContactStoreUriPtr& aUri) const |
|
200 { |
|
201 return iContactStoreList->Find(aUri); |
|
202 } |
|
203 |
|
204 void CContactStoreDomain::OpenAllL(MVPbkContactStoreListObserver& aObserver) |
|
205 { |
|
206 iContactStoreList->OpenAllL(aObserver); |
|
207 } |
|
208 |
|
209 void CContactStoreDomain::CloseAll(MVPbkContactStoreListObserver& aObserver) |
|
210 { |
|
211 iContactStoreList->CloseAll(aObserver); |
|
212 } |
|
213 |
|
214 MVPbkContactOperation* CContactStoreDomain::CreateContactRetrieverL |
|
215 (const MVPbkContactLink& aLink, |
|
216 MVPbkSingleContactOperationObserver& aObserver) |
|
217 { |
|
218 // test if aLink is in fact a instance of this domain |
|
219 MVPbkContactOperation* operation = NULL; |
|
220 if (CContactLink::Matches(*iDomainDescriptor, aLink, |
|
221 TVPbkContactStoreUriPtr::EContactStoreUriStoreType)) |
|
222 { |
|
223 operation = iOperationFactory->CreateContactRetrieverL(aLink, aObserver); |
|
224 } |
|
225 return operation; |
|
226 } |
|
227 |
|
228 MVPbkContactOperation* CContactStoreDomain::CreateDeleteContactsOperationL( |
|
229 const MVPbkContactLinkArray& aContactLinks, |
|
230 MVPbkBatchOperationObserver& aObserver) |
|
231 { |
|
232 return iOperationFactory->CreateDeleteContactsOperationL( aContactLinks, |
|
233 aObserver); |
|
234 } |
|
235 |
|
236 MVPbkContactOperation* CContactStoreDomain::CreateCommitContactsOperationL( |
|
237 const TArray<MVPbkStoreContact*>& aContacts, |
|
238 MVPbkBatchOperationObserver& aObserver) |
|
239 { |
|
240 return iOperationFactory->CreateCommitContactsOperationL( aContacts, |
|
241 aObserver ); |
|
242 } |
|
243 |
|
244 MVPbkContactOperation* CContactStoreDomain::CreateMatchPhoneNumberOperationL( |
|
245 const TDesC& aPhoneNumber, |
|
246 TInt aMaxMatchDigits, |
|
247 MVPbkContactFindObserver& aObserver) |
|
248 { |
|
249 return iOperationFactory->CreateMatchPhoneNumberOperationL( aPhoneNumber, |
|
250 aMaxMatchDigits, aObserver ); |
|
251 } |
|
252 |
|
253 MVPbkContactOperation* CContactStoreDomain::CreateFindOperationL( |
|
254 const TDesC& aSearchString, |
|
255 const MVPbkFieldTypeList& aFieldTypes, |
|
256 MVPbkContactFindObserver& aObserver) |
|
257 { |
|
258 return iOperationFactory->CreateFindOperationL( aSearchString, |
|
259 aFieldTypes, aObserver ); |
|
260 } |
|
261 |
|
262 MVPbkContactOperation* CContactStoreDomain::CreateFindOperationL( |
|
263 const MDesC16Array& aSearchStrings, |
|
264 const MVPbkFieldTypeList& aFieldTypes, |
|
265 MVPbkContactFindFromStoresObserver& aObserver, |
|
266 const TCallBack& aWordParserCallBack ) |
|
267 { |
|
268 return iOperationFactory->CreateFindOperationL( aSearchStrings, |
|
269 aFieldTypes, aObserver, aWordParserCallBack ); |
|
270 } |
|
271 |
|
272 |
|
273 TAny* CContactStoreDomain::ContactOperationFactoryExtension( TUid aExtensionUid ) |
|
274 { |
|
275 if ( aExtensionUid == KMVPbkContactOperationFactory2Uid ) |
|
276 { |
|
277 return static_cast<MVPbkContactOperationFactory2*>( this ); |
|
278 } |
|
279 return NULL; |
|
280 } |
|
281 |
|
282 |
|
283 MVPbkContactOperation* CContactStoreDomain::CreateFindOperationL( |
|
284 const MDesC16Array& aSearchStrings, |
|
285 const MVPbkFieldTypeList& aFieldTypes, |
|
286 MVPbkContactFindFromStoresObserver& aObserver, |
|
287 const TCallBack& aWordParserCallBack, |
|
288 const CDesC16ArrayFlat& aStoreEntriesArray ) |
|
289 { |
|
290 return iOperationFactory->CreateFindOperationL( aSearchStrings, |
|
291 aFieldTypes, aObserver, aWordParserCallBack, aStoreEntriesArray ); |
|
292 } |
|
293 |
|
294 MVPbkContactOperation* CContactStoreDomain::CreateCompressStoresOperationL( |
|
295 MVPbkBatchOperationObserver& aObserver) |
|
296 { |
|
297 return iOperationFactory->CreateCompressStoresOperationL( aObserver ); |
|
298 } |
|
299 |
|
300 } // namespace VPbkCntModel |
|
301 //End of file |