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