filebrowser/engine/FBFileUtils.cpp
changeset 55 2d9cac8919d3
parent 53 819e59dfc032
child 56 392f7045e621
equal deleted inserted replaced
53:819e59dfc032 55:2d9cac8919d3
     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 // INCLUDE FILES
       
    19 #include "FBFileUtils.h"
       
    20 #include "FBFileOps.h"
       
    21 #include "engine.h"
       
    22 #include "FB.hrh"
       
    23 #include <filebrowser.rsg>
       
    24 
       
    25 #include <textresolver.h> 
       
    26 #include <eikprogi.h>
       
    27 #include <e32svr.h>
       
    28 #include <eikfutil.h>
       
    29 #include <apparc.h>
       
    30 #include <apaid.h>
       
    31 #include <apaidpartner.h>
       
    32 #include <eikenv.h>
       
    33 #include <bautils.h>
       
    34 #include <gulicon.h>
       
    35 #include <babackup.h> 
       
    36 //#include <aknmemorycardui.mbg>
       
    37 #include <sendui.h>
       
    38 #include <CMessageData.h>
       
    39 #include <ezgzip.h>
       
    40 #include <e32hal.h>
       
    41 #include <pathinfo.h>
       
    42 #include <apgcli.h>
       
    43 #include <apmstd.h>
       
    44 #include <apgtask.h>
       
    45 #include <apacmdln.h>
       
    46 #include <DocumentHandler.h>
       
    47 #include <msvapi.h>
       
    48 #include <msvids.h>
       
    49 #include <msvstd.h>
       
    50 #include <msvstore.h>
       
    51 #include <mmsvattachmentmanager.h>
       
    52 #include <cmsvattachment.h>
       
    53 #include <hash.h>
       
    54 //#include <sbeclient.h>
       
    55 #include <e32property.h>
       
    56 #if (!defined __SERIES60_30__ && !defined __SERIES60_31__) 
       
    57 #include <driveinfo.h>
       
    58 #endif // !defined __SERIES60_30__ && !defined __SERIES60_31__
       
    59 
       
    60 #ifndef __SERIES60_30__
       
    61 //  #include <akniconconfig.h>
       
    62 #endif
       
    63 
       
    64 //_LIT(KGZipExt, ".gz");
       
    65 _LIT8(KFileNewLine, "\r\n");
       
    66 const TInt KForcedFormatTimeout = 1000000;
       
    67 
       
    68 // copied from coreapplicationuisdomainpskeys.h
       
    69 const TUid KPSUidCoreApplicationUIs = { 0x101F8767 };
       
    70 const TUint32 KCoreAppUIsMmcRemovedWithoutEject = 0x00000109;
       
    71 enum TCoreAppUIsMmcRemovedWithoutEject
       
    72     {
       
    73     ECoreAppUIsEjectCommandUsedUninitialized = 0,
       
    74     ECoreAppUIsEjectCommandNotUsed,
       
    75     ECoreAppUIsEjectCommandUsed,
       
    76     ECoreAppUIsEjectCommandUsedToDrive // Low 16-bits contain this value and high 16-bits TDriveNumber to eject
       
    77     };
       
    78 const TInt KDriveLetterStringLength = 3; // e.g. C:\
       
    79 
       
    80 // ================= MEMBER FUNCTIONS =======================
       
    81 
       
    82 CFileBrowserFileUtils* CFileBrowserFileUtils::NewL(CEngine* aEngine)
       
    83 	{
       
    84 	CFileBrowserFileUtils* self = new(ELeave) CFileBrowserFileUtils(aEngine);
       
    85 	CleanupStack::PushL(self);
       
    86 	self->ConstructL();
       
    87 	CleanupStack::Pop();
       
    88 	return self;
       
    89 	}
       
    90 
       
    91 // --------------------------------------------------------------------------------------------
       
    92 
       
    93 CFileBrowserFileUtils::CFileBrowserFileUtils(CEngine* aEngine) : CActive(EPriorityStandard), iEngine(aEngine)
       
    94 	{
       
    95 	}
       
    96 
       
    97 // --------------------------------------------------------------------------------------------
       
    98 
       
    99 void CFileBrowserFileUtils::ConstructL()
       
   100 	{
       
   101     User::LeaveIfError(iTimer.CreateLocal());
       
   102     User::LeaveIfError(iFs.Connect());
       
   103     User::LeaveIfError(iTz.Connect());
       
   104     
       
   105     iState = EIdle;
       
   106     iListingMode = ENormalEntries;
       
   107 
       
   108     iSortMode = EFileBrowserCmdViewSortByName;
       
   109     iOrderMode = EFileBrowserCmdViewOrderAscending;
       
   110     iCurrentPath = KNullDesC;
       
   111     
       
   112     iFileOps = CFileBrowserFileOps::NewL(iEngine);
       
   113     
       
   114     iDriveEntryList = new(ELeave) CDriveEntryList(8);
       
   115     iFileEntryList = new(ELeave) CFileEntryList(64);
       
   116     iFindFileEntryList = new(ELeave) CFileEntryList(64);
       
   117     iAppIconList = new(ELeave) CAppIconList(16);
       
   118     iClipBoardList = new(ELeave) CFileEntryList(64);
       
   119     iCurrentSelectionList = new(ELeave) CFileEntryList(64);
       
   120 
       
   121     iDocHandler = CDocumentHandler::NewL();
       
   122 //    iDocHandler->SetExitObserver(this);
       
   123     
       
   124     // set defaults to the search settings
       
   125     iSearchAttributes.iSearchDir = KNullDesC;
       
   126     iSearchAttributes.iWildCards = _L("*.jpg");
       
   127     iSearchAttributes.iTextInFile = KNullDesC;
       
   128     iSearchAttributes.iMinSize = 0;
       
   129     iSearchAttributes.iMaxSize = 999999999;
       
   130     iSearchAttributes.iMinDate = TDateTime(1980, EJanuary,   0,0,0,0,0);
       
   131     iSearchAttributes.iMaxDate = TDateTime(2060, EDecember, 30,0,0,0,0);
       
   132     iSearchAttributes.iRecurse = ETrue;
       
   133     
       
   134     // init the command array
       
   135     iCommandArray = new(ELeave) CCommandArray(64);
       
   136         
       
   137     // get current path from settings
       
   138     if (iEngine->Settings().iRememberLastPath)
       
   139         {
       
   140         TFileName settingPath = iEngine->Settings().iLastPath;
       
   141         if (BaflUtils::PathExists(iFs, settingPath))
       
   142             iCurrentPath = settingPath;
       
   143         
       
   144         if (iCurrentPath != KNullDesC)
       
   145             GetDriveListL();
       
   146         }
       
   147 
       
   148     CActiveScheduler::Add(this);
       
   149     }
       
   150 
       
   151 // --------------------------------------------------------------------------------------------
       
   152 
       
   153 CFileBrowserFileUtils::~CFileBrowserFileUtils()
       
   154 	{
       
   155 	Cancel();
       
   156 	
       
   157 	// save current path from settings
       
   158     if (iEngine->Settings().iRememberLastPath)
       
   159         {
       
   160         iEngine->Settings().iLastPath = iCurrentPath;
       
   161         TRAP_IGNORE(iEngine->SaveSettingsL(EFalse));
       
   162         }
       
   163 
       
   164 //    if (iWaitDialog)
       
   165 //        TRAP_IGNORE(iWaitDialog->ProcessFinishedL()); 
       
   166 //     
       
   167 //    if (iProgressDialog)
       
   168 //        TRAP_IGNORE(iProgressDialog->ProcessFinishedL());
       
   169     
       
   170         delete iFileOps;
       
   171 
       
   172         delete iDocHandler;
       
   173 	
       
   174 //	if (iOpenFileService)
       
   175 //	    delete iOpenFileService;
       
   176 	
       
   177         delete iCurrentSelectionList;
       
   178         delete iClipBoardList;
       
   179         delete iAppIconList;
       
   180         delete iFindFileEntryList;
       
   181         delete iFileEntryList;
       
   182         delete iDriveEntryList;
       
   183 
       
   184         delete iFileMan;
       
   185 
       
   186         if (iCommandArray)
       
   187             {
       
   188             ResetCommandArray();
       
   189             delete iCommandArray;
       
   190             }
       
   191 
       
   192         iTz.Close();
       
   193         iFs.Close();
       
   194         iTimer.Close();
       
   195         }
       
   196 
       
   197 // --------------------------------------------------------------------------------------------
       
   198 
       
   199 void CFileBrowserFileUtils::DoCancel()
       
   200 	{
       
   201     iTimer.Cancel();
       
   202 	}
       
   203 
       
   204 // --------------------------------------------------------------------------------------------
       
   205 
       
   206 void CFileBrowserFileUtils::StartExecutingCommandsL(const TDesC& aLabel)
       
   207     {
       
   208     if (iCommandArray->Count() >= 2)
       
   209         {
       
   210         // init progress bar
       
   211 //        iProgressDialog = new(ELeave) CAknProgressDialog((reinterpret_cast<CEikDialog**>(&iProgressDialog)), ETrue);
       
   212 //        iProgressDialog->SetCallback(this);
       
   213 //        iProgressDialog->PrepareLC(R_GENERAL_PROGRESS_NOTE);
       
   214 //        iProgressDialog->SetCurrentLabelL( EAknCtNote, aLabel );
       
   215 //        iProgressInfo = iProgressDialog->GetProgressInfoL();
       
   216 //        iProgressInfo->SetFinalValue( CommandArrayCount() );
       
   217 //        iProgressDialog->RunLD();
       
   218 //        iProgressDialog->MakeVisible( ETrue );        
       
   219         iEngine->FileBrowserUI()->ShowProgressDialog(aLabel, 0, CommandArrayCount());
       
   220         isProgressDialog = ETrue;
       
   221         }
       
   222     else if (iCommandArray->Count() >= 1)
       
   223         {
       
   224         // init wait dialog
       
   225 //        iWaitDialog = new(ELeave) CAknWaitDialog((reinterpret_cast<CEikDialog**>(&iWaitDialog)), ETrue);
       
   226 //        iWaitDialog->SetCallback(this);
       
   227 //        iWaitDialog->PrepareLC(R_GENERAL_WAIT_NOTE);
       
   228 //        iWaitDialog->SetTextL( aLabel );
       
   229 //        iWaitDialog->RunLD();
       
   230         iEngine->FileBrowserUI()->ShowWaitDialog(aLabel);
       
   231         isWaitDialog = ETrue;
       
   232         }
       
   233     else
       
   234         {
       
   235         // no commands, just do nothing
       
   236         return;
       
   237         }
       
   238 
       
   239 
       
   240     // start with the first operation
       
   241     iCurrentEntry = 0;
       
   242     iSucceededOperations = 0;
       
   243     iFailedOperations = 0;
       
   244 
       
   245     // starts executing commands
       
   246     ExecuteCommand();
       
   247     }
       
   248     
       
   249 // --------------------------------------------------------------------------------------------
       
   250 
       
   251 void CFileBrowserFileUtils::ExecuteCommand()
       
   252     {
       
   253     // make sure the engine isn't active, should never happen
       
   254     __ASSERT_ALWAYS(!IsActive(), User::Panic(_L("FileUtils:IsActive"), 333));
       
   255 
       
   256     // execute a command after a very short delay (25ms)
       
   257     if (isWaitDialog)
       
   258         {
       
   259         iEngine->FileBrowserUI()->ProcessEvents();
       
   260         }
       
   261     if (isProgressDialog)
       
   262         {
       
   263         TInt newValue = iCurrentEntry;
       
   264         iEngine->FileBrowserUI()->SetProgressValue(newValue);
       
   265         }
       
   266     iTimer.After(iStatus, 25);
       
   267     SetActive();
       
   268     }
       
   269 
       
   270 // --------------------------------------------------------------------------------------------
       
   271     
       
   272 void CFileBrowserFileUtils::RunL()
       
   273     {
       
   274     TInt err(KErrNone);
       
   275     TInt currentCommand = iCommandArray->At(iCurrentEntry).iCommandId;
       
   276 
       
   277     // execute a command from the queue
       
   278     switch(currentCommand)
       
   279         {
       
   280         case EFileBrowserFileOpCommandAttribs:
       
   281             {
       
   282             CCommandParamsAttribs* params = static_cast<CCommandParamsAttribs*>(iCommandArray->At(iCurrentEntry).iParameters);
       
   283             err = iFileOps->Attribs(params->iSourceEntry, params->iSetMask, params->iClearMask, params->iTime, params->iSwitch);
       
   284             }
       
   285             break;
       
   286             
       
   287         case EFileBrowserFileOpCommandCopy:
       
   288             {
       
   289             CCommandParamsCopyOrMove* params = static_cast<CCommandParamsCopyOrMove*>(iCommandArray->At(iCurrentEntry).iParameters);
       
   290             err = iFileOps->Copy(params->iSourceEntry, params->iTargetPath, params->iSwitch);
       
   291             }
       
   292             break;
       
   293             
       
   294         case EFileBrowserFileOpCommandMove:
       
   295             {
       
   296             CCommandParamsCopyOrMove* params = static_cast<CCommandParamsCopyOrMove*>(iCommandArray->At(iCurrentEntry).iParameters);
       
   297             err = iFileOps->Copy(params->iSourceEntry, params->iTargetPath, params->iSwitch, ETrue);
       
   298             }
       
   299             break;
       
   300                 
       
   301         case EFileBrowserFileOpCommandRename:
       
   302             {
       
   303             CCommandParamsRename* params = static_cast<CCommandParamsRename*>(iCommandArray->At(iCurrentEntry).iParameters);
       
   304             err = iFileOps->Rename(params->iSourceEntry, params->iTargetPath, params->iSwitch);
       
   305             }
       
   306             break;
       
   307 
       
   308         case EFileBrowserFileOpCommandDelete:
       
   309             {
       
   310             CCommandParamsDelete* params = static_cast<CCommandParamsDelete*>(iCommandArray->At(iCurrentEntry).iParameters);
       
   311             err = iFileOps->Delete(params->iSourceEntry, params->iSwitch);
       
   312             }
       
   313             break;
       
   314 
       
   315         case EFileBrowserFileOpCommandDriveSnapShot:
       
   316             {
       
   317             CCommandParamsDriveSnapShot* params = static_cast<CCommandParamsDriveSnapShot*>(iCommandArray->At(iCurrentEntry).iParameters);
       
   318             err = iFileOps->DriveSnapShot(params->iSourceDriveLetter, params->iTargetDriveLetter);
       
   319             }
       
   320             break;
       
   321                                                 
       
   322         default:
       
   323             User::Panic (_L("Unknown command"), 400);
       
   324             break;
       
   325         }
       
   326 
       
   327     
       
   328     if (err == KErrNone)
       
   329         {
       
   330         iSucceededOperations++;
       
   331         }
       
   332     else if ( err != KErrCancel )
       
   333         {
       
   334         iFailedOperations++;
       
   335         }
       
   336         
       
   337     iLastError = err;            
       
   338 
       
   339     // check for more commands in queue
       
   340     TRAP_IGNORE( CheckForMoreCommandsL() );
       
   341     }
       
   342 
       
   343 // ---------------------------------------------------------------------------
       
   344 
       
   345 TInt CFileBrowserFileUtils::RunError(TInt aError)
       
   346     {
       
   347     _LIT(KMessage, "Command error %d");
       
   348     TBuf<128> noteMsg;
       
   349     noteMsg.Format(KMessage, aError);
       
   350             
       
   351     iEngine->EikonEnv()->InfoMsg(noteMsg);
       
   352     
       
   353     TRAP_IGNORE( CheckForMoreCommandsL() );
       
   354     
       
   355     return KErrNone;
       
   356     }
       
   357 
       
   358 // ---------------------------------------------------------------------------
       
   359 
       
   360 void CFileBrowserFileUtils::CheckForMoreCommandsL()
       
   361     {
       
   362     //LOGSTRING("Creator: CCreatorEngine::CheckForMoreCommandsL");
       
   363     
       
   364     // update the progress bar
       
   365 //    if (iProgressInfo)
       
   366 //        iProgressInfo->IncrementAndDraw(1);
       
   367 
       
   368 	// check if we have more commands to be executed
       
   369 	if (iCurrentEntry >= CommandArrayCount() - 1)
       
   370 		{
       
   371         //LOGSTRING("Creator: CCreatorEngine::CheckForMoreCommandsL all done");
       
   372 
       
   373         // all done, free resources
       
   374         ResetCommandArray();
       
   375         
       
   376         // deactive secure backup if it was activated by a file command
       
   377         iFileOps->DeActivateSecureBackUpViaFileOp();
       
   378 
       
   379         // dismiss any wait/progress dialogs        
       
   380         if (isWaitDialog)
       
   381             {
       
   382             iEngine->FileBrowserUI()->CancelWaitDialog();
       
   383             isWaitDialog = EFalse;
       
   384             }
       
   385         if (isProgressDialog)
       
   386             {
       
   387             iEngine->FileBrowserUI()->CancelProgressDialog();
       
   388             isProgressDialog = EFalse;
       
   389             }
       
   390 //        if (iWaitDialog)
       
   391 //            {
       
   392 //            TRAP_IGNORE(iWaitDialog->ProcessFinishedL()); 
       
   393 //            iWaitDialog = NULL;
       
   394 //            }
       
   395 //        if (iProgressDialog)
       
   396 //            {
       
   397 //            TRAP_IGNORE(iProgressDialog->ProcessFinishedL());
       
   398 //            iProgressDialog = NULL;
       
   399 //            }
       
   400 
       
   401 
       
   402         // show result note
       
   403         if ( iSucceededOperations == 0 && iFailedOperations == 0 )
       
   404             {
       
   405             // single operation cancelled -> show nothing
       
   406             }
       
   407         else if (iSucceededOperations == 1 && iFailedOperations == 0)    
       
   408             {
       
   409             _LIT(KMessage, "Operation succeeded");
       
   410             iEngine->FileBrowserUI()->ShowConfirmationNote(KMessage);
       
   411             }
       
   412         else if (iSucceededOperations > 0 && iFailedOperations == 0)    
       
   413             {
       
   414             _LIT(KMessage, "%d operations succeeded");
       
   415             TBuf<128> noteMsg;
       
   416             noteMsg.Format(KMessage, iSucceededOperations);
       
   417             iEngine->FileBrowserUI()->ShowConfirmationNote(noteMsg);
       
   418             }
       
   419         else if (iSucceededOperations == 0 && iFailedOperations > 1)    
       
   420             {
       
   421             _LIT(KMessage, "%d operations failed");
       
   422             TBuf<128> noteMsg;
       
   423             noteMsg.Format(KMessage, iFailedOperations);
       
   424 
       
   425             iEngine->FileBrowserUI()->ShowErrorNote(noteMsg);
       
   426             }
       
   427         else if (iSucceededOperations > 0 && iFailedOperations > 0)    
       
   428             {
       
   429             _LIT(KMessage, "%d operations succeeded, %d failed");
       
   430             TBuf<128> noteMsg;
       
   431             noteMsg.Format(KMessage, iSucceededOperations, iFailedOperations);
       
   432 
       
   433             iEngine->FileBrowserUI()->ShowInformationNote(noteMsg, _L(""));
       
   434             }
       
   435         else    
       
   436             {
       
   437             CTextResolver* textResolver = CTextResolver::NewLC(*iEngine->EikonEnv());
       
   438 
       
   439             iEngine->FileBrowserUI()->ShowErrorNote(
       
   440                     textResolver->ResolveErrorString(iLastError, CTextResolver::ECtxNoCtxNoSeparator) );
       
   441 
       
   442             CleanupStack::PopAndDestroy();  //textResolver
       
   443             }
       
   444 
       
   445         RefreshViewL();
       
   446         iEngine->FileBrowserUI()->NotifyModelHasChanged();
       
   447 
       
   448             }
       
   449 	else
       
   450             {
       
   451             // maintain requests
       
   452             iCurrentEntry++;
       
   453 
       
   454             //LOGSTRING2("Creator: CCreatorEngine::CheckForMoreCommandsL iCurrentEntry=%d", iCurrentEntry);
       
   455 
       
   456             ExecuteCommand();
       
   457             }
       
   458     }    
       
   459 // --------------------------------------------------------------------------------------------
       
   460 
       
   461 // This callback function is called when cancel button of the progress bar was pressed
       
   462 void CFileBrowserFileUtils::DialogDismissedL(/*TInt aButtonId*/)
       
   463     {
       
   464 //    iProgressDialog = NULL;
       
   465 //    iProgressInfo = NULL;
       
   466 //    iWaitDialog = NULL;
       
   467     
       
   468     // check if cancel button was pressed
       
   469 //    if (aButtonId == EAknSoftkeyCancel)
       
   470 //        {
       
   471         // cancel the active object, command executer 
       
   472         Cancel();
       
   473         
       
   474         iFileOps->CancelOp();
       
   475         
       
   476         ResetCommandArray();
       
   477 
       
   478         isProgressDialog = EFalse;
       
   479 
       
   480         iEngine->FileBrowserUI()->ShowInformationNote(_L("Cancelled"), _L(""));
       
   481 //        }
       
   482     }
       
   483     
       
   484 // --------------------------------------------------------------------------------------------
       
   485 
       
   486 void CFileBrowserFileUtils::AppendToCommandArrayL(TInt aCommand, CCommandParamsBase* aParameters)
       
   487     {
       
   488     if (iCommandArray)
       
   489         iCommandArray->AppendL( TCommand(aCommand, aParameters) );
       
   490     else
       
   491         User::Leave(KErrNotReady);
       
   492     }
       
   493 
       
   494 // --------------------------------------------------------------------------------------------
       
   495 
       
   496 TInt CFileBrowserFileUtils::CommandArrayCount() const
       
   497     {
       
   498     TInt count(0);
       
   499     
       
   500     if (iCommandArray)
       
   501         count = iCommandArray->Count();
       
   502     
       
   503     return count;
       
   504     }
       
   505 
       
   506 // --------------------------------------------------------------------------------------------
       
   507 
       
   508 void CFileBrowserFileUtils::ResetCommandArray()
       
   509     {
       
   510     // delete params first
       
   511     for (TInt i=0; i<CommandArrayCount(); i++)
       
   512         {
       
   513         if ( iCommandArray->At(i).iParameters )
       
   514             {
       
   515             delete iCommandArray->At(i).iParameters;
       
   516             iCommandArray->At(i).iParameters = NULL;
       
   517             }
       
   518         }
       
   519 
       
   520     // reset the entries
       
   521     iCommandArray->Reset();
       
   522     }
       
   523                     
       
   524 // --------------------------------------------------------------------------------------------
       
   525 
       
   526 void CFileBrowserFileUtils::HandleSettingsChangeL()
       
   527     {
       
   528 	// TODO
       
   529 
       
   530 //    if (iEngine->FileListContainer())
       
   531 //        {
       
   532 //        iEngine->FileListContainer()->SetScreenLayoutL(iEngine->Settings().iDisplayMode);
       
   533 //        iEngine->FileListContainer()->CreateListBoxL(iEngine->Settings().iFileViewMode);
       
   534         //iEngine->FileListContainer()->SetNaviPaneTextL(iCurrentPath);
       
   535         RefreshViewL();
       
   536 //        }
       
   537     }
       
   538 
       
   539 // --------------------------------------------------------------------------------------------
       
   540 
       
   541 void CFileBrowserFileUtils::SetSortModeL(TInt aSortMode)
       
   542     {
       
   543     iSortMode = aSortMode;
       
   544     RefreshViewL();
       
   545     }
       
   546     
       
   547 // --------------------------------------------------------------------------------------------
       
   548 
       
   549 void CFileBrowserFileUtils::SetOrderModeL(TInt aOrderMode)
       
   550     {
       
   551     iOrderMode = aOrderMode;
       
   552     RefreshViewL();
       
   553     }
       
   554 
       
   555 // --------------------------------------------------------------------------------------------
       
   556 
       
   557 TKeyResponse CFileBrowserFileUtils::HandleOfferKeyEventL(const TKeyEvent& /*aKeyEvent*/, TEventCode /*aType*/)
       
   558     {
       
   559 	// TODO
       
   560 	/*
       
   561     if(aType != EEventKey)
       
   562         return EKeyWasNotConsumed;
       
   563     
       
   564     TBool shiftKeyPressed = (aKeyEvent.iModifiers & EModifierShift) ||
       
   565                             (aKeyEvent.iModifiers & EModifierLeftShift) ||
       
   566                             (aKeyEvent.iModifiers & EModifierRightShift);
       
   567     TBool controlKeyPressed = (aKeyEvent.iModifiers & EModifierCtrl) || 
       
   568                               (aKeyEvent.iModifiers & EModifierRightCtrl); 
       
   569     
       
   570     // handle left arrow key press
       
   571     if (aKeyEvent.iCode == EKeyLeftArrow)
       
   572         {
       
   573         MoveUpOneLevelL();
       
   574         return EKeyWasConsumed;
       
   575         }
       
   576     
       
   577     // handle right arrow key press
       
   578     else if (aKeyEvent.iCode == EKeyRightArrow)
       
   579         {
       
   580         if (IsDriveListViewActive() && iDriveEntryList->Count() > 0)
       
   581             {
       
   582             MoveDownToDirectoryL();
       
   583             return EKeyWasConsumed;
       
   584             }
       
   585         else if (iFileEntryList->Count() > 0)
       
   586             {
       
   587             MoveDownToDirectoryL();
       
   588             return EKeyWasConsumed;
       
   589             }        
       
   590         }    
       
   591 
       
   592     // skip OK/Enter keys when shift or ctrl is pressed because those are needed by the listbox
       
   593     else if ((aKeyEvent.iCode == EKeyOK || aKeyEvent.iCode == EKeyEnter) && (shiftKeyPressed || controlKeyPressed))
       
   594         {
       
   595         return EKeyWasNotConsumed;
       
   596         }
       
   597     
       
   598     // handle OK/Enter keys
       
   599     else if (aKeyEvent.iCode == EKeyOK || aKeyEvent.iCode == EKeyEnter)
       
   600         {
       
   601         if (IsDriveListViewActive() && iDriveEntryList->Count() > 0)
       
   602             {
       
   603             MoveDownToDirectoryL();
       
   604             return EKeyWasConsumed;
       
   605             }
       
   606         else if (iFileEntryList->Count() > 0)
       
   607             {
       
   608             TFileEntry fileEntry = iFileEntryList->At(iEngine->FileListContainer()->CurrentListBoxItemIndex());
       
   609             
       
   610             if (fileEntry.iEntry.IsDir())
       
   611                 MoveDownToDirectoryL();
       
   612             else
       
   613                 OpenCommonFileActionQueryL();
       
   614             
       
   615             return EKeyWasConsumed;
       
   616             } 
       
   617         }
       
   618     
       
   619     // handle Delete/Backspace keys
       
   620     else if (!iEngine->FileListContainer()->SearchField() && (aKeyEvent.iCode == EKeyBackspace || aKeyEvent.iCode == EKeyDelete) &&
       
   621              !iEngine->FileUtils()->IsCurrentDriveReadOnly() && !iEngine->FileUtils()->IsDriveListViewActive())
       
   622         {
       
   623         DeleteL();
       
   624         return EKeyWasConsumed;
       
   625         }
       
   626     */                      
       
   627     return EKeyWasNotConsumed;
       
   628     }        
       
   629 // --------------------------------------------------------------------------------------------
       
   630 
       
   631 void CFileBrowserFileUtils::RefreshViewL()
       
   632     {
       
   633 //    if (iEngine->FileListContainer())
       
   634 //        {
       
   635 //
       
   636 //        // make sure that the search field is disabled
       
   637 //        iEngine->FileListContainer()->DisableSearchFieldL();
       
   638         
       
   639         // read directory listing
       
   640         GenerateDirectoryDataL();
       
   641         
       
   642 //        // set an icon array
       
   643 //        iEngine->FileListContainer()->SetListBoxIconArrayL(GenerateIconArrayL());
       
   644 //
       
   645 //        // set text items
       
   646 //        iEngine->FileListContainer()->SetListBoxTextArrayL(GenerateItemTextArrayL());
       
   647 //        }
       
   648     }
       
   649     
       
   650 // --------------------------------------------------------------------------------------------
       
   651 
       
   652 //CAknIconArray* CFileBrowserFileUtils::GenerateIconArrayL(TBool aGenerateNewBasicIconArray)
       
   653 //    {
       
   654 //	// TODO
       
   655 //
       
   656 //    CAknIconArray* iconArray = NULL;
       
   657 //
       
   658 //    if (aGenerateNewBasicIconArray)
       
   659 //        {
       
   660 //        iconArray = new(ELeave) CAknIconArray(16);
       
   661 //        }
       
   662 //    else
       
   663 //        {
       
   664 //        if (iEngine->FileListContainer())
       
   665 //            iconArray = iEngine->FileListContainer()->ListBoxIconArrayL();
       
   666 //
       
   667 //        if (!iconArray)
       
   668 //            iconArray = new(ELeave) CAknIconArray(16);
       
   669 //        }
       
   670 //
       
   671 //
       
   672 //    CleanupStack::PushL(iconArray);
       
   673 //
       
   674 //    // generate basic items if not already existing
       
   675 //    if (iconArray->Count() < EFixedIconListLength)
       
   676 //        {
       
   677 //        // reset arrays
       
   678 //        iconArray->Reset();
       
   679 //        iAppIconList->Reset();
       
   680 //
       
   681 //        // get default control color
       
   682 //        TRgb defaultColor;
       
   683 //        defaultColor = iEngine->EikonEnv()->Color(EColorControlText);
       
   684 //
       
   685 //        // create a color icon of the marking indicator
       
   686 //        CFbsBitmap* markBitmap = NULL;
       
   687 //        CFbsBitmap* markBitmapMask = NULL;
       
   688 //
       
   689 //        AknsUtils::CreateColorIconL(AknsUtils::SkinInstance(),
       
   690 //                KAknsIIDQgnIndiMarkedAdd,
       
   691 //                KAknsIIDQsnIconColors,
       
   692 //                EAknsCIQsnIconColorsCG13,
       
   693 //                markBitmap,
       
   694 //                markBitmapMask,
       
   695 //                AknIconUtils::AvkonIconFileName(),
       
   696 //                EMbmAvkonQgn_indi_marked_add,
       
   697 //                EMbmAvkonQgn_indi_marked_add_mask,
       
   698 //                defaultColor
       
   699 //                );
       
   700 //
       
   701 //        // 0 marking indicator
       
   702 //        CGulIcon* markIcon = CGulIcon::NewL(markBitmap, markBitmapMask);
       
   703 //        iconArray->AppendL(markIcon);
       
   704 //
       
   705 //        // 1 empty
       
   706 //        AppendGulIconToIconArrayL(iconArray, AknIconUtils::AvkonIconFileName(),
       
   707 //                                  EMbmAvkonQgn_prop_empty, EMbmAvkonQgn_prop_empty_mask, KAknsIIDQgnPropEmpty);
       
   708 //        // 2 phone memory
       
   709 //        AppendGulIconToIconArrayL(iconArray, AknIconUtils::AvkonIconFileName(),
       
   710 //                                  EMbmAvkonQgn_prop_phone_memc, EMbmAvkonQgn_prop_phone_memc_mask, KAknsIIDQgnPropPhoneMemc);
       
   711 //        // 3 memory card
       
   712 //        AppendGulIconToIconArrayL(iconArray, KMemoryCardUiBitmapFile,
       
   713 //                                  EMbmAknmemorycarduiQgn_prop_mmc_memc, EMbmAknmemorycarduiQgn_prop_mmc_memc_mask, KAknsIIDQgnPropMmcMemc);
       
   714 //        // 4 memory card disabled
       
   715 //        AppendGulIconToIconArrayL(iconArray, KMemoryCardUiBitmapFile,
       
   716 //                                  EMbmAknmemorycarduiQgn_prop_mmc_non, EMbmAknmemorycarduiQgn_prop_mmc_non_mask, KAknsIIDQgnPropMmcNon);
       
   717 //        // 5 folder
       
   718 //        AppendGulIconToIconArrayL(iconArray, AknIconUtils::AvkonIconFileName(),
       
   719 //                                  EMbmAvkonQgn_prop_folder_small, EMbmAvkonQgn_prop_folder_small_mask, KAknsIIDQgnPropFolderSmall);
       
   720 //        // 6 folder with subfolders
       
   721 //        AppendGulIconToIconArrayL(iconArray, AknIconUtils::AvkonIconFileName(),
       
   722 //                                  EMbmAvkonQgn_prop_folder_sub_small, EMbmAvkonQgn_prop_folder_sub_small_mask, KAknsIIDQgnPropFolderSubSmall);
       
   723 //        // 7 current folder
       
   724 //        AppendGulIconToIconArrayL(iconArray, AknIconUtils::AvkonIconFileName(),
       
   725 //                                  EMbmAvkonQgn_prop_folder_current, EMbmAvkonQgn_prop_folder_current_mask, KAknsIIDQgnPropFolderCurrent);
       
   726 //        }
       
   727 //
       
   728 //    // append custom icons if not in drive list view and setting is enabled
       
   729 //    if (!aGenerateNewBasicIconArray && !IsDriveListViewActive() && iEngine->Settings().iShowAssociatedIcons)
       
   730 //        {
       
   731 //        // init id counter
       
   732 //        TInt idCounter(EFixedIconListLength + iAppIconList->Count());
       
   733 //
       
   734 //        // loop all items in the file list
       
   735 //        for (TInt i=0; i<iFileEntryList->Count(); i++)
       
   736 //            {
       
   737 //            TFileEntry& fileEntry = iFileEntryList->At(i);
       
   738 //
       
   739 //            // just check for normal files
       
   740 //            if (!fileEntry.iEntry.IsDir())
       
   741 //                {
       
   742 //                TUid appUid = GetAppUid(fileEntry);
       
   743 //                TInt iconId = AppIconIdForUid(appUid);
       
   744 //
       
   745 //                if (appUid != KNullUid && iconId == KErrNotFound)
       
   746 //                    {
       
   747 //                    // icon not found from the icon array, generate it
       
   748 //                    CFbsBitmap* bitmap = NULL;
       
   749 //                    CFbsBitmap* mask = NULL;
       
   750 //                    CGulIcon* appIcon = NULL;
       
   751 //
       
   752 //                    TRAPD(err,
       
   753 //                        AknsUtils::CreateAppIconLC(AknsUtils::SkinInstance(), appUid, EAknsAppIconTypeList, bitmap, mask);
       
   754 //                        appIcon = CGulIcon::NewL(bitmap, mask);
       
   755 //                        CleanupStack::Pop(2); //bitmap, mask
       
   756 //                        );
       
   757 //
       
   758 //                    if (err == KErrNone)
       
   759 //                        {
       
   760 //                        TAppIcon appIconEntry;
       
   761 //                        appIconEntry.iId = idCounter;
       
   762 //                        appIconEntry.iUid = appUid;
       
   763 //
       
   764 //                        appIcon->SetBitmapsOwnedExternally(EFalse);
       
   765 //                        iconArray->AppendL(appIcon);
       
   766 //                        iAppIconList->AppendL(appIconEntry);
       
   767 //
       
   768 //                        fileEntry.iIconId = idCounter;
       
   769 //
       
   770 //                        idCounter++;
       
   771 //                        }
       
   772 //                    else
       
   773 //                        {
       
   774 //                        delete bitmap;
       
   775 //                        delete mask;
       
   776 //
       
   777 //                        TAppIcon appIconEntry;
       
   778 //                        appIconEntry.iId = EFixedIconEmpty;
       
   779 //                        appIconEntry.iUid = appUid;
       
   780 //
       
   781 //                        iAppIconList->AppendL(appIconEntry);
       
   782 //                        }
       
   783 //                    }
       
   784 //
       
   785 //                else if (appUid != KNullUid && iconId >= 0)
       
   786 //                    {
       
   787 //                    // we already have already generated an icon for this uid, use it
       
   788 //                    fileEntry.iIconId = iconId;
       
   789 //                    }
       
   790 //                }
       
   791 //            }
       
   792 //        }
       
   793 //
       
   794 //    CleanupStack::Pop(); //iconArray
       
   795 //	return iconArray;
       
   796 //
       
   797 //	}
       
   798 //
       
   799 // --------------------------------------------------------------------------------------------
       
   800 
       
   801 //void CFileBrowserFileUtils::AppendGulIconToIconArrayL(CAknIconArray* aIconArray, const TDesC& aIconFile, TInt aIconId, TInt aMaskId, const TAknsItemID aAknsItemId)
       
   802 //    {
       
   803 //    CGulIcon* icon = AknsUtils::CreateGulIconL(
       
   804 //            AknsUtils::SkinInstance(),
       
   805 //            aAknsItemId,
       
   806 //            aIconFile,
       
   807 //            aIconId,
       
   808 //            aMaskId);
       
   809 //    CleanupStack::PushL(icon);
       
   810 //	
       
   811 //	icon->SetBitmapsOwnedExternally(EFalse);
       
   812 //	aIconArray->AppendL(icon);
       
   813 //	
       
   814 //	CleanupStack::Pop(); //icon          
       
   815 //    }
       
   816 
       
   817 // --------------------------------------------------------------------------------------------
       
   818 
       
   819 TInt CFileBrowserFileUtils::AppIconIdForUid(TUid aUid)
       
   820     {
       
   821     TInt result(KErrNotFound);
       
   822     
       
   823     for (TInt i=0; i<iAppIconList->Count(); i++)
       
   824         {
       
   825         if (iAppIconList->At(i).iUid == aUid)
       
   826             {
       
   827             result = iAppIconList->At(i).iId;
       
   828             break;
       
   829             }
       
   830         }
       
   831     
       
   832     return result;
       
   833     }
       
   834 
       
   835 // --------------------------------------------------------------------------------------------
       
   836 
       
   837 TUid CFileBrowserFileUtils::GetAppUid(TFileEntry aFileEntry)
       
   838     {
       
   839     TFileName fullPath;
       
   840     fullPath.Copy(aFileEntry.iPath);
       
   841     fullPath.Append(aFileEntry.iEntry.iName);
       
   842     
       
   843     TParse parsedName;
       
   844     parsedName.Set(fullPath, NULL, NULL);
       
   845 
       
   846     // this will boost performance in \sys\bin folder    
       
   847     if (parsedName.Ext().CompareF(_L(".dll")) == 0 || parsedName.Ext().CompareF(_L(".rsc")) == 0)
       
   848         return KNullUid;
       
   849     
       
   850     TInt err1(KErrNone), err2(KErrNone);
       
   851     TUid appUid;
       
   852     TDataType dataType;
       
   853     TBool isProgram;
       
   854     
       
   855     err1 = iEngine->LsSession().AppForDocument(fullPath, appUid, dataType);
       
   856     err2 = iEngine->LsSession().IsProgram(fullPath, isProgram);
       
   857         
       
   858     if (err1 == KErrNone && err2 == KErrNone)
       
   859         {
       
   860         if (isProgram)
       
   861             {
       
   862             // get the real app Uid from the app list
       
   863             TApaAppInfo appInfo;
       
   864             iEngine->LsSession().GetAllApps();
       
   865 
       
   866             while (iEngine->LsSession().GetNextApp(appInfo) == KErrNone)
       
   867                 {
       
   868                 if (fullPath.CompareF(appInfo.iFullName) == 0)
       
   869                     return appInfo.iUid;
       
   870                 }
       
   871             }
       
   872         else
       
   873             {
       
   874             // return the app Uid associated for it
       
   875             return appUid;
       
   876             }            
       
   877         }
       
   878 
       
   879     return KNullUid;
       
   880     }
       
   881 
       
   882 
       
   883 CFileEntryList* CFileBrowserFileUtils::FileEntries() const
       
   884 {
       
   885     return iFileEntryList;
       
   886 }
       
   887 CDriveEntryList* CFileBrowserFileUtils::DriveEntries() const
       
   888 {
       
   889     return iDriveEntryList;
       
   890 }
       
   891 
       
   892 //// --------------------------------------------------------------------------------------------
       
   893 //
       
   894 //CDesCArray* CFileBrowserFileUtils::GenerateItemTextArrayL()
       
   895 //    {
       
   896 //    iTextArray = new(ELeave) CDesCArrayFlat(64);
       
   897 ////    CleanupStack::PushL(textArray);
       
   898 //
       
   899 //    if (IsDriveListViewActive())
       
   900 //        {
       
   901 //        _LIT(KSimpleDriveEntry, "%d\t%c: <%S>\t\t");
       
   902 //        _LIT(KExtendedDriveEntry, "%d\t%c: <%S>\t%LD / %LD kB\t");
       
   903 //
       
   904 //        for (TInt i=0; i<iDriveEntryList->Count(); i++)
       
   905 //            {
       
   906 //            TFileName textEntry;
       
   907 //            TDriveEntry driveEntry = iDriveEntryList->At(i);
       
   908 //
       
   909 //            if (iEngine->Settings().iFileViewMode == EFileViewModeSimple)
       
   910 //                {
       
   911 //                textEntry.Format(KSimpleDriveEntry, driveEntry.iIconId, TUint(driveEntry.iLetter), &driveEntry.iMediaTypeDesc);
       
   912 //                }
       
   913 //            else if (iEngine->Settings().iFileViewMode == EFileViewModeExtended)
       
   914 //                {
       
   915 //                textEntry.Format(KExtendedDriveEntry, driveEntry.iIconId, TUint(driveEntry.iLetter), &driveEntry.iMediaTypeDesc, driveEntry.iVolumeInfo.iFree/1024, driveEntry.iVolumeInfo.iSize/1024);
       
   916 //                }
       
   917 //
       
   918 //            iTextArray->AppendL(textEntry);
       
   919 //            }
       
   920 //        }
       
   921 //
       
   922 //    else
       
   923 //        {
       
   924 //        _LIT(KSimpleFileEntry, "%d\t%S\t\t");
       
   925 //        _LIT(KExtendedFileEntry, "%d\t%S\t%S\t");
       
   926 //
       
   927 //        for (TInt i=0; i<iFileEntryList->Count(); i++)
       
   928 //            {
       
   929 //            TFileName textEntry;
       
   930 //            TFileEntry fileEntry = iFileEntryList->At(i);
       
   931 //
       
   932 //            // format text line entries
       
   933 //            if (iEngine->Settings().iFileViewMode == EFileViewModeSimple)
       
   934 //                {
       
   935 //                textEntry.Format(KSimpleFileEntry, fileEntry.iIconId, &fileEntry.iEntry.iName);
       
   936 //                }
       
   937 //            else if (iEngine->Settings().iFileViewMode == EFileViewModeExtended)
       
   938 //                {
       
   939 //                TBuf<128> extraData;
       
   940 //
       
   941 //                // append entry date
       
   942 //                TTime entryModified = fileEntry.iEntry.iModified;
       
   943 //                if ( iTz.ConvertToLocalTime( entryModified ) == KErrNone )
       
   944 //                    {
       
   945 //                    entryModified = fileEntry.iEntry.iModified;
       
   946 //                    }
       
   947 //
       
   948 //                _LIT(KCurrentDate,"%D%M%*Y%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B");
       
   949 //                entryModified.FormatL(extraData, KCurrentDate);
       
   950 //
       
   951 //                // for a directory append number of entries and for a file the file size
       
   952 //                if (fileEntry.iEntry.IsDir() && fileEntry.iDirEntries >= 0)
       
   953 //                    {
       
   954 //                    extraData.Append(_L(" - "));
       
   955 //                    extraData.AppendNum(fileEntry.iDirEntries);
       
   956 //
       
   957 //                    if (fileEntry.iDirEntries == 1)
       
   958 //                        extraData.Append(_L(" entry"));
       
   959 //                    else
       
   960 //                        extraData.Append(_L(" entries"));
       
   961 //                    }
       
   962 //
       
   963 //                // normal file entry
       
   964 //                else if (!fileEntry.iEntry.IsDir())
       
   965 //                    {
       
   966 //                    extraData.Append(_L(" - "));
       
   967 //
       
   968 //                    if (fileEntry.iEntry.iSize < 1024)
       
   969 //                        {
       
   970 //                        extraData.AppendNum(fileEntry.iEntry.iSize);
       
   971 //                        extraData.Append(_L(" B"));
       
   972 //                        }
       
   973 //                    else if (fileEntry.iEntry.iSize < 1024*1024)
       
   974 //                        {
       
   975 //                        TReal sizeKB = (TReal)fileEntry.iEntry.iSize / 1024;
       
   976 //                        extraData.AppendNum(sizeKB, TRealFormat(KDefaultRealWidth, 1));
       
   977 //                        extraData.Append(_L(" kB"));
       
   978 //                        }
       
   979 //                    else
       
   980 //                        {
       
   981 //                        TReal sizeMB = (TReal)fileEntry.iEntry.iSize / (1024*1024);
       
   982 //                        extraData.AppendNum(sizeMB, TRealFormat(KDefaultRealWidth, 1));
       
   983 //                        extraData.Append(_L(" MB"));
       
   984 //                        }
       
   985 //                    }
       
   986 //
       
   987 //                // append attribute flags if any
       
   988 //                TBuf<4> atts;
       
   989 //                if (fileEntry.iEntry.IsArchive())
       
   990 //                    atts.Append(_L("A"));
       
   991 //                if (fileEntry.iEntry.IsHidden())
       
   992 //                    atts.Append(_L("H"));
       
   993 //                if (fileEntry.iEntry.IsReadOnly())
       
   994 //                    atts.Append(_L("R"));
       
   995 //                if (fileEntry.iEntry.IsSystem())
       
   996 //                    atts.Append(_L("S"));
       
   997 //
       
   998 //                if (atts.Length() > 0)
       
   999 //                    {
       
  1000 //                    extraData.Append(_L(" - ["));
       
  1001 //                    extraData.Append(atts);
       
  1002 //                    extraData.Append(_L("]"));
       
  1003 //                    }
       
  1004 //
       
  1005 //                // format
       
  1006 //                textEntry.Format(KExtendedFileEntry, fileEntry.iIconId, &fileEntry.iEntry.iName, &extraData);
       
  1007 //                }
       
  1008 //
       
  1009 //            iTextArray->AppendL(textEntry);
       
  1010 //            }
       
  1011 //        }
       
  1012 //
       
  1013 ////    CleanupStack::Pop(); //textArray
       
  1014 //    return iTextArray;
       
  1015 //    }
       
  1016     
       
  1017 // --------------------------------------------------------------------------------------------
       
  1018 
       
  1019 void CFileBrowserFileUtils::GenerateDirectoryDataL()
       
  1020     {
       
  1021     if (iListingMode == ENormalEntries)
       
  1022         {
       
  1023         if (IsDriveListViewActive())
       
  1024             GetDriveListL();    
       
  1025         else
       
  1026             GetDirectoryListingL();        
       
  1027         }
       
  1028     }
       
  1029 
       
  1030 // --------------------------------------------------------------------------------------------
       
  1031 
       
  1032 void CFileBrowserFileUtils::GetDriveListL()
       
  1033     {
       
  1034     TDriveList driveList;
       
  1035     
       
  1036     // get drive listing depending of the support for network drives
       
  1037     if (iEngine->Settings().iSupportNetworkDrives)
       
  1038         {
       
  1039         #ifndef __SERIES60_30__
       
  1040             #ifndef __SERIES60_31__
       
  1041                 User::LeaveIfError(iFs.DriveList(driveList, KDriveAttAll));
       
  1042             #endif
       
  1043         #else    
       
  1044             User::LeaveIfError(iFs.DriveList(driveList));
       
  1045         #endif        
       
  1046         }
       
  1047     else
       
  1048         {
       
  1049         User::LeaveIfError(iFs.DriveList(driveList));
       
  1050         }
       
  1051     
       
  1052     iDriveEntryList->Reset();        
       
  1053     
       
  1054     for (TInt i=0; i<KMaxDrives; i++)
       
  1055         {
       
  1056         if (driveList[i])
       
  1057             {
       
  1058             TDriveEntry driveEntry;
       
  1059             
       
  1060             // set default icon
       
  1061             driveEntry.iIconId = EFixedIconPhoneMemory;
       
  1062 
       
  1063             // get drive letter and number 
       
  1064             driveEntry.iLetter = 'A' + i;
       
  1065             iFs.CharToDrive(driveEntry.iLetter, driveEntry.iNumber);
       
  1066             
       
  1067             // get volume info and check errors
       
  1068             if (iFs.Volume(driveEntry.iVolumeInfo, driveEntry.iNumber) == KErrNone)
       
  1069                 {
       
  1070                 // set media type descriptor
       
  1071                 TInt mediaType = driveEntry.iVolumeInfo.iDrive.iType;
       
  1072                 TBool extMountable( EFalse );
       
  1073                 
       
  1074                 if (mediaType == EMediaNotPresent)
       
  1075                     driveEntry.iMediaTypeDesc = _L("Not present");
       
  1076                 else if (mediaType ==EMediaUnknown )
       
  1077                     driveEntry.iMediaTypeDesc = _L("Unknown");
       
  1078                 else if (mediaType ==EMediaFloppy )
       
  1079                     driveEntry.iMediaTypeDesc = _L("Floppy");
       
  1080                 else if (mediaType == EMediaHardDisk)
       
  1081                     driveEntry.iMediaTypeDesc = _L("Mass storage");
       
  1082                 else if (mediaType == EMediaCdRom)
       
  1083                     driveEntry.iMediaTypeDesc = _L("CD-ROM");
       
  1084                 else if (mediaType == EMediaRam)
       
  1085                     driveEntry.iMediaTypeDesc = _L("RAM");
       
  1086                 else if (mediaType == EMediaFlash)
       
  1087                     driveEntry.iMediaTypeDesc = _L("Flash");
       
  1088                 else if (mediaType == EMediaRom)
       
  1089                     driveEntry.iMediaTypeDesc = _L("ROM");
       
  1090                 else if (mediaType == EMediaRemote)
       
  1091                     driveEntry.iMediaTypeDesc = _L("Remote");
       
  1092                 else if (mediaType == EMediaNANDFlash)
       
  1093                     driveEntry.iMediaTypeDesc = _L("NAND flash");
       
  1094                 
       
  1095                 // get real size of the ROM drive
       
  1096                 if (mediaType == EMediaRom)
       
  1097                     {
       
  1098                     TMemoryInfoV1Buf ramMemory;
       
  1099                     UserHal::MemoryInfo(ramMemory);
       
  1100                     driveEntry.iVolumeInfo.iSize = ramMemory().iTotalRomInBytes;
       
  1101                     }
       
  1102                 
       
  1103                 // set attribute descripitions
       
  1104                 if (driveEntry.iVolumeInfo.iDrive.iBattery == EBatNotSupported)
       
  1105                     driveEntry.iAttributesDesc.Append(_L("Battery not supported"));
       
  1106                 else if (driveEntry.iVolumeInfo.iDrive.iBattery == EBatGood)
       
  1107                     driveEntry.iAttributesDesc.Append(_L("Battery good"));
       
  1108                 else if (driveEntry.iVolumeInfo.iDrive.iBattery == EBatLow)
       
  1109                     driveEntry.iAttributesDesc.Append(_L("Battery low"));
       
  1110                 else
       
  1111                     driveEntry.iAttributesDesc.Append(_L("Battery state unknown"));
       
  1112                 
       
  1113                 if (driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAttLocal)
       
  1114                     driveEntry.iAttributesDesc.Append(_L(" + Local"));
       
  1115                 if (driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAttRom)
       
  1116                     driveEntry.iAttributesDesc.Append(_L(" + ROM"));
       
  1117                 if (driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAttRedirected)
       
  1118                     driveEntry.iAttributesDesc.Append(_L("+ Redirected"));
       
  1119                 if (driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAttSubsted)
       
  1120                     driveEntry.iAttributesDesc.Append(_L(" + Substed"));
       
  1121                 if (driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAttInternal)
       
  1122                     driveEntry.iAttributesDesc.Append(_L(" + Internal"));
       
  1123                 if (driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAttRemovable)
       
  1124                     {
       
  1125                     driveEntry.iAttributesDesc.Append(_L(" + Removable"));
       
  1126 #if (!defined __SERIES60_30__ && !defined __SERIES60_31__)
       
  1127                     TUint drvStatus( 0 );
       
  1128                     if ( !DriveInfo::GetDriveStatus( iFs, driveEntry.iNumber, drvStatus ) &&
       
  1129                          drvStatus & DriveInfo::EDriveExternallyMountable &&
       
  1130                          drvStatus & DriveInfo::EDriveInternal )
       
  1131                         {
       
  1132                         extMountable = ETrue;
       
  1133                         // iMediaTypeDesc already set as "Mass storage" 
       
  1134                         }
       
  1135                     else
       
  1136                         {
       
  1137                         driveEntry.iMediaTypeDesc = _L("Memory card");
       
  1138                         }
       
  1139 #else
       
  1140                     driveEntry.iMediaTypeDesc = _L("Memory card");
       
  1141 #endif
       
  1142                     }
       
  1143                 if (driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAttRemote)
       
  1144                     driveEntry.iAttributesDesc.Append(_L(" + Remote"));
       
  1145                 if (driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAttTransaction)
       
  1146                     driveEntry.iAttributesDesc.Append(_L(" + Transaction"));
       
  1147                                 
       
  1148                 if (driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttVariableSize)
       
  1149                     driveEntry.iAttributesDesc.Append(_L(" + Variable size"));
       
  1150                 if (driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttDualDensity)
       
  1151                     driveEntry.iAttributesDesc.Append(_L(" + Dual density"));
       
  1152                 if (driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttFormattable)
       
  1153                     driveEntry.iAttributesDesc.Append(_L(" + Formattable"));
       
  1154                 if (driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttWriteProtected)
       
  1155                     driveEntry.iAttributesDesc.Append(_L(" + Write protected"));
       
  1156                 if (driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttLockable)
       
  1157                     driveEntry.iAttributesDesc.Append(_L(" + Lockable"));
       
  1158                 if (driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttLocked)
       
  1159                     driveEntry.iAttributesDesc.Append(_L(" + Locked"));
       
  1160                 if (driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttHasPassword)
       
  1161                     driveEntry.iAttributesDesc.Append(_L(" + Has password"));
       
  1162                 if (driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttReadWhileWrite)
       
  1163                     driveEntry.iAttributesDesc.Append(_L(" + Read while write"));
       
  1164                 if (driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttDeleteNotify)
       
  1165                     driveEntry.iAttributesDesc.Append(_L(" + Supports DeleteNotify"));
       
  1166                 
       
  1167                 
       
  1168                 // mark a removable media with memory card icon
       
  1169                 if (driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAttRemovable && !extMountable)
       
  1170                     {
       
  1171                     if (driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttLocked || driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAbsent)
       
  1172                         {                
       
  1173                         driveEntry.iIconId = EFixedIconMemoryCardDisabled;
       
  1174                         }                 
       
  1175                     else
       
  1176                         {                
       
  1177                         driveEntry.iIconId = EFixedIconMemoryCard;
       
  1178                         } 
       
  1179                     }
       
  1180                 }   
       
  1181             
       
  1182             // if this fails, likely it's a memory card which is not present
       
  1183             else
       
  1184                 {
       
  1185                 TVolumeInfo volumeInfo;
       
  1186                 volumeInfo.iSize = 0;
       
  1187                 volumeInfo.iFree = 0;
       
  1188                 volumeInfo.iDrive.iDriveAtt = KDriveAttRemovable;
       
  1189                 volumeInfo.iDrive.iMediaAtt = KMediaAttWriteProtected;
       
  1190                 driveEntry.iVolumeInfo = volumeInfo;
       
  1191 
       
  1192                 driveEntry.iMediaTypeDesc = _L("Not ready");
       
  1193                 driveEntry.iIconId = EFixedIconMemoryCardDisabled;
       
  1194                 }
       
  1195             
       
  1196             if ( iPrevFolderName != KNullDesC && iPrevFolderName[0] == driveEntry.iLetter )
       
  1197                 {
       
  1198                 iPrevFolderIndex = iDriveEntryList->Count();
       
  1199                 }
       
  1200             
       
  1201             iDriveEntryList->AppendL(driveEntry);
       
  1202             }
       
  1203         }
       
  1204     
       
  1205     }
       
  1206 
       
  1207 // --------------------------------------------------------------------------------------------
       
  1208 
       
  1209 void CFileBrowserFileUtils::GetDirectoryListingL()
       
  1210     {
       
  1211     iFileEntryList->Reset();
       
  1212 
       
  1213     TInt sortMode(ESortByName);
       
  1214     if (iSortMode == EFileBrowserCmdViewSortByExtension)    
       
  1215         sortMode = ESortByExt; 
       
  1216     else if (iSortMode == EFileBrowserCmdViewSortBySize)    
       
  1217         sortMode = ESortBySize; 
       
  1218     else if (iSortMode == EFileBrowserCmdViewSortByDate)    
       
  1219         sortMode = ESortByDate; 
       
  1220     
       
  1221     TInt orderMode(EAscending);
       
  1222     if (iOrderMode == EFileBrowserCmdViewOrderDescending)    
       
  1223         orderMode = EDescending; 
       
  1224     
       
  1225     CDir* dir = NULL;
       
  1226     if (iFs.GetDir(iCurrentPath, KEntryAttMatchMask, sortMode | orderMode | EDirsFirst, dir) == KErrNone)
       
  1227         {
       
  1228         CleanupStack::PushL(dir);
       
  1229         
       
  1230         for (TInt i=0; i<dir->Count(); i++)
       
  1231             {
       
  1232             TFileEntry fileEntry;
       
  1233             fileEntry.iPath = iCurrentPath;
       
  1234             fileEntry.iEntry = (*dir)[i];
       
  1235             fileEntry.iDirEntries = KErrNotFound;
       
  1236             fileEntry.iIconId = EFixedIconEmpty;
       
  1237             
       
  1238             if ( iPrevFolderName != KNullDesC && iPrevFolderName == fileEntry.iEntry.iName )
       
  1239                 {
       
  1240                 iPrevFolderIndex = i;
       
  1241                 }
       
  1242             
       
  1243             // check for directory entries
       
  1244             if (fileEntry.iEntry.IsDir())
       
  1245                 {
       
  1246                 fileEntry.iIconId = EFixedIconFolder;
       
  1247 
       
  1248                 TFileName subPath = fileEntry.iPath;
       
  1249                 subPath.Append(fileEntry.iEntry.iName);
       
  1250                 subPath.Append(_L("\\"));
       
  1251                                 
       
  1252                 // get number of entries in this directory if extended info about sub directories enabled
       
  1253                 if (iEngine->Settings().iShowSubDirectoryInfo && iEngine->Settings().iFileViewMode == EFileViewModeExtended)
       
  1254                     {
       
  1255                     CDir* subDir = NULL;
       
  1256                     if (iFs.GetDir(subPath, KEntryAttMatchMask, ESortNone | EDirsFirst, subDir) == KErrNone)
       
  1257                         {
       
  1258                         fileEntry.iDirEntries = subDir->Count();
       
  1259                         delete subDir;    
       
  1260                         }
       
  1261                     }
       
  1262                 
       
  1263                 // apply subfolder icon for known directories (speed improvement)
       
  1264                 if (subPath[0]=='Z' && (subPath.CompareF(_L("Z:\\data\\"))==0 || subPath.CompareF(_L("Z:\\Nokia\\"))==0
       
  1265                     || subPath.Compare(_L("Z:\\private\\"))==0 || subPath.Compare(_L("Z:\\resource\\"))==0
       
  1266                     || subPath.Compare(_L("Z:\\sys\\"))==0 || subPath.Compare(_L("Z:\\system\\"))==0))
       
  1267                     {
       
  1268                     fileEntry.iIconId = EFixedIconFolderSub;
       
  1269                     }
       
  1270                 else if (subPath[0]=='Z' && (subPath.CompareF(_L("Z:\\sys\\bin\\"))==0))
       
  1271                     {
       
  1272                     // normal folder icon for these ones
       
  1273                     fileEntry.iIconId = EFixedIconFolder;
       
  1274                     }
       
  1275                 else
       
  1276                     {
       
  1277                     // check if this folder has subdirectories
       
  1278                     CDir* subDir = NULL;
       
  1279                     if (iFs.GetDir(subPath, KEntryAttDir|KEntryAttMatchMask, ESortNone | EDirsFirst, subDir) == KErrNone)
       
  1280                         {
       
  1281                         for (TInt j=0; j<subDir->Count(); j++)
       
  1282                             {
       
  1283                             TEntry entry = (*subDir)[j];
       
  1284 
       
  1285                             if (entry.IsDir())
       
  1286                                 {
       
  1287                                 fileEntry.iIconId = EFixedIconFolderSub;
       
  1288                                 break;    
       
  1289                                 }
       
  1290                             }
       
  1291 
       
  1292                         delete subDir;    
       
  1293                         }                    
       
  1294                     }
       
  1295                 }
       
  1296 
       
  1297             iFileEntryList->AppendL(fileEntry);
       
  1298             }
       
  1299         
       
  1300         CleanupStack::PopAndDestroy(); //dir    
       
  1301         }
       
  1302     }
       
  1303 
       
  1304 // --------------------------------------------------------------------------------------------
       
  1305 
       
  1306 void CFileBrowserFileUtils::MoveUpOneLevelL()
       
  1307     {
       
  1308     iPrevFolderIndex = KErrNotFound;
       
  1309     iPrevFolderName.Zero();
       
  1310     
       
  1311     // change back to normal mode or move up
       
  1312     if (iListingMode != ENormalEntries)
       
  1313         {
       
  1314         iListingMode = ENormalEntries;
       
  1315         }
       
  1316     else
       
  1317         {
       
  1318         // do nothing if displaying drive list view
       
  1319         if (IsDriveListViewActive())
       
  1320             return;
       
  1321         
       
  1322         if (iCurrentPath.Length() <= KDriveLetterStringLength)
       
  1323             {
       
  1324             if ( iCurrentPath.Length() > 0 )
       
  1325                 {
       
  1326                 iPrevFolderName.Append( iCurrentPath[0] );
       
  1327                 }
       
  1328             // move to drive list view if the current path is already short enough
       
  1329             iCurrentPath = KNullDesC;
       
  1330             }
       
  1331         else
       
  1332             {
       
  1333             // move one directory up
       
  1334             TInt marker(iCurrentPath.Length());
       
  1335             
       
  1336             // find second last dir marker
       
  1337             for (TInt i=iCurrentPath.Length()-2; i>=0; i--)
       
  1338                 {
       
  1339                 if (iCurrentPath[i] == '\\')
       
  1340                     {
       
  1341                     marker = i;
       
  1342                     break;
       
  1343                     }
       
  1344                     
       
  1345                 }
       
  1346             
       
  1347             // update iPrevDir with the directory name that we just left 
       
  1348             iPrevFolderName.Copy( iCurrentPath.RightTPtr( iCurrentPath.Length() -  marker - 1 ) );
       
  1349             iPrevFolderName.Delete( iPrevFolderName.Length() -1, 2 ); // remove extra '\\'
       
  1350             
       
  1351             iCurrentPath = iCurrentPath.LeftTPtr(marker+1);
       
  1352             }    
       
  1353         }
       
  1354 
       
  1355 //    if (iEngine->FileListContainer())
       
  1356 //        {
       
  1357         //iEngine->FileListContainer()->DisableSearchFieldL();
       
  1358         //iEngine->FileListContainer()->ListBox()->ClearSelection();
       
  1359         //iEngine->FileListContainer()->ListBox()->SetCurrentItemIndex(0);
       
  1360         //iEngine->FileListContainer()->SetNaviPaneTextL(iCurrentPath);
       
  1361 //        }
       
  1362     
       
  1363     // update view
       
  1364     RefreshViewL();
       
  1365     
       
  1366     if (iEngine->Settings().iRememberFolderSelection
       
  1367         //&& iEngine->FileListContainer()
       
  1368         && iPrevFolderIndex > KErrNotFound )
       
  1369         {
       
  1370         
       
  1371 //        TInt visibleItems = iEngine->FileListContainer()->ListBox()->Rect().Height() /
       
  1372 //                            iEngine->FileListContainer()->ListBox()->ItemHeight()
       
  1373 //                            - 1; // for the title row
       
  1374 //
       
  1375 //        // By default, the selected item would be the last visible item on the listbox.
       
  1376 //        // We want the selected item be displayed at the middle of the listbox, so we
       
  1377 //        // select one of the successor items first to scroll down a bit
       
  1378 //        iEngine->FileListContainer()->ListBox()->SetCurrentItemIndex(
       
  1379 //            Min( iEngine->FileListContainer()->ListBox()->Model()->ItemTextArray()->MdcaCount() -1,
       
  1380 //                 iPrevFolderIndex + visibleItems / 2 ) );
       
  1381 //
       
  1382 //        // ...and after that we select the the correct item.
       
  1383 //        iEngine->FileListContainer()->ListBox()->SetCurrentItemIndex( iPrevFolderIndex );
       
  1384         
       
  1385         // update view
       
  1386         RefreshViewL();
       
  1387         }
       
  1388     }
       
  1389 
       
  1390 // --------------------------------------------------------------------------------------------
       
  1391 
       
  1392 void CFileBrowserFileUtils::MoveDownToDirectoryL(TInt aIndex)
       
  1393     {
       
  1394 
       
  1395     // change back to normal mode
       
  1396     if (iListingMode != ENormalEntries)
       
  1397         {
       
  1398         iListingMode = ENormalEntries;
       
  1399         }
       
  1400     
       
  1401     if (aIndex >= 0)
       
  1402         {
       
  1403         TBool needsRefresh(EFalse);
       
  1404 
       
  1405         if (IsDriveListViewActive())
       
  1406             {
       
  1407             // currently in a drive list view, move to root of selected drive
       
  1408             if (iDriveEntryList->Count() > aIndex)
       
  1409                 {
       
  1410                 TDriveEntry driveEntry = iDriveEntryList->At(aIndex);
       
  1411                 
       
  1412                 iCurrentPath.Append(driveEntry.iLetter);    
       
  1413                 iCurrentPath.Append(_L(":\\"));
       
  1414                 
       
  1415                 needsRefresh = ETrue;    
       
  1416                 }
       
  1417             }
       
  1418         else
       
  1419             {
       
  1420             // otherwise just append the new directory
       
  1421             if (iFileEntryList->Count() > aIndex)
       
  1422                 {
       
  1423                 TFileEntry fileEntry = iFileEntryList->At(aIndex);
       
  1424                 
       
  1425                 if (fileEntry.iEntry.IsDir())
       
  1426                     {
       
  1427                     iCurrentPath.Copy(fileEntry.iPath);
       
  1428                     iCurrentPath.Append(fileEntry.iEntry.iName);
       
  1429                     iCurrentPath.Append(_L("\\"));
       
  1430 
       
  1431                     needsRefresh = ETrue;    
       
  1432                     }
       
  1433                 }
       
  1434             }
       
  1435 
       
  1436         if (needsRefresh /*&& iEngine->FileListContainer()*/)
       
  1437             {
       
  1438             //iEngine->FileListContainer()->DisableSearchFieldL();
       
  1439             //iEngine->FileListContainer()->ListBox()->ClearSelection();
       
  1440             //iEngine->FileListContainer()->ListBox()->SetCurrentItemIndex(0);
       
  1441             //iEngine->FileListContainer()->SetNaviPaneTextL(iCurrentPath);
       
  1442 
       
  1443             // update view
       
  1444             RefreshViewL();
       
  1445             }
       
  1446         }
       
  1447     }
       
  1448     
       
  1449 // --------------------------------------------------------------------------------------------
       
  1450 
       
  1451 TBool CFileBrowserFileUtils::IsCurrentDriveReadOnly()
       
  1452     {
       
  1453     if (iListingMode !=ENormalEntries || iCurrentPath.Length() < 2)
       
  1454         return EFalse;
       
  1455     else
       
  1456         {
       
  1457         for (TInt i=0; i<iDriveEntryList->Count(); i++)
       
  1458             {
       
  1459             TDriveEntry driveEntry = iDriveEntryList->At(i);
       
  1460             
       
  1461             if (driveEntry.iLetter == iCurrentPath[0])
       
  1462                 {
       
  1463                 if (driveEntry.iVolumeInfo.iDrive.iMediaAtt == KMediaAttWriteProtected || driveEntry.iVolumeInfo.iDrive.iMediaAtt == KMediaAttLocked || driveEntry.iVolumeInfo.iDrive.iDriveAtt == KDriveAbsent)
       
  1464                     return ETrue;    
       
  1465                 else
       
  1466                     return EFalse;
       
  1467                 }
       
  1468             }
       
  1469         }
       
  1470 
       
  1471     return EFalse;
       
  1472     }
       
  1473 
       
  1474 // --------------------------------------------------------------------------------------------
       
  1475 
       
  1476 TBool CFileBrowserFileUtils::IsItemDirectory(TInt aCurrentItemIndex)
       
  1477     {
       
  1478     if (aCurrentItemIndex < 0)
       
  1479         {
       
  1480         return EFalse;
       
  1481         }
       
  1482     else
       
  1483         {
       
  1484         if (iFileEntryList->Count() > aCurrentItemIndex)
       
  1485             {
       
  1486             TFileEntry fileEntry = iFileEntryList->At(aCurrentItemIndex) ;
       
  1487             return fileEntry.iEntry.IsDir();
       
  1488             }
       
  1489         else
       
  1490             {
       
  1491             return EFalse;
       
  1492             }
       
  1493         }
       
  1494     }
       
  1495 
       
  1496 // --------------------------------------------------------------------------------------------
       
  1497 
       
  1498 TInt CFileBrowserFileUtils::SetSelectedItemsOrCurrentItemL(const CArrayFix<TInt>* selectionIndexes,
       
  1499                                                            CFileEntryList* aFileEntryList)
       
  1500     {
       
  1501     aFileEntryList->Reset();
       
  1502 
       
  1503     // by default use selected items
       
  1504     if (selectionIndexes && selectionIndexes->Count() > 0)
       
  1505         {
       
  1506         TInt ref(0);
       
  1507         TKeyArrayFix key(0, ECmpTUint16);
       
  1508         TInt index(0);
       
  1509 
       
  1510         for (TInt i=0; i<iFileEntryList->Count(); i++)
       
  1511             {
       
  1512             ref = i;
       
  1513 
       
  1514             if (selectionIndexes->Find(ref, key, index) == 0)
       
  1515                 {
       
  1516                 aFileEntryList->AppendL(iFileEntryList->At(i));
       
  1517                 }
       
  1518             }
       
  1519         }
       
  1520     return aFileEntryList->Count();
       
  1521     }
       
  1522 
       
  1523 // --------------------------------------------------------------------------------------------
       
  1524 
       
  1525 TInt CFileBrowserFileUtils::ClipboardCutL(const CArrayFix<TInt>* aSelectionIndices)
       
  1526     {
       
  1527 	
       
  1528     iClipBoardMode = EClipBoardModeCut;
       
  1529     TInt operations = SetSelectedItemsOrCurrentItemL(aSelectionIndices, iClipBoardList);
       
  1530     return operations;
       
  1531     }
       
  1532 
       
  1533 // --------------------------------------------------------------------------------------------
       
  1534 
       
  1535 TInt CFileBrowserFileUtils::ClipboardCopyL(const CArrayFix<TInt>* aSelectionIndices)
       
  1536     {
       
  1537     iClipBoardMode = EClipBoardModeCopy;
       
  1538     TInt operations = SetSelectedItemsOrCurrentItemL(aSelectionIndices, iClipBoardList);
       
  1539     return operations;
       
  1540     }
       
  1541 
       
  1542 // --------------------------------------------------------------------------------------------
       
  1543 
       
  1544 void CFileBrowserFileUtils::ClipboardPasteL(const TOverwriteOptions &aOverwriteOptions)
       
  1545     {
       
  1546     if (iClipBoardMode == EClipBoardModeCut)
       
  1547         {
       
  1548         DoCopyToFolderL(iClipBoardList, iCurrentPath, aOverwriteOptions, ETrue );
       
  1549         iClipBoardList->Reset();
       
  1550         }
       
  1551     else if (iClipBoardMode == EClipBoardModeCopy)
       
  1552         {
       
  1553         DoCopyToFolderL(iClipBoardList, iCurrentPath, aOverwriteOptions, EFalse);
       
  1554         }
       
  1555     }
       
  1556 
       
  1557 // --------------------------------------------------------------------------------------------
       
  1558 
       
  1559 TInt CFileBrowserFileUtils::SetCurrentSelection(const CArrayFix<TInt>* aSelectionIndices)
       
  1560     {
       
  1561     TInt operations = SetSelectedItemsOrCurrentItemL(aSelectionIndices, iCurrentSelectionList);
       
  1562     return operations;
       
  1563     }
       
  1564 
       
  1565 // --------------------------------------------------------------------------------------------
       
  1566 
       
  1567 void CFileBrowserFileUtils::CopyToFolderL(TFileName aTargetDir,
       
  1568                                           const TOverwriteOptions &aOverwriteOptions,
       
  1569                                           TBool aMove)
       
  1570     {
       
  1571 
       
  1572     //	TFileName destinationFolder;
       
  1573 
       
  1574     // generate an icon array
       
  1575     // CAknIconArray* iconArray = GenerateIconArrayL(ETrue);
       
  1576     //    CleanupStack::PushL(iconArray);
       
  1577 
       
  1578     // run folder selection dialog
       
  1579     //    CFileBrowserDestinationFolderSelectionDlg* dlg = CFileBrowserDestinationFolderSelectionDlg::NewL(destinationFolder, iDriveEntryList, iconArray);
       
  1580 
       
  1581     // do the file operations
       
  1582     //DoCopyToFolderL(entryList, aTargetDir, aOverwriteOptions, aMove);
       
  1583     DoCopyToFolderL(iCurrentSelectionList, aTargetDir, aOverwriteOptions, aMove);
       
  1584 
       
  1585     //    CleanupStack::Pop(); //iconArray
       
  1586     }
       
  1587 
       
  1588 // --------------------------------------------------------------------------------------------
       
  1589 
       
  1590 TBool CFileBrowserFileUtils::IsDestinationEntriesExists(const TDesC& aTargetDir)
       
  1591     {
       
  1592     TBool someEntryExists(EFalse);
       
  1593     if (iCurrentSelectionList && iCurrentSelectionList->Count() > 0)
       
  1594         {
       
  1595         // check if some destination entries also exists
       
  1596         for (TInt i=0; i<iCurrentSelectionList->Count(); i++)
       
  1597             {
       
  1598             TFileEntry fileEntry = iCurrentSelectionList->At(i);
       
  1599 
       
  1600             TFileName targetEntry = aTargetDir;
       
  1601             targetEntry.Append(fileEntry.iEntry.iName);
       
  1602 
       
  1603             if (fileEntry.iEntry.IsDir())
       
  1604                 {
       
  1605                 targetEntry.Append(_L("\\"));
       
  1606 
       
  1607                 if (BaflUtils::PathExists(iFs, targetEntry))
       
  1608                     {
       
  1609                     someEntryExists = ETrue;
       
  1610                     break;
       
  1611                     }
       
  1612                 }
       
  1613             else
       
  1614                 {
       
  1615                 if (BaflUtils::FileExists(iFs, targetEntry))
       
  1616                     {
       
  1617                     someEntryExists = ETrue;
       
  1618                     break;
       
  1619                     }
       
  1620                 }
       
  1621             }
       
  1622         }
       
  1623     return someEntryExists;
       
  1624     }
       
  1625 
       
  1626 // --------------------------------------------------------------------------------------------
       
  1627 
       
  1628 void CFileBrowserFileUtils::DoCopyToFolderL(CFileEntryList* aEntryList,
       
  1629                                             const TDesC& aTargetDir,
       
  1630                                             const TOverwriteOptions &aOverwriteOptions,
       
  1631                                             TBool aDeleteSource)
       
  1632     {
       
  1633     if (aEntryList && aEntryList->Count() > 0)
       
  1634         {
       
  1635         if (aOverwriteOptions.iDoFileOperations)
       
  1636             {
       
  1637             // set correct command id depending if we are copying or moving
       
  1638             TInt commandId(EFileBrowserFileOpCommandCopy);
       
  1639             if (aDeleteSource)
       
  1640                 commandId = EFileBrowserFileOpCommandMove;
       
  1641             
       
  1642             // do the file operations for each entry
       
  1643             for (TInt i=0; i<aEntryList->Count(); i++)
       
  1644                 {
       
  1645                 TFileEntry fileEntry = aEntryList->At(i);
       
  1646                 
       
  1647                 TFileName targetEntry = aTargetDir;
       
  1648                 targetEntry.Append(fileEntry.iEntry.iName);
       
  1649                 
       
  1650                 if (aOverwriteOptions.iQueryIndex == EFileActionGenerateUniqueFilenames)
       
  1651                     {
       
  1652                     CApaApplication::GenerateFileName(iFs, targetEntry);
       
  1653                     }
       
  1654                 else if (aOverwriteOptions.iQueryIndex == EFileActionQueryPostFix)
       
  1655                     {
       
  1656                     targetEntry.Append(aOverwriteOptions.iPostFix);
       
  1657                     }
       
  1658 
       
  1659                 
       
  1660                 // append the new command to the command array
       
  1661                 if (fileEntry.iEntry.IsDir())
       
  1662                     {
       
  1663                     AppendToCommandArrayL(commandId,
       
  1664                                           new(ELeave)CCommandParamsCopyOrMove(fileEntry, targetEntry, aOverwriteOptions.iOverWriteFlags|CFileMan::ERecurse)
       
  1665                                          );
       
  1666                     }
       
  1667                 else
       
  1668                     {
       
  1669                     AppendToCommandArrayL(commandId,
       
  1670                                           new(ELeave)CCommandParamsCopyOrMove(fileEntry, targetEntry, aOverwriteOptions.iOverWriteFlags)
       
  1671                                          );
       
  1672                     }
       
  1673 
       
  1674                 }
       
  1675             }
       
  1676         }
       
  1677     }
       
  1678 
       
  1679 // --------------------------------------------------------------------------------------------
       
  1680 
       
  1681 void CFileBrowserFileUtils::DeleteL()
       
  1682     {
       
  1683     // do the file operations for each entry
       
  1684     for (TInt i=0; i<iCurrentSelectionList->Count(); i++)
       
  1685         {
       
  1686         TFileEntry fileEntry = iCurrentSelectionList->At(i);
       
  1687 
       
  1688         // append the new command to the command array
       
  1689         if (fileEntry.iEntry.IsDir())
       
  1690             {
       
  1691             AppendToCommandArrayL(EFileBrowserFileOpCommandDelete,
       
  1692                                   new(ELeave)CCommandParamsDelete(fileEntry, CFileMan::ERecurse)
       
  1693                                  );
       
  1694             }
       
  1695         else
       
  1696             {
       
  1697             AppendToCommandArrayL(EFileBrowserFileOpCommandDelete,
       
  1698                                   new(ELeave)CCommandParamsDelete(fileEntry, 0)
       
  1699                                  );
       
  1700             }
       
  1701 
       
  1702         }
       
  1703     }
       
  1704 
       
  1705 
       
  1706 // --------------------------------------------------------------------------------------------
       
  1707 
       
  1708 TBool CFileBrowserFileUtils::SelectionHasDirs()
       
  1709 {
       
  1710     TBool isDir(EFalse);
       
  1711 
       
  1712     // check if any directories and ask recursion
       
  1713     for (TInt i=0; i<iCurrentSelectionList->Count(); i++)
       
  1714         {
       
  1715         TFileEntry fileEntry = iCurrentSelectionList->At(i);
       
  1716 
       
  1717         if (fileEntry.iEntry.IsDir())
       
  1718             {
       
  1719             isDir = ETrue;
       
  1720             break;
       
  1721             }
       
  1722         }
       
  1723     return isDir;
       
  1724 }
       
  1725 
       
  1726 // --------------------------------------------------------------------------------------------
       
  1727 
       
  1728 void CFileBrowserFileUtils::TouchL(TBool aRecurse)
       
  1729     {
       
  1730     // now go through all entries
       
  1731     for (TInt i=0; i<iCurrentSelectionList->Count(); i++)
       
  1732         {
       
  1733         TFileEntry fileEntry = iCurrentSelectionList->At(i);
       
  1734 
       
  1735         // touch to current time
       
  1736         TTime now;
       
  1737         now.UniversalTime();
       
  1738 
       
  1739 
       
  1740         // append the new command to the command array
       
  1741         if (fileEntry.iEntry.IsDir() && aRecurse)
       
  1742             {
       
  1743             AppendToCommandArrayL(EFileBrowserFileOpCommandAttribs,
       
  1744                                   new(ELeave)CCommandParamsAttribs(fileEntry, NULL, NULL, now, CFileMan::ERecurse)
       
  1745                                  );
       
  1746             }
       
  1747         else
       
  1748             {
       
  1749             AppendToCommandArrayL(EFileBrowserFileOpCommandAttribs,
       
  1750                                   new(ELeave)CCommandParamsAttribs(fileEntry, NULL, NULL, now, 0)
       
  1751                                  );
       
  1752             }
       
  1753         }
       
  1754     }
       
  1755 
       
  1756 TBool CFileBrowserFileUtils::TargetExists(const TInt aIndex, const TFileName &newName)
       
  1757     {
       
  1758     TBool alreadyExists(EFalse);
       
  1759     if (iFileEntryList->Count() > aIndex && aIndex >= 0)
       
  1760         {
       
  1761 
       
  1762         TFileEntry fileEntry = iFileEntryList->At(aIndex);
       
  1763         TFileName targetEntry = fileEntry.iPath;
       
  1764         targetEntry.Append(newName);
       
  1765         if (fileEntry.iEntry.IsDir())
       
  1766             {
       
  1767             //targetEntry.Append(_L("\\"));
       
  1768             alreadyExists = BaflUtils::PathExists(iFs, targetEntry);
       
  1769             }
       
  1770         else
       
  1771             {
       
  1772             alreadyExists = BaflUtils::FileExists(iFs, targetEntry);
       
  1773             }
       
  1774         }
       
  1775     return alreadyExists;
       
  1776     }
       
  1777 
       
  1778 // --------------------------------------------------------------------------------------------
       
  1779 
       
  1780 void CFileBrowserFileUtils::RenameL(const TInt aIndex, const TFileName &newName)
       
  1781     {
       
  1782         if (iFileEntryList->Count() > aIndex && aIndex >= 0)
       
  1783         {
       
  1784             TFileEntry fileEntry = iFileEntryList->At(aIndex);
       
  1785 
       
  1786             TFileName targetEntry = fileEntry.iPath;
       
  1787             targetEntry.Append(newName);
       
  1788 
       
  1789             // append the new command to the command array
       
  1790             AppendToCommandArrayL(EFileBrowserFileOpCommandRename,
       
  1791                                   new(ELeave)CCommandParamsRename(fileEntry, targetEntry, CFileMan::EOverWrite)
       
  1792                                  );
       
  1793         }
       
  1794     }
       
  1795 
       
  1796 // --------------------------------------------------------------------------------------------
       
  1797 
       
  1798 void CFileBrowserFileUtils::SetAttributesL(TUint &aSetAttMask, TUint &aClearAttMask, TBool &aRecurse)
       
  1799     {
       
  1800     for (TInt i=0; i<iCurrentSelectionList->Count(); i++)
       
  1801         {
       
  1802         TFileEntry fileEntry = iCurrentSelectionList->At(i);
       
  1803 
       
  1804         // append the new command to the command array
       
  1805         if (fileEntry.iEntry.IsDir() && aRecurse)
       
  1806             {
       
  1807             AppendToCommandArrayL(EFileBrowserFileOpCommandAttribs,
       
  1808                                   new(ELeave)CCommandParamsAttribs(fileEntry, aSetAttMask, aClearAttMask, fileEntry.iEntry.iModified, CFileMan::ERecurse)
       
  1809                                  );
       
  1810             }
       
  1811         else
       
  1812             {
       
  1813             AppendToCommandArrayL(EFileBrowserFileOpCommandAttribs,
       
  1814                                   new(ELeave)CCommandParamsAttribs(fileEntry, aSetAttMask, aClearAttMask, fileEntry.iEntry.iModified, 0)
       
  1815                                  );
       
  1816             }
       
  1817         }
       
  1818 
       
  1819     // execute all operations
       
  1820     StartExecutingCommandsL(_L("Changing attributes"));
       
  1821     }
       
  1822        
       
  1823 // --------------------------------------------------------------------------------------------
       
  1824 
       
  1825 void CFileBrowserFileUtils::SearchL()
       
  1826     {
       
  1827 //    iEngine->FileListContainer()->SetScreenLayoutL(EDisplayModeNormal);
       
  1828 //    iEngine->FileListContainer()->SetNaviPaneTextL(KNullDesC);
       
  1829 //
       
  1830 //    iSearchAttributes.iSearchDir = iCurrentPath;
       
  1831 //
       
  1832 //    CFileBrowserSearchQueryDlg* dlg = CFileBrowserSearchQueryDlg::NewL(iSearchAttributes);
       
  1833 //    TBool dlgResult = dlg->RunQueryLD();
       
  1834 //
       
  1835 //    iEngine->FileListContainer()->SetScreenLayoutL(iEngine->Settings().iDisplayMode);
       
  1836 //    iEngine->FileListContainer()->SetNaviPaneTextL(iCurrentPath);
       
  1837 //
       
  1838 //    if (dlgResult)
       
  1839 //        {
       
  1840 //        iEngine->EikonEnv()->BusyMsgL(_L("** Searching **"), TGulAlignment(EHCenterVTop));
       
  1841 
       
  1842 
       
  1843         iEngine->FileBrowserUI()->ShowWaitDialog(_L("Searching"));
       
  1844         iFileEntryList->Reset();
       
  1845 
       
  1846         // if search dir is empty, find from all drives
       
  1847         if (iSearchAttributes.iSearchDir == KNullDesC)
       
  1848             {
       
  1849             for (TInt i=0; i<iDriveEntryList->Count(); i++)
       
  1850                 {
       
  1851                 TDriveEntry driveEntry = iDriveEntryList->At(i);
       
  1852 
       
  1853                 TBuf<10> driveRoot;
       
  1854                 driveRoot.Append(driveEntry.iLetter);
       
  1855                 driveRoot.Append(_L(":\\"));
       
  1856 
       
  1857                 DoSearchFiles(iSearchAttributes.iWildCards, driveRoot);
       
  1858 
       
  1859                 if (iSearchAttributes.iRecurse)
       
  1860                     DoSearchFilesRecursiveL(iSearchAttributes.iWildCards, driveRoot);
       
  1861                 }
       
  1862 
       
  1863             }
       
  1864 
       
  1865         // otherwise just search from the selected directory
       
  1866         else
       
  1867             {
       
  1868             DoSearchFiles(iSearchAttributes.iWildCards, iSearchAttributes.iSearchDir);
       
  1869 
       
  1870             if (iSearchAttributes.iRecurse)
       
  1871                 DoSearchFilesRecursiveL(iSearchAttributes.iWildCards, iSearchAttributes.iSearchDir);
       
  1872             }
       
  1873 
       
  1874 //        iEngine->EikonEnv()->BusyMsgCancel();
       
  1875         iEngine->FileBrowserUI()->CancelWaitDialog();
       
  1876 
       
  1877 //        TInt operations = iFileEntryList->Count();
       
  1878 
       
  1879         iListingMode = ESearchResults;
       
  1880         // TODO iEngine->FileListContainer()->ListBox()->SetCurrentItemIndex(0);
       
  1881         RefreshViewL();
       
  1882 
       
  1883 //        _LIT(KMessage, "%d entries found");
       
  1884 //        TFileName noteMsg;
       
  1885 //        noteMsg.Format(KMessage, operations);
       
  1886 //
       
  1887 //        iEngine->FileBrowserUI()->ShowInformationNote(noteMsg, _L(""));
       
  1888 //        }
       
  1889     }
       
  1890 
       
  1891 // --------------------------------------------------------------------------------------------
       
  1892 
       
  1893 TInt CFileBrowserFileUtils::DoSearchFiles(const TDesC& aFileName, const TDesC& aPath)
       
  1894     {
       
  1895     TFindFile fileFinder(iFs);
       
  1896     CDir* dir;
       
  1897     TInt err = fileFinder.FindWildByPath(aFileName, &aPath, dir);
       
  1898 
       
  1899     while (err == KErrNone && iAllowProcessing)
       
  1900         {
       
  1901         iEngine->FileBrowserUI()->ProcessEvents();
       
  1902         for (TInt i=0; i<dir->Count(); i++)
       
  1903             {
       
  1904             TEntry entry = (*dir)[i];
       
  1905             
       
  1906             TTime entryModified = entry.iModified;
       
  1907             // convert from universal time
       
  1908             if ( iTz.ConvertToLocalTime( entryModified ) == KErrNone )
       
  1909                 {
       
  1910                 entryModified = entry.iModified;
       
  1911                 }
       
  1912             if ((entry.IsDir() && entryModified >= iSearchAttributes.iMinDate && entryModified <= iSearchAttributes.iMaxDate) ||
       
  1913                 (!entry.IsDir() &&entry.iSize >= iSearchAttributes.iMinSize && entry.iSize <= iSearchAttributes.iMaxSize &&
       
  1914                  entryModified >= iSearchAttributes.iMinDate && entryModified <= iSearchAttributes.iMaxDate))
       
  1915                 {
       
  1916                 TParse parsedName;
       
  1917                 parsedName.Set(entry.iName, &fileFinder.File(), NULL);
       
  1918                 
       
  1919                 if (parsedName.Drive().Length() && aPath.Length() && parsedName.Drive()[0] == aPath[0])
       
  1920                     {
       
  1921                     TFileEntry fileEntry;
       
  1922                     fileEntry.iPath = parsedName.DriveAndPath();
       
  1923                     fileEntry.iEntry = entry;
       
  1924                     fileEntry.iDirEntries = KErrNotFound;
       
  1925                     
       
  1926                     TBool appendToArray(EFalse);
       
  1927                     
       
  1928                     // append directories always
       
  1929                     if (entry.IsDir() && !iSearchAttributes.iTextInFile.Length())
       
  1930                         {
       
  1931                         fileEntry.iIconId = EFixedIconFolder;
       
  1932                         appendToArray = ETrue;    
       
  1933                         }
       
  1934                     
       
  1935                     // normal file
       
  1936                     else
       
  1937                         {
       
  1938                         fileEntry.iIconId = EFixedIconEmpty;
       
  1939                         
       
  1940                         // check if a string needs to be found inside the file
       
  1941                         if (iSearchAttributes.iTextInFile.Length())
       
  1942                             {
       
  1943                             // currently only 8-bit searching, so convert from 16-bit
       
  1944                             TBuf8<256> searchText;
       
  1945                             searchText.Copy(iSearchAttributes.iTextInFile);
       
  1946                             
       
  1947                             // specify buffer size and create a buffer
       
  1948                             const TInt KReadBufSize = 1024*1024;
       
  1949                             HBufC8* buffer = HBufC8::NewLC(KReadBufSize);
       
  1950                             TPtr8 bufferPtr = buffer->Des();
       
  1951 
       
  1952                             // open the file for reading
       
  1953                             RFile file;
       
  1954                             if (file.Open(iFs, parsedName.FullName(), EFileRead) == KErrNone)
       
  1955                                 {
       
  1956                                 TInt currentPos(0);
       
  1957                                 
       
  1958                                 for (;;)
       
  1959                                     {
       
  1960                                     // read from the file
       
  1961                                     file.Read(currentPos, bufferPtr, KReadBufSize);
       
  1962 
       
  1963                                     // stop looping if the read buffer isn't long enough
       
  1964                                     if (bufferPtr.Length() < searchText.Length())
       
  1965                                         {
       
  1966                                         break;
       
  1967                                         }
       
  1968                                         
       
  1969                                     // try to find the text
       
  1970                                     if (bufferPtr.FindF(searchText) >= 0)
       
  1971                                         {
       
  1972                                         // match found!
       
  1973                                         appendToArray = ETrue;
       
  1974                                         break;
       
  1975                                         }
       
  1976                                         
       
  1977                                     // calculate the next position
       
  1978                                     currentPos += KReadBufSize - searchText.Length();    
       
  1979                                     }
       
  1980                                 
       
  1981                                 file.Close();
       
  1982                                 }
       
  1983                             
       
  1984                             CleanupStack::PopAndDestroy(); //buffer
       
  1985                             }
       
  1986                         else
       
  1987                             {
       
  1988                             appendToArray = ETrue;
       
  1989                             }
       
  1990                         }
       
  1991 
       
  1992                     if (appendToArray)
       
  1993                         TRAP(err, iFileEntryList->AppendL(fileEntry));    
       
  1994                     }
       
  1995                 }
       
  1996             }
       
  1997 
       
  1998         delete dir;
       
  1999         err = fileFinder.FindWild(dir);
       
  2000         }
       
  2001 
       
  2002     return err;
       
  2003     }
       
  2004 
       
  2005 // --------------------------------------------------------------------------------------------
       
  2006 
       
  2007 TInt CFileBrowserFileUtils::DoSearchFilesRecursiveL(const TDesC& aFileName, const TDesC& aPath)
       
  2008 	{
       
  2009     TInt err(KErrNone);
       
  2010     CDirScan* scan = CDirScan::NewLC(iFs);
       
  2011     scan->SetScanDataL(aPath, KEntryAttDir|KEntryAttMatchMask, ESortByName | EAscending | EDirsFirst);
       
  2012     CDir* dir = NULL;
       
  2013 
       
  2014     for(;;)
       
  2015         {
       
  2016         TRAP(err, scan->NextL(dir));
       
  2017         if (!dir  || (err != KErrNone))
       
  2018             break;
       
  2019 
       
  2020         for (TInt i=0; i<dir->Count(); i++)
       
  2021             {
       
  2022             TEntry entry = (*dir)[i];
       
  2023             
       
  2024             if (entry.IsDir())
       
  2025                 {
       
  2026                 TFileName path(scan->FullPath());
       
  2027                 
       
  2028                 if (path.Length())
       
  2029                     {
       
  2030                     path.Append(entry.iName);
       
  2031                     path.Append(_L("\\"));
       
  2032                     DoSearchFiles(aFileName, path);
       
  2033                     }
       
  2034                 }
       
  2035             }
       
  2036         delete(dir);
       
  2037         }
       
  2038 
       
  2039     CleanupStack::PopAndDestroy(scan);
       
  2040     return err;
       
  2041     }
       
  2042          
       
  2043 // --------------------------------------------------------------------------------------------
       
  2044 
       
  2045 void CFileBrowserFileUtils::NewFileL(const TFileName &aNewFileName)
       
  2046     {
       
  2047     TFileName fullPath = iCurrentPath;
       
  2048     fullPath.Append(aNewFileName);
       
  2049 
       
  2050     TParse nameParser;
       
  2051     TInt err = nameParser.SetNoWild(fullPath, NULL, NULL);
       
  2052 
       
  2053     if (err == KErrNone)
       
  2054         {
       
  2055         // do not try to recreate the file if it already exists
       
  2056         if (BaflUtils::PathExists(iFs, nameParser.DriveAndPath()))
       
  2057             {
       
  2058             err = iFileOps->CreateEmptyFile(fullPath);
       
  2059             }
       
  2060         else
       
  2061             err = KErrAlreadyExists;
       
  2062         }
       
  2063 
       
  2064     if (err == KErrNone)
       
  2065         {
       
  2066         iEngine->FileBrowserUI()->ShowConfirmationNote(_L("New file created"));
       
  2067         }
       
  2068 
       
  2069     else if (err == KErrAlreadyExists)
       
  2070         {
       
  2071         iEngine->FileBrowserUI()->ShowInformationNote(_L("File already exists"), _L(""));
       
  2072         }
       
  2073 
       
  2074     else
       
  2075         {
       
  2076         CTextResolver* textResolver = CTextResolver::NewLC(*iEngine->EikonEnv());
       
  2077 
       
  2078         iEngine->FileBrowserUI()->ShowErrorNote( textResolver->ResolveErrorString(err, CTextResolver::ECtxNoCtxNoSeparator) );
       
  2079 
       
  2080         CleanupStack::PopAndDestroy();  //textResolver
       
  2081         }
       
  2082 
       
  2083     RefreshViewL();
       
  2084     }
       
  2085 
       
  2086 // --------------------------------------------------------------------------------------------
       
  2087 
       
  2088 void CFileBrowserFileUtils::NewDirectoryL(const TFileName &aNewDirectoryName)
       
  2089     {       
       
  2090     TFileName fullPath = iCurrentPath;
       
  2091     fullPath.Append(aNewDirectoryName);
       
  2092     fullPath.Append(_L("\\"));
       
  2093 
       
  2094     TInt err = iFileOps->MkDirAll(fullPath, 0, ETrue);
       
  2095 
       
  2096     if (err == KErrNone)
       
  2097         {
       
  2098         iEngine->FileBrowserUI()->ShowConfirmationNote(_L("New directory created"));
       
  2099         }
       
  2100 
       
  2101     else if (err == KErrAlreadyExists)
       
  2102         {
       
  2103         iEngine->FileBrowserUI()->ShowInformationNote(_L("Directory already exists"), _L(""));
       
  2104         }
       
  2105 
       
  2106     else
       
  2107         {
       
  2108         CTextResolver* textResolver = CTextResolver::NewLC(*iEngine->EikonEnv());
       
  2109 
       
  2110         iEngine->FileBrowserUI()->ShowErrorNote( textResolver->ResolveErrorString(err, CTextResolver::ECtxNoCtxNoSeparator) );
       
  2111 
       
  2112         CleanupStack::PopAndDestroy();  //textResolver
       
  2113         }
       
  2114 
       
  2115     RefreshViewL();
       
  2116     }
       
  2117 
       
  2118 // --------------------------------------------------------------------------------------------
       
  2119 
       
  2120 void CFileBrowserFileUtils::SendToL()
       
  2121     {
       
  2122 //    CFileEntryList* entries = new(ELeave) CFileEntryList(32);
       
  2123 //    GetSelectedItemsOrCurrentItemL(entries);
       
  2124 //    CleanupStack::PushL(entries);
       
  2125 //
       
  2126 //    TInt operations(0);
       
  2127 //
       
  2128 //    CSendUi* sendUi = CSendUi::NewL();
       
  2129 //    CleanupStack::PushL(sendUi);
       
  2130 //    CMessageData* messageData = CMessageData::NewL();
       
  2131 //    CleanupStack::PushL(messageData);
       
  2132 //
       
  2133 //    for (TInt i=0; i<entries->Count(); i++)
       
  2134 //        {
       
  2135 //        TFileEntry fileEntry = entries->At(i);
       
  2136 //
       
  2137 //        // only supported for normal file entries
       
  2138 //        if (!fileEntry.iEntry.IsDir())
       
  2139 //            {
       
  2140 //            TFileName fullPath = fileEntry.iPath;
       
  2141 //            fullPath.Append(fileEntry.iEntry.iName);
       
  2142 //
       
  2143 //            messageData->AppendAttachmentL(fullPath);
       
  2144 //            operations++;
       
  2145 //
       
  2146 //            }
       
  2147 //        }
       
  2148 //
       
  2149 //    if (operations > 0)
       
  2150 //        {
       
  2151 //        sendUi->ShowQueryAndSendL(messageData, TSendingCapabilities(0, 0, TSendingCapabilities::ESupportsAttachments));
       
  2152 //
       
  2153 //        // I guess this note is not needed..
       
  2154 ////        _LIT(KMessage, "%d entries sent");
       
  2155 ////        TFileName noteMsg;
       
  2156 ////        noteMsg.Format(KMessage, operations);
       
  2157 ////
       
  2158 ////        iEngine->FileBrowserUI()->ShowConfirmationNote(noteMsg);
       
  2159 //        }
       
  2160 //    else
       
  2161 //        {
       
  2162 //        _LIT(KMessage, "Nothing to send");
       
  2163 //        iEngine->FileBrowserUI()->ShowInformationNote(KMessage, _L(""));
       
  2164 //        }
       
  2165 //
       
  2166 //    CleanupStack::PopAndDestroy(3); // entries, sendUi, messageData
       
  2167     }
       
  2168 
       
  2169 // --------------------------------------------------------------------------------------------
       
  2170 
       
  2171 void CFileBrowserFileUtils::CompressL()
       
  2172     {
       
  2173 //    CFileEntryList* entries = new(ELeave) CFileEntryList(16);
       
  2174 //    GetSelectedItemsOrCurrentItemL(entries);
       
  2175 //    CleanupStack::PushL(entries);
       
  2176 //
       
  2177 //    for (TInt i=0; i<entries->Count(); i++)
       
  2178 //        {
       
  2179 //        TFileEntry fileEntry = entries->At(i);
       
  2180 //
       
  2181 //        TFileName sourceEntry = fileEntry.iPath;
       
  2182 //        sourceEntry.Append(fileEntry.iEntry.iName);
       
  2183 //
       
  2184 //        TFileName targetEntry = sourceEntry;
       
  2185 //        targetEntry.Append(KGZipExt);
       
  2186 //
       
  2187 //        TFileName targetEntryShort;
       
  2188 //        targetEntryShort.Copy(fileEntry.iEntry.iName);
       
  2189 //        targetEntryShort.Append(KGZipExt);
       
  2190 //
       
  2191 //        if (BaflUtils::FileExists(iFs, targetEntry))
       
  2192 //            {
       
  2193 //            _LIT(KMessage, "%S already exists");
       
  2194 //            TFileName noteMsg;
       
  2195 //            noteMsg.Format(KMessage, &targetEntryShort);
       
  2196 //
       
  2197 //            iEngine->FileBrowserUI()->ShowInformationNote(noteMsg, _L(""));
       
  2198 //            }
       
  2199 //        else
       
  2200 //            {
       
  2201 //            TRAPD(err,
       
  2202 //                RFile inputFile;
       
  2203 //                User::LeaveIfError(inputFile.Open(iFs, sourceEntry, EFileStream | EFileRead | EFileShareAny));
       
  2204 //                CleanupClosePushL(inputFile);
       
  2205 //
       
  2206 //                CEZFileToGZip* gZip = CEZFileToGZip::NewLC(iFs, targetEntry, inputFile);
       
  2207 //
       
  2208 //                while (gZip->DeflateL())
       
  2209 //                    ;
       
  2210 //
       
  2211 //                CleanupStack::PopAndDestroy(2); //inputFile, gZip
       
  2212 //                );
       
  2213 //
       
  2214 //             if (err == KErrNone)
       
  2215 //                {
       
  2216 //                _LIT(KMessage, "%S created succesfully");
       
  2217 //                TFileName noteMsg;
       
  2218 //                noteMsg.Format(KMessage, &targetEntryShort);
       
  2219 //
       
  2220 //                iEngine->FileBrowserUI()->ShowConfirmationNote(noteMsg);
       
  2221 //                }
       
  2222 //             else
       
  2223 //                {
       
  2224 //                _LIT(KMessage, "Unable to create %S");
       
  2225 //                TFileName noteMsg;
       
  2226 //                noteMsg.Format(KMessage, &targetEntryShort);
       
  2227 //
       
  2228 //                iEngine->FileBrowserUI()->ShowErrorNote(noteMsg);
       
  2229 //                }
       
  2230 //
       
  2231 //            RefreshViewL();
       
  2232 //            }
       
  2233 //        }
       
  2234 //
       
  2235 //    CleanupStack::PopAndDestroy(); //entries
       
  2236     }
       
  2237 
       
  2238 // --------------------------------------------------------------------------------------------
       
  2239 
       
  2240 void CFileBrowserFileUtils::DecompressL()
       
  2241     {
       
  2242 //    CFileEntryList* entries = new(ELeave) CFileEntryList(16);
       
  2243 //    GetSelectedItemsOrCurrentItemL(entries);
       
  2244 //    CleanupStack::PushL(entries);
       
  2245 //
       
  2246 //    for (TInt i=0; i<entries->Count(); i++)
       
  2247 //        {
       
  2248 //        TFileEntry fileEntry = entries->At(i);
       
  2249 //
       
  2250 //        TFileName sourceEntry = fileEntry.iPath;
       
  2251 //        sourceEntry.Append(fileEntry.iEntry.iName);
       
  2252 //
       
  2253 //        TFileName targetEntry;
       
  2254 //        TFileName targetEntryShort;
       
  2255 //
       
  2256 //        TInt sourceNameLen = fileEntry.iEntry.iName.Length();
       
  2257 //        TInt gZipExtLen = KGZipExt().Length();
       
  2258 //
       
  2259 //        if (sourceNameLen > gZipExtLen && sourceEntry.Right(gZipExtLen).CompareF(KGZipExt) == 0)
       
  2260 //            {
       
  2261 //            targetEntry = sourceEntry.Left(sourceEntry.Length() - gZipExtLen);
       
  2262 //            targetEntryShort = fileEntry.iEntry.iName.Left(sourceNameLen - gZipExtLen);
       
  2263 //
       
  2264 //            if (BaflUtils::FileExists(iFs, targetEntry))
       
  2265 //                {
       
  2266 //                _LIT(KMessage, "%S already exists");
       
  2267 //                TFileName noteMsg;
       
  2268 //                noteMsg.Format(KMessage, &targetEntryShort);
       
  2269 //
       
  2270 //                iEngine->FileBrowserUI()->ShowInformationNote(noteMsg, _L(""));
       
  2271 //                }
       
  2272 //            else
       
  2273 //                {
       
  2274 //                TRAPD(err,
       
  2275 //                    RFile outputFile;
       
  2276 //                    User::LeaveIfError(outputFile.Create(iFs, targetEntry, EFileStream | EFileWrite | EFileShareExclusive));
       
  2277 //                    CleanupClosePushL(outputFile);
       
  2278 //
       
  2279 //                    CEZGZipToFile* gZip = CEZGZipToFile::NewLC(iFs, sourceEntry, outputFile);
       
  2280 //
       
  2281 //                    while (gZip->InflateL())
       
  2282 //                        ;
       
  2283 //
       
  2284 //                    CleanupStack::PopAndDestroy(2); //outputFile, gZip
       
  2285 //                    );
       
  2286 //
       
  2287 //                 if (err == KErrNone)
       
  2288 //                    {
       
  2289 //                    _LIT(KMessage, "%S decompressed succesfully");
       
  2290 //                    TFileName noteMsg;
       
  2291 //                    noteMsg.Format(KMessage, &fileEntry.iEntry.iName);
       
  2292 //
       
  2293 //                    iEngine->FileBrowserUI()->ShowConfirmationNote(noteMsg);
       
  2294 //                    }
       
  2295 //                 else
       
  2296 //                    {
       
  2297 //                    _LIT(KMessage, "Unable to decompress %S");
       
  2298 //                    TFileName noteMsg;
       
  2299 //                    noteMsg.Format(KMessage, &fileEntry.iEntry.iName);
       
  2300 //
       
  2301 //                    iEngine->FileBrowserUI()->ShowErrorNote(noteMsg);
       
  2302 //                    }
       
  2303 //
       
  2304 //                RefreshViewL();
       
  2305 //                }
       
  2306 //            }
       
  2307 //        else
       
  2308 //            {
       
  2309 //            _LIT(KMessage, "%S does not have %S extension");
       
  2310 //            TFileName noteMsg;
       
  2311 //            noteMsg.Format(KMessage, &fileEntry.iEntry.iName, &KGZipExt);
       
  2312 //
       
  2313 //            iEngine->FileBrowserUI()->ShowInformationNote(noteMsg, _L(""));
       
  2314 //            }
       
  2315 //        }
       
  2316 //
       
  2317 //    CleanupStack::PopAndDestroy(); //entries
       
  2318     }
       
  2319 
       
  2320 // --------------------------------------------------------------------------------------------
       
  2321 
       
  2322 bool CFileBrowserFileUtils::PropertiesL(TInt aCurrentItemIndex, CDesCArray* entryLines, TFileName &titleText)
       
  2323     {
       
  2324 
       
  2325     TBool showDialog(EFalse);
       
  2326     
       
  2327     _LIT(KPropertiesEntryStr,       "%S\t%S");
       
  2328     _LIT(KPropertiesEntryInt,       "%S\t%d");
       
  2329     _LIT(KPropertiesEntryUintHex,   "%S\t0x%x");
       
  2330     
       
  2331     _LIT(KDateFormat,               "%D%M%Y%/0%1%/1%2%/2%3%/3");
       
  2332     _LIT(KTimeFormat,               "%-B%:0%J%:1%T%:2%S%:3%+B");
       
  2333     
       
  2334     _LIT(KMediaType,                "Media");
       
  2335     _LIT(KAttributes,               "Atts");
       
  2336     _LIT(KVolumeName,               "Name");
       
  2337     _LIT(KUniqueID,                 "ID");
       
  2338     _LIT(KNumberOfEntries,          "Entries");
       
  2339     _LIT(KNumberOfFiles,            "Files");
       
  2340     _LIT(KUsed,                     "Used (B)");
       
  2341     _LIT(KFree,                     "Free (B)");
       
  2342     _LIT(KSize,                     "Size (B)");
       
  2343     _LIT(KPath,                     "Path");
       
  2344     _LIT(KDate,                     "Date");
       
  2345     _LIT(KTime,                     "Time");
       
  2346     _LIT(KMimeType,                 "Mime");
       
  2347     _LIT(KOpensWith,                "Opens");
       
  2348  
       
  2349 
       
  2350     // create an array for the items
       
  2351 //    CDesCArray* entryLines = new(ELeave) CDesCArrayFlat(16);
       
  2352 //    CleanupStack::PushL(entryLines);
       
  2353 //    TFileName titleText;
       
  2354     
       
  2355     // just get current item
       
  2356 //    TInt currentItemIndex = iEngine->QueryCurrentItemIndex();
       
  2357     
       
  2358     if (IsDriveListViewActive() && iDriveEntryList->Count() > aCurrentItemIndex && aCurrentItemIndex >= 0)
       
  2359         {
       
  2360         // it is a drive entry
       
  2361         TDriveEntry driveEntry = iDriveEntryList->At(aCurrentItemIndex);
       
  2362         TFileName textEntry;
       
  2363         
       
  2364         // set title
       
  2365         titleText.Append(driveEntry.iLetter);
       
  2366         titleText.Append(_L(":"));
       
  2367         
       
  2368         // media type
       
  2369         textEntry.Format(KPropertiesEntryStr, &KMediaType, &driveEntry.iMediaTypeDesc);
       
  2370         entryLines->AppendL(textEntry);
       
  2371 
       
  2372         // attributes
       
  2373         textEntry.Format(KPropertiesEntryStr, &KAttributes, &driveEntry.iAttributesDesc);
       
  2374         entryLines->AppendL(textEntry);
       
  2375 
       
  2376         // volume name
       
  2377         if (driveEntry.iVolumeInfo.iName.Length())
       
  2378             {
       
  2379             textEntry.Format(KPropertiesEntryStr, &KVolumeName, &driveEntry.iVolumeInfo.iName);
       
  2380             entryLines->AppendL(textEntry);
       
  2381             }
       
  2382 
       
  2383         // unique id
       
  2384         textEntry.Format(KPropertiesEntryUintHex, &KUniqueID, driveEntry.iVolumeInfo.iUniqueID);
       
  2385         entryLines->AppendL(textEntry);
       
  2386         
       
  2387         // number of files
       
  2388         if (iEngine->Settings().iShowSubDirectoryInfo)
       
  2389             {
       
  2390             iFindFileEntryList->Reset();
       
  2391             
       
  2392             TBuf<10> driveRoot;
       
  2393             driveRoot.Append(driveEntry.iLetter);
       
  2394             driveRoot.Append(_L(":\\"));
       
  2395 
       
  2396             DoFindFiles(_L("*"), driveRoot);
       
  2397             DoFindFilesRecursiveL(_L("*"), driveRoot);
       
  2398             
       
  2399             textEntry.Format(KPropertiesEntryInt, &KNumberOfFiles, iFindFileEntryList->Count());
       
  2400             entryLines->AppendL(textEntry);
       
  2401             
       
  2402             iFindFileEntryList->Reset();
       
  2403             }
       
  2404       
       
  2405         // used
       
  2406         TBuf<32> usedBuf;
       
  2407         usedBuf.AppendNum(driveEntry.iVolumeInfo.iSize-driveEntry.iVolumeInfo.iFree, TRealFormat(KDefaultRealWidth, 0));
       
  2408         textEntry.Format(KPropertiesEntryStr, &KUsed, &usedBuf);
       
  2409         entryLines->AppendL(textEntry);        
       
  2410 
       
  2411         // free
       
  2412         TBuf<32> freeBuf;
       
  2413         freeBuf.AppendNum(driveEntry.iVolumeInfo.iFree, TRealFormat(KDefaultRealWidth, 0));
       
  2414         textEntry.Format(KPropertiesEntryStr, &KFree, &freeBuf);
       
  2415         entryLines->AppendL(textEntry);
       
  2416                 
       
  2417         // size
       
  2418         TBuf<32> sizeBuf;
       
  2419         sizeBuf.AppendNum(driveEntry.iVolumeInfo.iSize, TRealFormat(KDefaultRealWidth, 0));
       
  2420         textEntry.Format(KPropertiesEntryStr, &KSize, &sizeBuf);
       
  2421         entryLines->AppendL(textEntry);   
       
  2422 
       
  2423         showDialog = ETrue;
       
  2424         }
       
  2425     
       
  2426     else if (iFileEntryList->Count() > aCurrentItemIndex && aCurrentItemIndex >= 0)
       
  2427         {
       
  2428         // it is a file or a directory entry
       
  2429         TFileEntry fileEntry = iFileEntryList->At(aCurrentItemIndex);
       
  2430         TFileName textEntry;
       
  2431         
       
  2432         // set title
       
  2433         titleText.Append(fileEntry.iEntry.iName);
       
  2434         
       
  2435         // path
       
  2436         textEntry.Format(KPropertiesEntryStr, &KPath, &fileEntry.iPath);
       
  2437         entryLines->AppendL(textEntry);
       
  2438 
       
  2439         // date
       
  2440         TTime entryModified = fileEntry.iEntry.iModified;
       
  2441         
       
  2442         // convert from universal time
       
  2443         if ( iTz.ConvertToLocalTime( entryModified ) == KErrNone )
       
  2444             {
       
  2445             entryModified = fileEntry.iEntry.iModified; // use universal time
       
  2446             }
       
  2447         
       
  2448         TBuf<32> dateBuf;
       
  2449         entryModified.FormatL(dateBuf, KDateFormat);
       
  2450         textEntry.Format(KPropertiesEntryStr, &KDate, &dateBuf);
       
  2451         entryLines->AppendL(textEntry);
       
  2452 
       
  2453         // time
       
  2454         TBuf<32> timeBuf;
       
  2455         entryModified.FormatL(timeBuf, KTimeFormat);
       
  2456         textEntry.Format(KPropertiesEntryStr, &KTime, &timeBuf);
       
  2457         entryLines->AppendL(textEntry);
       
  2458 
       
  2459         if (!fileEntry.iEntry.IsDir())
       
  2460             {
       
  2461             // size
       
  2462             TBuf<32> sizeBuf;
       
  2463             sizeBuf.AppendNum(fileEntry.iEntry.iSize, TRealFormat(KDefaultRealWidth, 0));
       
  2464             textEntry.Format(KPropertiesEntryStr, &KSize, &sizeBuf);
       
  2465             entryLines->AppendL(textEntry);            
       
  2466             }
       
  2467         else if (fileEntry.iEntry.IsDir() && iEngine->Settings().iShowSubDirectoryInfo)
       
  2468             {
       
  2469             iFindFileEntryList->Reset();
       
  2470             
       
  2471             TFileName fullPath;
       
  2472             fullPath.Append(fileEntry.iPath);
       
  2473             fullPath.Append(fileEntry.iEntry.iName);
       
  2474             fullPath.Append(_L("\\"));
       
  2475             
       
  2476             // number of entries
       
  2477             CDir* subDir = NULL;
       
  2478             if (iFs.GetDir(fullPath, KEntryAttMatchMask, ESortNone | EDirsFirst, subDir) == KErrNone)
       
  2479                 {
       
  2480                 CleanupStack::PushL(subDir);
       
  2481                 textEntry.Format(KPropertiesEntryInt, &KNumberOfEntries, subDir->Count());
       
  2482                 entryLines->AppendL(textEntry);
       
  2483                 CleanupStack::PopAndDestroy(); //subDir 
       
  2484                 }
       
  2485             
       
  2486             // number of files
       
  2487             DoFindFiles(_L("*"), fullPath);
       
  2488             DoFindFilesRecursiveL(_L("*"), fullPath);
       
  2489             textEntry.Format(KPropertiesEntryInt, &KNumberOfFiles, iFindFileEntryList->Count());
       
  2490             entryLines->AppendL(textEntry);
       
  2491             
       
  2492             // size
       
  2493             TInt64 size(0);
       
  2494             for (TInt i=0; i<iFindFileEntryList->Count(); i++)
       
  2495                 {
       
  2496                 TFileEntry fileEntry = iFindFileEntryList->At(i);
       
  2497                 size += fileEntry.iEntry.iSize;
       
  2498                 }
       
  2499             
       
  2500             TBuf<32> sizeBuf;
       
  2501             sizeBuf.AppendNum(size, TRealFormat(KDefaultRealWidth, 0));
       
  2502             textEntry.Format(KPropertiesEntryStr, &KSize, &sizeBuf);
       
  2503             entryLines->AppendL(textEntry); 
       
  2504             
       
  2505             iFindFileEntryList->Reset();            
       
  2506             }
       
  2507         
       
  2508         // attributes
       
  2509         TBuf<32> attBuf;
       
  2510         if (fileEntry.iEntry.IsArchive())
       
  2511             attBuf.Append(_L("Arc "));
       
  2512         if (fileEntry.iEntry.IsHidden())
       
  2513             attBuf.Append(_L("Hid "));
       
  2514         if (fileEntry.iEntry.IsReadOnly())
       
  2515             attBuf.Append(_L("R/O "));
       
  2516         if (fileEntry.iEntry.IsSystem())
       
  2517             attBuf.Append(_L("Sys"));
       
  2518         textEntry.Format(KPropertiesEntryStr, &KAttributes, &attBuf);
       
  2519         entryLines->AppendL(textEntry);            
       
  2520 
       
  2521         if (!fileEntry.iEntry.IsDir())
       
  2522             {
       
  2523             // mime type
       
  2524             TFileName fullPath = fileEntry.iPath;
       
  2525             fullPath.Append(fileEntry.iEntry.iName);
       
  2526             TDataType dataType;
       
  2527             TUid appUid;
       
  2528             if (iEngine->LsSession().AppForDocument(fullPath, appUid, dataType) == KErrNone)
       
  2529                 {
       
  2530                 TBuf<128> mimeTypeBuf;
       
  2531                 mimeTypeBuf.Copy(dataType.Des8());
       
  2532                 if (mimeTypeBuf == KNullDesC)
       
  2533                     mimeTypeBuf.Copy(_L("N/A"));
       
  2534                 textEntry.Format(KPropertiesEntryStr, &KMimeType, &mimeTypeBuf);
       
  2535                 entryLines->AppendL(textEntry); 
       
  2536                 }
       
  2537 
       
  2538             // opens with
       
  2539             TApaAppInfo appInfo;
       
  2540             if (iEngine->LsSession().GetAppInfo(appInfo, appUid) == KErrNone)
       
  2541                 {
       
  2542                 TFileName opensWithBuf;
       
  2543                 _LIT(KOpensWithFormat, "%S (0x%08X)");
       
  2544                 opensWithBuf.Format(KOpensWithFormat, &appInfo.iCaption, appInfo.iUid);
       
  2545                 textEntry.Format(KPropertiesEntryStr, &KOpensWith, &opensWithBuf);
       
  2546                 entryLines->AppendL(textEntry); 
       
  2547                 }
       
  2548             }
       
  2549         
       
  2550         showDialog = ETrue;
       
  2551         }   
       
  2552     return showDialog;
       
  2553 
       
  2554 //    if (showDialog)
       
  2555 //        {
       
  2556 //        CAknSingleHeadingPopupMenuStyleListBox* listBox = new(ELeave) CAknSingleHeadingPopupMenuStyleListBox;
       
  2557 //        CleanupStack::PushL(listBox);
       
  2558 //
       
  2559 //        CAknPopupList* popupList = CAknPopupList::NewL(listBox, R_AVKON_SOFTKEYS_OK_EMPTY, AknPopupLayouts::EMenuDoubleWindow);
       
  2560 //        CleanupStack::PushL(popupList);
       
  2561 //
       
  2562 //        listBox->ConstructL(popupList, CEikListBox::ELeftDownInViewRect);
       
  2563 //        listBox->ItemDrawer()->ColumnData()->EnableMarqueeL(ETrue);
       
  2564 //        listBox->CreateScrollBarFrameL(ETrue);
       
  2565 //        listBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
  2566 //        listBox->Model()->SetItemTextArray(entryLines);
       
  2567 //        listBox->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray);
       
  2568 //        listBox->HandleItemAdditionL();
       
  2569 //
       
  2570 //        popupList->SetTitleL(titleText);
       
  2571 //        popupList->ExecuteLD();
       
  2572 //
       
  2573 //        CleanupStack::Pop(); // popupList
       
  2574 //        CleanupStack::PopAndDestroy(); // listBox
       
  2575 //        }
       
  2576 //
       
  2577 //        CleanupStack::PopAndDestroy(); //entryLines
       
  2578 	}
       
  2579     
       
  2580 // --------------------------------------------------------------------------------------------
       
  2581 
       
  2582 void CFileBrowserFileUtils::OpenWithApparcL(TFileName aFileName)
       
  2583     {
       
  2584        
       
  2585         TFileName fullPath = aFileName;
       
  2586         TInt err1(KErrNone), err2(KErrNone);
       
  2587         TUid appUid;
       
  2588         TDataType dataType;
       
  2589         TBool isProgram;
       
  2590         
       
  2591 	
       
  2592         err1 = iEngine->LsSession().AppForDocument(fullPath, appUid, dataType);
       
  2593         err2 = iEngine->LsSession().IsProgram(fullPath, isProgram);
       
  2594         
       
  2595         if (err1 == KErrNone && err2 == KErrNone)
       
  2596             {
       
  2597             if (appUid != KNullUid)
       
  2598                 {
       
  2599                 // found an app, run using it
       
  2600                 TApaTaskList taskList(CEikonEnv::Static()->WsSession());
       
  2601                 TApaTask task = (taskList.FindApp(appUid));
       
  2602                 if (task.Exists())
       
  2603                     {
       
  2604                     User::LeaveIfError(task.SwitchOpenFile(fullPath));
       
  2605                     task.BringToForeground();
       
  2606                     }
       
  2607                 else
       
  2608                     {
       
  2609                     TThreadId id;
       
  2610                     iEngine->LsSession().StartDocument(fullPath, appUid, id, RApaLsSession::ESwitchFiles);
       
  2611                     }
       
  2612                 }
       
  2613             else if (isProgram)
       
  2614                 {
       
  2615                 LaunchProgramL(fullPath);
       
  2616                 }            
       
  2617             }
       
  2618         //}   
       
  2619     }
       
  2620 	
       
  2621 // --------------------------------------------------------------------------------------------
       
  2622 
       
  2623 //void CFileBrowserFileUtils::HandleServerAppExit(TInt aReason)
       
  2624 //	{
       
  2625 //	if (iOpenFileService)
       
  2626 //		{
       
  2627 //		delete iOpenFileService;
       
  2628 //		iOpenFileService = NULL;
       
  2629 //		}
       
  2630 //	MAknServerAppExitObserver::HandleServerAppExit(aReason);
       
  2631 //	}
       
  2632 
       
  2633 // --------------------------------------------------------------------------------------------
       
  2634 
       
  2635 void CFileBrowserFileUtils::OpenWithDocHandlerL(TFileName aFileName, TBool aEmbed)
       
  2636     {
       
  2637         TFileName fullPath = aFileName;
       
  2638         RFile sharableFile;
       
  2639         iDocHandler->OpenTempFileL(fullPath, sharableFile);
       
  2640         CleanupClosePushL(sharableFile);
       
  2641         TDataType dataType;
       
  2642         if (aEmbed) 
       
  2643             {
       
  2644     	    iDocHandler->OpenFileEmbeddedL(sharableFile, dataType);
       
  2645             }
       
  2646         else
       
  2647             {
       
  2648     	    iDocHandler->OpenFileL(sharableFile, dataType);
       
  2649             }
       
  2650         CleanupStack::PopAndDestroy();  //sharableFile
       
  2651     //    }   
       
  2652     }
       
  2653 
       
  2654 	// --------------------------------------------------------------------------------------------
       
  2655 
       
  2656 void CFileBrowserFileUtils::OpenWithFileServiceL(TInt aCurrentItemIndex)
       
  2657     {
       
  2658     if (iFileEntryList->Count() > aCurrentItemIndex && aCurrentItemIndex >= 0)
       
  2659         {
       
  2660         TFileEntry fileEntry = iFileEntryList->At(aCurrentItemIndex);
       
  2661         
       
  2662         TFileName fullPath = fileEntry.iPath;
       
  2663         fullPath.Append(fileEntry.iEntry.iName);
       
  2664 
       
  2665     	TBool itemSelected(EFalse);
       
  2666         RFile sharableFile;
       
  2667 //        TUid appUidExtracted;
       
  2668         
       
  2669         TRAPD(err,
       
  2670            
       
  2671         	// use doc handler to get a sharable file handle
       
  2672             iDocHandler->OpenTempFileL(fullPath, sharableFile);
       
  2673             CleanupClosePushL(sharableFile);
       
  2674             
       
  2675             // find the data type
       
  2676             TDataRecognitionResult dataType;
       
  2677         	User::LeaveIfError(iEngine->LsSession().RecognizeData(sharableFile, dataType));
       
  2678 
       
  2679         	// get all apps that support OpenFileService for this datatype
       
  2680         	CApaAppServiceInfoArray* apps = iEngine->LsSession().GetServiceImplementationsLC(KOpenServiceUid, dataType.iDataType);
       
  2681         	TArray<TApaAppServiceInfo> appServiceInfos = apps->Array();
       
  2682     	
       
  2683         	if (appServiceInfos.Count() > 0)
       
  2684         		{
       
  2685         		// build an array of the app names
       
  2686         		CDesCArray* names = new (ELeave) CDesCArrayFlat(16);
       
  2687         		CleanupStack::PushL(names);
       
  2688         		for (TInt ii=0; ii<appServiceInfos.Count(); ii++)
       
  2689         			{
       
  2690         			TUid appUid = appServiceInfos[ii].Uid();
       
  2691         			TApaAppInfo appInfo;
       
  2692         			if (iEngine->LsSession().GetAppInfo(appInfo, appUid) == KErrNone)
       
  2693         				{
       
  2694         				names->AppendL(appInfo.iCaption);
       
  2695         				}
       
  2696         			else
       
  2697         				{
       
  2698         				TBuf<10> buf;
       
  2699         				buf.Format(_L("0x%08x"), appUid);
       
  2700         				names->AppendL(buf);
       
  2701         				}
       
  2702         			}
       
  2703     		
       
  2704         		// use a list query to select the app
       
  2705 //        		TInt index(0);
       
  2706 //        		CAknListQueryDialog* dlg = new(ELeave) CAknListQueryDialog(&index);
       
  2707 //        		dlg->PrepareLC(R_APP_SELECTION_QUERY);
       
  2708 //        		dlg->SetItemTextArray(names);
       
  2709 //        		dlg->SetOwnershipType(ELbmDoesNotOwnItemArray);
       
  2710 //
       
  2711 //        		if(dlg->RunLD())
       
  2712 //        			{
       
  2713 //        			// extract the chosen UID
       
  2714 //        			appUidExtracted = appServiceInfos[index].Uid();
       
  2715 //        			itemSelected = ETrue;
       
  2716 //        			}
       
  2717     		
       
  2718         		CleanupStack::PopAndDestroy(); // names
       
  2719         		}
       
  2720 
       
  2721             if (itemSelected)
       
  2722                 {
       
  2723                 // start OpenFileService for the selected app
       
  2724                 CAiwGenericParamList& paramList = iDocHandler->InParamListL();
       
  2725                 
       
  2726 //                if (iOpenFileService)
       
  2727 //                    {
       
  2728 //                    delete iOpenFileService;
       
  2729 //                    iOpenFileService = NULL;
       
  2730 //                    }
       
  2731 
       
  2732 //                iOpenFileService = CAknOpenFileService::NewL(appUidExtracted, sharableFile, this, &paramList);
       
  2733                 }
       
  2734 
       
  2735             CleanupStack::PopAndDestroy(2); // sharableFile, apps
       
  2736 
       
  2737             ); // TRAPD
       
  2738 
       
  2739         if (err != KErrNone)
       
  2740             {
       
  2741             _LIT(KMessage, "No file service available for %S");
       
  2742             TFileName noteMsg;
       
  2743             noteMsg.Format(KMessage, &fileEntry.iEntry.iName);
       
  2744             
       
  2745             iEngine->FileBrowserUI()->ShowInformationNote(noteMsg, _L(""));
       
  2746             }
       
  2747         }   
       
  2748     }
       
  2749     
       
  2750 // --------------------------------------------------------------------------------------------
       
  2751 
       
  2752 TBool CFileBrowserFileUtils::FileExists(const TDesC& aPath)
       
  2753     {
       
  2754     return BaflUtils::FileExists(iFs, aPath);
       
  2755     }
       
  2756 
       
  2757 // --------------------------------------------------------------------------------------------
       
  2758 
       
  2759 TInt CFileBrowserFileUtils::LaunchProgramL(const TDesC& aPath)
       
  2760     {
       
  2761     CApaCommandLine* commandLine = CApaCommandLine::NewLC();
       
  2762     commandLine->SetExecutableNameL(aPath);
       
  2763     commandLine->SetCommandL(EApaCommandRun);
       
  2764     TInt err = iEngine->LsSession().StartApp(*commandLine);
       
  2765     CleanupStack::PopAndDestroy(); //commandLine
       
  2766     return err;
       
  2767     }
       
  2768 
       
  2769 // --------------------------------------------------------------------------------------------
       
  2770 
       
  2771 void CFileBrowserFileUtils::MemoryInfoPopupL()
       
  2772     {
       
  2773     _LIT(KUsedBytesEntry, "Used: %S bytes\n");
       
  2774     _LIT(KFreeBytesEntry, "Free: %S bytes\n");
       
  2775     _LIT(KSizeBytesEntry, "Size: %S bytes\n");
       
  2776         
       
  2777     HBufC* messageBuf = HBufC::NewLC(2048);
       
  2778     TPtr messagePtr = messageBuf->Des();
       
  2779     TBuf<128> entryLine;
       
  2780 
       
  2781     // RAM
       
  2782     TMemoryInfoV1Buf ramMemory;
       
  2783     UserHal::MemoryInfo(ramMemory);
       
  2784     messagePtr.Append(_L("RAM\n"));
       
  2785 
       
  2786     // used
       
  2787     TBuf<32> usedBuf;
       
  2788     usedBuf.AppendNum(ramMemory().iMaxFreeRamInBytes-ramMemory().iFreeRamInBytes, TRealFormat(KDefaultRealWidth, 0));
       
  2789     entryLine.Format(KUsedBytesEntry, &usedBuf);
       
  2790     messagePtr.Append(entryLine);        
       
  2791 
       
  2792     // free
       
  2793     TBuf<32> freeBuf;
       
  2794     freeBuf.AppendNum(ramMemory().iFreeRamInBytes, TRealFormat(KDefaultRealWidth, 0));
       
  2795     entryLine.Format(KFreeBytesEntry, &freeBuf);
       
  2796     messagePtr.Append(entryLine);
       
  2797             
       
  2798     // size
       
  2799     TBuf<32> sizeBuf;
       
  2800     sizeBuf.AppendNum(ramMemory().iMaxFreeRamInBytes, TRealFormat(KDefaultRealWidth, 0));
       
  2801     entryLine.Format(KSizeBytesEntry, &sizeBuf);
       
  2802     messagePtr.Append(entryLine); 
       
  2803     
       
  2804     // All drives
       
  2805     for (TInt i=0; i<iDriveEntryList->Count(); i++)
       
  2806         {
       
  2807         TDriveEntry driveEntry = iDriveEntryList->At(i);
       
  2808 
       
  2809         messagePtr.Append(_L("\n"));
       
  2810         messagePtr.Append(driveEntry.iLetter);
       
  2811         messagePtr.Append(_L(":\n"));
       
  2812 
       
  2813         // used
       
  2814         TBuf<32> usedBuf;
       
  2815         usedBuf.AppendNum(driveEntry.iVolumeInfo.iSize-driveEntry.iVolumeInfo.iFree, TRealFormat(KDefaultRealWidth, 0));
       
  2816         entryLine.Format(KUsedBytesEntry, &usedBuf);
       
  2817         messagePtr.Append(entryLine);        
       
  2818 
       
  2819         // free
       
  2820         TBuf<32> freeBuf;
       
  2821         freeBuf.AppendNum(driveEntry.iVolumeInfo.iFree, TRealFormat(KDefaultRealWidth, 0));
       
  2822         entryLine.Format(KFreeBytesEntry, &freeBuf);
       
  2823         messagePtr.Append(entryLine);
       
  2824                 
       
  2825         // size
       
  2826         TBuf<32> sizeBuf;
       
  2827         sizeBuf.AppendNum(driveEntry.iVolumeInfo.iSize, TRealFormat(KDefaultRealWidth, 0));
       
  2828         entryLine.Format(KSizeBytesEntry, &sizeBuf);
       
  2829         messagePtr.Append(entryLine); 
       
  2830         }
       
  2831 
       
  2832 //    CAknMessageQueryDialog* dialog = new(ELeave) CAknMessageQueryDialog;
       
  2833 //    dialog->PrepareLC(R_MEMORYINFO_DIALOG);
       
  2834 //    dialog->SetMessageTextL(messagePtr);
       
  2835 //    dialog->RunLD();
       
  2836     
       
  2837     CleanupStack::PopAndDestroy(); //messageBuf
       
  2838     }
       
  2839 
       
  2840 // --------------------------------------------------------------------------------------------
       
  2841 
       
  2842 void CFileBrowserFileUtils::ShowFileCheckSumsL(TInt aCurrentItemIndex, TInt aType)
       
  2843     {
       
  2844     if (iFileEntryList->Count() > aCurrentItemIndex && aCurrentItemIndex >= 0)
       
  2845         {
       
  2846         TFileEntry fileEntry = iFileEntryList->At(aCurrentItemIndex);
       
  2847         TFileName fullPath = fileEntry.iPath;
       
  2848         fullPath.Append(fileEntry.iEntry.iName);
       
  2849         
       
  2850         // try to open the file for reading
       
  2851         RFile fileP;
       
  2852         TInt err = fileP.Open(iEngine->EikonEnv()->FsSession(), fullPath, EFileRead|EFileShareReadersOnly);
       
  2853         
       
  2854         if (err == KErrNone)
       
  2855             {
       
  2856             CleanupClosePushL(fileP);
       
  2857 
       
  2858             TBuf<128> checkSum;
       
  2859             HBufC* messageBuf = HBufC::NewLC(2048);
       
  2860             TPtr messagePtr = messageBuf->Des();
       
  2861             
       
  2862             // get MD5 checksum
       
  2863             if (aType == EFileChecksumsMD5)
       
  2864                 {
       
  2865                 CMD5* md5 = CMD5::NewL();
       
  2866                 CleanupStack::PushL(md5);
       
  2867                 HBufC8* md5Buf = MessageDigestInHexLC(md5, fileP);
       
  2868                 checkSum.Copy(*md5Buf);
       
  2869                 messagePtr.Append(_L("MD5\n"));
       
  2870                 messagePtr.Append(checkSum);
       
  2871                 CleanupStack::PopAndDestroy(2); // md5, md5Buf
       
  2872                 }
       
  2873 
       
  2874             // get MD2 checksum
       
  2875             else if (aType == EFileChecksumsMD2)
       
  2876                 {                
       
  2877                 CMD2* md2 = CMD2::NewL();
       
  2878                 CleanupStack::PushL(md2);
       
  2879                 HBufC8* md2Buf = MessageDigestInHexLC(md2, fileP);
       
  2880                 checkSum.Copy(*md2Buf);
       
  2881                 messagePtr.Append(_L("MD2\n"));
       
  2882                 messagePtr.Append(checkSum);
       
  2883                 CleanupStack::PopAndDestroy(2); // md2, md2Buf
       
  2884                 }
       
  2885 
       
  2886             // get SHA-1 checksum
       
  2887             else if (aType == EFileChecksumsSHA1)
       
  2888                 {
       
  2889                 CSHA1* sha1 = CSHA1::NewL();
       
  2890                 CleanupStack::PushL(sha1);
       
  2891                 HBufC8* sha1Buf = MessageDigestInHexLC(sha1, fileP);
       
  2892                 checkSum.Copy(*sha1Buf);
       
  2893                 messagePtr.Append(_L("SHA-1\n"));
       
  2894                 messagePtr.Append(checkSum);
       
  2895                 CleanupStack::PopAndDestroy(2); // sha1, sha1Buf
       
  2896                 }
       
  2897             
       
  2898             else
       
  2899                 {
       
  2900                 User::Panic(_L("Inv.CS.Type"), 723);
       
  2901                 }
       
  2902                             
       
  2903             // show dialog
       
  2904             iEngine->FileBrowserUI()->ShowInformationNote(messagePtr, fileEntry.iEntry.iName);
       
  2905 
       
  2906             CleanupStack::PopAndDestroy(2); // messageBuf, fileP
       
  2907             }
       
  2908         else
       
  2909             {
       
  2910             // open failed, show an error note
       
  2911             CTextResolver* textResolver = CTextResolver::NewLC(*iEngine->EikonEnv());
       
  2912 
       
  2913             iEngine->FileBrowserUI()->ShowErrorNote(
       
  2914                     textResolver->ResolveErrorString(err, CTextResolver::ECtxNoCtxNoSeparator) );
       
  2915 
       
  2916             CleanupStack::PopAndDestroy();  //textResolver
       
  2917             }
       
  2918         }
       
  2919     }
       
  2920 
       
  2921 // --------------------------------------------------------------------------------------------
       
  2922 
       
  2923 HBufC8* CFileBrowserFileUtils::MessageDigestInHexLC(CMessageDigest* aMD, RFile& aFile)
       
  2924     {
       
  2925     // seek to file start
       
  2926     TInt startPos(0);
       
  2927     aFile.Seek(ESeekStart, startPos);
       
  2928 
       
  2929     // create result buffer
       
  2930     HBufC8* result = HBufC8::NewLC(128);
       
  2931 
       
  2932     const TInt KBufSize(1024);
       
  2933     TInt fileSize(0);
       
  2934     TInt fileOffset(0);
       
  2935 
       
  2936     // get file size
       
  2937     aFile.Size(fileSize);
       
  2938 
       
  2939     HBufC8* buf = HBufC8::NewMaxLC(KBufSize);
       
  2940     TPtr8 bufPtr(buf->Des());
       
  2941 
       
  2942     // read to buffer
       
  2943     while (fileOffset < fileSize - KBufSize)
       
  2944         {
       
  2945         aFile.Read(bufPtr, KBufSize);
       
  2946         aMD->Hash(bufPtr);
       
  2947         fileOffset += bufPtr.Length();
       
  2948         }
       
  2949 
       
  2950     aFile.Read(bufPtr, fileSize - fileOffset);
       
  2951     bufPtr.SetLength(fileSize - fileOffset);
       
  2952     
       
  2953     // get final message digest
       
  2954     TPtrC8 hashedSig(aMD->Final(bufPtr));
       
  2955     
       
  2956     // change size of the result buffer
       
  2957     result->ReAllocL(hashedSig.Length() * 2);
       
  2958     TPtr8 resultPtr = result->Des();
       
  2959 
       
  2960     // convert to hex format
       
  2961     for (TInt i=0; i<hashedSig.Length(); i++)
       
  2962         {
       
  2963         resultPtr.AppendFormat(_L8("%+02x"), hashedSig[i]);
       
  2964         }
       
  2965                     
       
  2966     CleanupStack::PopAndDestroy(); // buf
       
  2967     
       
  2968     return result;
       
  2969     }
       
  2970         
       
  2971 // --------------------------------------------------------------------------------------------
       
  2972 
       
  2973 void CFileBrowserFileUtils::SetErrRdL(TBool aEnable)
       
  2974     {
       
  2975     #ifndef FILEBROWSER_LITE
       
  2976     if (iEngine->Settings().iBypassPlatformSecurity)
       
  2977         {
       
  2978         TInt err(KErrNone);
       
  2979         
       
  2980         if (aEnable)
       
  2981             {
       
  2982             // make sure that the directory exists
       
  2983             iFileOps->MkDirAll(KErrRdPath);        
       
  2984 
       
  2985             // create the file
       
  2986             err = iFileOps->CreateEmptyFile(KErrRdPath);
       
  2987             }
       
  2988         else    
       
  2989             {
       
  2990             // get TEntry of ErrRd
       
  2991             TEntry entry;
       
  2992             err = iFs.Entry(KErrRdPath, entry);
       
  2993             
       
  2994             if (err == KErrNone)
       
  2995                 {
       
  2996                 TFileEntry fileEntry;
       
  2997                 fileEntry.iPath = KErrRdDir;
       
  2998                 fileEntry.iEntry = entry;
       
  2999                 
       
  3000                 err = iFileOps->Delete(fileEntry);                
       
  3001                 }
       
  3002             }        
       
  3003 
       
  3004         // update view
       
  3005         RefreshViewL(); 
       
  3006     
       
  3007         if (err == KErrNone)
       
  3008             {
       
  3009             iEngine->FileBrowserUI()->ShowConfirmationNote(_L("State changed"));
       
  3010             }
       
  3011         else    
       
  3012             {
       
  3013             iEngine->FileBrowserUI()->ShowErrorNote(_L("Cannot change the state"));
       
  3014             }        
       
  3015         }
       
  3016     else
       
  3017         {
       
  3018         iEngine->FileBrowserUI()->ShowInformationNote(_L("Enable \"bypass platform security\" from the settings first"), _L(""));
       
  3019         }
       
  3020     #else
       
  3021         aEnable = aEnable;
       
  3022         iEngine->FileBrowserUI()->ShowInformationNote(_L("Not supported in lite version"), _L(""));
       
  3023     #endif
       
  3024     }
       
  3025 
       
  3026 // --------------------------------------------------------------------------------------------
       
  3027 
       
  3028 //void CFileBrowserFileUtils::EnableAvkonIconCacheL(TBool aEnable)
       
  3029 //    {
       
  3030 //#ifndef __SERIES60_30__
       
  3031 //    if (AknIconConfig::EnableAknIconSrvCache(aEnable) == KErrNone)
       
  3032 //        {
       
  3033 //        iEngine->FileBrowserUI()->ShowConfirmationNote(_L("State changed"));
       
  3034 //        }
       
  3035 //    else
       
  3036 //        {
       
  3037 //        iEngine->FileBrowserUI()->ShowErrorNote(_L("Unknown error occured"));
       
  3038 //        }
       
  3039 // #else
       
  3040 //    aEnable = aEnable;
       
  3041 //    iEngine->FileBrowserUI()->ShowInformationNote(_L("Not supported in S60 3.0"), _L(""));
       
  3042 // #endif
       
  3043 // 
       
  3044 //    }
       
  3045 
       
  3046 // --------------------------------------------------------------------------------------------
       
  3047 
       
  3048 void CFileBrowserFileUtils::SimulateLeaveL(TInt aLeaveCode)
       
  3049     {
       
  3050     User::Leave(aLeaveCode);
       
  3051     }
       
  3052 
       
  3053 // --------------------------------------------------------------------------------------------
       
  3054 
       
  3055 void CFileBrowserFileUtils::SimulatePanicL(const TDesC& aPanicCategory, TInt aPanicCode)
       
  3056     {
       
  3057     User::Panic(aPanicCategory, aPanicCode);
       
  3058     }
       
  3059 
       
  3060 // --------------------------------------------------------------------------------------------
       
  3061 
       
  3062 void CFileBrowserFileUtils::SimulateExceptionL(TInt aExceptionCode)
       
  3063     {
       
  3064     User::RaiseException((TExcType)aExceptionCode);
       
  3065     }
       
  3066 
       
  3067 // --------------------------------------------------------------------------------------------
       
  3068 
       
  3069 TUint32 CFileBrowserFileUtils::GetDebugMask()
       
  3070     {
       
  3071     return UserSvr::DebugMask();
       
  3072     }
       
  3073 
       
  3074 // --------------------------------------------------------------------------------------------
       
  3075 
       
  3076 void CFileBrowserFileUtils::SetDebugMaskL(TUint32 aDbgMask)
       
  3077     {
       
  3078     User::SetDebugMask(aDbgMask);
       
  3079     }
       
  3080     
       
  3081 // --------------------------------------------------------------------------------------------
       
  3082 
       
  3083 void CFileBrowserFileUtils::WriteAllAppsL()
       
  3084     {
       
  3085     _LIT(KAllAppsFileName, "AllApps.txt");
       
  3086     TFileName allAppsPath = PathInfo::PhoneMemoryRootPath();
       
  3087     allAppsPath.Append(KAllAppsFileName);
       
  3088 
       
  3089     RFile file;
       
  3090     if (file.Replace(iFs, allAppsPath, EFileWrite) == KErrNone)
       
  3091         {
       
  3092         CleanupClosePushL(file);
       
  3093         
       
  3094         CDesC8Array* appsArray = new(ELeave) CDesC8ArrayFlat(192);
       
  3095         CleanupStack::PushL(appsArray);
       
  3096         
       
  3097         TBuf8<KMaxFileName> fileEntry;
       
  3098         TBuf8<KMaxFileName> appFullPath;
       
  3099         _LIT8(KAppEntryFormat, "%S (0x%08X)%S");
       
  3100         TApaAppInfo appInfo;
       
  3101 
       
  3102         iEngine->LsSession().GetAllApps();        
       
  3103 
       
  3104         while (iEngine->LsSession().GetNextApp(appInfo) == KErrNone)
       
  3105             {
       
  3106             appFullPath.Copy(appInfo.iFullName);
       
  3107             fileEntry.Format(KAppEntryFormat, &appFullPath, appInfo.iUid, &KFileNewLine);
       
  3108             appsArray->AppendL(fileEntry);    
       
  3109             }
       
  3110         
       
  3111         appsArray->Sort();
       
  3112         
       
  3113         for (TInt i=0; i<appsArray->Count(); i++)
       
  3114             {
       
  3115             file.Write(appsArray->MdcaPoint(i));
       
  3116             }
       
  3117         
       
  3118         CleanupStack::PopAndDestroy(2); //appsArray, file
       
  3119         
       
  3120         _LIT(KMessage, "App list written to %S");
       
  3121         TFileName noteMsg;
       
  3122         noteMsg.Format(KMessage, &allAppsPath);
       
  3123 
       
  3124         iEngine->FileBrowserUI()->ShowConfirmationNote(noteMsg, ETrue); // NoTimeout
       
  3125         }
       
  3126     else
       
  3127         {
       
  3128         _LIT(KMessage, "Failed writing to %S");
       
  3129         TFileName noteMsg;
       
  3130         noteMsg.Format(KMessage, &allAppsPath);
       
  3131 
       
  3132         iEngine->FileBrowserUI()->ShowErrorNote(noteMsg, ETrue); // NoTimeout
       
  3133         }    
       
  3134     }
       
  3135 
       
  3136 // --------------------------------------------------------------------------------------------
       
  3137 
       
  3138 void CFileBrowserFileUtils::WriteAllFilesL()
       
  3139     {
       
  3140     _LIT(KAllFilesFileName, "AllFiles.txt");
       
  3141     TFileName allFilesPath = PathInfo::PhoneMemoryRootPath();
       
  3142     allFilesPath.Append(KAllFilesFileName);
       
  3143 
       
  3144     RFile file;
       
  3145     if (file.Replace(iFs, allFilesPath, EFileWrite) == KErrNone)
       
  3146         {
       
  3147         CleanupClosePushL(file);
       
  3148         iFindFileEntryList->Reset();
       
  3149         
       
  3150         iEngine->FileBrowserUI()->ShowWaitDialog(_L("Generating"));
       
  3151         
       
  3152         for (TInt i=0; i<iDriveEntryList->Count(); i++)
       
  3153             {
       
  3154             TDriveEntry driveEntry = iDriveEntryList->At(i);
       
  3155 
       
  3156             TBuf<10> driveRoot;
       
  3157             driveRoot.Append(driveEntry.iLetter);
       
  3158             driveRoot.Append(_L(":\\"));
       
  3159 
       
  3160             // current dir
       
  3161             DoFindFiles(_L("*"), driveRoot);
       
  3162             
       
  3163             // recurse into sub directories
       
  3164             DoFindFilesRecursiveL(_L("*"), driveRoot);
       
  3165             }
       
  3166         
       
  3167         // write entries
       
  3168         TBuf8<KMaxFileName> writeBuf;
       
  3169         for (TInt i=0; i<iFindFileEntryList->Count(); i++)
       
  3170             {
       
  3171             TFileEntry fileEntry = iFindFileEntryList->At(i);
       
  3172             
       
  3173             writeBuf.Copy(fileEntry.iPath);
       
  3174             writeBuf.Append(fileEntry.iEntry.iName);
       
  3175             writeBuf.Append(_L(","));
       
  3176             writeBuf.AppendNum(fileEntry.iEntry.iSize);
       
  3177             writeBuf.Append(_L(" B"));
       
  3178 
       
  3179 //            // date
       
  3180 //            TTime entryModified = fileEntry.iEntry.iModified;
       
  3181 //            // convert from universal time
       
  3182 //            if ( iTz.ConvertToLocalTime( entryModified ) == KErrNone )
       
  3183 //                {
       
  3184 //                entryModified = fileEntry.iEntry.iModified; // use universal time
       
  3185 //                }
       
  3186 //
       
  3187 //            _LIT(KDateFormat,               "%D%M%Y%/0%1%/1%2%/2%3%/3");
       
  3188 //            TBuf<32> dateBuf;
       
  3189 //            entryModified.FormatL(dateBuf, KDateFormat);
       
  3190 //            writeBuf.Append(dateBuf);
       
  3191 //
       
  3192 //            writeBuf.Append(_L(" "));
       
  3193 //            // time
       
  3194 //            _LIT(KTimeFormat, "%-B%:0%J%:1%T%:2%S%:3%+B");
       
  3195 //            TBuf<32> timeBuf;
       
  3196 //            entryModified.FormatL(timeBuf, KTimeFormat);
       
  3197 //            writeBuf.Append(timeBuf);
       
  3198 //
       
  3199             writeBuf.Append(KFileNewLine);
       
  3200             file.Write(writeBuf);
       
  3201             }
       
  3202         
       
  3203         iEngine->FileBrowserUI()->CancelWaitDialog();
       
  3204         
       
  3205         CleanupStack::PopAndDestroy(); //file
       
  3206         iFindFileEntryList->Reset();
       
  3207         
       
  3208         _LIT(KMessage, "File list written to %S");
       
  3209         TFileName noteMsg;
       
  3210         noteMsg.Format(KMessage, &allFilesPath);
       
  3211 
       
  3212         iEngine->FileBrowserUI()->ShowConfirmationNote(noteMsg, EFalse); // NoTimeout
       
  3213         }
       
  3214     else
       
  3215         {
       
  3216         _LIT(KMessage, "Failed writing to %S");
       
  3217         TFileName noteMsg;
       
  3218         noteMsg.Format(KMessage, &allFilesPath);
       
  3219 
       
  3220         iEngine->FileBrowserUI()->ShowErrorNote(noteMsg, ETrue); // NoTimeout
       
  3221         }    
       
  3222     }
       
  3223 
       
  3224 // --------------------------------------------------------------------------------------------
       
  3225 
       
  3226 TInt CFileBrowserFileUtils::DoFindFiles(const TDesC& aFileName, const TDesC& aPath)
       
  3227     {
       
  3228     TFindFile fileFinder(iFs);
       
  3229     CDir* dir;
       
  3230     TInt err = fileFinder.FindWildByPath(aFileName, &aPath, dir);
       
  3231 
       
  3232     while (err == KErrNone && iAllowProcessing)
       
  3233         {
       
  3234         iEngine->FileBrowserUI()->ProcessEvents();
       
  3235         for (TInt i=0; i<dir->Count(); i++)
       
  3236             {
       
  3237             TEntry entry = (*dir)[i];
       
  3238 
       
  3239             // ignore any directory entries
       
  3240             if (!entry.IsDir() && entry.iName.Length() && aPath.Length())
       
  3241                 {
       
  3242                 TParse parsedName;
       
  3243                 parsedName.Set(entry.iName, &fileFinder.File(), NULL);
       
  3244                 
       
  3245                 if (parsedName.Drive().Length() && aPath.Length() && parsedName.Drive()[0] == aPath[0])
       
  3246                     {
       
  3247                     TFileEntry fileEntry;
       
  3248                     fileEntry.iPath = parsedName.DriveAndPath();
       
  3249                     fileEntry.iEntry = entry;
       
  3250                     fileEntry.iDirEntries = KErrNotFound;
       
  3251                     fileEntry.iIconId = EFixedIconEmpty;
       
  3252                     
       
  3253                     TRAP(err, iFindFileEntryList->AppendL(fileEntry));             
       
  3254                     }
       
  3255                 }
       
  3256             }
       
  3257 
       
  3258         delete dir;
       
  3259         dir = NULL;
       
  3260         err = fileFinder.FindWild(dir);
       
  3261         }
       
  3262 
       
  3263     return err;
       
  3264     }
       
  3265 
       
  3266 // --------------------------------------------------------------------------------------------
       
  3267 
       
  3268 TInt CFileBrowserFileUtils::DoFindFilesRecursiveL(const TDesC& aFileName, const TDesC& aPath)
       
  3269 	{
       
  3270     TInt err(KErrNone);
       
  3271     CDirScan* scan = CDirScan::NewLC(iFs);
       
  3272     scan->SetScanDataL(aPath, KEntryAttDir|KEntryAttMatchMask, ESortByName | EAscending | EDirsFirst);
       
  3273     CDir* dir = NULL;
       
  3274 
       
  3275     for(;;)
       
  3276         {
       
  3277         TRAP(err, scan->NextL(dir));
       
  3278         if (!dir  || (err != KErrNone))
       
  3279             break;
       
  3280 
       
  3281         for (TInt i=0; i<dir->Count(); i++)
       
  3282             {
       
  3283             TEntry entry = (*dir)[i];
       
  3284             
       
  3285             if (entry.IsDir())
       
  3286                 {
       
  3287                 TFileName path(scan->FullPath());
       
  3288                 
       
  3289                 if (path.Length())
       
  3290                     {
       
  3291                     path.Append(entry.iName);
       
  3292                     path.Append(_L("\\"));
       
  3293                     DoFindFiles(aFileName, path);
       
  3294                     }
       
  3295                 }
       
  3296             }
       
  3297         delete(dir);
       
  3298         }
       
  3299 
       
  3300     CleanupStack::PopAndDestroy(scan);
       
  3301     return err;
       
  3302     }
       
  3303 
       
  3304 // --------------------------------------------------------------------------------------------
       
  3305 
       
  3306 void CFileBrowserFileUtils::ListOpenFilesL()
       
  3307     {
       
  3308     iFileEntryList->Reset();
       
  3309 
       
  3310     CFileList* dir = NULL;
       
  3311     TOpenFileScan fileScan(iFs);
       
  3312     fileScan.NextL(dir);
       
  3313     
       
  3314     while (dir)
       
  3315         {
       
  3316         for (TInt i=0; i<dir->Count(); i++)
       
  3317             {
       
  3318             TEntry entry = (*dir)[i];
       
  3319             TFileName fullPath;
       
  3320 
       
  3321             // TOpenFileScan does not return drive letters for the entries, so try to guess it
       
  3322             if (entry.iName.Length() > 2 && entry.iName[1] != ':')
       
  3323                 {
       
  3324                 for (TInt i=0; i<iDriveEntryList->Count(); i++)
       
  3325                     {
       
  3326                     TDriveEntry driveEntry = iDriveEntryList->At(i);
       
  3327                     
       
  3328                     TFileName guessPath;
       
  3329                     guessPath.Append(driveEntry.iLetter);
       
  3330                     guessPath.Append(_L(":"));
       
  3331                     guessPath.Append(entry.iName);
       
  3332                     
       
  3333                     // check if the file exists
       
  3334                     if (BaflUtils::FileExists(iFs, guessPath))
       
  3335                         {
       
  3336                         // if it's on read only drive, then take it or check if it's really in use
       
  3337                         TBool readOnlyDrive(ETrue);
       
  3338                         BaflUtils::DiskIsReadOnly(iFs, guessPath, readOnlyDrive);
       
  3339                         
       
  3340                         if (readOnlyDrive || iFs.SetEntry(guessPath, entry.iModified, NULL, NULL) == KErrInUse)
       
  3341                             {
       
  3342                             fullPath = guessPath;
       
  3343                             break;
       
  3344                             }
       
  3345                         }
       
  3346                     }
       
  3347                 }
       
  3348             else
       
  3349                 {
       
  3350                 fullPath = entry.iName;   
       
  3351                 }
       
  3352 
       
  3353             TParse nameParser;
       
  3354             if (fullPath.Length() && nameParser.SetNoWild(fullPath, NULL, NULL) == KErrNone)
       
  3355                 {
       
  3356                 entry.iName = nameParser.NameAndExt();
       
  3357                 
       
  3358                 TFileEntry fileEntry;
       
  3359                 fileEntry.iPath = nameParser.DriveAndPath();
       
  3360                 fileEntry.iEntry = entry;
       
  3361                 fileEntry.iDirEntries = KErrNotFound;
       
  3362                 fileEntry.iIconId = EFixedIconEmpty;
       
  3363                 
       
  3364                 iFileEntryList->AppendL(fileEntry);                
       
  3365                 }
       
  3366             }
       
  3367             
       
  3368         delete dir;
       
  3369         dir = NULL;
       
  3370         fileScan.NextL(dir);
       
  3371         }
       
  3372 
       
  3373     TInt operations = iFileEntryList->Count();
       
  3374     
       
  3375     iListingMode = EOpenFiles;
       
  3376 	// TODO
       
  3377     //iEngine->FileListContainer()->ListBox()->SetCurrentItemIndex(0);
       
  3378     RefreshViewL();            
       
  3379 
       
  3380     _LIT(KMessage, "%d open files found");
       
  3381     TFileName noteMsg;
       
  3382     noteMsg.Format(KMessage, operations);
       
  3383 
       
  3384     iEngine->FileBrowserUI()->ShowInformationNote(noteMsg, _L(""));
       
  3385     }
       
  3386 
       
  3387 // --------------------------------------------------------------------------------------------
       
  3388 
       
  3389 void CFileBrowserFileUtils::ListMessageAttachmentsL(TInt aType)
       
  3390     {
       
  3391     iFileEntryList->Reset();
       
  3392 
       
  3393     CMsvSession* session = CMsvSession::OpenSyncL(*this);
       
  3394     CleanupStack::PushL(session);
       
  3395     
       
  3396     CMsvEntry* context = NULL;
       
  3397     
       
  3398     if (aType == EFileBrowserCmdToolsMsgAttachmentsInbox)
       
  3399         context = session->GetEntryL(KMsvGlobalInBoxIndexEntryId);
       
  3400     else if (aType == EFileBrowserCmdToolsMsgAttachmentsDrafts)
       
  3401         context = session->GetEntryL(KMsvDraftEntryId);
       
  3402     else if (aType == EFileBrowserCmdToolsMsgAttachmentsSentItems)
       
  3403         context = session->GetEntryL(KMsvSentEntryId);
       
  3404     else if (aType == EFileBrowserCmdToolsMsgAttachmentsOutbox)
       
  3405         context = session->GetEntryL(KMsvGlobalOutBoxIndexEntryId);
       
  3406     else
       
  3407         User::Panic(_L("MsgAtt.Mode"), 100);
       
  3408     
       
  3409     CleanupStack::PushL(context);
       
  3410     
       
  3411     CDesCArray* attPaths = new(ELeave) CDesCArrayFlat(128);
       
  3412     CleanupStack::PushL(attPaths);
       
  3413     
       
  3414     // read attachment paths
       
  3415     ReadAttachmentPathsRecursiveL(session, context, attPaths);
       
  3416     
       
  3417     // create file entries of the paths
       
  3418     for (TInt i=0; i<attPaths->MdcaCount(); i++)
       
  3419         {
       
  3420         TFileEntry fileEntry;
       
  3421         TEntry entry;
       
  3422         TParse nameParser;
       
  3423         
       
  3424         if (attPaths->MdcaPoint(i).Length() &&
       
  3425             nameParser.SetNoWild(attPaths->MdcaPoint(i), NULL, NULL) == KErrNone &&
       
  3426             iFs.Entry(attPaths->MdcaPoint(i), entry) == KErrNone)
       
  3427             {
       
  3428             TFileEntry fileEntry;
       
  3429             fileEntry.iPath = nameParser.DriveAndPath();
       
  3430             fileEntry.iEntry = entry;
       
  3431             fileEntry.iDirEntries = KErrNotFound;
       
  3432             fileEntry.iIconId = EFixedIconEmpty;
       
  3433 
       
  3434             iFileEntryList->AppendL(fileEntry);                
       
  3435             }
       
  3436         }
       
  3437     
       
  3438     CleanupStack::PopAndDestroy(3); //session, context, attPaths
       
  3439             
       
  3440     TInt operations = iFileEntryList->Count();
       
  3441     
       
  3442     if (aType == EFileBrowserCmdToolsMsgAttachmentsInbox)
       
  3443         iListingMode = EMsgAttachmentsInbox;
       
  3444     else if (aType == EFileBrowserCmdToolsMsgAttachmentsDrafts)
       
  3445         iListingMode = EMsgAttachmentsDrafts;
       
  3446     else if (aType == EFileBrowserCmdToolsMsgAttachmentsSentItems)
       
  3447         iListingMode = EMsgAttachmentsSentItems;
       
  3448     else if (aType == EFileBrowserCmdToolsMsgAttachmentsOutbox)
       
  3449         iListingMode = EMsgAttachmentsOutbox;
       
  3450 	
       
  3451     // TODO
       
  3452     //iEngine->FileListContainer()->ListBox()->SetCurrentItemIndex(0);
       
  3453     RefreshViewL();            
       
  3454 
       
  3455     _LIT(KMessage, "%d files found");
       
  3456     TFileName noteMsg;
       
  3457     noteMsg.Format(KMessage, operations);
       
  3458 
       
  3459     iEngine->FileBrowserUI()->ShowInformationNote(noteMsg, _L(""));
       
  3460     }
       
  3461 
       
  3462 // --------------------------------------------------------------------------------------------
       
  3463 
       
  3464 void CFileBrowserFileUtils::ReadAttachmentPathsRecursiveL(CMsvSession* aSession, CMsvEntry* aContext, CDesCArray* aAttPaths)
       
  3465     {
       
  3466     CMsvEntrySelection* entrySelection = aContext->ChildrenL(); 
       
  3467     CleanupStack::PushL(entrySelection);
       
  3468     
       
  3469     for (TInt i=0; i<entrySelection->Count(); i++)
       
  3470         {
       
  3471         CMsvEntry* entry = aSession->GetEntryL((*entrySelection)[i]);
       
  3472         CleanupStack::PushL(entry);
       
  3473         
       
  3474         CMsvStore* store = NULL;
       
  3475         TRAPD(err, store = entry->ReadStoreL());
       
  3476         
       
  3477         if (err == KErrNone)
       
  3478             {
       
  3479             CleanupStack::PushL(store);
       
  3480 
       
  3481             for (TInt j=0; j<store->AttachmentManagerL().AttachmentCount(); j++)
       
  3482                 {
       
  3483                 CMsvAttachment* attachment = store->AttachmentManagerL().GetAttachmentInfoL(j);
       
  3484                 CleanupStack::PushL(attachment);
       
  3485                 
       
  3486                 aAttPaths->AppendL(attachment->FilePath());
       
  3487                 
       
  3488                 CleanupStack::PopAndDestroy(); //attachment
       
  3489                 }
       
  3490             CleanupStack::PopAndDestroy(); // store
       
  3491             }
       
  3492 
       
  3493         // recurse into children
       
  3494         if (entry->Count() > 0)
       
  3495             {
       
  3496             ReadAttachmentPathsRecursiveL(aSession, entry, aAttPaths);
       
  3497             }
       
  3498 
       
  3499         CleanupStack::PopAndDestroy(); // entry
       
  3500         }      
       
  3501     }
       
  3502 
       
  3503 // --------------------------------------------------------------------------------------------
       
  3504 
       
  3505 void CFileBrowserFileUtils::WriteMsgStoreWalkL()
       
  3506     {
       
  3507     _LIT(KAllAppsFileName, "MsgStoreWalk.txt");
       
  3508     TFileName allAppsPath = PathInfo::PhoneMemoryRootPath();
       
  3509     allAppsPath.Append(KAllAppsFileName);
       
  3510 
       
  3511     if (iMsgStoreWalkFile.Replace(iFs, allAppsPath, EFileWrite) == KErrNone)
       
  3512         {
       
  3513         CMsvSession* session = CMsvSession::OpenSyncL(*this);
       
  3514         CleanupStack::PushL(session);
       
  3515         
       
  3516         CMsvEntry* context = session->GetEntryL(KMsvRootIndexEntryId);
       
  3517         CleanupStack::PushL(context);
       
  3518         
       
  3519         iMsgStoreWalkFile.Write(_L8("id  service_id  related_id  type  mtm  date  size  error  biotype  mtmdata1  mtmdata2  mtmdata3  description  details\r\n\r\n"));
       
  3520         
       
  3521         // write details about the root entry
       
  3522         DoWriteMessageEntryInfoL(context, iMsgStoreWalkFile, 0);
       
  3523         
       
  3524         // get and write info recursively
       
  3525         TInt level(1);        
       
  3526         WriteMessageEntryInfoRecursiveL(session, context, iMsgStoreWalkFile, level);
       
  3527 
       
  3528         CleanupStack::PopAndDestroy(2); //session, context
       
  3529         
       
  3530         iMsgStoreWalkFile.Flush();
       
  3531         iMsgStoreWalkFile.Close();
       
  3532         
       
  3533         _LIT(KMessage, "Msg. store walk written to %S");
       
  3534         TFileName noteMsg;
       
  3535         noteMsg.Format(KMessage, &allAppsPath);
       
  3536 
       
  3537         iEngine->FileBrowserUI()->ShowConfirmationNote(noteMsg, ETrue); // NoTimeout
       
  3538         }
       
  3539     else
       
  3540         {
       
  3541         _LIT(KMessage, "Failed writing to %S");
       
  3542         TFileName noteMsg;
       
  3543         noteMsg.Format(KMessage, &allAppsPath);
       
  3544 
       
  3545         iEngine->FileBrowserUI()->ShowErrorNote(noteMsg, ETrue); // NoTimeout
       
  3546         }    
       
  3547     }
       
  3548 
       
  3549 // --------------------------------------------------------------------------------------------
       
  3550 
       
  3551 void CFileBrowserFileUtils::WriteMessageEntryInfoRecursiveL(CMsvSession* aSession, CMsvEntry* aContext, RFile& aFile, TInt& aLevel)
       
  3552     {
       
  3553     CMsvEntrySelection* entrySelection = aContext->ChildrenL(); 
       
  3554     CleanupStack::PushL(entrySelection);
       
  3555     
       
  3556     for (TInt i=0; i<entrySelection->Count(); i++)
       
  3557         {
       
  3558         CMsvEntry* entry = aSession->GetEntryL((*entrySelection)[i]);
       
  3559         CleanupStack::PushL(entry);
       
  3560         
       
  3561         DoWriteMessageEntryInfoL(entry, aFile, aLevel);
       
  3562 
       
  3563         // recurse into children
       
  3564         if (entry->Count() > 0)
       
  3565             {
       
  3566             aLevel++;
       
  3567             WriteMessageEntryInfoRecursiveL(aSession, entry, aFile, aLevel);
       
  3568             aLevel--;
       
  3569             }
       
  3570 
       
  3571         CleanupStack::PopAndDestroy(); // entry
       
  3572         }      
       
  3573     }
       
  3574 
       
  3575 // --------------------------------------------------------------------------------------------
       
  3576 
       
  3577 void CFileBrowserFileUtils::DoWriteMessageEntryInfoL(CMsvEntry* aContext, RFile& aFile, TInt aLevel)
       
  3578     {
       
  3579     TMsvEntry messageEntry = aContext->Entry();
       
  3580     
       
  3581     for (TInt j=0; j<aLevel; j++)
       
  3582         {
       
  3583         aFile.Write(_L8("     "));
       
  3584         }
       
  3585 
       
  3586     TBuf8<256> desc;
       
  3587     desc.Copy(messageEntry.iDescription);
       
  3588 
       
  3589     TBuf8<256> details;
       
  3590     details.Copy(messageEntry.iDetails);
       
  3591 
       
  3592     _LIT8(KLine, "-> %d  %d  %d  %d  %d  %Ld  %d  %d  %d  %d  %d  %d  %S  %S\r\n");
       
  3593     TBuf8<1024> buf;
       
  3594     buf.Format(KLine, messageEntry.Id(), messageEntry.iServiceId, messageEntry.iRelatedId, messageEntry.iType.iUid,
       
  3595         messageEntry.iMtm.iUid, messageEntry.iDate.Int64(), messageEntry.iSize, messageEntry.iError, messageEntry.iBioType,
       
  3596         messageEntry.iMtmData1, messageEntry.iMtmData2, messageEntry.iMtmData3, &desc, &details);
       
  3597 
       
  3598     aFile.Write(buf);
       
  3599     }
       
  3600 
       
  3601 // --------------------------------------------------------------------------------------------
       
  3602 
       
  3603 void CFileBrowserFileUtils::HandleSessionEventL(TMsvSessionEvent /*aEvent*/, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/)
       
  3604     {
       
  3605     }
       
  3606 
       
  3607 // --------------------------------------------------------------------------------------------
       
  3608 
       
  3609 void CFileBrowserFileUtils::FileEditorL(TInt aCurrentItemIndex, TInt /*aType*/)
       
  3610     {
       
  3611     // TODO
       
  3612     // just get current item 
       
  3613     //TInt currentItemIndex = iEngine->QueryCurrentItemIndex();
       
  3614     
       
  3615     if (iFileEntryList->Count() > aCurrentItemIndex && aCurrentItemIndex >= 0)
       
  3616         {
       
  3617         TFileEntry fileEntry = iFileEntryList->At(aCurrentItemIndex);
       
  3618         
       
  3619         // only valid for files
       
  3620         if (!fileEntry.iEntry.IsDir())
       
  3621             {
       
  3622             TFileName fullPath = fileEntry.iPath;
       
  3623             fullPath.Append(fileEntry.iEntry.iName);
       
  3624 
       
  3625 //            iEngine->FileListContainer()->SetNaviPaneTextL(fileEntry.iEntry.iName);
       
  3626 //
       
  3627 //            TInt editorMode(0);
       
  3628 //
       
  3629 //            if (aType == EFileBrowserCmdFileViewText)
       
  3630 //                editorMode = EFileEditorViewAsText;
       
  3631 //            else if (aType == EFileBrowserCmdFileViewHex)
       
  3632 //                editorMode = EFileEditorViewAsHex;
       
  3633 //            else if (aType == EFileBrowserCmdFileEditText)
       
  3634 //                editorMode = EFileEditorEditAsText;
       
  3635 //            else if (aType == EFileBrowserCmdFileEditHex)
       
  3636 //                editorMode = EFileEditorEditAsHex;
       
  3637 //            else
       
  3638 //                User::Panic(_L("Inv.Ed.Mode"), 843);
       
  3639 //
       
  3640 //            // launch dialog
       
  3641 //            CFileBrowserFileEditorDlg* dlg = CFileBrowserFileEditorDlg::NewL(fullPath, editorMode);
       
  3642 //            dlg->RunDlgLD();
       
  3643 //
       
  3644 //            iEngine->FileListContainer()->SetNaviPaneTextL(iCurrentPath);
       
  3645 //
       
  3646 //            if (aType == EFileBrowserCmdFileEditText || aType == EFileBrowserCmdFileEditHex)
       
  3647 //                {
       
  3648 //                RefreshViewL();
       
  3649 //                }
       
  3650             }
       
  3651         }
       
  3652     }
       
  3653 
       
  3654 // --------------------------------------------------------------------------------------------
       
  3655 
       
  3656 TBool CFileBrowserFileUtils::DriveSnapShotPossible()
       
  3657     {
       
  3658 //    // TODO
       
  3659 //    // check that E-drive is available
       
  3660 //    TBool EDriveIsOK(EFalse);
       
  3661 //
       
  3662 //    for (TInt i=0; i<iDriveEntryList->Count(); i++)
       
  3663 //        {
       
  3664 //        TDriveEntry driveEntry = iDriveEntryList->At(i);
       
  3665 //
       
  3666 //        if (driveEntry.iNumber == EDriveE)
       
  3667 //            {
       
  3668 //            if (driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttLocked || driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAbsent)
       
  3669 //                EDriveIsOK = EFalse;
       
  3670 //            else
       
  3671 //                EDriveIsOK = ETrue;
       
  3672 //            }
       
  3673 //        }
       
  3674 //
       
  3675 //    if (!EDriveIsOK)
       
  3676 //        return EFalse;
       
  3677 //
       
  3678 //    // get current item
       
  3679 //    TInt currentItemIndex = iEngine->QueryCurrentItemIndex();
       
  3680 //
       
  3681 //    if (iDriveEntryList->Count() > currentItemIndex && currentItemIndex >= 0)
       
  3682 //        {
       
  3683 //        TDriveEntry driveEntry = iDriveEntryList->At(currentItemIndex);
       
  3684 //
       
  3685 //        // drive snapshot not possible when E-drive is highlighted, since that's where we are copying
       
  3686 //        if (driveEntry.iNumber == EDriveE)
       
  3687 //            return EFalse;
       
  3688 //        else
       
  3689 //            return ETrue;
       
  3690 //        }
       
  3691     return EFalse;
       
  3692     }
       
  3693 
       
  3694 // --------------------------------------------------------------------------------------------
       
  3695 
       
  3696 void CFileBrowserFileUtils::DriveSnapShotL()
       
  3697     {
       
  3698 //    if (iEngine->Settings().iBypassPlatformSecurity)
       
  3699 //        {
       
  3700 //        // get current item
       
  3701 //        TInt currentItemIndex = iEngine->QueryCurrentItemIndex();
       
  3702 //
       
  3703 //        if (iDriveEntryList->Count() > currentItemIndex && currentItemIndex >= 0)
       
  3704 //            {
       
  3705 //            TDriveEntry driveEntry = iDriveEntryList->At(currentItemIndex);
       
  3706 //
       
  3707 //            TChar sourceDriveLetter = driveEntry.iLetter;
       
  3708 //            TChar targetDriveLetter = 'E';  // hardcoded drive letter, could be better if would be queried from the user
       
  3709 //
       
  3710 //            // append to the command array
       
  3711 //            AppendToCommandArrayL(EFileBrowserFileOpCommandDriveSnapShot,
       
  3712 //                                  new(ELeave)CCommandParamsDriveSnapShot(sourceDriveLetter, targetDriveLetter)
       
  3713 //                                 );
       
  3714 //
       
  3715 //            // execute the operation
       
  3716 //            StartExecutingCommandsL(_L("Copying"));
       
  3717 //            }
       
  3718 //        }
       
  3719 //    else
       
  3720 //        {
       
  3721 //        iEngine->FileBrowserUI()->ShowInformationNote(_L("Enable \"bypass platform security\" from the settings first"), _L(""));
       
  3722 //        }
       
  3723     }
       
  3724     
       
  3725 // --------------------------------------------------------------------------------------------
       
  3726 
       
  3727 void CFileBrowserFileUtils::SetDrivePasswordL(TInt aIndex,
       
  3728                                               const TFileName &aOldPassword,
       
  3729                                               const TFileName &aNewPassword)
       
  3730     {    
       
  3731     if (iDriveEntryList->Count() > aIndex && aIndex >= 0)
       
  3732         {
       
  3733         TMediaPassword oldPassword;
       
  3734         TMediaPassword newPassword;
       
  3735 
       
  3736         TDriveEntry driveEntry = iDriveEntryList->At(aIndex);
       
  3737 
       
  3738         ConvertCharsToPwd(aOldPassword, oldPassword);
       
  3739         ConvertCharsToPwd(aNewPassword, newPassword);
       
  3740 
       
  3741         // set the password, does not actually lock the drive
       
  3742         TInt err = iFs.LockDrive(driveEntry.iNumber, oldPassword, newPassword, ETrue);
       
  3743 
       
  3744         if (err == KErrNone)
       
  3745             {
       
  3746             iEngine->FileBrowserUI()->ShowConfirmationNote(_L("Password set"));
       
  3747             }
       
  3748         else if (err == KErrNotSupported)
       
  3749             {
       
  3750             iEngine->FileBrowserUI()->ShowErrorNote(_L("Not supported for this drive"));
       
  3751             }
       
  3752         else
       
  3753             {
       
  3754             CTextResolver* textResolver = CTextResolver::NewLC(*iEngine->EikonEnv());
       
  3755 
       
  3756             iEngine->FileBrowserUI()->ShowErrorNote(
       
  3757                     textResolver->ResolveErrorString(err, CTextResolver::ECtxNoCtxNoSeparator) );
       
  3758 
       
  3759             CleanupStack::PopAndDestroy();  //textResolver
       
  3760             }
       
  3761 
       
  3762         RefreshViewL();
       
  3763         }
       
  3764     }
       
  3765 
       
  3766 // --------------------------------------------------------------------------------------------
       
  3767 
       
  3768 void CFileBrowserFileUtils::UnlockDriveL(TInt aIndex, const TFileName &aOldPassword)
       
  3769     {
       
  3770     if (iDriveEntryList->Count() > aIndex && aIndex >= 0)
       
  3771         {
       
  3772         TDriveEntry driveEntry = iDriveEntryList->At(aIndex);
       
  3773 
       
  3774         TMediaPassword oldPassword;
       
  3775         ConvertCharsToPwd(aOldPassword, oldPassword);
       
  3776 
       
  3777         // unlock the drive
       
  3778         TInt err = iFs.UnlockDrive(driveEntry.iNumber, oldPassword, ETrue) == KErrNone;
       
  3779 
       
  3780         if (err == KErrNone)
       
  3781             {
       
  3782             iEngine->FileBrowserUI()->ShowConfirmationNote(_L("Drive unlocked"));
       
  3783             }
       
  3784         else if (err == KErrNotSupported)
       
  3785             {
       
  3786             iEngine->FileBrowserUI()->ShowErrorNote(_L("Not supported for this drive"));
       
  3787             }
       
  3788         else
       
  3789             {
       
  3790             CTextResolver* textResolver = CTextResolver::NewLC(*iEngine->EikonEnv());
       
  3791 
       
  3792             iEngine->FileBrowserUI()->ShowErrorNote( textResolver->ResolveErrorString(err, CTextResolver::ECtxNoCtxNoSeparator) );
       
  3793 
       
  3794             CleanupStack::PopAndDestroy();  //textResolver
       
  3795             }
       
  3796 
       
  3797         RefreshViewL();
       
  3798         }
       
  3799     }
       
  3800 
       
  3801 // --------------------------------------------------------------------------------------------
       
  3802 
       
  3803 void CFileBrowserFileUtils::ClearDrivePasswordL(TInt aIndex, const TFileName &aOldPassword)
       
  3804     {
       
  3805     if (iDriveEntryList->Count() > aIndex && aIndex >= 0)
       
  3806         {
       
  3807         TDriveEntry driveEntry = iDriveEntryList->At(aIndex);
       
  3808 
       
  3809         TMediaPassword oldPassword;
       
  3810 
       
  3811         ConvertCharsToPwd(aOldPassword, oldPassword);
       
  3812 
       
  3813         // clear the password from the drive
       
  3814         TInt err = iFs.ClearPassword(driveEntry.iNumber, oldPassword);
       
  3815 
       
  3816         if (err == KErrNone)
       
  3817             {
       
  3818             iEngine->FileBrowserUI()->ShowConfirmationNote(_L("Password cleared"));
       
  3819             }
       
  3820         else if (err == KErrNotSupported)
       
  3821             {
       
  3822             iEngine->FileBrowserUI()->ShowErrorNote(_L("Not supported for this drive"));
       
  3823             }
       
  3824         else
       
  3825             {
       
  3826             CTextResolver* textResolver = CTextResolver::NewLC(*iEngine->EikonEnv());
       
  3827 
       
  3828             iEngine->FileBrowserUI()->ShowErrorNote(
       
  3829                     textResolver->ResolveErrorString(err, CTextResolver::ECtxNoCtxNoSeparator) );
       
  3830 
       
  3831             CleanupStack::PopAndDestroy();  //textResolver
       
  3832             }
       
  3833 
       
  3834         RefreshViewL();
       
  3835         }
       
  3836     }
       
  3837 
       
  3838 // --------------------------------------------------------------------------------------------
       
  3839 
       
  3840 void CFileBrowserFileUtils::EraseDrivePasswordL(TInt aIndex)
       
  3841     {
       
  3842     if (iDriveEntryList->Count() > aIndex && aIndex >= 0)
       
  3843         {
       
  3844         TDriveEntry driveEntry = iDriveEntryList->At(aIndex);
       
  3845         
       
  3846         // erase the password from the drive
       
  3847         TInt err(KErrNone);
       
  3848         err = iFs.ErasePassword(driveEntry.iNumber);
       
  3849 
       
  3850         if (err == KErrNone)
       
  3851             {
       
  3852             iEngine->FileBrowserUI()->ShowConfirmationNote(_L("Password erased"));
       
  3853             }
       
  3854         else if (err == KErrNotSupported)
       
  3855             {
       
  3856             iEngine->FileBrowserUI()->ShowErrorNote(_L("Not supported for this drive"));
       
  3857             }
       
  3858         else
       
  3859             {
       
  3860             iEngine->FileBrowserUI()->ShowErrorNote(_L("Cannot erase, you may have to format the drive first"));
       
  3861             }
       
  3862 
       
  3863         RefreshViewL();
       
  3864         }
       
  3865     }
       
  3866 
       
  3867 // --------------------------------------------------------------------------------------------
       
  3868 
       
  3869 void CFileBrowserFileUtils::FormatDriveL(TInt aIndex, TBool aQuickFormat)
       
  3870     {    
       
  3871     if (iDriveEntryList->Count() > aIndex && aIndex >= 0)
       
  3872         {
       
  3873         TDriveEntry driveEntry = iDriveEntryList->At(aIndex);
       
  3874 
       
  3875         TInt err(KErrNone);
       
  3876         TInt formatCount(0);
       
  3877 
       
  3878         TBuf<10> driveRoot;
       
  3879         driveRoot.Append(driveEntry.iLetter);
       
  3880         driveRoot.Append(_L(":"));
       
  3881 
       
  3882         TUint formatMode(0);
       
  3883         if (aQuickFormat)
       
  3884             formatMode = ESpecialFormat|EQuickFormat;
       
  3885         else
       
  3886             formatMode = ESpecialFormat|EFullFormat;
       
  3887 
       
  3888         // set as system application to prevent getting shut down events
       
  3889         iEngine->EikonEnv()->SetSystem(ETrue);
       
  3890 
       
  3891         // first close any open applications
       
  3892         CBaBackupSessionWrapper* BSWrapper = CBaBackupSessionWrapper::NewL();
       
  3893         CleanupStack::PushL(BSWrapper);
       
  3894 
       
  3895         TBackupOperationAttributes atts(MBackupObserver::EReleaseLockNoAccess, MBackupOperationObserver::EStart);
       
  3896         BSWrapper->NotifyBackupOperationL(atts);
       
  3897 
       
  3898         CAsyncWaiter* waiter = CAsyncWaiter::NewLC();
       
  3899         BSWrapper->CloseAll( MBackupObserver::EReleaseLockNoAccess, waiter->iStatus );
       
  3900         waiter->StartAndWait();
       
  3901         CleanupStack::PopAndDestroy(); //waiter
       
  3902 
       
  3903         // some delay to make sure all applications have been closed
       
  3904         User::After(1000000);
       
  3905 
       
  3906         // format the drive
       
  3907         RFormat format;
       
  3908         err = format.Open(iFs, driveRoot, formatMode, formatCount);
       
  3909 
       
  3910         // Forced format for locked card
       
  3911         if ( err == KErrLocked )
       
  3912             {
       
  3913             // Erase password and try again
       
  3914             err = iFs.ErasePassword( driveEntry.iNumber );
       
  3915             if ( !err )
       
  3916                 {
       
  3917                 err = format.Open(iFs, driveRoot, formatMode, formatCount);
       
  3918                 }
       
  3919             }
       
  3920 
       
  3921         if( err != KErrNone &&  err != KErrLocked )
       
  3922             {
       
  3923 //            CAknQueryDialog* lockQuery = CAknQueryDialog::NewL();
       
  3924 //            if ( lockQuery->ExecuteLD(R_GENERAL_CONFIRMATION_QUERY, _L("Memory card in use by other application. Proceed anyway?")))
       
  3925             // TODO Dialog should be opened in UI part
       
  3926             if (iEngine->FileBrowserUI()->ShowConfirmationQuery(_L("Memory card in use by other application. Proceed anyway?")))
       
  3927                 {
       
  3928                 // If format could not be started, someone is still keeping
       
  3929                 // files open on media. Let's try to dismount file system, then
       
  3930                 // remount with own extension embedded and try again.
       
  3931 
       
  3932                 TFullName fsName;
       
  3933                 err = iFs.FileSystemName( fsName, driveEntry.iNumber );
       
  3934 
       
  3935                 if ( err == KErrNone && fsName.Length() > 0 )
       
  3936                     {
       
  3937                     // Prevent SysAp shutting down applications
       
  3938                     RProperty::Set(
       
  3939                         KPSUidCoreApplicationUIs,
       
  3940                         KCoreAppUIsMmcRemovedWithoutEject,
       
  3941                         ECoreAppUIsEjectCommandUsed );
       
  3942 
       
  3943                     TRequestStatus stat;
       
  3944                     iFs.NotifyDismount( driveEntry.iNumber, stat, EFsDismountForceDismount );
       
  3945                     User::WaitForRequest( stat );
       
  3946 
       
  3947                     // Unfortunately, at the moment we have to wait until clients have received
       
  3948                     // notification about card dismount. Otherwise at least causes problems with
       
  3949                     // theme selected from card. In future clients should use new notify-API.
       
  3950                     User::After( KForcedFormatTimeout );
       
  3951 
       
  3952                     // Let's set priority higher than normally. This is done to decrease the chance
       
  3953                     // that someone reopens files on memory card after mandatory file system
       
  3954                     // remounting hence preventing formatting again.
       
  3955                     TThreadPriority priority( RThread().Priority() );
       
  3956                     RThread().SetPriority( EPriorityAbsoluteHigh );
       
  3957 
       
  3958                     // Mount file system back...
       
  3959                     err = iFs.MountFileSystem( fsName, driveEntry.iNumber );
       
  3960                     err = format.Open(iFs, driveRoot, formatMode, formatCount);
       
  3961                     RThread().SetPriority( priority );
       
  3962                     }
       
  3963                 }
       
  3964             }
       
  3965 
       
  3966 
       
  3967         if (err == KErrNone)
       
  3968             {
       
  3969             // needs to be implemented with active objects
       
  3970             // CAknProgressDialog* dlg = new(ELeave) CAknProgressDialog(formatCount, 1, 1, NULL);
       
  3971             // dlg->SetTone(CAknNoteDialog::ENoTone);
       
  3972             // dlg->ExecuteLD(R_FORMAT_PROGRESS_NOTE);
       
  3973 
       
  3974             while (formatCount && err == KErrNone)
       
  3975                 {
       
  3976                 err = format.Next(formatCount);
       
  3977                 }
       
  3978             }
       
  3979 
       
  3980         format.Close();
       
  3981 
       
  3982         // restart closed applications
       
  3983         TBackupOperationAttributes atts2(MBackupObserver::ETakeLock, MBackupOperationObserver::EEnd);
       
  3984         BSWrapper->NotifyBackupOperationL(atts2);
       
  3985         BSWrapper->RestartAll();
       
  3986         CleanupStack::PopAndDestroy(); //BSWrapper
       
  3987 
       
  3988         // system status not needed anymore
       
  3989         iEngine->EikonEnv()->SetSystem(EFalse);
       
  3990 
       
  3991 
       
  3992         if (err == KErrNone)
       
  3993             {
       
  3994             iEngine->FileBrowserUI()->ShowConfirmationNote(_L("Format succeeded"));
       
  3995             }
       
  3996         else if (err == KErrNotSupported)
       
  3997             {
       
  3998             iEngine->FileBrowserUI()->ShowErrorNote(_L("Not supported for this drive"));
       
  3999             }
       
  4000         else
       
  4001             {
       
  4002             CTextResolver* textResolver = CTextResolver::NewLC(*iEngine->EikonEnv());
       
  4003 
       
  4004             iEngine->FileBrowserUI()->ShowErrorNote(
       
  4005                     textResolver->ResolveErrorString(err, CTextResolver::ECtxNoCtxNoSeparator) );
       
  4006 
       
  4007             CleanupStack::PopAndDestroy();  //textResolver
       
  4008             }
       
  4009 
       
  4010         RefreshViewL();
       
  4011         }
       
  4012     }
       
  4013 
       
  4014 // --------------------------------------------------------------------------------------------
       
  4015 
       
  4016 void CFileBrowserFileUtils::EraseMBRL(TInt aIndex)
       
  4017     {
       
  4018     // TODO
       
  4019     #ifndef FILEBROWSER_LITE
       
  4020     if (iEngine->Settings().iBypassPlatformSecurity)
       
  4021         {        
       
  4022         if (iDriveEntryList->Count() > aIndex && aIndex >= 0)
       
  4023             {
       
  4024             TDriveEntry driveEntry = iDriveEntryList->At(aIndex);
       
  4025 
       
  4026             TInt err(KErrNone);
       
  4027 
       
  4028             iEngine->FileBrowserUI()->ShowInformationNote(_L("Please wait, this may take 30 seconds"), _L(""));
       
  4029 
       
  4030             // set as system application to prevent getting shut down events
       
  4031             iEngine->EikonEnv()->SetSystem(ETrue);
       
  4032 
       
  4033             // first close any open applications
       
  4034             CBaBackupSessionWrapper* BSWrapper = CBaBackupSessionWrapper::NewL();
       
  4035             CleanupStack::PushL(BSWrapper);
       
  4036 
       
  4037             TBackupOperationAttributes atts(MBackupObserver::EReleaseLockNoAccess, MBackupOperationObserver::EStart);
       
  4038             BSWrapper->NotifyBackupOperationL(atts);
       
  4039 
       
  4040             CAsyncWaiter* waiter = CAsyncWaiter::NewLC();
       
  4041             BSWrapper->CloseAll( MBackupObserver::EReleaseLockNoAccess, waiter->iStatus );
       
  4042             waiter->StartAndWait();
       
  4043             CleanupStack::PopAndDestroy(); //waiter
       
  4044 
       
  4045             // some delay to make sure all applications have been closed
       
  4046             User::After(1000000);
       
  4047 
       
  4048 
       
  4049             // do the erase MBR operation
       
  4050             err = iFileOps->EraseMBR(driveEntry.iNumber);
       
  4051 
       
  4052 
       
  4053             // restart closed applications
       
  4054             TBackupOperationAttributes atts2(MBackupObserver::ETakeLock, MBackupOperationObserver::EEnd);
       
  4055             BSWrapper->NotifyBackupOperationL(atts2);
       
  4056             BSWrapper->RestartAll();
       
  4057             CleanupStack::PopAndDestroy(); //BSWrapper
       
  4058 
       
  4059             // system status not needed anymore
       
  4060             iEngine->EikonEnv()->SetSystem(EFalse);
       
  4061 
       
  4062 
       
  4063             if (err == KErrNone)
       
  4064                 {
       
  4065                 iEngine->FileBrowserUI()->ShowConfirmationNote(_L("Erase MBR succeeded"));
       
  4066                 }
       
  4067             else if (err == KErrNotSupported)
       
  4068                 {
       
  4069                 iEngine->FileBrowserUI()->ShowErrorNote(_L("Not supported for this drive"));
       
  4070                 }
       
  4071             else
       
  4072                 {
       
  4073                 CTextResolver* textResolver = CTextResolver::NewLC(*iEngine->EikonEnv());
       
  4074 
       
  4075                 iEngine->FileBrowserUI()->ShowErrorNote(
       
  4076                         textResolver->ResolveErrorString(err, CTextResolver::ECtxNoCtxNoSeparator) );
       
  4077 
       
  4078                 CleanupStack::PopAndDestroy();  //textResolver
       
  4079                 }
       
  4080 
       
  4081             RefreshViewL();
       
  4082             }
       
  4083         }
       
  4084     else
       
  4085         {
       
  4086         iEngine->FileBrowserUI()->ShowInformationNote(_L("Enable \"bypass platform security\" from the settings first"), _L(""));
       
  4087         }
       
  4088     #else
       
  4089         iEngine->FileBrowserUI()->ShowInformationNote(_L("Not supported in lite version"), _L(""));
       
  4090     #endif
       
  4091     }
       
  4092     
       
  4093 // --------------------------------------------------------------------------------------------
       
  4094 
       
  4095 void CFileBrowserFileUtils::PartitionDriveL(TInt aIndex, TBool aEraseMBR, TInt aAmountOfPartitions)
       
  4096     {
       
  4097     // TODO
       
  4098     #ifndef FILEBROWSER_LITE
       
  4099     if (iEngine->Settings().iBypassPlatformSecurity)
       
  4100         {
       
  4101         if (iDriveEntryList->Count() > aIndex && aIndex >= 0)
       
  4102             {
       
  4103             TDriveEntry driveEntry = iDriveEntryList->At(aIndex);
       
  4104 
       
  4105             TInt err(KErrNone);
       
  4106 
       
  4107             iEngine->FileBrowserUI()->ShowInformationNote(_L("Please wait, this may take 30 seconds"), _L(""));
       
  4108 
       
  4109             // set as system application to prevent getting shut down events
       
  4110             iEngine->EikonEnv()->SetSystem(ETrue);
       
  4111 
       
  4112             // first close any open applications
       
  4113             CBaBackupSessionWrapper* BSWrapper = CBaBackupSessionWrapper::NewL();
       
  4114             CleanupStack::PushL(BSWrapper);
       
  4115 
       
  4116             TBackupOperationAttributes atts(MBackupObserver::EReleaseLockNoAccess, MBackupOperationObserver::EStart);
       
  4117             BSWrapper->NotifyBackupOperationL(atts);
       
  4118 
       
  4119             CAsyncWaiter* waiter = CAsyncWaiter::NewLC();
       
  4120             BSWrapper->CloseAll( MBackupObserver::EReleaseLockNoAccess, waiter->iStatus );
       
  4121             waiter->StartAndWait();
       
  4122             CleanupStack::PopAndDestroy(); //waiter
       
  4123 
       
  4124             // some delay to make sure all applications have been closed
       
  4125             User::After(1000000);
       
  4126 
       
  4127             // do the erase operation
       
  4128             if (aEraseMBR)
       
  4129                 {
       
  4130                 err = iFileOps->EraseMBR(driveEntry.iNumber);
       
  4131 
       
  4132                 if (err != KErrNone)
       
  4133                     {
       
  4134                     iEngine->FileBrowserUI()->ShowErrorNote(_L("Erase MBR failed"));
       
  4135                     }
       
  4136 
       
  4137                 User::After(500000);
       
  4138                 }
       
  4139 
       
  4140 
       
  4141             // do the partition operation
       
  4142             err = iFileOps->PartitionDrive(driveEntry.iNumber, aAmountOfPartitions);
       
  4143 
       
  4144 
       
  4145             // restart closed applications
       
  4146             TBackupOperationAttributes atts2(MBackupObserver::ETakeLock, MBackupOperationObserver::EEnd);
       
  4147             BSWrapper->NotifyBackupOperationL(atts2);
       
  4148             BSWrapper->RestartAll();
       
  4149             CleanupStack::PopAndDestroy(); //BSWrapper
       
  4150 
       
  4151             // system status not needed anymore
       
  4152             iEngine->EikonEnv()->SetSystem(EFalse);
       
  4153 
       
  4154 
       
  4155             if (err == KErrNone)
       
  4156                 {
       
  4157                 iEngine->FileBrowserUI()->ShowConfirmationNote(_L("Partition succeeded"));
       
  4158                 }
       
  4159             else if (err == KErrNotSupported)
       
  4160                 {
       
  4161                 iEngine->FileBrowserUI()->ShowErrorNote(_L("Not supported for this drive"));
       
  4162                 }
       
  4163             else
       
  4164                 {
       
  4165                 CTextResolver* textResolver = CTextResolver::NewLC(*iEngine->EikonEnv());
       
  4166 
       
  4167                 iEngine->FileBrowserUI()->ShowErrorNote(
       
  4168                         textResolver->ResolveErrorString(err, CTextResolver::ECtxNoCtxNoSeparator) );
       
  4169 
       
  4170                 CleanupStack::PopAndDestroy();  //textResolver
       
  4171                 }
       
  4172 
       
  4173             RefreshViewL();
       
  4174             }
       
  4175         }
       
  4176     else
       
  4177         {
       
  4178         iEngine->FileBrowserUI()->ShowInformationNote(_L("Enable \"bypass platform security\" from the settings first"), _L(""));
       
  4179         }
       
  4180     #else
       
  4181         iEngine->FileBrowserUI()->ShowInformationNote(_L("Not supported in lite version"), _L(""));
       
  4182     #endif
       
  4183 	}
       
  4184     
       
  4185 // --------------------------------------------------------------------------------------------
       
  4186 
       
  4187 void CFileBrowserFileUtils::CheckDiskL(TInt aIndex)
       
  4188     {    
       
  4189     if (iDriveEntryList->Count() > aIndex && aIndex >= 0)
       
  4190         {
       
  4191         TDriveEntry driveEntry = iDriveEntryList->At(aIndex);
       
  4192         
       
  4193         TBuf<10> driveRoot;
       
  4194         driveRoot.Append(driveEntry.iLetter);
       
  4195         driveRoot.Append(_L(":"));
       
  4196         
       
  4197         // check disk
       
  4198         TInt err = iFs.CheckDisk(driveRoot);
       
  4199 
       
  4200         if (err == KErrNone)
       
  4201             {
       
  4202             iEngine->FileBrowserUI()->ShowConfirmationNote(_L("Integrity of the disk is ok"));
       
  4203             }
       
  4204         else if (err == KErrNotReady)
       
  4205             {
       
  4206             iEngine->FileBrowserUI()->ShowInformationNote(_L("Disk is empty"), _L(""));
       
  4207             }
       
  4208         else if (err == KErrNotSupported)
       
  4209             {
       
  4210             iEngine->FileBrowserUI()->ShowErrorNote(_L("Not supported for this drive"));
       
  4211             }
       
  4212         else
       
  4213             {
       
  4214             iEngine->FileBrowserUI()->ShowErrorNote(_L("Disk is corrupted"));
       
  4215             }        
       
  4216 
       
  4217         RefreshViewL();
       
  4218         }
       
  4219     }
       
  4220 
       
  4221 // --------------------------------------------------------------------------------------------
       
  4222 
       
  4223 void CFileBrowserFileUtils::ScanDriveL(TInt aIndex)
       
  4224     {
       
  4225     if (iDriveEntryList->Count() > aIndex && aIndex >= 0)
       
  4226         {
       
  4227         TDriveEntry driveEntry = iDriveEntryList->At(aIndex);
       
  4228 
       
  4229         TBuf<10> driveRoot;
       
  4230         driveRoot.Append(driveEntry.iLetter);
       
  4231         driveRoot.Append(_L(":"));
       
  4232 
       
  4233         // scan disk
       
  4234         TInt err = iFs.ScanDrive(driveRoot);
       
  4235 
       
  4236         if (err == KErrNone)
       
  4237             {
       
  4238             iEngine->FileBrowserUI()->ShowConfirmationNote(_L("Run succesfully"));
       
  4239             }
       
  4240         else if (err == KErrNotSupported)
       
  4241             {
       
  4242             iEngine->FileBrowserUI()->ShowErrorNote(_L("Not supported for this drive"));
       
  4243             }
       
  4244         else
       
  4245             {
       
  4246             CTextResolver* textResolver = CTextResolver::NewLC(*iEngine->EikonEnv());
       
  4247 
       
  4248             iEngine->FileBrowserUI()->ShowErrorNote(
       
  4249                     textResolver->ResolveErrorString(err, CTextResolver::ECtxNoCtxNoSeparator) );
       
  4250 
       
  4251             CleanupStack::PopAndDestroy();  //textResolver
       
  4252             }
       
  4253 
       
  4254         RefreshViewL();
       
  4255         }
       
  4256     }
       
  4257 
       
  4258 // --------------------------------------------------------------------------------------------
       
  4259 
       
  4260 void CFileBrowserFileUtils::GetDriveName(TInt aIndex, TFileName &aDriveName)
       
  4261     {
       
  4262     if (iDriveEntryList->Count() > aIndex && aIndex >= 0)
       
  4263         {
       
  4264         TDriveEntry driveEntry = iDriveEntryList->At(aIndex);
       
  4265 
       
  4266         // get existing drive name
       
  4267         iFs.GetDriveName(driveEntry.iNumber, aDriveName);
       
  4268         }
       
  4269     }
       
  4270 
       
  4271 // --------------------------------------------------------------------------------------------
       
  4272 
       
  4273 void CFileBrowserFileUtils::SetDriveNameL(TInt aIndex, const TFileName &aDriveName)
       
  4274     {
       
  4275     if (iDriveEntryList->Count() > aIndex && aIndex >= 0)
       
  4276         {
       
  4277         TDriveEntry driveEntry = iDriveEntryList->At(aIndex);
       
  4278 
       
  4279         // set drive name
       
  4280         TInt err = iFs.SetDriveName(driveEntry.iNumber, aDriveName);
       
  4281 
       
  4282         if (err == KErrNone)
       
  4283             {
       
  4284             iEngine->FileBrowserUI()->ShowConfirmationNote(_L("Name changed"));
       
  4285             }
       
  4286         else if (err == KErrNotSupported)
       
  4287             {
       
  4288             iEngine->FileBrowserUI()->ShowErrorNote(_L("Not supported for this drive"));
       
  4289             }
       
  4290         else
       
  4291             {
       
  4292             CTextResolver* textResolver = CTextResolver::NewLC(*iEngine->EikonEnv());
       
  4293 
       
  4294             iEngine->FileBrowserUI()->ShowErrorNote(
       
  4295                     textResolver->ResolveErrorString(err, CTextResolver::ECtxNoCtxNoSeparator) );
       
  4296 
       
  4297             CleanupStack::PopAndDestroy();  //textResolver
       
  4298             }
       
  4299 
       
  4300         RefreshViewL();
       
  4301         }
       
  4302     }
       
  4303 
       
  4304 // --------------------------------------------------------------------------------------------
       
  4305 
       
  4306 void CFileBrowserFileUtils::GetDriveVolumeLabel(TInt aIndex, TFileName &aVolumeLabel)
       
  4307     {
       
  4308     if (iDriveEntryList->Count() > aIndex && aIndex >= 0)
       
  4309         {
       
  4310         TDriveEntry driveEntry = iDriveEntryList->At(aIndex);
       
  4311 
       
  4312         // get existing volume label
       
  4313         aVolumeLabel.Copy(driveEntry.iVolumeInfo.iName);
       
  4314         }
       
  4315     }
       
  4316 
       
  4317 // --------------------------------------------------------------------------------------------
       
  4318 
       
  4319 void CFileBrowserFileUtils::SetDriveVolumeLabelL(TInt aIndex, const TFileName &aVolumeLabel)
       
  4320     {
       
  4321     if (iDriveEntryList->Count() > aIndex && aIndex >= 0)
       
  4322         {
       
  4323         TDriveEntry driveEntry = iDriveEntryList->At(aIndex);
       
  4324 
       
  4325         // set volume label
       
  4326         TInt err = iFs.SetVolumeLabel(aVolumeLabel, driveEntry.iNumber);
       
  4327 
       
  4328         if (err == KErrNone)
       
  4329             {
       
  4330             iEngine->FileBrowserUI()->ShowConfirmationNote(_L("Volume label changed"));
       
  4331             }
       
  4332         else if (err == KErrNotSupported)
       
  4333             {
       
  4334             iEngine->FileBrowserUI()->ShowErrorNote(_L("Not supported for this drive"));
       
  4335             }
       
  4336         else
       
  4337             {
       
  4338             CTextResolver* textResolver = CTextResolver::NewLC(*iEngine->EikonEnv());
       
  4339 
       
  4340             iEngine->FileBrowserUI()->ShowErrorNote(
       
  4341                     textResolver->ResolveErrorString(err, CTextResolver::ECtxNoCtxNoSeparator) );
       
  4342 
       
  4343             CleanupStack::PopAndDestroy();  //textResolver
       
  4344             }
       
  4345 
       
  4346         RefreshViewL();
       
  4347         }
       
  4348     }
       
  4349 
       
  4350 // --------------------------------------------------------------------------------------------
       
  4351 
       
  4352 void CFileBrowserFileUtils::EjectDriveL(TInt aIndex)
       
  4353     {
       
  4354     if (iDriveEntryList->Count() > aIndex && aIndex >= 0)
       
  4355         {
       
  4356         TDriveEntry driveEntry = iDriveEntryList->At(aIndex);
       
  4357         
       
  4358         TInt err(KErrNone);
       
  4359         
       
  4360         // get current filesystem name
       
  4361         TFileName fileSystemName;
       
  4362         err = iFs.FileSystemName(fileSystemName, driveEntry.iNumber);
       
  4363         
       
  4364         if (err == KErrNone)
       
  4365             {
       
  4366             // Prevent SysAp shutting down applications
       
  4367             RProperty::Set(
       
  4368                 KPSUidCoreApplicationUIs,
       
  4369                 KCoreAppUIsMmcRemovedWithoutEject,
       
  4370                 ECoreAppUIsEjectCommandUsed );
       
  4371             
       
  4372             // dismount the file system
       
  4373             err = iFs.DismountFileSystem(fileSystemName, driveEntry.iNumber);
       
  4374             
       
  4375             if (err == KErrNone)
       
  4376                 {
       
  4377                 // remount the file system
       
  4378                 err = iFs.MountFileSystem(fileSystemName, driveEntry.iNumber);
       
  4379                 
       
  4380                 if (err == KErrInUse)
       
  4381                     {
       
  4382                     // try to remount after a while if locked
       
  4383                     User::After(1000000);
       
  4384                     err = iFs.MountFileSystem(fileSystemName, driveEntry.iNumber);
       
  4385                     }                
       
  4386                 }
       
  4387             }
       
  4388 
       
  4389         if (err == KErrNone)
       
  4390             {
       
  4391             iEngine->FileBrowserUI()->ShowConfirmationNote(_L("Ejected succesfully"));
       
  4392             }
       
  4393         else if (err == KErrNotSupported)
       
  4394             {
       
  4395             iEngine->FileBrowserUI()->ShowErrorNote(_L("Not supported for this drive"));
       
  4396             }
       
  4397         else
       
  4398             {
       
  4399             CTextResolver* textResolver = CTextResolver::NewLC(*iEngine->EikonEnv());
       
  4400 
       
  4401             iEngine->FileBrowserUI()->ShowErrorNote(
       
  4402                     textResolver->ResolveErrorString(err, CTextResolver::ECtxNoCtxNoSeparator) );
       
  4403 
       
  4404             CleanupStack::PopAndDestroy();  //textResolver
       
  4405             }              
       
  4406 
       
  4407         RefreshViewL();
       
  4408         }
       
  4409     }
       
  4410     
       
  4411 // --------------------------------------------------------------------------------------------
       
  4412 
       
  4413 void CFileBrowserFileUtils::DismountFileSystemL(TInt aIndex)
       
  4414     {
       
  4415     if (iDriveEntryList->Count() > aIndex && aIndex >= 0)
       
  4416         {
       
  4417         TDriveEntry driveEntry = iDriveEntryList->At(aIndex);
       
  4418 
       
  4419         TInt err(KErrNone);
       
  4420 
       
  4421         // get current filesystem name
       
  4422         TFileName fileSystemName;
       
  4423         err = iFs.FileSystemName(fileSystemName, driveEntry.iNumber);
       
  4424 
       
  4425         if (err == KErrNone)
       
  4426             {
       
  4427             // Prevent SysAp shutting down applications
       
  4428             RProperty::Set(
       
  4429                 KPSUidCoreApplicationUIs,
       
  4430                 KCoreAppUIsMmcRemovedWithoutEject,
       
  4431                 ECoreAppUIsEjectCommandUsed );
       
  4432 
       
  4433             // dismount the file system
       
  4434             err = iFs.DismountFileSystem(fileSystemName, driveEntry.iNumber);
       
  4435             }
       
  4436 
       
  4437         if (err == KErrNone)
       
  4438             {
       
  4439             iEngine->FileBrowserUI()->ShowConfirmationNote(_L("Dismounted succesfully"));
       
  4440             }
       
  4441         else if (err == KErrNotSupported)
       
  4442             {
       
  4443             iEngine->FileBrowserUI()->ShowErrorNote(_L("Not supported for this drive"));
       
  4444             }
       
  4445         else
       
  4446             {
       
  4447             CTextResolver* textResolver = CTextResolver::NewLC(*iEngine->EikonEnv());
       
  4448 
       
  4449             iEngine->FileBrowserUI()->ShowErrorNote(
       
  4450                     textResolver->ResolveErrorString(err, CTextResolver::ECtxNoCtxNoSeparator) );
       
  4451 
       
  4452             CleanupStack::PopAndDestroy();  //textResolver
       
  4453             }
       
  4454 
       
  4455         RefreshViewL();
       
  4456         }
       
  4457     }
       
  4458     
       
  4459 // --------------------------------------------------------------------------------------------
       
  4460 
       
  4461 void CFileBrowserFileUtils::ConvertCharsToPwd(const TDesC& aWord, TDes8& aConverted) const
       
  4462     {
       
  4463     aConverted.FillZ(aConverted.MaxLength());
       
  4464     aConverted.Zero();
       
  4465     
       
  4466     if (aWord.Length())
       
  4467         {
       
  4468         aConverted.Copy( (TUint8*)(&aWord[0]), aWord.Size() );
       
  4469         }
       
  4470     }
       
  4471 
       
  4472 // --------------------------------------------------------------------------------------------
       
  4473 
       
  4474 void CFileBrowserFileUtils::EditDataTypesL()
       
  4475     {
       
  4476 	// TODO
       
  4477 	/*
       
  4478     iEngine->FileListContainer()->SetScreenLayoutL(EDisplayModeNormal);
       
  4479     iEngine->FileListContainer()->SetNaviPaneTextL(KNullDesC);
       
  4480     
       
  4481     CFileBrowserDataTypesDlg* dlg = CFileBrowserDataTypesDlg::NewL();
       
  4482     dlg->RunQueryLD();
       
  4483 
       
  4484     iEngine->FileListContainer()->SetScreenLayoutL(iEngine->Settings().iDisplayMode);
       
  4485     iEngine->FileListContainer()->SetNaviPaneTextL(iCurrentPath);  
       
  4486 	*/	
       
  4487     }
       
  4488 
       
  4489 // --------------------------------------------------------------------------------------------
       
  4490 
       
  4491 void CFileBrowserFileUtils::SecureBackupL(TInt aType)
       
  4492     {
       
  4493     TInt err(KErrNone);
       
  4494     TInt showStatus(EFalse);
       
  4495     
       
  4496     if (aType == EFileBrowserCmdToolsSecureBackupStartBackup || aType == EFileBrowserCmdToolsSecureBackupStartRestore)
       
  4497         {
       
  4498 //        TInt queryIndexState(0);
       
  4499 //        TInt queryIndexType(0);
       
  4500         
       
  4501 //        CAknListQueryDialog* listQueryDlgState = new(ELeave) CAknListQueryDialog(&queryIndexState);
       
  4502 //        if (listQueryDlgState->ExecuteLD(R_SECUREBACKUP_STATE_QUERY))
       
  4503 //            {
       
  4504 //
       
  4505 //            CAknListQueryDialog* listQueryDlgType = new(ELeave) CAknListQueryDialog(&queryIndexType);
       
  4506 //            if (listQueryDlgType->ExecuteLD(R_SECUREBACKUP_TYPE_QUERY))
       
  4507 //                {
       
  4508 //                conn::TBURPartType partType = conn::EBURNormal;
       
  4509 //                conn::TBackupIncType backupIncType = conn::ENoBackup;
       
  4510 //                
       
  4511 //                if (aType == EFileBrowserCmdToolsSecureBackupStartBackup)
       
  4512 //                    {
       
  4513 //                    if (queryIndexState == ESecureBackupStateFull)
       
  4514 //                        partType = conn::EBURBackupFull;
       
  4515 //                    else if (queryIndexState == ESecureBackupStatePartial)
       
  4516 //                        partType = conn::EBURBackupPartial;
       
  4517 //                    }
       
  4518 //                else if (aType == EFileBrowserCmdToolsSecureBackupStartRestore)
       
  4519 //                    {
       
  4520 //                    if (queryIndexState == ESecureBackupStateFull)
       
  4521 //                        partType = conn::EBURRestoreFull;
       
  4522 //                    else if (queryIndexState == ESecureBackupStatePartial)
       
  4523 //                        partType = conn::EBURRestorePartial;
       
  4524 //                    }
       
  4525 //                    
       
  4526 //                if (queryIndexType == ESecureBackupTypeBase)
       
  4527 //                    backupIncType = conn::EBackupBase;
       
  4528 //                else if (queryIndexType == ESecureBackupTypeIncremental)    
       
  4529 //                    backupIncType = conn::EBackupIncrement;    
       
  4530 //
       
  4531 //                // start secure backup
       
  4532 //                err = iFileOps->ActivateSecureBackUp(partType, backupIncType);
       
  4533 //                showStatus = ETrue;
       
  4534 //                }
       
  4535 //            }
       
  4536         }
       
  4537 
       
  4538     else if (aType == EFileBrowserCmdToolsSecureBackupStop)
       
  4539         {
       
  4540         err = iFileOps->DeActivateSecureBackUp();
       
  4541         showStatus = ETrue;
       
  4542         }
       
  4543 
       
  4544     else
       
  4545         User::Panic(_L("Sec.br.mode"), 101);
       
  4546     
       
  4547     
       
  4548     if (showStatus)
       
  4549         {
       
  4550         if (err == KErrNone)
       
  4551             {
       
  4552             iEngine->FileBrowserUI()->ShowConfirmationNote(_L("Succeeded"));
       
  4553             }
       
  4554         else
       
  4555             {
       
  4556             CTextResolver* textResolver = CTextResolver::NewLC(*iEngine->EikonEnv());
       
  4557 
       
  4558             iEngine->FileBrowserUI()->ShowErrorNote(
       
  4559                     textResolver->ResolveErrorString(err, CTextResolver::ECtxNoCtxNoSeparator) );
       
  4560 
       
  4561             CleanupStack::PopAndDestroy();  //textResolver
       
  4562             }  
       
  4563         }
       
  4564     }
       
  4565 
       
  4566 // --------------------------------------------------------------------------------------------
       
  4567 
       
  4568 void CFileBrowserFileUtils::OpenCommonFileActionQueryL(TInt aCurrentItemIndex)
       
  4569     {
       
  4570     // TODO
       
  4571     // just get current item
       
  4572 //    TInt currentItemIndex = iEngine->QueryCurrentItemIndex();
       
  4573 
       
  4574     if (iFileEntryList->Count() > aCurrentItemIndex && aCurrentItemIndex >= 0)
       
  4575         {
       
  4576 //        TInt queryIndex(0);
       
  4577 //
       
  4578 //        CAknListQueryDialog* listQueryDlg = new(ELeave) CAknListQueryDialog(&queryIndex);
       
  4579 //
       
  4580 //        if (listQueryDlg->ExecuteLD(R_COMMON_FILE_ACTION_QUERY))
       
  4581 //            {
       
  4582 //            if (queryIndex == ECommonFileActionViewAsTextHex)
       
  4583 //                {
       
  4584 //                TFileEntry fileEntry = iFileEntryList->At(aCurrentItemIndex);
       
  4585 //
       
  4586 //                TFileName fullPath = fileEntry.iPath;
       
  4587 //                fullPath.Append(fileEntry.iEntry.iName);
       
  4588 //
       
  4589 //                TInt viewerType(EFileBrowserCmdFileViewHex);
       
  4590 //
       
  4591 //                // check from mime type if it's text
       
  4592 //                TDataType dataType;
       
  4593 //                TUid appUid;
       
  4594 //                if (iEngine->LsSession().AppForDocument(fullPath, appUid, dataType) == KErrNone)
       
  4595 //                    {
       
  4596 //                    TBuf<128> mimeTypeBuf;
       
  4597 //                    mimeTypeBuf.Copy(dataType.Des8());
       
  4598 //                    if (mimeTypeBuf == KNullDesC)
       
  4599 //                        mimeTypeBuf.Copy(_L("N/A"));
       
  4600 //
       
  4601 //                    if (mimeTypeBuf.CompareF(_L("text/plain")) == 0)
       
  4602 //                        viewerType = EFileBrowserCmdFileViewText;
       
  4603 //                    }
       
  4604 //
       
  4605 //                FileEditorL(viewerType);
       
  4606 //                }
       
  4607 //
       
  4608 //            else if (queryIndex == ECommonFileActionOpenWithApparc)
       
  4609 //                {
       
  4610 //                // TODO
       
  4611 //                //OpenWithApparcL();
       
  4612 //                }
       
  4613 //
       
  4614 //            else if (queryIndex == ECommonFileActionOpenWithDocHandlerEmbed)
       
  4615 //                {
       
  4616 //                // TODO
       
  4617 //                //OpenWithDocHandlerL(ETrue);
       
  4618 //                }
       
  4619 //
       
  4620 //            else
       
  4621 //                User::Panic(_L("Unk.Com.Act"), 221);
       
  4622 //            }
       
  4623         }
       
  4624     }
       
  4625     
       
  4626 // --------------------------------------------------------------------------------------------
       
  4627 	            
       
  4628 // End of File