vtuis/videotelui/src/features/volume/cvtuivolumecontrol.cpp
changeset 18 d9b6a8729acd
parent 4 6dc066157ed4
child 23 c378a0498b84
child 27 dcbddbbaf8fd
equal deleted inserted replaced
4:6dc066157ed4 18:d9b6a8729acd
     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:  Implementation of the cvtuivolumecontrol class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include    "cvtuivolumecontrol.h"
       
    20 #include    "MVtUiEngineCommandManager.h"
       
    21 #include    <mvtengcommandhandler.h>
       
    22 #include    <cvtlogger.h>
       
    23 #include    "cvtuivolume.h"
       
    24 #include    "cvtuifeaturemanager.h"
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // CVtUiVolumeControl::CVtUiVolumeControl
       
    28 // -----------------------------------------------------------------------------
       
    29 //
       
    30 CVtUiVolumeControl::CVtUiVolumeControl(
       
    31         MVtEngCommandHandler& aCommandHandler,
       
    32         MVtEngAudio& aAudio,
       
    33         MVtUiEngineCommandManager& aCommandManager,
       
    34         CVtUiFeatureManager& aFeatureManager )
       
    35     :  iCommandHandler( aCommandHandler ),
       
    36       iAudio( aAudio ),
       
    37       iCommandManager( aCommandManager ),
       
    38       iVolumePtr( (TUint8*)&iVolume, sizeof( TVolume ) ),
       
    39       iFeatureManager( aFeatureManager )
       
    40     {
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CVtUiVolumeControl::~CVtUiVolumeControl
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CVtUiVolumeControl::~CVtUiVolumeControl()
       
    48     {
       
    49     if ( iIsActive )
       
    50         {
       
    51         iCommandHandler.CancelCommand( KVtEngSetAudioVolume ); // ignore error
       
    52         }
       
    53     iCommandManager.RemoveObserver( *this );               
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CVtUiVolumeControl::ExecuteDialogLD
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 void CVtUiVolumeControl::ConstructL()
       
    61     {
       
    62     CleanupStack::PushL( this );
       
    63     iCommandManager.AddObserverL( *this );
       
    64     CleanupStack::Pop( this );
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CVtUiVolumeControl::SetVoAdjustVolumeL
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 void CVtUiVolumeControl::AdjustVolumeL( TVolume aVolume  )
       
    72     {
       
    73     __VTPRINTENTER( "VtUiVolCtrl.AdjustVolumeL")
       
    74     if ( iIsActive )
       
    75         {
       
    76         __VTPRINTENTER( "VtUiVolCtrl.AdjustVolumeL.Isactive")
       
    77         return;
       
    78         }
       
    79     iIsActive = ETrue;         
       
    80     iVolume = aVolume;
       
    81     iCommandHandler.ExecuteL( KVtEngSetAudioVolume, &iVolumePtr );
       
    82     __VTPRINTEXIT( "VtUiVolCtrl.AdjustVolumeL")
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CVtUiVolumeControl::HandleVTCommandPerformedL
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CVtUiVolumeControl::HandleVTCommandPerformedL(
       
    90         TVtEngCommandId aCommand,
       
    91         const TInt aError )
       
    92     {
       
    93     __VTPRINTENTER( "VtUiVolCtrl.HandleVTCommandPerformedL")
       
    94     if ( aCommand == KVtEngSetAudioVolume )
       
    95         {
       
    96         __VTPRINT( DEBUG_GEN, "VtUiVolCtrl.perf" )
       
    97         TInt error = aError;
       
    98         // If volume has been changed, then try to set volume again.
       
    99         //iIsActive = ETrue;
       
   100         if ( IsVolumeChangedL() )
       
   101             {
       
   102             __VTPRINT( DEBUG_GEN, "VtUiVolCtrl.retry" )
       
   103             TRAP( error,
       
   104                iCommandHandler.ExecuteL(
       
   105                    KVtEngSetAudioVolume,
       
   106                    &iVolumePtr ) );
       
   107             __VTPRINT2( DEBUG_GEN, "VtUiVolCtrl.err.%d", error )
       
   108             iIsActive = ( error == KErrNone );
       
   109             }
       
   110         else
       
   111             {
       
   112              __VTPRINT( DEBUG_GEN,
       
   113               "VtUiVolCtrl.HandleVTCommandPerformedL iIsActive = EFalse; " )
       
   114             iIsActive = EFalse; 
       
   115             }            
       
   116       
       
   117         }
       
   118     __VTPRINTEXIT( "VtUiVolCtrl.HandleVTCommandPerformedL")        
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CVtUiVolumeControl::IsVolumeChangedL
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 TBool CVtUiVolumeControl::IsVolumeChangedL()
       
   126     {
       
   127     __VTPRINTENTER( "VtUiVolCtrl.IsVolumeChangedL" )
       
   128     MVtEngAudio::TAudioRoutingState audioRouting;
       
   129     User::LeaveIfError( iAudio.GetRoutingState( audioRouting ) );
       
   130     const TInt volume( iAudio.OutputVolume(
       
   131         !( audioRouting == MVtEngAudio::EAudioLoudspeaker ) ) );
       
   132      
       
   133     CVtUiVolume* vp = static_cast< CVtUiVolume* >(
       
   134     iFeatureManager.GetFeatureById( EVtUiFeatureIdVolume ) );
       
   135     TInt sliderVolume( volume );
       
   136     if ( vp )
       
   137         {
       
   138         sliderVolume = vp->GetVolumeValue();
       
   139         // update correct volume
       
   140         if ( audioRouting == MVtEngAudio::EAudioLoudspeaker )
       
   141             {
       
   142             __VTPRINT( DEBUG_GEN, "VtUiVolCtrl.IsVolumeChangedL.LS")
       
   143             iVolume.iHandsfreeVolume = sliderVolume;
       
   144             }
       
   145         else
       
   146             {
       
   147             __VTPRINT( DEBUG_GEN, "VtUiVolCtrl.IsVolumeChangedL.HS")
       
   148             iVolume.iHandsetVolume = sliderVolume;
       
   149             }
       
   150         }
       
   151         
       
   152     __VTPRINT2( DEBUG_GEN, "VtUiVolCtrl.vol %d", volume )        
       
   153     __VTPRINT2( DEBUG_GEN, "VtUiVolCtrl.slidvol %d", sliderVolume )
       
   154     __VTPRINTEXITR( "VtUiVolCtrl.IsVolumeChangedL %d", sliderVolume == volume )    
       
   155     return sliderVolume == volume ? EFalse : ETrue; 
       
   156     }
       
   157 //  End of File