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_FileManData
27 #include "T_FileManData.h"
28 #include "T_SfSrvServer.h"
30 const TInt KMaxFileNameLength =255;
35 _LIT(KFileName, "filename");
36 _LIT(KFileFrom, "filefrom");
37 _LIT(KFileTo, "fileto");
38 _LIT(KOldName, "oldname");
39 _LIT(KNewName, "newname");
40 _LIT(KRFsObject, "rfsObject");
41 _LIT(KRFileObject, "rfileObject");
42 _LIT(KUseObserver, "use_observer");
43 _LIT(KAsync, "async");
45 _LIT(KSetMask, "setmask");
46 _LIT(KClearMask, "clearmask");
47 _LIT(KOperation, "operation");
48 _LIT(KCurrentAction, "current_action");
49 _LIT(KBytes, "bytes");
50 _LIT(KError, "error");
51 _LIT(KTarget, "target");
52 _LIT(KSource, "source");
53 _LIT(KNotifyType, "notify_type");
54 _LIT(KReadHistory, "read_history");
56 _LIT(KNullDesCStr, "KNullDesC");
57 _LIT(KTotalBytes, "total_bytes");
59 _LIT(KClearHistory, "clear_history");
60 _LIT(KSetTcontrol, "set_tcontrol");
61 //For searching file names.
62 _LIT(KPattern, "*%S*");
65 _LIT(KCmdNewL, "NewL");
66 _LIT(KCmdAttribs, "Attribs");
67 _LIT(KCmdCopy, "Copy");
68 _LIT(KCmdMove, "Move");
69 _LIT(KCmdDelete, "Delete");
70 _LIT(KCmdRename, "Rename");
71 _LIT(KCmdRmDir, "RmDir");
72 _LIT(KCmdSetObserver, "SetObserver");
73 _LIT(KCmdCurrentAction, "CurrentAction");
74 _LIT(KCmdGetCurrentTarget, "GetCurrentTarget");
75 _LIT(KCmdGetCurrentSource, "GetCurrentSource");
76 _LIT(KCmdBytesTransferredByCopyStep, "BytesTransferredByCopyStep");
77 _LIT(KCmdCurrentEntry, "CurrentEntry");
78 _LIT(KCmdAbbreviatedPath, "AbbreviatedPath");
79 _LIT(KCmdFullPath, "FullPath");
80 _LIT(KCmdGetLastError, "GetLastError");
81 _LIT(KCmdGetMoreInfoAboutError, "GetMoreInfoAboutError");
82 _LIT(KCmdDestructor, "~");
85 _LIT(KENone, "ENone");
86 _LIT(KEAttribs, "EAttribs");
87 _LIT(KECopy, "ECopy");
88 _LIT(KEDelete, "EDelete");
89 _LIT(KEMove, "EMove");
90 _LIT(KERename, "ERename");
91 _LIT(KERmDir, "ERmDir");
92 _LIT(KERenameInvalidEntry, "ERenameInvalidEntry");
93 _LIT(KECopyFromHandle, "ECopyFromHandle");
97 _LIT(KEOverWrite, "EOverWrite");
98 _LIT(KERecurse, "ERecurse");
101 _LIT(KEContinue, "EContinue");
102 _LIT(KEAbort, "EAbort");
103 _LIT(KECancel, "ECancel");
104 _LIT(KERetry, "ERetry");
107 _LIT(KENoExtraInformation, "ENoExtraInformation");
108 _LIT(KEInitializationFailed, "EInitializationFailed");
109 _LIT(KEScanNextDirectoryFailed, "EScanNextDirectoryFailed");
110 _LIT(KESrcOpenFailed, "ESrcOpenFailed");
111 _LIT(KETrgOpenFailed, "ETrgOpenFailed");
112 _LIT(KENoFilesProcessed, "ENoFilesProcessed");
115 _LIT(KNotifyStarted, "started");
116 _LIT(KNotifyOperation, "operation");
117 _LIT(KNotifyEnded, "ended");
121 CT_FileManData* CT_FileManData::NewL()
123 * Two phase constructor
126 CT_FileManData* ret = new (ELeave) CT_FileManData();
127 CleanupStack::PushL(ret);
129 CleanupStack::Pop(ret);
134 CT_FileManData::CT_FileManData()
136 , iAsyncErrorIndex(0)
138 , iFileManObserver(NULL)
139 , iUseTControl(EFalse)
142 * Protected constructor. First phase construction
148 void CT_FileManData::ConstructL()
150 * Protected constructor. Second phase construction
156 CT_FileManData::~CT_FileManData()
163 iAttribs.ResetAndDestroy();
164 iCopy.ResetAndDestroy();
165 iDelete.ResetAndDestroy();
166 iMove.ResetAndDestroy();
167 iRename.ResetAndDestroy();
168 iRmDir.ResetAndDestroy();
173 TAny* CT_FileManData::GetObject()
179 TBool CT_FileManData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
181 * Process a command read from the ini file
183 * @param aCommand the command to process
184 * @param aSection the section in the ini file requiring the command to be processed
186 * @return ETrue if the command is processed
189 TBool retVal = ETrue;
191 if (aCommand == KCmdNewL)
195 else if (aCommand == KCmdDestructor)
199 else if (aCommand == KCmdAttribs)
201 DoCmdAttribsL(aSection, aAsyncErrorIndex);
203 else if (aCommand == KCmdCopy)
205 DoCmdCopyL(aSection, aAsyncErrorIndex);
207 else if (aCommand == KCmdMove)
209 DoCmdMoveL(aSection, aAsyncErrorIndex);
211 else if (aCommand == KCmdDelete)
213 DoCmdDeleteL(aSection, aAsyncErrorIndex);
215 else if (aCommand == KCmdRename)
217 DoCmdRenameL(aSection, aAsyncErrorIndex);
219 else if (aCommand == KCmdRmDir)
221 DoCmdRmDirL(aSection, aAsyncErrorIndex);
223 else if (aCommand == KCmdSetObserver)
227 else if (aCommand == KCmdCurrentAction)
229 DoCmdCurrentAction(aSection);
231 else if (aCommand == KCmdGetCurrentTarget)
233 DoCmdGetCurrentTarget(aSection);
235 else if (aCommand == KCmdGetCurrentSource)
237 DoCmdGetCurrentSource(aSection);
239 else if (aCommand == KCmdBytesTransferredByCopyStep)
241 DoCmdBytesTransferredByCopyStep(aSection);
243 else if(aCommand == KCmdCurrentEntry)
245 DoCmdCurrentEntryL(aSection);
247 else if(aCommand == KCmdAbbreviatedPath)
249 DoCmdAbbreviatedPath(aSection);
251 else if(aCommand == KCmdFullPath)
253 DoCmdFullPath(aSection);
255 else if(aCommand == KCmdGetLastError)
257 DoCmdGetLastError(aSection);
259 else if(aCommand == KCmdGetMoreInfoAboutError)
261 DoCmdGetMoreInfoAboutError(aSection);
266 void CT_FileManData::DoCleanup()
268 INFO_PRINTF1(_L("Doing cleanup"));
278 /** Inform the observer that an operation is about to start **/
279 MFileManObserver::TControl CT_FileManData::NotifyFileManStarted()
281 THistoryData *record = new THistoryData();
282 CreateHistoryRecord(*record);
283 iStartedHistory.Append(record);
284 if(record->iLastError != KErrNone)
288 SetAsyncError(iAsyncErrorIndex, record->iLastError);
293 SetError(record->iLastError);
296 TControl ret = EContinue;
297 //Check if we need to return TControl value specified in INI.
298 if(iUseTControl && iObserverNotifyType == ENotifyStarted)
300 TBuf<KMaxFileNameLength> buffer;
301 buffer.Format(KPattern(), &iNotifyFileName);
302 //Check if we need to return TControl for this file.
303 if(record->iCurrentSource.Match(buffer) != KErrNotFound)
305 iUseTControl = EFalse;
312 /** Informs the observer that an operation, i.e. a copy or a move, is proceeding. **/
313 MFileManObserver::TControl CT_FileManData::NotifyFileManOperation()
315 THistoryData *record = new THistoryData();
316 CreateHistoryRecord(*record);
317 iOperationHistory.Append(record);
318 if(record->iLastError != KErrNone)
322 SetAsyncError(iAsyncErrorIndex, record->iLastError);
327 SetError(record->iLastError);
330 TControl ret = EContinue;
331 //Check if we need to return TControl value specified in INI.
332 if(iUseTControl && iObserverNotifyType == ENotifyOperation)
334 TBuf<KMaxFileNameLength> buffer;
335 buffer.Format(KPattern(), &iNotifyFileName);
336 //Check if we need to return TControl for this file.
337 if(record->iCurrentSource.Match(buffer) != KErrNotFound)
339 iUseTControl = EFalse;
346 /** Informs the observer that an operation is complete. **/
347 MFileManObserver::TControl CT_FileManData::NotifyFileManEnded()
349 THistoryData *record = new THistoryData();
350 CreateHistoryRecord(*record);
351 iEndedHistory.Append(record);
352 if(record->iLastError != KErrNone)
356 SetAsyncError(iAsyncErrorIndex, record->iLastError);
361 SetError(record->iLastError);
364 TControl ret = EContinue;
365 //Check if we need to return TControl value specified in INI.
366 if(iUseTControl && iObserverNotifyType == ENotifyEnded)
368 TBuf<KMaxFileNameLength> buffer;
369 buffer.Format(KPattern(), &iNotifyFileName);
370 //Check if we need to return TControl for this file.
371 if(record->iCurrentSource.Match(buffer) != KErrNotFound)
373 iUseTControl = EFalse;
380 void CT_FileManData::DoCmdNewL(const TDesC& aSection)
383 TBool useObserver = EFalse;
385 GET_OPTIONAL_BOOL_PARAMETER(KUseObserver, aSection, useObserver);
388 RFs* rfsObject = NULL;
389 if (GET_MANDATORY_STRING_PARAMETER(KRFsObject, aSection, rfsObjectName))
391 rfsObject = (RFs*)GetDataObjectL(rfsObjectName);
397 INFO_PRINTF1(_L("CFileMan::NewL(RFs, MFileManObserver)"));
398 TRAP(err, iFileMan = CFileMan::NewL(*rfsObject, iFileManObserver));
402 INFO_PRINTF1(_L("CFileMan::NewL(RFs)"));
403 TRAP(err, iFileMan = CFileMan::NewL(*rfsObject));
407 ERR_PRINTF1(_L("CFileMan object is not created"));
408 SetBlockResult(EFail);
412 void CT_FileManData::DoCmdAttribsL(const TDesC& aSection, TInt aAsyncErrorIndex)
414 INFO_PRINTF1(_L("Setting attributes!"));
416 TBool dataOk = ETrue;
418 //Reading path for file or files.
420 if (!GET_MANDATORY_STRING_PARAMETER(KFileName, aSection, fileName))
425 //Reading new TTime from ini
428 if(GET_MANDATORY_STRING_PARAMETER(KTime, aSection, inputTime))
430 TInt err = iniTime.Set(inputTime);
433 ERR_PRINTF3(_L("Cannot convert (%S) to time. Error: %d"), &inputTime ,err);
435 SetBlockResult(EFail);
443 //Reading Async parameter (True/False)
444 TBool async = EFalse;
445 if(!GET_MANDATORY_BOOL_PARAMETER(KAsync, aSection, async))
449 //Read SetMask attribute
451 if(!FileserverUtil::GetAttMask(*this, aSection, KSetMask(), setMask))
456 //Read ClearMask attribute
458 if(!FileserverUtil::GetAttMask(*this, aSection, KClearMask(), clearMask))
463 //Read operation TSwitch
465 if(!GetOperationFromConfig(KOperation(), aSection, operation))
471 TInt error = KErrNone;
474 CActiveCallback* active = CActiveCallback::NewLC(*this);
475 iAttribs.AppendL(active);
476 CleanupStack::Pop(active);
477 error = iFileMan->Attribs(fileName, setMask, clearMask, iniTime, operation, active->iStatus);
478 if(error == KErrNone)
480 active->Activate(aAsyncErrorIndex);
481 iAsyncErrorIndex = aAsyncErrorIndex;
488 error = iFileMan->Attribs(fileName, setMask, clearMask, iniTime, operation);
490 if (error != KErrNone)
492 ERR_PRINTF3(_L("Attribs(%S) Error: %d"), &fileName, error);
497 INFO_PRINTF2(_L("Attribs operation on (%S) is successfull!"), &fileName);
501 void CT_FileManData::DoCmdCopyL(const TDesC& aSection, TInt aAsyncErrorIndex)
503 TBool clearHistory = EFalse;
504 GET_OPTIONAL_BOOL_PARAMETER(KClearHistory, aSection, clearHistory);
509 TBool setTControl = EFalse;
510 GET_OPTIONAL_BOOL_PARAMETER(KSetTcontrol, aSection, setTControl);
513 ReadTControl(aSection);
516 INFO_PRINTF1(_L("Coping files!"));
517 TBool dataOk = ETrue;
519 TPtrC rfileObjectName;
520 RFile* rfileObject = NULL;
522 if (!GET_OPTIONAL_STRING_PARAMETER(KOldName, aSection, oldName))
524 if (GET_OPTIONAL_STRING_PARAMETER(KRFileObject, aSection, rfileObjectName))
526 rfileObject = (RFile*)GetDataObjectL(rfileObjectName);
530 ERR_PRINTF1(_L("Cannot read \"oldname\" or \"rfileObject\" arguments!"));
531 SetBlockResult(EFail);
537 if (!GET_MANDATORY_STRING_PARAMETER(KNewName, aSection, newName))
543 if (!GetOperationFromConfig(KOperation, aSection, operation))
548 if (!GET_MANDATORY_BOOL_PARAMETER(KAsync, aSection, async))
555 TInt error = KErrNone;
558 CActiveCallback* active = CActiveCallback::NewLC(*this);
559 iCopy.AppendL(active);
560 CleanupStack::Pop(active);
563 error = iFileMan->Copy(*rfileObject, newName, operation, active->iStatus);
567 error = iFileMan->Copy(oldName, newName, operation, active->iStatus);
569 if(error == KErrNone)
571 active->Activate(aAsyncErrorIndex);
572 iAsyncErrorIndex = aAsyncErrorIndex;
581 error = iFileMan->Copy(*rfileObject, newName, operation);
585 error = iFileMan->Copy(oldName, newName, operation);
588 if (error != KErrNone)
590 ERR_PRINTF2(_L("Copy(), Error: %d"), error);
595 INFO_PRINTF1(_L("Copy() operation is successfully!"));
600 void CT_FileManData::DoCmdDeleteL(const TDesC& aSection, TInt aAsyncErrorIndex)
602 TBool clearHistory = EFalse;
603 GET_OPTIONAL_BOOL_PARAMETER(KClearHistory, aSection, clearHistory);
608 TBool setTControl = EFalse;
609 GET_OPTIONAL_BOOL_PARAMETER(KSetTcontrol, aSection, setTControl);
612 ReadTControl(aSection);
615 INFO_PRINTF1(_L("Deleting files!"));
617 TBool dataOk = ETrue;
619 if (GET_MANDATORY_STRING_PARAMETER(KFileName, aSection, fileName))
621 if(fileName == KNullDesCStr)
623 fileName.Set(KNullDesC);
631 if(!GetOperationFromConfig(KOperation, aSection, operation))
635 TBool async = EFalse;
636 if (!GET_MANDATORY_BOOL_PARAMETER(KAsync, aSection, async))
642 TInt error = KErrNone;
645 CActiveCallback* active = CActiveCallback::NewLC(*this);
646 iDelete.AppendL(active);
647 CleanupStack::Pop(active);
648 error = iFileMan->Delete(fileName, operation, active->iStatus);
649 if (error == KErrNone)
651 active->Activate(aAsyncErrorIndex);
652 iAsyncErrorIndex = aAsyncErrorIndex;
659 error = iFileMan->Delete(fileName, operation);
662 if (error != KErrNone)
664 ERR_PRINTF3(_L("Delete (%S), Error: %d"), &fileName, error);
669 INFO_PRINTF2(_L("Delete (%S) operation is successfully!"), &fileName);
674 void CT_FileManData::DoCmdMoveL(const TDesC& aSection, TInt aAsyncErrorIndex)
676 TBool clearHistory = EFalse;
677 GET_OPTIONAL_BOOL_PARAMETER(KClearHistory, aSection, clearHistory);
682 TBool setTControl = EFalse;
683 GET_OPTIONAL_BOOL_PARAMETER(KSetTcontrol, aSection, setTControl);
686 ReadTControl(aSection);
689 INFO_PRINTF1(_L("Moving files!"));
691 TBool dataOk = ETrue;
693 if (!GET_MANDATORY_STRING_PARAMETER(KFileFrom, aSection, fileFrom))
699 if (!GET_MANDATORY_STRING_PARAMETER(KFileTo, aSection, fileTo))
704 if (!GET_MANDATORY_BOOL_PARAMETER(KAsync, aSection, async))
709 if (!GetOperationFromConfig(KOperation, aSection, operation))
715 TInt error = KErrNone;
718 CActiveCallback* active = CActiveCallback::NewLC(*this);
719 iMove.AppendL(active);
720 CleanupStack::Pop(active);
721 error = iFileMan->Move(fileFrom, fileTo, operation, active->iStatus);
722 if(error == KErrNone)
724 active->Activate(aAsyncErrorIndex);
725 iAsyncErrorIndex = aAsyncErrorIndex;
732 error = iFileMan->Move(fileFrom, fileTo, operation);
734 if (error != KErrNone)
736 ERR_PRINTF2(_L("Move(), Error: %d"), error);
741 INFO_PRINTF1(_L("Move() operation is successfully!"));
746 void CT_FileManData::DoCmdRenameL(const TDesC& aSection, TInt aAsyncErrorIndex)
748 TBool clearHistory = EFalse;
749 GET_OPTIONAL_BOOL_PARAMETER(KClearHistory, aSection, clearHistory);
754 TBool setTControl = EFalse;
755 GET_OPTIONAL_BOOL_PARAMETER(KSetTcontrol, aSection, setTControl);
758 ReadTControl(aSection);
760 INFO_PRINTF1(_L("Renaming files!"));
762 TBool dataOk = ETrue;
766 if (!GET_MANDATORY_STRING_PARAMETER(KOldName, aSection, oldName))
773 if (!GET_MANDATORY_STRING_PARAMETER(KNewName, aSection, newName))
778 //Rading TSwitch - Operation
780 if (!GetOperationFromConfig(KOperation(), aSection, operation))
786 if (!GET_MANDATORY_BOOL_PARAMETER(KAsync, aSection, async))
792 TInt error = KErrNone;
795 CActiveCallback* active = CActiveCallback::NewLC(*this);
796 iRename.AppendL(active);
797 CleanupStack::Pop(active);
798 error = iFileMan->Rename(oldName, newName, operation, active->iStatus);
799 if(error == KErrNone)
801 active->Activate(aAsyncErrorIndex);
802 iAsyncErrorIndex = aAsyncErrorIndex;
809 error = iFileMan->Rename(oldName, newName, operation);
811 if (error != KErrNone)
813 ERR_PRINTF2(_L("Rename() Error: %d"), error);
818 INFO_PRINTF1(_L("Rename() operation is successfully!"));
823 void CT_FileManData::DoCmdRmDirL(const TDesC& aSection, TInt aAsyncErrorIndex)
825 INFO_PRINTF1(_L("Removing directory!"));
827 TBool dataOk = ETrue;
830 if (!GET_MANDATORY_STRING_PARAMETER(KPath, aSection, path))
835 TBool async = EFalse;
836 if (!GET_MANDATORY_BOOL_PARAMETER(KAsync, aSection, async))
843 TInt error = KErrNone;
846 CActiveCallback* active = CActiveCallback::NewLC(*this);
847 iRmDir.AppendL(active);
848 CleanupStack::Pop(active);
849 error = iFileMan->RmDir(path, active->iStatus);
850 if(error == KErrNone)
852 active->Activate(aAsyncErrorIndex);
853 iAsyncErrorIndex = aAsyncErrorIndex;
860 error = iFileMan->RmDir(path);
862 if (error != KErrNone)
864 ERR_PRINTF3(_L("RmDir(%S), Error: %d"), &path, error);
869 INFO_PRINTF2(_L("Callled RmDir(%S)"), &path);
874 void CT_FileManData::DoCmdSetObserver()
876 INFO_PRINTF1(_L("Setting observer"));
878 iFileMan->SetObserver(this);
881 void CT_FileManData::DoCmdCurrentAction(const TDesC& aSection)
883 TBool readHistory = EFalse;
884 GET_OPTIONAL_BOOL_PARAMETER(KReadHistory, aSection, readHistory);
885 CFileMan::TAction currentAction = CFileMan::ENone;
889 /** Get needed history array **/
890 RPointerArray<THistoryData>* history = GetHistoryDataByType(aSection);
893 CFileMan::TAction expectedAction;
895 if(GetActionFromConfig(KCurrentAction(), aSection, expectedAction))
897 CFileMan::TAction action;
898 TInt count = history->Count();
899 /** Search for expected TAction in history **/
900 for(TInt i = 0; (i < count) && (!found); i++)
902 action = ((*history)[i])->iCurrentAction;
903 if( action == expectedAction)
905 currentAction = action;
911 TPtrC expectedActionStr;
912 ConvertActionToString(expectedAction, expectedActionStr);
913 ERR_PRINTF2(_L("CurrentAction() %S not found in history!"), &expectedActionStr);
914 SetBlockResult(EFail);
919 ERR_PRINTF2(_L("Cannot read %S"), &KCurrentAction());
920 SetBlockResult(EFail);
926 currentAction = iFileMan->CurrentAction();
932 ConvertActionToString(currentAction, actionStr);
934 CFileMan::TAction expectedAction;
935 if(GetActionFromConfig(KCurrentAction(), aSection, expectedAction))
937 TPtrC expectedActionStr;
938 ConvertActionToString(expectedAction, expectedActionStr);
939 if(expectedAction != currentAction)
941 ERR_PRINTF3(_L("CurrentAction(): %S != %S Expected Action"), &actionStr, &expectedActionStr);
942 SetBlockResult(EFail);
946 INFO_PRINTF3(_L("CurrentAction(): %S == %S Expected Action"), &actionStr, &expectedActionStr);
951 INFO_PRINTF2(_L("CurrentAction: %S"), &actionStr);
956 void CT_FileManData::DoCmdGetCurrentTarget(const TDesC& aSection)
958 TBool readHistory = EFalse;
959 GET_OPTIONAL_BOOL_PARAMETER(KReadHistory, aSection, readHistory);
964 /** Get needed history array **/
965 RPointerArray<THistoryData>* history = GetHistoryDataByType(aSection);
968 TPtrC expectedTarget;
970 if(GET_MANDATORY_STRING_PARAMETER(KTarget, aSection, expectedTarget))
972 TInt count = history->Count();
973 /** Search for expected target in history **/
974 for(TInt i = 0; (!found) && (i < count); i++)
976 if( ((*history)[i])->iCurrentTarget == expectedTarget)
978 target = ((*history)[i])->iCurrentTarget;
984 ERR_PRINTF2(_L("GetCurrentTarget() %S not found in history!"), &expectedTarget);
985 SetBlockResult(EFail);
992 iFileMan->GetCurrentTarget(target);
996 TPtrC expectedTarget;
997 if(GET_OPTIONAL_STRING_PARAMETER(KTarget, aSection, expectedTarget))
999 if(target == expectedTarget)
1001 INFO_PRINTF3(_L("GetCurrentTarget() %S == %S ExpectedResult"), &target, &expectedTarget);
1005 ERR_PRINTF3(_L("GetCurrentTarget() %S != %S ExpectedResult"), &target, &expectedTarget);
1006 SetBlockResult(EFail);
1012 INFO_PRINTF2(_L("GetCurrentTarget() %S"), &target);
1016 void CT_FileManData::DoCmdGetCurrentSource(const TDesC& aSection)
1018 TBool readHistory = EFalse;
1019 GET_OPTIONAL_BOOL_PARAMETER(KReadHistory, aSection, readHistory);
1021 TBool found = ETrue;
1024 /** Get needed history array **/
1025 RPointerArray<THistoryData>* history = GetHistoryDataByType(aSection);
1028 TPtrC expectedSource;
1030 if(GET_MANDATORY_STRING_PARAMETER(KSource, aSection, expectedSource))
1032 TInt count = history->Count();
1033 /** Search for expected source in history **/
1034 for(TInt i = 0; (!found) && (i < count); i++)
1036 if( (*history)[i]->iCurrentSource == expectedSource)
1038 source = (*history)[i]->iCurrentSource;
1044 ERR_PRINTF2(_L("GetCurrentSource() %S not found in history!"), &expectedSource);
1045 SetBlockResult(EFail);
1052 iFileMan->GetCurrentSource(source);
1057 TPtrC expectedSource;
1058 if(GET_OPTIONAL_STRING_PARAMETER(KSource, aSection, expectedSource))
1060 if(source == expectedSource)
1062 INFO_PRINTF3(_L("GetCurrentSource() %S == %S ExpectedResult"), &source, &expectedSource);
1066 ERR_PRINTF3(_L("GetCurrentSource() %S != %S ExpectedResult"), &source, &expectedSource);
1067 SetBlockResult(EFail);
1073 INFO_PRINTF2(_L("GetCurrentSource() %S"), &source);
1078 void CT_FileManData::DoCmdBytesTransferredByCopyStep(const TDesC& aSection)
1080 TBool readHistory = EFalse;
1081 GET_OPTIONAL_BOOL_PARAMETER(KReadHistory, aSection, readHistory);
1083 TBool found = ETrue;
1086 /** Get needed history array **/
1087 RPointerArray<THistoryData>* history = GetHistoryDataByType(aSection);
1092 if(GET_MANDATORY_INT_PARAMETER(KBytes, aSection, expectedBytes))
1094 TBool totalBytes = EFalse;
1095 GET_OPTIONAL_BOOL_PARAMETER(KTotalBytes, aSection, totalBytes);
1096 TInt count = history->Count();
1098 /** Search for expected transferred bytes in history **/
1099 for(TInt i = 0; (!found) && (i < count); i++)
1101 bytesTemp = ((*history)[i])->iBytesTransferred;
1108 if( bytesTemp == expectedBytes)
1121 ERR_PRINTF2(_L("BytesTransferredByCopyStep() %d not found in history!"), expectedBytes);
1122 SetBlockResult(EFail);
1129 bytes = iFileMan->BytesTransferredByCopyStep();
1134 if(GET_OPTIONAL_INT_PARAMETER(KBytes, aSection, expectedBytes))
1136 if(expectedBytes != bytes)
1138 ERR_PRINTF3(_L("BytesTransferredByCopyStep(): %d != %d Expected Bytes"), bytes, expectedBytes);
1139 SetBlockResult(EFail);
1143 INFO_PRINTF3(_L("BytesTransferredByCopyStep(): %d == %d Expected Bytes"), bytes, expectedBytes);
1148 INFO_PRINTF2(_L("BytesTransferredByCopyStep(): %d"), bytes);
1152 void CT_FileManData::DoCmdCurrentEntryL(const TDesC& aSection)
1155 TEntry* entryObject = NULL;
1156 TBool found = ETrue;
1157 TBool readHistory = EFalse;
1158 GET_OPTIONAL_BOOL_PARAMETER(KReadHistory, aSection, readHistory);
1161 /** Get needed history array **/
1162 RPointerArray<THistoryData>* history = GetHistoryDataByType(aSection);
1167 if(GET_MANDATORY_STRING_PARAMETER(KName, aSection, expectedName))
1169 TInt count = history->Count();
1171 /** Search for expected TEntry.iName in history **/
1172 for(TInt i = 0; (!found) && (i < count); i++)
1174 entry = ((*history)[i])->iCurrentEntry;
1175 if( entry.iName == expectedName)
1177 entryObject = &entry;
1183 ERR_PRINTF1(_L("CurrentEntry() not found in history!"));
1184 SetBlockResult(EFail);
1191 *entryObject = iFileMan->CurrentEntry();
1195 if(!FileserverUtil::VerifyTEntryDataFromIniL(*this, aSection, *entryObject))
1197 SetBlockResult(EFail);
1202 void CT_FileManData::DoCmdAbbreviatedPath(const TDesC& aSection)
1204 TBool readHistory = EFalse;
1205 GET_OPTIONAL_BOOL_PARAMETER(KReadHistory, aSection, readHistory);
1207 TBool found = ETrue;
1210 /** Get needed history array **/
1211 RPointerArray<THistoryData>* history = GetHistoryDataByType(aSection);
1216 if(GET_MANDATORY_STRING_PARAMETER(KPath, aSection, expectedPath))
1218 TInt count = history->Count();
1219 /** Search for expected abbreviated path in history **/
1220 for(TInt i = 0; (!found) && (i < count); i++)
1222 if( ((*history)[i])->iAbbreviatedPath == expectedPath)
1224 path.Set(((*history)[i])->iAbbreviatedPath);
1230 ERR_PRINTF2(_L("AbbreviatedPath() %S not found in history!"), &expectedPath);
1231 SetBlockResult(EFail);
1238 path.Set(iFileMan->AbbreviatedPath());
1244 if(GET_OPTIONAL_STRING_PARAMETER(KPath, aSection, expectedPath))
1246 if(expectedPath.Compare(path) != 0)
1248 ERR_PRINTF3(_L("AbbreviatedPath(): %S != %S Expected Path"), &path, &expectedPath);
1249 SetBlockResult(EFail);
1253 INFO_PRINTF3(_L("AbbreviatedPath(): %S == %S Expected Path"), &path, &expectedPath);
1258 INFO_PRINTF2(_L("AbbreviatedPath(): %S"), &path);
1262 void CT_FileManData::DoCmdFullPath(const TDesC& aSection)
1264 TBool readHistory = EFalse;
1265 GET_OPTIONAL_BOOL_PARAMETER(KReadHistory, aSection, readHistory);
1267 TBool found = ETrue;
1270 /** Get needed history array **/
1271 RPointerArray<THistoryData>* history = GetHistoryDataByType(aSection);
1276 if(GET_MANDATORY_STRING_PARAMETER(KPath, aSection, expectedPath))
1278 TInt count = history->Count();
1279 /** Search for expected full path in history **/
1280 for(TInt i = 0; (!found) && (i < count); i++)
1282 if( ((*history)[i])->iFullPath == expectedPath)
1284 fullPath.Set(((*history)[i])->iFullPath);
1290 ERR_PRINTF2(_L("FullPath() %S not found in history!"), &expectedPath);
1291 SetBlockResult(EFail);
1298 fullPath.Set(iFileMan->FullPath());
1303 if(GET_OPTIONAL_STRING_PARAMETER(KPath, aSection, expectedPath))
1305 if(expectedPath.Compare(fullPath) != 0)
1307 ERR_PRINTF3(_L("FullPath(): %S != %S Expected Path"), &fullPath, &expectedPath);
1308 SetBlockResult(EFail);
1312 INFO_PRINTF3(_L("FullPath(): %S == %S Expected Path"), &fullPath, &expectedPath);
1317 INFO_PRINTF2(_L("FullPath(): %S"), &fullPath);
1321 void CT_FileManData::DoCmdGetLastError(const TDesC& aSection)
1323 TBool readHistory = EFalse;
1324 GET_OPTIONAL_BOOL_PARAMETER(KReadHistory, aSection, readHistory);
1325 TInt lastError = KErrNone;
1326 TBool found = ETrue;
1329 /** Get needed history array **/
1330 RPointerArray<THistoryData>* history = GetHistoryDataByType(aSection);
1335 if(GET_MANDATORY_INT_PARAMETER(KError, aSection, expectedError))
1337 TInt count = history->Count();
1339 /** Search for expected error in history **/
1340 for(TInt i = 0; (!found) && (i < count); i++)
1342 err = (*history)[i]->iLastError;
1343 if( err == expectedError)
1351 ERR_PRINTF2(_L("GetLastError() %d not found in history!"), expectedError);
1352 SetBlockResult(EFail);
1359 lastError = iFileMan->GetLastError();
1364 if(GET_OPTIONAL_INT_PARAMETER(KError, aSection, expectedError))
1366 if(expectedError != lastError)
1368 ERR_PRINTF3(_L("GetLastError(): %d != %d Expected Error"), lastError, expectedError);
1369 SetBlockResult(EFail);
1373 INFO_PRINTF3(_L("GetLastError(): %d == %d Expected Error"), lastError, expectedError);
1378 INFO_PRINTF2(_L("GetLastError(): %d"), lastError);
1383 void CT_FileManData::DoCmdGetMoreInfoAboutError(const TDesC& aSection)
1385 TBool readHistory = EFalse;
1386 GET_OPTIONAL_BOOL_PARAMETER(KReadHistory, aSection, readHistory);
1387 TFileManError lastError;
1388 TBool found = ETrue;
1391 /** Get needed history array **/
1392 RPointerArray<THistoryData>* history = GetHistoryDataByType(aSection);
1395 TFileManError expectedError;
1397 if(GetFileManErrorFromConfig(KError, aSection, expectedError))
1399 TInt count = history->Count();
1400 TFileManError error;
1401 /** Search for expected error in history **/
1402 for(TInt i = 0; (!found) && (i < count); i++)
1404 error = (*history)[i]->iMoreInfoAboutError;
1405 if( (error == expectedError))
1413 ERR_PRINTF2(_L("GetMoreInfoAboutError() %S not found in history!"), expectedError);
1414 SetBlockResult(EFail);
1421 lastError = iFileMan->GetMoreInfoAboutError();
1426 ConvertFileManErrorToString(lastError, errorStr);
1427 TFileManError expectedError;
1428 if(GetFileManErrorFromConfig(KError, aSection, expectedError))
1430 TPtrC expectedErrorStr;
1431 ConvertFileManErrorToString(expectedError, expectedErrorStr);
1433 if(expectedError != lastError)
1435 ERR_PRINTF3(_L("GetMoreInfoAboutError(): %S != %S Expected Error"), &errorStr, &expectedErrorStr);
1436 SetBlockResult(EFail);
1440 INFO_PRINTF3(_L("GetMoreInfoAboutError(): %S == %S Expected Error"), &errorStr, &expectedErrorStr);
1445 INFO_PRINTF2(_L("GetMoreInfoAboutError(): %S"), &errorStr);
1450 void CT_FileManData::RunL(CActive* aActive, TInt aIndex)
1452 Virtual RunL - Called on completion of an asynchronous command
1454 @see MActiveCallback
1455 @param aActive Active Object that RunL has been called on
1458 @leave system wide error code
1461 INFO_PRINTF1(_L("CT_FileManData::RunL Called"));
1462 TBool foundActiveObject = EFalse;
1465 TBool completed=ETrue;
1467 count = iAttribs.Count();
1468 for( index=0; (index<count) && (!foundActiveObject); ++index )
1470 if( aActive == iAttribs[index] )
1472 INFO_PRINTF1(_L("RunL iAttribs called"));
1473 foundActiveObject = ETrue;
1474 iAttribs.Remove(index);
1478 count = iCopy.Count();
1479 for( index=0; (index<count) && (!foundActiveObject); ++index )
1481 if( aActive == iCopy[index] )
1483 INFO_PRINTF1(_L("RunL iCopy called"));
1484 foundActiveObject = ETrue;
1485 iCopy.Remove(index);
1489 count = iDelete.Count();
1490 for( index=0; (index<count) && (!foundActiveObject); ++index )
1492 if( aActive == iDelete[index] )
1494 INFO_PRINTF1(_L("RunL iDelete called"));
1495 foundActiveObject = ETrue;
1496 iDelete.Remove(index);
1500 count = iMove.Count();
1501 for( index=0; (index<count) && (!foundActiveObject); ++index )
1503 if( aActive == iMove[index] )
1505 INFO_PRINTF1(_L("RunL iMove called"));
1506 foundActiveObject = ETrue;
1507 iMove.Remove(index);
1511 count = iRename.Count();
1512 for( index=0; (index<count) && (!foundActiveObject); ++index )
1514 if( aActive == iRename[index] )
1516 INFO_PRINTF1(_L("RunL iRename called"));
1517 foundActiveObject = ETrue;
1518 iRename.Remove(index);
1522 count = iRmDir.Count();
1523 for( index=0; (index<count) && (!foundActiveObject); ++index )
1525 if( aActive == iRmDir[index] )
1527 INFO_PRINTF1(_L("RunL iRmDir called"));
1528 foundActiveObject = ETrue;
1529 iRmDir.Remove(index);
1533 if( foundActiveObject )
1535 TInt err = aActive->iStatus.Int();
1536 if( err != KErrNone )
1538 ERR_PRINTF2(_L("RunL Error %d"), err);
1539 SetAsyncError( aIndex, err );
1540 iAsyncCall = EFalse;
1545 // Reset the outstanding request state
1552 ERR_PRINTF1(_L("Stray RunL signal"));
1553 SetBlockResult(EFail);
1558 void CT_FileManData::DoCancel(CActive* aActive, TInt aIndex)
1560 Virtual DoCancel - Request to cancel the asynchronous command
1562 @see - MActiveCallback
1563 @param aActive Active Object that DoCancel has been called on
1566 @leave system wide error code
1569 INFO_PRINTF1(_L("CT_FileManData::DoCancelL Called"));
1571 TBool foundActiveObject = EFalse;
1576 // See if it is in iAttribs
1577 count = iAttribs.Count();
1578 for( index=0; (index<count) && (!foundActiveObject); ++index )
1580 if( aActive == iAttribs[index] )
1582 INFO_PRINTF1(_L("DoCancel iAttribs called"));
1583 foundActiveObject = ETrue;
1584 iAttribs.Remove(index);
1588 // See if it is in iCopy2
1589 count = iCopy.Count();
1590 for( index=0; (index<count) && (!foundActiveObject); ++index )
1592 if( aActive == iCopy[index] )
1594 INFO_PRINTF1(_L("DoCancel iCopy called"));
1595 foundActiveObject = ETrue;
1596 iCopy.Remove(index);
1600 // See if it is in iDelete
1601 count = iDelete.Count();
1602 for( index=0; (index<count) && (!foundActiveObject); ++index )
1604 if( aActive == iDelete[index] )
1606 INFO_PRINTF1(_L("DoCancel iDelete called"));
1607 foundActiveObject = ETrue;
1608 iDelete.Remove(index);
1612 // See if it is in iMove
1613 count = iMove.Count();
1614 for( index=0; (index<count) && (!foundActiveObject); ++index )
1616 if( aActive == iMove[index] )
1618 INFO_PRINTF1(_L("DoCancel iMove called"));
1619 foundActiveObject = ETrue;
1620 iMove.Remove(index);
1624 // See if it is in iRename
1625 count = iRename.Count();
1626 for( index=0; (index<count) && (!foundActiveObject); ++index )
1628 if( aActive == iRename[index] )
1630 INFO_PRINTF1(_L("DoCancel iRename called"));
1631 foundActiveObject = ETrue;
1632 iRename.Remove(index);
1636 // See if it is in iRmDir
1637 count = iRmDir.Count();
1638 for( index=0; (index<count) && (!foundActiveObject); ++index )
1640 if( aActive == iRmDir[index] )
1642 INFO_PRINTF1(_L("DoCancel iRmDir called"));
1643 foundActiveObject = ETrue;
1644 iRmDir.Remove(index);
1648 if( foundActiveObject )
1650 TInt err = aActive->iStatus.Int();
1651 if( err != KErrNone )
1653 ERR_PRINTF2(_L("DoCancel Error %d"), err);
1654 SetAsyncError( aIndex, err );
1657 // Reset the outstanding request state
1664 ERR_PRINTF1(_L("Stray DoCancel signal"));
1665 SetBlockResult(EFail);
1669 /** Reads TFileManError from INI and converts it to TFileManError type. **/
1670 TBool CT_FileManData::GetFileManErrorFromConfig(const TDesC& aParameterName, const TDesC& aSection, TFileManError& aError)
1673 TBool ret = GET_OPTIONAL_STRING_PARAMETER(aParameterName, aSection, errorStr);
1676 if(errorStr == KENoExtraInformation)
1678 aError = ENoExtraInformation;
1680 else if(errorStr == KEInitializationFailed)
1682 aError = EInitializationFailed;
1684 else if (errorStr == KEScanNextDirectoryFailed)
1686 aError = EScanNextDirectoryFailed;
1688 else if (errorStr == KESrcOpenFailed)
1690 aError = ESrcOpenFailed;
1692 else if (errorStr == KETrgOpenFailed)
1694 aError = ETrgOpenFailed;
1696 else if (errorStr == KENoFilesProcessed)
1698 aError = ENoFilesProcessed;
1708 /** Converts TFileManError type to string **/
1709 void CT_FileManData::ConvertFileManErrorToString(TFileManError& aError, TPtrC& aErrorStr)
1711 if(aError == ENoExtraInformation)
1713 aErrorStr.Set(KENoExtraInformation());
1715 else if(aError == EInitializationFailed)
1717 aErrorStr.Set(KEInitializationFailed());
1719 else if (aError == EScanNextDirectoryFailed)
1721 aErrorStr.Set(KEScanNextDirectoryFailed());
1723 else if (aError == ESrcOpenFailed)
1725 aErrorStr.Set(KESrcOpenFailed());
1727 else if (aError == ETrgOpenFailed)
1729 aErrorStr.Set(KETrgOpenFailed());
1731 else if (aError == ENoFilesProcessed)
1733 aErrorStr.Set(KENoFilesProcessed());
1737 /** Converts CFileMan::TAction type to string **/
1738 void CT_FileManData::ConvertActionToString(CFileMan::TAction aAction, TPtrC& aActionStr)
1740 if (aAction == CFileMan::EAttribs)
1742 aActionStr.Set(KEAttribs());
1744 else if (aAction == CFileMan::ECopy)
1746 aActionStr.Set(KECopy());
1748 else if (aAction == CFileMan::EDelete)
1750 aActionStr.Set(KEDelete());
1752 else if (aAction == CFileMan::EMove)
1754 aActionStr.Set(KEMove());
1756 else if (aAction == CFileMan::ERename)
1758 aActionStr.Set(KERename());
1760 else if (aAction == CFileMan::ERmDir)
1762 aActionStr.Set(KERmDir());
1764 else if (aAction == CFileMan::ERenameInvalidEntry)
1766 aActionStr.Set(KERenameInvalidEntry());
1768 else if (aAction == CFileMan::ECopyFromHandle)
1770 aActionStr.Set(KECopyFromHandle());
1774 aActionStr.Set(KENone());
1779 /** Reads CFileMan::TAction from INI and converts it to CFileMan::TAction type. **/
1780 TBool CT_FileManData::GetActionFromConfig(const TDesC& aParameterName, const TDesC& aSection, CFileMan::TAction& aAction)
1783 TBool ret = GET_OPTIONAL_STRING_PARAMETER(aParameterName, aSection, actionStr);
1786 if (actionStr == KEAttribs)
1788 aAction = CFileMan::EAttribs;
1790 else if (actionStr == KECopy)
1792 aAction = CFileMan::ECopy;
1794 else if (actionStr == KEDelete)
1796 aAction = CFileMan::EDelete;
1798 else if (actionStr == KEMove)
1800 aAction = CFileMan::EMove;
1802 else if (actionStr == KERename)
1804 aAction = CFileMan::ERename;
1806 else if (actionStr == KERmDir)
1808 aAction = CFileMan::ERmDir;
1810 else if (actionStr == KERenameInvalidEntry)
1812 aAction = CFileMan::ERenameInvalidEntry;
1814 else if (actionStr == KECopyFromHandle)
1816 aAction = CFileMan::ECopyFromHandle;
1818 else if (actionStr == KENone)
1820 aAction = CFileMan::ENone;
1830 /** Reads CFileMan::TSwitch from INI and converts it to CFileMan::TSwitch type. **/
1831 TBool CT_FileManData::GetOperationFromConfig(const TDesC& aParameterName, const TDesC& aSection, TUint& aSwitch)
1834 TBool ret=GET_MANDATORY_STRING_PARAMETER(aParameterName, aSection, operation);
1837 if (operation == KEOverWrite)
1839 aSwitch = CFileMan::EOverWrite;
1841 else if (operation == KERecurse)
1843 aSwitch = CFileMan::ERecurse;
1847 TInt operationInt=0;
1848 ret = GET_MANDATORY_INT_PARAMETER(aParameterName, aSection, operationInt);
1851 aSwitch = (CFileMan::TSwitch) operationInt;
1858 /** Clears all arrays with history **/
1859 void CT_FileManData::ClearHistory()
1861 INFO_PRINTF1(_L("Clearing history!"));
1863 iStartedHistory.ResetAndDestroy();
1864 iOperationHistory.ResetAndDestroy();
1865 iEndedHistory.ResetAndDestroy();
1869 * Creates a history entry.
1870 * This method runs only from NotifyFileManStarted(), NotifyFileManOperation(), NotifyFileManEnded().
1872 void CT_FileManData::CreateHistoryRecord(THistoryData& aRecord)
1875 iFileMan->GetCurrentSource(source);
1876 aRecord.iCurrentSource = source;
1879 iFileMan->GetCurrentTarget(target);
1880 aRecord.iCurrentTarget = target;
1882 aRecord.iCurrentEntry = iFileMan->CurrentEntry();
1883 aRecord.iBytesTransferred = iFileMan->BytesTransferredByCopyStep();
1884 aRecord.iCurrentAction = iFileMan->CurrentAction();
1885 aRecord.iLastError = iFileMan->GetLastError();
1886 aRecord.iMoreInfoAboutError = iFileMan->GetMoreInfoAboutError();
1887 aRecord.iFullPath.Set( iFileMan->FullPath() );
1888 aRecord.iAbbreviatedPath.Set( iFileMan->AbbreviatedPath() );
1891 /** Reads type of notification from INI and converts it to TObserverNotifyType **/
1892 TBool CT_FileManData::GetNotifyType(const TDesC& aParameterName, const TDesC& aSection, TObserverNotifyType& aType)
1895 TBool ret=GET_MANDATORY_STRING_PARAMETER(aParameterName, aSection, type);
1898 if (type == KNotifyStarted)
1900 aType = ENotifyStarted;
1902 else if (type == KNotifyOperation)
1904 aType = ENotifyOperation;
1906 else if (type == KNotifyEnded)
1908 aType = ENotifyEnded;
1918 /** Returns specific array of history using TObserverNotifyType value **/
1919 RPointerArray<THistoryData>* CT_FileManData::GetHistoryDataByType(const TDesC& aSection)
1921 TObserverNotifyType type;
1922 RPointerArray<THistoryData>* history = NULL;
1923 //Reads history name which must be returned.
1924 if (GetNotifyType(KNotifyType(), aSection, type))
1926 if(type == ENotifyStarted)
1928 history = (RPointerArray<THistoryData>*)&iStartedHistory;
1930 else if(type == ENotifyOperation)
1932 history = (RPointerArray<THistoryData>*)&iOperationHistory;
1934 else if(type == ENotifyEnded)
1936 history = (RPointerArray<THistoryData>*)&iEndedHistory;
1941 /** Reads TControl from config and converts it to TControl type **/
1942 TBool CT_FileManData::GetTControlFromConfig(const TDesC& aParameterName, const TDesC& aSection, TControl& aFlag)
1945 TBool ret=GET_MANDATORY_STRING_PARAMETER(aParameterName, aSection, flag);
1948 if (flag == KEContinue)
1952 else if (flag == KEAbort)
1956 else if (flag == KECancel)
1960 else if (flag == KERetry)
1972 /** Reads TControl and file name from INI **/
1973 void CT_FileManData::ReadTControl(const TDesC& aSection)
1975 TBool dataOk = ETrue;
1976 if(!GetNotifyType(KNotifyType(), aSection, iObserverNotifyType))
1981 if(GET_MANDATORY_STRING_PARAMETER(KFileName(), aSection, fileName))
1983 iNotifyFileName = fileName;
1989 if(!GetTControlFromConfig(KFlag(), aSection, iTControl))
1995 iUseTControl = ETrue;