filebrowser/engine/engine.cpp
branchRCL_3
changeset 22 fad26422216a
parent 21 b3cee849fa46
child 23 f8280f3bfeb7
equal deleted inserted replaced
21:b3cee849fa46 22:fad26422216a
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 
       
    20 #include "engine.h"
       
    21 
       
    22 //#include "FBApp.h"
       
    23 #include "FB.hrh"
       
    24 #include "FBFileUtils.h"
       
    25 #include "FBStd.h"
       
    26 //#include <filebrowser.rsg>
       
    27 
       
    28 #include <eikenv.h>
       
    29 #include <coeutils.h>
       
    30 #include <bautils.h>
       
    31 #include <apaid.h>
       
    32 #include <s32file.h>
       
    33 
       
    34 // CONSTANTS
       
    35 // UID of the application
       
    36 const TUid KUidFileBrowser = { 0x102828D6 };
       
    37 
       
    38 const TInt KSettingsDrive = EDriveC;
       
    39 _LIT(KSettingsFileName, "filebrowser_settings.ini");
       
    40 
       
    41 // ===================================== MEMBER FUNCTIONS =====================================
       
    42 
       
    43 CEngine* CEngine::NewL(MFileBrowserUI *aFileBrowserUI)
       
    44     {
       
    45     CEngine* self = new(ELeave) CEngine;
       
    46     CleanupStack::PushL(self);
       
    47     self->ConstructL(aFileBrowserUI);
       
    48     CleanupStack::Pop();
       
    49     return self;
       
    50     }
       
    51 
       
    52 // --------------------------------------------------------------------------------------------
       
    53 
       
    54 CEngine::CEngine()
       
    55     : iFileUtils(NULL)
       
    56     {
       
    57     }
       
    58 
       
    59 // --------------------------------------------------------------------------------------------
       
    60 
       
    61 void CEngine::ConstructL(MFileBrowserUI *aFileBrowserUI)
       
    62     {
       
    63     iFileBrowserUI = aFileBrowserUI;
       
    64     iEnv = CEikonEnv::Static();
       
    65     User::LeaveIfError(iLs.Connect());
       
    66     }
       
    67 
       
    68 // --------------------------------------------------------------------------------------------
       
    69 
       
    70 CEngine::~CEngine()
       
    71     {
       
    72 	if (iFileUtils != NULL)
       
    73 	    delete iFileUtils;
       
    74 
       
    75 	iLs.Close();
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 
       
    80 void CEngine::ActivateEngineL()
       
    81     {
       
    82     TRAP_IGNORE( LoadSettingsL() );
       
    83 
       
    84     iFileUtils = CFileBrowserFileUtils::NewL(this);
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 
       
    89 void CEngine::DeActivateEngineL()
       
    90     {
       
    91     }
       
    92 	
       
    93 // ---------------------------------------------------------------------------
       
    94 
       
    95 void CEngine::LoadDFSValueL(CDictionaryFileStore* aDicFS, const TUid& aUid, TInt& aValue)
       
    96     {
       
    97     if (aDicFS->IsPresentL(aUid))
       
    98         {
       
    99         RDictionaryReadStream in;
       
   100         in.OpenLC(*aDicFS, aUid);
       
   101         aValue = in.ReadInt16L();
       
   102         CleanupStack::PopAndDestroy(); // in        
       
   103         }
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 
       
   108 void CEngine::LoadDFSValueL(CDictionaryFileStore* aDicFS, const TUid& aUid, TDes& aValue)
       
   109     {
       
   110     if (aDicFS->IsPresentL(aUid))
       
   111         {
       
   112         RDictionaryReadStream in;
       
   113         in.OpenLC(*aDicFS, aUid);
       
   114         TInt bufLength = in.ReadInt16L();   // get length of descriptor
       
   115         in.ReadL(aValue, bufLength);        // get the descriptor itself
       
   116         CleanupStack::PopAndDestroy(); // in
       
   117         }
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 
       
   122 void CEngine::SaveDFSValueL(CDictionaryFileStore* aDicFS, const TUid& aUid, const TInt& aValue)
       
   123     {
       
   124     RDictionaryWriteStream out;
       
   125     out.AssignLC(*aDicFS, aUid);
       
   126     out.WriteInt16L(aValue);
       
   127     out.CommitL(); 	
       
   128     CleanupStack::PopAndDestroy(1);// out
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 
       
   133 void CEngine::SaveDFSValueL(CDictionaryFileStore* aDicFS, const TUid& aUid, const TDes& aValue)
       
   134     {
       
   135     RDictionaryWriteStream out;
       
   136     out.AssignLC(*aDicFS, aUid);
       
   137     out.WriteInt16L(aValue.Length());       // write length of the descriptor
       
   138     out.WriteL(aValue, aValue.Length());    // write the descriptor itself
       
   139     out.CommitL(); 	
       
   140     CleanupStack::PopAndDestroy(1);// out
       
   141     }
       
   142         
       
   143 // --------------------------------------------------------------------------------------------
       
   144 
       
   145 void CEngine::LoadSettingsL()
       
   146     {
       
   147     const TSize screenSize = iEnv->ScreenDevice()->SizeInPixels();
       
   148 
       
   149     // set defaults
       
   150     iSettings.iDisplayMode = EDisplayModeFullScreen;
       
   151     iSettings.iFileViewMode = IsQHD(screenSize) ? EFileViewModeExtended : EFileViewModeSimple;
       
   152     iSettings.iShowSubDirectoryInfo = EFalse;
       
   153     iSettings.iShowAssociatedIcons = EFalse;
       
   154     iSettings.iRememberLastPath = EFalse;
       
   155     iSettings.iLastPath = KNullDesC;
       
   156     iSettings.iRememberFolderSelection = ETrue;
       
   157 //#if 0 // TODO
       
   158 //#if(!defined __SERIES60_30__ && !defined __SERIES60_31__ && !defined __S60_32__)
       
   159 //    if ( AknLayoutUtils::PenEnabled() )
       
   160 //        {
       
   161 //        iSettings.iEnableToolbar = ETrue;
       
   162 //        }
       
   163 //    else
       
   164 //        {
       
   165 //        iSettings.iEnableToolbar = EFalse;
       
   166 //        }
       
   167 //#else
       
   168 //    iSettings.iEnableToolbar = EFalse;
       
   169 //#endif
       
   170 //#endif // TODO
       
   171 
       
   172     iSettings.iSupportNetworkDrives = EFalse;
       
   173     iSettings.iBypassPlatformSecurity = EFalse;
       
   174     iSettings.iRemoveFileLocks = ETrue;
       
   175     iSettings.iIgnoreProtectionsAtts = ETrue;
       
   176     iSettings.iRemoveROMWriteProrection = ETrue;
       
   177 
       
   178     // build specific defaults
       
   179 #if(!defined __SERIES60_30__ && !defined __SERIES60_31__)
       
   180     iSettings.iSupportNetworkDrives = ETrue;
       
   181 #endif 
       
   182 
       
   183 
       
   184     // make sure that the private path of this app in c-drive exists
       
   185     iEnv->FsSession().CreatePrivatePath( KSettingsDrive ); // c:\\private\\102828d6\\
       
   186     
       
   187     // handle settings always in the private directory 
       
   188     if (iEnv->FsSession().SetSessionToPrivate( KSettingsDrive ) == KErrNone)
       
   189         {
       
   190         // open or create a dictionary file store
       
   191         CDictionaryFileStore* settingsStore = CDictionaryFileStore::OpenLC(iEnv->FsSession(), KSettingsFileName, KUidFileBrowser);
       
   192 
       
   193         LoadDFSValueL(settingsStore, KFBSettingDisplayMode,                 iSettings.iDisplayMode);
       
   194         LoadDFSValueL(settingsStore, KFBSettingFileViewMode,                iSettings.iFileViewMode);
       
   195         LoadDFSValueL(settingsStore, KFBSettingShowSubDirectoryInfo,        iSettings.iShowSubDirectoryInfo);
       
   196         LoadDFSValueL(settingsStore, KFBSettingShowAssociatedIcons,         iSettings.iShowAssociatedIcons);
       
   197         LoadDFSValueL(settingsStore, KFBSettingRememberLastPath,            iSettings.iRememberLastPath);
       
   198         LoadDFSValueL(settingsStore, KFBSettingLastPath,                    iSettings.iLastPath);
       
   199         LoadDFSValueL(settingsStore, KFBSettingFolderSelection,             iSettings.iRememberFolderSelection);
       
   200         LoadDFSValueL(settingsStore, KFBSettingEnableToolbar,               iSettings.iEnableToolbar);
       
   201 
       
   202         LoadDFSValueL(settingsStore, KFBSettingSupportNetworkDrives,        iSettings.iSupportNetworkDrives);
       
   203         LoadDFSValueL(settingsStore, KFBSettingBypassPlatformSecurity,      iSettings.iBypassPlatformSecurity);
       
   204         LoadDFSValueL(settingsStore, KFBSettingRemoveFileLocks,             iSettings.iRemoveFileLocks);
       
   205         LoadDFSValueL(settingsStore, KFBSettingIgnoreProtectionsAtts,       iSettings.iIgnoreProtectionsAtts);
       
   206         LoadDFSValueL(settingsStore, KFBSettingRemoveROMWriteProtection,    iSettings.iRemoveROMWriteProrection);
       
   207 
       
   208         CleanupStack::PopAndDestroy(); // settingsStore         
       
   209         }
       
   210     }
       
   211 
       
   212 // --------------------------------------------------------------------------------------------
       
   213 
       
   214 void CEngine::SaveSettingsL(TBool aNotifyModules)
       
   215     {
       
   216     // handle settings always in c:\\private\\102828d6\\
       
   217     if (iEnv->FsSession().SetSessionToPrivate( KSettingsDrive ) == KErrNone)
       
   218         {
       
   219         // delete existing store to make sure that it is clean and not eg corrupted
       
   220         if (BaflUtils::FileExists(iEnv->FsSession(), KSettingsFileName))
       
   221             {
       
   222             iEnv->FsSession().Delete(KSettingsFileName);
       
   223             }
       
   224         
       
   225         // create a dictionary file store
       
   226         CDictionaryFileStore* settingsStore = CDictionaryFileStore::OpenLC(iEnv->FsSession(), KSettingsFileName, KUidFileBrowser);
       
   227 
       
   228         SaveDFSValueL(settingsStore, KFBSettingDisplayMode,                 iSettings.iDisplayMode);
       
   229         SaveDFSValueL(settingsStore, KFBSettingFileViewMode,                iSettings.iFileViewMode);
       
   230         SaveDFSValueL(settingsStore, KFBSettingShowSubDirectoryInfo,        iSettings.iShowSubDirectoryInfo);
       
   231         SaveDFSValueL(settingsStore, KFBSettingShowAssociatedIcons,         iSettings.iShowAssociatedIcons);
       
   232         SaveDFSValueL(settingsStore, KFBSettingRememberLastPath,            iSettings.iRememberLastPath);
       
   233         SaveDFSValueL(settingsStore, KFBSettingLastPath,                    iSettings.iLastPath);
       
   234         SaveDFSValueL(settingsStore, KFBSettingFolderSelection,             iSettings.iRememberFolderSelection);
       
   235         SaveDFSValueL(settingsStore, KFBSettingEnableToolbar,               iSettings.iEnableToolbar);
       
   236 
       
   237         SaveDFSValueL(settingsStore, KFBSettingSupportNetworkDrives,        iSettings.iSupportNetworkDrives);
       
   238         SaveDFSValueL(settingsStore, KFBSettingBypassPlatformSecurity,      iSettings.iBypassPlatformSecurity);
       
   239         SaveDFSValueL(settingsStore, KFBSettingRemoveFileLocks,             iSettings.iRemoveFileLocks);
       
   240         SaveDFSValueL(settingsStore, KFBSettingIgnoreProtectionsAtts,       iSettings.iIgnoreProtectionsAtts);
       
   241         SaveDFSValueL(settingsStore, KFBSettingRemoveROMWriteProtection,    iSettings.iRemoveROMWriteProrection);
       
   242         
       
   243         settingsStore->CommitL();
       
   244         CleanupStack::PopAndDestroy(); // settingsStore             
       
   245         }
       
   246 
       
   247     // update changes to modules
       
   248     if (aNotifyModules)
       
   249         {
       
   250         //iScreenCapture->HandleSettingsChangeL();
       
   251         if (iFileUtils != NULL) 
       
   252 			{
       
   253 			iFileUtils->HandleSettingsChangeL();
       
   254 			}
       
   255         //iFileListContainer->HandleSettingsChangeL();
       
   256         }
       
   257     }
       
   258 
       
   259 // --------------------------------------------------------------------------------------------
       
   260 
       
   261 TInt CEngine::LaunchSettingsDialogL()
       
   262     {
       
   263 	TInt retValue = KErrNone;
       
   264 	// TODO:
       
   265     // set to normal mode
       
   266     //iFileListContainer->SetScreenLayoutL(EDisplayModeNormal);
       
   267     //iFileListContainer->DeleteNaviPane();
       
   268     //iFileListContainer->HideToolbar();
       
   269     
       
   270     // launch the dialog and save settings
       
   271     //CFileBrowserSettingViewDlg* dlg = CFileBrowserSettingViewDlg::NewL(iSettings);
       
   272     //TInt retValue = dlg->ExecuteLD(R_FILEBROWSER_SETTINGS_DIALOG);        
       
   273     //FileListContainer()->CreateEmptyNaviPaneLabelL();
       
   274     TRAP_IGNORE(SaveSettingsL());
       
   275     return retValue;
       
   276     }
       
   277 	
       
   278 // --------------------------------------------------------------------------------------------
       
   279 // --------------------------------------------------------------------------------------------
       
   280 
       
   281 CAsyncWaiter* CAsyncWaiter::NewL(TInt aPriority)
       
   282 	{
       
   283 	CAsyncWaiter* self = new(ELeave) CAsyncWaiter(aPriority);
       
   284 	return self;
       
   285 	}
       
   286 
       
   287 CAsyncWaiter* CAsyncWaiter::NewLC(TInt aPriority)
       
   288 	{
       
   289 	CAsyncWaiter* self = new(ELeave) CAsyncWaiter(aPriority);
       
   290 	CleanupStack::PushL(self);
       
   291 	return self;
       
   292 	}
       
   293 	
       
   294 CAsyncWaiter::CAsyncWaiter(TInt aPriority) : CActive(aPriority)
       
   295 	{
       
   296 	CActiveScheduler::Add(this);
       
   297 	}	
       
   298 
       
   299 CAsyncWaiter::~CAsyncWaiter()
       
   300 	{
       
   301 	Cancel();
       
   302 	}
       
   303 	
       
   304 void CAsyncWaiter::StartAndWait()
       
   305 	{
       
   306         iStatus = KRequestPending;
       
   307         SetActive();
       
   308         iWait.Start();
       
   309 	}
       
   310 	
       
   311 TInt CAsyncWaiter::Result() const
       
   312 	{
       
   313 	return iError;
       
   314 	}
       
   315 	
       
   316 void CAsyncWaiter::RunL()
       
   317 	{
       
   318 	iError = iStatus.Int();
       
   319 	//CAknEnv::StopSchedulerWaitWithBusyMessage( iWait );
       
   320 	iWait.AsyncStop();
       
   321 	}
       
   322 	
       
   323 void CAsyncWaiter::DoCancel()
       
   324 	{
       
   325 	iError = KErrCancel;
       
   326     if( iStatus == KRequestPending )
       
   327         {
       
   328         TRequestStatus* s=&iStatus;
       
   329         User::RequestComplete( s, KErrCancel );
       
   330         }
       
   331 
       
   332         //CAknEnv::StopSchedulerWaitWithBusyMessage( iWait );
       
   333 	iWait.AsyncStop();
       
   334 	}
       
   335 
       
   336 // --------------------------------------------------------------------------------------------
       
   337 
       
   338 void CEngine::OpenWithApparcL(TFileName aFileName)
       
   339         {
       
   340 	if (iFileUtils != NULL) 
       
   341 		{
       
   342 		iFileUtils->OpenWithApparcL(aFileName);
       
   343 		}
       
   344 	}
       
   345 
       
   346 // --------------------------------------------------------------------------------------------
       
   347 
       
   348 void CEngine::OpenWithDocHandlerL(TFileName aFileName, TBool aEmbed)
       
   349         {
       
   350 	if (iFileUtils != NULL) 
       
   351 		{
       
   352 		iFileUtils->OpenWithDocHandlerL(aFileName, aEmbed);
       
   353 		}
       
   354 	}
       
   355 
       
   356 // --------------------------------------------------------------------------------------------
       
   357 
       
   358 //TInt CEngine::QueryCurrentItemIndex()
       
   359 //	{
       
   360 //        return iFileBrowserUI->QueryCurrentItemIndex();
       
   361 //	}
       
   362 
       
   363 // --------------------------------------------------------------------------------------------	
       
   364 
       
   365 TSearchAttributes CEngine::GetSearchAttributes()
       
   366 	{
       
   367 	if (iFileUtils != NULL) 
       
   368 		{
       
   369 		return iFileUtils->GetSearchAttributes();
       
   370 		} 
       
   371 	else
       
   372 		{
       
   373 		return TSearchAttributes(); 
       
   374 		}
       
   375 	}
       
   376 
       
   377 // --------------------------------------------------------------------------------------------	
       
   378 
       
   379 void CEngine::ChangeAttributes(TSearchAttributes attributes) 
       
   380 	{ 
       
   381 	if (iFileUtils != NULL) 
       
   382 		{
       
   383 		iFileUtils->ChangeAttributes(attributes); 
       
   384 		}
       
   385 	}
       
   386 
       
   387 // --------------------------------------------------------------------------------------------	
       
   388 
       
   389 TSearchResults CEngine::SearchResults() 
       
   390 	{ 
       
   391 	if (iFileUtils != NULL) 
       
   392 		{
       
   393 		return iFileUtils->SearchResults(); 
       
   394 		}
       
   395 	else
       
   396 		{
       
   397 		return TSearchResults();
       
   398 		}
       
   399 	}
       
   400 
       
   401 // --------------------------------------------------------------------------------------------	
       
   402 
       
   403 CFileEntryList* CEngine::FoundFiles() 
       
   404 	{ 
       
   405 	if (iFileUtils != NULL) 
       
   406 		{
       
   407 		return iFileUtils->FoundFiles(); 
       
   408 		}
       
   409 	else 
       
   410 		{
       
   411 		return NULL;
       
   412 		}
       
   413 	}
       
   414 	
       
   415 // --------------------------------------------------------------------------------------------	
       
   416 
       
   417 void CEngine::SearchL() 
       
   418 	{ 
       
   419 	if (iFileUtils != NULL) 
       
   420 		{
       
   421 		TRAP_IGNORE(iFileUtils->SearchL()); 
       
   422 		}
       
   423 	}
       
   424 	
       
   425 // --------------------------------------------------------------------------------------------	
       
   426 	
       
   427 // End of File