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_ParseData.h" sl@0: sl@0: sl@0: // Commands sl@0: _LIT( KCmdDelete, "~" ); sl@0: _LIT( KCmdAddDir, "AddDir"); sl@0: _LIT( KCmdPopDir, "PopDir"); sl@0: _LIT( KCmdNew, "new" ); sl@0: _LIT( KCmdSet, "Set" ); sl@0: _LIT( KCmdSetNoWild, "SetNoWild" ); sl@0: // Parameters sl@0: _LIT( KParamDefaultSpec, "DefaultSpec" ); sl@0: _LIT( KParamFileSpec, "FileName" ); sl@0: _LIT( KParamRelatedSpec, "RelatedSpec" ); sl@0: _LIT( KParamDirName, "DirName" ); sl@0: sl@0: sl@0: CT_ParseData* CT_ParseData::NewL() sl@0: /** sl@0: * Two phase constructor sl@0: */ sl@0: { sl@0: CT_ParseData* ret = new (ELeave) CT_ParseData(); sl@0: CleanupStack::PushL( ret ); sl@0: ret->ConstructL(); sl@0: CleanupStack::Pop( ret ); sl@0: return ret; sl@0: } sl@0: sl@0: TParseBase* CT_ParseData::GetParse() sl@0: { sl@0: return iParse; sl@0: } sl@0: sl@0: sl@0: CT_ParseData::CT_ParseData() sl@0: : iParse(NULL) sl@0: /** sl@0: * Protected constructor. First phase construction sl@0: */ sl@0: { sl@0: } sl@0: sl@0: void CT_ParseData::ConstructL() sl@0: /** sl@0: * Protected constructor. Second phase construction sl@0: */ sl@0: { sl@0: } sl@0: sl@0: CT_ParseData::~CT_ParseData() sl@0: /** sl@0: * Destructor. sl@0: */ sl@0: { sl@0: DoCleanup(); sl@0: } sl@0: sl@0: sl@0: TAny* CT_ParseData::GetObject() sl@0: /** sl@0: * Return a pointer to the object that the data wraps sl@0: * sl@0: * @return pointer to the object that the data wraps sl@0: */ sl@0: { sl@0: return iParse; sl@0: } sl@0: sl@0: TBool CT_ParseData::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(); sl@0: } sl@0: else if ( aCommand == KCmdSet ) sl@0: { sl@0: DoCmdSet( aSection ); sl@0: } sl@0: else if ( aCommand == KCmdSetNoWild ) sl@0: { sl@0: DoCmdSetNoWild( aSection ); sl@0: } sl@0: else if ( aCommand == KCmdPopDir ) sl@0: { sl@0: DoCmdPopDir(); sl@0: } sl@0: else if ( aCommand == KCmdAddDir ) sl@0: { sl@0: DoCmdAddDir( aSection ); 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_ParseData::DoCleanup() sl@0: /** Deletes TParse class instance */ sl@0: { sl@0: INFO_PRINTF1( _L( "Delete TParse class instance." ) ); sl@0: sl@0: delete iParse; sl@0: iParse = NULL; sl@0: } sl@0: sl@0: void CT_ParseData::DoCmdNew() sl@0: /** Creates new TParse class instance */ sl@0: { sl@0: DoCleanup(); sl@0: sl@0: INFO_PRINTF1( _L( "Create new TParse class instance." ) ); sl@0: sl@0: TRAPD( err, iParse = new (ELeave) TParse() ); sl@0: if ( err != KErrNone ) sl@0: { sl@0: ERR_PRINTF2( _L( "new TParse error=%d" ), err ); sl@0: SetError( err ); sl@0: } sl@0: } sl@0: sl@0: void CT_ParseData::DoCmdSet( const TDesC& aSection ) sl@0: { sl@0: TPtrC fileSpec; sl@0: if ( GET_MANDATORY_STRING_PARAMETER( KParamFileSpec, aSection, fileSpec ) ) sl@0: { sl@0: TPtrC relatedSpec(_L("")); sl@0: GET_OPTIONAL_STRING_PARAMETER( KParamRelatedSpec, aSection, relatedSpec ); sl@0: sl@0: TPtrC defaultSpec(_L("")); sl@0: GET_OPTIONAL_STRING_PARAMETER( KParamDefaultSpec, aSection, defaultSpec ); sl@0: sl@0: INFO_PRINTF4( _L( "Set(%S, %S, %S)"), &fileSpec, &relatedSpec, &defaultSpec ); sl@0: sl@0: TInt error = iParse->Set( fileSpec, &relatedSpec, &defaultSpec ); sl@0: sl@0: if ( error != KErrNone) sl@0: { sl@0: ERR_PRINTF2( _L( "Set() returned %d error"), error); sl@0: SetError(error); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_ParseData::DoCmdSetNoWild( const TDesC& aSection ) sl@0: { sl@0: TPtrC fileSpec; sl@0: if ( GET_MANDATORY_STRING_PARAMETER( KParamFileSpec, aSection, fileSpec ) ) sl@0: { sl@0: TPtrC relatedSpec(_L("")); sl@0: GET_OPTIONAL_STRING_PARAMETER( KParamRelatedSpec, aSection, relatedSpec ); sl@0: sl@0: TPtrC defaultSpec(_L("")); sl@0: GET_OPTIONAL_STRING_PARAMETER( KParamDefaultSpec, aSection, defaultSpec ); sl@0: sl@0: INFO_PRINTF4( _L( "SetNoWild(%S, %S, %S)"), &fileSpec, &relatedSpec, &defaultSpec ); sl@0: sl@0: TInt error = iParse->SetNoWild( fileSpec, &relatedSpec, &defaultSpec ); sl@0: sl@0: if ( error != KErrNone) sl@0: { sl@0: ERR_PRINTF2( _L( "SetNoWild() returned %d error"), error); sl@0: SetError(error); sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: void CT_ParseData::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 error = iParse->PopDir(); sl@0: if( error != KErrNone) sl@0: { sl@0: ERR_PRINTF2( _L( "PopDir() returned %d error"), error); sl@0: SetError(error); sl@0: } sl@0: } sl@0: sl@0: sl@0: void CT_ParseData::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 error = iParse->AddDir( dirName ); sl@0: if( error != KErrNone) sl@0: { sl@0: ERR_PRINTF2( _L( "AddDir() returned %d error"), error); sl@0: SetError(error); sl@0: } sl@0: } sl@0: } sl@0: