|
1 /* |
|
2 * Copyright (c) 2007-2008 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 * |
|
16 */ |
|
17 |
|
18 #include <xmlengdom.h> |
|
19 #include <liwservicehandler.h> |
|
20 #include <hnmdbasekey.h> |
|
21 #include <hnconvutils.h> |
|
22 |
|
23 #include "hnmdvaluetext.h" |
|
24 #include "hnglobals.h" |
|
25 #include "hnmdmodel.h" |
|
26 #include "hnliwutils.h" |
|
27 #include "hnutils.h" |
|
28 #include "hnstringhandler.h" |
|
29 #include "hnattributetext.h" |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 CHnMdValueText* CHnMdValueText::NewL( |
|
36 const TXmlEngElement& aElement, THnMdCommonPointers* aCmnPtrs ) |
|
37 { |
|
38 CHnMdValueText* self = |
|
39 new (ELeave)CHnMdValueText(); |
|
40 CleanupStack::PushL(self); |
|
41 self->ConstructL( aElement, aCmnPtrs ); |
|
42 CleanupStack::Pop(self); |
|
43 return self; |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 void CHnMdValueText::ConstructL( const TXmlEngElement& aElement, |
|
51 THnMdCommonPointers* aCmnPtrs ) |
|
52 { |
|
53 iCmnPtrs = aCmnPtrs; |
|
54 |
|
55 if ( !aElement.Name().Compare( KTextElementItem8 ) ) |
|
56 { |
|
57 // handle text node |
|
58 HnUtils::SetAttributeL( aElement, KResourceAttrName8 , iResourceFile ); |
|
59 HnUtils::SetAttributeL( aElement, KIdAttrName8 , iResourceId ); |
|
60 HnUtils::SetAttributeL( aElement, KValueAttrName8 , iSimpleValue); |
|
61 |
|
62 if ( aElement.HasChildNodes() ) |
|
63 { |
|
64 iParameters = new(ELeave)CDesC8ArraySeg(1); |
|
65 iCachedDesParameters = new(ELeave)CDesC16ArraySeg(1); |
|
66 iCachedIntParameters = new(ELeave)CArrayFixSeg<TInt>(1); |
|
67 // get child element from output and pass to set value |
|
68 RXmlEngNodeList< TXmlEngElement > childElements; |
|
69 CleanupClosePushL( childElements ); |
|
70 aElement.GetChildElements( childElements ); |
|
71 TInt amount = childElements.Count(); |
|
72 |
|
73 for (TInt i(0); i<amount; i++) |
|
74 { |
|
75 TXmlEngElement child = childElements.Next(); |
|
76 RBuf8 tmp; |
|
77 CleanupClosePushL(tmp); |
|
78 HnUtils::SetAttributeL( child, KValueAttrName8 , tmp); |
|
79 if (tmp.Length() > 0) |
|
80 { |
|
81 iParameters->AppendL( tmp ); |
|
82 } |
|
83 CleanupStack::PopAndDestroy( &tmp ); |
|
84 } |
|
85 CleanupStack::PopAndDestroy( &childElements ); |
|
86 } |
|
87 } |
|
88 else |
|
89 { |
|
90 // it can accept element that have text define in element node |
|
91 // or value attribute |
|
92 if ( iSimpleValue.Length() == 0 ) |
|
93 { |
|
94 HnUtils::SetAttributeL( aElement, KValueAttrName8 , iSimpleValue ); |
|
95 } |
|
96 HnUtils::SetAttributeL(aElement, iSimpleValue); |
|
97 } |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 CHnMdValueText::CHnMdValueText() |
|
105 { |
|
106 // No implementation required |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 CHnMdValueText::~CHnMdValueText() |
|
114 { |
|
115 iSimpleValue.Close(); |
|
116 iResourceFile.Close(); |
|
117 iResourceId.Close(); |
|
118 iCachedValue.Close(); |
|
119 delete iParameters; |
|
120 delete iCachedDesParameters; |
|
121 delete iCachedIntParameters; |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 void CHnMdValueText::FillParamsL( const CLiwGenericParamList* aQueryList, |
|
129 TInt aPos, |
|
130 CDesC16Array& aDesParams, |
|
131 CArrayFix<TInt>& aNumericParams) |
|
132 { |
|
133 if (iParameters) |
|
134 { |
|
135 // remove old values |
|
136 aDesParams.Reset(); |
|
137 aNumericParams.Reset(); |
|
138 |
|
139 for (TInt i(0); i < iParameters->Count(); i++) |
|
140 { |
|
141 TLiwVariant value; |
|
142 CleanupStack::PushL( |
|
143 TCleanupItem( TLiwVariant::VariantCleanup , &value) ); |
|
144 |
|
145 HnLiwUtils::GetVariantL( *aQueryList, |
|
146 iParameters->MdcaPoint(i), |
|
147 aPos, |
|
148 value ); |
|
149 |
|
150 if ( value.TypeId() == LIW::EVariantTypeTInt32 ) |
|
151 { |
|
152 aNumericParams.AppendL( value.AsTInt32() ); |
|
153 } |
|
154 else if ( value.TypeId() == LIW::EVariantTypeTUint ) |
|
155 { |
|
156 aNumericParams.AppendL( value.AsTUint() ); |
|
157 } |
|
158 else if ( value.TypeId() == LIW::EVariantTypeTBool ) |
|
159 { |
|
160 aNumericParams.AppendL( value.AsTBool() ); |
|
161 } |
|
162 else if ( value.TypeId() == LIW::EVariantTypeTTime ) |
|
163 { |
|
164 // PW add time formating |
|
165 } |
|
166 else if ( value.TypeId() != LIW::EVariantTypeNull ) |
|
167 { |
|
168 RBuf vbuf; |
|
169 CleanupClosePushL(vbuf); |
|
170 HnLiwUtils::VariantToStringL( value, vbuf ); |
|
171 aDesParams.AppendL(vbuf); |
|
172 CleanupStack::PopAndDestroy(&vbuf); |
|
173 } |
|
174 CleanupStack::PopAndDestroy(&value); |
|
175 } |
|
176 } |
|
177 } |
|
178 |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 TInt CHnMdValueText::GetFromResourceFileL( |
|
185 const CLiwGenericParamList* aParamList, TInt aPos, RBuf& aValue ) |
|
186 { |
|
187 TInt retFile(KErrNotFound); |
|
188 TInt retId(KErrNotFound); |
|
189 RBuf resourceFile; |
|
190 RBuf resourceId; |
|
191 |
|
192 CleanupClosePushL(resourceFile); |
|
193 CleanupClosePushL(resourceId); |
|
194 |
|
195 retFile = HnLiwUtils::GetStringL( *aParamList, iResourceFile, aPos, resourceFile ); |
|
196 retId = HnLiwUtils::GetStringL( *aParamList, iResourceId, aPos, resourceId ); |
|
197 if ( retFile != KErrBadDescriptor && retId != KErrBadDescriptor ) |
|
198 { |
|
199 RBuf resourceName; |
|
200 CleanupClosePushL(resourceName); |
|
201 resourceName.CreateL( resourceFile.Length()+ 1 + resourceId.Length() ); |
|
202 // concatenate resource file with id, localization understands it |
|
203 resourceName.Append(resourceFile); |
|
204 resourceName.Append(KColon); |
|
205 resourceName.Append(resourceId); |
|
206 |
|
207 FillParamsL( aParamList, aPos, *iCachedDesParameters, |
|
208 *iCachedIntParameters); |
|
209 |
|
210 HnStringHandler::LocaliseL( aValue, resourceName, |
|
211 iCachedDesParameters, iCachedIntParameters, iCmnPtrs ); |
|
212 |
|
213 CleanupStack::PopAndDestroy(&resourceName); |
|
214 } |
|
215 |
|
216 CleanupStack::PopAndDestroy(&resourceId); |
|
217 CleanupStack::PopAndDestroy(&resourceFile); |
|
218 |
|
219 return (retFile != KErrNone) ? retFile : retId; |
|
220 } |
|
221 |
|
222 // --------------------------------------------------------------------------- |
|
223 // |
|
224 // --------------------------------------------------------------------------- |
|
225 // |
|
226 TInt CHnMdValueText::GetSimpleValueL( |
|
227 const CLiwGenericParamList* aParamList, TInt aPos, RBuf& /*aValue*/ ) |
|
228 { |
|
229 TInt ret(KErrNotFound); |
|
230 RBuf vbuf; |
|
231 CleanupClosePushL(vbuf); |
|
232 |
|
233 ret = HnLiwUtils::GetStringL( *aParamList, iSimpleValue, aPos, vbuf ); |
|
234 if ( ret != KErrNotFound ) |
|
235 { |
|
236 FillParamsL( aParamList, aPos, *iCachedDesParameters, |
|
237 *iCachedIntParameters); |
|
238 |
|
239 HnStringHandler::LocaliseL( iCachedValue, vbuf, iCachedDesParameters, |
|
240 iCachedIntParameters, iCmnPtrs ); |
|
241 } |
|
242 CleanupStack::PopAndDestroy(&vbuf); |
|
243 return ret; |
|
244 } |
|
245 |
|
246 // --------------------------------------------------------------------------- |
|
247 // |
|
248 // --------------------------------------------------------------------------- |
|
249 // |
|
250 TInt CHnMdValueText::GetL( |
|
251 const CLiwGenericParamList* aParamList, TInt aPos, |
|
252 TPtrC& aValue ) |
|
253 { |
|
254 TInt ret(KErrNone); |
|
255 iCachedValue.Close(); |
|
256 // first let's check resource file and id |
|
257 if (iResourceFile.Length() > 0 && iResourceId.Length() > 0) |
|
258 { |
|
259 ret = GetFromResourceFileL(aParamList, aPos, iCachedValue); |
|
260 } |
|
261 // if still cached value is empty, let's try with simple value |
|
262 if (iSimpleValue.Length() > 0 && iCachedValue.Length() == 0 ) |
|
263 { |
|
264 ret = GetSimpleValueL(aParamList, aPos, iCachedValue); |
|
265 } |
|
266 |
|
267 aValue.Set(iCachedValue); |
|
268 return ret; |
|
269 } |
|
270 // --------------------------------------------------------------------------- |
|
271 // |
|
272 // --------------------------------------------------------------------------- |
|
273 // |
|
274 CHnAttributeBase* CHnMdValueText::CreateAttributeL( |
|
275 const CLiwGenericParamList* aQueriesResultsList, |
|
276 TInt aPos ) |
|
277 { |
|
278 CHnAttributeText* attr = 0; |
|
279 TPtrC val; |
|
280 if( GetL(aQueriesResultsList, aPos, val) != KErrNotFound ) |
|
281 { |
|
282 attr = CHnAttributeText::NewLC(); |
|
283 HBufC8* bufVal( HnConvUtils::StrToStr8LC( val ) ); |
|
284 attr->SetValueL( *bufVal ); |
|
285 |
|
286 // clean up |
|
287 CleanupStack::PopAndDestroy( bufVal ); |
|
288 CleanupStack::Pop( attr ); |
|
289 } |
|
290 return attr; |
|
291 } |
|
292 |