~ppsspp/ppsspp/ppsspp_1.3.0

« back to all changes in this revision

Viewing changes to ext/native/base/SymbianMediaKeys.cpp

  • Committer: Sérgio Benjamim
  • Date: 2017-01-02 00:12:05 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20170102001205-cxbta9za203nmjwm
1.3.0 source (from ppsspp_1.3.0-r160.p5.l1762.a165.t83~56~ubuntu16.04.1.tar.xz).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2013 Antti Pohjola
 
3
 *
 
4
 */
 
5
//Adds mediakey support for Symbian (volume up/down)
 
6
 
 
7
#include <QApplication>
 
8
#include "SymbianMediaKeys.h"
 
9
#include "input/keycodes.h"
 
10
#include "input/input_state.h"
 
11
#include "base/NativeApp.h"
 
12
 
 
13
#define KTimeOut 80
 
14
 
 
15
SymbianMediaKeys::SymbianMediaKeys()
 
16
        : CActive ( EPriorityNormal ){
 
17
        CActiveScheduler::Add( this );
 
18
        iInterfaceSelector = CRemConInterfaceSelector::NewL();
 
19
        iRemConCore = CRemConCoreApiTarget::NewL(*iInterfaceSelector, *this);
 
20
        iInterfaceSelector->OpenTargetL();
 
21
        
 
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()));
 
34
}
 
35
 
 
36
SymbianMediaKeys::~SymbianMediaKeys(){
 
37
        delete iInterfaceSelector;
 
38
        iRemConCore = NULL; //owned by interfaceselector
 
39
        Cancel();
 
40
        iResponseQ.Reset();
 
41
        iResponseQ.Close();
 
42
}
 
43
 
 
44
void SymbianMediaKeys::subscribeKeyEvent(QObject* aObject ){
 
45
        receiver = aObject;
 
46
}
 
47
 
 
48
/*
 
49
 * it seems that it takes about 600ms to get an update after buttonpress
 
50
 * */
 
51
void SymbianMediaKeys::MrccatoCommand(TRemConCoreApiOperationId aOperationId,TRemConCoreApiButtonAction aButtonAct){
 
52
        TRequestStatus status;
 
53
        switch( aOperationId ){
 
54
        case ERemConCoreApiPausePlayFunction:
 
55
        {
 
56
                switch (aButtonAct){
 
57
                case ERemConCoreApiButtonPress:
 
58
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_PLAY_PAUSE, KEY_DOWN));
 
59
                        break;
 
60
                case ERemConCoreApiButtonRelease:
 
61
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_PLAY_PAUSE, KEY_UP));
 
62
                        break;
 
63
                case ERemConCoreApiButtonClick:
 
64
                        playtimer->start(KTimeOut);
 
65
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_PLAY_PAUSE, KEY_DOWN));
 
66
                        break;
 
67
                default:
 
68
                        // Play/Pause unknown action
 
69
                        break;
 
70
                }
 
71
                break;
 
72
        }
 
73
 
 
74
        case ERemConCoreApiStop:
 
75
        {
 
76
                switch (aButtonAct){
 
77
                case ERemConCoreApiButtonPress:
 
78
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_STOP, KEY_DOWN));
 
79
                        break;
 
80
                case ERemConCoreApiButtonRelease:
 
81
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_STOP, KEY_UP));
 
82
                        break;
 
83
                case ERemConCoreApiButtonClick:
 
84
                        stoptimer->start(KTimeOut);
 
85
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_STOP, KEY_DOWN));
 
86
                        break;
 
87
                default:
 
88
                        break;
 
89
                }
 
90
                break;
 
91
        }
 
92
        case ERemConCoreApiRewind:
 
93
        {
 
94
                switch (aButtonAct){
 
95
                case ERemConCoreApiButtonPress:
 
96
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_PREVIOUS, KEY_DOWN));
 
97
                        break;
 
98
                case ERemConCoreApiButtonRelease:
 
99
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_PREVIOUS, KEY_UP));
 
100
                        break;
 
101
                case ERemConCoreApiButtonClick:
 
102
                        backwardtimer->start(KTimeOut);
 
103
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_PREVIOUS, KEY_DOWN));
 
104
                default:
 
105
                        break;
 
106
                }
 
107
                break;
 
