menucontentsrv/srvsrc/mcssuiteparser.cpp
changeset 0 79c6a41cd166
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 2008 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 #include <xcfwtree.h>
       
    20 #include <gecoobjectbase.h>
       
    21 #include <gecodefaultobject.h>
       
    22 
       
    23 #include "mcssuiteparser.h"
       
    24 #include "mcssuiteobject.h"
       
    25 #include "mcsdef.h"
       
    26 #include "mcssuiteobjectfactory.h"
       
    27 
       
    28 
       
    29 // ---------------------------------------------------------
       
    30 // CSuiteObject::CSuiteParser
       
    31 // ---------------------------------------------------------
       
    32 //
       
    33 CSuiteParser::CSuiteParser()
       
    34 	{
       
    35 	// No implementation required
       
    36 	}
       
    37 
       
    38 // ---------------------------------------------------------
       
    39 // CSuiteObject::~CSuiteParser
       
    40 // ---------------------------------------------------------
       
    41 //
       
    42 CSuiteParser::~CSuiteParser()
       
    43 	{
       
    44 	iFileName.Close();
       
    45     delete iContentEngine;
       
    46     delete iObjectFactory;
       
    47     delete iActiveScheduler;
       
    48     delete iContentTree;
       
    49 	}
       
    50 
       
    51 // ---------------------------------------------------------
       
    52 // CSuiteObject::NewLC
       
    53 // ---------------------------------------------------------
       
    54 //
       
    55 CSuiteParser* CSuiteParser::NewLC( const TDesC& aFileName )
       
    56 	{
       
    57 	CSuiteParser* self = new (ELeave) CSuiteParser();
       
    58 	CleanupStack::PushL(self);
       
    59 	self->ConstructL( aFileName );
       
    60 	return self;
       
    61 	}
       
    62 
       
    63 // ---------------------------------------------------------
       
    64 // CSuiteObject::NewL
       
    65 // ---------------------------------------------------------
       
    66 //
       
    67 CSuiteParser* CSuiteParser::NewL( const TDesC& aFileName )
       
    68 	{
       
    69 	CSuiteParser* self = CSuiteParser::NewLC( aFileName );
       
    70 	CleanupStack::Pop( self ); // self;
       
    71 	return self;
       
    72 	}
       
    73 
       
    74 // ---------------------------------------------------------
       
    75 // CSuiteObject::ConstructL
       
    76 // ---------------------------------------------------------
       
    77 //
       
    78 void CSuiteParser::ConstructL( const TDesC& aFileName )
       
    79 	{
       
    80 	iFileName.CreateL( aFileName );
       
    81 	iActiveScheduler = new ( ELeave ) CActiveSchedulerWait();
       
    82     iObjectFactory = CSuiteObjectFactory::NewL();
       
    83     iContentEngine = CXCFWEngine::NewL( this );
       
    84     iContentEngine->RegisterObjectFactoryL( iObjectFactory );
       
    85 	}
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CSuiteParser::GetSuitsArrayL
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 TInt CSuiteParser::GetSuitsArrayL(  RPointerArray<CSuiteObject>& aSuitesArray  )
       
    92     {
       
    93     TInt err;
       
    94     iContentTree = CXCFWTree::NewL( );
       
    95     iContentEngine->LoadL( *iContentTree, iFileName );
       
    96 
       
    97     iActiveScheduler->Start( );
       
    98 
       
    99     if ( iCompletionStatus == 0 /*TSuiteParsingStatus::ECompleted*/ )
       
   100         {
       
   101         //this trap ensures stoping the ActiveSheduler
       
   102         //in case a leave occurs when updating data
       
   103         TRAP( err, HandleEntriesL( aSuitesArray ) );
       
   104         }
       
   105 
       
   106     delete iContentTree;
       
   107     iContentTree = NULL;
       
   108     return err;
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------
       
   112 // CSuiteObject::HandleEngineEventL
       
   113 // ---------------------------------------------------------
       
   114 //
       
   115 void CSuiteParser::HandleEngineEventL( TXCFWEngineEvent aEvent )
       
   116     {
       
   117     // handle completion
       
   118     if ( aEvent == EEvtParsingComplete )
       
   119         {
       
   120         TSuiteParsingStatus status = ECompleted;
       
   121         HandleCompletionL( status );
       
   122         }
       
   123     // else => ignore
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------
       
   127 // CSuiteObject::HandleEngineErrorL
       
   128 // ---------------------------------------------------------
       
   129 //
       
   130 void CSuiteParser::HandleEngineErrorL( TInt /*aErrorCode*/)
       
   131     {
       
   132     HandleCompletionL( EFailed );
       
   133     }
       
   134 
       
   135 // ---------------------------------------------------------
       
   136 // CSuiteObject::HandleCompletionL
       
   137 // ---------------------------------------------------------
       
   138 //
       
   139 void CSuiteParser::HandleCompletionL(
       
   140 		TSuiteParsingStatus aStatus )
       
   141     {
       
   142     iCompletionStatus = aStatus;
       
   143     iActiveScheduler->AsyncStop( );
       
   144     }
       
   145 
       
   146 
       
   147 // ---------------------------------------------------------
       
   148 // CSuiteObject::HandleEntriesL
       
   149 // ---------------------------------------------------------
       
   150 //
       
   151 void CSuiteParser::HandleEntriesL( RPointerArray<CSuiteObject>& aSuitesArray )
       
   152     {
       
   153     MXCFWNode* root = iContentTree->Root( );
       
   154     // get children 
       
   155     RNodeArray suites;
       
   156     CleanupClosePushL( suites );
       
   157     iContentTree->GetChildNodesL( root, suites );
       
   158     for ( TInt i = 0; i < suites.Count( ); i++ )
       
   159         {
       
   160         CSuiteObject* suite = CreateSuiteLC( suites[i] );
       
   161         aSuitesArray.AppendL( suite );
       
   162         CleanupStack::Pop( suite );
       
   163         }
       
   164     
       
   165     // clean up
       
   166     CleanupStack::PopAndDestroy( &suites );
       
   167     }
       
   168 
       
   169 // ---------------------------------------------------------
       
   170 // CSuiteObject::CreateSuiteLC
       
   171 // ---------------------------------------------------------
       
   172 //
       
   173 CSuiteObject* CSuiteParser::CreateSuiteLC( MXCFWNode* aNode )
       
   174 	{
       
   175 	TInt lastBackSlash = iFileName.Length() -
       
   176         iFileName.LocateReverseF( KBackSlashSuite ) - 1;
       
   177 	CSuiteObject* suite = 
       
   178         CSuiteObject::NewLC( iFileName.Right( lastBackSlash ) );
       
   179 	
       
   180     CGECODefaultObject* node=
       
   181             static_cast<CGECODefaultObject*>( aNode->Data() );
       
   182 
       
   183     TPtrC name;
       
   184     TPtrC value;
       
   185     TInt attrCount = node->NumAttributes();
       
   186     TBool isLocalized = EFalse;
       
   187 
       
   188     for( TInt i = 0; i < attrCount; i++ )
       
   189         {
       
   190 		node->AttributeDetailsL( i, name, value, isLocalized );
       
   191         if( name == KMenuAttSuiteName() )
       
   192         	{
       
   193         	suite->SetSuiteNameL( value );
       
   194         	}
       
   195 			suite->SetInitialAttributeL( name, value, isLocalized );
       
   196         }
       
   197     
       
   198     return suite;
       
   199 	}
       
   200