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: /** sl@0: @test sl@0: @internalComponent sl@0: v sl@0: This contains CT_DirData sl@0: */ sl@0: sl@0: // User includes sl@0: #include "T_DirData.h" sl@0: #include "T_SfSrvServer.h" sl@0: sl@0: /*@{*/ sl@0: /// Parameters sl@0: _LIT(KArrayElementNumber, "element_number"); sl@0: _LIT(KExpected, "expected"); sl@0: _LIT(KSortkey, "sortkey"); sl@0: _LIT(KNumSortkey, "numsortkey"); sl@0: _LIT(KEntryObject, "entryObject"); sl@0: sl@0: ///Commands sl@0: _LIT(KCmdCount, "Count"); sl@0: _LIT(KCmdOperatorBrackets, "[]"); sl@0: _LIT(KCmdSort, "Sort"); sl@0: _LIT(KCmdDestructor, "~"); sl@0: sl@0: sl@0: //Sort keys sl@0: _LIT(KESortNone, "ESortNone"); sl@0: _LIT(KESortByName, "ESortByName"); sl@0: _LIT(KESortByExt, "ESortByExt"); sl@0: _LIT(KESortBySize, "ESortBySize"); sl@0: _LIT(KESortByDate, "ESortByDate"); sl@0: _LIT(KESortByUid, "ESortByUid"); sl@0: _LIT(KEDirsAnyOrder, "EDirsAnyOrder"); sl@0: _LIT(KEDirsFirst, "EDirsFirst"); sl@0: _LIT(KEDirsLast, "EDirsLast"); sl@0: _LIT(KEAscending, "EAscending"); sl@0: _LIT(KEDescending, "EDescending"); sl@0: _LIT(KEDirDescending, "EDirDescending"); sl@0: sl@0: sl@0: CT_DirData* CT_DirData::NewL() sl@0: /** sl@0: * Two phase constructor sl@0: */ sl@0: { sl@0: CT_DirData* ret = new (ELeave) CT_DirData(); sl@0: CleanupStack::PushL(ret); sl@0: ret->ConstructL(); sl@0: CleanupStack::Pop(ret); sl@0: return ret; sl@0: } sl@0: sl@0: sl@0: CT_DirData::CT_DirData() sl@0: : iDir(NULL) sl@0: /** sl@0: * Protected constructor. First phase construction sl@0: */ sl@0: { sl@0: } sl@0: sl@0: sl@0: void CT_DirData::ConstructL() sl@0: /** sl@0: * Protected constructor. Second phase construction sl@0: */ sl@0: { sl@0: } sl@0: sl@0: sl@0: CT_DirData::~CT_DirData() sl@0: /** sl@0: * Destructor. sl@0: */ sl@0: { sl@0: DoCleanup(); sl@0: } sl@0: sl@0: sl@0: TAny* CT_DirData::GetObject() sl@0: { sl@0: return iDir; sl@0: } sl@0: sl@0: sl@0: void CT_DirData::SetObjectL(TAny* aAny) sl@0: { sl@0: DoCleanup(); sl@0: iDir = static_cast (aAny); sl@0: } sl@0: sl@0: sl@0: void CT_DirData::DisownObjectL() sl@0: { sl@0: iDir = NULL; sl@0: } sl@0: sl@0: sl@0: inline TCleanupOperation CT_DirData::CleanupOperation() sl@0: { sl@0: return CleanupOperation; sl@0: } sl@0: sl@0: sl@0: void CT_DirData::CleanupOperation(TAny* aAny) sl@0: { sl@0: CDir* dir=static_cast(aAny); sl@0: delete dir; sl@0: } sl@0: sl@0: sl@0: TBool CT_DirData::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 == KCmdCount) sl@0: { sl@0: DoCmdCount(aSection); sl@0: } sl@0: else if (aCommand == KCmdOperatorBrackets) sl@0: { sl@0: DoCmdOperatorBracketsL(aSection); sl@0: } sl@0: else if (aCommand == KCmdSort) sl@0: { sl@0: DoCmdSort(aSection); sl@0: } sl@0: else if (aCommand == KCmdDestructor) sl@0: { sl@0: DoCleanup(); sl@0: } sl@0: else sl@0: { sl@0: retVal = EFalse; sl@0: } sl@0: return retVal; sl@0: } sl@0: sl@0: sl@0: void CT_DirData::DoCleanup() sl@0: { sl@0: INFO_PRINTF1(_L("Doing cleanup")); sl@0: if (iDir) sl@0: { sl@0: delete iDir; sl@0: iDir = NULL; sl@0: } sl@0: } sl@0: sl@0: void CT_DirData::DoCmdCount(const TDesC& aSection) sl@0: { sl@0: INFO_PRINTF1(_L("Counts directory entries!")); sl@0: sl@0: TInt expected; sl@0: if (GET_MANDATORY_INT_PARAMETER(KExpected, aSection, expected)) sl@0: { sl@0: TInt count = iDir->Count(); sl@0: if (count != expected) sl@0: { sl@0: ERR_PRINTF3(_L("Result didn't match with expected result! COUNT: %d, expected: %d"), count, expected); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("Result matched with expected result (%d)!"), count); sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: void CT_DirData::DoCmdOperatorBracketsL(const TDesC& aSection) sl@0: { sl@0: INFO_PRINTF1(_L("Getting element and compare it with expected!")); sl@0: sl@0: TInt elementNumber; sl@0: sl@0: if (GET_MANDATORY_INT_PARAMETER(KArrayElementNumber, aSection, elementNumber)) sl@0: { sl@0: INFO_PRINTF2( _L( "Get element[%d]" ), elementNumber); sl@0: TEntry* entryObject = new(ELeave) TEntry(); sl@0: CleanupStack::PushL(entryObject); sl@0: sl@0: *entryObject = iDir->operator[](elementNumber); sl@0: sl@0: if ( !FileserverUtil::VerifyTEntryDataFromIniL(*this, aSection, *entryObject)) sl@0: { sl@0: SetBlockResult(EFail); sl@0: } sl@0: sl@0: TPtrC entryObjectName; sl@0: if (GET_OPTIONAL_STRING_PARAMETER(KEntryObject, aSection, entryObjectName)) sl@0: { sl@0: CT_EntryData* entryWrapperObject = static_cast(GetDataWrapperL(entryObjectName)); sl@0: if(entryWrapperObject) sl@0: { sl@0: entryWrapperObject->SetObjectL(entryObject); sl@0: entryObject = NULL; sl@0: } sl@0: else sl@0: { sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: sl@0: CleanupStack::Pop(); sl@0: delete entryObject; sl@0: entryObject = NULL; sl@0: } sl@0: } sl@0: sl@0: void CT_DirData::DoCmdSort(const TDesC& aSection) sl@0: { sl@0: INFO_PRINTF1(_L("Sorting directory entries!")); sl@0: sl@0: TPtrC sortKey; sl@0: sl@0: if (GET_OPTIONAL_STRING_PARAMETER(KSortkey, aSection, sortKey)) sl@0: { sl@0: TUint fixedKey = 0; sl@0: sl@0: if ( !ConvertSortKeys(sortKey, fixedKey) ) sl@0: { sl@0: ERR_PRINTF2(_L("Given sortkey (%S) is invalid"), &sortKey); sl@0: SetBlockResult(EFail); sl@0: } sl@0: sl@0: TInt err = iDir->Sort(fixedKey); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Directory entries have not been sorted! Error code = %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Directory entries have been sorted!")); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: TInt numSortKey; sl@0: if (GET_MANDATORY_INT_PARAMETER(KNumSortkey, aSection, numSortKey)) sl@0: { sl@0: TInt err = iDir->Sort(numSortKey); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Directory entries has not been sorted! Error code = %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Directory entries has been sorted!")); sl@0: } sl@0: } sl@0: } sl@0: INFO_PRINTF1(_L("Results after sorting!")); sl@0: for (TInt i = 0; i < iDir->Count(); i++) sl@0: { sl@0: INFO_PRINTF3(_L("%d) %S"), i+1, &(*iDir)[i].iName); sl@0: } sl@0: } sl@0: sl@0: TBool CT_DirData::ConvertSortKeys(TDesC &aConstantName, TUint& aSortKey) sl@0: { sl@0: sl@0: TBool ret = ETrue; sl@0: sl@0: if (aConstantName == KESortByName) sl@0: { sl@0: aSortKey = ESortByName; sl@0: } sl@0: else if (aConstantName == KESortByExt) sl@0: { sl@0: aSortKey = ESortByExt; sl@0: } sl@0: else if (aConstantName == KESortBySize) sl@0: { sl@0: aSortKey = ESortBySize; sl@0: } sl@0: else if (aConstantName == KESortByDate) sl@0: { sl@0: aSortKey = ESortByDate; sl@0: } sl@0: else if (aConstantName == KESortByUid) sl@0: { sl@0: aSortKey = ESortByUid; sl@0: } sl@0: else if (aConstantName == KEDirsAnyOrder) sl@0: { sl@0: aSortKey = EDirsAnyOrder; sl@0: } sl@0: else if (aConstantName == KEDirsFirst) sl@0: { sl@0: aSortKey = EDirsFirst; sl@0: } sl@0: else if (aConstantName == KEDirsLast) sl@0: { sl@0: aSortKey = EDirsLast; sl@0: } sl@0: else if (aConstantName == KEAscending) sl@0: { sl@0: aSortKey = EAscending; sl@0: } sl@0: else if (aConstantName == KEDescending) sl@0: { sl@0: aSortKey = EDescending; sl@0: } sl@0: else if (aConstantName == KEDirDescending) sl@0: { sl@0: aSortKey = EDirDescending; sl@0: } sl@0: else if (aConstantName == KESortNone) sl@0: { sl@0: aSortKey = ESortNone; sl@0: } sl@0: else sl@0: { sl@0: TInt location = aConstantName.Match(_L("*|*")); sl@0: if( location != KErrNotFound ) sl@0: { sl@0: //Converting Left part of the data sl@0: TPtrC tempStr = aConstantName.Left(location); sl@0: ret = ConvertSortKeys(tempStr, aSortKey); sl@0: sl@0: //Converting right data can be with another "|" sl@0: tempStr.Set(aConstantName.Mid(location + 1)); sl@0: sl@0: TUint tmp; sl@0: if ( ConvertSortKeys(tempStr, tmp) ) sl@0: { sl@0: aSortKey |= tmp; sl@0: } sl@0: else sl@0: { sl@0: ret = EFalse; sl@0: } sl@0: } sl@0: } sl@0: sl@0: return ret; sl@0: }