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.
19 #include "T_FindFileData.h"
22 _LIT( KCmdDelete, "~" );
23 _LIT( KCmdNew, "new" );
24 _LIT( KCmdFile, "File" );
25 _LIT( KCmdFind, "Find" );
26 _LIT( KCmdFindByDir, "FindByDir" );
27 _LIT( KCmdFindByPath, "FindByPath" );
28 _LIT( KCmdFindWild, "FindWild" );
29 _LIT( KCmdFindWildByDir, "FindWildByDir" );
30 _LIT( KCmdFindWildByPath, "FindWildByPath" );
31 _LIT( KCmdSetFindMask, "SetFindMask" );
34 _LIT( KParamFileName, "filename" );
35 _LIT( KParamFileSession, "FileSession" );
36 _LIT( KParamExpected, "expected" );
37 _LIT( KParamPathList, "pathlist" );
38 _LIT( KDriveAtt, "drive_att");
39 _LIT( KDirWrapper, "dir_wrapper");
42 _LIT(KDriveAttLocalStr, "KDriveAttLocal");
43 _LIT(KDriveAttRomStr, "KDriveAttRom");
44 _LIT(KDriveAttRedirectedStr, "KDriveAttRedirected");
45 _LIT(KDriveAttSubstedStr, "KDriveAttSubsted");
46 _LIT(KDriveAttInternalStr, "KDriveAttInternal");
47 _LIT(KDriveAttRemovableStr, "KDriveAttRemovable");
50 CT_FindFileData* CT_FindFileData::NewL()
52 * Two phase constructor
55 CT_FindFileData* ret = new (ELeave) CT_FindFileData();
56 CleanupStack::PushL( ret );
58 CleanupStack::Pop( ret );
62 CT_FindFileData::CT_FindFileData()
65 * Protected constructor. First phase construction
70 void CT_FindFileData::ConstructL()
72 * Protected constructor. Second phase construction
77 CT_FindFileData::~CT_FindFileData()
85 TAny* CT_FindFileData::GetObject()
87 * Return a pointer to the object that the data wraps
89 * @return pointer to the object that the data wraps
95 TBool CT_FindFileData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/ )
97 * Process a command read from the ini file
99 * @param aCommand the command to process
100 * @param aSection the entry in the ini file requiring the command to be processed
102 * @return ETrue if the command is processed
105 TBool retVal = ETrue;
107 if ( aCommand == KCmdDelete )
111 else if ( aCommand == KCmdFile )
113 DoCmdFile( aSection );
115 else if ( aCommand == KCmdFind )
117 DoCmdFind( aSection );
119 else if ( aCommand == KCmdFindByDir )
121 DoCmdFindByDir( aSection );
123 else if ( aCommand == KCmdFindByPath )
125 DoCmdFindByPath( aSection );
127 else if ( aCommand == KCmdFindWild )
129 DoCmdFindWildL( aSection );
131 else if ( aCommand == KCmdFindWildByDir )
133 DoCmdFindWildByDirL( aSection );
135 else if ( aCommand == KCmdFindWildByPath )
137 DoCmdFindWildByPathL( aSection );
139 else if ( aCommand == KCmdNew )
143 else if ( aCommand == KCmdSetFindMask )
145 DoCmdSetFindMask( aSection);
155 void CT_FindFileData::DoCleanup()
156 /** Deletes TFindFile class instance */
158 INFO_PRINTF1( _L( "Delete TFindFile class instance" ) );
163 void CT_FindFileData::DoCmdFile( const TDesC& aSection )
164 /** calls File() and comaperes the result with the expected */
167 strResult.Set( iFindFile->File() );
168 INFO_PRINTF2( _L( "File(): %S" ), &strResult );
171 if ( GET_OPTIONAL_STRING_PARAMETER (KParamExpected, aSection, strExpected) )
173 if ( strExpected.CompareF(strResult) )
175 ERR_PRINTF3( _L( "File returned %S, expected %S") , &strResult, &strExpected );
176 SetBlockResult( EFail );
181 void CT_FindFileData::DoCmdFind( const TDesC& /*aSection*/ )
182 /** performs a search of a file using Find */
184 TInt result = iFindFile->Find();
186 if( result != KErrNone)
188 ERR_PRINTF2( _L( "Find() return error = %d"), result );
193 void CT_FindFileData::DoCmdFindByDir( const TDesC& aSection )
194 /** performs a search of a file using FindByDir */
197 if( GET_MANDATORY_STRING_PARAMETER( KParamFileName, aSection, fileName ) &&
198 GET_MANDATORY_STRING_PARAMETER( KParamPathList, aSection, iPathList ) )
200 TInt err = iFindFile->FindByDir( fileName, iPathList );
204 ERR_PRINTF2( _L( "FindByDir() return error = %d"), err );
210 void CT_FindFileData::DoCmdFindByPath( const TDesC& aSection )
211 /** performs a search of a file using FindByPath */
214 if( GET_MANDATORY_STRING_PARAMETER( KParamFileName, aSection, fileName ) &&
215 GET_MANDATORY_STRING_PARAMETER( KParamPathList, aSection, iPathList ) )
217 TInt err = iFindFile->FindByPath( fileName, &iPathList );
221 ERR_PRINTF2( _L( "FindByPath() return error = %d"), err );
229 void CT_FindFileData::DoCmdFindWildL( const TDesC& aSection)
230 /** performs a search of a file using FindWild */
232 TPtrC dirWrapperName;
233 if (GET_MANDATORY_STRING_PARAMETER(KDirWrapper, aSection, dirWrapperName))
235 CT_DirData *dirWrapper = NULL;
236 TRAPD( error, dirWrapper = static_cast<CT_DirData*>(GetDataWrapperL(dirWrapperName)))
238 if( dirWrapper && (error == KErrNone) )
241 TInt err = iFindFile->FindWild( dir );
245 ERR_PRINTF2( _L( "FindWild() return error = %d"), err );
250 dirWrapper->SetObjectL(dir);
255 ERR_PRINTF2( _L( "Wrong CDir wrapper name %S"), &dirWrapperName );
256 SetBlockResult( EFail );
261 void CT_FindFileData::DoCmdFindWildByDirL( const TDesC& aSection )
262 /** performs a search of a file using FindWildByDir */
265 TPtrC dirWrapperName;
266 if( GET_MANDATORY_STRING_PARAMETER( KParamFileName, aSection, fileName ) &&
267 GET_MANDATORY_STRING_PARAMETER( KParamPathList, aSection, iPathList ) &&
268 GET_MANDATORY_STRING_PARAMETER( KDirWrapper, aSection, dirWrapperName) )
270 CT_DirData *dirWrapper = NULL;
271 TRAPD( error, dirWrapper = static_cast<CT_DirData*>(GetDataWrapperL(dirWrapperName)))
273 if(dirWrapper && (error == KErrNone) )
276 TInt err = iFindFile->FindWildByDir( fileName, iPathList, dir );
280 ERR_PRINTF2( _L( "FindWildByDir() return error = %d"), err );
285 dirWrapper->SetObjectL(dir);
290 ERR_PRINTF2( _L( "Wrong CDir wrapper name %S"), &dirWrapperName );
291 SetBlockResult( EFail );
296 void CT_FindFileData::DoCmdFindWildByPathL( const TDesC& aSection )
297 /** performs a search of a file using FindWildByPath */
300 TPtrC dirWrapperName;
301 if( GET_MANDATORY_STRING_PARAMETER( KParamFileName, aSection, fileName ) &&
302 GET_MANDATORY_STRING_PARAMETER( KParamPathList, aSection, iPathList ) &&
303 GET_MANDATORY_STRING_PARAMETER( KDirWrapper, aSection, dirWrapperName) )
305 CT_DirData *dirWrapper = NULL;
306 TRAPD( error, dirWrapper = static_cast<CT_DirData*>(GetDataWrapperL(dirWrapperName)))
308 if( dirWrapper && (error == KErrNone))
311 TInt err = iFindFile->FindWildByPath( fileName, &iPathList, dir );
315 ERR_PRINTF2( _L( "FindWildByPath() return error = %d"), err );
320 dirWrapper->SetObjectL(dir);
325 ERR_PRINTF2( _L( "Wrong CDir wrapper name %S"), &dirWrapperName );
326 SetBlockResult( EFail );
333 void CT_FindFileData::DoCmdNew( const TDesC& aSection )
334 /** Creates new TFindFile class instance */
339 if( GET_MANDATORY_STRING_PARAMETER( KParamFileSession, aSection, fsObjectName ) )
341 RFs* fsObject = NULL;
342 TRAPD( err, fsObject = (RFs*)GetDataObjectL(fsObjectName));
343 if ( err == KErrNone )
345 INFO_PRINTF1( _L( "Create new TFindFile class instance." ) );
346 TRAP( err, iFindFile = new (ELeave) TFindFile( *fsObject ) );
347 if ( err != KErrNone )
349 ERR_PRINTF3( _L( "new TFindFile(%S) error %d" ), &fsObjectName, err );
350 SetBlockResult( EFail );
355 ERR_PRINTF3( _L( "Unrecognized object name parameter value: %S. Error %d"), &fsObjectName, err );
356 SetBlockResult( EFail );
361 void CT_FindFileData::DoCmdSetFindMask( const TDesC& aSection )
362 /** Specify a combination of drive attributes */
365 if( GetDriveAttsFromConfig( aSection, iniMask ) )
367 INFO_PRINTF2( _L( "Mask is %d"), iniMask );
368 TInt err = iFindFile->SetFindMask( iniMask );
370 if ( err != KErrNone)
372 ERR_PRINTF2( _L( "SetFindMask return error = %d"), err );
377 INFO_PRINTF1( _L( "SetFindMask OK"));
383 TBool CT_FindFileData::ConvertToDriveAtts(const TDesC& aDriveAttStr, TUint& aDriveAtt)
384 /** Convert string to mask */
387 if ( aDriveAttStr==KDriveAttLocalStr )
389 aDriveAtt=KDriveAttLocal;
391 else if ( aDriveAttStr==KDriveAttRomStr )
393 aDriveAtt=KDriveAttRom;
395 else if ( aDriveAttStr==KDriveAttRedirectedStr )
397 aDriveAtt=KDriveAttRedirected;
399 else if ( aDriveAttStr==KDriveAttSubstedStr )
401 aDriveAtt=KDriveAttSubsted;
403 else if ( aDriveAttStr==KDriveAttInternalStr )
405 aDriveAtt=KDriveAttInternal;
407 else if ( aDriveAttStr==KDriveAttRemovableStr )
409 aDriveAtt=KDriveAttRemovable;
413 TInt location = aDriveAttStr.Match(_L("*|*"));
414 if( location!=KErrNotFound )
416 //Converting Left part of the data
417 TPtrC tempStr = aDriveAttStr.Left(location);
418 ret=ConvertToDriveAtts(tempStr, aDriveAtt);
420 //Converting right data can be with another "|"
421 tempStr.Set(aDriveAttStr.Mid(location+1));
424 if ( ConvertToDriveAtts(tempStr, driveAttTmp) )
426 aDriveAtt=aDriveAtt|driveAttTmp;
443 TBool CT_FindFileData::GetDriveAttsFromConfig(const TDesC& aSection, TUint& aDriveAtt)
446 TBool ret = GET_MANDATORY_STRING_PARAMETER(KDriveAtt(), aSection, driveAttStr);
450 if ( !ConvertToDriveAtts(driveAttStr, aDriveAtt) )
453 ret=GET_MANDATORY_INT_PARAMETER(KDriveAtt(), aSection, intTemp);