fmradio/fmradio/src/fmradiosvkevents.cpp
branchRCL_3
changeset 20 93c594350b9a
parent 0 f3d95d9c00ab
equal deleted inserted replaced
19:cce62ebc198e 20:93c594350b9a
       
     1 /*
       
     2 * Copyright (c) 2005 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 *  Class which implements handling Side Volume Key events (SVK).
       
    16 *  This class implements methods of MRemConCoreApiTargetObserver
       
    17 *
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 
       
    23 // INCLUDE FILES
       
    24 #include <remconcoreapitarget.h>
       
    25 #include <remconcoreapitargetobserver.h>
       
    26 #include <RemConCallHandlingTarget.h>
       
    27 #include <RemConCallHandlingTargetObserver.h>
       
    28 #include <remconinterfaceselector.h>
       
    29 #include <aknconsts.h>                      // KAknStandardKeyboardRepeatRate
       
    30 #include <aknViewAppUi.h>
       
    31 
       
    32 #include "fmradiosvkevents.h"
       
    33 
       
    34 
       
    35 // CONSTANTS
       
    36 const TInt KVolumeControlExpiryPeriod = 2000000;
       
    37 const TInt KVolumeFirstChangePeriod = KAknStandardKeyboardRepeatRate;
       
    38 const TInt KVolumeChangePeriod = KAknStandardKeyboardRepeatRate;
       
    39 const TInt KVolumeChangeUp = 1;
       
    40 const TInt KVolumeChangeDown = -1;
       
    41 
       
    42 
       
    43 // ============================ MEMBER FUNCTIONS ===============================
       
    44 
       
    45 // ----------------------------------------------------------------------------
       
    46 // CFMRadioSvkEvents
       
    47 // ----------------------------------------------------------------------------
       
    48 //
       
    49 CFMRadioSvkEvents* CFMRadioSvkEvents::NewL( MFMRadioSvkEventsObserver& aObserver )
       
    50     {
       
    51 #ifdef _DEBUG
       
    52 	RDebug::Print(_L("CFMRadioSvkEvents::NewL"));
       
    53 #endif
       
    54     CFMRadioSvkEvents* self = new ( ELeave ) CFMRadioSvkEvents( aObserver );
       
    55     CleanupStack::PushL( self );
       
    56     self->ConstructL();
       
    57     CleanupStack::Pop( self );
       
    58     return self;
       
    59     }
       
    60 
       
    61 // ----------------------------------------------------------------------------
       
    62 // CFMRadioSvkEvents
       
    63 // ----------------------------------------------------------------------------
       
    64 //
       
    65 CFMRadioSvkEvents::CFMRadioSvkEvents( MFMRadioSvkEventsObserver& aObserver ) :
       
    66     iObserver( aObserver )
       
    67     {
       
    68     }
       
    69 
       
    70 
       
    71 // ----------------------------------------------------------------------------
       
    72 // CFMRadioSvkEvents::~CFMRadioSvkEvents
       
    73 // ----------------------------------------------------------------------------
       
    74 //
       
    75 CFMRadioSvkEvents::~CFMRadioSvkEvents()
       
    76     {
       
    77 #ifdef _DEBUG
       
    78 	RDebug::Print(_L("CFMRadioSvkEvents::~CFMRadioSvkEvents"));
       
    79 #endif
       
    80     delete iRemoveTimer;
       
    81     delete iVolumeTimer;
       
    82     delete iInterfaceSelector;
       
    83     iCoreTarget = NULL; // For LINT. Owned by iInterfaceSelector
       
    84     iCallTarget = NULL; // For LINT. Owned by iInterfaceSelector
       
    85     }
       
    86 
       
    87 // ----------------------------------------------------------------------------
       
    88 // ConstructL
       
    89 // ----------------------------------------------------------------------------
       
    90 //
       
    91 void CFMRadioSvkEvents::ConstructL( )
       
    92     {
       
    93 #ifdef _DEBUG
       
    94 	RDebug::Print(_L("CFMRadioSvkEvents::ConstructL"));
       
    95 #endif
       
    96 
       
    97     iTargetOpen = EFalse;
       
    98     iInterfaceSelector = CRemConInterfaceSelector::NewL();
       
    99 
       
   100     // owned by iInterfaceSelector
       
   101     iCoreTarget = CRemConCoreApiTarget::NewL( *iInterfaceSelector, *this );
       
   102     iCallTarget = CRemConCallHandlingTarget::NewL(*iInterfaceSelector, *this);
       
   103 
       
   104     if (!iTargetOpen)
       
   105     {
       
   106     	iInterfaceSelector->OpenTargetL();
       
   107     	iTargetOpen = ETrue ;
       
   108     }
       
   109 
       
   110     // Remote control server command repeat timer.
       
   111     iVolumeTimer = CPeriodic::NewL( EPriorityNormal );
       
   112     iRemoveTimer = CPeriodic::NewL( EPriorityNormal );
       
   113     }
       
   114 
       
   115 // ----------------------------------------------------------------------------
       
   116 // CFMRadioSvkEvents::MrccatoCommand
       
   117 // Handles side volume key events.
       
   118 // ----------------------------------------------------------------------------
       
   119 //
       
   120 void CFMRadioSvkEvents::MrccatoCommand( TRemConCoreApiOperationId   aOperationId,
       
   121                                     TRemConCoreApiButtonAction  aButtonAct )
       
   122     {
       
   123 #ifdef _DEBUG
       
   124 	RDebug::Print(_L("CFMRadioSvkEvents::MrccatoCommand, Operation ID [%d]"), aOperationId);
       
   125 #endif
       
   126     switch ( aOperationId )
       
   127         {
       
   128         case ERemConCoreApiVolumeUp: //  Volume Up
       
   129         	{
       
   130             HandleVolumeButtons( aButtonAct, KVolumeChangeUp ); 
       
   131             break;
       
   132         	}
       
   133         case ERemConCoreApiVolumeDown: //  Volume Down
       
   134         	{
       
   135             HandleVolumeButtons( aButtonAct, KVolumeChangeDown ); 
       
   136             break;
       
   137         	}
       
   138         case ERemConCoreApiBackward: //  Backward
       
   139             {
       
   140 			iObserver.FMRadioHeadsetEvent( ERewind );
       
   141             break;
       
   142             }
       
   143 		case ERemConCoreApiForward: //   Forward
       
   144             {
       
   145 			iObserver.FMRadioHeadsetEvent( EForward );
       
   146             break;
       
   147             }
       
   148         case ERemConCoreApiRewind: //  Tune down
       
   149             {
       
   150             if ( aButtonAct == ERemConCoreApiButtonPress )
       
   151             	{
       
   152             	TuneChannel( EFMRadioCmdSeekDown );
       
   153             	}
       
   154             break;
       
   155             }
       
   156 		case ERemConCoreApiFastForward: //   Tune up
       
   157             {
       
   158             if ( aButtonAct == ERemConCoreApiButtonPress )
       
   159              	{
       
   160              	TuneChannel( EFMRadioCmdSeekUp );
       
   161              	}
       
   162             break;
       
   163             }
       
   164         case ERemConCoreApiPausePlayFunction:        
       
   165         	{
       
   166         	iObserver.FMRadioHeadsetEvent( EPausePlay );
       
   167         	break;
       
   168         	}
       
   169         case ERemConCoreApiStop:
       
   170         	{
       
   171         	iObserver.FMRadioHeadsetEvent( EStop );
       
   172         	break;	
       
   173         	}            
       
   174         default :
       
   175             {
       
   176             // Don’t Panic or do anything here. Other events such as Stop, Rewind, Forward will fall here.
       
   177             break;
       
   178             }
       
   179         }
       
   180     }
       
   181 
       
   182 
       
   183 // ----------------------------------------------------------------------------
       
   184 // StartRemoveTimerL
       
   185 //
       
   186 // ----------------------------------------------------------------------------
       
   187 //
       
   188 void CFMRadioSvkEvents::StartRemoveTimerL( )
       
   189     {
       
   190 #ifdef _DEBUG
       
   191 	RDebug::Print(_L("CFMRadioSvkEvents::StartRemoveTimerL" ));
       
   192 #endif
       
   193     iRemoveTimer->Cancel();
       
   194     iRemoveTimer->Start(    KVolumeControlExpiryPeriod,
       
   195                             KVolumeControlExpiryPeriod,
       
   196                             TCallBack( RemoveControl, this ) );
       
   197     }
       
   198 
       
   199 // ----------------------------------------------------------------------------
       
   200 // CancelRemoveTimer
       
   201 // ----------------------------------------------------------------------------
       
   202 //
       
   203 void CFMRadioSvkEvents::CancelRemoveTimer( )
       
   204     {
       
   205     iRemoveTimer->Cancel();
       
   206     }
       
   207 
       
   208 // ----------------------------------------------------------------------------
       
   209 // DoChangeVolume
       
   210 //
       
   211 // ----------------------------------------------------------------------------
       
   212 //
       
   213 void CFMRadioSvkEvents::DoChangeVolume( )
       
   214     {
       
   215 #ifdef _DEBUG
       
   216 	RDebug::Print(_L("CFMRadioSvkEvents::DoChangeVolume" ));
       
   217 #endif
       
   218     TRAP_IGNORE( iObserver.FMRadioSvkChangeVolumeL( iChange ) );
       
   219     iRemoveTimer->Cancel();
       
   220     iRemoveTimer->Start(   KVolumeControlExpiryPeriod,
       
   221                             KVolumeControlExpiryPeriod,
       
   222                             TCallBack( RemoveControl, this ) );
       
   223     }
       
   224 
       
   225 
       
   226 // ----------------------------------------------------------------------------
       
   227 // TuneChannel
       
   228 //
       
   229 // ----------------------------------------------------------------------------
       
   230 //
       
   231 void CFMRadioSvkEvents::TuneChannel( TFMRadioCommandIds aDirection )
       
   232     {
       
   233 	CAknViewAppUi* appUi = static_cast<CAknViewAppUi*>( CCoeEnv::Static()->AppUi() ); 
       
   234     TRAP_IGNORE( appUi->HandleCommandL( aDirection ) );
       
   235     }
       
   236 
       
   237 // ----------------------------------------------------------------------------
       
   238 // RemoveControlL
       
   239 //
       
   240 // ----------------------------------------------------------------------------
       
   241 //
       
   242 void CFMRadioSvkEvents::RemoveControlL( )
       
   243     {
       
   244     iRemoveTimer->Cancel();
       
   245     iObserver.FMRadioSvkRemoveVolumeL( );
       
   246     }
       
   247 
       
   248 
       
   249 
       
   250 // ----------------------------------------------------------------------------
       
   251 // ChangeVolume
       
   252 //
       
   253 // ----------------------------------------------------------------------------
       
   254 //
       
   255 TInt CFMRadioSvkEvents::ChangeVolume( TAny* aObject )
       
   256     {
       
   257     // cast, and call non-static function
       
   258     static_cast<CFMRadioSvkEvents*>( aObject )->DoChangeVolume( );
       
   259     return KErrNone;
       
   260     }
       
   261 
       
   262 // ----------------------------------------------------------------------------
       
   263 // RemoveControl
       
   264 //
       
   265 // ----------------------------------------------------------------------------
       
   266 //
       
   267 TInt CFMRadioSvkEvents::RemoveControl( TAny* aObject )
       
   268     {
       
   269     // cast, and call non-static function
       
   270     TRAP_IGNORE( static_cast<CFMRadioSvkEvents*>( aObject )->RemoveControlL() );
       
   271     return KErrNone;
       
   272     }
       
   273 
       
   274 
       
   275 // ---------------------------------------------------------
       
   276 // CFMRadioSvkEvents::AnswerCall
       
   277 // ---------------------------------------------------------
       
   278 //
       
   279 void CFMRadioSvkEvents::AnswerCall()
       
   280     {
       
   281     }
       
   282 
       
   283 // ---------------------------------------------------------
       
   284 // CFMRadioSvkEvents::AnswerEndCall
       
   285 // ---------------------------------------------------------
       
   286 //
       
   287 void CFMRadioSvkEvents::AnswerEndCall()
       
   288     {
       
   289 	iObserver.FMRadioHeadsetEvent(EForward);
       
   290     }
       
   291 
       
   292 // ---------------------------------------------------------
       
   293 // CFMRadioSvkEvents::DialCall
       
   294 // ---------------------------------------------------------
       
   295 //
       
   296 void CFMRadioSvkEvents::DialCall( const TDesC8& /*aTelNumber*/ )
       
   297     {
       
   298     }
       
   299 
       
   300 // ---------------------------------------------------------
       
   301 // CFMRadioSvkEvents::EndCall
       
   302 // ---------------------------------------------------------
       
   303 //
       
   304 void CFMRadioSvkEvents::EndCall()
       
   305     {
       
   306     }
       
   307 
       
   308 // ---------------------------------------------------------
       
   309 // CFMRadioSvkEvents::GenerateDTMF
       
   310 // ---------------------------------------------------------
       
   311 //
       
   312 void CFMRadioSvkEvents::GenerateDTMF( const TChar /*aChar*/ )
       
   313     {
       
   314     }
       
   315 
       
   316 // ---------------------------------------------------------
       
   317 // CFMRadioSvkEvents::LastNumberRedial
       
   318 // ---------------------------------------------------------
       
   319 //
       
   320 void CFMRadioSvkEvents::LastNumberRedial()
       
   321     {
       
   322     }
       
   323 
       
   324 // ---------------------------------------------------------
       
   325 // CFMRadioSvkEvents::MultipartyCalling
       
   326 // ---------------------------------------------------------
       
   327 //
       
   328 void CFMRadioSvkEvents::MultipartyCalling( const TDesC8& /*aData*/ )
       
   329     {
       
   330     }
       
   331 
       
   332 // ---------------------------------------------------------
       
   333 // CFMRadioSvkEvents::SpeedDial
       
   334 // ---------------------------------------------------------
       
   335 //
       
   336 void CFMRadioSvkEvents::SpeedDial( const TInt /*aIndex*/ )
       
   337     {
       
   338     }
       
   339 
       
   340 // ---------------------------------------------------------
       
   341 // CFMRadioSvkEvents::VoiceDial
       
   342 // ---------------------------------------------------------
       
   343 //
       
   344 void CFMRadioSvkEvents::VoiceDial( const TBool /*aActivate*/ )
       
   345     {
       
   346     }
       
   347 // ---------------------------------------------------------
       
   348 // CFMRadioSvkEvents::HandleVolumeButtons
       
   349 // ---------------------------------------------------------
       
   350 //
       
   351 void CFMRadioSvkEvents::HandleVolumeButtons( TRemConCoreApiButtonAction aButtonAct, TInt aDirection  )
       
   352 	{
       
   353 	switch( aButtonAct )
       
   354         {
       
   355         case ERemConCoreApiButtonPress:
       
   356             {
       
   357             // Volume up hold down for 0,6 seconds
       
   358             iVolumeTimer->Cancel();
       
   359             iVolumeTimer->Start( KVolumeFirstChangePeriod,
       
   360                                  KVolumeChangePeriod,
       
   361                                  TCallBack( ChangeVolume, this ) );
       
   362        	    iChange = aDirection;
       
   363        		DoChangeVolume( );
       
   364             break;
       
   365             }
       
   366         case ERemConCoreApiButtonRelease:
       
   367             {
       
   368             iVolumeTimer->Cancel();
       
   369             break;
       
   370             }
       
   371         case ERemConCoreApiButtonClick:
       
   372             {
       
   373             iChange = aDirection;
       
   374             DoChangeVolume( );
       
   375             break;
       
   376             }
       
   377         default:
       
   378             {
       
   379             // Never hits this
       
   380             break;
       
   381             }
       
   382         }
       
   383 	}
       
   384 // End of File