voicerecorder/AppSrc/CVRSettingsDialogMMCSupported.cpp
changeset 0 845549f293a7
child 5 35a9006a7fc7
equal deleted inserted replaced
-1:000000000000 0:845549f293a7
       
     1 /*
       
     2 * Copyright (c) 2002-2006 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 *     This class defines a settings dialog for the Voice Recorder application.
       
    16 *
       
    17 */
       
    18 
       
    19 #include <bldvariant.hrh>
       
    20 
       
    21 #include <aknlists.h>
       
    22 #include <featmgr.h>
       
    23 #include "CVRSettingsDialogMMCSupported.h"
       
    24 #include "voicerecorder.hrh"
       
    25 #include <voicerecorder.rsg>
       
    26 #include "VRConsts.h"
       
    27 #include "VRUtils.h"
       
    28 #include <hlplch.h>
       
    29 
       
    30 #include <CAknMemorySelectionSettingItem.h>
       
    31 #include <aknnotewrappers.h>
       
    32 #include <StringLoader.h>
       
    33 #include <AknCommonDialogsDynMem.h>
       
    34 
       
    35 #ifdef RD_MULTIPLE_DRIVE
       
    36 #include <AknCommonDialogsDynMem.h>
       
    37 #include <driveinfo.h>
       
    38 #include <CAknMemorySelectionDialogMultiDrive.h>
       
    39 #endif
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CVRSettingsDialog::~CVRSettingsDialog
       
    43 // 
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 CVRSettingsDialog::~CVRSettingsDialog()
       
    47     {
       
    48 	iSettingItemArray.ResetAndDestroy();
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CVRSettingsDialog::CVRSettingsDialog
       
    53 // 
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CVRSettingsDialog* CVRSettingsDialog::NewL()
       
    57     {
       
    58     CVRSettingsDialog* self = new( ELeave ) CVRSettingsDialog;
       
    59 	CleanupStack::PushL( self );
       
    60 	self->ConstructL( R_VR_SETTINGS_MENUBAR );
       
    61 	CleanupStack::Pop();
       
    62     return self;
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CVRSettingsDialog::OkToExitL
       
    67 // 
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 TBool CVRSettingsDialog::OkToExitL( TInt aButtonId )
       
    71 	{
       
    72 	if ( aButtonId == EAknSoftkeyOptions )
       
    73         {
       
    74         DisplayMenuL();
       
    75         return EFalse;
       
    76         }
       
    77 	
       
    78 	// If want to exit settings afterwards
       
    79 	TBool exitAfter( ETrue );
       
    80 	
       
    81 	// MSK button pressed in settings view
       
    82 	if ( aButtonId == ECmdMSK )
       
    83 		{
       
    84 		// A new key event is simulated
       
    85 		TKeyEvent key;
       
    86         key.iRepeats = 0;
       
    87         key.iCode = EKeyEnter;
       
    88         key.iModifiers = 0;
       
    89         CEikonEnv::Static()->SimulateKeyEventL( key, EEventKey );
       
    90 		
       
    91 
       
    92 		exitAfter = EFalse;	// No Exit
       
    93 		}
       
    94 	// Do not store settings anymore when exit
       
    95 	return exitAfter;
       
    96 	}
       
    97 
       
    98 
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // CVRSettingsDialog::PreLayoutDynInitL
       
   102 // Intialize layout
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 void CVRSettingsDialog::PreLayoutDynInitL()
       
   106 	{
       
   107     if ( VRUtils::FeatureEnabled( EVRFeatureShowQualitySetting ) )
       
   108         {
       
   109 	    iQuality = VRUtils::QualityL();
       
   110         }
       
   111     // Convert the internal memory enumeration to CFD enumeration
       
   112 #ifndef RD_MULTIPLE_DRIVE 
       
   113 	if ( VRUtils::MemoStoreL() == EMemoStorePhoneMemory )
       
   114 		{
       
   115 		iMemoStore = CAknMemorySelectionSettingPage::EPhoneMemory;
       
   116 		}
       
   117 	else
       
   118 		{
       
   119 		iMemoStore = CAknMemorySelectionSettingPage::EMemoryCard;
       
   120 		}
       
   121     
       
   122     // for multiple drives
       
   123 #else
       
   124     iDrive = (TDriveNumber)VRUtils::MemoDriveL();
       
   125     
       
   126 #endif
       
   127 
       
   128 	CAknSettingStyleListBox* listBox = static_cast< CAknSettingStyleListBox* >
       
   129 										( Control( EVRSettingsListboxId ) );
       
   130 	User::LeaveIfNull( listBox );
       
   131     CAknSettingItem* settingItem;
       
   132   
       
   133     HBufC* itemTitle;
       
   134    	TInt id( 0 );
       
   135     if ( VRUtils::FeatureEnabled( EVRFeatureShowQualitySetting ) )
       
   136         {
       
   137     	// Add quality setting
       
   138 #ifdef  __AAC_ENCODER_PLUGIN    	
       
   139     	settingItem = new( ELeave ) CAknEnumeratedTextPopupSettingItem ( 0, ( TInt& ) iQuality );
       
   140 
       
   141 #else
       
   142         settingItem = new( ELeave ) CAknBinaryPopupSettingItem ( 0, ( TInt& ) iQuality );
       
   143 #endif
       
   144 
       
   145     	CleanupStack::PushL( settingItem );
       
   146 
       
   147     	itemTitle = iCoeEnv->AllocReadResourceLC( R_QTN_VOREC_SET_QUALITY );
       
   148     	settingItem->ConstructL( EFalse, id, *itemTitle, NULL,
       
   149     	                     R_VR_SETTINGS_DEFAULT_SPEAKER_PAGE, EAknCtPopupField, NULL,
       
   150     						 R_VR_SETTINGS_QUALITY_TEXTS );
       
   151     	CleanupStack::PopAndDestroy();		// itemTitle
       
   152 
       
   153     	// Add quality item to the settings array
       
   154     	iSettingItemArray.AppendL( settingItem ); 
       
   155     	CleanupStack::Pop();	// settingItem
       
   156     	id++;
       
   157         }
       
   158 
       
   159 
       
   160 	// Create the memo store item
       
   161 	// Set memo store item's title
       
   162 	itemTitle = iCoeEnv->AllocReadResourceLC( R_QTN_VOREC_SET_STORE );
       
   163 
       
   164 #ifndef RD_MULTIPLE_DRIVE
       
   165 	settingItem = new( ELeave ) CAknMemorySelectionSettingItem( 0, iMemoStore );
       
   166 	CleanupStack::PushL( settingItem ); 
       
   167     settingItem->ConstructL( EFalse, id, *itemTitle, NULL,
       
   168        R_VOREC_MEMORY_SELECTION_DIALOG, EAknCtPopupSettingList );
       
   169 	// Add memo store item to the settings array
       
   170 	iSettingItemArray.AppendL( settingItem );
       
   171 	id++;
       
   172 	CleanupStack::Pop();	// settingItem
       
   173 
       
   174 #else    //multiple drives
       
   175 
       
   176 	CAknMemorySelectionDialogMultiDrive* dlg = CAknMemorySelectionDialogMultiDrive::NewL(
       
   177     ECFDDialogTypeNormal, 
       
   178     R_VOREC_MEMORY_SELECTION_DIALOG, // Default resource Id
       
   179     EFalse,
       
   180     AknCommonDialogsDynMem::EMemoryTypePhone |
       
   181     AknCommonDialogsDynMem::EMemoryTypeInternalMassStorage |
       
   182     AknCommonDialogsDynMem::EMemoryTypeMMCExternal);
       
   183 
       
   184     CleanupStack::PushL( dlg );
       
   185     TBool value = dlg->ExecuteL( iDrive );
       
   186     CleanupStack::PopAndDestroy( dlg );
       
   187     if (value)
       
   188      	{
       
   189         VRUtils::SetMemoDriveL( iDrive );
       
   190        	}
       
   191  
       
   192 #endif
       
   193 
       
   194 
       
   195 	CleanupStack::PopAndDestroy();	// itemTitle
       
   196 
       
   197 	CTextListBoxModel* model = listBox->Model();
       
   198 	model->SetItemTextArray( &iSettingItemArray );
       
   199 	// Ownership retained by us
       
   200 	model->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   201 
       
   202 	iSettingItemArray.RecalculateVisibleIndicesL();
       
   203 	listBox->CreateScrollBarFrameL( ETrue );
       
   204 	listBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   205 						CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   206 	listBox->HandleItemAdditionL();
       
   207 	listBox->SetListBoxObserver( this );
       
   208 	listBox->UpdateScrollBarsL();
       
   209 
       
   210 	}
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // CVRSettingsDialog::HandleListBoxEventL
       
   214 // 
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 void CVRSettingsDialog::HandleListBoxEventL( CEikListBox* aListBox, TListBoxEvent aEventType)
       
   218 	{
       
   219 
       
   220 	switch ( aEventType )
       
   221 		{
       
   222 		case EEventItemDoubleClicked: // Pointer events (highlighted item before pressing) 
       
   223 		case EEventEnterKeyPressed:	// Normal button presses
       
   224 		case EEventEditingStarted: // From ProcessCommand->ECmdChange
       
   225 			{
       
   226 			TInt index( aListBox->CurrentItemIndex() );
       
   227 			if ( index >=0 )	// index is -1 if there are no items in the list
       
   228 				{
       
   229 			    iSettingItemArray.At( index )->EditItemL( 
       
   230 				aEventType == EEventEditingStarted );
       
   231 			    aListBox->DrawItem( index );
       
   232 				}
       
   233 			StoreAllSettingsL();	
       
   234 			break;
       
   235 			}
       
   236 		default:
       
   237 			{
       
   238 			break;	
       
   239 			}
       
   240 		}
       
   241 
       
   242 	}
       
   243 
       
   244 // ---------------------------------------------------------------------------
       
   245 // CVRSettingsDialog::ProcessCommandL
       
   246 // 
       
   247 // ---------------------------------------------------------------------------
       
   248 //
       
   249 void CVRSettingsDialog::ProcessCommandL( TInt aCommandId )
       
   250 	{
       
   251 	HideMenu();
       
   252 	switch ( aCommandId )
       
   253 		{
       
   254 		case ECmdChange:
       
   255 			{
       
   256 			CEikListBox* listBox = static_cast< CEikListBox* >( Control( EVRSettingsListboxId ) );
       
   257 			HandleListBoxEventL( listBox, EEventEditingStarted );
       
   258 			StoreAllSettingsL();
       
   259 			break;
       
   260 			}
       
   261 		case EEikCmdExit:
       
   262 			{
       
   263 			TryExitL( EEikCmdExit );
       
   264 			CEikonEnv::Static()->EikAppUi()->HandleCommandL( aCommandId );
       
   265 			break;
       
   266 			}
       
   267 		default:
       
   268 			{
       
   269 			CEikonEnv::Static()->EikAppUi()->HandleCommandL( aCommandId );
       
   270 			break;
       
   271 			}
       
   272 		}
       
   273 	}
       
   274 
       
   275 // ---------------------------------------------------------------------------
       
   276 // CVRSettingsDialog::StoreAllSettingsL
       
   277 // Stores values in settings list to permanent storage
       
   278 // ---------------------------------------------------------------------------
       
   279 //
       
   280 void CVRSettingsDialog::StoreAllSettingsL()
       
   281     {
       
   282 
       
   283     TInt settingItemCount( iSettingItemArray.Count() );
       
   284 
       
   285 	for ( TInt i( 0 ); i < settingItemCount; i++ )
       
   286 		{
       
   287 		iSettingItemArray.At( i )->StoreL();
       
   288 		}
       
   289 
       
   290 #ifndef RD_MULTIPLE_DRIVE    
       
   291 	if ( iMemoStore == CAknMemorySelectionSettingPage::EPhoneMemory )
       
   292 		{
       
   293 		VRUtils::SetMemoStoreL( EMemoStorePhoneMemory );
       
   294 		}
       
   295 	else
       
   296 		{
       
   297 		// check if MMC is read-only
       
   298 		TVRDriveInfo mmcInfo;
       
   299 		VRUtils::GetMMCInfo( mmcInfo );
       
   300 
       
   301 		if ( mmcInfo.iDriveReadOnly )
       
   302 			{
       
   303 			HBufC* noteText = iCoeEnv->AllocReadResourceLC(
       
   304 													 R_QTN_MEMC_READONLY );
       
   305 			CAknInformationNote* infoNote =
       
   306 								new( ELeave ) CAknInformationNote( ETrue );
       
   307 			infoNote->ExecuteLD( *noteText );
       
   308 			CleanupStack::PopAndDestroy();	// noteText
       
   309 			VRUtils::SetMemoStoreL( EMemoStorePhoneMemory );
       
   310 			}
       
   311 		else
       
   312 			{
       
   313 			VRUtils::SetMemoStoreL( EMemoStoreMMC );
       
   314 			}
       
   315 		}
       
   316 
       
   317     // for multiple drives
       
   318 #else
       
   319      TUint status( 0 );
       
   320 	 TInt defaultDrive = VRUtils::DefaultMemoDriveL();
       
   321 	 if (VRUtils::MemoDriveL() != defaultDrive)
       
   322 	 	{
       
   323  	    VRUtils::GetDriveInfo(iDrive, status);
       
   324      	// check if drive status is ok 
       
   325 	 	if ( status & DriveInfo::EDriveReadOnly )
       
   326 			{
       
   327 			HBufC* noteText = iCoeEnv->AllocReadResourceLC(R_QTN_MEMC_READONLY );
       
   328 			CAknInformationNote* infoNote =	new( ELeave ) CAknInformationNote( ETrue );
       
   329 			infoNote->ExecuteLD( *noteText );
       
   330 			CleanupStack::PopAndDestroy();	// noteText
       
   331         
       
   332         	// use default device drive to save files
       
   333         	iDrive = (TDriveNumber)defaultDrive;
       
   334   			}
       
   335 	 	}
       
   336         VRUtils::SetMemoDriveL( iDrive );
       
   337 #endif 
       
   338      
       
   339     if ( VRUtils::FeatureEnabled( EVRFeatureShowQualitySetting ) )
       
   340         {
       
   341         // Save the quality setting	
       
   342 	    VRUtils::SetQualityL( iQuality );
       
   343         }
       
   344     }
       
   345 
       
   346 // ---------------------------------------------------------------------------
       
   347 // CVRSettingsDialog::DynInitMenuPaneL
       
   348 // 
       
   349 // ---------------------------------------------------------------------------
       
   350 //
       
   351 void CVRSettingsDialog::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )
       
   352 	{
       
   353 
       
   354 	switch ( aResourceId )
       
   355 		{
       
   356 		case R_VR_SETTINGS_MENUPANE:
       
   357 			{
       
   358 			// Check if HELP is enabled in FeatureManager, if not, disable the Help menu item
       
   359 			if (!FeatureManager::FeatureSupported(KFeatureIdHelp))
       
   360 				{
       
   361 				aMenuPane->SetItemDimmed(ECmdHelp, ETrue);
       
   362 				}
       
   363             break; 
       
   364 			}
       
   365 		default:
       
   366 			{
       
   367 			break;
       
   368 			}
       
   369 		}
       
   370 	}
       
   371 
       
   372 
       
   373 // End of file