profilesapplication/Profiles/ProfileApp/SettingsViewSrc/CProfile3dSettingPage.cpp
branchRCL_3
changeset 19 cd54903d48da
equal deleted inserted replaced
18:b7fa36b488f8 19:cd54903d48da
       
     1 /*
       
     2 * Copyright (c) 2008 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 3D settings.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDES
       
    21 #include "CProfile3dSettingPage.h"
       
    22 #include "ProfileSettingsView.hrh"
       
    23 
       
    24 #include <CFLDController.h>
       
    25 #include <profilesettingsview.rsg>
       
    26 #include <apgcli.h>	// For RApaLsSession
       
    27 #include <bautils.h> // For BaflUtils
       
    28 #include <centralrepository.h>
       
    29 #include <ProfileEngineInternalCRKeys.h>
       
    30 #include <ProfileInternal.hrh>
       
    31 
       
    32 // CONSTANTS
       
    33 namespace
       
    34 	{
       
    35     const TInt K3DEffectBase( 1000 );
       
    36     const TInt K3DEchoBase( 2000 );
       
    37 
       
    38 	const TInt KRepeatDelayInMicroSeconds( 1000000 ); // One second
       
    39 
       
    40 #ifdef RD_VIDEO_AS_RINGING_TONE
       
    41 	_LIT( KFLDCommonVideoType, "video/*" );
       
    42 	_LIT( KFLDRM1VideoMimeType, "application/vnd.rn-realmedia" );
       
    43 	_LIT( KFLDRM2VideoMimeType, "application/x-pn-realmedia" );
       
    44 	_LIT( KFLDSDPVideoMimeType, "application/sdp" );
       
    45 #endif
       
    46 
       
    47 	}
       
    48 // ============================ MEMBER FUNCTIONS ===============================
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CProfile3dSettingPage::CProfile3dSettingPage
       
    52 // C++ constructor can NOT contain any code, that might leave.
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CProfile3dSettingPage::CProfile3dSettingPage(
       
    56     TInt aResourceID,
       
    57     MAknQueryValue& aQueryValue,
       
    58     const TDesC& aRingingTone,
       
    59     const TInt& aRingingType,
       
    60     const TBool& aVibratingAlert,
       
    61     const TInt& aVolume,
       
    62     const TInt& a3DEffectOrEcho,
       
    63     TInt aIdentifier )
       
    64     :   CAknPopupSettingPage( aResourceID, aQueryValue ),
       
    65         iRingingTone( aRingingTone ),
       
    66         iRingingType( aRingingType ),
       
    67         iVibratingAlert( aVibratingAlert ),
       
    68         iVolume( aVolume ),
       
    69         i3DEffectOrEcho( a3DEffectOrEcho ),
       
    70         iIdentifier( aIdentifier )
       
    71     {
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CProfile3dSettingPage::ConstructL
       
    76 // Symbian 2nd phase constructor can leave.
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 void CProfile3dSettingPage::ConstructL()
       
    80     {
       
    81     CAknPopupSettingPage::ConstructL();
       
    82 
       
    83 	TBool showErrorMsgs( EFalse );
       
    84 	
       
    85     iFs = new ( ELeave ) RFs;
       
    86     User::LeaveIfError( iFs->Connect() );
       
    87 
       
    88 	CheckRingingToneTypeL();
       
    89 
       
    90     iController = CFLDController::NewL( showErrorMsgs, KRepeatDelayInMicroSeconds );
       
    91 	iController->CompleteConstructionL( Window() );
       
    92 	iController->SetRingingType( iRingingType );
       
    93 	iController->SetVibra( iVibratingAlert );
       
    94 	iController->SetVolume( iVolume );
       
    95     }
       
    96 
       
    97 // Destructor.
       
    98 CProfile3dSettingPage::~CProfile3dSettingPage()
       
    99     {
       
   100     if( iFs )
       
   101     	{
       
   102     	iFs->Close();
       
   103     	}
       
   104     delete iFs;
       
   105     delete iController;
       
   106     delete iPreviewTone;
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CProfile3dSettingPage::OfferKeyEventL
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 TKeyResponse CProfile3dSettingPage::OfferKeyEventL(
       
   114     const TKeyEvent& aKeyEvent, TEventCode aType )
       
   115     {
       
   116     if( aType == EEventKey )
       
   117         {
       
   118         if( ( aKeyEvent.iCode == EKeyUpArrow ) ||
       
   119             ( aKeyEvent.iCode == EKeyDownArrow ) )
       
   120             {
       
   121             // Get current setting
       
   122             TInt currentValue = PopupSettingListBox()->CurrentItemIndex();
       
   123 
       
   124             // Call base classes method
       
   125             TKeyResponse response( CAknPopupSettingPage::OfferKeyEventL( aKeyEvent, aType ) );
       
   126 
       
   127             // Get new setting
       
   128             TInt newValue = PopupSettingListBox()->CurrentItemIndex();
       
   129 
       
   130             if( newValue != currentValue )
       
   131                 {
       
   132                 // Setting has changed
       
   133                 if( ( iIdentifier == EProfileSetting3dEffectId && newValue != EProfile3DEffectOff ) ||
       
   134                 	( iIdentifier == EProfileSetting3dEchoId && i3DEffectOrEcho != EProfile3DEffectOff ) )
       
   135                 	{
       
   136                     // Set 3D parameters
       
   137                 	if( iIdentifier == EProfileSetting3dEffectId )
       
   138                 		{
       
   139                         iController->Set3dEffects( K3DEffectBase + newValue );
       
   140                         iController->Set3dEffects( K3DEchoBase + i3DEffectOrEcho );
       
   141                 		}
       
   142                 	else
       
   143                 		{
       
   144                         iController->Set3dEffects( K3DEffectBase + i3DEffectOrEcho );
       
   145                         iController->Set3dEffects( K3DEchoBase + newValue );
       
   146                 		}
       
   147                 	iController->Set3dEffects( ETrue );
       
   148                 	}
       
   149                 else
       
   150                 	{
       
   151                 	iController->Set3dEffects( EFalse );
       
   152                 	}
       
   153                 iController->HandleFileListBoxEventL(
       
   154                     MFLDFileListBoxObserver::EFocusChanged, iPreviewTone->Des() );
       
   155                 }
       
   156             return response;
       
   157             }
       
   158         // Cancels playback on any key event
       
   159         iController->HandleFileListBoxEventL(
       
   160             MFLDFileListBoxObserver::EOtherKeyEvent, iPreviewTone->Des() );
       
   161         }
       
   162 
       
   163     return CAknPopupSettingPage::OfferKeyEventL( aKeyEvent, aType );
       
   164     }
       
   165 
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // CProfile3dSettingPage::HandlePointerEventL
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 void CProfile3dSettingPage::HandlePointerEventL(
       
   172     const TPointerEvent& aPointerEvent )
       
   173     {
       
   174     if( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   175         {
       
   176         // Get current setting
       
   177         iTempValue = PopupSettingListBox()->CurrentItemIndex();
       
   178         }
       
   179     else if( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   180     	{
       
   181 	    CAknPopupSettingPage::HandlePointerEventL( aPointerEvent );
       
   182         // Get new setting
       
   183         TInt newValue = PopupSettingListBox()->CurrentItemIndex();
       
   184         if( newValue != iTempValue )
       
   185             {
       
   186             // Setting has changed
       
   187             if( ( iIdentifier == EProfileSetting3dEffectId && newValue != EProfile3DEffectOff ) ||
       
   188             	( iIdentifier == EProfileSetting3dEchoId && i3DEffectOrEcho != EProfile3DEffectOff ) )
       
   189             	{
       
   190                 // Set 3D parameters
       
   191             	if( iIdentifier == EProfileSetting3dEffectId )
       
   192             		{
       
   193                     iController->Set3dEffects( K3DEffectBase + newValue );
       
   194                     iController->Set3dEffects( K3DEchoBase + i3DEffectOrEcho );
       
   195             		}
       
   196             	else
       
   197             		{
       
   198                     iController->Set3dEffects( K3DEffectBase + i3DEffectOrEcho );
       
   199                     iController->Set3dEffects( K3DEchoBase + newValue );
       
   200             		}
       
   201             	iController->Set3dEffects( ETrue );
       
   202             	}
       
   203             else
       
   204             	{
       
   205             	iController->Set3dEffects( EFalse );
       
   206             	}
       
   207 
       
   208             iController->HandleFileListBoxEventL(
       
   209                 MFLDFileListBoxObserver::EFocusChanged, iPreviewTone->Des() );
       
   210             }
       
   211         return;
       
   212         }
       
   213     // Cancels playback on any key event
       
   214     iController->HandleFileListBoxEventL(
       
   215         MFLDFileListBoxObserver::EOtherKeyEvent, iPreviewTone->Des() );
       
   216 
       
   217     CAknPopupSettingPage::HandlePointerEventL( aPointerEvent );
       
   218     }
       
   219 
       
   220 
       
   221 // -----------------------------------------------------------------------------
       
   222 // CProfile3dSettingPage::CheckRingingToneTypeL
       
   223 // -----------------------------------------------------------------------------
       
   224 //
       
   225 void CProfile3dSettingPage::CheckRingingToneTypeL()
       
   226 	{
       
   227 	// Get default tone from cenrep
       
   228 	TFileName defaultTone;
       
   229 	CRepository* cenrep = CRepository::NewL( KCRUidProfileEngine );
       
   230 	CleanupStack::PushL( cenrep );
       
   231 	User::LeaveIfError( cenrep->Get( KProEngDefaultRingingTone, defaultTone ) );
       
   232 	CleanupStack::PopAndDestroy( cenrep );
       
   233 
       
   234 	if( !BaflUtils::FileExists( *iFs, iRingingTone ) )
       
   235 		{
       
   236 		// If the file does not exist, use default tone for volume preview
       
   237 		iPreviewTone = defaultTone.AllocL();
       
   238 		return;
       
   239 		}
       
   240 
       
   241 #ifdef RD_VIDEO_AS_RINGING_TONE
       
   242 	// Find out MIME type
       
   243 	RApaLsSession apaLsSession;
       
   244 	User::LeaveIfError( apaLsSession.Connect() );
       
   245 	CleanupClosePushL( apaLsSession );
       
   246 	TUid dummyUid = { 0 }; // instantiate as zero
       
   247 	TDataType dataType( dummyUid );
       
   248 	User::LeaveIfError(
       
   249 		apaLsSession.AppForDocument( iRingingTone, dummyUid, dataType ) );
       
   250 	CleanupStack::PopAndDestroy(); // apaLsSession.Close()
       
   251 
       
   252 	// See if this is a video MIME type
       
   253 	if ( dataType.Des().MatchF( KFLDCommonVideoType ) == 0 ||
       
   254 		dataType.Des().CompareF( KFLDRM1VideoMimeType ) == 0 ||
       
   255 		dataType.Des().CompareF( KFLDRM2VideoMimeType ) == 0 ||
       
   256 		dataType.Des().CompareF( KFLDSDPVideoMimeType ) == 0 )
       
   257 		{
       
   258 		iPreviewTone = defaultTone.AllocL();
       
   259 		}
       
   260 	else
       
   261 		{
       
   262 		iPreviewTone = iRingingTone.AllocL();
       
   263 		}
       
   264 #else
       
   265 	iPreviewTone = iRingingTone.AllocL();
       
   266 #endif
       
   267 	}
       
   268 
       
   269 // End of File