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_DirScanData
27 #include "T_DirScanData.h"
28 #include "T_SfSrvServer.h"
32 _LIT(KAttMask, "attmask" );
33 _LIT(KRfsObject, "rfsObject");
34 _LIT(KDirObject, "dirObject");
35 _LIT(KExpected, "expected");
37 _LIT(KEntrySortKey, "sortkey");
38 _LIT(KScanDirection, "scandirection");
41 _LIT(KCmdNewL, "NewL");
42 _LIT(KCmdNewLC, "NewLC");
43 _LIT(KCmdSetScanDataL, "SetScanDataL");
44 _LIT(KCmdFullPath, "FullPath");
45 _LIT(KCmdAbbreviatedPath, "AbbreviatedPath");
46 _LIT(KCmdNextL, "NextL");
47 _LIT(KCmdDestructor, "~");
50 _LIT(KESortNone, "ESortNone");
51 _LIT(KESortByName, "ESortByName");
52 _LIT(KESortByExt, "ESortByExt");
53 _LIT(KESortBySize, "ESortBySize");
54 _LIT(KESortByDate, "ESortByDate");
55 _LIT(KESortByUid, "ESortByUid");
56 _LIT(KEDirsAnyOrder, "EDirsAnyOrder");
57 _LIT(KEDirsFirst, "EDirsFirst");
58 _LIT(KEDirsLast, "EDirsLast");
59 _LIT(KEAscending, "EAscending");
60 _LIT(KEDescending, "EDescending");
61 _LIT(KEDirDescending, "EDirDescending");
64 _LIT(KEScanUpTree, "EScanUpTree");
65 _LIT(KEScanDownTree, "EScanDownTree");
68 CT_DirScanData* CT_DirScanData::NewL()
70 * Two phase constructor
73 CT_DirScanData* ret = new (ELeave) CT_DirScanData();
74 CleanupStack::PushL(ret);
76 CleanupStack::Pop(ret);
81 CT_DirScanData::CT_DirScanData()
84 * Protected constructor. First phase construction
90 void CT_DirScanData::ConstructL()
92 * Protected constructor. Second phase construction
98 CT_DirScanData::~CT_DirScanData()
107 TAny* CT_DirScanData::GetObject()
113 TBool CT_DirScanData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
115 * Process a command read from the ini file
117 * @param aCommand the command to process
118 * @param aSection the section in the ini file requiring the command to be processed
120 * @return ETrue if the command is processed
123 TBool retVal = ETrue;
125 if (aCommand == KCmdNewL)
129 else if (aCommand == KCmdDestructor)
133 else if (aCommand == KCmdNewLC)
135 DoCmdNewLC(aSection);
137 else if (aCommand == KCmdSetScanDataL)
139 DoCmdSetScanDataL(aSection);
141 else if (aCommand == KCmdNextL)
143 DoCmdNextL(aSection);
145 else if (aCommand == KCmdAbbreviatedPath)
147 DoCmdAbbreviatedPath(aSection);
149 else if (aCommand == KCmdFullPath)
151 DoCmdFullPath(aSection);
160 void CT_DirScanData::DoCleanup()
162 INFO_PRINTF1(_L("Doing cleanup!"));
171 void CT_DirScanData::DoCmdNewL(const TDesC& aSection)
173 INFO_PRINTF1(_L("Constructing CDirScan object!"));
175 RFs* rfsObject = NULL;
177 if (GET_MANDATORY_STRING_PARAMETER(KRfsObject, aSection, rfsObjectName))
179 rfsObject = (RFs*)GetDataObjectL(rfsObjectName);
183 TRAPD (error, iDirScan = CDirScan::NewL(*rfsObject));
184 if (error == KErrNone)
186 INFO_PRINTF1(_L("CDirScan object has been created with NewL constructor!"));
190 ERR_PRINTF2(_L("CDirScan object is not created with NewL constructor! Error code: %d"), error);
195 void CT_DirScanData::DoCmdNewLC(const TDesC& aSection)
197 INFO_PRINTF1(_L("Constructing CDirScan object!"));
199 RFs* rfsObject = NULL;
201 if (GET_MANDATORY_STRING_PARAMETER(KRfsObject, aSection, rfsObjectName))
203 rfsObject = (RFs*)GetDataObjectL(rfsObjectName);
207 TRAPD (error, iDirScan = CDirScan::NewLC(*rfsObject); CleanupStack::Pop(iDirScan) );
208 if (error == KErrNone)
210 INFO_PRINTF1(_L("CDirScan object has been created with NewLC constructor!"));
214 ERR_PRINTF2(_L("CDirScan object is not created with NewLC constructor! Error code: %d"), error);
219 void CT_DirScanData::DoCmdSetScanDataL(const TDesC& aSection)
221 INFO_PRINTF1(_L("Setting data scanning!"));
223 TBool dataOk = ETrue;
226 if (!GET_MANDATORY_STRING_PARAMETER(KPath(), aSection, path))
231 TUint attMask = KEntryAttHidden;
232 if ( !FileserverUtil::GetAttMask(*this, aSection, KAttMask(), attMask))
238 TUint sortKey = ESortNone;
240 if (GET_OPTIONAL_STRING_PARAMETER(KEntrySortKey(), aSection, entrySortKey))
242 if ( !ConvertToSortKey(entrySortKey, sortKey) )
245 if ( GET_MANDATORY_INT_PARAMETER(KEntrySortKey(), aSection, intTemp) )
256 TPtrC entryScanDirection;
257 CDirScan::TScanDirection scanDirection = CDirScan::EScanDownTree;
259 if (GET_OPTIONAL_STRING_PARAMETER(KScanDirection(), aSection, entryScanDirection))
261 if ( !ConvertToScanDirection(entryScanDirection, scanDirection))
270 TRAPD (err, iDirScan->SetScanDataL(path, attMask, sortKey, scanDirection));
273 INFO_PRINTF1(_L("SetScanDataL complete!"));
277 ERR_PRINTF2(_L("SetScanDataL() Error: %d"), err);
283 void CT_DirScanData::DoCmdNextL(const TDesC& aSection)
285 INFO_PRINTF1(_L("Scanning next directory entries!"));
287 CDir* dirObject = NULL;
288 CT_DirData* dirWrapperObject = NULL;
291 if (GET_MANDATORY_STRING_PARAMETER(KDirObject, aSection, dirObjectName))
293 dirWrapperObject = static_cast<CT_DirData*>(GetDataWrapperL(dirObjectName));
295 TRAPD (err, iDirScan->NextL(dirObject));
298 if (dirObject == NULL)
300 INFO_PRINTF1(_L("CDir instance is NULL, there is no directory left to go."));
304 INFO_PRINTF1(_L("Scanning the next directory entry completed successfully!"));
309 ERR_PRINTF2(_L("Can't scan the next directory entry in the structure Error code: %d"), err);
317 dirWrapperObject->SetObjectL(dirObject);
327 void CT_DirScanData::DoCmdAbbreviatedPath(const TDesC& aSection)
329 INFO_PRINTF1(_L("Getting directory abbreviated path!"));
332 if (GET_MANDATORY_STRING_PARAMETER(KExpected(), aSection, expected))
335 abbPath.Set(iDirScan->AbbreviatedPath());
337 if (abbPath != expected)
339 ERR_PRINTF3(_L("Result (%S) didn't match with expected result (%S)!"), &abbPath, &expected);
340 SetBlockResult(EFail);
344 INFO_PRINTF2(_L("Result (%S) match with expected result!"), &abbPath);
349 void CT_DirScanData::DoCmdFullPath(const TDesC& aSection)
351 INFO_PRINTF1(_L("Getting directory full path!"));
354 if (GET_MANDATORY_STRING_PARAMETER(KExpected(), aSection, expected))
357 fullPath.Set(iDirScan->FullPath());
359 if (fullPath != expected)
361 ERR_PRINTF3(_L("Result (%S) didn't match with expected result (%S)!"), &fullPath, &expected);
362 SetBlockResult(EFail);
366 INFO_PRINTF2(_L("Result (%S) match with expected result!"), &fullPath);
372 TBool CT_DirScanData::ConvertToSortKey(const TDesC& aSortKeyStr, TUint& aSortKey)
376 if (aSortKeyStr == KESortNone)
378 aSortKey = ESortNone;
380 else if (aSortKeyStr == KESortByName)
382 aSortKey = ESortByName;
384 else if (aSortKeyStr == KESortByExt)
386 aSortKey = ESortByExt;
388 else if (aSortKeyStr == KESortBySize)
390 aSortKey = ESortBySize;
392 else if (aSortKeyStr == KESortByDate)
394 aSortKey = ESortByDate;
396 else if (aSortKeyStr == KESortByUid)
398 aSortKey = ESortByUid;
400 else if (aSortKeyStr == KEDirsAnyOrder)
402 aSortKey = EDirsAnyOrder;
404 else if (aSortKeyStr == KEDirsFirst)
406 aSortKey = EDirsFirst;
408 else if (aSortKeyStr == KEDirsLast)
410 aSortKey = EDirsLast;
412 else if (aSortKeyStr == KEAscending)
414 aSortKey = EAscending;
416 else if (aSortKeyStr == KEDescending)
418 aSortKey = EDescending;
420 else if (aSortKeyStr == KEDirDescending)
422 aSortKey = EDirDescending;
424 else if (aSortKeyStr.Match((_L("*|*"))) != KErrNotFound)
428 TInt location = aSortKeyStr.Match(_L("*|*"));
429 //Converting Left part of the data
430 TPtrC left = aSortKeyStr.Left(location);
431 if (ConvertToSortKey(left, tmpSortKey))
433 aSortKey = tmpSortKey;
440 //Converting right data can be with another "|"
441 TPtrC right = aSortKeyStr.Mid(location + 1);
443 if (ConvertToSortKey(right, tmpSortKey))
445 aSortKey = aSortKey | tmpSortKey;
462 TBool CT_DirScanData::ConvertToScanDirection(const TDesC& aScanDirectionStr, CDirScan::TScanDirection& aScanDirection)
466 if (aScanDirectionStr == KEScanUpTree)
468 aScanDirection = CDirScan::EScanUpTree;
470 else if (aScanDirectionStr == KEScanDownTree)
472 aScanDirection = CDirScan::EScanDownTree;