filebrowser/engine/FBFileUtils.h
changeset 17 4f2773374eff
child 19 4b22a598b890
equal deleted inserted replaced
15:e11368ed4880 17:4f2773374eff
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     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".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef FILEBROWSER_FILEUTILS_H
       
    19 #define FILEBROWSER_FILEUTILS_H
       
    20 
       
    21 // INCLUDES
       
    22 #include <e32base.h>
       
    23 #include <f32file.h>
       
    24 #include <w32std.h>
       
    25 #include <badesca.h>
       
    26 #include <coedef.h>
       
    27 #include <AknServerApp.h>
       
    28 #include <msvapi.h>
       
    29 #include <AknProgressDialog.h>
       
    30 #include <tz.h>
       
    31 
       
    32 _LIT(KIRAppPath, "z:\\sys\\bin\\irapp.exe");
       
    33 _LIT(KBTAppPath, "z:\\sys\\bin\\btui.exe");
       
    34 _LIT(KUSBAppPath, "z:\\sys\\bin\\usbclasschangeui.exe");
       
    35 _LIT(KErrRdPath, "c:\\resource\\ErrRd");
       
    36 _LIT(KErrRdDir, "c:\\resource\\");
       
    37 
       
    38 
       
    39 // FORWARD DECLARATIONS
       
    40 class CEngine;
       
    41 class CFileBrowserFileOps;
       
    42 class CAknIconArray;
       
    43 class TAknsItemID;
       
    44 class CDocumentHandler;
       
    45 //class CAknWaitDialog;
       
    46 //class CAknProgressDialog;
       
    47 class CEikProgressInfo;
       
    48 class CFBFileOpClient;
       
    49 //class CAknProgressDialog;
       
    50 class CEikProgressInfo;
       
    51 class CAknOpenFileService;
       
    52 class CMessageDigest;
       
    53 
       
    54 // CLASS DECLARATIONS
       
    55 
       
    56 class TSearchAttributes
       
    57 	{
       
    58 public:
       
    59     TFileName       iSearchDir;
       
    60     TFileName       iWildCards;
       
    61     TFileName       iTextInFile;
       
    62     TUint           iMinSize;
       
    63     TUint           iMaxSize;
       
    64     TTime           iMinDate;
       
    65     TTime           iMaxDate;
       
    66     TBool           iRecurse;
       
    67 	};
       
    68 
       
    69 class TDriveEntry
       
    70 	{
       
    71 public:
       
    72     TChar           iLetter;
       
    73     TInt            iNumber;
       
    74     TVolumeInfo     iVolumeInfo;
       
    75     TBuf<64>        iMediaTypeDesc;
       
    76     TBuf<128>       iAttributesDesc;
       
    77     TInt            iIconId;
       
    78 	};
       
    79 
       
    80 class TFileEntry
       
    81 	{
       
    82 public:
       
    83     TFileName       iFullName;	
       
    84     TFileName       iPath;
       
    85     TEntry          iEntry;
       
    86     TInt            iDirEntries;
       
    87     TInt            iIconId;
       
    88 	};
       
    89 
       
    90 class TAppIcon
       
    91 	{
       
    92 public:
       
    93     TInt            iId;
       
    94     TUid            iUid;
       
    95 	};
       
    96 
       
    97 typedef CArrayFixSeg<TDriveEntry> CDriveEntryList;
       
    98 typedef CArrayFixSeg<TFileEntry> CFileEntryList;
       
    99 typedef CArrayFixSeg<TAppIcon> CAppIconList;
       
   100 
       
   101 class TSearchResults
       
   102     {
       
   103 public:
       
   104     TInt iNumberOfFoundFiles;
       
   105     //CFileEntryList iFoundFilesList;
       
   106     };
       
   107 
       
   108 class TOverwriteOptions
       
   109     {
       
   110 public:
       
   111     TBool iDoFileOperations/*(ETrue)*/;
       
   112     TInt iQueryIndex/*(0)*/;
       
   113     TFileName iPostFix;
       
   114     TInt iOverWriteFlags/* = CFileMan::EOverWrite*/;
       
   115     };
       
   116 
       
   117 class CCommandParamsBase : public CBase
       
   118     {
       
   119     };
       
   120 
       
   121 class CCommandParamsAttribs : public CCommandParamsBase
       
   122     {
       
   123 public:
       
   124     TFileEntry iSourceEntry;
       
   125     TUint iSetMask;
       
   126     TUint iClearMask;
       
   127     TTime iTime;
       
   128     TUint iSwitch;
       
   129 public:
       
   130     CCommandParamsAttribs(const TFileEntry& aSourceEntry, TUint aSetMask, TUint aClearMask, const TTime& aTime, TUint aSwitch) : iSourceEntry(aSourceEntry), iSetMask(aSetMask), iClearMask(aClearMask), iTime(aTime), iSwitch(aSwitch) {}
       
   131     };
       
   132     
       
   133 class CCommandParamsCopyOrMove : public CCommandParamsBase
       
   134     {
       
   135 public:
       
   136     TFileEntry iSourceEntry;
       
   137     TFileName iTargetPath;
       
   138     TUint iSwitch;
       
   139 public:
       
   140     CCommandParamsCopyOrMove(const TFileEntry& aSourceEntry, const TDesC& aTargetPath, TUint aSwitch) : iSourceEntry(aSourceEntry), iTargetPath(aTargetPath), iSwitch(aSwitch) {}
       
   141     };
       
   142         
       
   143 class CCommandParamsRename : public CCommandParamsBase
       
   144     {
       
   145 public:
       
   146     TFileEntry iSourceEntry;
       
   147     TFileName iTargetPath;
       
   148     TUint iSwitch;
       
   149 public:
       
   150     CCommandParamsRename(const TFileEntry& aSourceEntry, const TDesC& aTargetPath, TUint aSwitch) : iSourceEntry(aSourceEntry), iTargetPath(aTargetPath), iSwitch(aSwitch) {}
       
   151     };
       
   152 
       
   153 class CCommandParamsDelete : public CCommandParamsBase
       
   154     {
       
   155 public:
       
   156     TFileEntry iSourceEntry;
       
   157     TUint iSwitch;
       
   158 public:
       
   159     CCommandParamsDelete(const TFileEntry& aSourceEntry, TUint aSwitch) : iSourceEntry(aSourceEntry), iSwitch(aSwitch) {}
       
   160     };
       
   161 
       
   162 class CCommandParamsDriveSnapShot : public CCommandParamsBase
       
   163     {
       
   164 public:
       
   165     TInt iSourceDriveLetter;
       
   166     TInt iTargetDriveLetter;
       
   167 public:
       
   168     CCommandParamsDriveSnapShot(TChar aSourceDriveLetter, TChar aTargetDriveLetter) : iSourceDriveLetter(aSourceDriveLetter), iTargetDriveLetter(aTargetDriveLetter) {}
       
   169     };
       
   170     
       
   171 class TCommand
       
   172     {
       
   173 public:
       
   174     TInt iCommandId;
       
   175     CCommandParamsBase* iParameters;
       
   176 public:
       
   177     TCommand(TInt aCommandId, CCommandParamsBase* aParameters) : iCommandId(aCommandId), iParameters(aParameters) {}
       
   178     };
       
   179 
       
   180 typedef CArrayFixSeg<TCommand> CCommandArray;
       
   181 
       
   182 
       
   183 
       
   184 class CFileBrowserFileUtils : public CActive, public MAknServerAppExitObserver, public MMsvSessionObserver, public MProgressDialogCallback 
       
   185 	{
       
   186 private:
       
   187     enum TState // active object states
       
   188     	{
       
   189     	EIdle = 0,              // do nothing
       
   190     	};
       
   191 
       
   192     enum TClipBoardMode
       
   193     	{
       
   194     	EClipBoardModeCut = 0,
       
   195     	EClipBoardModeCopy
       
   196     	};
       
   197 
       
   198     enum TListingMode
       
   199     	{
       
   200     	ENormalEntries = 0,
       
   201     	ESearchResults,
       
   202     	EOpenFiles,
       
   203     	EMsgAttachmentsInbox,
       
   204     	EMsgAttachmentsDrafts,
       
   205     	EMsgAttachmentsSentItems,
       
   206     	EMsgAttachmentsOutbox
       
   207     	};
       
   208     	    	
       
   209 public:
       
   210 	static CFileBrowserFileUtils* NewL(CEngine* aEngine);
       
   211 	~CFileBrowserFileUtils();
       
   212 
       
   213 private:
       
   214 	CFileBrowserFileUtils(CEngine* aEngine);
       
   215 	void ConstructL();
       
   216 
       
   217 private: // from CActive
       
   218 	void RunL();
       
   219     TInt RunError(TInt aError);
       
   220 	void DoCancel();
       
   221 
       
   222 private: // from MAknServerAppExitObserver
       
   223     void HandleServerAppExit(TInt aReason);
       
   224 
       
   225 private: // from MMsvSessionObserver
       
   226     void HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* aArg3);
       
   227 
       
   228 private:  //from MProgressDialogCallback
       
   229     void DialogDismissedL(TInt aButtonId);  
       
   230     
       
   231 public: // command handling
       
   232     void StartExecutingCommandsL(const TDesC& aLabel);
       
   233 private: // command handling
       
   234     void ExecuteCommand();
       
   235     void CheckForMoreCommandsL();
       
   236     void AppendToCommandArrayL(TInt aCommand, CCommandParamsBase* aParameters);
       
   237     TInt CommandArrayCount() const;
       
   238     void ResetCommandArray();       
       
   239 
       
   240 private: // misc functionality
       
   241     void GenerateDirectoryDataL();
       
   242     void GetDriveListL();
       
   243     void GetDirectoryListingL();
       
   244 //    CAknIconArray* GenerateIconArrayL(TBool aGenerateNewBasicIconArray=EFalse);
       
   245 //    void AppendGulIconToIconArrayL(CAknIconArray* aIconArray, const TDesC& aIconFile, TInt aIconId, TInt aMaskId, const TAknsItemID aAknsItemId);
       
   246     TInt AppIconIdForUid(TUid aUid);
       
   247     TUid GetAppUid(TFileEntry aFileEntry);
       
   248 //    CDesCArray* GenerateItemTextArrayL();
       
   249 //    TInt GetSelectedItemsOrCurrentItemL(CFileEntryList* aFileEntryList);
       
   250     TInt SetSelectedItemsOrCurrentItemL(const CArrayFix<TInt>* selectionIndexes,
       
   251                                         CFileEntryList* aFileEntryList);
       
   252 
       
   253 //    TBool IsDestinationEntriesExists(const CFileEntryList* aEntryList, const TDesC& aTargetDir);
       
   254     void DoCopyToFolderL(CFileEntryList* aEntryList, const TDesC& aTargetDir, const TOverwriteOptions &aOverwriteOptions, TBool aDeleteSource);
       
   255     TInt DoSearchFiles(const TDesC& aFileName, const TDesC& aPath);
       
   256     TInt DoSearchFilesRecursiveL(const TDesC& aFileName, const TDesC& aPath);
       
   257     TInt DoFindFiles(const TDesC& aFileName, const TDesC& aPath);
       
   258     TInt DoFindFilesRecursiveL(const TDesC& aFileName, const TDesC& aPath);
       
   259     void ReadAttachmentPathsRecursiveL(CMsvSession* aSession, CMsvEntry* aContext, CDesCArray* aAttPaths);
       
   260     void WriteMessageEntryInfoRecursiveL(CMsvSession* aSession, CMsvEntry* aContext, RFile& aFile, TInt& aLevel);
       
   261     void DoWriteMessageEntryInfoL(CMsvEntry* aContext, RFile& aFile, TInt aLevel);
       
   262     void ConvertCharsToPwd(const TDesC& aWord, TDes8& aConverted) const;
       
   263     HBufC8* MessageDigestInHexLC(CMessageDigest* aMD, RFile& aFile);
       
   264     void OpenCommonFileActionQueryL(TInt aCurrentItemIndex);
       
   265     
       
   266 public: // public interfaces
       
   267     TKeyResponse HandleOfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
       
   268     void HandleSettingsChangeL();
       
   269     void SetSortModeL(TInt aSortMode);
       
   270     void SetOrderModeL(TInt aOrderMode);
       
   271     void RefreshViewL();
       
   272     TBool IsCurrentDriveReadOnly();
       
   273     TBool IsItemDirectory(TInt aCurrentItemIndex);
       
   274     void MoveUpOneLevelL();
       
   275     void MoveDownToDirectoryL(TInt aIndex);
       
   276     TInt ClipboardCutL(const CArrayFix<TInt>* aSelectionIndices);
       
   277     TInt ClipboardCopyL(const CArrayFix<TInt>* aSelectionIndices);
       
   278     void ClipboardPasteL(const TOverwriteOptions &aOverwriteOptions);
       
   279     TInt SetCurrentSelection(const CArrayFix<TInt>* aSelectionIndices);
       
   280     void CopyToFolderL(TFileName aTargetDir, const TOverwriteOptions &aOverwriteOptions, TBool aMove=EFalse);
       
   281     void DeleteL();
       
   282     TBool SelectionHasDirs();
       
   283     void TouchL(TBool aRecurse);
       
   284     void RenameL(const TInt aIndex, const TFileName &newName);
       
   285     void SetAttributesL();
       
   286     void SearchL();
       
   287     void NewFileL(const TFileName &aNewFileName);
       
   288     void NewDirectoryL(const TFileName &aNewDirectoryName);
       
   289     void SendToL();
       
   290     void CompressL();
       
   291     void DecompressL();
       
   292     bool PropertiesL(TInt currentItemIndex, CDesCArray* entryLines, TFileName &titleText);
       
   293     void OpenWithApparcL(TFileName aFileName);
       
   294     void OpenWithDocHandlerL(TFileName aFileName, TBool aEmbed);
       
   295     void OpenWithFileServiceL(TInt aCurrentItemIndex);
       
   296     TBool FileExists(const TDesC& aPath);
       
   297     TInt LaunchProgramL(const TDesC& aPath);
       
   298     void MemoryInfoPopupL();
       
   299     void ShowFileCheckSumsL(TInt aCurrentItemIndex, TInt aType);
       
   300     void SetErrRdL(TBool aEnable);
       
   301 //    void EnableAvkonIconCacheL(TBool aEnable);
       
   302     void SimulateLeaveL(TInt aLeaveCode);
       
   303     void SimulatePanicL(const TDesC& aPanicCategory, TInt aPanicCode);
       
   304     void SimulateExceptionL(TInt aExceptionCode);
       
   305     TUint32 GetDebugMask();
       
   306     void SetDebugMaskL(TUint32 aDbgMask);
       
   307     void WriteAllAppsL();
       
   308     void WriteAllFilesL();
       
   309     void ListOpenFilesL();
       
   310     void ListMessageAttachmentsL(TInt aType);
       
   311     void WriteMsgStoreWalkL();
       
   312     void FileEditorL(TInt aCurrentItemIndex, TInt aType);
       
   313     void SetDrivePasswordL(TInt aIndex, const TFileName &aOldPassword, const TFileName &aNewPassword);
       
   314     void UnlockDriveL(TInt aIndex, const TFileName &aOldPassword);
       
   315     void ClearDrivePasswordL(TInt aIndex, const TFileName &aOldPassword);
       
   316     void EraseDrivePasswordL(TInt aIndex);
       
   317     void FormatDriveL(TInt aIndex, TBool aQuickFormat);
       
   318     void CheckDiskL(TInt aIndex);
       
   319     void ScanDriveL(TInt aIndex);
       
   320     void SetDriveNameL(TInt aIndex, const TFileName &aDriveName);
       
   321     void SetDriveVolumeLabelL(TInt aIndex, const TFileName &aVolumeLabel);
       
   322     void EjectDriveL(TInt aIndex);
       
   323     void DismountFileSystemL(TInt aIndex);
       
   324     void EraseMBRL(TInt aIndex);
       
   325     void PartitionDriveL(TInt aIndex, TBool aEraseMBR, TInt aAmountOfPartitions);
       
   326     TBool DriveSnapShotPossible();
       
   327     void DriveSnapShotL();
       
   328     void EditDataTypesL();
       
   329     void SecureBackupL(TInt aType);
       
   330 
       
   331     TBool IsDestinationEntriesExists(const TDesC& aTargetDir);
       
   332     TBool TargetExists(const TInt aIndex, const TFileName &newName);
       
   333     void GetDriveName(TInt aIndex, TFileName &aDriveName);
       
   334     void GetDriveVolumeLabel(TInt aIndex, TFileName &aVolumeLabel);
       
   335 
       
   336     CFileEntryList* FileEntries() const;
       
   337     CDriveEntryList* DriveEntries() const;   
       
   338     
       
   339 public:    
       
   340     inline TInt SortMode() { return iSortMode; }
       
   341     inline TInt OrderMode() { return iOrderMode; }
       
   342     inline CFileEntryList* ClipBoardList() { return iClipBoardList; }
       
   343     inline CFileEntryList* CurrentSelectionList() { return iCurrentSelectionList; }
       
   344     inline TBool IsDriveListViewActive() { return iCurrentPath==KNullDesC && iListingMode==ENormalEntries; }
       
   345     inline TBool IsNormalModeActive() { return iListingMode==ENormalEntries; }
       
   346     inline TFileName CurrentPath() { return iCurrentPath; }
       
   347 	
       
   348     inline TSearchAttributes GetSearchAttributes(){ return iSearchAttributes; };
       
   349     inline void ChangeAttributes(TSearchAttributes attributes) { iSearchAttributes = attributes; };
       
   350     inline TSearchResults SearchResults(){ return iFileSearchResults; };
       
   351     inline CFileEntryList* FoundFiles() { return iFileEntryList; };
       
   352 	
       
   353 private:
       
   354     TState                          iState;
       
   355     CEngine*                        iEngine;
       
   356     CFileBrowserFileOps*            iFileOps;
       
   357 //    CAknWaitDialog*                 iWaitDialog;
       
   358 //    CAknProgressDialog*             iProgressDialog;
       
   359     CEikProgressInfo*               iProgressInfo;
       
   360     CCommandArray*                  iCommandArray;
       
   361     TInt                            iCurrentEntry;
       
   362     TInt                            iSucceededOperations;
       
   363     TInt                            iFailedOperations;
       
   364     TInt                            iLastError;
       
   365     RTimer                          iTimer;
       
   366     RFs                             iFs;
       
   367     TListingMode                    iListingMode;
       
   368     CFileMan*                       iFileMan;
       
   369     TInt                            iViewMode;
       
   370     TFileName                       iCurrentPath;
       
   371     TInt                            iSortMode;
       
   372     TInt                            iOrderMode;
       
   373     TInt                            iClipboardMode;
       
   374     CDesCArray*                     iClipboardPaths;
       
   375     CDriveEntryList*                iDriveEntryList;
       
   376     CFileEntryList*                 iFileEntryList;
       
   377     CFileEntryList*                 iFindFileEntryList;
       
   378     CAppIconList*                   iAppIconList;
       
   379     TClipBoardMode                  iClipBoardMode;
       
   380     CFileEntryList*                 iClipBoardList;
       
   381     CFileEntryList*                 iCurrentSelectionList;
       
   382     TSearchAttributes               iSearchAttributes;
       
   383     CDocumentHandler*               iDocHandler;
       
   384     CAknOpenFileService*            iOpenFileService;
       
   385     RFile                           iMsgStoreWalkFile;
       
   386     TInt                            iPrevFolderIndex;
       
   387     TFileName                       iPrevFolderName;
       
   388     RTz                             iTz;
       
   389     TSearchResults                  iFileSearchResults;
       
   390     CDesCArray*                     iTextArray;
       
   391     };
       
   392 
       
   393 
       
   394 // utility class for waiting for asychronous requests
       
   395 class CAsyncWaiter : public CActive
       
   396 	{
       
   397 public:
       
   398 	static CAsyncWaiter* NewL( TInt aPriority = EPriorityStandard );
       
   399 	static CAsyncWaiter* NewLC( TInt aPriority = EPriorityStandard );
       
   400 	~CAsyncWaiter();
       
   401 	
       
   402 	void StartAndWait();
       
   403 	TInt Result() const;
       
   404 	
       
   405 private:
       
   406 	CAsyncWaiter( TInt aPriority );
       
   407 	
       
   408 	// from CActive
       
   409 	void RunL();
       
   410 	void DoCancel();
       
   411 	
       
   412 private:
       
   413     CActiveSchedulerWait iWait;
       
   414 	TInt iError;
       
   415 	};
       
   416 	
       
   417 	
       
   418 #endif
       
   419 
       
   420 // End of File
       
   421