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