filebrowser/src/FBModel.cpp
changeset 0 d6fe6244b863
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 
       
    21 #include "FBModel.h"
       
    22 #include "FBApp.h"
       
    23 #include "FB.hrh"
       
    24 #include "FBSettingViewDlg.h"
       
    25 #include "FBFileUtils.h"
       
    26 #include "FBFileListContainer.h"
       
    27 #include "FBStd.h"
       
    28 #include <filebrowser.rsg>
       
    29 
       
    30 #include <coeutils.h>
       
    31 #include <bautils.h>
       
    32 #include <apaid.h>
       
    33 #include <AknGlobalConfirmationQuery.h>
       
    34 #include <s32file.h>
       
    35 
       
    36 // hash key selection related includes
       
    37 #ifndef __SERIES60_30__
       
    38   #include <centralrepository.h>
       
    39   #include <AknFepInternalCRKeys.h>
       
    40   #include <AvkonInternalCRKeys.h>
       
    41   #include <e32property.h> 
       
    42 #endif
       
    43 
       
    44 const TInt KSettingsDrive = EDriveC;
       
    45 _LIT(KSettingsFileName, "filebrowser_settings.ini");
       
    46 
       
    47 // ===================================== MEMBER FUNCTIONS =====================================
       
    48 
       
    49 CFileBrowserModel* CFileBrowserModel::NewL()
       
    50 	{
       
    51 	CFileBrowserModel* self = new(ELeave) CFileBrowserModel;
       
    52 	CleanupStack::PushL(self);
       
    53 	self->ConstructL();
       
    54 	CleanupStack::Pop();
       
    55 	return self;
       
    56 	}
       
    57 
       
    58 // --------------------------------------------------------------------------------------------
       
    59 
       
    60 CFileBrowserModel::CFileBrowserModel()
       
    61 	{
       
    62 	}
       
    63 
       
    64 // --------------------------------------------------------------------------------------------
       
    65 
       
    66 void CFileBrowserModel::ConstructL()
       
    67 	{
       
    68     iEnv = CEikonEnv::Static();
       
    69     User::LeaveIfError(iLs.Connect());
       
    70 	}
       
    71 
       
    72 // --------------------------------------------------------------------------------------------
       
    73 
       
    74 CFileBrowserModel::~CFileBrowserModel()
       
    75 	{
       
    76 	if (iFileUtils)
       
    77 	    delete iFileUtils;
       
    78 
       
    79 	iLs.Close();
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 
       
    84 void CFileBrowserModel::ActivateModelL()
       
    85 	{
       
    86     TRAP_IGNORE( LoadSettingsL() );
       
    87 
       
    88     iFileUtils = CFileBrowserFileUtils::NewL(this);
       
    89     
       
    90     // get hash key selection value
       
    91     GetHashKeySelectionStatus();
       
    92 	}
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 
       
    96 void CFileBrowserModel::DeActivateModelL()
       
    97 	{
       
    98 	}
       
    99 	
       
   100 // --------------------------------------------------------------------------------------------
       
   101 
       
   102 void CFileBrowserModel::SetFileListContainer(CFileBrowserFileListContainer* aFileListContainer)
       
   103     {
       
   104     iFileListContainer = aFileListContainer;
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 
       
   109 void CFileBrowserModel::LoadDFSValueL(CDictionaryFileStore* aDicFS, const TUid& aUid, TInt& aValue)
       
   110     {
       
   111     if (aDicFS->IsPresentL(aUid))
       
   112         {
       
   113         RDictionaryReadStream in;
       
   114         in.OpenLC(*aDicFS, aUid);
       
   115         aValue = in.ReadInt16L();
       
   116         CleanupStack::PopAndDestroy(); // in        
       
   117         }
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 
       
   122 void CFileBrowserModel::LoadDFSValueL(CDictionaryFileStore* aDicFS, const TUid& aUid, TDes& aValue)
       
   123     {
       
   124     if (aDicFS->IsPresentL(aUid))
       
   125         {
       
   126         RDictionaryReadStream in;
       
   127         in.OpenLC(*aDicFS, aUid);
       
   128         TInt bufLength = in.ReadInt16L();   // get length of descriptor
       
   129         in.ReadL(aValue, bufLength);        // get the descriptor itself
       
   130         CleanupStack::PopAndDestroy(); // in
       
   131         }
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 
       
   136 void CFileBrowserModel::SaveDFSValueL(CDictionaryFileStore* aDicFS, const TUid& aUid, const TInt& aValue)
       
   137     {
       
   138     RDictionaryWriteStream out;
       
   139     out.AssignLC(*aDicFS, aUid);
       
   140     out.WriteInt16L(aValue);
       
   141     out.CommitL(); 	
       
   142     CleanupStack::PopAndDestroy(1);// out
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 
       
   147 void CFileBrowserModel::SaveDFSValueL(CDictionaryFileStore* aDicFS, const TUid& aUid, const TDes& aValue)
       
   148     {
       
   149     RDictionaryWriteStream out;
       
   150     out.AssignLC(*aDicFS, aUid);
       
   151     out.WriteInt16L(aValue.Length());       // write length of the descriptor
       
   152     out.WriteL(aValue, aValue.Length());    // write the descriptor itself
       
   153     out.CommitL(); 	
       
   154     CleanupStack::PopAndDestroy(1);// out
       
   155     }
       
   156         
       
   157 // --------------------------------------------------------------------------------------------
       
   158 
       
   159 void CFileBrowserModel::LoadSettingsL()
       
   160     {
       
   161     const TSize screenSize = iEnv->ScreenDevice()->SizeInPixels();
       
   162 
       
   163     // set defaults
       
   164     iSettings.iDisplayMode = EDisplayModeFullScreen;
       
   165     iSettings.iFileViewMode = IsQHD(screenSize) ? EFileViewModeExtended : EFileViewModeSimple;
       
   166     iSettings.iShowSubDirectoryInfo = EFalse;
       
   167     iSettings.iShowAssociatedIcons = EFalse;
       
   168     iSettings.iRememberLastPath = EFalse;
       
   169     iSettings.iLastPath = KNullDesC;
       
   170     iSettings.iRememberFolderSelection = ETrue;
       
   171 #if(!defined __SERIES60_30__ && !defined __SERIES60_31__ && !defined __S60_32__)
       
   172     if ( AknLayoutUtils::PenEnabled() )
       
   173         {
       
   174         iSettings.iEnableToolbar = ETrue;
       
   175         }
       
   176     else
       
   177         {
       
   178         iSettings.iEnableToolbar = EFalse;
       
   179         }
       
   180 #else
       
   181     iSettings.iEnableToolbar = EFalse;
       
   182 #endif
       
   183 
       
   184     iSettings.iSupportNetworkDrives = EFalse;
       
   185     iSettings.iBypassPlatformSecurity = EFalse;
       
   186     iSettings.iRemoveFileLocks = ETrue;
       
   187     iSettings.iIgnoreProtectionsAtts = ETrue;
       
   188     iSettings.iRemoveROMWriteProrection = ETrue;
       
   189 
       
   190     // build specific defaults
       
   191 #if(!defined __SERIES60_30__ && !defined __SERIES60_31__)
       
   192     iSettings.iSupportNetworkDrives = ETrue;
       
   193 #endif 
       
   194 
       
   195 
       
   196     // make sure that the private path of this app in c-drive exists
       
   197     iEnv->FsSession().CreatePrivatePath( KSettingsDrive ); // c:\\private\\102828d6\\
       
   198     
       
   199     // handle settings always in the private directory 
       
   200     if (iEnv->FsSession().SetSessionToPrivate( KSettingsDrive ) == KErrNone)
       
   201         {
       
   202         // open or create a dictionary file store
       
   203         CDictionaryFileStore* settingsStore = CDictionaryFileStore::OpenLC(iEnv->FsSession(), KSettingsFileName, KUidFileBrowser);
       
   204 
       
   205         LoadDFSValueL(settingsStore, KFBSettingDisplayMode,                 iSettings.iDisplayMode);
       
   206         LoadDFSValueL(settingsStore, KFBSettingFileViewMode,                iSettings.iFileViewMode);
       
   207         LoadDFSValueL(settingsStore, KFBSettingShowSubDirectoryInfo,        iSettings.iShowSubDirectoryInfo);
       
   208         LoadDFSValueL(settingsStore, KFBSettingShowAssociatedIcons,         iSettings.iShowAssociatedIcons);
       
   209         LoadDFSValueL(settingsStore, KFBSettingRememberLastPath,            iSettings.iRememberLastPath);
       
   210         LoadDFSValueL(settingsStore, KFBSettingLastPath,                    iSettings.iLastPath);
       
   211         LoadDFSValueL(settingsStore, KFBSettingFolderSelection,             iSettings.iRememberFolderSelection);
       
   212         LoadDFSValueL(settingsStore, KFBSettingEnableToolbar,               iSettings.iEnableToolbar);
       
   213 
       
   214         LoadDFSValueL(settingsStore, KFBSettingSupportNetworkDrives,        iSettings.iSupportNetworkDrives);
       
   215         LoadDFSValueL(settingsStore, KFBSettingBypassPlatformSecurity,      iSettings.iBypassPlatformSecurity);
       
   216         LoadDFSValueL(settingsStore, KFBSettingRemoveFileLocks,             iSettings.iRemoveFileLocks);
       
   217         LoadDFSValueL(settingsStore, KFBSettingIgnoreProtectionsAtts,       iSettings.iIgnoreProtectionsAtts);
       
   218         LoadDFSValueL(settingsStore, KFBSettingRemoveROMWriteProtection,    iSettings.iRemoveROMWriteProrection);
       
   219 
       
   220         CleanupStack::PopAndDestroy(); // settingsStore         
       
   221         }
       
   222     }
       
   223 
       
   224 // --------------------------------------------------------------------------------------------
       
   225 
       
   226 void CFileBrowserModel::SaveSettingsL(TBool aNotifyModules)
       
   227     {
       
   228     // handle settings always in c:\\private\\102828d6\\
       
   229     if (iEnv->FsSession().SetSessionToPrivate( KSettingsDrive ) == KErrNone)
       
   230         {
       
   231         // delete existing store to make sure that it is clean and not eg corrupted
       
   232         if (BaflUtils::FileExists(iEnv->FsSession(), KSettingsFileName))
       
   233             {
       
   234             iEnv->FsSession().Delete(KSettingsFileName);
       
   235             }
       
   236         
       
   237         // create a dictionary file store
       
   238         CDictionaryFileStore* settingsStore = CDictionaryFileStore::OpenLC(iEnv->FsSession(), KSettingsFileName, KUidFileBrowser);
       
   239 
       
   240         SaveDFSValueL(settingsStore, KFBSettingDisplayMode,                 iSettings.iDisplayMode);
       
   241         SaveDFSValueL(settingsStore, KFBSettingFileViewMode,                iSettings.iFileViewMode);
       
   242         SaveDFSValueL(settingsStore, KFBSettingShowSubDirectoryInfo,        iSettings.iShowSubDirectoryInfo);
       
   243         SaveDFSValueL(settingsStore, KFBSettingShowAssociatedIcons,         iSettings.iShowAssociatedIcons);
       
   244         SaveDFSValueL(settingsStore, KFBSettingRememberLastPath,            iSettings.iRememberLastPath);
       
   245         SaveDFSValueL(settingsStore, KFBSettingLastPath,                    iSettings.iLastPath);
       
   246         SaveDFSValueL(settingsStore, KFBSettingFolderSelection,             iSettings.iRememberFolderSelection);
       
   247         SaveDFSValueL(settingsStore, KFBSettingEnableToolbar,               iSettings.iEnableToolbar);
       
   248 
       
   249         SaveDFSValueL(settingsStore, KFBSettingSupportNetworkDrives,        iSettings.iSupportNetworkDrives);
       
   250         SaveDFSValueL(settingsStore, KFBSettingBypassPlatformSecurity,      iSettings.iBypassPlatformSecurity);
       
   251         SaveDFSValueL(settingsStore, KFBSettingRemoveFileLocks,             iSettings.iRemoveFileLocks);
       
   252         SaveDFSValueL(settingsStore, KFBSettingIgnoreProtectionsAtts,       iSettings.iIgnoreProtectionsAtts);
       
   253         SaveDFSValueL(settingsStore, KFBSettingRemoveROMWriteProtection,    iSettings.iRemoveROMWriteProrection);
       
   254         
       
   255         settingsStore->CommitL();
       
   256         CleanupStack::PopAndDestroy(); // settingsStore             
       
   257         }
       
   258 
       
   259     // update changes to modules
       
   260     if (aNotifyModules)
       
   261         {
       
   262         //iScreenCapture->HandleSettingsChangeL();
       
   263         iFileUtils->HandleSettingsChangeL();
       
   264         iFileListContainer->HandleSettingsChangeL();
       
   265         }
       
   266     }
       
   267 
       
   268 // --------------------------------------------------------------------------------------------
       
   269 
       
   270 void CFileBrowserModel::GetHashKeySelectionStatus()
       
   271     {
       
   272     TBool hashKeySelectionInUse(EFalse);
       
   273     
       
   274 #ifndef __SERIES60_30__
       
   275     
       
   276     // get hash key selection value
       
   277     TRAP_IGNORE(
       
   278         CRepository* repository = CRepository::NewLC(KCRUidAknFep);
       
   279         repository->Get(KAknFepHashKeySelection, hashKeySelectionInUse);
       
   280         CleanupStack::PopAndDestroy();
       
   281     );
       
   282     
       
   283     // even if hash key selection is in use, ignore the value in qwerty mode
       
   284     if (hashKeySelectionInUse)
       
   285         {
       
   286         TBool qwertyMode(EFalse);
       
   287         RProperty qwertyModeStatusProperty;
       
   288         qwertyModeStatusProperty.Attach(KCRUidAvkon, KAknQwertyInputModeActive);
       
   289         qwertyModeStatusProperty.Get(qwertyMode);
       
   290         qwertyModeStatusProperty.Close();
       
   291         
       
   292         if (qwertyMode)
       
   293             hashKeySelectionInUse = EFalse;        
       
   294         }
       
   295 
       
   296 #endif
       
   297 
       
   298     iIsHashKeySelectionInUse = hashKeySelectionInUse;
       
   299     }
       
   300     	
       
   301 // --------------------------------------------------------------------------------------------
       
   302 
       
   303 TInt CFileBrowserModel::LaunchSettingsDialogL()
       
   304     {
       
   305     // set to normal mode
       
   306     iFileListContainer->SetScreenLayoutL(EDisplayModeNormal);
       
   307     iFileListContainer->DeleteNaviPane();
       
   308     iFileListContainer->HideToolbar();
       
   309     
       
   310     // launch the dialog and save settings
       
   311     CFileBrowserSettingViewDlg* dlg = CFileBrowserSettingViewDlg::NewL(iSettings);
       
   312     TInt retValue = dlg->ExecuteLD(R_FILEBROWSER_SETTINGS_DIALOG);        
       
   313     FileListContainer()->CreateEmptyNaviPaneLabelL();
       
   314     TRAP_IGNORE(SaveSettingsL());
       
   315     return retValue;
       
   316     }
       
   317 	
       
   318 // --------------------------------------------------------------------------------------------
       
   319 // --------------------------------------------------------------------------------------------
       
   320 
       
   321 CAsyncWaiter* CAsyncWaiter::NewL(TInt aPriority)
       
   322 	{
       
   323 	CAsyncWaiter* self = new(ELeave) CAsyncWaiter(aPriority);
       
   324 	return self;
       
   325 	}
       
   326 
       
   327 CAsyncWaiter* CAsyncWaiter::NewLC(TInt aPriority)
       
   328 	{
       
   329 	CAsyncWaiter* self = new(ELeave) CAsyncWaiter(aPriority);
       
   330 	CleanupStack::PushL(self);
       
   331 	return self;
       
   332 	}
       
   333 	
       
   334 CAsyncWaiter::CAsyncWaiter(TInt aPriority) : CActive(aPriority)
       
   335 	{
       
   336 	CActiveScheduler::Add(this);
       
   337 	}	
       
   338 
       
   339 CAsyncWaiter::~CAsyncWaiter()
       
   340 	{
       
   341 	Cancel();
       
   342 	}
       
   343 	
       
   344 void CAsyncWaiter::StartAndWait()
       
   345 	{
       
   346     iStatus = KRequestPending;
       
   347     SetActive();
       
   348     iWait.Start();
       
   349 	}
       
   350 	
       
   351 TInt CAsyncWaiter::Result() const
       
   352 	{
       
   353 	return iError;
       
   354 	}
       
   355 	
       
   356 void CAsyncWaiter::RunL()
       
   357 	{
       
   358 	iError = iStatus.Int();
       
   359 	CAknEnv::StopSchedulerWaitWithBusyMessage( iWait );
       
   360 	}
       
   361 	
       
   362 void CAsyncWaiter::DoCancel()
       
   363 	{
       
   364 	iError = KErrCancel;
       
   365     if( iStatus == KRequestPending )
       
   366         {
       
   367         TRequestStatus* s=&iStatus;
       
   368         User::RequestComplete( s, KErrCancel );
       
   369         }
       
   370 
       
   371     CAknEnv::StopSchedulerWaitWithBusyMessage( iWait );
       
   372 	}
       
   373 
       
   374 // --------------------------------------------------------------------------------------------
       
   375 
       
   376 // End of File