|
1 /* |
|
2 * Copyright (c) 2009 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 FILES |
|
19 |
|
20 #include "menuengobjectfactoryproxy.h" |
|
21 #include "menuengobjectfactory.h" |
|
22 #include "menuenglegacyobjectfactory.h" |
|
23 #include "menuengobject.h" |
|
24 |
|
25 _LIT( KLegacyTypeData, "appshell:data" ); ///< Legacy data type. |
|
26 _LIT( KMenuAttrVersion, "version" ); ///< Version attribute. |
|
27 LOCAL_D const TInt KSmallestMajorVersion = 5; |
|
28 |
|
29 // ================= MEMBER FUNCTIONS ======================= |
|
30 |
|
31 // --------------------------------------------------------- |
|
32 // CMenuEngObjectFactoryProxy::~CMenuEngObjectFactoryProxy |
|
33 // --------------------------------------------------------- |
|
34 // |
|
35 CMenuEngObjectFactoryProxy::~CMenuEngObjectFactoryProxy() |
|
36 { |
|
37 delete iLegacyFactory; |
|
38 delete iObjFactory; |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------- |
|
42 // CMenuEngObjectFactoryProxy::NewL |
|
43 // --------------------------------------------------------- |
|
44 // |
|
45 CMenuEngObjectFactoryProxy* CMenuEngObjectFactoryProxy::NewL( CMenuEng& aEng ) |
|
46 { |
|
47 CMenuEngObjectFactoryProxy* factory = |
|
48 new (ELeave) CMenuEngObjectFactoryProxy( aEng ); |
|
49 CleanupStack::PushL( factory ); |
|
50 factory->ConstructL(); |
|
51 CleanupStack::Pop( factory ); |
|
52 return factory; |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------- |
|
56 // CMenuEngObjectFactoryProxy::CMenuEngObjectFactoryProxy |
|
57 // --------------------------------------------------------- |
|
58 // |
|
59 CMenuEngObjectFactoryProxy::CMenuEngObjectFactoryProxy( CMenuEng& aEng ) |
|
60 : iEng( aEng ) |
|
61 { |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------- |
|
65 // CMenuEngObjectFactoryProxy::ConstructL |
|
66 // --------------------------------------------------------- |
|
67 // |
|
68 void CMenuEngObjectFactoryProxy::ConstructL() |
|
69 { |
|
70 iObjFactory = CMenuEngObjectFactory::NewL( iEng ); |
|
71 // iLegacyFactory is created only when needed |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------- |
|
75 // CMenuEngObjectFactoryProxy::SupportLegacyFormat |
|
76 // --------------------------------------------------------- |
|
77 // |
|
78 void CMenuEngObjectFactoryProxy::SupportLegacyFormat( TBool aSupport ) |
|
79 { |
|
80 iSupportLegacyFormat = aSupport; |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------- |
|
84 // CMenuEngObjectFactoryProxy::SupportLegacyFormat |
|
85 // --------------------------------------------------------- |
|
86 // |
|
87 TBool CMenuEngObjectFactoryProxy::IsLegacyFormat() |
|
88 { |
|
89 return iParsingInLegacyFormat; |
|
90 } |
|
91 |
|
92 |
|
93 // --------------------------------------------------------- |
|
94 // CMenuEngObjectFactoryProxy::Reset |
|
95 // --------------------------------------------------------- |
|
96 // |
|
97 void CMenuEngObjectFactoryProxy::Reset() |
|
98 { |
|
99 iSupportLegacyFormat = EFalse; |
|
100 delete iLegacyFactory; |
|
101 iLegacyFactory = 0; |
|
102 iParsingInLegacyFormat = EFalse; |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------- |
|
106 // CMenuEngObjectFactoryProxy::GetContentObjectAndSetContextL |
|
107 // Note: due to XCFW no hierarcy is seen from the factory, |
|
108 // thus it is ensured that only one 'data' node can exist. |
|
109 // --------------------------------------------------------- |
|
110 // |
|
111 CGECOObjectBase* CMenuEngObjectFactoryProxy::GetContentObjectAndSetContextL |
|
112 ( const TDesC& aTypeIdentifier ) |
|
113 { |
|
114 CGECOObjectBase* object = 0; |
|
115 if( iParsingInLegacyFormat ) |
|
116 { |
|
117 __ASSERT_DEBUG( iLegacyFactory, User::Invariant() ); |
|
118 object = iLegacyFactory->GetContentObjectAndSetContextL( aTypeIdentifier ); |
|
119 } |
|
120 else |
|
121 { |
|
122 // If there is a legacy 'data' node, it is always saved with new prefix. |
|
123 TPtrC type( aTypeIdentifier ); |
|
124 if( iSupportLegacyFormat && aTypeIdentifier == KLegacyTypeData ) |
|
125 { |
|
126 type.Set( KMenuTypeData ); |
|
127 } |
|
128 object = iObjFactory->GetContentObjectAndSetContextL( type ); |
|
129 } |
|
130 // Do not call SetContext( object ); because it forwards the call! |
|
131 iContext = object; |
|
132 return object; |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------- |
|
136 // CMenuEngObjectFactoryProxy::InitializeObjectL |
|
137 // --------------------------------------------------------- |
|
138 // |
|
139 void CMenuEngObjectFactoryProxy::InitializeObjectL |
|
140 ( MGECOAttributeProvider& aAttributeProvider ) |
|
141 { |
|
142 // check the 'data' node's version identifier. If the version is |
|
143 // less than 5.0, then the factory will function in legacy mode |
|
144 // until parsing completed (see CMenuEng::HandleEngineEventL). |
|
145 CMenuEngObject* object = (CMenuEngObject*)iContext; |
|
146 if ( iSupportLegacyFormat && object->Type() == KMenuTypeData ) |
|
147 { |
|
148 iParsingInLegacyFormat = EFalse; // By default |
|
149 TPtrC name; |
|
150 TPtrC value; |
|
151 TBool localized; |
|
152 const TInt count = aAttributeProvider.NumAttributes(); |
|
153 for ( TInt i = 0; i < count; i++ ) |
|
154 { |
|
155 aAttributeProvider.AttributeDetailsL( i, name, value, localized ); |
|
156 if ( name == KMenuAttrVersion ) |
|
157 { |
|
158 // Format is: <major>.<minor> |
|
159 TReal32 version( 0. ); |
|
160 TLex lex( value ); |
|
161 const TInt err = lex.Val( version, TChar('.') ); |
|
162 if ( !err && version < KSmallestMajorVersion ) |
|
163 { |
|
164 // Considered as legacy xml format |
|
165 if( !iLegacyFactory ) |
|
166 { |
|
167 iLegacyFactory = CMenuEngLegacyObjectFactory::NewL( iEng ); |
|
168 } |
|
169 iParsingInLegacyFormat = ETrue; |
|
170 } |
|
171 break; |
|
172 } |
|
173 } |
|
174 } |
|
175 |
|
176 CGECODefaultObjectFactory::InitializeObjectL(aAttributeProvider); |
|
177 if( iParsingInLegacyFormat ) |
|
178 { |
|
179 __ASSERT_DEBUG( iLegacyFactory, User::Invariant() ); |
|
180 iLegacyFactory->InitializeObjectL( aAttributeProvider ); |
|
181 } |
|
182 else |
|
183 { |
|
184 iObjFactory->InitializeObjectL( aAttributeProvider ); |
|
185 } |
|
186 } |
|
187 |
|
188 // --------------------------------------------------------- |
|
189 // CMenuEngObjectFactoryProxy::SetContext |
|
190 // --------------------------------------------------------- |
|
191 // |
|
192 TInt CMenuEngObjectFactoryProxy::SetContext( CGECOObjectBase* aContext ) |
|
193 { |
|
194 __ASSERT_DEBUG( !iLegacyFactory, User::Invariant() ); |
|
195 iContext = aContext; |
|
196 return iObjFactory->SetContext( aContext ); |
|
197 } |
|
198 |
|
199 // --------------------------------------------------------- |
|
200 // CMenuEngObjectFactoryProxy::NumAttributes |
|
201 // --------------------------------------------------------- |
|
202 // |
|
203 TInt CMenuEngObjectFactoryProxy::NumAttributes() |
|
204 { |
|
205 __ASSERT_DEBUG( !iLegacyFactory, User::Invariant() ); |
|
206 return iObjFactory->NumAttributes(); |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------- |
|
210 // CMenuEngObjectFactoryProxy::AttributeDetailsL |
|
211 // --------------------------------------------------------- |
|
212 // |
|
213 void CMenuEngObjectFactoryProxy::AttributeDetailsL( |
|
214 const TInt aIndex, |
|
215 TPtrC& aAttrName, |
|
216 TPtrC& aAttrValue, |
|
217 TBool& aIsLocalized ) |
|
218 { |
|
219 __ASSERT_DEBUG( !iLegacyFactory, User::Invariant() ); |
|
220 iObjFactory->AttributeDetailsL( aIndex, aAttrName, aAttrValue, aIsLocalized ); |
|
221 } |
|
222 |
|
223 // --------------------------------------------------------- |
|
224 // CMenuEngObjectFactoryProxy::AttributeDetailsL |
|
225 // --------------------------------------------------------- |
|
226 // |
|
227 void CMenuEngObjectFactoryProxy::AttributeDetailsL( |
|
228 const TInt aIndex, |
|
229 TPtrC& aAttrName, |
|
230 TPtrC& aAttrValue ) |
|
231 { |
|
232 __ASSERT_DEBUG( !iLegacyFactory, User::Invariant() ); |
|
233 TRAPD( err, CGECODefaultObjectFactory::AttributeDetailsL( |
|
234 aIndex, |
|
235 aAttrName, |
|
236 aAttrValue ) ); |
|
237 if( KErrNotFound==err ) |
|
238 { |
|
239 TBool dummy = EFalse; |
|
240 AttributeDetailsL( aIndex, aAttrName, aAttrValue, dummy ); |
|
241 } |
|
242 } |
|
243 |
|
244 // --------------------------------------------------------- |
|
245 // CMenuEngObjectFactoryProxy::HasTextData |
|
246 // --------------------------------------------------------- |
|
247 // |
|
248 TBool CMenuEngObjectFactoryProxy::HasTextData() |
|
249 { |
|
250 __ASSERT_DEBUG( !iLegacyFactory, User::Invariant() ); |
|
251 return iObjFactory->HasTextData(); |
|
252 } |
|
253 |
|
254 // --------------------------------------------------------- |
|
255 // CMenuEngObjectFactoryProxy::TextDetailsL |
|
256 // --------------------------------------------------------- |
|
257 // |
|
258 void CMenuEngObjectFactoryProxy::TextDetailsL |
|
259 ( TPtrC& aText, TBool& aIsLocalized ) |
|
260 { |
|
261 __ASSERT_DEBUG( !iLegacyFactory, User::Invariant() ); |
|
262 iObjFactory->TextDetailsL( aText, aIsLocalized ); |
|
263 } |
|
264 |
|
265 // End of File |