profilesapplication/Profiles/ProfileApp/SettingsViewSrc/CProfileKeypadVolumeSettingPage.cpp
branchRCL_3
changeset 19 cd54903d48da
equal deleted inserted replaced
18:b7fa36b488f8 19:cd54903d48da
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Setting page class for keypad volume setting.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDES
       
    21 #include "CProfileKeypadVolumeSettingPage.h"
       
    22 
       
    23 #include <AudioPreference.h>
       
    24 #include <aknsoundsystem.h>
       
    25 #include <StringLoader.h>	// For StringLoader
       
    26 #include <aknnotewrappers.h> // For CAknInformationNote
       
    27 #include <profilesettingsview.rsg>
       
    28 
       
    29 // for power save mode handling
       
    30 #include <psmsettings.h>
       
    31 #include <psmsrvdomaincrkeys.h>
       
    32 #include <centralrepository.h>
       
    33 
       
    34 namespace
       
    35 	{
       
    36 // CONSTANTS
       
    37 #ifdef __WINS__
       
    38 	// These constants are for WINS only because sequences are not played in emulator.
       
    39 	const TInt KKeypadToneFrequency( 1760 ); /// In Hz
       
    40 	const TInt KKeypadToneDuration( 20000 ); /// In microseconds
       
    41 #endif // __WINS__
       
    42 	}
       
    43 // ============================ MEMBER FUNCTIONS ===============================
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CProfileKeypadVolumeSettingPage::CProfileKeypadVolumeSettingPage
       
    47 // C++ constructor can NOT contain any code, that might leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CProfileKeypadVolumeSettingPage::CProfileKeypadVolumeSettingPage(
       
    51 	TInt aResourceID,
       
    52 	MAknQueryValue& aQueryValue,
       
    53 	CAknKeySoundSystem* aSoundSystem )
       
    54 	:	CAknPopupSettingPage( aResourceID, aQueryValue ),
       
    55 		iSoundSystem( aSoundSystem )
       
    56 	{
       
    57 	}
       
    58 
       
    59 // Destructor.
       
    60 CProfileKeypadVolumeSettingPage::~CProfileKeypadVolumeSettingPage()
       
    61 	{
       
    62 	if( iAudioUtility )
       
    63 		{
       
    64 		if( iAudioUtility->State() != EMdaAudioToneUtilityNotReady )
       
    65 			{
       
    66 			// Set volume back to original
       
    67 			iAudioUtility->SetVolume( iOriginalVolume );
       
    68 			}
       
    69 		delete iAudioUtility;
       
    70 		}
       
    71 	if( iSoundSystem )
       
    72 		{
       
    73 		// Re-enable keypad sounds
       
    74 		iSoundSystem->PopContext();
       
    75 		}
       
    76 	}
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CProfileKeypadVolumeSettingPage::ConstructL
       
    80 // Symbian 2nd phase constructor can leave.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 void CProfileKeypadVolumeSettingPage::ConstructL()
       
    84 	{
       
    85 	User::LeaveIfNull( iSoundSystem );
       
    86 
       
    87 	CAknPopupSettingPage::ConstructL();
       
    88 
       
    89 	// Own construction starts here
       
    90 
       
    91 	// Disable keypad sounds
       
    92 	iSoundSystem->PushContextL( R_AVKON_SILENT_SKEY_LIST );
       
    93 
       
    94 	// Create audio player and prepare to play a tone
       
    95 	iAudioUtility = CMdaAudioToneUtility::NewL( *this );
       
    96 
       
    97 #ifdef __WINS__ // Sequences are not supported on emulator
       
    98 	iAudioUtility->PrepareToPlayTone( KKeypadToneFrequency,
       
    99 		TTimeIntervalMicroSeconds( KKeypadToneDuration ) );
       
   100 #else
       
   101 	CAknSoundInfo* soundInfo = CAknSoundInfo::NewL();
       
   102 	CleanupStack::PushL( soundInfo );
       
   103 	User::LeaveIfError( iSoundSystem->RequestSoundInfoL(
       
   104 		EAvkonSIDStandardKeyClick, *soundInfo ) );
       
   105 	iAudioUtility->PrepareToPlayDesSequence( *soundInfo->iSequence );
       
   106 	CleanupStack::PopAndDestroy( soundInfo );
       
   107 #endif // __WINS__
       
   108 	}
       
   109 
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CProfileKeypadVolumeSettingPage::OkToExitL
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 TBool CProfileKeypadVolumeSettingPage::OkToExitL( TBool aAccept )
       
   116     {
       
   117     if( aAccept )
       
   118         {
       
   119         TInt psm = EPsmsrvModeNormal;
       
   120         CRepository* cenrep = CRepository::NewLC( KCRUidPowerSaveMode );
       
   121         cenrep->Get( KPsmCurrentMode, psm );
       
   122         CleanupStack::PopAndDestroy( cenrep );
       
   123         if( psm == EPsmsrvModePowerSave )
       
   124             {
       
   125             HBufC* buf = StringLoader::LoadLC( R_PROFILE_TEXT_PSM_INFONOTE );
       
   126             CAknInformationNote* queryDialog = new (ELeave) CAknInformationNote( EFalse );
       
   127          	queryDialog->ExecuteLD( *buf );
       
   128             CleanupStack::PopAndDestroy( buf );
       
   129             }
       
   130         }
       
   131     return ETrue;
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CProfileKeypadVolumeSettingPage::OfferKeyEventL
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 TKeyResponse CProfileKeypadVolumeSettingPage::OfferKeyEventL(
       
   139 	const TKeyEvent& aKeyEvent, TEventCode aType )
       
   140 	{
       
   141 	// Cache pointer used multiple times
       
   142 	CAknSetStyleListBox* listBoxControl = ListBoxControl();
       
   143 	// Get current index from listbox
       
   144 	TInt oldIndex( listBoxControl->CurrentItemIndex() );
       
   145 	// Call OfferKeyEventL of base class
       
   146 	TKeyResponse response( CAknPopupSettingPage::OfferKeyEventL( aKeyEvent, aType ) );
       
   147 	// Get audio player state
       
   148 	TInt state( iAudioUtility->State() );
       
   149 	// Get new index from listbox
       
   150 	TInt newIndex( listBoxControl->CurrentItemIndex() );
       
   151 
       
   152 	if( ( oldIndex != newIndex ) && // check if listbox focus has changed
       
   153 		( newIndex != 0 ) && // check that new focus is not on first item "Off"
       
   154 		( state != EMdaAudioToneUtilityNotReady ) ) // check that tone player is ready
       
   155 		{
       
   156 		// Resolve last index of listbox
       
   157 		TInt lastIndex( listBoxControl->Model()->MatchableTextArray()->MdcaCount() - 1 );
       
   158 		// Resolve correct volume from current listbox index
       
   159 		TInt volume( iAudioUtility->MaxVolume() * newIndex / lastIndex );
       
   160 
       
   161 		if( state == EMdaAudioToneUtilityPlaying )
       
   162 			{
       
   163 			// Cancel play if still playing previous keyclick
       
   164 	        iAudioUtility->CancelPlay();
       
   165 			}
       
   166 		iAudioUtility->SetVolume( volume );
       
   167 		iAudioUtility->Play();
       
   168 		}
       
   169 	return response;
       
   170 	}
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CProfileKeypadVolumeSettingPage::MatoPrepareComplete
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 void CProfileKeypadVolumeSettingPage::MatoPrepareComplete( TInt aError )
       
   177 	{
       
   178 	if( !aError )
       
   179 		{
       
   180 		// After prepare is completed, store original volume level
       
   181 		iOriginalVolume = iAudioUtility->Volume();
       
   182 		// Set priority
       
   183 		iAudioUtility->SetPriority( KAudioPriorityKeyPress,
       
   184 			TMdaPriorityPreference( KAudioPrefKeyPressPreview ) );
       
   185 		}
       
   186 	}
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CProfileKeypadVolumeSettingPage::MatoPlayComplete
       
   190 // Error ignored because if playing of the keypad tone is unsuccesful
       
   191 // nothing can be done.
       
   192 // -----------------------------------------------------------------------------
       
   193 //
       
   194 void CProfileKeypadVolumeSettingPage::MatoPlayComplete( TInt /*aError*/ )
       
   195 	{
       
   196 	}
       
   197 
       
   198 // End of File