|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <QSettings> |
|
20 |
|
21 // User includes |
|
22 #include "irmonitorservice.h" |
|
23 #include "irapplication.h" |
|
24 #include "irplaycontroller.h" |
|
25 #include "irlastplayedstationinfo.h" |
|
26 #include "irqisdsdatastructure.h" |
|
27 #include "irqmetadata.h" |
|
28 #include "irplaylist.h" |
|
29 #include "irviewmanager.h" |
|
30 #include "irqlogger.h" |
|
31 |
|
32 // Contants |
|
33 static const QString IR_MONITOR_SERVICE = "internet_radio_10_1.com.nokia.symbian.IInternetRadioMonitor"; |
|
34 |
|
35 #define IS_READY(itemFlag) mReadyItems.testFlag(itemFlag) |
|
36 #define SET_FLAG(itemFlag) mReadyItems |= itemFlag |
|
37 #define CLEAR_FLAG(itemFlag) mReadyItems &= ~itemFlag |
|
38 #define CLEAR_ALL_FLAGS() mReadyItems &= !mReadyItems |
|
39 #define ANY_READY() \ |
|
40 mReadyItems.testFlag(StationName) || \ |
|
41 mReadyItems.testFlag(StationLogo) || \ |
|
42 mReadyItems.testFlag(MetaData) || \ |
|
43 mReadyItems.testFlag(IrState) |
|
44 |
|
45 // Constructor |
|
46 IrMonitorService::IrMonitorService(IRApplication *aIrApp, QObject *aParent) : |
|
47 XQServiceProvider(IR_MONITOR_SERVICE, aParent), |
|
48 mStationLogoAvailable(false), |
|
49 mIrState(IrAppState::Unknown), |
|
50 mIrApp(aIrApp), |
|
51 mPlayController(NULL) |
|
52 { |
|
53 publishAll(); |
|
54 mPlayController = mIrApp->getPlayController(); |
|
55 setupConnection(); |
|
56 } |
|
57 |
|
58 // Destructor |
|
59 IrMonitorService::~IrMonitorService() |
|
60 { |
|
61 } |
|
62 |
|
63 void IrMonitorService::setupConnection() |
|
64 { |
|
65 // meta data update |
|
66 connect(mPlayController, SIGNAL(metaDataAvailable(IRQMetaData*)), |
|
67 this, SLOT(updateMetaData(IRQMetaData*))); |
|
68 // station logo update |
|
69 connect(mPlayController, SIGNAL(stationLogoUpdated(bool)), |
|
70 this, SLOT(handleStationLogoUpdated(bool))); |
|
71 // connecting started |
|
72 connect(mPlayController, SIGNAL(connectingStarted(QString)), |
|
73 this, SLOT(handleLoadingStarted(QString))); |
|
74 // buffering started |
|
75 connect(mPlayController, SIGNAL(bufferingStarted(QString)), |
|
76 this, SLOT(handleLoadingStarted(QString))); |
|
77 // playing started |
|
78 connect(mPlayController, SIGNAL(playingStarted()), |
|
79 this, SLOT(handlePlayStarted())); |
|
80 // playing stopped |
|
81 connect(mPlayController, SIGNAL(playingStopped()), |
|
82 this, SLOT(handlePlayStopped())); |
|
83 // connecting cancelled |
|
84 connect(mPlayController, SIGNAL(connectingCancelled(QString)), |
|
85 this, SLOT(handleLoadingCancelled(QString))); |
|
86 // buffering cancelled |
|
87 connect(mPlayController, SIGNAL(bufferingCancelled(QString)), |
|
88 this, SLOT(handleLoadingCancelled(QString))); |
|
89 } |
|
90 |
|
91 // service interface, called via Qt Highway |
|
92 void IrMonitorService::registerNotifications() |
|
93 { |
|
94 mRequestList.append(setCurrentRequestAsync()); |
|
95 |
|
96 if (ANY_READY()) |
|
97 { |
|
98 notifyAll(); |
|
99 } |
|
100 } |
|
101 |
|
102 // service interface, called via Qt Highway |
|
103 void IrMonitorService::refreshAllData() |
|
104 { |
|
105 IrServiceDataList notificationList; |
|
106 |
|
107 IRQPreset * currentPreset = mPlayController->getNowPlayingPreset(); |
|
108 |
|
109 switch (mPlayController->state()) |
|
110 { |
|
111 case IRPlayController::EIdle: |
|
112 notificationList.append(IrServiceData((int)IrServiceNotification::IrState, (int)IrAppState::RunningInit)); |
|
113 break; |
|
114 |
|
115 case IRPlayController::EStopped: |
|
116 notificationList.append(IrServiceData((int)IrServiceNotification::StationName, currentPreset->name)); |
|
117 #ifdef HS_WIDGET_ENABLED |
|
118 notificationList.append(IrServiceData((int)IrServiceNotification::StationLogo, mPlayController->isStationLogoAvailable())); |
|
119 #endif |
|
120 notificationList.append(IrServiceData((int)IrServiceNotification::MetaData, QString(""))); |
|
121 notificationList.append(IrServiceData((int)IrServiceNotification::IrState, (int)IrAppState::RunningStopped)); |
|
122 break; |
|
123 |
|
124 #ifdef HS_WIDGET_ENABLED |
|
125 case IRPlayController::EConnecting: |
|
126 notificationList.append(IrServiceData((int)IrServiceNotification::StationName, mPlayController->getConnectingStationName())); |
|
127 notificationList.append(IrServiceData((int)IrServiceNotification::StationLogo, mPlayController->isStationLogoAvailable())); |
|
128 notificationList.append(IrServiceData((int)IrServiceNotification::MetaData, QString(""))); |
|
129 notificationList.append(IrServiceData((int)IrServiceNotification::IrState, (int)IrAppState::Loading)); |
|
130 break; |
|
131 #endif |
|
132 |
|
133 case IRPlayController::EBuffering: |
|
134 notificationList.append(IrServiceData((int)IrServiceNotification::StationName, currentPreset->name)); |
|
135 notificationList.append(IrServiceData((int)IrServiceNotification::StationLogo, mPlayController->isStationLogoAvailable())); |
|
136 notificationList.append(IrServiceData((int)IrServiceNotification::MetaData, QString(""))); |
|
137 notificationList.append(IrServiceData((int)IrServiceNotification::IrState, (int)IrAppState::Loading)); |
|
138 break; |
|
139 |
|
140 case IRPlayController::EPlaying: |
|
141 notificationList.append(IrServiceData((int)IrServiceNotification::StationName, currentPreset->name)); |
|
142 #ifdef HS_WIDGET_ENABLED |
|
143 notificationList.append(IrServiceData((int)IrServiceNotification::StationLogo, mPlayController->isStationLogoAvailable())); |
|
144 #endif |
|
145 notificationList.append(IrServiceData((int)IrServiceNotification::MetaData, mMetaData)); |
|
146 notificationList.append(IrServiceData((int)IrServiceNotification::IrState, (int)IrAppState::Playing)); |
|
147 break; |
|
148 |
|
149 default: |
|
150 break; |
|
151 } |
|
152 |
|
153 completeRequest(setCurrentRequestAsync(), qVariantFromValue(notificationList)); |
|
154 } |
|
155 |
|
156 /******************************************************************************************************** |
|
157 * SLOT for Play Controller |
|
158 ******************************************************************************************************* |
|
159 */ |
|
160 |
|
161 void IrMonitorService::updateMetaData(IRQMetaData* aMetaData) |
|
162 { |
|
163 if (aMetaData) |
|
164 { |
|
165 SET_FLAG(MetaData); |
|
166 mMetaData = aMetaData->getArtistSongName(); |
|
167 |
|
168 notifyAll(); |
|
169 } |
|
170 } |
|
171 |
|
172 void IrMonitorService::handleStationLogoUpdated(bool aLogoAvailable) |
|
173 { |
|
174 mStationLogoAvailable = aLogoAvailable; |
|
175 SET_FLAG(StationLogo); |
|
176 |
|
177 notifyAll(); |
|
178 } |
|
179 |
|
180 void IrMonitorService::handleLoadingStarted(const QString &aStationName) |
|
181 { |
|
182 mMetaData.clear(); |
|
183 SET_FLAG(MetaData); |
|
184 |
|
185 mStationName = aStationName; |
|
186 SET_FLAG(StationName); |
|
187 |
|
188 mIrState = IrAppState::Loading; |
|
189 SET_FLAG(IrState); |
|
190 |
|
191 notifyAll(); |
|
192 } |
|
193 |
|
194 void IrMonitorService::handleLoadingCancelled(const QString &aStationName) |
|
195 { |
|
196 mMetaData.clear(); |
|
197 SET_FLAG(MetaData); |
|
198 |
|
199 mStationName = aStationName; |
|
200 SET_FLAG(StationName); |
|
201 |
|
202 if (mPlayController->isStopped()) |
|
203 { |
|
204 mIrState = IrAppState::RunningStopped; |
|
205 } |
|
206 else |
|
207 { |
|
208 mIrState = IrAppState::RunningInit; |
|
209 } |
|
210 SET_FLAG(IrState); |
|
211 |
|
212 notifyAll(); |
|
213 } |
|
214 |
|
215 void IrMonitorService::handlePlayStarted() |
|
216 { |
|
217 mMetaData.clear(); |
|
218 SET_FLAG(MetaData); |
|
219 |
|
220 IRQPreset * currentPreset = mPlayController->getNowPlayingPreset(); |
|
221 mStationName = currentPreset->name; |
|
222 SET_FLAG(StationName); |
|
223 |
|
224 mIrState = IrAppState::Playing; |
|
225 SET_FLAG(IrState); |
|
226 |
|
227 notifyAll(); |
|
228 } |
|
229 |
|
230 void IrMonitorService::handlePlayStopped() |
|
231 { |
|
232 mMetaData.clear(); |
|
233 SET_FLAG(MetaData); |
|
234 |
|
235 mIrState = IrAppState::RunningStopped; |
|
236 SET_FLAG(IrState); |
|
237 |
|
238 notifyAll(); |
|
239 } |
|
240 |
|
241 |
|
242 /******************************************************************************************************** |
|
243 * Others |
|
244 ******************************************************************************************************* |
|
245 */ |
|
246 void IrMonitorService::notifyAll() |
|
247 { |
|
248 IrServiceDataList notificationList; |
|
249 |
|
250 if(IS_READY(StationName)) |
|
251 { |
|
252 notificationList.append(IrServiceData((int)IrServiceNotification::StationName, mStationName)); |
|
253 } |
|
254 |
|
255 if(IS_READY(StationLogo)) |
|
256 { |
|
257 notificationList.append(IrServiceData((int)IrServiceNotification::StationLogo, mStationLogoAvailable)); |
|
258 } |
|
259 |
|
260 if(IS_READY(MetaData)) |
|
261 { |
|
262 notificationList.append(IrServiceData((int)IrServiceNotification::MetaData, mMetaData)); |
|
263 } |
|
264 |
|
265 if(IS_READY(IrState)) |
|
266 { |
|
267 notificationList.append(IrServiceData((int)IrServiceNotification::IrState, (int)mIrState)); |
|
268 } |
|
269 |
|
270 if(notifyList(notificationList)) |
|
271 { |
|
272 CLEAR_ALL_FLAGS(); |
|
273 } |
|
274 } |
|
275 |
|
276 bool IrMonitorService::notifyList(const IrServiceDataList &aDataList) |
|
277 { |
|
278 bool retVal = true; |
|
279 |
|
280 if (mRequestList.count() > 0 |
|
281 && aDataList.count() > 0) |
|
282 { |
|
283 foreach (int requestId, mRequestList) |
|
284 { |
|
285 retVal &= completeRequest(requestId, qVariantFromValue(aDataList)); |
|
286 } |
|
287 mRequestList.clear(); |
|
288 } |
|
289 else |
|
290 { |
|
291 return false; |
|
292 } |
|
293 |
|
294 return retVal; |
|
295 } |
|
296 |
|
297 Q_IMPLEMENT_USER_METATYPE(IrServiceData) |
|
298 Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(IrServiceDataList) |
|
299 |