Update contrib.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
23 This contains CT_DirData
27 #include "T_DirData.h"
28 #include "T_SfSrvServer.h"
32 _LIT(KArrayElementNumber, "element_number");
33 _LIT(KExpected, "expected");
34 _LIT(KSortkey, "sortkey");
35 _LIT(KNumSortkey, "numsortkey");
36 _LIT(KEntryObject, "entryObject");
39 _LIT(KCmdCount, "Count");
40 _LIT(KCmdOperatorBrackets, "[]");
41 _LIT(KCmdSort, "Sort");
42 _LIT(KCmdDestructor, "~");
46 _LIT(KESortNone, "ESortNone");
47 _LIT(KESortByName, "ESortByName");
48 _LIT(KESortByExt, "ESortByExt");
49 _LIT(KESortBySize, "ESortBySize");
50 _LIT(KESortByDate, "ESortByDate");
51 _LIT(KESortByUid, "ESortByUid");
52 _LIT(KEDirsAnyOrder, "EDirsAnyOrder");
53 _LIT(KEDirsFirst, "EDirsFirst");
54 _LIT(KEDirsLast, "EDirsLast");
55 _LIT(KEAscending, "EAscending");
56 _LIT(KEDescending, "EDescending");
57 _LIT(KEDirDescending, "EDirDescending");
60 CT_DirData* CT_DirData::NewL()
62 * Two phase constructor
65 CT_DirData* ret = new (ELeave) CT_DirData();
66 CleanupStack::PushL(ret);
68 CleanupStack::Pop(ret);
73 CT_DirData::CT_DirData()
76 * Protected constructor. First phase construction
82 void CT_DirData::ConstructL()
84 * Protected constructor. Second phase construction
90 CT_DirData::~CT_DirData()
99 TAny* CT_DirData::GetObject()
105 void CT_DirData::SetObjectL(TAny* aAny)
108 iDir = static_cast<CDir*> (aAny);
112 void CT_DirData::DisownObjectL()
118 inline TCleanupOperation CT_DirData::CleanupOperation()
120 return CleanupOperation;
124 void CT_DirData::CleanupOperation(TAny* aAny)
126 CDir* dir=static_cast<CDir*>(aAny);
131 TBool CT_DirData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
133 * Process a command read from the ini file
135 * @param aCommand the command to process
136 * @param aSection the entry in the ini file requiring the command to be processed
138 * @return ETrue if the command is processed
141 TBool retVal = ETrue;
143 if (aCommand == KCmdCount)
145 DoCmdCount(aSection);
147 else if (aCommand == KCmdOperatorBrackets)
149 DoCmdOperatorBracketsL(aSection);
151 else if (aCommand == KCmdSort)
155 else if (aCommand == KCmdDestructor)
167 void CT_DirData::DoCleanup()
169 INFO_PRINTF1(_L("Doing cleanup"));
177 void CT_DirData::DoCmdCount(const TDesC& aSection)
179 INFO_PRINTF1(_L("Counts directory entries!"));
182 if (GET_MANDATORY_INT_PARAMETER(KExpected, aSection, expected))
184 TInt count = iDir->Count();
185 if (count != expected)
187 ERR_PRINTF3(_L("Result didn't match with expected result! COUNT: %d, expected: %d"), count, expected);
188 SetBlockResult(EFail);
192 INFO_PRINTF2(_L("Result matched with expected result (%d)!"), count);
198 void CT_DirData::DoCmdOperatorBracketsL(const TDesC& aSection)
200 INFO_PRINTF1(_L("Getting element and compare it with expected!"));
204 if (GET_MANDATORY_INT_PARAMETER(KArrayElementNumber, aSection, elementNumber))
206 INFO_PRINTF2( _L( "Get element[%d]" ), elementNumber);
207 TEntry* entryObject = new(ELeave) TEntry();
208 CleanupStack::PushL(entryObject);
210 *entryObject = iDir->operator[](elementNumber);
212 if ( !FileserverUtil::VerifyTEntryDataFromIniL(*this, aSection, *entryObject))
214 SetBlockResult(EFail);
217 TPtrC entryObjectName;
218 if (GET_OPTIONAL_STRING_PARAMETER(KEntryObject, aSection, entryObjectName))
220 CT_EntryData* entryWrapperObject = static_cast<CT_EntryData*>(GetDataWrapperL(entryObjectName));
221 if(entryWrapperObject)
223 entryWrapperObject->SetObjectL(entryObject);
228 SetBlockResult(EFail);
238 void CT_DirData::DoCmdSort(const TDesC& aSection)
240 INFO_PRINTF1(_L("Sorting directory entries!"));
244 if (GET_OPTIONAL_STRING_PARAMETER(KSortkey, aSection, sortKey))
248 if ( !ConvertSortKeys(sortKey, fixedKey) )
250 ERR_PRINTF2(_L("Given sortkey (%S) is invalid"), &sortKey);
251 SetBlockResult(EFail);
254 TInt err = iDir->Sort(fixedKey);
258 ERR_PRINTF2(_L("Directory entries have not been sorted! Error code = %d"), err);
263 INFO_PRINTF1(_L("Directory entries have been sorted!"));
269 if (GET_MANDATORY_INT_PARAMETER(KNumSortkey, aSection, numSortKey))
271 TInt err = iDir->Sort(numSortKey);
275 ERR_PRINTF2(_L("Directory entries has not been sorted! Error code = %d"), err);
280 INFO_PRINTF1(_L("Directory entries has been sorted!"));
284 INFO_PRINTF1(_L("Results after sorting!"));
285 for (TInt i = 0; i < iDir->Count(); i++)
287 INFO_PRINTF3(_L("%d) %S"), i+1, &(*iDir)[i].iName);
291 TBool CT_DirData::ConvertSortKeys(TDesC &aConstantName, TUint& aSortKey)
296 if (aConstantName == KESortByName)
298 aSortKey = ESortByName;
300 else if (aConstantName == KESortByExt)
302 aSortKey = ESortByExt;
304 else if (aConstantName == KESortBySize)
306 aSortKey = ESortBySize;
308 else if (aConstantName == KESortByDate)
310 aSortKey = ESortByDate;
312 else if (aConstantName == KESortByUid)
314 aSortKey = ESortByUid;
316 else if (aConstantName == KEDirsAnyOrder)
318 aSortKey = EDirsAnyOrder;
320 else if (aConstantName == KEDirsFirst)
322 aSortKey = EDirsFirst;
324 else if (aConstantName == KEDirsLast)
326 aSortKey = EDirsLast;
328 else if (aConstantName == KEAscending)
330 aSortKey = EAscending;
332 else if (aConstantName == KEDescending)
334 aSortKey = EDescending;
336 else if (aConstantName == KEDirDescending)
338 aSortKey = EDirDescending;
340 else if (aConstantName == KESortNone)
342 aSortKey = ESortNone;
346 TInt location = aConstantName.Match(_L("*|*"));
347 if( location != KErrNotFound )
349 //Converting Left part of the data
350 TPtrC tempStr = aConstantName.Left(location);
351 ret = ConvertSortKeys(tempStr, aSortKey);
353 //Converting right data can be with another "|"
354 tempStr.Set(aConstantName.Mid(location + 1));
357 if ( ConvertSortKeys(tempStr, tmp) )