|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU Lesser General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU Lesser General Public License |
|
15 * along with this program. If not, |
|
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
17 * |
|
18 * Description: |
|
19 * |
|
20 */ |
|
21 |
|
22 #include "targetwrapper.h" |
|
23 |
|
24 #include <QMenuBar> |
|
25 #include <QApplication> |
|
26 #include <QVBoxLayout> |
|
27 #include <QPlainTextEdit> |
|
28 #include <QTimer> |
|
29 |
|
30 #include <QDebug> |
|
31 #include <QtGlobal> |
|
32 |
|
33 #include "responsehandler.h" |
|
34 #include "responsehandlerex.h" |
|
35 |
|
36 #include "txlogger.h" |
|
37 |
|
38 TargetWrapper::TargetWrapper() |
|
39 : |
|
40 selector(0), |
|
41 basicApi(false), |
|
42 callHandlingApi(false), |
|
43 target(0), |
|
44 targetEx(0), |
|
45 handler(0), |
|
46 handlerEx(0) |
|
47 { |
|
48 initMapping(); |
|
49 } |
|
50 |
|
51 TargetWrapper::~TargetWrapper() |
|
52 { |
|
53 delete selector; |
|
54 } |
|
55 |
|
56 void TargetWrapper::setBasicApi(bool basic) |
|
57 { |
|
58 basicApi = basic; |
|
59 } |
|
60 |
|
61 void TargetWrapper::setCallHandlingApi(bool callHandling) |
|
62 { |
|
63 callHandlingApi = callHandling; |
|
64 } |
|
65 |
|
66 |
|
67 void TargetWrapper::init() |
|
68 { |
|
69 try { |
|
70 delete selector; |
|
71 |
|
72 QT_TRAP_THROWING(selector = CRemConInterfaceSelector::NewL()); |
|
73 |
|
74 if (basicApi) { |
|
75 QT_TRAP_THROWING(target = CRemConCoreApiTarget::NewL(*selector, *this)); |
|
76 QT_TRAP_THROWING(handler = ResponseHandler::NewL(*target)); |
|
77 } |
|
78 |
|
79 if (callHandlingApi) { |
|
80 QT_TRAP_THROWING(targetEx = CRemConCallHandlingTarget::NewL(*selector, *this)); |
|
81 QT_TRAP_THROWING(handlerEx = ResponseHandlerEx::NewL(*targetEx)); |
|
82 } |
|
83 |
|
84 QT_TRAP_THROWING(selector->OpenTargetL()); |
|
85 |
|
86 } catch (const std::exception &e) { |
|
87 delete selector; |
|
88 selector = 0; |
|
89 target = 0; |
|
90 targetEx = 0; |
|
91 handler = 0; |
|
92 handlerEx = 0; |
|
93 qDebug() << "TargetWrapper::init - exception: " << e.what(); |
|
94 throw; |
|
95 } |
|
96 } |
|
97 |
|
98 Qt::Key TargetWrapper::mapKey(TRemConCoreApiOperationId aOperationId) |
|
99 { |
|
100 Qt::Key key = keyMapping.value(aOperationId); |
|
101 |
|
102 if (key != Qt::Key()) |
|
103 return key; |
|
104 else { |
|
105 return Qt::Key_unknown; |
|
106 } |
|
107 |
|
108 } |
|
109 |
|
110 void TargetWrapper::MrccatoCommand(TRemConCoreApiOperationId aOperationId, TRemConCoreApiButtonAction aButtonAct) |
|
111 { |
|
112 Qt::Key key = mapKey(aOperationId); |
|
113 |
|
114 switch (aButtonAct) { |
|
115 case ERemConCoreApiButtonPress: |
|
116 TX_LOG_ARGS("ERemConCoreApiButtonPress"); |
|
117 sendPressKey(key, Qt::NoModifier); |
|
118 break; |
|
119 case ERemConCoreApiButtonRelease: |
|
120 TX_LOG_ARGS("ERemConCoreApiButtonRelease"); |
|
121 sendReleaseKey(key, Qt::NoModifier); |
|
122 break; |
|
123 case ERemConCoreApiButtonClick: |
|
124 TX_LOG_ARGS("ERemConCoreApiButtonClick"); |
|
125 sendPressKey(key, Qt::NoModifier); |
|
126 sendReleaseKey(key, Qt::NoModifier); |
|
127 break; |
|
128 default: |
|
129 break; |
|
130 } |
|
131 |
|
132 |
|
133 handler->CompleteAnyKey(aOperationId); |
|
134 |
|
135 } |
|
136 |
|
137 void TargetWrapper::AnswerCall() |
|
138 { |
|
139 sendPressKey(Qt::Key_Call, Qt::NoModifier); |
|
140 sendReleaseKey(Qt::Key_Call, Qt::NoModifier); |
|
141 handlerEx->CompleteAnyKey(0); |
|
142 } |
|
143 |
|
144 void TargetWrapper::EndCall() |
|
145 { |
|
146 sendPressKey(Qt::Key_Hangup, Qt::NoModifier); |
|
147 sendReleaseKey(Qt::Key_Hangup, Qt::NoModifier); |
|
148 handlerEx->CompleteAnyKey(0); |
|
149 } |
|
150 |
|
151 void TargetWrapper::AnswerEndCall() |
|
152 { |
|
153 sendPressKey(Qt::Key_Hangup, Qt::NoModifier); //TODO: Qt::Key_ToggleCallHangup |
|
154 sendReleaseKey(Qt::Key_Hangup, Qt::NoModifier); |
|
155 handlerEx->CompleteAnyKey(0); |
|
156 } |
|
157 |
|
158 void TargetWrapper::VoiceDial( const TBool aActivate ) |
|
159 { |
|
160 Q_UNUSED(aActivate) |
|
161 } |
|
162 |
|
163 void TargetWrapper::LastNumberRedial() |
|
164 { |
|
165 } |
|
166 |
|
167 void TargetWrapper::DialCall( const TDesC8& aTelNumber ) |
|
168 { |
|
169 Q_UNUSED(aTelNumber) |
|
170 } |
|
171 |
|
172 void TargetWrapper::MultipartyCalling( const TDesC8& aData ) |
|
173 { |
|
174 Q_UNUSED(aData) |
|
175 } |
|
176 |
|
177 void TargetWrapper::GenerateDTMF( const TChar aChar ) |
|
178 { |
|
179 Q_UNUSED(aChar) |
|
180 } |
|
181 |
|
182 void TargetWrapper::SpeedDial( const TInt aIndex ) |
|
183 { |
|
184 Q_UNUSED(aIndex) |
|
185 } |
|
186 |
|
187 |
|
188 QWidget *TargetWrapper::getTargetWidget() |
|
189 { |
|
190 QWidget *widget; |
|
191 widget = QWidget::keyboardGrabber(); |
|
192 |
|
193 if (!widget) { |
|
194 widget = QApplication::focusWidget(); |
|
195 } |
|
196 |
|
197 if (!widget) { |
|
198 if (QApplication::activePopupWidget()) { |
|
199 widget = QApplication::activePopupWidget()->focusWidget(); |
|
200 if (!widget) { |
|
201 widget = QApplication::activePopupWidget(); |
|
202 } |
|
203 } |
|
204 } |
|
205 |
|
206 return widget; |
|
207 } |
|
208 |
|
209 void TargetWrapper::sendPressKey(Qt::Key key, Qt::KeyboardModifiers modFlags) |
|
210 { |
|
211 QWidget *widget = getTargetWidget(); |
|
212 if (widget) { |
|
213 QKeyEvent event(QKeyEvent::KeyPress, key, modFlags, 0, false, 1); |
|
214 QApplication::sendEvent(widget, &event); |
|
215 } |
|
216 qDebug("sending key event!"); |
|
217 } |
|
218 |
|
219 void TargetWrapper::sendReleaseKey(Qt::Key key, Qt::KeyboardModifiers modFlags) |
|
220 { |
|
221 QWidget *widget = getTargetWidget(); |
|
222 if (widget) { |
|
223 QKeyEvent event(QKeyEvent::KeyRelease, key, modFlags, 0, false, 1); |
|
224 QApplication::sendEvent(widget, &event); |
|
225 } |
|
226 } |
|
227 |
|
228 void TargetWrapper::initMapping() |
|
229 { |
|
230 keyMapping.insert(ERemConCoreApiSelect, Qt::Key_Select); |
|
231 keyMapping.insert(ERemConCoreApiUp, Qt::Key_Up); |
|
232 keyMapping.insert(ERemConCoreApiDown, Qt::Key_Down); |
|
233 keyMapping.insert(ERemConCoreApiLeft, Qt::Key_Left); // Qt::Key_Direction_L |
|
234 keyMapping.insert(ERemConCoreApiRight, Qt::Key_Right); // Qt::Key_Direction_R |
|
235 keyMapping.insert(ERemConCoreApiRightUp, Qt::Key_unknown); |
|
236 keyMapping.insert(ERemConCoreApiRightDown, Qt::Key_unknown); |
|
237 keyMapping.insert(ERemConCoreApiLeftUp, Qt::Key_unknown); |
|
238 keyMapping.insert(ERemConCoreApiLeftDown, Qt::Key_unknown); |
|
239 keyMapping.insert(ERemConCoreApiRootMenu, Qt::Key_TopMenu); // Qt::Key_Menu |
|
240 keyMapping.insert(ERemConCoreApiSetupMenu, Qt::Key_unknown); |
|
241 keyMapping.insert(ERemConCoreApiContentsMenu, Qt::Key_unknown); |
|
242 keyMapping.insert(ERemConCoreApiFavoriteMenu, Qt::Key_Favorites); |
|
243 keyMapping.insert(ERemConCoreApiExit, Qt::Key_unknown); // Qt::Key_Escape, Qt::Key_Cancel, Qt::Key_No |
|
244 keyMapping.insert(ERemConCoreApi0, Qt::Key_0); |
|
245 keyMapping.insert(ERemConCoreApi1, Qt::Key_1); |
|
246 keyMapping.insert(ERemConCoreApi2, Qt::Key_2); |
|
247 keyMapping.insert(ERemConCoreApi3, Qt::Key_3); |
|
248 keyMapping.insert(ERemConCoreApi4, Qt::Key_4); |
|
249 keyMapping.insert(ERemConCoreApi5, Qt::Key_5); |
|
250 keyMapping.insert(ERemConCoreApi6, Qt::Key_6); |
|
251 keyMapping.insert(ERemConCoreApi7, Qt::Key_7); |
|
252 keyMapping.insert(ERemConCoreApi8, Qt::Key_8); |
|
253 keyMapping.insert(ERemConCoreApi9, Qt::Key_9); |
|
254 keyMapping.insert(ERemConCoreApiDot, Qt::Key_Period); |
|
255 keyMapping.insert(ERemConCoreApiEnter, Qt::Key_Enter); |
|
256 keyMapping.insert(ERemConCoreApiClear, Qt::Key_Clear); |
|
257 keyMapping.insert(ERemConCoreApiChannelUp, Qt::Key_unknown); |
|
258 keyMapping.insert(ERemConCoreApiChannelDown, Qt::Key_unknown); |
|
259 keyMapping.insert(ERemConCoreApiPreviousChannel, Qt::Key_unknown); |
|
260 keyMapping.insert(ERemConCoreApiSoundSelect, Qt::Key_unknown); |
|
261 keyMapping.insert(ERemConCoreApiInputSelect, Qt::Key_unknown); |
|
262 keyMapping.insert(ERemConCoreApiDisplayInformation, Qt::Key_unknown); // Qt::Key_Time ??? |
|
263 keyMapping.insert(ERemConCoreApiHelp, Qt::Key_unknown); |
|
264 keyMapping.insert(ERemConCoreApiPageUp, Qt::Key_unknown); |
|
265 keyMapping.insert(ERemConCoreApiPageDown, Qt::Key_unknown); |
|
266 keyMapping.insert(ERemConCoreApiPower, Qt::Key_unknown); // Qt::Key_PowerOff, Qt::Key_WakeUp, Qt::Key_PowerDown, Qt::Key_Suspend |
|
267 keyMapping.insert(ERemConCoreApiVolumeUp, Qt::Key_VolumeUp); |
|
268 keyMapping.insert(ERemConCoreApiVolumeDown, Qt::Key_VolumeDown); |
|
269 keyMapping.insert(ERemConCoreApiMute, Qt::Key_unknown); |
|
270 keyMapping.insert(ERemConCoreApiPlay, Qt::Key_MediaPlay); |
|
271 keyMapping.insert(ERemConCoreApiStop, Qt::Key_MediaStop); |
|
272 keyMapping.insert(ERemConCoreApiPause, Qt::Key_unknown); // NEW: Qt::Key_MediaPause |
|
273 keyMapping.insert(ERemConCoreApiRecord, Qt::Key_MediaRecord); |
|
274 keyMapping.insert(ERemConCoreApiRewind, Qt::Key_AudioRewind); |
|
275 keyMapping.insert(ERemConCoreApiFastForward, Qt::Key_AudioForward); |
|
276 keyMapping.insert(ERemConCoreApiEject, Qt::Key_Eject); |
|
277 keyMapping.insert(ERemConCoreApiForward, Qt::Key_MediaNext); |
|
278 keyMapping.insert(ERemConCoreApiBackward, Qt::Key_MediaPrevious); |
|
279 keyMapping.insert(ERemConCoreApiAngle, Qt::Key_unknown); |
|
280 keyMapping.insert(ERemConCoreApiSubpicture, Qt::Key_unknown); // Qt::Key_SplitScreen ??? |
|
281 keyMapping.insert(ERemConCoreApiPausePlayFunction, Qt::Key_MediaPlay); // NEW: Media_PausePlay |
|
282 keyMapping.insert(ERemConCoreApiRestoreVolumeFunction, Qt::Key_unknown); |
|
283 keyMapping.insert(ERemConCoreApiTuneFunction, Qt::Key_unknown); |
|
284 keyMapping.insert(ERemConCoreApiSelectDiskFunction, Qt::Key_unknown); |
|
285 keyMapping.insert(ERemConCoreApiSelectAvInputFunction, Qt::Key_unknown); |
|
286 keyMapping.insert(ERemConCoreApiSelectAudioInputFunction, Qt::Key_unknown); |
|
287 keyMapping.insert(ERemConCoreApiF1, Qt::Key_F1); |
|
288 keyMapping.insert(ERemConCoreApiF2, Qt::Key_F2); |
|
289 keyMapping.insert(ERemConCoreApiF3, Qt::Key_F3); |
|
290 keyMapping.insert(ERemConCoreApiF4, Qt::Key_F4); |
|
291 keyMapping.insert(ERemConCoreApiF5, Qt::Key_F5); |
|
292 keyMapping.insert(ENop, Qt::Key_unknown); |
|
293 } |