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