|
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: A class that reads an array of PSU2_COPY_TO_SIM_FIELDTYPE_INFO |
|
15 * items |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include "CPsu2CopyToSimFieldInfoArray.h" |
|
23 |
|
24 #include <RPbk2LocalizedResourceFile.h> |
|
25 #include <Pbk2DataCaging.hrh> |
|
26 #include <Pbk2USimUIRes.rsg> |
|
27 #include <Pbk2CommonUi.rsg> |
|
28 |
|
29 #include <TVPbkFieldTypeMapping.h> |
|
30 #include <CVPbkFieldTypeSelector.h> |
|
31 #include <MVPbkFieldType.h> |
|
32 |
|
33 #include <coemain.h> |
|
34 #include <barsread.h> |
|
35 #include <gsmerror.h> |
|
36 |
|
37 #include <VPbkEng.rsg> |
|
38 |
|
39 namespace |
|
40 { |
|
41 |
|
42 _LIT(KPsu2USimExtensionResFile, "Pbk2USimUIRes.rsc"); |
|
43 |
|
44 // ============================= LOCAL FUNCTIONS =============================== |
|
45 |
|
46 #ifdef _DEBUG |
|
47 enum TPanicCode |
|
48 { |
|
49 EPostCond_ConstructL, |
|
50 EPostCond_CreateMappingsL |
|
51 }; |
|
52 |
|
53 void Panic(TInt aReason) |
|
54 { |
|
55 _LIT(KPanicText, "SimFieldInfoArray"); |
|
56 User::Panic(KPanicText, aReason); |
|
57 } |
|
58 #endif // _DEBUG |
|
59 } |
|
60 |
|
61 /** |
|
62 * A class that can read PSU2_COPY_TO_SIM_FIELDTYPE_MAPPING resource |
|
63 * structure from Pbk2USimUi.rh |
|
64 */ |
|
65 class CPsu2CopyToSimFieldtypeMapping : public CBase |
|
66 { |
|
67 public: |
|
68 |
|
69 /** |
|
70 * @param aReader a resource reader to |
|
71 * PSU2_COPY_TO_SIM_FIELDTYPE_MAPPING. |
|
72 * @param aMasterFieldTypeList all field types from CVPbkContactManager |
|
73 */ |
|
74 static CPsu2CopyToSimFieldtypeMapping* NewLC( |
|
75 TResourceReader& aReader, |
|
76 const MVPbkFieldTypeList& aMasterFieldTypeList ); |
|
77 |
|
78 // Destructor |
|
79 ~CPsu2CopyToSimFieldtypeMapping(); |
|
80 |
|
81 /** |
|
82 * The selector for the source field types. |
|
83 * |
|
84 * @return The selector for the source field types. |
|
85 */ |
|
86 MVPbkFieldTypeSelector& SourceTypeSelector() const; |
|
87 |
|
88 /** |
|
89 * Returns the resource id (VPbkEng.rsg) of the target field type. |
|
90 * |
|
91 * @return the resource id (VPbkEng.rsg) of the target field type. |
|
92 */ |
|
93 TInt TargetFieldtypeResId() const; |
|
94 |
|
95 /** |
|
96 * Returns flags defined Pbk2UsimUi.hrh |
|
97 * |
|
98 * @return flags defined Pbk2UsimUi.hrh |
|
99 */ |
|
100 TUint8 Flags() const; |
|
101 |
|
102 /** |
|
103 * @return TPsu2ErrorCode that causes this sim field type |
|
104 * to be blocked. |
|
105 */ |
|
106 TUint8 BlockingError() const; |
|
107 |
|
108 private: |
|
109 void ConstructL( TResourceReader& aReader, |
|
110 const MVPbkFieldTypeList& aMasterFieldTypeList ); |
|
111 |
|
112 private: // Data |
|
113 /// Own: source field type selector |
|
114 CVPbkFieldTypeSelector* iSourceTypeSelector; |
|
115 /// Own: target field type resource id (VPbkEng.rsg) |
|
116 TInt iTargetFieldTypeResId; |
|
117 /// Flags from Pbk2UsimUi.hrh |
|
118 TUint8 iFlags; |
|
119 /// See TPsu2ErrorCode |
|
120 TUint8 iBlockingError; |
|
121 }; |
|
122 |
|
123 // ============================ MEMBER FUNCTIONS =============================== |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // TPsu2CopyToSimFieldInfo::TPsu2CopyToSimFieldInfo |
|
127 // C++ default constructor can NOT contain any code, that |
|
128 // might leave. |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 TPsu2CopyToSimFieldInfo::TPsu2CopyToSimFieldInfo( |
|
132 const MVPbkFieldType& aSourceType, |
|
133 const MVPbkFieldType& aSimType, |
|
134 TUint8 aFlags, |
|
135 TUint8 aBlockingError ) |
|
136 : iSourceType( aSourceType ), |
|
137 iSimType( aSimType ), |
|
138 iFlags( aFlags ), |
|
139 iBlockingError( aBlockingError ) |
|
140 { |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CPsu2CopyToSimFieldtypeMapping::NewLC |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 CPsu2CopyToSimFieldtypeMapping* CPsu2CopyToSimFieldtypeMapping::NewLC( |
|
148 TResourceReader& aReader, |
|
149 const MVPbkFieldTypeList& aMasterFieldTypeList ) |
|
150 { |
|
151 CPsu2CopyToSimFieldtypeMapping* self = |
|
152 new( ELeave ) CPsu2CopyToSimFieldtypeMapping; |
|
153 CleanupStack::PushL( self ); |
|
154 self->ConstructL( aReader, aMasterFieldTypeList ); |
|
155 return self; |
|
156 } |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // CPsu2CopyToSimFieldtypeMapping::ConstructL |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 void CPsu2CopyToSimFieldtypeMapping::ConstructL( TResourceReader& aReader, |
|
163 const MVPbkFieldTypeList& aMasterFieldTypeList ) |
|
164 { |
|
165 iSourceTypeSelector = CVPbkFieldTypeSelector::NewL( aReader, |
|
166 aMasterFieldTypeList ); |
|
167 iTargetFieldTypeResId = aReader.ReadInt32(); |
|
168 iFlags = aReader.ReadUint8(); |
|
169 iBlockingError = aReader.ReadUint8(); |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CPsu2CopyToSimFieldtypeMapping::~CPsu2CopyToSimFieldtypeMapping |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 CPsu2CopyToSimFieldtypeMapping::~CPsu2CopyToSimFieldtypeMapping() |
|
177 { |
|
178 delete iSourceTypeSelector; |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CPsu2CopyToSimFieldtypeMapping::SourceTypeSelector |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 MVPbkFieldTypeSelector& CPsu2CopyToSimFieldtypeMapping::SourceTypeSelector() const |
|
186 { |
|
187 return *iSourceTypeSelector; |
|
188 } |
|
189 |
|
190 // ----------------------------------------------------------------------------- |
|
191 // CPsu2CopyToSimFieldtypeMapping::TargetFieldtypeResId |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 TInt CPsu2CopyToSimFieldtypeMapping::TargetFieldtypeResId() const |
|
195 { |
|
196 return iTargetFieldTypeResId; |
|
197 } |
|
198 |
|
199 // ----------------------------------------------------------------------------- |
|
200 // CPsu2CopyToSimFieldtypeMapping::Flags |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 TUint8 CPsu2CopyToSimFieldtypeMapping::Flags() const |
|
204 { |
|
205 return iFlags; |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CPsu2CopyToSimFieldtypeMapping::BlockingError |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 TUint8 CPsu2CopyToSimFieldtypeMapping::BlockingError() const |
|
213 { |
|
214 return iBlockingError; |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CPsu2CopyToSimFieldInfoArray::CPsu2CopyToSimFieldInfoArray |
|
219 // C++ default constructor can NOT contain any code, that |
|
220 // might leave. |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 CPsu2CopyToSimFieldInfoArray::CPsu2CopyToSimFieldInfoArray( |
|
224 const MVPbkFieldTypeList& aMasterFieldTypeList) |
|
225 : iMasterFieldTypeList(aMasterFieldTypeList) |
|
226 { |
|
227 } |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // CPsu2CopyToSimFieldInfoArray::ConstructL |
|
231 // Symbian 2nd phase constructor can leave. |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 void CPsu2CopyToSimFieldInfoArray::ConstructL( RFs& aFs ) |
|
235 { |
|
236 // Open USIM extension resource file for reading field mappings. |
|
237 // This class can be used from SIM copy policy so it must not |
|
238 // depend on CCoeEnv in anyway. |
|
239 RPbk2LocalizedResourceFile resFile( &aFs ); |
|
240 resFile.OpenLC(KPbk2RomFileDrive, |
|
241 KDC_RESOURCE_FILES_DIR, KPsu2USimExtensionResFile); |
|
242 |
|
243 TResourceReader reader; |
|
244 reader.SetBuffer( |
|
245 resFile.AllocReadLC( R_PSU2_COPY_TO_SIM_FIELDTYPE_MAPPINGS ) ); |
|
246 |
|
247 // Go through all mappings in resource and create a mapping array |
|
248 const TInt count = reader.ReadInt16(); |
|
249 for ( TInt i = 0; i < count; ++i ) |
|
250 { |
|
251 CPsu2CopyToSimFieldtypeMapping* cmapping = |
|
252 CPsu2CopyToSimFieldtypeMapping::NewLC( reader, |
|
253 iMasterFieldTypeList ); |
|
254 CreateMappingsL( *cmapping ); |
|
255 CleanupStack::PopAndDestroy( cmapping ); |
|
256 } |
|
257 CleanupStack::PopAndDestroy(); // R_PSU2_COPY_TO_SIM_FIELDTYPE_MAPPINGS |
|
258 |
|
259 // Valid characters for number fields. |
|
260 // Note: StringLoader can not be used in this class because it depends |
|
261 // on CCoeEnv. This class can be run in non-UI context because |
|
262 // CPsu2ContactCopyPolicy uses this class. |
|
263 reader.SetBuffer( |
|
264 resFile.AllocReadLC( R_PSU2_STANDARD_NUMBER_CHARACTER_MAP ) ); |
|
265 iNumberKeyMap = reader.ReadHBufCL(); |
|
266 // R_PSU2_STANDARD_NUMBER_CHARACTER_MAP, resFile |
|
267 CleanupStack::PopAndDestroy(2); |
|
268 |
|
269 // Get SIM name field type. This must be the same type as the type |
|
270 // defined in VPbkSimStore |
|
271 iSimNameType = iMasterFieldTypeList.Find( R_VPBK_FIELD_TYPE_LASTNAME ); |
|
272 iSimReadingType = |
|
273 iMasterFieldTypeList.Find( R_VPBK_FIELD_TYPE_LASTNAMEREADING ); |
|
274 |
|
275 __ASSERT_DEBUG( iSimNameType && iSimReadingType, |
|
276 Panic( EPostCond_ConstructL ) ); |
|
277 } |
|
278 |
|
279 // ----------------------------------------------------------------------------- |
|
280 // CPsu2CopyToSimFieldInfoArray::NewL |
|
281 // Two-phased constructor. |
|
282 // ----------------------------------------------------------------------------- |
|
283 // |
|
284 CPsu2CopyToSimFieldInfoArray* CPsu2CopyToSimFieldInfoArray::NewL( |
|
285 const MVPbkFieldTypeList& aMasterFieldTypeList, RFs& aFs ) |
|
286 { |
|
287 CPsu2CopyToSimFieldInfoArray* self = |
|
288 new( ELeave ) CPsu2CopyToSimFieldInfoArray(aMasterFieldTypeList); |
|
289 CleanupStack::PushL( self ); |
|
290 self->ConstructL( aFs ); |
|
291 CleanupStack::Pop(); |
|
292 return self; |
|
293 } |
|
294 |
|
295 |
|
296 // Destructor |
|
297 CPsu2CopyToSimFieldInfoArray::~CPsu2CopyToSimFieldInfoArray() |
|
298 { |
|
299 iInfoArray.Close(); |
|
300 iMatchedTypes.Close(); |
|
301 delete iNumberKeyMap; |
|
302 } |
|
303 |
|
304 // ----------------------------------------------------------------------------- |
|
305 // CPsu2CopyToSimFieldInfoArray::FindInfoForSourceType |
|
306 // ----------------------------------------------------------------------------- |
|
307 // |
|
308 const TPsu2CopyToSimFieldInfo* |
|
309 CPsu2CopyToSimFieldInfoArray::FindInfoForSourceType( |
|
310 const MVPbkFieldType& aSourceType ) |
|
311 { |
|
312 const TPsu2CopyToSimFieldInfo* result = NULL; |
|
313 const TInt count = iInfoArray.Count(); |
|
314 for (TInt i = 0; i < count && !result; ++i) |
|
315 { |
|
316 if (iInfoArray[i].SourceType().IsSame( aSourceType ) ) |
|
317 { |
|
318 result = &iInfoArray[i]; |
|
319 } |
|
320 } |
|
321 return result; |
|
322 } |
|
323 |
|
324 // ----------------------------------------------------------------------------- |
|
325 // CPsu2CopyToSimFieldInfoArray::SimNameType |
|
326 // ----------------------------------------------------------------------------- |
|
327 // |
|
328 const MVPbkFieldType& CPsu2CopyToSimFieldInfoArray::SimNameType() const |
|
329 { |
|
330 return *iSimNameType; |
|
331 } |
|
332 |
|
333 // ----------------------------------------------------------------------------- |
|
334 // CPsu2CopyToSimFieldInfoArray::LastNameReadingType |
|
335 // ----------------------------------------------------------------------------- |
|
336 // |
|
337 const MVPbkFieldType& CPsu2CopyToSimFieldInfoArray::LastNameReadingType() const |
|
338 { |
|
339 return *iSimReadingType; |
|
340 } |
|
341 |
|
342 // ----------------------------------------------------------------------------- |
|
343 // CPsu2CopyToSimFieldInfoArray::ConvertToSimType |
|
344 // ----------------------------------------------------------------------------- |
|
345 // |
|
346 const MVPbkFieldType* CPsu2CopyToSimFieldInfoArray::ConvertToSimType( |
|
347 const MVPbkFieldType& aSourceType) |
|
348 { |
|
349 const TInt count = iInfoArray.Count(); |
|
350 for (TInt i = 0; i < count; ++i) |
|
351 { |
|
352 if (iInfoArray[i].SourceType().IsSame(aSourceType)) |
|
353 { |
|
354 return &iInfoArray[i].SimType(); |
|
355 } |
|
356 } |
|
357 return NULL; |
|
358 } |
|
359 |
|
360 // ----------------------------------------------------------------------------- |
|
361 // CPsu2CopyToSimFieldInfoArray::TruncationAllowed |
|
362 // ----------------------------------------------------------------------------- |
|
363 // |
|
364 TBool CPsu2CopyToSimFieldInfoArray::TruncationAllowed( |
|
365 const MVPbkFieldType& aSimType ) |
|
366 { |
|
367 const TInt count = iInfoArray.Count(); |
|
368 for ( TInt i = 0; i < count; ++i ) |
|
369 { |
|
370 if ( iInfoArray[i].SimType().IsSame( aSimType ) ) |
|
371 { |
|
372 return iInfoArray[i].TruncationAllowed(); |
|
373 } |
|
374 } |
|
375 return EFalse; |
|
376 } |
|
377 |
|
378 // ----------------------------------------------------------------------------- |
|
379 // CPsu2CopyToSimFieldInfoArray::NumberKeyMap |
|
380 // ----------------------------------------------------------------------------- |
|
381 // |
|
382 const TDesC& CPsu2CopyToSimFieldInfoArray::NumberKeyMap() const |
|
383 { |
|
384 return *iNumberKeyMap; |
|
385 } |
|
386 |
|
387 // ----------------------------------------------------------------------------- |
|
388 // CPsu2CopyToSimFieldInfoArray::CreateMappingsL |
|
389 // ----------------------------------------------------------------------------- |
|
390 // |
|
391 void CPsu2CopyToSimFieldInfoArray::CreateMappingsL( |
|
392 CPsu2CopyToSimFieldtypeMapping& aCMapping ) |
|
393 { |
|
394 const TInt typeCount = iMasterFieldTypeList.FieldTypeCount(); |
|
395 // First find the target type |
|
396 const MVPbkFieldType* targetType = iMasterFieldTypeList.Find( |
|
397 aCMapping.TargetFieldtypeResId() ); |
|
398 |
|
399 // Then find all source types and create mappings |
|
400 MVPbkFieldTypeSelector& selector = aCMapping.SourceTypeSelector(); |
|
401 for ( TInt i = 0; i < typeCount; ++i ) |
|
402 { |
|
403 if ( selector.IsFieldTypeIncluded( |
|
404 iMasterFieldTypeList.FieldTypeAt( i ) ) ) |
|
405 { |
|
406 TPsu2CopyToSimFieldInfo info( |
|
407 iMasterFieldTypeList.FieldTypeAt( i ), |
|
408 *targetType, aCMapping.Flags(), aCMapping.BlockingError() ); |
|
409 iInfoArray.AppendL( info ); |
|
410 } |
|
411 } |
|
412 |
|
413 // Target type must be found from master field type list. |
|
414 // If it doesn't, then either the field type list is not the |
|
415 // master field types list or the field type resource id is corrupted. |
|
416 __ASSERT_DEBUG( targetType, Panic( EPostCond_CreateMappingsL) ); |
|
417 } |
|
418 // End of File |