114
|
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 |
#ifndef __MENUENG_H__
|
|
19 |
#define __MENUENG_H__
|
|
20 |
|
|
21 |
#include <e32base.h>
|
|
22 |
#include <xcfwengine.h>
|
|
23 |
#include <xcfwtree.h> // for RNodeArray
|
|
24 |
#include "mcsmenunotifier.h" // for notification events
|
|
25 |
|
|
26 |
// FORWARD DECLARATION
|
|
27 |
|
|
28 |
class TMenuItem;
|
|
29 |
class CXCFWTree;
|
|
30 |
class MXCFWNode;
|
|
31 |
class CMenuEngObjectFactoryProxy;
|
|
32 |
class CMenuEngObject;
|
|
33 |
class CMenuEngIdManager;
|
|
34 |
class MMenuEngObserver;
|
|
35 |
class MMenuEngOperation;
|
|
36 |
class MMenuEngFilter;
|
|
37 |
class MMenuEngVisitor;
|
|
38 |
|
|
39 |
/**
|
|
40 |
* Event notification data.
|
|
41 |
*/
|
|
42 |
class TMenuEngNotify
|
|
43 |
{
|
|
44 |
|
|
45 |
public: // construction
|
|
46 |
|
|
47 |
/**
|
|
48 |
* Constructor.
|
|
49 |
* @param aFolder Folder.
|
|
50 |
* @param aEvents Events.
|
|
51 |
*/
|
|
52 |
TMenuEngNotify( TInt aFolder, TInt aEvents )
|
|
53 |
: iFolder( aFolder ), iEvents( aEvents ) {}
|
|
54 |
|
|
55 |
public: // data
|
|
56 |
|
|
57 |
TInt iFolder; ///< Folder.
|
|
58 |
TInt iEvents; ///< Events.
|
|
59 |
|
|
60 |
};
|
|
61 |
|
|
62 |
/**
|
|
63 |
* Menu Engine.
|
|
64 |
*/
|
|
65 |
NONSHARABLE_CLASS( CMenuEng ): public CActive, public MXCFWEngineObserver
|
|
66 |
{
|
|
67 |
|
|
68 |
public: // construction
|
|
69 |
|
|
70 |
/**
|
|
71 |
* Destructor.
|
|
72 |
*/
|
|
73 |
IMPORT_C virtual ~CMenuEng();
|
|
74 |
|
|
75 |
/**
|
|
76 |
* Two-phased constructor.
|
|
77 |
* @param aName Name.
|
|
78 |
* @param aObserver Observer.
|
|
79 |
* @return The created object.
|
|
80 |
*/
|
|
81 |
IMPORT_C static CMenuEng* NewL(
|
|
82 |
const TDesC& aName,
|
|
83 |
MMenuEngObserver& aObserver );
|
|
84 |
|
|
85 |
protected: // construction
|
|
86 |
|
|
87 |
/**
|
|
88 |
* Constructor.
|
|
89 |
* @param aObserver Observer.
|
|
90 |
*/
|
|
91 |
CMenuEng( MMenuEngObserver& aObserver );
|
|
92 |
|
|
93 |
/**
|
|
94 |
* Second phase constructor.
|
|
95 |
* @param aName Name.
|
|
96 |
*/
|
|
97 |
void ConstructL( const TDesC& aName );
|
|
98 |
|
|
99 |
public: // new methods
|
|
100 |
|
|
101 |
enum TState /// State machine states.
|
|
102 |
{
|
|
103 |
ENull = 0, ///< Initial state.
|
|
104 |
ELoadRamFile, ///< Loading RAM file.
|
|
105 |
ELoadRomFile, ///< Loading ROM file.
|
|
106 |
ESaveFile, ///< Saving TEMP file and replacing RAM file.
|
|
107 |
EExecuteOp, ///< Operation scheduled for execution or being executed.
|
|
108 |
EReady, ///< Idle.
|
|
109 |
EDead ///< Unrecoverable error; final state.
|
|
110 |
};
|
|
111 |
|
|
112 |
/**
|
|
113 |
* Queue an operation for execution.
|
|
114 |
* Queued operations are scheduled for execution by the Engine.
|
|
115 |
* @param aOperation Operation.
|
|
116 |
*/
|
|
117 |
IMPORT_C void QueueOperationL( MMenuEngOperation& aOperation );
|
|
118 |
|
|
119 |
/**
|
|
120 |
* Dequeue an operation (remove from the operation queue). Safe to call
|
|
121 |
* if not queued.
|
|
122 |
* @param aOperation Operation.
|
|
123 |
*/
|
|
124 |
IMPORT_C void DequeueOperation( MMenuEngOperation& aOperation );
|
|
125 |
|
|
126 |
/**
|
|
127 |
* Traverse a subtree of the item tree.
|
|
128 |
* @param aFolder traversal starts at this folder.
|
|
129 |
* @param aVisitor Visitor visiting the nodes and controlling the traversal.
|
|
130 |
*/
|
|
131 |
IMPORT_C void TraverseFolderL(
|
|
132 |
TInt aFolder,
|
|
133 |
MMenuEngVisitor& aVisitor ) const;
|
|
134 |
|
|
135 |
/**
|
|
136 |
* Create a new object. Owner is the caller. The object is not added to
|
|
137 |
* the engine yet, but it has an ID already. It can be used to AddL() item.
|
|
138 |
* @param aType Type.
|
|
139 |
* @return Created object. Owner is the caller.
|
|
140 |
*/
|
|
141 |
IMPORT_C CMenuEngObject* NewObjectL( const TDesC& aType );
|
|
142 |
|
|
143 |
/**
|
|
144 |
* Returns current engine state.
|
|
145 |
* @return Current state.
|
|
146 |
*/
|
|
147 |
inline TState State() const;
|
|
148 |
|
|
149 |
/*
|
|
150 |
* Gets legacy format
|
|
151 |
* @return legacy format
|
|
152 |
*/
|
|
153 |
IMPORT_C TBool GetOnceLegacyFormat();
|
|
154 |
|
|
155 |
public: // data query (read access)
|
|
156 |
|
|
157 |
// Read-access methods can be called any time.
|
|
158 |
// There is a short startup period during which the engine data is not
|
|
159 |
// ready yet; calls made in that period leave with KErrNotReady.
|
|
160 |
// When the engine becomes ready, an (0 ,EItemsAddedRemoved) event is
|
|
161 |
// sent to the observer.
|
|
162 |
|
|
163 |
/**
|
|
164 |
* Get ID of root folder.
|
|
165 |
* @param aId ID of root folder.
|
|
166 |
*/
|
|
167 |
IMPORT_C void RootFolderL( TInt& aId ) const;
|
|
168 |
|
|
169 |
/**
|
|
170 |
* Get parent folder of item.
|
|
171 |
* @param aId Item ID.
|
|
172 |
* @param aParentId ID of parent folder.
|
|
173 |
*/
|
|
174 |
IMPORT_C void ParentFolderL( TInt aId, TInt& aParentId ) const;
|
|
175 |
|
|
176 |
/**
|
|
177 |
* Get item header.
|
|
178 |
* @param aId Item ID.
|
|
179 |
* @param aItem Item header is returned here.
|
|
180 |
*/
|
|
181 |
IMPORT_C void GetItemL( TInt aId, TMenuItem& aItem ) const;
|
|
182 |
|
|
183 |
/**
|
|
184 |
* Get list of items.
|
|
185 |
* @param aItemArray Array receiving item list. Existing content not touched
|
|
186 |
* (new items are appended).
|
|
187 |
* @param aFolder Get items from this folder.
|
|
188 |
* @param aFilter Filter criteria or NULL for unfiltered results.
|
|
189 |
* @param aRecursive ETrue to recurse folders, EFalse for immediate
|
|
190 |
* children only.
|
|
191 |
*/
|
|
192 |
IMPORT_C void GetItemsL(
|
|
193 |
RArray<TMenuItem>& aItemArray,
|
|
194 |
TInt aFolder,
|
|
195 |
const MMenuEngFilter* aFilter,
|
|
196 |
TBool aRecursive ) const;
|
|
197 |
|
|
198 |
/**
|
|
199 |
* Get object.
|
|
200 |
* @param aId Item ID.
|
|
201 |
* @return Object.
|
|
202 |
*/
|
|
203 |
IMPORT_C const CMenuEngObject& ObjectL( TInt aId ) const;
|
|
204 |
|
|
205 |
public: // data manipulation (write access).
|
|
206 |
|
|
207 |
// All write-access methods methods must be wrapped in MMenuEngOperation
|
|
208 |
// objects (scheduled execution), otherwise they leave with KErrLocked.
|
|
209 |
|
|
210 |
/**
|
|
211 |
* Remove item.
|
|
212 |
* @param aId ID of item to be removed.
|
|
213 |
*/
|
|
214 |
IMPORT_C void RemoveL( TInt aId );
|
|
215 |
|
|
216 |
/**
|
|
217 |
* Move items to another folder.
|
|
218 |
* @param aItems ID-s of items to be to be moved. All items must be in
|
|
219 |
* the same folder.
|
|
220 |
* @param aFolder Target folder.
|
|
221 |
* @param aMoveBefore. In the target folder, items will be inserted before
|
|
222 |
* this item (if found). If the target folder contains no item with that ID,
|
|
223 |
* the moved items are appended to the end of existing items. Pass 0 to
|
|
224 |
* append to the end.
|
|
225 |
*/
|
|
226 |
IMPORT_C void MoveToFolderL(
|
|
227 |
RArray<TInt>& aItems,
|
|
228 |
TInt aFolder,
|
|
229 |
TInt aMoveBefore );
|
|
230 |
|
|
231 |
/**
|
|
232 |
* Move item to a different position in its current folder.
|
|
233 |
* @param aId ID of item to be to be reordered.
|
|
234 |
* @param aMoveBefore. Move the item before this item (if found).
|
|
235 |
* If aMoveBefore is not found, the item is moved to the end.
|
|
236 |
*/
|
|
237 |
IMPORT_C void ReorderL( TInt aId, TInt aMoveBefore );
|
|
238 |
|
|
239 |
/**
|
|
240 |
* Add new object.
|
|
241 |
* @param aObject Object to be added. Note, the object must have been
|
|
242 |
* created with NewObjectL of THIS engine (or the call fails)!
|
|
243 |
* Ownership taken.
|
|
244 |
* @param aFolder Parent folder.
|
|
245 |
* @param aMoveBefore. Move the item before this item (if found).
|
|
246 |
* If aMoveBefore is not found, the item is added to the end.
|
|
247 |
*/
|
|
248 |
IMPORT_C void AddL(
|
|
249 |
CMenuEngObject& aObject,
|
|
250 |
TInt aFolder,
|
|
251 |
TInt aInsertBefore );
|
|
252 |
|
|
253 |
/**
|
|
254 |
* Get modifiable object. Note: when this method is called, the engine
|
|
255 |
* marks the object as changed (without checking if there was really
|
|
256 |
* a change or not). Therefore, it is advisable to use ObjectL() to
|
|
257 |
* investigate an object, and only call ModifiableObjectL if changes are
|
|
258 |
* really needed. This results in better performace, as it avoids
|
|
259 |
* unnecessary saving.
|
|
260 |
* @param aId Item ID.
|
|
261 |
* @param aEvent event for engine to append.
|
|
262 |
* @return Modifiable object. Already marked as changed.
|
|
263 |
*/
|
|
264 |
IMPORT_C CMenuEngObject& ModifiableObjectL( TInt aId,
|
|
265 |
TInt aEvent = RMenuNotifier::EItemAttributeChanged );
|
|
266 |
|
|
267 |
|
|
268 |
/**
|
|
269 |
* Append new notification to the list of pending notifications.
|
|
270 |
* @param aFolder Folder.
|
|
271 |
* @param aEvents Events.
|
|
272 |
*/
|
|
273 |
IMPORT_C void AppendNotifyL( TInt aFolder, TInt aEvents );
|
|
274 |
|
|
275 |
/**
|
|
276 |
* Checks if object exists and is not hidden nor missing.
|
|
277 |
* @param aId item id.
|
|
278 |
*/
|
|
279 |
IMPORT_C TBool Exist( TInt aId ) const;
|
|
280 |
|
|
281 |
private: // from CActive
|
|
282 |
|
|
283 |
/**
|
|
284 |
* Outstanding request completed.
|
|
285 |
*/
|
|
286 |
void RunL();
|
|
287 |
|
|
288 |
/**
|
|
289 |
* Cancel outstanding request.
|
|
290 |
*/
|
|
291 |
void DoCancel();
|
|
292 |
|
|
293 |
/**
|
|
294 |
* Handle error.
|
|
295 |
* @param aError Error code.
|
|
296 |
* @return KErrNone.
|
|
297 |
*/
|
|
298 |
TInt RunError( TInt aError );
|
|
299 |
|
|
300 |
private: // from MXCFWEngineObserver
|
|
301 |
|
|
302 |
/**
|
|
303 |
* Called when Engine parsing / saving state changes.
|
|
304 |
* @param aEvent Engine event
|
|
305 |
*/
|
|
306 |
void HandleEngineEventL( TXCFWEngineEvent aEvent );
|
|
307 |
|
|
308 |
/**
|
|
309 |
* Called when there's an error during parsing / saving.
|
|
310 |
* @param aErrorCode Error code
|
|
311 |
*/
|
|
312 |
void HandleEngineErrorL( TInt aErrorCode );
|
|
313 |
|
|
314 |
private: // types
|
|
315 |
|
|
316 |
enum TFile /// File selector.
|
|
317 |
{
|
|
318 |
ERomFile, ///< Factory file in ROM.
|
|
319 |
ERamFile, ///< Working file in RAM.
|
|
320 |
ETempFile, ///< Temp file for saving (RAM).
|
|
321 |
};
|
|
322 |
|
|
323 |
private: // new methods
|
|
324 |
|
|
325 |
/**
|
|
326 |
* Get object from node.
|
|
327 |
* @param aNode Node.
|
|
328 |
* @return Object.
|
|
329 |
*/
|
|
330 |
inline CMenuEngObject& Object( MXCFWNode& aNode ) const;
|
|
331 |
|
|
332 |
/**
|
|
333 |
* Tree is up, perform structure check.
|
|
334 |
* @param aTree Tree.
|
|
335 |
* @return The root folder node.
|
|
336 |
*/
|
|
337 |
MXCFWNode& CheckTreeL( MXCFWTree& aTree ) const;
|
|
338 |
|
|
339 |
/**
|
|
340 |
* Sanity ID check for all nodes in the tree.
|
|
341 |
* @param aTree Tree.
|
|
342 |
* @return ETrue if ID-s are OK.
|
|
343 |
*/
|
|
344 |
TBool DebugSanityCheck( MXCFWTree& aTree ) const;
|
|
345 |
|
|
346 |
/**
|
|
347 |
* Wait for data xml file to load.
|
|
348 |
*/
|
|
349 |
void ActiveWaitForFileLoadL();
|
|
350 |
|
|
351 |
/**
|
|
352 |
* Sanity ID check for one nodes in the tree.
|
|
353 |
* @param aNode Node.
|
|
354 |
* @return ETrue if ID is OK.
|
|
355 |
*/
|
|
356 |
TBool DebugSanityCheck( MXCFWNode& aNode ) const;
|
|
357 |
|
|
358 |
/**
|
|
359 |
* Find node by ID, leave with KErrNotFound if not found.
|
|
360 |
* @param aId ID.
|
|
361 |
* @return Node.
|
|
362 |
*/
|
|
363 |
MXCFWNode& NodeL( TInt aId ) const;
|
|
364 |
|
|
365 |
/**
|
|
366 |
* Find folder node by ID, leave with KErrNotFound if not found or not
|
|
367 |
* folder.
|
|
368 |
* @param aId ID.
|
|
369 |
* @return Folder node.
|
|
370 |
*/
|
|
371 |
MXCFWNode& FolderNodeL( TInt aId ) const;
|
|
372 |
|
|
373 |
/**
|
|
374 |
* Find child of aParent with given id, or NULL. Not recursive.
|
|
375 |
* @param aParent Folder.
|
|
376 |
* @param aId Child ID.
|
|
377 |
* @return Child or NULL.
|
|
378 |
*/
|
|
379 |
MXCFWNode* Child( MXCFWNode& aParent, TInt aId );
|
|
380 |
|
|
381 |
/**
|
|
382 |
* Cancel all operations in the queue.
|
|
383 |
*/
|
|
384 |
void CancelAllOperations();
|
|
385 |
|
|
386 |
/**
|
|
387 |
* Validate content filename. Leave with KErrArgument if not valid.
|
|
388 |
* @param aName Content filename (without extension).
|
|
389 |
*/
|
|
390 |
void ValidateNameL( const TDesC& aName );
|
|
391 |
|
|
392 |
/**
|
|
393 |
* Generate filename of content file.
|
|
394 |
* @param aFname Generated filename is returned here.
|
|
395 |
* @param aSelector Filename selector.
|
|
396 |
*/
|
|
397 |
void GetFileNameL( TFileName& aFname, TFile aSelector );
|
|
398 |
|
|
399 |
/**
|
|
400 |
* Traverse a node.
|
|
401 |
* @param aNode Node.
|
|
402 |
* @param aVisitor Visitor visiting the nodes and controlling the traversal.
|
|
403 |
*/
|
|
404 |
TBool TraverseNodeL( MXCFWNode& aNode, MMenuEngVisitor& aVisitor ) const;
|
|
405 |
|
|
406 |
/**
|
|
407 |
* Tree is up; create and initialize ID manager and tree ID-s.
|
|
408 |
* @param aRootNode Root node.
|
|
409 |
*/
|
|
410 |
void InitIdManagerL( MXCFWNode& aRootNode );
|
|
411 |
|
|
412 |
/**
|
|
413 |
* Read id_seed from the tree.
|
|
414 |
* @param aIdSeed ID seed.
|
|
415 |
*/
|
|
416 |
void GetIdSeedL( TInt& aIdSeed );
|
|
417 |
|
|
418 |
/**
|
|
419 |
* Write the id_seed to the tree.
|
|
420 |
* @param aSeed ID seed.
|
|
421 |
*/
|
|
422 |
void SetIdSeedL( TInt aSeed );
|
|
423 |
|
|
424 |
/**
|
|
425 |
* Appends predefined attribute to items in a tree
|
|
426 |
*/
|
|
427 |
void AppendPredefinedAttributeL( );
|
|
428 |
|
|
429 |
private: // state machine parts
|
|
430 |
|
|
431 |
/**
|
|
432 |
* Self-completion: go to RunL() asynchronously.
|
|
433 |
* @param aError Error code.
|
|
434 |
*/
|
|
435 |
void SelfComplete( TInt aError );
|
|
436 |
|
|
437 |
/**
|
|
438 |
* Initiate loading RAM file.
|
|
439 |
*/
|
|
440 |
void LoadRamFileL();
|
|
441 |
|
|
442 |
/**
|
|
443 |
* Initiate loading ROM file.
|
|
444 |
*/
|
|
445 |
void LoadRomFileL();
|
|
446 |
|
|
447 |
/**
|
|
448 |
* Initiate saving to TEMP file.
|
|
449 |
*/
|
|
450 |
void SaveTempFileL();
|
|
451 |
|
|
452 |
/**
|
|
453 |
* Replace RAM file with TEMP file.
|
|
454 |
*/
|
|
455 |
void ReplaceRamFileL();
|
|
456 |
|
|
457 |
/**
|
|
458 |
* Complete current operation, if any.
|
|
459 |
* @param aError Completion code.
|
|
460 |
*/
|
|
461 |
void CompleteCurrentOperation( TInt aError );
|
|
462 |
|
|
463 |
/**
|
|
464 |
* Start executing next operation, if any.
|
|
465 |
*/
|
|
466 |
void ExecuteOperationL();
|
|
467 |
|
|
468 |
/**
|
|
469 |
* Save changes, if any.
|
|
470 |
*/
|
|
471 |
void SaveChangesL();
|
|
472 |
|
|
473 |
private: // data
|
|
474 |
|
|
475 |
RBuf iName; ///< Own.
|
|
476 |
RBuf iTempFileName; ///< Own.
|
|
477 |
RBuf iRamFileName; ///< Own.
|
|
478 |
TBool iChanged; ///< ETrue if there are unsaved changes.
|
|
479 |
MMenuEngObserver& iObserver;
|
|
480 |
TState iState; ///< State.
|
|
481 |
CXCFWTree* iTree; ///< DOM tree. Own.
|
|
482 |
CXCFWEngine* iEngine; ///< XML Engline. Own.
|
|
483 |
CMenuEngObjectFactoryProxy* iObjectFactory; ///< Object factory. Own.
|
|
484 |
TInt iRoot; ///< Cached root folder id.
|
|
485 |
RPointerArray<MMenuEngOperation> iOperations; ///< Pending operations.
|
|
486 |
MMenuEngOperation* iCurrentOperation; ///< Operation being served.
|
|
487 |
RArray<TMenuEngNotify> iNotifyQueue; ///< Events for notifiers.
|
|
488 |
RFs iFs; ///< File Server Session. Own.
|
|
489 |
CMenuEngIdManager* iIdManager; ///< ID manager. Owned.
|
|
490 |
CActiveSchedulerWait* iActiveWait;
|
|
491 |
/*
|
|
492 |
* Legacy format
|
|
493 |
*/
|
|
494 |
TBool iLegacyFormat;
|
|
495 |
/**
|
|
496 |
* True if the last saving was unsuccessful
|
|
497 |
*/
|
|
498 |
TBool iDiskWasFullAndRamFileWasNotCreated;
|
|
499 |
};
|
|
500 |
|
|
501 |
// -----------------------------------------------------------------------------
|
|
502 |
// CMenuEng::State
|
|
503 |
// -----------------------------------------------------------------------------
|
|
504 |
//
|
|
505 |
CMenuEng::TState CMenuEng::State() const
|
|
506 |
{
|
|
507 |
return iState;
|
|
508 |
}
|
|
509 |
|
|
510 |
#endif // __MENUENG_H__
|