2
* Copyright (c) 2013 Antti Pohjola
5
//Adds mediakey support for Symbian (volume up/down)
7
#include <QApplication>
8
#include "SymbianMediaKeys.h"
9
#include "input/keycodes.h"
10
#include "input/input_state.h"
11
#include "base/NativeApp.h"
15
SymbianMediaKeys::SymbianMediaKeys()
16
: CActive ( EPriorityNormal ){
17
CActiveScheduler::Add( this );
18
iInterfaceSelector = CRemConInterfaceSelector::NewL();
19
iRemConCore = CRemConCoreApiTarget::NewL(*iInterfaceSelector, *this);
20
iInterfaceSelector->OpenTargetL();
22
playtimer = new QTimer(this);
23
connect(playtimer, SIGNAL(timeout()), this, SLOT(playtimerexpired()));
24
stoptimer = new QTimer(this);
25
connect(stoptimer, SIGNAL(timeout()), this, SLOT(stoptimerexpired()));
26
forwardtimer = new QTimer(this);
27
connect(forwardtimer, SIGNAL(timeout()), this, SLOT(forwardtimerexpired()));
28
backwardtimer = new QTimer(this);
29
connect(backwardtimer, SIGNAL(timeout()), this, SLOT(backwardtimerexpired()));
30
voluptimer = new QTimer(this);
31
connect(voluptimer, SIGNAL(timeout()), this, SLOT(voluptimerexpired()));
32
voldowntimer = new QTimer(this);
33
connect(voldowntimer, SIGNAL(timeout()), this, SLOT(voldowntimerexpired()));
36
SymbianMediaKeys::~SymbianMediaKeys(){
37
delete iInterfaceSelector;
38
iRemConCore = NULL; //owned by interfaceselector
44
void SymbianMediaKeys::subscribeKeyEvent(QObject* aObject ){
49
* it seems that it takes about 600ms to get an update after buttonpress
51
void SymbianMediaKeys::MrccatoCommand(TRemConCoreApiOperationId aOperationId,TRemConCoreApiButtonAction aButtonAct){
52
TRequestStatus status;
53
switch( aOperationId ){
54
case ERemConCoreApiPausePlayFunction:
57
case ERemConCoreApiButtonPress:
58
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_PLAY_PAUSE, KEY_DOWN));
60
case ERemConCoreApiButtonRelease:
61
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_PLAY_PAUSE, KEY_UP));
63
case ERemConCoreApiButtonClick:
64
playtimer->start(KTimeOut);
65
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_PLAY_PAUSE, KEY_DOWN));
68
// Play/Pause unknown action
74
case ERemConCoreApiStop:
77
case ERemConCoreApiButtonPress:
78
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_STOP, KEY_DOWN));
80
case ERemConCoreApiButtonRelease:
81
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_STOP, KEY_UP));
83
case ERemConCoreApiButtonClick:
84
stoptimer->start(KTimeOut);
85
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_STOP, KEY_DOWN));
92
case ERemConCoreApiRewind:
95
case ERemConCoreApiButtonPress:
96
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_PREVIOUS, KEY_DOWN));
98
case ERemConCoreApiButtonRelease:
99
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_PREVIOUS, KEY_UP));
101
case ERemConCoreApiButtonClick:
102
backwardtimer->start(KTimeOut);
103
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_PREVIOUS, KEY_DOWN));
109
case ERemConCoreApiFastForward:
112
case ERemConCoreApiButtonPress:
113
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_NEXT, KEY_DOWN));
115
case ERemConCoreApiButtonRelease:
116
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_NEXT, KEY_UP));
118
case ERemConCoreApiButtonClick:
119
forwardtimer->start(KTimeOut);
120
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_NEXT, KEY_DOWN));
126
case ERemConCoreApiVolumeUp:
129
case ERemConCoreApiButtonPress:
130
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_VOLUME_UP, KEY_DOWN));
132
case ERemConCoreApiButtonRelease:
133
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_VOLUME_UP, KEY_UP));
135
case ERemConCoreApiButtonClick:
136
voluptimer->start(KTimeOut);
137
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_VOLUME_UP, KEY_DOWN));
143
case ERemConCoreApiVolumeDown:
146
case ERemConCoreApiButtonPress:
147
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_VOLUME_DOWN, KEY_DOWN));
149
case ERemConCoreApiButtonRelease:
150
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_VOLUME_DOWN, KEY_UP));
152
case ERemConCoreApiButtonClick:
153
voldowntimer->start(KTimeOut);
154
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_VOLUME_DOWN, KEY_DOWN));
160
case ERemConCoreApiBackward:
164
case ERemConCoreApiButtonPress:
165
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_PREVIOUS, KEY_DOWN));
167
case ERemConCoreApiButtonRelease:
168
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_PREVIOUS, KEY_UP));
170
case ERemConCoreApiButtonClick:
171
backwardtimer->start(KTimeOut);
172
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_PREVIOUS, KEY_DOWN));
178
case ERemConCoreApiForward:
182
case ERemConCoreApiButtonPress:
183
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_NEXT, KEY_DOWN));
185
case ERemConCoreApiButtonRelease:
186
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_NEXT, KEY_UP));
188
case ERemConCoreApiButtonClick:
189
forwardtimer->start(KTimeOut);
190
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_NEXT, KEY_DOWN));
201
CompleteMediaKeyEvent( aOperationId );
204
void SymbianMediaKeys::MrccatoPlay(TRemConCoreApiPlaybackSpeed aSpeed,TRemConCoreApiButtonAction aButtonAct){
208
void SymbianMediaKeys::MrccatoTuneFunction(TBool aTwoPart, TUint aMajorChannel,TUint aMinorChannel,TRemConCoreApiButtonAction aButtonAct){
212
void SymbianMediaKeys::MrccatoSelectDiskFunction(TUint aDisk, TRemConCoreApiButtonAction aButtonAct){
216
void SymbianMediaKeys::MrccatoSelectAvInputFunction(TUint8 aAvInputSignalNumber,TRemConCoreApiButtonAction aButtonAct){
220
void SymbianMediaKeys::MrccatoSelectAudioInputFunction(TUint8 aAudioInputSignalNumber,TRemConCoreApiButtonAction aButtonAct){
224
void SymbianMediaKeys::CompleteMediaKeyEvent( TRemConCoreApiOperationId aOperationId ){
226
switch ( aOperationId )
228
case ERemConCoreApiVolumeUp:
230
iRemConCore->VolumeUpResponse( iStatus, KErrNone );
235
case ERemConCoreApiVolumeDown:
237
iRemConCore->VolumeDownResponse( iStatus, KErrNone );
241
case ERemConCoreApiPlay:
243
iRemConCore-> PlayResponse(iStatus, KErrNone);
247
case ERemConCoreApiStop:
249
iRemConCore->StopResponse(iStatus, KErrNone);
253
case ERemConCoreApiPause:
255
iRemConCore->PauseResponse(iStatus, KErrNone);
259
case ERemConCoreApiRewind:
261
iRemConCore->RewindResponse(iStatus, KErrNone);
265
case ERemConCoreApiFastForward:
267
iRemConCore->FastForwardResponse(iStatus, KErrNone);
271
case ERemConCoreApiForward:
273
iRemConCore->ForwardResponse( iStatus, KErrNone );
277
case ERemConCoreApiBackward:
279
iRemConCore->BackwardResponse(iStatus, KErrNone );
288
//active, append to queue
289
iResponseQ.Append( aOperationId );
293
void SymbianMediaKeys::RunL(){
294
if ( iResponseQ.Count() ){
295
CompleteMediaKeyEvent( iResponseQ[0] );
296
//remove old response from que
297
iResponseQ.Remove(0);
298
iResponseQ.Compress();
302
void SymbianMediaKeys::DoCancel(){
305
void SymbianMediaKeys::playtimerexpired(){
307
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_PLAY_PAUSE, KEY_UP));
310
void SymbianMediaKeys::stoptimerexpired(){
312
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_STOP, KEY_UP));
315
void SymbianMediaKeys::forwardtimerexpired(){
316
forwardtimer->stop();
317
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_NEXT, KEY_UP));
320
void SymbianMediaKeys::backwardtimerexpired(){
321
backwardtimer->stop();
322
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_PREVIOUS, KEY_UP));
325
void SymbianMediaKeys::voluptimerexpired(){
327
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_VOLUME_UP, KEY_UP));
330
void SymbianMediaKeys::voldowntimerexpired(){
331
voldowntimer->stop();
332
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_VOLUME_DOWN, KEY_UP));