35 static const QString KIrServiceControlOperation = "handleCmd(int)"; |
35 static const QString KIrServiceControlOperation = "handleCmd(int)"; |
36 static const QString KIrServiceMonitorInterfaceName = "com.nokia.symbian.IInternetRadioMonitor"; |
36 static const QString KIrServiceMonitorInterfaceName = "com.nokia.symbian.IInternetRadioMonitor"; |
37 static const QString KIrServiceMonitorOperation = "registerNotifications()"; |
37 static const QString KIrServiceMonitorOperation = "registerNotifications()"; |
38 static const QString KIrServiceRefreshOperation = "refreshAllData()"; |
38 static const QString KIrServiceRefreshOperation = "refreshAllData()"; |
39 |
39 |
|
40 |
|
41 // Initialize the static member variable |
|
42 QMutex IrServiceClient::mMutex; |
|
43 int IrServiceClient::mRef = 0; |
|
44 bool IrServiceClient::mMonitoringStarted = false; |
|
45 IrServiceClient *IrServiceClient::mInstatnce = NULL; |
|
46 |
|
47 |
40 // ==================== MEMBER FUNCTIONS ====================== |
48 // ==================== MEMBER FUNCTIONS ====================== |
|
49 // Static function to get a singleton instance of IrServiceClient |
|
50 IrServiceClient* IrServiceClient::openInstance() |
|
51 { |
|
52 mMutex.lock(); |
|
53 if (NULL == mInstatnce) |
|
54 { |
|
55 mInstatnce = new IrServiceClient(); |
|
56 } |
|
57 if (mInstatnce != NULL) |
|
58 { |
|
59 mRef++; |
|
60 } |
|
61 mMutex.unlock(); |
|
62 return mInstatnce; |
|
63 } |
|
64 |
|
65 // Close a singleton instance of IrServiceClient |
|
66 void IrServiceClient::closeInstance() |
|
67 { |
|
68 if (mInstatnce != NULL) |
|
69 { |
|
70 mMutex.lock(); |
|
71 if (mRef > 0) |
|
72 { |
|
73 mRef--; |
|
74 } |
|
75 |
|
76 if (0 == mRef) |
|
77 { |
|
78 delete mInstatnce; |
|
79 } |
|
80 mMutex.unlock(); |
|
81 } |
|
82 } |
|
83 |
41 // Constructor |
84 // Constructor |
42 IrServiceClient::IrServiceClient(QObject *aParent) : |
85 IrServiceClient::IrServiceClient() : |
43 QObject(aParent), |
|
44 mIrAppInspector(NULL), |
86 mIrAppInspector(NULL), |
45 mMonitorReqOngoing(false), |
87 mMonitorReqOngoing(false), |
46 mControlReqOngoing(false), |
88 mControlReqOngoing(false), |
47 mMonitorRequest(NULL), |
89 mMonitorRequest(NULL), |
48 mRefreshRequest(NULL), |
90 mRefreshRequest(NULL), |
67 mControlRequest = NULL; |
109 mControlRequest = NULL; |
68 } |
110 } |
69 |
111 |
70 bool IrServiceClient::startMonitoringIrState() |
112 bool IrServiceClient::startMonitoringIrState() |
71 { |
113 { |
|
114 if (mMonitoringStarted) |
|
115 { |
|
116 refreshAllActiveHsWidgets(); |
|
117 return true; |
|
118 } |
|
119 |
|
120 // if this is the first active hs widget |
|
121 mMonitoringStarted = true; |
72 bool retVal = false; |
122 bool retVal = false; |
73 if (mIrAppInspector->isIrRunning()) |
123 if (mIrAppInspector->isIrRunning()) |
74 { |
124 { |
75 retVal = doSendRefreshRequest(); |
125 retVal = doSendRefreshRequest(); |
76 } |
126 } |
80 { |
130 { |
81 initHsWidgetNoRunStopped(); |
131 initHsWidgetNoRunStopped(); |
82 } |
132 } |
83 else |
133 else |
84 { |
134 { |
85 emit irStateChanged(IrAppState::NoRunInit); |
135 notifyIrStateChanged(IrAppState::NoRunInit); |
86 } |
136 } |
87 } |
137 } |
88 |
138 |
89 return mIrAppInspector->startInspectingIrRunningStatus() && retVal; |
139 return mIrAppInspector->startInspectingIrRunningStatus() && retVal; |
90 } |
140 } |
91 |
141 |
92 void IrServiceClient::stopMonitoringIrState() |
|
93 { |
|
94 delete mMonitorRequest; |
|
95 mMonitorRequest = NULL; |
|
96 |
|
97 delete mRefreshRequest; |
|
98 mRefreshRequest = NULL; |
|
99 } |
|
100 |
142 |
101 void IrServiceClient::initHsWidgetNoRunStopped() |
143 void IrServiceClient::initHsWidgetNoRunStopped() |
102 { |
144 { |
103 emit irStateChanged(IrAppState::NoRunStopped); |
|
104 |
|
105 QString stationName; |
145 QString stationName; |
106 if (loadStationName(stationName)) |
146 if (loadStationName(stationName)) |
107 { |
147 { |
108 emit stationNameUpdated(stationName); |
148 notifyStationNameUpdated(stationName); |
109 } |
149 } |
110 else |
150 else |
111 { |
151 { |
112 emit stationNameUpdated(QString("")); |
152 #ifdef SUBTITLE_STR_BY_LOCID |
113 } |
153 notifyStationNameUpdated(hbTrId("txt_irad_info_unnamed_station")); |
114 |
154 #else |
115 emit stationLogoUpdated(loadStationLogoFlag()); |
155 notifyStationNameUpdated(hbTrId("Unnamed station")); |
|
156 #endif |
|
157 } |
|
158 |
|
159 notifyStationLogoUpdated(loadStationLogoFlag()); |
|
160 |
|
161 notifyIrStateChanged(IrAppState::NoRunStopped); |
|
162 } |
|
163 |
|
164 void IrServiceClient::refreshAllActiveHsWidgets() |
|
165 { |
|
166 emit stationNameUpdated(mStationName); |
|
167 emit stationLogoUpdated(mStationLogoAvailable); |
|
168 emit metaDataUpdated(mMetaData); |
|
169 emit irStateChanged(mIrState); |
116 } |
170 } |
117 |
171 |
118 /****************************************************************** |
172 /****************************************************************** |
119 **************** Monitor Service Request ********************** |
173 **************** Monitor Service Request ********************** |
120 *******************************************************************/ |
174 *******************************************************************/ |
222 mMonitorReqOngoing = false; |
276 mMonitorReqOngoing = false; |
223 |
277 |
224 doSendMonitorRequest(); |
278 doSendMonitorRequest(); |
225 |
279 |
226 if (aRetValue.isValid() |
280 if (aRetValue.isValid() |
227 && aRetValue.canConvert(QVariant::List)) |
281 && aRetValue.canConvert<IrServiceDataList>()) |
228 { |
282 { |
229 QVariantList dataList = aRetValue.toList(); |
283 IrServiceDataList dataList; |
230 foreach (const QVariant& data, dataList) |
284 dataList = qVariantValue<IrServiceDataList>(aRetValue); |
231 { |
285 foreach (const IrServiceData& data, dataList) |
232 if (data.canConvert<IrServiceData>()) |
286 { |
233 { |
287 processNotificationData(data); |
234 IrServiceData serviceData = data.value<IrServiceData>(); |
|
235 processNotificationData(serviceData); |
|
236 } |
|
237 } |
288 } |
238 } |
289 } |
239 } |
290 } |
240 |
291 |
241 void IrServiceClient::handleMonitorRequestError(int aErrCode, const QString &aErrMessage) |
292 void IrServiceClient::handleMonitorRequestError(int aErrCode, const QString &aErrMessage) |
381 case IrAppInspector::StartingUp : |
432 case IrAppInspector::StartingUp : |
382 doSendRefreshRequest(); |
433 doSendRefreshRequest(); |
383 break; |
434 break; |
384 |
435 |
385 case IrAppInspector::Exiting : |
436 case IrAppInspector::Exiting : |
386 stopMonitoringIrState(); |
437 { |
387 |
438 clearMonitorServiceRequest(); |
388 if (isStationPlayed()) |
439 QString stationName; |
|
440 if (loadStationName(stationName)) |
389 { |
441 { |
390 resetHsWidgetExitStopped(); |
442 notifyMetaDataUpdated(QString("")); |
|
443 notifyStationNameUpdated(stationName); |
|
444 notifyStationLogoUpdated(loadStationLogoFlag()); |
|
445 notifyIrStateChanged(IrAppState::NoRunStopped); |
391 } |
446 } |
392 else |
447 else |
393 { |
448 { |
394 emit irStateChanged(IrAppState::NoRunInit); |
449 notifyIrStateChanged(IrAppState::NoRunInit); |
395 } |
450 } |
396 break; |
451 break; |
|
452 } |
397 |
453 |
398 default: |
454 default: |
399 break; |
455 break; |
400 } |
456 } |
401 } |
457 } |
402 |
458 |
403 void IrServiceClient::resetHsWidgetExitStopped() |
459 void IrServiceClient::clearMonitorServiceRequest() |
404 { |
460 { |
405 emit irStateChanged(IrAppState::NoRunStopped); |
461 delete mMonitorRequest; |
406 emit metaDataUpdated(QString("")); |
462 mMonitorRequest = NULL; |
|
463 |
|
464 delete mRefreshRequest; |
|
465 mRefreshRequest = NULL; |
407 } |
466 } |
408 |
467 |
409 // used to process service data sent from IR app. |
468 // used to process service data sent from IR app. |
410 void IrServiceClient::processNotificationData(const IrServiceData &aServiceData) |
469 void IrServiceClient::processNotificationData(const IrServiceData &aServiceData) |
411 { |
470 { |
417 switch (aServiceData.mType) |
476 switch (aServiceData.mType) |
418 { |
477 { |
419 case IrServiceNotification::StationName: |
478 case IrServiceNotification::StationName: |
420 if (data.canConvert(QVariant::String)) |
479 if (data.canConvert(QVariant::String)) |
421 { |
480 { |
422 emit stationNameUpdated(data.toString()); |
481 notifyStationNameUpdated(data.toString()); |
423 } |
482 } |
424 break; |
483 break; |
425 |
484 |
426 case IrServiceNotification::MetaData: |
485 case IrServiceNotification::MetaData: |
427 if (data.canConvert(QVariant::String)) |
486 if (data.canConvert(QVariant::String)) |
428 { |
487 { |
429 emit metaDataUpdated(data.toString()); |
488 notifyMetaDataUpdated(data.toString()); |
430 } |
489 } |
431 break; |
490 break; |
432 |
491 |
433 case IrServiceNotification::StationLogo: |
492 case IrServiceNotification::StationLogo: |
434 if (data.canConvert(QVariant::Bool)) |
493 if (data.canConvert(QVariant::Bool)) |
435 { |
494 { |
436 emit stationLogoUpdated(data.toBool()); |
495 notifyStationLogoUpdated(data.toBool()); |
437 } |
496 } |
438 break; |
497 break; |
439 |
498 |
440 case IrServiceNotification::IrState: |
499 case IrServiceNotification::IrState: |
441 if (data.canConvert(QVariant::Int)) |
500 if (data.canConvert(QVariant::Int)) |
442 { |
501 { |
443 emit irStateChanged((IrAppState::Type)data.toInt()); |
502 notifyIrStateChanged((IrAppState::Type)data.toInt()); |
444 } |
503 } |
445 break; |
504 break; |
446 |
505 |
447 default: |
506 default: |
448 break; |
507 break; |
474 } |
533 } |
475 |
534 |
476 aRequest->setInfo(reqInfo); |
535 aRequest->setInfo(reqInfo); |
477 } |
536 } |
478 |
537 |
|
538 void IrServiceClient::notifyStationNameUpdated(const QString &aStationName) |
|
539 { |
|
540 mStationName = aStationName; |
|
541 emit stationNameUpdated(mStationName); |
|
542 } |
|
543 |
|
544 void IrServiceClient::notifyStationLogoUpdated(bool aIsLogoAvailable) |
|
545 { |
|
546 mStationLogoAvailable = aIsLogoAvailable; |
|
547 emit stationLogoUpdated(mStationLogoAvailable); |
|
548 } |
|
549 |
|
550 void IrServiceClient::notifyMetaDataUpdated(const QString &aMetaData) |
|
551 { |
|
552 mMetaData = aMetaData; |
|
553 emit metaDataUpdated(mMetaData); |
|
554 } |
|
555 |
|
556 void IrServiceClient::notifyIrStateChanged(IrAppState::Type aNewState) |
|
557 { |
|
558 mIrState = aNewState; |
|
559 emit irStateChanged(mIrState); |
|
560 } |
|
561 |
479 bool IrServiceClient::isStationPlayed() |
562 bool IrServiceClient::isStationPlayed() |
480 { |
563 { |
481 QSettings settings(KIrSettingOrganization, KIrSettingApplicaton); |
564 QSettings settings(KIrSettingOrganization, KIrSettingApplication); |
482 QString stationName = settings.value(KIrSettingStationName,KIrDefaultStationName).toString(); |
565 QString stationName = settings.value(KIrSettingStationName,KIrDefaultStationName).toString(); |
483 return stationName != KIrDefaultStationName; |
566 return stationName != KIrDefaultStationName; |
484 } |
567 } |
485 |
568 |
486 bool IrServiceClient::loadStationLogoFlag() |
569 bool IrServiceClient::loadStationLogoFlag() |
487 { |
570 { |
488 QSettings settings(KIrSettingOrganization, KIrSettingApplicaton); |
571 QSettings settings(KIrSettingOrganization, KIrSettingApplication); |
489 return settings.value(KIrSettingStationLogoAvailable,false).toBool(); |
572 return settings.value(KIrSettingStationLogoAvailable,false).toBool(); |
490 } |
573 } |
491 |
574 |
492 bool IrServiceClient::loadStationName(QString &aStationName) |
575 bool IrServiceClient::loadStationName(QString &aStationName) |
493 { |
576 { |
494 QSettings settings(KIrSettingOrganization, KIrSettingApplicaton); |
577 QSettings settings(KIrSettingOrganization, KIrSettingApplication); |
495 aStationName = settings.value(KIrSettingStationName,KIrDefaultStationName).toString(); |
578 aStationName = settings.value(KIrSettingStationName,KIrDefaultStationName).toString(); |
496 if(aStationName != KIrDefaultStationName) |
579 if(aStationName != KIrDefaultStationName) |
497 { |
580 { |
498 return true; |
581 return true; |
499 } |
582 } |