1 /* |
|
2 * Copyright (c) 2002 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: |
|
15 * This is the implementation of the class defined in CCnvConverter.h |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include <s32strm.h> |
|
22 #include <barsread.h> |
|
23 |
|
24 #include "CCnvConverter.h" |
|
25 #include "CCnvCategory.h" |
|
26 #include "TCnvCategory.h" |
|
27 |
|
28 |
|
29 EXPORT_C CCnvConverter::~CCnvConverter() |
|
30 { |
|
31 iCategoryArray.ResetAndDestroy(); |
|
32 } |
|
33 |
|
34 EXPORT_C CCnvConverter* CCnvConverter::NewL( TResourceReader& aReader ) |
|
35 { |
|
36 CCnvConverter* self = new( ELeave ) CCnvConverter; |
|
37 CleanupStack::PushL( self ); |
|
38 self->ConstructFromResourceL( aReader ); |
|
39 CleanupStack::Pop(); // self; |
|
40 |
|
41 return self; |
|
42 } |
|
43 |
|
44 void CCnvConverter::ConstructFromResourceL( TResourceReader& aReader ) |
|
45 { |
|
46 iModelVersion = aReader.ReadInt16(); |
|
47 iCurrencyCategory = aReader.ReadInt16(); |
|
48 iCurrencyCategory = iCurrencyCategory ; |
|
49 |
|
50 TUint numCategories( aReader.ReadInt16() ); |
|
51 |
|
52 for( TUint i = 0; i < numCategories ; i++ ) |
|
53 { |
|
54 if(i == iCurrencyCategory) |
|
55 { |
|
56 CCnvCategory* category = CCnvCategory::NewLC( aReader, ETrue ); // Load Currency |
|
57 iCategoryArray.AppendL( category ); |
|
58 CleanupStack::Pop(); // category |
|
59 } |
|
60 else |
|
61 { |
|
62 CCnvCategory* category = CCnvCategory::NewLC( aReader ); |
|
63 iCategoryArray.AppendL( category ); |
|
64 CleanupStack::Pop(); // category |
|
65 } |
|
66 } |
|
67 } |
|
68 |
|
69 TInt CCnvConverter::MdcaCount() const |
|
70 { |
|
71 return iCategoryArray.Count(); |
|
72 } |
|
73 |
|
74 TPtrC CCnvConverter::MdcaPoint( TInt aIndex ) const |
|
75 { |
|
76 return TPtrC( iCategoryArray.At( aIndex )->Name() ); |
|
77 } |
|
78 |
|
79 EXPORT_C void CCnvConverter::GetCategoryAccessor( TCnvCategory& aCategory, |
|
80 TUint aCategoryIndex ) |
|
81 { |
|
82 aCategory = TCnvCategory( iCategoryArray.At( aCategoryIndex ) ); |
|
83 } |
|
84 |
|
85 EXPORT_C void CCnvConverter::GetCategorylistAccessor( |
|
86 TCnvCategory& aCategory ) |
|
87 { |
|
88 aCategory = TCnvCategory( this ); |
|
89 } |
|
90 |
|
91 EXPORT_C TUint CCnvConverter::CurrencyCategoryId() const |
|
92 { |
|
93 return iCurrencyCategory; |
|
94 } |
|
95 |
|
96 // Store the data in a stream. |
|
97 EXPORT_C void CCnvConverter::ExternalizeL( RWriteStream& aStream ) const |
|
98 { |
|
99 // Write the current model version |
|
100 aStream.WriteUint32L( iModelVersion ); |
|
101 |
|
102 // Write the current model language variant |
|
103 aStream.WriteUint32L( User::Language() ); |
|
104 |
|
105 // Save out the currency category as a whole |
|
106 CCnvCategory* category = iCategoryArray.At( iCurrencyCategory ); |
|
107 category->ExternalizeL( aStream ); |
|
108 |
|
109 // Save |
|
110 TUint len( iCategoryArray.Count() ); |
|
111 for( TUint i = 0; i < len; i++ ) |
|
112 { |
|
113 TUint aSrc( 0 ), aDst( 0 ); |
|
114 category = iCategoryArray.At( i ); |
|
115 category->GetDefaultUnits( aSrc, aDst ); |
|
116 aStream.WriteUint8L( aSrc ); |
|
117 aStream.WriteUint8L( aDst ); |
|
118 } |
|
119 } |
|
120 |
|
121 // Recover the data from a stream. |
|
122 EXPORT_C void CCnvConverter::InternalizeL( RReadStream& aStream ) |
|
123 { |
|
124 TUint version( aStream.ReadUint32L() ); |
|
125 if( version != iModelVersion ) |
|
126 { |
|
127 User::Leave( KErrCorrupt ); |
|
128 } |
|
129 TInt language( aStream.ReadUint32L() ); |
|
130 language = language; // suppress compiler warnings |
|
131 /*if( language != User::Language() ) |
|
132 { |
|
133 User::Leave( KErrCorrupt ); |
|
134 } |
|
135 */ |
|
136 // Read in the currency category as a whole |
|
137 CCnvCategory* category = iCategoryArray.At( iCurrencyCategory ); |
|
138 category->InternalizeL( aStream ); |
|
139 |
|
140 TUint len( iCategoryArray.Count() ); |
|
141 for( TUint i = 0; i < len; i++ ) |
|
142 { |
|
143 TUint src( aStream.ReadUint8L() ); |
|
144 TUint dst( aStream.ReadUint8L() ); |
|
145 category = iCategoryArray.At( i ); |
|
146 category->SetDefaultUnits( src, dst ); |
|
147 } |
|
148 } |
|
149 |
|
150 |
|
151 void CCnvConverter::SkipCategoriesL( TInt aCount, TResourceReader& aReader ) |
|
152 { |
|
153 for( TInt i = 0; i < aCount; i++ ) |
|
154 { |
|
155 CCnvCategory::NewLC( aReader ); |
|
156 CleanupStack::PopAndDestroy(); |
|
157 } |
|
158 } |
|
159 |
|
160 // End of File |
|