|
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 ), |
|
85 iAppType( ENoTypeApp ) |
|
86 { |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------- |
|
90 // CMenuEngObject::ConstructL |
|
91 // --------------------------------------------------------- |
|
92 // |
|
93 void CMenuEngObject::ConstructL( const TDesC& aType ) |
|
94 { |
|
95 CGECODefaultObject::BaseConstructL( aType ); |
|
96 iType.CreateL( aType ); |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------- |
|
100 // CMenuEngObject::Id |
|
101 // --------------------------------------------------------- |
|
102 // |
|
103 EXPORT_C TInt CMenuEngObject::Id() const |
|
104 { |
|
105 return iId; |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------- |
|
109 // CMenuEngObject::Flags |
|
110 // --------------------------------------------------------- |
|
111 // |
|
112 EXPORT_C TUint32 CMenuEngObject::Flags( TBool aFactoryCall ) const |
|
113 { |
|
114 TUint32 flags = iFlags; |
|
115 //if hidden flag is not set, we check it in central repository |
|
116 if( !aFactoryCall ) |
|
117 { |
|
118 TRAP_IGNORE( UpdateCrHiddenFlagL( flags ) ); |
|
119 } |
|
120 return flags; |
|
121 } |
|
122 |
|
123 |
|
124 // --------------------------------------------------------- |
|
125 // CMenuEngObject::UpdateCrHiddenFlagL |
|
126 // --------------------------------------------------------- |
|
127 // |
|
128 void CMenuEngObject::UpdateCrHiddenFlagL( TUint32& aFlags ) const |
|
129 { |
|
130 if ( iType == KMenuTypeFolder() && !( iFlags & TMenuItem::EHidden ) ) |
|
131 { |
|
132 TBool localized; |
|
133 TPtrC folderName(KNullDesC); |
|
134 TBool exists = FindAttribute( KMenuAttrAppGroupName, folderName, localized ); |
|
135 |
|
136 if ( exists && IsInCrL( folderName ) ) |
|
137 { |
|
138 aFlags |= TMenuItem::EHidden; |
|
139 } |
|
140 } |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------- |
|
144 // CMenuEngObject::ParseHiddenFoldersL |
|
145 // --------------------------------------------------------- |
|
146 // |
|
147 void CMenuEngObject::ParseHiddenFoldersL( |
|
148 const TDesC& aHiddenFolders, |
|
149 RArray<TPtrC>& aHiddenFoldersArray ) const |
|
150 { |
|
151 TLex input( aHiddenFolders ); |
|
152 TLexMark startMark; |
|
153 input.Mark( startMark ); |
|
154 TBool notEmpty = EFalse; |
|
155 while ( !input.Eos() ) |
|
156 { |
|
157 if( input.Peek() == ',') |
|
158 { |
|
159 User::LeaveIfError( aHiddenFoldersArray. |
|
160 Append( input.MarkedToken( startMark ) ) ); |
|
161 input.Inc(); |
|
162 input.Mark( startMark ); |
|
163 } |
|
164 input.Inc(); |
|
165 notEmpty = ETrue; |
|
166 } |
|
167 if ( notEmpty ) |
|
168 { |
|
169 User::LeaveIfError( aHiddenFoldersArray. |
|
170 Append( input.MarkedToken( startMark ) ) ); |
|
171 } |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------- |
|
175 // CMenuEngObject::IsInCrL |
|
176 // --------------------------------------------------------- |
|
177 // |
|
178 TBool CMenuEngObject::IsInCrL( const TDesC& aFolderName ) const |
|
179 { |
|
180 RBuf hiddenCRFolders; |
|
181 CleanupClosePushL( hiddenCRFolders ); |
|
182 hiddenCRFolders.CreateL( KCenRepBufferSize ); |
|
183 |
|
184 CRepository* cenRepSession = CRepository::NewLC( KCRUidMenu ); |
|
185 cenRepSession->Get( KMenuHideCPFolder, hiddenCRFolders ); |
|
186 CleanupStack::PopAndDestroy( cenRepSession ); |
|
187 |
|
188 RArray<TPtrC> hiddenFoldersArray; |
|
189 CleanupClosePushL( hiddenFoldersArray ); |
|
190 ParseHiddenFoldersL( hiddenCRFolders, hiddenFoldersArray ); |
|
191 |
|
192 TBool result(EFalse); |
|
193 TInt id = hiddenFoldersArray.Find(aFolderName); |
|
194 if (KErrNotFound != id ) |
|
195 { |
|
196 TPtrC folderName(KNullDesC); |
|
197 folderName.Set( hiddenFoldersArray[id] ); |
|
198 if (folderName == aFolderName) |
|
199 { |
|
200 result = ETrue; |
|
201 } |
|
202 } |
|
203 |
|
204 CleanupStack::PopAndDestroy( &hiddenFoldersArray ); |
|
205 CleanupStack::PopAndDestroy( &hiddenCRFolders ); |
|
206 |
|
207 return result; |
|
208 } |
|
209 |
|
210 // --------------------------------------------------------- |
|
211 // CMenuEngObject::Type |
|
212 // --------------------------------------------------------- |
|
213 // |
|
214 EXPORT_C TPtrC CMenuEngObject::Type() const |
|
215 { |
|
216 return iType; |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------- |
|
220 // CMenuEngObject::NumAttributes |
|
221 // --------------------------------------------------------- |
|
222 // |
|
223 TInt CMenuEngObject::NumAttributes() const |
|
224 { |
|
225 return iAttributes.Count(); |
|
226 } |
|
227 |
|
228 // --------------------------------------------------------- |
|
229 // CMenuEngObject::GetAttribute |
|
230 // --------------------------------------------------------- |
|
231 // |
|
232 EXPORT_C TBool CMenuEngObject::GetAttribute |
|
233 ( TInt aIndex, TPtrC& aName, TPtrC& aValue, TBool& aLocalized ) const |
|
234 { |
|
235 if( aIndex < 0 || aIndex >= iAttributes.Count() ) |
|
236 { |
|
237 return EFalse; |
|
238 } |
|
239 CMenuEngObjectAttr* attr = iAttributes[aIndex]; |
|
240 aName.Set( attr->Name() ); |
|
241 aValue.Set( attr->Value() ); |
|
242 aLocalized = attr->Localized(); |
|
243 return ETrue; |
|
244 } |
|
245 |
|
246 // --------------------------------------------------------- |
|
247 // CMenuEngObject::FindAttribute |
|
248 // --------------------------------------------------------- |
|
249 // |
|
250 EXPORT_C TBool CMenuEngObject::FindAttribute |
|
251 ( const TDesC& aName, TPtrC& aValue, TBool& aLocalized ) const |
|
252 { |
|
253 TInt i = iAttributes.Find( aName ); |
|
254 if ( KErrNotFound != i ) |
|
255 { |
|
256 CMenuEngObjectAttr* attr = iAttributes[i]; |
|
257 aValue.Set( attr->Value() ); |
|
258 aLocalized = attr->Localized(); |
|
259 return ETrue; |
|
260 } |
|
261 return EFalse; |
|
262 } |
|
263 |
|
264 // --------------------------------------------------------- |
|
265 // CMenuEngObject::SetFlags |
|
266 // --------------------------------------------------------- |
|
267 // |
|
268 EXPORT_C void CMenuEngObject::SetFlags( TUint32 aMask, TBool aOn ) |
|
269 { |
|
270 if ( aOn ) |
|
271 { |
|
272 iFlags |= aMask; |
|
273 } |
|
274 else |
|
275 { |
|
276 iFlags &= ~aMask; |
|
277 } |
|
278 } |
|
279 |
|
280 // ---------------------------------------------------------------------------- |
|
281 // CMenuEngObject::SetAttributeL |
|
282 // Menu item lock flags are checked (e.g. can rename), but only when the |
|
283 // current SetAttributeL call is not made from the object factories. |
|
284 // If it is called from there, no flags checking is made. |
|
285 // This method is called from object factories when the engine is in |
|
286 // ELoadRamFile or ELoadRomFile states. |
|
287 // ---------------------------------------------------------------------------- |
|
288 // |
|
289 EXPORT_C void CMenuEngObject::SetAttributeL |
|
290 ( const TDesC& aAttrName, const TDesC& aAttrValue, TBool aLocalized ) |
|
291 { |
|
292 SetInitialAttributeL( aAttrName, aAttrValue, aLocalized ); |
|
293 CGECODefaultObject::RemoveAttribute( aAttrName ); |
|
294 CGECODefaultObject::SetAttributeL( aAttrName, aAttrValue, aLocalized ); |
|
295 } |
|
296 |
|
297 void CMenuEngObject::SetInitialAttributeL |
|
298 ( const TDesC& aAttrName, const TDesC& aAttrValue, TBool aLocalized ) |
|
299 { |
|
300 CheckAttrNameL( aAttrName ); |
|
301 |
|
302 if ( iEng.State() != CMenuEng::ELoadRamFile && |
|
303 iEng.State() != CMenuEng::ELoadRomFile && |
|
304 Flags() & TMenuItem::ELockName && |
|
305 ( 0 == aAttrName.Compare( KMenuAttrShortName ) || |
|
306 0 == aAttrName.Compare( KMenuAttrLongName ) || |
|
307 0 == aAttrName.Compare( KMenuAttrTitleName ) ) ) |
|
308 { |
|
309 User::Leave( KErrAccessDenied ); |
|
310 } |
|
311 |
|
312 CMenuEngObjectAttr* attr = NULL; |
|
313 TInt i = iAttributes.Find( aAttrName ); |
|
314 if ( KErrNotFound == i ) |
|
315 { |
|
316 attr = CMenuEngObjectAttr::NewLC( aAttrName ); |
|
317 iAttributes.AppendL( attr ); |
|
318 CleanupStack::Pop( attr ); |
|
319 } |
|
320 else |
|
321 { |
|
322 attr = iAttributes[i]; |
|
323 } |
|
324 __ASSERT_DEBUG( attr, User::Invariant() ); |
|
325 attr->SetValueL( aAttrValue ); |
|
326 attr->SetLocalized( aLocalized ); |
|
327 } |
|
328 |
|
329 // --------------------------------------------------------- |
|
330 // CMenuEngObject::SetNative |
|
331 // --------------------------------------------------------- |
|
332 // |
|
333 EXPORT_C void CMenuEngObject::SetAppType( TAppType aAppType ) |
|
334 { |
|
335 iAppType = aAppType; |
|
336 } |
|
337 |
|
338 // --------------------------------------------------------- |
|
339 // CMenuEngObject::GetNative |
|
340 // --------------------------------------------------------- |
|
341 // |
|
342 EXPORT_C CMenuEngObject::TAppType CMenuEngObject::GetAppType() const |
|
343 { |
|
344 return iAppType; |
|
345 } |
|
346 |
|
347 // --------------------------------------------------------- |
|
348 // CMenuEngObject::RemoveAttribute |
|
349 // --------------------------------------------------------- |
|
350 // |
|
351 EXPORT_C void CMenuEngObject::RemoveAttribute( const TDesC& aName ) |
|
352 { |
|
353 TInt i = iAttributes.Find( aName ); |
|
354 if ( KErrNotFound != i ) |
|
355 { |
|
356 delete iAttributes[i]; |
|
357 iAttributes.Remove( i ); |
|
358 CGECODefaultObject::RemoveAttribute( aName ); |
|
359 } |
|
360 } |
|
361 |
|
362 // --------------------------------------------------------- |
|
363 // CMenuEngObject::Reset |
|
364 // --------------------------------------------------------- |
|
365 // |
|
366 EXPORT_C void CMenuEngObject::Reset() |
|
367 { |
|
368 iAttributes.ResetAndDestroy(); |
|
369 iFlags = 0; |
|
370 } |
|
371 |
|
372 // --------------------------------------------------------- |
|
373 // CMenuEngObject::SetId |
|
374 // --------------------------------------------------------- |
|
375 // |
|
376 void CMenuEngObject::SetId( TInt aId ) |
|
377 { |
|
378 iId = aId; |
|
379 } |
|
380 |
|
381 // --------------------------------------------------------- |
|
382 // CMenuEngObject::Engine |
|
383 // --------------------------------------------------------- |
|
384 // |
|
385 CMenuEng& CMenuEngObject::Engine() |
|
386 { |
|
387 return iEng; |
|
388 } |
|
389 |
|
390 // --------------------------------------------------------- |
|
391 // CMenuEngObject::TypeIdentifier |
|
392 // --------------------------------------------------------- |
|
393 // |
|
394 const TDesC& CMenuEngObject::TypeIdentifier() |
|
395 { |
|
396 return iType; |
|
397 } |
|
398 |
|
399 // End of File |