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_DirScanData sl@0: */ sl@0: sl@0: // User includes sl@0: #include "T_DirScanData.h" sl@0: #include "T_SfSrvServer.h" sl@0: sl@0: /*@{*/ sl@0: /// Parameters sl@0: _LIT(KAttMask, "attmask" ); sl@0: _LIT(KRfsObject, "rfsObject"); sl@0: _LIT(KDirObject, "dirObject"); sl@0: _LIT(KExpected, "expected"); sl@0: _LIT(KPath, "path"); sl@0: _LIT(KEntrySortKey, "sortkey"); sl@0: _LIT(KScanDirection, "scandirection"); sl@0: sl@0: ///Commands sl@0: _LIT(KCmdNewL, "NewL"); sl@0: _LIT(KCmdNewLC, "NewLC"); sl@0: _LIT(KCmdSetScanDataL, "SetScanDataL"); sl@0: _LIT(KCmdFullPath, "FullPath"); sl@0: _LIT(KCmdAbbreviatedPath, "AbbreviatedPath"); sl@0: _LIT(KCmdNextL, "NextL"); sl@0: _LIT(KCmdDestructor, "~"); sl@0: sl@0: // Sort key 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: // Scan directions sl@0: _LIT(KEScanUpTree, "EScanUpTree"); sl@0: _LIT(KEScanDownTree, "EScanDownTree"); sl@0: sl@0: sl@0: CT_DirScanData* CT_DirScanData::NewL() sl@0: /** sl@0: * Two phase constructor sl@0: */ sl@0: { sl@0: CT_DirScanData* ret = new (ELeave) CT_DirScanData(); 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_DirScanData::CT_DirScanData() sl@0: : iDirScan(NULL) sl@0: /** sl@0: * Protected constructor. First phase construction sl@0: */ sl@0: { sl@0: } sl@0: sl@0: sl@0: void CT_DirScanData::ConstructL() sl@0: /** sl@0: * Protected constructor. Second phase construction sl@0: */ sl@0: { sl@0: } sl@0: sl@0: sl@0: CT_DirScanData::~CT_DirScanData() sl@0: /** sl@0: * Destructor. sl@0: */ sl@0: { sl@0: DoCleanup(); sl@0: } sl@0: sl@0: sl@0: TAny* CT_DirScanData::GetObject() sl@0: { sl@0: return iDirScan; sl@0: } sl@0: sl@0: sl@0: TBool CT_DirScanData::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 section 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 == KCmdNewL) sl@0: { sl@0: DoCmdNewL(aSection); sl@0: } sl@0: else if (aCommand == KCmdDestructor) sl@0: { sl@0: DoCleanup(); sl@0: } sl@0: else if (aCommand == KCmdNewLC) sl@0: { sl@0: DoCmdNewLC(aSection); sl@0: } sl@0: else if (aCommand == KCmdSetScanDataL) sl@0: { sl@0: DoCmdSetScanDataL(aSection); sl@0: } sl@0: else if (aCommand == KCmdNextL) sl@0: { sl@0: DoCmdNextL(aSection); sl@0: } sl@0: else if (aCommand == KCmdAbbreviatedPath) sl@0: { sl@0: DoCmdAbbreviatedPath(aSection); sl@0: } sl@0: else if (aCommand == KCmdFullPath) sl@0: { sl@0: DoCmdFullPath(aSection); sl@0: } sl@0: else sl@0: { sl@0: retVal = EFalse; sl@0: } sl@0: return retVal; sl@0: } sl@0: sl@0: void CT_DirScanData::DoCleanup() sl@0: { sl@0: INFO_PRINTF1(_L("Doing cleanup!")); sl@0: sl@0: if (iDirScan) sl@0: { sl@0: delete iDirScan; sl@0: iDirScan = NULL; sl@0: } sl@0: } sl@0: sl@0: void CT_DirScanData::DoCmdNewL(const TDesC& aSection) sl@0: { sl@0: INFO_PRINTF1(_L("Constructing CDirScan object!")); sl@0: sl@0: RFs* rfsObject = NULL; sl@0: TPtrC rfsObjectName; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KRfsObject, aSection, rfsObjectName)) sl@0: { sl@0: rfsObject = (RFs*)GetDataObjectL(rfsObjectName); sl@0: } sl@0: sl@0: DoCleanup(); sl@0: TRAPD (error, iDirScan = CDirScan::NewL(*rfsObject)); sl@0: if (error == KErrNone) sl@0: { sl@0: INFO_PRINTF1(_L("CDirScan object has been created with NewL constructor!")); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("CDirScan object is not created with NewL constructor! Error code: %d"), error); sl@0: SetError(error); sl@0: } sl@0: } sl@0: sl@0: void CT_DirScanData::DoCmdNewLC(const TDesC& aSection) sl@0: { sl@0: INFO_PRINTF1(_L("Constructing CDirScan object!")); sl@0: sl@0: RFs* rfsObject = NULL; sl@0: TPtrC rfsObjectName; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KRfsObject, aSection, rfsObjectName)) sl@0: { sl@0: rfsObject = (RFs*)GetDataObjectL(rfsObjectName); sl@0: } sl@0: sl@0: DoCleanup(); sl@0: TRAPD (error, iDirScan = CDirScan::NewLC(*rfsObject); CleanupStack::Pop(iDirScan) ); sl@0: if (error == KErrNone) sl@0: { sl@0: INFO_PRINTF1(_L("CDirScan object has been created with NewLC constructor!")); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("CDirScan object is not created with NewLC constructor! Error code: %d"), error); sl@0: SetError(error); sl@0: } sl@0: } sl@0: sl@0: void CT_DirScanData::DoCmdSetScanDataL(const TDesC& aSection) sl@0: { sl@0: INFO_PRINTF1(_L("Setting data scanning!")); sl@0: sl@0: TBool dataOk = ETrue; sl@0: sl@0: TPtrC path; sl@0: if (!GET_MANDATORY_STRING_PARAMETER(KPath(), aSection, path)) sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: TUint attMask = KEntryAttHidden; sl@0: if ( !FileserverUtil::GetAttMask(*this, aSection, KAttMask(), attMask)) sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: TPtrC entrySortKey; sl@0: TUint sortKey = ESortNone; sl@0: sl@0: if (GET_OPTIONAL_STRING_PARAMETER(KEntrySortKey(), aSection, entrySortKey)) sl@0: { sl@0: if ( !ConvertToSortKey(entrySortKey, sortKey) ) sl@0: { sl@0: TInt intTemp; sl@0: if ( GET_MANDATORY_INT_PARAMETER(KEntrySortKey(), aSection, intTemp) ) sl@0: { sl@0: sortKey=intTemp; sl@0: } sl@0: else sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: } sl@0: } sl@0: sl@0: TPtrC entryScanDirection; sl@0: CDirScan::TScanDirection scanDirection = CDirScan::EScanDownTree; sl@0: sl@0: if (GET_OPTIONAL_STRING_PARAMETER(KScanDirection(), aSection, entryScanDirection)) sl@0: { sl@0: if ( !ConvertToScanDirection(entryScanDirection, scanDirection)) sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: } sl@0: sl@0: sl@0: if (dataOk) sl@0: { sl@0: TRAPD (err, iDirScan->SetScanDataL(path, attMask, sortKey, scanDirection)); sl@0: if(err == KErrNone) sl@0: { sl@0: INFO_PRINTF1(_L("SetScanDataL complete!")); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("SetScanDataL() Error: %d"), err); sl@0: SetError(err); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_DirScanData::DoCmdNextL(const TDesC& aSection) sl@0: { sl@0: INFO_PRINTF1(_L("Scanning next directory entries!")); sl@0: sl@0: CDir* dirObject = NULL; sl@0: CT_DirData* dirWrapperObject = NULL; sl@0: TPtrC dirObjectName; sl@0: sl@0: if (GET_MANDATORY_STRING_PARAMETER(KDirObject, aSection, dirObjectName)) sl@0: { sl@0: dirWrapperObject = static_cast(GetDataWrapperL(dirObjectName)); sl@0: } sl@0: TRAPD (err, iDirScan->NextL(dirObject)); sl@0: if (err == KErrNone) sl@0: { sl@0: if (dirObject == NULL) sl@0: { sl@0: INFO_PRINTF1(_L("CDir instance is NULL, there is no directory left to go.")); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Scanning the next directory entry completed successfully!")); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("Can't scan the next directory entry in the structure Error code: %d"), err); sl@0: SetError(err); sl@0: } sl@0: sl@0: if (dirObject) sl@0: { sl@0: if(dirWrapperObject) sl@0: { sl@0: dirWrapperObject->SetObjectL(dirObject); sl@0: } sl@0: else sl@0: { sl@0: delete dirObject; sl@0: dirObject = NULL; sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_DirScanData::DoCmdAbbreviatedPath(const TDesC& aSection) sl@0: { sl@0: INFO_PRINTF1(_L("Getting directory abbreviated path!")); sl@0: sl@0: TPtrC expected; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KExpected(), aSection, expected)) sl@0: { sl@0: TPtrC abbPath; sl@0: abbPath.Set(iDirScan->AbbreviatedPath()); sl@0: sl@0: if (abbPath != expected) sl@0: { sl@0: ERR_PRINTF3(_L("Result (%S) didn't match with expected result (%S)!"), &abbPath, &expected); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("Result (%S) match with expected result!"), &abbPath); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_DirScanData::DoCmdFullPath(const TDesC& aSection) sl@0: { sl@0: INFO_PRINTF1(_L("Getting directory full path!")); sl@0: sl@0: TPtrC expected; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KExpected(), aSection, expected)) sl@0: { sl@0: TPtrC fullPath; sl@0: fullPath.Set(iDirScan->FullPath()); sl@0: sl@0: if (fullPath != expected) sl@0: { sl@0: ERR_PRINTF3(_L("Result (%S) didn't match with expected result (%S)!"), &fullPath, &expected); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("Result (%S) match with expected result!"), &fullPath); sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: TBool CT_DirScanData::ConvertToSortKey(const TDesC& aSortKeyStr, TUint& aSortKey) sl@0: { sl@0: TBool ret = ETrue; sl@0: sl@0: if (aSortKeyStr == KESortNone) sl@0: { sl@0: aSortKey = ESortNone; sl@0: } sl@0: else if (aSortKeyStr == KESortByName) sl@0: { sl@0: aSortKey = ESortByName; sl@0: } sl@0: else if (aSortKeyStr == KESortByExt) sl@0: { sl@0: aSortKey = ESortByExt; sl@0: } sl@0: else if (aSortKeyStr == KESortBySize) sl@0: { sl@0: aSortKey = ESortBySize; sl@0: } sl@0: else if (aSortKeyStr == KESortByDate) sl@0: { sl@0: aSortKey = ESortByDate; sl@0: } sl@0: else if (aSortKeyStr == KESortByUid) sl@0: { sl@0: aSortKey = ESortByUid; sl@0: } sl@0: else if (aSortKeyStr == KEDirsAnyOrder) sl@0: { sl@0: aSortKey = EDirsAnyOrder; sl@0: } sl@0: else if (aSortKeyStr == KEDirsFirst) sl@0: { sl@0: aSortKey = EDirsFirst; sl@0: } sl@0: else if (aSortKeyStr == KEDirsLast) sl@0: { sl@0: aSortKey = EDirsLast; sl@0: } sl@0: else if (aSortKeyStr == KEAscending) sl@0: { sl@0: aSortKey = EAscending; sl@0: } sl@0: else if (aSortKeyStr == KEDescending) sl@0: { sl@0: aSortKey = EDescending; sl@0: } sl@0: else if (aSortKeyStr == KEDirDescending) sl@0: { sl@0: aSortKey = EDirDescending; sl@0: } sl@0: else if (aSortKeyStr.Match((_L("*|*"))) != KErrNotFound) sl@0: { sl@0: TUint tmpSortKey; sl@0: sl@0: TInt location = aSortKeyStr.Match(_L("*|*")); sl@0: //Converting Left part of the data sl@0: TPtrC left = aSortKeyStr.Left(location); sl@0: if (ConvertToSortKey(left, tmpSortKey)) sl@0: { sl@0: aSortKey = tmpSortKey; sl@0: } sl@0: else sl@0: { sl@0: ret = EFalse; sl@0: } sl@0: sl@0: //Converting right data can be with another "|" sl@0: TPtrC right = aSortKeyStr.Mid(location + 1); sl@0: sl@0: if (ConvertToSortKey(right, tmpSortKey)) sl@0: { sl@0: aSortKey = aSortKey | tmpSortKey; sl@0: } sl@0: else sl@0: { sl@0: ret = EFalse; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ret = EFalse; sl@0: } sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: sl@0: sl@0: TBool CT_DirScanData::ConvertToScanDirection(const TDesC& aScanDirectionStr, CDirScan::TScanDirection& aScanDirection) sl@0: { sl@0: TBool ret = ETrue; sl@0: sl@0: if (aScanDirectionStr == KEScanUpTree) sl@0: { sl@0: aScanDirection = CDirScan::EScanUpTree; sl@0: } sl@0: else if (aScanDirectionStr == KEScanDownTree) sl@0: { sl@0: aScanDirection = CDirScan::EScanDownTree; sl@0: } sl@0: else sl@0: { sl@0: ret = EFalse; sl@0: } sl@0: sl@0: return ret; sl@0: }