108
        }
 
109
        case ERemConCoreApiFastForward:
 
110
        {
 
111
                switch (aButtonAct){
 
112
                case ERemConCoreApiButtonPress:
 
113
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_NEXT, KEY_DOWN));
 
114
                        break;
 
115
                case ERemConCoreApiButtonRelease:
 
116
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_NEXT, KEY_UP));
 
117
                        break;
 
118
                case ERemConCoreApiButtonClick:
 
119
                        forwardtimer->start(KTimeOut);
 
120
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_NEXT, KEY_DOWN));
 
121
                default:
 
122
                        break;
 
123
                }
 
124
                break;
 
125
        }
 
126
        case ERemConCoreApiVolumeUp:
 
127
        {
 
128
                switch (aButtonAct){
 
129
                case ERemConCoreApiButtonPress:
 
130
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_VOLUME_UP, KEY_DOWN));
 
131
                        break;
 
132
                case ERemConCoreApiButtonRelease:
 
133
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_VOLUME_UP, KEY_UP));
 
134
                        break;
 
135
                case ERemConCoreApiButtonClick:
 
136
                        voluptimer->start(KTimeOut);
 
137
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_VOLUME_UP, KEY_DOWN));
 
138
                default:
 
139
                        break;
 
140
                }
 
141
                break;
 
142
        }
 
143
        case ERemConCoreApiVolumeDown:
 
144
        {
 
145
                switch (aButtonAct){
 
146
                case ERemConCoreApiButtonPress:
 
147
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_VOLUME_DOWN, KEY_DOWN));
 
148
                        break;
 
149
                case ERemConCoreApiButtonRelease:
 
150
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_VOLUME_DOWN, KEY_UP));
 
151
                        break;
 
152
                case ERemConCoreApiButtonClick:
 
153
                        voldowntimer->start(KTimeOut);
 
154
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_VOLUME_DOWN, KEY_DOWN));
 
155
                default:
 
156
                        break;
 
157
                }
 
158
                break;
 
159
        }
 
160
        case ERemConCoreApiBackward:
 
161
        {
 
162
                switch (aButtonAct)
 
163
                {
 
164
                case ERemConCoreApiButtonPress:
 
165
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_PREVIOUS, KEY_DOWN));
 
166
                        break;
 
167
                case ERemConCoreApiButtonRelease:
 
168
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_PREVIOUS, KEY_UP));
 
169
                        break;
 
170
                case ERemConCoreApiButtonClick:
 
171
                        backwardtimer->start(KTimeOut);
 
172
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_PREVIOUS, KEY_DOWN));
 
173
                default:
 
174
                        break;
 
175
                }
 
176
                break;
 
177
        }
 
178
        case ERemConCoreApiForward:
 
179
        {
 
180
                switch (aButtonAct)
 
181
                {
 
182
                case ERemConCoreApiButtonPress:
 
183
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_NEXT, KEY_DOWN));
 
184
                        break;
 
185
                case ERemConCoreApiButtonRelease:
 
186
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_NEXT, KEY_UP));
 
187
                        break;
 
188
                case ERemConCoreApiButtonClick:
 
189
                        forwardtimer->start(KTimeOut);
 
190
                        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_NEXT, KEY_DOWN));
 
191
                default:
 
192
                        break;
 
193
                }
 
194
                break;
 
195
        }
 
196
 
 
197
        default:
 
198
                break;
 
199
        }
 
200
        //complete key event
 
201
        CompleteMediaKeyEvent( aOperationId );
 
202
}
 
203
 
 
204
void SymbianMediaKeys::MrccatoPlay(TRemConCoreApiPlaybackSpeed aSpeed,TRemConCoreApiButtonAction aButtonAct){
 
205
 
 
206
}
 
207
 
 
208
void SymbianMediaKeys::MrccatoTuneFunction(TBool aTwoPart, TUint aMajorChannel,TUint aMinorChannel,TRemConCoreApiButtonAction aButtonAct){
 
209
 
 
210
}
 
211
 
 
212
void SymbianMediaKeys::MrccatoSelectDiskFunction(TUint aDisk, TRemConCoreApiButtonAction aButtonAct){
 
213
 
 
214
}
 
