diff -r 000000000000 -r 845549f293a7 voicerecorder/RecViewSrc/CVRRemConObserver.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/voicerecorder/RecViewSrc/CVRRemConObserver.cpp Thu Dec 17 08:46:57 2009 +0200 @@ -0,0 +1,185 @@ +/* +* Copyright (c) 2002 - 2006 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Class that observer remote controller framework events +* and forwards them as key events to observe +* +*/ + + +// INCLUDE FILES + +#include +#include +#include +#include +#include + +#include "MVRVolumeEventObserver.h" +#include "CVRRemConObserver.h" + + +// ============================ MEMBER FUNCTIONS ============================== + +// ---------------------------------------------------------------------------- +// CVRRemConObserver::CVRRemConObserver +// C++ default constructor can NOT contain any code, that +// might leave. +// ---------------------------------------------------------------------------- +// +CVRRemConObserver::CVRRemConObserver( MVRVolumeEventObserver* aObserver ) + : iObserver( aObserver ) + { + } + +// ---------------------------------------------------------------------------- +// CVRRemConObserver::ConstructL +// Symbian 2nd phase constructor can leave. +// ---------------------------------------------------------------------------- +// +void CVRRemConObserver::ConstructL() + { + iInterfaceSelector = CRemConInterfaceSelector::NewL(); + + iCoreTarget = CRemConCoreApiTarget::NewL( *iInterfaceSelector, *this ); + + iInterfaceSelector->OpenTargetL(); + + iVolumeRepeatTimer = CPeriodic::NewL( CActive::EPriorityHigh ); + } + +// ---------------------------------------------------------------------------- +// CVRRemConObserver::NewL +// Two-phased constructor. +// ---------------------------------------------------------------------------- +// +CVRRemConObserver* CVRRemConObserver::NewL( MVRVolumeEventObserver* aObserver ) + { + CVRRemConObserver* self = new( ELeave ) CVRRemConObserver( aObserver ); + + CleanupStack::PushL( self ); + self->ConstructL(); + CleanupStack::Pop(); + + return self; + } + + +// ---------------------------------------------------------------------------- +// CVRRemConObserver::~CVRRemConObserver +// Destructor +// ---------------------------------------------------------------------------- +// +CVRRemConObserver::~CVRRemConObserver() + { + delete iInterfaceSelector; // it internally deletes iCoreTarget + + if( iVolumeRepeatTimer->IsActive() ) + { + iVolumeRepeatTimer->Cancel(); + } + delete iVolumeRepeatTimer; + } + + +// ---------------------------------------------------------------------------- +// CVRRemConObserver::MrccatoCommand +// +// ---------------------------------------------------------------------------- +// +EXPORT_C void CVRRemConObserver::MrccatoCommand( + TRemConCoreApiOperationId aOperationId, + TRemConCoreApiButtonAction aButtonAct ) + { + TKeyEvent myEvent; + + if( iVolumeRepeatTimer->IsActive()) + { + iVolumeRepeatTimer->Cancel(); + } + + switch( aOperationId ) + { + case ERemConCoreApiVolumeUp: + { + // Simulate a "right button event" for CAknVolumeControl + myEvent.iCode = EKeyRightArrow; + break; + } + case ERemConCoreApiVolumeDown: + { + // Simulate a "left button event" for CAknVolumeControl + myEvent.iCode = EKeyLeftArrow; + break; + } + default: + { + // Ignore other commands + return; + } + } + + // Convert the remote control event to a button click and send it to + // volume control + switch( aButtonAct ) + { + case ERemConCoreApiButtonClick: + { + TRAP_IGNORE( iObserver->HandleVolumeChangeL( myEvent, + EEventKey ) ); + break; + } + case ERemConCoreApiButtonPress: + { + // Start repeat + iVolumeChange = myEvent; + iVolumeRepeatTimer->Cancel(); + iVolumeRepeatTimer->Start( + KAknStandardKeyboardRepeatRate, + KAknStandardKeyboardRepeatRate, + TCallBack( DoHandleVolumeRepeatL, this ) ); + break; + } + case ERemConCoreApiButtonRelease: + { + iVolumeChange.iCode = 0; + break; + } + default: + { + break; + } + } + + } + + +// ---------------------------------------------------------------------------- +// CVRRemConObserver::DoHandleVolumeRepeatL +// +// ---------------------------------------------------------------------------- +// +TInt CVRRemConObserver::DoHandleVolumeRepeatL( TAny* aAny ) + { + // Repeat last keypress + CVRRemConObserver* self = reinterpret_cast< CVRRemConObserver* >( aAny ); + if ( self->iObserver->HandleVolumeChangeL( self->iVolumeChange, EEventKey ) + != KErrNone ) + { + self->iVolumeChange.iCode = 0; + self->iVolumeRepeatTimer->Cancel(); + } + return KErrNone; + } + +// End of File