sl@0: /* sl@0: * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "T_ParsePtrCData.h" sl@0: sl@0: sl@0: // Commands sl@0: _LIT( KCmdDelete, "~" ); sl@0: _LIT( KCmdNew, "new" ); sl@0: _LIT( KCmdAddDir, "AddDir"); sl@0: _LIT( KCmdPopDir, "PopDir"); sl@0: sl@0: // Parameters sl@0: _LIT( KParamFileName, "FileName" ); sl@0: _LIT( KParamDirName, "DirName" ); sl@0: sl@0: sl@0: CT_ParsePtrCData* CT_ParsePtrCData::NewL() sl@0: /** sl@0: * Two phase constructor sl@0: */ sl@0: { sl@0: CT_ParsePtrCData* ret = new (ELeave) CT_ParsePtrCData(); sl@0: CleanupStack::PushL( ret ); sl@0: ret->ConstructL(); sl@0: CleanupStack::Pop( ret ); sl@0: return ret; sl@0: } sl@0: sl@0: CT_ParsePtrCData::CT_ParsePtrCData() sl@0: : iParsePtrC(NULL) sl@0: /** sl@0: * Protected constructor. First phase construction sl@0: */ sl@0: { sl@0: } sl@0: sl@0: void CT_ParsePtrCData::ConstructL() sl@0: /** sl@0: * Protected constructor. Second phase construction sl@0: */ sl@0: { sl@0: } sl@0: sl@0: CT_ParsePtrCData::~CT_ParsePtrCData() sl@0: /** sl@0: * Destructor. sl@0: */ sl@0: { sl@0: DoCleanup(); sl@0: } sl@0: sl@0: sl@0: sl@0: TParseBase* CT_ParsePtrCData::GetParse() sl@0: { sl@0: return iParsePtrC; sl@0: } sl@0: sl@0: TBool CT_ParsePtrCData::DoCommandL( const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex) sl@0: /** sl@0: * Process a command read from the ini file sl@0: * sl@0: * @param aCommand the command to process sl@0: * @param aSection the entry in the ini file requiring the command to be processed sl@0: * sl@0: * @return ETrue if the command is processed sl@0: */ sl@0: { sl@0: TBool retVal = ETrue; sl@0: sl@0: if ( aCommand == KCmdDelete ) sl@0: { sl@0: DoCleanup(); sl@0: } sl@0: else if ( aCommand == KCmdNew ) sl@0: { sl@0: DoCmdNew( aSection ); sl@0: } sl@0: else if ( aCommand == KCmdAddDir ) sl@0: { sl@0: DoCmdAddDir( aSection ); sl@0: } sl@0: else if ( aCommand == KCmdPopDir ) sl@0: { sl@0: DoCmdPopDir(); sl@0: } sl@0: else sl@0: { sl@0: retVal = CT_ParseBaseData::DoCommandL(aCommand, aSection, aAsyncErrorIndex); sl@0: } sl@0: sl@0: return retVal; sl@0: } sl@0: sl@0: void CT_ParsePtrCData::DoCleanup() sl@0: /** Deletes TParsePtr class instance */ sl@0: { sl@0: INFO_PRINTF1( _L( "Delete TParsePtrC class instance." ) ); sl@0: sl@0: delete iParsePtrC; sl@0: iParsePtrC = NULL; sl@0: } sl@0: sl@0: void CT_ParsePtrCData::DoCmdNew( const TDesC& aSection ) sl@0: /** Creates new TParsePtr class instance */ sl@0: { sl@0: DoCleanup(); sl@0: sl@0: TPtrC fileName; sl@0: if ( GET_MANDATORY_STRING_PARAMETER( KParamFileName, aSection, fileName ) ) sl@0: { sl@0: INFO_PRINTF2( _L( "Create new TParsePtrC(\"%S\") class instance." ), &fileName ); sl@0: sl@0: iFileName = fileName; sl@0: TRAPD( err, iParsePtrC = new (ELeave) TParsePtrC( iFileName ) ); sl@0: if ( err != KErrNone ) sl@0: { sl@0: ERR_PRINTF3( _L( "new TParsePtrC(\"%S\") error=%d" ), &fileName, err ); sl@0: SetError( err ); sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: void CT_ParsePtrCData::DoCmdPopDir() sl@0: /** Removes the last directory from the path using PopDir(). */ sl@0: { sl@0: INFO_PRINTF1( _L( "PopDir()" ) ); sl@0: sl@0: TInt err = iParsePtrC->PopDir(); sl@0: sl@0: if( err != KErrNone) sl@0: { sl@0: ERR_PRINTF2( _L( "PopDir() returned %d error"), err); sl@0: SetError(err); sl@0: } sl@0: } sl@0: sl@0: sl@0: void CT_ParsePtrCData::DoCmdAddDir( const TDesC& aSection ) sl@0: /** Adds a single directory onto the end of the path using AddDir. */ sl@0: { sl@0: TPtrC dirName; sl@0: if ( GET_MANDATORY_STRING_PARAMETER( KParamDirName, aSection, dirName ) ) sl@0: { sl@0: INFO_PRINTF2( _L( "AddDir(\"%S\")" ), &dirName ); sl@0: sl@0: TInt err = iParsePtrC->AddDir( dirName ); sl@0: if( err != KErrNone) sl@0: { sl@0: ERR_PRINTF2( _L( "AddDir() returned %d error"), err); sl@0: SetError(err); sl@0: } sl@0: } sl@0: } sl@0: