utilities/mpmediacontroller/src/mpmediakeyhandler_p.cpp
changeset 48 af3740e3753f
equal deleted inserted replaced
42:79c49924ae23 48:af3740e3753f
       
     1 /*
       
     2 * Copyright (c) 2009 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: Music Player media key handler - private implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //symbian header files
       
    20 #include <remconcoreapitarget.h>
       
    21 #include <remconinterfaceselector.h>
       
    22 
       
    23 #include "mpmediakeyhandler_p.h"
       
    24 #include "mpmediakeyhandler.h"
       
    25 #include "mpmediakeyremconresponse.h"
       
    26 #include "mpenginefactory.h"
       
    27 #include "mpcommondefs.h"
       
    28 #include "mptrace.h"
       
    29 
       
    30 
       
    31 /*!
       
    32  \internal
       
    33  */
       
    34 MpMediaKeyHandlerPrivate::MpMediaKeyHandlerPrivate( MpMediaKeyHandler *wrapper )
       
    35     : q_ptr( wrapper ),
       
    36       iInterfaceSelector(NULL),
       
    37       iResponseHandler(NULL),
       
    38       iMpEngine(NULL),
       
    39       iSideKeyAlreadyClicked(false)
       
    40 {
       
    41     TX_LOG
       
    42 }
       
    43 
       
    44 /*!
       
    45  \internal
       
    46  */
       
    47 MpMediaKeyHandlerPrivate::~MpMediaKeyHandlerPrivate()
       
    48 {
       
    49     TX_ENTRY
       
    50     delete iResponseHandler;
       
    51     delete iInterfaceSelector;
       
    52     TX_EXIT
       
    53 }
       
    54 
       
    55 /*!
       
    56  \internal
       
    57  */
       
    58 void MpMediaKeyHandlerPrivate::init()
       
    59 {
       
    60     TX_ENTRY
       
    61     TRAPD(err, DoInitL());
       
    62     if ( err != KErrNone ) {
       
    63         TX_LOG_ARGS("Error: " << err << "; should never get here.");
       
    64     }
       
    65     TX_EXIT
       
    66 
       
    67 }
       
    68 
       
    69 /*!
       
    70  From MRemConCoreApiTargetObserver
       
    71  A command has been received.
       
    72  */
       
    73 void MpMediaKeyHandlerPrivate::MrccatoCommand(
       
    74     TRemConCoreApiOperationId aOperationId,
       
    75     TRemConCoreApiButtonAction aButtonAct )
       
    76 {
       
    77     TX_ENTRY_ARGS( " aOperationId=" << aOperationId << " aButtonAct=" << aButtonAct );
       
    78 
       
    79     switch ( aOperationId ) {
       
    80     case ERemConCoreApiPausePlayFunction:
       
    81         if ( aButtonAct == ERemConCoreApiButtonClick ) {
       
    82             iMpEngine->playPause();
       
    83         }
       
    84         break;
       
    85     case ERemConCoreApiPlay:
       
    86         if ( aButtonAct == ERemConCoreApiButtonClick
       
    87              || aButtonAct == ERemConCoreApiButtonPress ) {
       
    88             iMpEngine->play();
       
    89         }
       
    90         break;
       
    91     case ERemConCoreApiStop:
       
    92         if ( aButtonAct == ERemConCoreApiButtonClick
       
    93              || aButtonAct == ERemConCoreApiButtonPress ) {
       
    94             iMpEngine->stop();
       
    95         }
       
    96         break;
       
    97     case ERemConCoreApiPause:
       
    98         if ( aButtonAct == ERemConCoreApiButtonClick
       
    99              || aButtonAct == ERemConCoreApiButtonPress ) {
       
   100             iMpEngine->pause();
       
   101         }
       
   102         break;
       
   103     case ERemConCoreApiRewind:
       
   104         switch ( aButtonAct ) {
       
   105         case ERemConCoreApiButtonPress:
       
   106             iMpEngine->startSeekBackward();
       
   107             break;
       
   108         case ERemConCoreApiButtonRelease:
       
   109             iMpEngine->stopSeeking();
       
   110             break;
       
   111         default:
       
   112             break;
       
   113         }
       
   114         break;
       
   115     case ERemConCoreApiFastForward:
       
   116         switch ( aButtonAct ) {
       
   117         case ERemConCoreApiButtonPress:
       
   118             iMpEngine->startSeekForward();
       
   119             break;
       
   120         case ERemConCoreApiButtonRelease:
       
   121             iMpEngine->stopSeeking();
       
   122             break;
       
   123         default:
       
   124             break;
       
   125         }
       
   126         break;
       
   127     case ERemConCoreApiBackward:
       
   128         if ( aButtonAct == ERemConCoreApiButtonClick ) {
       
   129             iMpEngine->skipBackward();
       
   130         }
       
   131         break;
       
   132     case ERemConCoreApiForward:
       
   133         if ( aButtonAct == ERemConCoreApiButtonClick ) {
       
   134             iMpEngine->skipForward();
       
   135         }
       
   136         break;
       
   137     // Pressing headset volume key only generates ButtonPress, however pressing and holding hardware side key
       
   138     // generates ButtonClick and after a while ButtonPressed, we should make sure increase/decrease only once
       
   139     case ERemConCoreApiVolumeUp:
       
   140         if ( aButtonAct == ERemConCoreApiButtonClick || 
       
   141              ( aButtonAct == ERemConCoreApiButtonPress && !iSideKeyAlreadyClicked ) ) {
       
   142             iSideKeyAlreadyClicked = true;
       
   143             iMpEngine->increaseVolume();
       
   144         }
       
   145         else if ( aButtonAct == ERemConCoreApiButtonRelease ) {
       
   146             iSideKeyAlreadyClicked = false;
       
   147         }
       
   148         break;
       
   149     case ERemConCoreApiVolumeDown:
       
   150         if ( aButtonAct == ERemConCoreApiButtonClick || 
       
   151              ( aButtonAct == ERemConCoreApiButtonPress && !iSideKeyAlreadyClicked ) ) {
       
   152             iSideKeyAlreadyClicked = true;
       
   153             iMpEngine->decreaseVolume();
       
   154         }
       
   155         else if ( aButtonAct == ERemConCoreApiButtonRelease ) {
       
   156             iSideKeyAlreadyClicked = false;
       
   157         }
       
   158         break;
       
   159     default:
       
   160         break;
       
   161     }
       
   162     iResponseHandler->CompleteAnyKey( aOperationId );
       
   163     TX_EXIT
       
   164 }
       
   165 
       
   166 /*!
       
   167  From MRemConCoreApiTargetObserver
       
   168  A 'play' command has been received.
       
   169  */
       
   170 void MpMediaKeyHandlerPrivate::MrccatoPlay(
       
   171     TRemConCoreApiPlaybackSpeed aSpeed,
       
   172     TRemConCoreApiButtonAction aButtonAct )
       
   173 {
       
   174     TX_ENTRY_ARGS( "aButtonAct=" << aButtonAct );
       
   175     Q_UNUSED(aSpeed);
       
   176 
       
   177     if ( ( aButtonAct == ERemConCoreApiButtonClick ) ||
       
   178         ( aButtonAct == ERemConCoreApiButtonPress ) ) {
       
   179             iMpEngine->play();
       
   180         }
       
   181     iResponseHandler->CompleteAnyKey( ERemConCoreApiPlay );
       
   182     TX_EXIT
       
   183 }
       
   184 
       
   185 /*!
       
   186  From MRemConCoreApiTargetObserver
       
   187  A 'tune function' command has been received.
       
   188  */
       
   189 void MpMediaKeyHandlerPrivate::MrccatoTuneFunction(
       
   190     TBool aTwoPart,
       
   191     TUint aMajorChannel,
       
   192     TUint aMinorChannel,
       
   193     TRemConCoreApiButtonAction aButtonAct )
       
   194 {
       
   195     Q_UNUSED(aTwoPart);
       
   196     Q_UNUSED(aMajorChannel);
       
   197     Q_UNUSED(aMinorChannel);
       
   198     Q_UNUSED(aButtonAct);
       
   199 
       
   200     iResponseHandler->CompleteAnyKey( ERemConCoreApiTuneFunction );
       
   201 }
       
   202 
       
   203 /*!
       
   204  From MRemConCoreApiTargetObserver
       
   205  A 'select disk function' has been received.
       
   206  */
       
   207 void MpMediaKeyHandlerPrivate::MrccatoSelectDiskFunction(
       
   208     TUint aDisk,
       
   209     TRemConCoreApiButtonAction aButtonAct )
       
   210 {
       
   211     Q_UNUSED(aDisk);
       
   212     Q_UNUSED(aButtonAct);
       
   213 
       
   214     iResponseHandler->CompleteAnyKey( ERemConCoreApiSelectDiskFunction );
       
   215 }
       
   216 
       
   217 /*!
       
   218  From MRemConCoreApiTargetObserver
       
   219  A 'select AV input function' has been received.
       
   220  */
       
   221 void MpMediaKeyHandlerPrivate::MrccatoSelectAvInputFunction(
       
   222     TUint8 aAvInputSignalNumber,
       
   223     TRemConCoreApiButtonAction aButtonAct )
       
   224 {
       
   225     Q_UNUSED(aAvInputSignalNumber);
       
   226     Q_UNUSED(aButtonAct);
       
   227 
       
   228     iResponseHandler->CompleteAnyKey( ERemConCoreApiSelectAvInputFunction );
       
   229 
       
   230 }
       
   231 
       
   232 /*!
       
   233  From MRemConCoreApiTargetObserver
       
   234  A 'select audio input function' has been received.
       
   235 */
       
   236 void MpMediaKeyHandlerPrivate::MrccatoSelectAudioInputFunction(
       
   237     TUint8 aAudioInputSignalNumber,
       
   238     TRemConCoreApiButtonAction aButtonAct )
       
   239 {
       
   240     Q_UNUSED(aAudioInputSignalNumber);
       
   241     Q_UNUSED(aButtonAct);
       
   242 
       
   243     iResponseHandler->CompleteAnyKey( ERemConCoreApiSelectAudioInputFunction );
       
   244 
       
   245 }
       
   246 
       
   247 /*!
       
   248  \internal
       
   249  */
       
   250 void MpMediaKeyHandlerPrivate::DoInitL()
       
   251 {
       
   252     TX_ENTRY
       
   253     // Register to remote control framework
       
   254     iInterfaceSelector = CRemConInterfaceSelector::NewL();
       
   255     CRemConCoreApiTarget *coreTarget = CRemConCoreApiTarget::NewL( *iInterfaceSelector, *this );
       
   256     CleanupStack::PushL( coreTarget );
       
   257     iInterfaceSelector->OpenTargetL();
       
   258     iResponseHandler = MpMediaKeyRemConResponse::NewL( *coreTarget );
       
   259     CleanupStack::Pop(coreTarget);
       
   260 
       
   261     iMpEngine = MpEngineFactory::sharedEngine();
       
   262     TX_EXIT
       
   263 }
       
   264