photosgallery/slideshow/view/src/shwmediakeyshandler.cpp
changeset 0 4e91876724a2
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     1 /*
       
     2 * Copyright (c) 2006-2006 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:    Command object factory
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <glxlog.h>
       
    22 #include <glxtracer.h>
       
    23 #include <coemain.h>
       
    24 //#include <ViaPlayerMediaKeyObserver.h>  // CViaPlayerMediaKeyObserver
       
    25 #include <e32keys.h>
       
    26 #include <e32event.h>
       
    27 
       
    28 #include "shwmediakeyshandler.h"
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // Constructor
       
    32 // ---------------------------------------------------------------------------
       
    33 //   
       
    34 CShwMediaKeyUtility::CShwMediaKeyUtility()
       
    35     {
       
    36     TRACER("CShwMediaKeyUtility::CShwMediaKeyUtility");
       
    37     GLX_LOG_ENTRY_EXIT("CShwMediaKeyUtility::CShwMediaKeyUtility()");
       
    38     }
       
    39     
       
    40 // ---------------------------------------------------------------------------
       
    41 // Destructor.  Remove itself as a listner from the ViaPlayerMediaKeyObserver
       
    42 // ---------------------------------------------------------------------------
       
    43 //   
       
    44 CShwMediaKeyUtility::~CShwMediaKeyUtility()
       
    45     {
       
    46     TRACER("CShwMediaKeyUtility::~CShwMediaKeyUtility");
       
    47     GLX_LOG_ENTRY_EXIT("CShwMediaKeyUtility::~CShwMediaKeyUtility()");
       
    48     delete iInterfaceSelector;
       
    49 
       
    50     }
       
    51     
       
    52 // ---------------------------------------------------------------------------
       
    53 // NewLC - Standard two phase constructor placing itself on the cleanup stack
       
    54 // ---------------------------------------------------------------------------
       
    55 //   
       
    56 CShwMediaKeyUtility* CShwMediaKeyUtility::NewLC()
       
    57     {
       
    58     TRACER("CShwMediaKeyUtility::NewLC");
       
    59     GLX_LOG_ENTRY_EXIT("CShwMediaKeyUtility::NewLC()");
       
    60     CShwMediaKeyUtility* self = new (ELeave) CShwMediaKeyUtility();
       
    61     CleanupStack::PushL(self);
       
    62     self->ConstructL();
       
    63     return self;
       
    64     }
       
    65     
       
    66 // ---------------------------------------------------------------------------
       
    67 // NewL - Standard two phase constructor
       
    68 // ---------------------------------------------------------------------------
       
    69 //   
       
    70 CShwMediaKeyUtility* CShwMediaKeyUtility::NewL()
       
    71     {
       
    72     TRACER("CShwMediaKeyUtility::NewL");
       
    73     GLX_LOG_ENTRY_EXIT_LEAVE_L("CShwMediaKeyUtility::NewL()");
       
    74     CShwMediaKeyUtility* self = CShwMediaKeyUtility::NewLC();
       
    75     CleanupStack::Pop(self);
       
    76     return self;
       
    77     }
       
    78     
       
    79 // ---------------------------------------------------------------------------
       
    80 // ConstructL - Adds istself as a media key listener to the
       
    81 //              ViaPlayerMediaKeyObserver
       
    82 // ---------------------------------------------------------------------------
       
    83 //   
       
    84 void CShwMediaKeyUtility::ConstructL()
       
    85     {
       
    86     TRACER("CShwMediaKeyUtility::ConstructL");
       
    87     GLX_LOG_ENTRY_EXIT_LEAVE_L("CShwMediaKeyUtility::ConstructL()");
       
    88     iInterfaceSelector = CRemConInterfaceSelector::NewL();
       
    89 
       
    90     iCoreTarget = CRemConCoreApiTarget::NewL(*iInterfaceSelector, *this);
       
    91     iInterfaceSelector->OpenTargetL();
       
    92     }
       
    93     
       
    94 // ----------------------------------------------------------------------------
       
    95 // MrccatoCommand()
       
    96 // Receives events (press/click/release) from the following buttons:
       
    97 // 'Play/Pause', 'Volume Up', 'Volume Down', 'Stop', 'Rewind', 'Forward'
       
    98 // ----------------------------------------------------------------------------
       
    99 //   
       
   100 void CShwMediaKeyUtility::MrccatoCommand(TRemConCoreApiOperationId aOperationId, 
       
   101                                      TRemConCoreApiButtonAction aButtonAct)
       
   102     {
       
   103     TRACER("CShwMediaKeyUtility::MrccatoCommand");
       
   104     GLX_LOG_ENTRY_EXIT("CShwMediaKeyUtility::MediaKeyEventL()");
       
   105     TStdScanCode scanCode = TranslateKeyEvent(aOperationId);
       
   106     DispatchKeyEvent(aButtonAct, scanCode);
       
   107     }
       
   108     
       
   109     
       
   110 // ---------------------------------------------------------------------------
       
   111 // DoSimulateKeyEvent - Add key event to application queue
       
   112 // ---------------------------------------------------------------------------
       
   113 //   
       
   114 void CShwMediaKeyUtility::DoSimulateKeyEvent(TRawEvent::TType aKeyCode, 
       
   115                                                         TStdScanCode aScanCode )
       
   116 	{
       
   117 	TRACER("CShwMediaKeyUtility::DoSimulateKeyEvent");
       
   118     GLX_LOG_ENTRY_EXIT("CShwMediaKeyUtility::DoSimulateKeyEvent()");
       
   119     TRawEvent rawEvent;
       
   120     rawEvent.Set(aKeyCode, aScanCode);
       
   121     UserSvr::AddEvent(rawEvent);  
       
   122 	}
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // TranslateKeyEvent - Translates RemCon keys into standard scan codes
       
   126 // ---------------------------------------------------------------------------
       
   127 //   
       
   128 TStdScanCode CShwMediaKeyUtility::TranslateKeyEvent(TRemConCoreApiOperationId aOperationId)
       
   129     {
       
   130     TRACER("CShwMediaKeyUtility::TranslateKeyEvent");
       
   131     GLX_LOG_ENTRY_EXIT("CShwMediaKeyUtility::TranslateKeyEvent()");
       
   132     
       
   133     TStdScanCode scanCode = EStdKeyNull;
       
   134     TRequestStatus status;
       
   135     
       
   136     switch (aOperationId)
       
   137         {
       
   138     case ERemConCoreApiVolumeUp:
       
   139         scanCode = EStdKeyIncVolume;
       
   140         break;
       
   141         
       
   142     case ERemConCoreApiVolumeDown:
       
   143         scanCode = EStdKeyDecVolume;
       
   144         break;
       
   145     case ERemConCoreApiPausePlayFunction:
       
   146         scanCode = EStdKeyDictaphonePlay;
       
   147         iCoreTarget->PausePlayFunctionResponse(status, KErrNone); 
       
   148         User::WaitForRequest(status);
       
   149   
       
   150         break;
       
   151         
       
   152     default:
       
   153         break;
       
   154         }
       
   155         
       
   156     return scanCode;
       
   157     }
       
   158     
       
   159 // ---------------------------------------------------------------------------
       
   160 // DispatchKeyEvent - Interperets the button action and acts accordingly
       
   161 // ---------------------------------------------------------------------------
       
   162 //   
       
   163 void CShwMediaKeyUtility::DispatchKeyEvent(TRemConCoreApiButtonAction aButtonAct,
       
   164                                                             TStdScanCode aScanCode)
       
   165     {
       
   166     TRACER("CShwMediaKeyUtility::DispatchKeyEvent");
       
   167     GLX_LOG_ENTRY_EXIT("CShwMediaKeyUtility::DispatchKeyEvent()");
       
   168 
       
   169     if (EStdKeyNull == aScanCode)
       
   170         {
       
   171         return;
       
   172         }
       
   173         
       
   174     switch (aButtonAct)
       
   175         {
       
   176     case ERemConCoreApiButtonPress:
       
   177         DoSimulateKeyEvent(TRawEvent::EKeyDown, aScanCode);
       
   178         break;
       
   179         
       
   180     case ERemConCoreApiButtonRelease:
       
   181         DoSimulateKeyEvent(TRawEvent::EKeyUp, aScanCode);
       
   182         break;
       
   183         
       
   184     case ERemConCoreApiButtonClick:
       
   185         DoSimulateKeyEvent(TRawEvent::EKeyDown, aScanCode);
       
   186         DoSimulateKeyEvent(TRawEvent::EKeyUp, aScanCode);
       
   187         break;
       
   188         }
       
   189     }
       
   190