1 /* |
|
2 * Copyright (c) 2009 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: FM Radio widget radio service client |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <xqserviceglobal.h> |
|
20 |
|
21 // User includes |
|
22 #include "fmradiohswidgetradioserviceclient.h" |
|
23 #include "fmradiohswidget.h" |
|
24 #include "radioservicedef.h" |
|
25 #include "radionotificationdata.h" |
|
26 |
|
27 /*! |
|
28 Constructor |
|
29 */ |
|
30 FmRadioHsWidgetRadioServiceClient::FmRadioHsWidgetRadioServiceClient(QObject *parent) : |
|
31 QObject(parent), |
|
32 mRequestPending(false), |
|
33 mRadioMonitorRequest(0), |
|
34 mRadioControlRequest(0), |
|
35 mDataInitialized(false) |
|
36 { |
|
37 } |
|
38 |
|
39 /*! |
|
40 Destructor |
|
41 */ |
|
42 FmRadioHsWidgetRadioServiceClient::~FmRadioHsWidgetRadioServiceClient() |
|
43 { |
|
44 stopMonitoring(); |
|
45 } |
|
46 |
|
47 /*! |
|
48 * Initialize all data |
|
49 */ |
|
50 void FmRadioHsWidgetRadioServiceClient::init() |
|
51 { |
|
52 const bool radioIsRunning = false; //TODO: Find out if radio is running. Use P&S key for now |
|
53 if ( radioIsRunning ) { |
|
54 //startMonitoring(); |
|
55 } |
|
56 } |
|
57 |
|
58 |
|
59 /*! |
|
60 Starting of FM Radio. |
|
61 |
|
62 /param startupState |
|
63 */ |
|
64 /* |
|
65 void FmRadioHsWidgetRadioServiceClient::doStartFmRadio(FmRadioStartupState startupState) |
|
66 { |
|
67 if (!mRadioControlRequest) { |
|
68 createControlServiceRequest(); |
|
69 } |
|
70 |
|
71 QVariant commandArgument; |
|
72 switch (startupState) { |
|
73 case StartForeground: |
|
74 // TODO: Include header and remove comment. |
|
75 commandArgument.setValue(*//*RadioServiceCommand::Foreground*/ //6); |
|
76 /* break; |
|
77 case StartBackground: |
|
78 // TODO: Include header and remove comment. |
|
79 commandArgument.setValue(*//*RadioServiceCommand::Background*/ //7); |
|
80 /* break; |
|
81 default: |
|
82 break; |
|
83 } |
|
84 QList<QVariant> arguments; |
|
85 arguments.append(commandArgument); |
|
86 mRadioControlRequest->setArguments(arguments); |
|
87 |
|
88 bool res = mRadioControlRequest->send(); |
|
89 } |
|
90 */ |
|
91 /*! |
|
92 Bring FM Radio to foreground. |
|
93 |
|
94 */ |
|
95 void FmRadioHsWidgetRadioServiceClient::doChangeFmRadioVisibility(FmRadioVisibilty visibility) |
|
96 { |
|
97 QVariant commandArgument; |
|
98 switch (visibility) { |
|
99 case ToForeground: |
|
100 commandArgument.setValue((int) RadioServiceCommand::Foreground); |
|
101 break; |
|
102 case ToBackground: |
|
103 commandArgument.setValue((int) RadioServiceCommand::Background); |
|
104 case DoNotChange: |
|
105 default: |
|
106 break; |
|
107 } |
|
108 doSendControlRequest(commandArgument, visibility); |
|
109 } |
|
110 |
|
111 /*! |
|
112 Changing of FM Radio channel. |
|
113 |
|
114 /param command Command to execute. |
|
115 */ |
|
116 void FmRadioHsWidgetRadioServiceClient::doChangeFmRadioChannel( |
|
117 FmRadioChannelChangeCommand command) |
|
118 { |
|
119 QVariant commandArgument; |
|
120 switch (command) { |
|
121 case PreviousFavouriteChannel: |
|
122 commandArgument.setValue((int) RadioServiceCommand::Previous); |
|
123 break; |
|
124 case NextFavouriteChannel: |
|
125 commandArgument.setValue((int) RadioServiceCommand::Next); |
|
126 break; |
|
127 default: |
|
128 break; |
|
129 } |
|
130 doSendControlRequest(commandArgument, DoNotChange); |
|
131 } |
|
132 |
|
133 /*! |
|
134 Changing of FM Radio channel. |
|
135 |
|
136 /param command Command to execute. |
|
137 */ |
|
138 void FmRadioHsWidgetRadioServiceClient::doControlFmRadioAudio( |
|
139 FmRadioAudioControlCommand command) |
|
140 { |
|
141 QVariant commandArgument; |
|
142 switch (command) { |
|
143 case Mute: |
|
144 commandArgument.setValue((int) RadioServiceCommand::Pause); |
|
145 break; |
|
146 case Unmute: |
|
147 commandArgument.setValue((int) RadioServiceCommand::Play); |
|
148 break; |
|
149 default: |
|
150 break; |
|
151 } |
|
152 doSendControlRequest(commandArgument, DoNotChange); |
|
153 } |
|
154 |
|
155 /*! |
|
156 Start FM Radio information listening. |
|
157 */ |
|
158 void FmRadioHsWidgetRadioServiceClient::doSendControlRequest(QVariant &argument, |
|
159 FmRadioVisibilty visibility) |
|
160 { |
|
161 if (!mRadioControlRequest) { |
|
162 createControlServiceRequest(); |
|
163 } |
|
164 |
|
165 QList<QVariant> arguments; |
|
166 arguments.append(argument); |
|
167 mRadioControlRequest->setArguments(arguments); |
|
168 |
|
169 prepareRequestInfo(mRadioControlRequest, visibility); |
|
170 |
|
171 bool res = mRadioControlRequest->send(); |
|
172 |
|
173 if (!res) { |
|
174 int error = mRadioControlRequest->lastError(); |
|
175 handleRequestError(error); |
|
176 } |
|
177 |
|
178 //stopMonitoring(); |
|
179 //startMonitoring(); |
|
180 } |
|
181 |
|
182 /*! |
|
183 Start FM Radio information listening. |
|
184 */ |
|
185 void FmRadioHsWidgetRadioServiceClient::doSendMonitorRequest(FmRadioVisibilty visibility) |
|
186 { |
|
187 prepareRequestInfo(mRadioMonitorRequest, visibility); |
|
188 if (!mRequestPending) { |
|
189 //FmRadioHsWidgetRadioServiceSingleton::instance()->sendRequest(); |
|
190 mRequestPending = mRadioMonitorRequest->send(); |
|
191 } |
|
192 } |
|
193 |
|
194 /*! |
|
195 Handle changes in FM Radio information texts. |
|
196 |
|
197 /param value |
|
198 */ |
|
199 void FmRadioHsWidgetRadioServiceClient::handleFmRadioInformationChange(const QVariant& value) |
|
200 { |
|
201 mRequestPending = false; |
|
202 if (!mDataInitialized) { |
|
203 mRadioMonitorRequest->setOperation(KRadioServiceMonitorOperation); |
|
204 mDataInitialized = true; |
|
205 } |
|
206 startMonitoring(DoNotChange); |
|
207 if ( value.isValid() && value.canConvert( QVariant::List ) ) { |
|
208 QVariantList notificationList = value.toList(); |
|
209 foreach ( const QVariant& variant, notificationList ) { |
|
210 RadioNotificationData notification = variant.value<RadioNotificationData>(); |
|
211 const int notificationId = notification.mType; |
|
212 emit radioInformationChanged( notificationId, notification.mData ); |
|
213 } |
|
214 } |
|
215 } |
|
216 |
|
217 /*! |
|
218 Handles request error. |
|
219 |
|
220 /param int Error value. |
|
221 */ |
|
222 void FmRadioHsWidgetRadioServiceClient::handleRequestError(int error) |
|
223 { |
|
224 QString errorStr; |
|
225 QVariant var(FmRadioHsWidget::NotRunning); |
|
226 switch (error) { |
|
227 case XQService::ENoError: |
|
228 errorStr = "No error"; |
|
229 break; |
|
230 case XQService::EConnectionError: |
|
231 errorStr = "(/*!< Error in IPC Connection */"; |
|
232 break; |
|
233 case XQService::EConnectionClosed: |
|
234 errorStr = "/*!< IPC Connection is closed */"; |
|
235 stopMonitoring(); |
|
236 handleFmRadioStateChange(var); |
|
237 break; |
|
238 case XQService::EServerNotFound: |
|
239 errorStr = "/*!< Can not find server */"; |
|
240 break; |
|
241 case XQService::EIPCError: |
|
242 errorStr = "/*!< Known IPC error defined by SDK */"; |
|
243 break; |
|
244 case XQService::EUnknownError: |
|
245 errorStr = "/*!< Unknown IPC error */"; |
|
246 break; |
|
247 case XQService::ERequestPending: |
|
248 errorStr = "/*!< Already pending request */"; |
|
249 break; |
|
250 default: |
|
251 break; |
|
252 } |
|
253 } |
|
254 |
|
255 /*! |
|
256 Handle changes in FM Radio state. |
|
257 |
|
258 /param value New state of FM Radio. |
|
259 */ |
|
260 void FmRadioHsWidgetRadioServiceClient::handleFmRadioStateChange(QVariant& value) |
|
261 { |
|
262 if (value.isValid()) { |
|
263 emit radioStateChanged(value); |
|
264 } |
|
265 } |
|
266 |
|
267 /*! |
|
268 Handle request completion. |
|
269 |
|
270 /param value |
|
271 */ |
|
272 void FmRadioHsWidgetRadioServiceClient::requestCompleted(const QVariant& value) |
|
273 { |
|
274 if (value.isValid()) { |
|
275 } |
|
276 } |
|
277 |
|
278 /*! |
|
279 Handle error. |
|
280 |
|
281 /param errorCode |
|
282 /param errorMessage |
|
283 */ |
|
284 void FmRadioHsWidgetRadioServiceClient::handleError(int errorCode, const QString& errorMessage) |
|
285 { |
|
286 int e = errorCode; |
|
287 QString em = errorMessage; |
|
288 handleRequestError(e); |
|
289 } |
|
290 |
|
291 /*! |
|
292 Creates control service request object. |
|
293 */ |
|
294 void FmRadioHsWidgetRadioServiceClient::createControlServiceRequest() |
|
295 { |
|
296 if (!mRadioControlRequest) { |
|
297 QString fullInterfaceName = /*KRadioServiceName +"."+*/ KRadioServiceControlInterfaceName; |
|
298 mRadioControlRequest = mApplicationManager.create(fullInterfaceName, |
|
299 KRadioServiceControlOperation, false); |
|
300 |
|
301 if (mRadioControlRequest) { |
|
302 mRadioControlRequest->setEmbedded(false); |
|
303 mRadioControlRequest->setSynchronous(true); |
|
304 //TODO: Do backgound set through XQRequestInfo in MCL wk14. |
|
305 //mRadioControlRequest->setBackground(true); |
|
306 |
|
307 /* |
|
308 bool b = connect(mRadioControlRequest, SIGNAL(requestOk(const QVariant&)), this, |
|
309 SLOT(requestCompleted(const QVariant&))); |
|
310 bool t = connect(mRadioControlRequest, SIGNAL(requestError(int,const QString&)), this, |
|
311 SLOT(handleError(int,const QString&))); |
|
312 */ |
|
313 } |
|
314 } |
|
315 } |
|
316 |
|
317 /*! |
|
318 Creates monitor service request object. |
|
319 */ |
|
320 void FmRadioHsWidgetRadioServiceClient::createMonitorServiceRequest() |
|
321 { |
|
322 if (!mRadioMonitorRequest) { |
|
323 QString operation = mDataInitialized ? KRadioServiceMonitorOperation |
|
324 : KRadioServiceRefreshOperation; |
|
325 QString fullInterfaceName = /*KRadioServiceName +"."+*/ KRadioServiceMonitorInterfaceName; |
|
326 |
|
327 /* |
|
328 QList<XQAiwInterfaceDescriptor> list; |
|
329 list = mApplicationManager.list(KRadioServiceName, fullInterfaceName, ""); |
|
330 XQAiwInterfaceDescriptor interfaceDescriptor; |
|
331 foreach (XQAiwInterfaceDescriptor d, list) |
|
332 { |
|
333 QString in = d.interfaceName(); |
|
334 QString sn = d.serviceName(); |
|
335 if (sn == KRadioServiceName && in == fullInterfaceName) { |
|
336 interfaceDescriptor = d; |
|
337 } |
|
338 } |
|
339 */ |
|
340 |
|
341 /* |
|
342 mRadioMonitorRequest = mApplicationManager.create(interfaceDescriptor, |
|
343 KRadioServiceMonitorOperation, false); |
|
344 */ |
|
345 |
|
346 mRadioMonitorRequest = mApplicationManager.create( |
|
347 fullInterfaceName, operation, false); |
|
348 |
|
349 if (mRadioMonitorRequest) { |
|
350 connect(mRadioMonitorRequest, SIGNAL(requestOk(const QVariant&)), |
|
351 this, SLOT(handleFmRadioInformationChange(const QVariant&))); |
|
352 connect(mRadioMonitorRequest, |
|
353 SIGNAL(requestError(int,const QString&)), this, |
|
354 SLOT(handleError(int,const QString&))); |
|
355 |
|
356 mRadioMonitorRequest->setSynchronous(false); |
|
357 mRadioMonitorRequest->setEmbedded(false); |
|
358 } |
|
359 } |
|
360 } |
|
361 |
|
362 /*! |
|
363 Start radio monitoring. |
|
364 */ |
|
365 void FmRadioHsWidgetRadioServiceClient::startMonitoring(FmRadioVisibilty visibility) |
|
366 { |
|
367 //FmRadioHsWidgetRadioServiceSingleton::instance(this)->requestNotifications(this); |
|
368 |
|
369 if (!mRadioMonitorRequest) { |
|
370 createMonitorServiceRequest(); |
|
371 } |
|
372 doSendMonitorRequest(visibility); |
|
373 } |
|
374 |
|
375 /*! |
|
376 Stops radio monitoring. |
|
377 */ |
|
378 void FmRadioHsWidgetRadioServiceClient::stopMonitoring() |
|
379 { |
|
380 //FmRadioHsWidgetRadioServiceSingleton::instance(this)->cancelNotifications(this); |
|
381 |
|
382 if (mRadioMonitorRequest) { |
|
383 delete mRadioMonitorRequest; |
|
384 mRadioMonitorRequest = NULL; |
|
385 } |
|
386 mRequestPending = false; |
|
387 mDataInitialized = false; |
|
388 } |
|
389 |
|
390 /*! |
|
391 Prepares the visibility of the request. |
|
392 */ |
|
393 void FmRadioHsWidgetRadioServiceClient::prepareRequestInfo(XQAiwRequest *request, |
|
394 FmRadioVisibilty visibility) |
|
395 { |
|
396 XQRequestInfo info; |
|
397 switch (visibility) { |
|
398 case ToForeground: |
|
399 //info.setForeground(true); |
|
400 break; |
|
401 case ToBackground: |
|
402 info.setBackground(true); |
|
403 break; |
|
404 case DoNotChange: |
|
405 default: |
|
406 break; |
|
407 } |
|
408 if (request) { |
|
409 request->setInfo(info); |
|
410 bool a = request->isBackground(); |
|
411 } |
|
412 //bool f = info.isForeground(); |
|
413 bool b = info.isBackground(); |
|
414 } |
|
415 |
|
416 void FmRadioHsWidgetRadioServiceClient::test() |
|
417 { |
|
418 // Test is kept for example. We have to switch to use the XQAiwRequest and this includes workin example code. |
|
419 //XQAiwRequest* req; |
|
420 /* |
|
421 QUrl uri("application://101FF976"); |
|
422 QString a = "Uri=" + uri.toString(); |
|
423 if (uri.isValid()) { |
|
424 QString b = "isValid"; |
|
425 } |
|
426 QString c = "Uri authority=" + uri.authority(); |
|
427 */ |
|
428 /* |
|
429 QList<XQAiwInterfaceDescriptor> list = mApplicationManager.list(KRadioServiceName, KRadioServiceMonitorInterfaceName); |
|
430 foreach (XQAiwInterfaceDescriptor d, list) { |
|
431 QString in = d.interfaceName(); |
|
432 QString sn = d.serviceName(); |
|
433 } |
|
434 |
|
435 list = mApplicationManager.list(KRadioServiceName, KRadioServiceMonitorInterfaceName, ""); |
|
436 foreach (XQAiwInterfaceDescriptor d, list) { |
|
437 QString in = d.interfaceName(); |
|
438 QString sn = d.serviceName(); |
|
439 } |
|
440 |
|
441 list = mApplicationManager.list(KRadioServiceMonitorInterfaceName, ""); |
|
442 foreach (XQAiwInterfaceDescriptor d, list) { |
|
443 QString in = d.interfaceName(); |
|
444 QString sn = d.serviceName(); |
|
445 } |
|
446 */ |
|
447 //req = mApplicationManager.create(uri, false); |
|
448 |
|
449 /*req = mApplicationManager.create(KRadioServiceMonitorInterfaceName, KRadioServiceMonitorOperation, |
|
450 false);*/ |
|
451 |
|
452 /* /// |
|
453 if (!mRadioMonitorRequest) { |
|
454 createMonitorServiceRequest(); |
|
455 } |
|
456 bool res = mRadioMonitorRequest->send(); |
|
457 /// |
|
458 */ |
|
459 |
|
460 /*if (req) {*/ |
|
461 /* |
|
462 // Connect signals once |
|
463 bool a = connect(req, SIGNAL(requestOk(const QVariant&)), this, |
|
464 SLOT(handleOk(const QVariant&))); |
|
465 bool b = connect(req, SIGNAL(requestError(int,const QString&)), this, |
|
466 SLOT(handleError(int,const QString&))); |
|
467 */ |
|
468 /*bool b = connect(req, SIGNAL(requestOk(const QVariant&)), this, |
|
469 SLOT(handleFmRadioInformationChange(QVariant))); |
|
470 bool c = connect(req, SIGNAL(requestError(int,const QString&)), this, |
|
471 SLOT(handleError(int,const QString&)));*/ |
|
472 /* |
|
473 QList<QVariant> arg; |
|
474 arg << ""; |
|
475 req->setArguments(arg); |
|
476 */ |
|
477 /* |
|
478 QString op = req->operation(); |
|
479 req->setOperation(KRadioServiceMonitorOperation); |
|
480 op = req->operation(); |
|
481 */ |
|
482 /*bool res = req->send();*/ |
|
483 |
|
484 /*if (res) { |
|
485 //QTimer::singleShot(40000, this, SLOT(doSendMonitorRequest())); |
|
486 } |
|
487 else { |
|
488 // Request failed. |
|
489 int x = 2; |
|
490 } |
|
491 |
|
492 } |
|
493 else { |
|
494 int r; |
|
495 r = 5; |
|
496 }*/ |
|
497 } |
|