|
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 "menuengobjectfactory.h" |
|
21 #include "menuengobject.h" |
|
22 #include "menuengflags.h" |
|
23 |
|
24 // ================= MEMBER FUNCTIONS ======================= |
|
25 |
|
26 // --------------------------------------------------------- |
|
27 // CMenuEngObjectFactory::~CMenuEngObjectFactory |
|
28 // --------------------------------------------------------- |
|
29 // |
|
30 CMenuEngObjectFactory::~CMenuEngObjectFactory() |
|
31 { |
|
32 } |
|
33 |
|
34 // --------------------------------------------------------- |
|
35 // CMenuEngObjectFactory::NewL |
|
36 // --------------------------------------------------------- |
|
37 // |
|
38 CMenuEngObjectFactory* CMenuEngObjectFactory::NewL( CMenuEng& aEng ) |
|
39 { |
|
40 CMenuEngObjectFactory* factory = |
|
41 new (ELeave) CMenuEngObjectFactory( aEng ); |
|
42 return factory; |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------- |
|
46 // CMenuEngObjectFactory::CMenuEngObjectFactory |
|
47 // --------------------------------------------------------- |
|
48 // |
|
49 CMenuEngObjectFactory::CMenuEngObjectFactory( CMenuEng& aEng ) |
|
50 : iEng( aEng ) |
|
51 { |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------- |
|
55 // CMenuEngObjectFactory::GetContentObjectAndSetContextL |
|
56 // --------------------------------------------------------- |
|
57 // |
|
58 CGECOObjectBase* CMenuEngObjectFactory::GetContentObjectAndSetContextL |
|
59 ( const TDesC& aTypeIdentifier ) |
|
60 { |
|
61 // Notes: |
|
62 // Here we create an object for all nodes, even for the ones we don't know. |
|
63 // (We can't check the type because of extensibility). |
|
64 // This is a problem, as not all XML nodes are part of the menu structure, |
|
65 // for example the "appshell:data" is not. |
|
66 // |
|
67 // Is it a solution to use an *exclusion* list of types here?? |
|
68 CMenuEngObject* object = CMenuEngObject::NewL( iEng, aTypeIdentifier ); |
|
69 SetContext( object ); |
|
70 return object; |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------- |
|
74 // CMenuEngObjectFactory::InitializeObjectL |
|
75 // --------------------------------------------------------- |
|
76 // |
|
77 void CMenuEngObjectFactory::InitializeObjectL |
|
78 ( MGECOAttributeProvider& aAttributeProvider ) |
|
79 { |
|
80 if ( iContext ) |
|
81 { |
|
82 CMenuEngObject* context = (CMenuEngObject*)iContext; |
|
83 TPtrC name; |
|
84 TPtrC value; |
|
85 TBool localized; |
|
86 context->Reset(); |
|
87 const TInt count = aAttributeProvider.NumAttributes(); |
|
88 for ( TInt i = 0; i < count; i++ ) |
|
89 { |
|
90 aAttributeProvider.AttributeDetailsL( i, name, value, localized ); |
|
91 if ( KMenuAttrId() == name ) |
|
92 { |
|
93 // "id" -> internal attribute, convert to integer. |
|
94 context->SetId( MenuEngId::AsInt( value ) ); |
|
95 } |
|
96 else if ( KMenuAttrFlags() == name ) |
|
97 { |
|
98 // "flags" -> internal attribute, convert to integer. |
|
99 context->SetFlags( MenuEngFlags::AsInt( value ), ETrue ); |
|
100 CGECODefaultObject* defaultContext = (CGECODefaultObject*)context; |
|
101 defaultContext->RemoveAttribute(KMenuAttrFlags); |
|
102 } |
|
103 else |
|
104 { |
|
105 // Other attributes stored normally, in the object. |
|
106 context->SetInitialAttributeL( name, value, localized ); |
|
107 } |
|
108 } |
|
109 } |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------- |
|
113 // CMenuEngObjectFactory::SetContext |
|
114 // --------------------------------------------------------- |
|
115 // |
|
116 TInt CMenuEngObjectFactory::SetContext( CGECOObjectBase* aContext ) |
|
117 { |
|
118 iContext = aContext; |
|
119 return KErrNone; |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------- |
|
123 // CMenuEngObjectFactory::NumAttributes |
|
124 // --------------------------------------------------------- |
|
125 // |
|
126 TInt CMenuEngObjectFactory::NumAttributes() |
|
127 { |
|
128 TInt count = 0; |
|
129 if ( iContext ) |
|
130 { |
|
131 count = 1; // We always have the ID. |
|
132 CMenuEngObject* context = (CMenuEngObject*)iContext; |
|
133 count += context->NumAttributes(); |
|
134 if ( context->Flags( ETrue ) ) |
|
135 { |
|
136 // Flags, if any, are written to XML as an attribute |
|
137 // named "flags". |
|
138 // The object cannot have an attribute with that name. |
|
139 count++; |
|
140 } |
|
141 } |
|
142 return count; |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------- |
|
146 // CMenuEngObjectFactory::AttributeDetailsL |
|
147 // --------------------------------------------------------- |
|
148 // |
|
149 void CMenuEngObjectFactory::AttributeDetailsL( |
|
150 const TInt aIndex, |
|
151 TPtrC& aAttrName, |
|
152 TPtrC& aAttrValue, |
|
153 TBool& aIsLocalized ) |
|
154 { |
|
155 if ( iContext ) |
|
156 { |
|
157 CMenuEngObject* context = (CMenuEngObject*)iContext; |
|
158 if ( aIndex < context->NumAttributes() ) |
|
159 { |
|
160 // External attributes retrieved normally, from the object. |
|
161 (void)context->GetAttribute |
|
162 ( aIndex, aAttrName, aAttrValue, aIsLocalized ); |
|
163 } |
|
164 else if ( aIndex == context->NumAttributes() ) |
|
165 { |
|
166 // "id" -> internal attribute, convert to string. |
|
167 MenuEngId::AsString( context->Id(), iBuf ); |
|
168 aAttrName.Set( KMenuAttrId() ); |
|
169 aAttrValue.Set( iBuf ); |
|
170 aIsLocalized = EFalse; |
|
171 } |
|
172 else |
|
173 { |
|
174 // "flags" -> internal attribute, convert to string. |
|
175 __ASSERT_DEBUG( context->Flags( ETrue ), User::Invariant() ); |
|
176 MenuEngFlags::AsString( context->Flags( ETrue ), iBuf ); |
|
177 aAttrName.Set( KMenuAttrFlags() ); |
|
178 aAttrValue.Set( iBuf ); |
|
179 aIsLocalized = EFalse; |
|
180 } |
|
181 } |
|
182 } |
|
183 |
|
184 // --------------------------------------------------------- |
|
185 // CMenuEngObjectFactory::AttributeDetailsL |
|
186 // --------------------------------------------------------- |
|
187 // |
|
188 void CMenuEngObjectFactory::AttributeDetailsL( |
|
189 const TInt aIndex, |
|
190 TPtrC& aAttrName, |
|
191 TPtrC& aAttrValue ) |
|
192 { |
|
193 CGECODefaultObjectFactory::AttributeDetailsL( aIndex, aAttrName, aAttrValue); |
|
194 } |
|
195 |
|
196 // --------------------------------------------------------- |
|
197 // CMenuEngObjectFactory::HasTextData |
|
198 // --------------------------------------------------------- |
|
199 // |
|
200 TBool CMenuEngObjectFactory::HasTextData() |
|
201 { |
|
202 return EFalse; |
|
203 } |
|
204 |
|
205 // --------------------------------------------------------- |
|
206 // CMenuEngObjectFactory::TextDetailsL |
|
207 // --------------------------------------------------------- |
|
208 // |
|
209 void CMenuEngObjectFactory::TextDetailsL |
|
210 ( TPtrC& /*aText*/, TBool& /*aIsLocalized*/ ) |
|
211 { |
|
212 } |
|
213 |
|
214 // End of File |