|
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 #include "mcsdef.h" |
|
18 #include "menuengobject.h" |
|
19 #include "mcsmenuitem.h" |
|
20 #include "menueng.h" |
|
21 #include "centralrepository.h" |
|
22 |
|
23 // ================= LOCAL FUNCTIONS ======================= |
|
24 |
|
25 /** |
|
26 * Check if this is a valid attribute name. Leave with KErrArgument if not. |
|
27 * We don't accept whitespace or exotic characters anywhere, and also |
|
28 * forbid setting reserved attribute "flags". |
|
29 */ |
|
30 LOCAL_C void CheckAttrNameL( const TDesC& aAttrName ) |
|
31 { |
|
32 if ( !aAttrName.Length() ) |
|
33 { |
|
34 User::Leave( KErrArgument ); |
|
35 } |
|
36 if ( KMenuAttrFlags() == aAttrName || KMenuAttrId() == aAttrName ) |
|
37 { |
|
38 // Internal attributes, disallow. |
|
39 User::Leave( KErrArgument ); |
|
40 } |
|
41 for ( TInt i = 0; i < aAttrName.Length(); i++ ) |
|
42 { |
|
43 TChar c = aAttrName[i]; |
|
44 if ( !c.IsAlphaDigit() && |
|
45 '_' != c && |
|
46 '-' != c && |
|
47 ':' != c ) |
|
48 { |
|
49 User::Leave( KErrArgument ); |
|
50 } |
|
51 } |
|
52 } |
|
53 |
|
54 // ================= MEMBER FUNCTIONS ======================= |
|
55 |
|
56 // --------------------------------------------------------- |
|
57 // CMenuEngObject::~CMenuEngObject |
|
58 // --------------------------------------------------------- |
|
59 // |
|
60 EXPORT_C CMenuEngObject::~CMenuEngObject() |
|
61 { |
|
62 iAttributes.ResetAndDestroy(); |
|
63 iType.Close(); |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------- |
|
67 // CMenuEngObject::NewL |
|
68 // --------------------------------------------------------- |
|
69 // |
|
70 CMenuEngObject* CMenuEngObject::NewL |
|
71 ( CMenuEng& aEng, const TDesC& aType ) |
|
72 { |
|
73 CMenuEngObject* obj = new (ELeave) CMenuEngObject( aEng ); |
|
74 CleanupStack::PushL( obj ); |
|
75 obj->ConstructL( aType ); |
|
76 CleanupStack::Pop( obj ); |
|
77 return obj; |
|
78 } |
|
79 |
|
80 // --------------------------------------------------------- |
|
81 // CMenuEngObject::CMenuEngObject |
|
82 // --------------------------------------------------------- |
|
83 // |
|
84 CMenuEngObject::CMenuEngObject( CMenuEng& aEng ): iEng( aEng ), iNative( ETrue ) |
|
85 { |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------- |
|
89 // CMenuEngObject::ConstructL |
|
90 // --------------------------------------------------------- |
|
91 // |
|
92 void CMenuEngObject::ConstructL( const TDesC& aType ) |
|
93 { |
|
94 CGECODefaultObject::BaseConstructL( aType ); |
|
95 iType.CreateL( aType ); |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------- |
|
99 // CMenuEngObject::Id |
|
100 // --------------------------------------------------------- |
|
101 // |
|
102 EXPORT_C TInt CMenuEngObject::Id() const |
|
103 { |
|
104 return iId; |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------- |
|
108 // CMenuEngObject::Flags |
|
109 // --------------------------------------------------------- |
|
110 // |
|
111 EXPORT_C TUint32 CMenuEngObject::Flags( TBool aFactoryCall ) const |
|
112 { |
|
113 TUint32 flags = iFlags; |
|
114 //if hidden flag is not set, we check it in central repository |
|
115 if( !aFactoryCall ) |
|
116 { |
|
117 TRAP_IGNORE( UpdateCrHiddenFlagL( flags ) ); |
|
118 } |
|
119 return flags; |
|
120 } |
|
121 |
|
122 |
|
123 // --------------------------------------------------------- |
|
124 // CMenuEngObject::UpdateCrHiddenFlagL |
|
125 // --------------------------------------------------------- |
|
126 // |
|
127 void CMenuEngObject::UpdateCrHiddenFlagL( TUint32& aFlags ) const |
|
128 { |
|
129 if ( iType == KMenuTypeFolder() && !( iFlags & TMenuItem::EHidden ) ) |
|
130 { |
|
131 TBool localized; |
|
132 TPtrC folderName(KNullDesC); |
|
133 TBool exists = FindAttribute( KMenuAttrAppGroupName, folderName, localized ); |
|
134 |
|
135 if ( exists && IsInCrL( folderName ) ) |
|
136 { |
|
137 aFlags |= TMenuItem::EHidden; |
|
138 } |
|
139 } |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------- |
|
143 // CMenuEngObject::ParseHiddenFoldersL |
|
144 // --------------------------------------------------------- |
|
145 // |
|
146 void CMenuEngObject::ParseHiddenFoldersL( |
|
147 const TDesC& aHiddenFolders, |
|
148 RArray<TPtrC>& aHiddenFoldersArray ) const |
|
149 { |
|
150 TLex input( aHiddenFolders ); |
|
151 TLexMark startMark; |
|
152 input.Mark( startMark ); |
|
153 TBool notEmpty = EFalse; |
|
154 while ( !input.Eos() ) |
|
155 { |
|
156 if( input.Peek() == ',') |
|
157 { |
|
158 User::LeaveIfError( aHiddenFoldersArray. |
|
159 Append( input.MarkedToken( startMark ) ) ); |
|
160 input.Inc(); |
|
161 input.Mark( startMark ); |
|
162 } |
|
163 input.Inc(); |
|
164 notEmpty = ETrue; |
|
165 } |
|
166 if ( notEmpty ) |
|
167 { |
|
168 User::LeaveIfError( aHiddenFoldersArray. |
|
169 Append( input.MarkedToken( startMark ) ) ); |
|
170 } |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------- |
|
174 // CMenuEngObject::IsInCrL |
|
175 // --------------------------------------------------------- |
|
176 // |
|
177 TBool CMenuEngObject::IsInCrL( const TDesC& aFolderName ) const |
|
178 { |
|
179 RBuf hiddenCRFolders; |
|
180 CleanupClosePushL( hiddenCRFolders ); |
|
181 hiddenCRFolders.CreateL( KCenRepBufferSize ); |
|
182 |
|
183 CRepository* cenRepSession = CRepository::NewLC( KCRUidMenu ); |
|
184 cenRepSession->Get( KMenuHideCPFolder, hiddenCRFolders ); |
|
185 CleanupStack::PopAndDestroy( cenRepSession ); |
|
186 |
|
187 RArray<TPtrC> hiddenFoldersArray; |
|
188 CleanupClosePushL( hiddenFoldersArray ); |
|
189 ParseHiddenFoldersL( hiddenCRFolders, hiddenFoldersArray ); |
|
190 |
|
191 TBool result(EFalse); |
|
192 TInt id = hiddenFoldersArray.Find(aFolderName); |
|
193 if (KErrNotFound != id ) |
|
194 { |
|
195 TPtrC folderName(KNullDesC); |
|
196 folderName.Set( hiddenFoldersArray[id] ); |
|
197 if (folderName == aFolderName) |
|
198 { |
|
199 result = ETrue; |
|
200 } |
|
201 } |
|
202 |
|
203 CleanupStack::PopAndDestroy( &hiddenFoldersArray ); |
|
204 CleanupStack::PopAndDestroy( &hiddenCRFolders ); |
|
205 |
|
206 return result; |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------- |
|
210 // CMenuEngObject::Type |
|
211 // --------------------------------------------------------- |
|
212 // |
|
213 EXPORT_C TPtrC CMenuEngObject::Type() const |
|
214 { |
|
215 return iType; |
|
216 } |
|
217 |
|
218 // --------------------------------------------------------- |
|
219 // CMenuEngObject::NumAttributes |
|
220 // --------------------------------------------------------- |
|
221 // |
|
222 TInt CMenuEngObject::NumAttributes() const |
|
223 { |
|
224 return iAttributes.Count(); |
|
225 } |
|
226 |
|
227 // --------------------------------------------------------- |
|
228 // CMenuEngObject::GetAttribute |
|
229 // --------------------------------------------------------- |
|
230 // |
|
231 EXPORT_C TBool CMenuEngObject::GetAttribute |
|
232 ( TInt aIndex, TPtrC& aName, TPtrC& aValue, TBool& aLocalized ) const |
|
233 { |
|
234 if( aIndex < 0 || aIndex >= iAttributes.Count() ) |
|
235 { |
|
236 return EFalse; |
|
237 } |
|
238 CMenuEngObjectAttr* attr = iAttributes[aIndex]; |
|
239 aName.Set( attr->Name() ); |
|
240 aValue.Set( attr->Value() ); |
|
241 aLocalized = attr->Localized(); |
|
242 return ETrue; |
|
243 } |
|
244 |
|
245 // --------------------------------------------------------- |
|
246 // CMenuEngObject::FindAttribute |
|
247 // --------------------------------------------------------- |
|
248 // |
|
249 EXPORT_C TBool CMenuEngObject::FindAttribute |
|
250 ( const TDesC& aName, TPtrC& aValue, TBool& aLocalized ) const |
|
251 { |
|
252 TInt i = iAttributes.Find( aName ); |
|
253 if ( KErrNotFound != i ) |
|
254 { |
|
255 CMenuEngObjectAttr* attr = iAttributes[i]; |
|
256 aValue.Set( attr->Value() ); |
|
257 aLocalized = attr->Localized(); |
|
258 return ETrue; |
|
259 } |
|
260 return EFalse; |
|
261 } |
|
262 |
|
263 // --------------------------------------------------------- |
|
264 // CMenuEngObject::SetFlags |
|
265 // --------------------------------------------------------- |
|
266 // |
|
267 EXPORT_C void CMenuEngObject::SetFlags( TUint32 aMask, TBool aOn ) |
|
268 { |
|
269 if ( aOn ) |
|
270 { |
|
271 iFlags |= aMask; |
|
272 } |
|
273 else |
|
274 { |
|
275 iFlags &= ~aMask; |
|
276 } |
|
277 } |
|
278 |
|
279 // ---------------------------------------------------------------------------- |
|
280 // CMenuEngObject::SetAttributeL |
|
281 // Menu item lock flags are checked (e.g. can rename), but only when the |
|
282 // current SetAttributeL call is not made from the object factories. |
|
283 // If it is called from there, no flags checking is made. |
|
284 // This method is called from object factories when the engine is in |
|
285 // ELoadRamFile or ELoadRomFile states. |
|
286 // ---------------------------------------------------------------------------- |
|
287 // |
|
288 EXPORT_C void CMenuEngObject::SetAttributeL |
|
289 ( const TDesC& aAttrName, const TDesC& aAttrValue, TBool aLocalized ) |
|
290 { |
|
291 SetInitialAttributeL( aAttrName, aAttrValue, aLocalized ); |
|
292 CGECODefaultObject::RemoveAttribute( aAttrName ); |
|
293 CGECODefaultObject::SetAttributeL( aAttrName, aAttrValue, aLocalized ); |
|
294 } |
|
295 |
|
296 void CMenuEngObject::SetInitialAttributeL |
|
297 ( const TDesC& aAttrName, const TDesC& aAttrValue, TBool aLocalized ) |
|
298 { |
|
299 CheckAttrNameL( aAttrName ); |
|
300 |
|
301 if ( iEng.State() != CMenuEng::ELoadRamFile && |
|
302 iEng.State() != CMenuEng::ELoadRomFile && |
|
303 Flags() & TMenuItem::ELockName && |
|
304 ( 0 == aAttrName.Compare( KMenuAttrShortName ) || |
|
305 0 == aAttrName.Compare( KMenuAttrLongName ) || |
|
306 0 == aAttrName.Compare( KMenuAttrTitleName ) ) ) |
|
307 { |
|
308 User::Leave( KErrAccessDenied ); |
|
309 } |
|
310 |
|
311 CMenuEngObjectAttr* attr = NULL; |
|
312 TInt i = iAttributes.Find( aAttrName ); |
|
313 if ( KErrNotFound == i ) |
|
314 { |
|
315 attr = CMenuEngObjectAttr::NewLC( aAttrName ); |
|
316 iAttributes.AppendL( attr ); |
|
317 CleanupStack::Pop( attr ); |
|
318 } |
|
319 else |
|
320 { |
|
321 attr = iAttributes[i]; |
|
322 } |
|
323 __ASSERT_DEBUG( attr, User::Invariant() ); |
|
324 attr->SetValueL( aAttrValue ); |
|
325 attr->SetLocalized( aLocalized ); |
|
326 } |
|
327 |
|
328 // --------------------------------------------------------- |
|
329 // CMenuEngObject::SetNative |
|
330 // --------------------------------------------------------- |
|
331 // |
|
332 EXPORT_C void CMenuEngObject::SetNative( TBool aNative ) |
|
333 { |
|
334 iNative = aNative; |
|
335 } |
|
336 |
|
337 // --------------------------------------------------------- |
|
338 // CMenuEngObject::GetNative |
|
339 // --------------------------------------------------------- |
|
340 // |
|
341 EXPORT_C TBool CMenuEngObject::GetNative() const |
|
342 { |
|
343 return iNative; |
|
344 } |
|
345 |
|
346 // --------------------------------------------------------- |
|
347 // CMenuEngObject::RemoveAttribute |
|
348 // --------------------------------------------------------- |
|
349 // |
|
350 EXPORT_C void CMenuEngObject::RemoveAttribute( const TDesC& aName ) |
|
351 { |
|
352 TInt i = iAttributes.Find( aName ); |
|
353 if ( KErrNotFound != i ) |
|
354 { |
|
355 delete iAttributes[i]; |
|
356 iAttributes.Remove( i ); |
|
357 CGECODefaultObject::RemoveAttribute( aName ); |
|
358 } |
|
359 } |
|
360 |
|
361 // --------------------------------------------------------- |
|
362 // CMenuEngObject::Reset |
|
363 // --------------------------------------------------------- |
|
364 // |
|
365 EXPORT_C void CMenuEngObject::Reset() |
|
366 { |
|
367 iAttributes.ResetAndDestroy(); |
|
368 iFlags = 0; |
|
369 } |
|
370 |
|
371 // --------------------------------------------------------- |
|
372 // CMenuEngObject::SetId |
|
373 // --------------------------------------------------------- |
|
374 // |
|
375 void CMenuEngObject::SetId( TInt aId ) |
|
376 { |
|
377 iId = aId; |
|
378 } |
|
379 |
|
380 // --------------------------------------------------------- |
|
381 // CMenuEngObject::Engine |
|
382 // --------------------------------------------------------- |
|
383 // |
|
384 CMenuEng& CMenuEngObject::Engine() |
|
385 { |
|
386 return iEng; |
|
387 } |
|
388 |
|
389 // --------------------------------------------------------- |
|
390 // CMenuEngObject::TypeIdentifier |
|
391 // --------------------------------------------------------- |
|
392 // |
|
393 const TDesC& CMenuEngObject::TypeIdentifier() |
|
394 { |
|
395 return iType; |
|
396 } |
|
397 |
|
398 // End of File |