215
 
 
216
void SymbianMediaKeys::MrccatoSelectAvInputFunction(TUint8 aAvInputSignalNumber,TRemConCoreApiButtonAction aButtonAct){
 
217
 
 
218
}
 
219
 
 
220
void SymbianMediaKeys::MrccatoSelectAudioInputFunction(TUint8 aAudioInputSignalNumber,TRemConCoreApiButtonAction aButtonAct){
 
221
 
 
222
}
 
223
 
 
224
void SymbianMediaKeys::CompleteMediaKeyEvent( TRemConCoreApiOperationId aOperationId ){
 
225
        if( !IsActive() ){
 
226
                switch ( aOperationId )
 
227
                {
 
228
                        case ERemConCoreApiVolumeUp:
 
229
                        {
 
230
                                iRemConCore->VolumeUpResponse( iStatus, KErrNone );
 
231
                                SetActive();
 
232
                                break;
 
233
                        }
 
234
 
 
235
                        case ERemConCoreApiVolumeDown:
 
236
                        {
 
237
                                iRemConCore->VolumeDownResponse( iStatus, KErrNone );
 
238
                                SetActive();
 
239
                                break;
 
240
                        }
 
241
                        case ERemConCoreApiPlay:
 
242
                        {
 
243
                                iRemConCore-> PlayResponse(iStatus, KErrNone);
 
244
                                SetActive();
 
245
                                break;
 
246
                        }
 
247
                        case ERemConCoreApiStop:
 
248
                        {
 
249
                                iRemConCore->StopResponse(iStatus, KErrNone);
 
250
                                SetActive();
 
251
                                break;
 
252
                        }
 
253
                        case ERemConCoreApiPause:
 
254
                        {
 
255
                                iRemConCore->PauseResponse(iStatus, KErrNone);
 
256
                                SetActive();
 
257
                                break;
 
258
                        }
 
259
                        case ERemConCoreApiRewind:
 
260
                        {
 
261
                                iRemConCore->RewindResponse(iStatus, KErrNone);
 
262
                                SetActive();
 
263
                                break;
 
264
                        }
 
265
                        case ERemConCoreApiFastForward:
 
266
                        {
 
267
                                iRemConCore->FastForwardResponse(iStatus, KErrNone);
 
268
                                SetActive();
 
269
                                break;
 
270
                        }
 
271
                        case ERemConCoreApiForward:
 
272
                        {
 
273
                                iRemConCore->ForwardResponse( iStatus, KErrNone );
 
274
                                SetActive();
 
275
                                break;
 
276
                        }
 
277
                        case ERemConCoreApiBackward:
 
278
                        {
 
279
                                iRemConCore->BackwardResponse(iStatus, KErrNone );
 
280
                                SetActive();
 
281
                                break;
 
282
                        }
 
283
                        default:
 
284
                                break;
 
285
                }
 
286
        }
 
287
        else{
 
288
                //active, append to queue
 
289
                iResponseQ.Append( aOperationId );
 
290
        }
 
291
}
 
292
 
 
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();
 
299
        }
 
300
}
 
301
 
 
302
void SymbianMediaKeys::DoCancel(){
 
303
}
 
304
 
 
305
void SymbianMediaKeys::playtimerexpired(){
 
306
        playtimer->stop();
 
307
        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_PLAY_PAUSE, KEY_UP));
 
308
}
 
309
 
 
310
void SymbianMediaKeys::stoptimerexpired(){
 
311
        stoptimer->stop();
 
312
        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_STOP, KEY_UP));
 
313
}
 
314
 
 
315
void SymbianMediaKeys::forwardtimerexpired(){
 
316
        forwardtimer->stop();
 
317
        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_NEXT, KEY_UP));
 
318
}
 
319
 
 
320
void SymbianMediaKeys::backwardtimerexpired(){
 
321
        backwardtimer->stop();
 
322
        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_MEDIA_PREVIOUS, KEY_UP));
 
323
}
 
324
 
 
325
void SymbianMediaKeys::voluptimerexpired(){
 
326
        voluptimer->stop();
 
327
        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_VOLUME_UP, KEY_UP));
 
328
}
 
329
 
 
330
void SymbianMediaKeys::voldowntimerexpired(){
 
331
        voldowntimer->stop();
 
332
        NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_VOLUME_DOWN, KEY_UP));
 
333
}