|
1 /* |
|
2 * Copyright (c) 2006-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: Virtual Phonebook vCard data class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CVPbkVCardData.h" |
|
20 #include "CVPbkVCardIdNameMapping.h" |
|
21 #include "CVPbkVCardFieldTypeProperty.h" |
|
22 #include "CVPbkVCardFieldTypeList.h" |
|
23 #include "CVPbkVCardOperationFactory.h" |
|
24 |
|
25 #include <CVPbkContactManager.h> |
|
26 #include <VPbkDataCaging.hrh> |
|
27 #include <VPbkVCardEng.rsg> |
|
28 #include <RLocalizedResourceFile.h> |
|
29 #include <CVPbkContactCopyPolicyManager.h> |
|
30 #include <VPbkStoreUriLiterals.h> |
|
31 #include <MVPbkContactStoreList.h> |
|
32 #include <TVPbkContactStoreUriPtr.h> |
|
33 #include <CVPbkContactStoreUriArray.h> |
|
34 #include <CVPbkContactDuplicatePolicy.h> |
|
35 #include <VPbkUtil.h> |
|
36 |
|
37 #include <barsread.h> |
|
38 #include <vcard.h> |
|
39 |
|
40 namespace |
|
41 { |
|
42 /// VCard engine default resource file |
|
43 _LIT(KVCardEngDefResFileName, "VPbkVCardEng.rsc"); |
|
44 } |
|
45 |
|
46 CVPbkVCardData::CVPbkVCardData(CVPbkContactManager& aContactManager) : |
|
47 iContactManager(aContactManager), |
|
48 iMaskedFieldsArray(NULL) |
|
49 { |
|
50 } |
|
51 |
|
52 inline void CVPbkVCardData::ConstructL() |
|
53 { |
|
54 // Open a file server session |
|
55 RFs fs; |
|
56 User::LeaveIfError(fs.Connect()); |
|
57 CleanupClosePushL(fs); |
|
58 |
|
59 // Create text store for extension names |
|
60 iTextStore = new(ELeave) VPbkEngUtils::CTextStore; |
|
61 |
|
62 VPbkEngUtils::RLocalizedResourceFile resFile; |
|
63 resFile.OpenLC( fs, |
|
64 KVPbkRomFileDrive, |
|
65 KDC_RESOURCE_FILES_DIR, |
|
66 KVCardEngDefResFileName ); |
|
67 HBufC8* fieldTypesBuf = resFile.AllocReadLC( R_VPBK_TYPE_MAPPINGS ); |
|
68 TResourceReader resReader; |
|
69 resReader.SetBuffer( fieldTypesBuf ); |
|
70 |
|
71 TInt propertyCount( resReader.ReadInt16() ); |
|
72 while (propertyCount-- > 0) |
|
73 { |
|
74 CVPbkVCardFieldTypeProperty* prop = |
|
75 CVPbkVCardFieldTypeProperty::NewLC( resReader, *iTextStore ); |
|
76 User::LeaveIfError( iProperties.Append( prop ) ); |
|
77 CleanupStack::Pop( prop ); |
|
78 } |
|
79 |
|
80 resReader.SetBuffer( |
|
81 resFile.AllocReadLC( R_VPBK_VCARD_PARAM_ID_NAME_MAPPINGS ) ); |
|
82 TInt mappingsCount( resReader.ReadInt16() ); |
|
83 while ( mappingsCount-- > 0 ) |
|
84 { |
|
85 CVPbkVCardIdNameMapping* mapping = |
|
86 CVPbkVCardIdNameMapping::NewLC( resReader ); |
|
87 User::LeaveIfError( iParamIdNameMappings.Append( mapping ) ); |
|
88 CleanupStack::Pop( mapping ); |
|
89 } |
|
90 |
|
91 resReader.SetBuffer( |
|
92 resFile.AllocReadLC( R_VPBK_VCARD_VNAME_ID_NAME_MAPPINGS ) ); |
|
93 TInt vNameMappingsCount( resReader.ReadInt16() ); |
|
94 while ( vNameMappingsCount-- > 0 ) |
|
95 { |
|
96 CVPbkVCardIdNameMapping* mapping = |
|
97 CVPbkVCardIdNameMapping::NewLC( resReader ); |
|
98 User::LeaveIfError( iVNameIdNameMappings.Append( mapping ) ); |
|
99 CleanupStack::Pop( mapping ); |
|
100 } |
|
101 |
|
102 HBufC8* dataMaskedFields = resFile.AllocReadLC(R_VPBK_VCARD_MASKED_FIELDS); |
|
103 resReader.SetBuffer(dataMaskedFields); |
|
104 iMaskedFieldsArray = resReader.ReadDesC8ArrayL(); |
|
105 CleanupStack::PopAndDestroy(dataMaskedFields); |
|
106 |
|
107 CleanupStack::PopAndDestroy(4, &resFile); |
|
108 // R_VPBK_VCARD_VNAME_ID_NAME_MAPPINGS |
|
109 // R_VPBK_VCARD_PARAMETER_ID_NAME_MAPPINGS, fieldTypesBuf, resFile |
|
110 |
|
111 CleanupStack::PopAndDestroy(); // fs |
|
112 |
|
113 iSupportedFieldTypes = |
|
114 CVPbkVCardFieldTypeList::NewLC( |
|
115 iProperties.Array(), iContactManager.FieldTypes() ); |
|
116 CleanupStack::Pop(); // iSupportedFieldTypes |
|
117 |
|
118 CVPbkContactDuplicatePolicy::TParam param( iContactManager ); |
|
119 |
|
120 iCopyPolicyManager = CVPbkContactCopyPolicyManager::NewL(); |
|
121 |
|
122 // Don leave if implementation is not found -> duplicate checking |
|
123 // is not used if there is no policy |
|
124 TRAPD( res, iDuplicatePolicy = CVPbkContactDuplicatePolicy::NewL( param )); |
|
125 if ( res != KErrNone && res != KErrNotFound ) |
|
126 { |
|
127 User::LeaveIfError( res ); |
|
128 } |
|
129 } |
|
130 |
|
131 CVPbkVCardData* CVPbkVCardData::NewL(CVPbkContactManager& aContactManager) |
|
132 { |
|
133 CVPbkVCardData* self = new(ELeave) CVPbkVCardData(aContactManager); |
|
134 CleanupStack::PushL(self); |
|
135 self->ConstructL(); |
|
136 CleanupStack::Pop(self); |
|
137 return self; |
|
138 } |
|
139 |
|
140 CVPbkVCardData::~CVPbkVCardData() |
|
141 { |
|
142 delete iCopyPolicyManager; |
|
143 iParamIdNameMappings.ResetAndDestroy(); |
|
144 iVNameIdNameMappings.ResetAndDestroy(); |
|
145 iProperties.ResetAndDestroy(); |
|
146 delete iSupportedFieldTypes; |
|
147 delete iDuplicatePolicy; |
|
148 delete iTextStore; |
|
149 delete iMaskedFieldsArray; |
|
150 } |
|
151 |
|
152 const MVPbkFieldTypeList& CVPbkVCardData::SupportedFieldTypes() const |
|
153 { |
|
154 return *iSupportedFieldTypes; |
|
155 } |
|
156 |
|
157 TArray<CVPbkVCardFieldTypeProperty*> CVPbkVCardData::Properties() const |
|
158 { |
|
159 return iProperties.Array(); |
|
160 } |
|
161 |
|
162 TArray<CVPbkVCardIdNameMapping*> CVPbkVCardData::VNameIdNameMappings() const |
|
163 { |
|
164 return iVNameIdNameMappings.Array(); |
|
165 } |
|
166 |
|
167 TArray<CVPbkVCardIdNameMapping*> CVPbkVCardData::ParamIdNameMappings() const |
|
168 { |
|
169 return iParamIdNameMappings.Array(); |
|
170 } |
|
171 |
|
172 MVPbkContactAttributeManager& CVPbkVCardData::AttributeManagerL() const |
|
173 { |
|
174 return iContactManager.ContactAttributeManagerL(); |
|
175 } |
|
176 |
|
177 MVPbkContactDuplicatePolicy* CVPbkVCardData::DuplicatePolicy() |
|
178 { |
|
179 return iDuplicatePolicy; |
|
180 } |
|
181 |
|
182 MVPbkContactCopyPolicy& CVPbkVCardData::CopyPolicyL( |
|
183 const TVPbkContactStoreUriPtr& aUri) const |
|
184 { |
|
185 MVPbkContactCopyPolicy* policy = |
|
186 iCopyPolicyManager->GetPolicyL(iContactManager,aUri); |
|
187 if (!policy) |
|
188 { |
|
189 User::Leave(KErrNotFound); |
|
190 } |
|
191 return *policy; |
|
192 } |
|
193 |
|
194 MVPbkContactStore& CVPbkVCardData::GetCntModelStoreL() |
|
195 { |
|
196 TVPbkContactStoreUriPtr uriPtr(KVPbkDefaultCntDbURI); |
|
197 MVPbkContactStore* store = iContactManager.ContactStoresL().Find(uriPtr); |
|
198 if (!store) |
|
199 { |
|
200 iContactManager.LoadContactStoreL(uriPtr); |
|
201 store = iContactManager.ContactStoresL().Find(uriPtr); |
|
202 } |
|
203 return *store; |
|
204 } |
|
205 |
|
206 const CDesC8ArrayFlat* CVPbkVCardData::GetMaskedFields() |
|
207 { |
|
208 return (const CDesC8ArrayFlat*) iMaskedFieldsArray; |
|
209 } |
|
210 CVPbkContactManager& CVPbkVCardData::GetContactManager() |
|
211 { |
|
212 return iContactManager; |
|
213 } |