25 #include "radiostation.h" |
29 #include "radiostation.h" |
26 #include "radioservicedef.h" |
30 #include "radioservicedef.h" |
27 #include "radionotificationdata.h" |
31 #include "radionotificationdata.h" |
28 #include "radiologger.h" |
32 #include "radiologger.h" |
29 |
33 |
|
34 // Constants |
|
35 const int NOTIFICATION_DELAY = 200; |
|
36 |
30 #define RUN_NOTIFY( type, data ) \ |
37 #define RUN_NOTIFY( type, data ) \ |
31 do { \ |
38 do { \ |
32 QVariant variant; \ |
39 QVariant variant; \ |
33 variant.setValue( RadioNotificationData( RadioServiceNotification::type, data ) ); \ |
40 variant.setValue( RadioNotificationData( RadioServiceNotification::type, data ) ); \ |
34 notify( variant ); \ |
41 notify( variant ); \ |
36 |
43 |
37 /*! |
44 /*! |
38 * |
45 * |
39 */ |
46 */ |
40 RadioMonitorService::RadioMonitorService( RadioUiEnginePrivate& engine ) : |
47 RadioMonitorService::RadioMonitorService( RadioUiEnginePrivate& engine ) : |
41 XQServiceProvider( RADIO_MONITOR_SERVICE, &engine.api() ), |
48 XQServiceProvider( RADIO_SERVICE +"."+ RADIO_MONITOR_SERVICE, &engine.api() ), |
42 mUiEngine( engine ), |
49 mUiEngine( engine ), |
43 mRadioStatus( RadioStatus::UnSpecified ) |
50 mRadioStatus( RadioStatus::UnSpecified ), |
44 { |
51 mNotificationTimer( new QTimer( this ) ) |
|
52 { |
|
53 mNotificationTimer->setSingleShot( true ); |
|
54 mNotificationTimer->setInterval( NOTIFICATION_DELAY ); |
|
55 Radio::connect( mNotificationTimer, SIGNAL(timeout()), |
|
56 this, SLOT(sendNotifications()) ); |
|
57 |
45 publishAll(); |
58 publishAll(); |
46 } |
59 } |
47 |
60 |
48 /*! |
61 /*! |
49 * |
62 * |
56 * |
69 * |
57 */ |
70 */ |
58 void RadioMonitorService::init() |
71 void RadioMonitorService::init() |
59 { |
72 { |
60 RadioStationModel* stationModel = &mUiEngine.api().stationModel(); |
73 RadioStationModel* stationModel = &mUiEngine.api().stationModel(); |
61 connectAndTest( stationModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), |
74 Radio::connect( stationModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), |
62 this, SLOT(notifyFavoriteCount()) ); |
75 this, SLOT(notifyFavoriteCount()) ); |
63 connectAndTest( stationModel, SIGNAL(favoriteChanged(RadioStation)), |
76 Radio::connect( stationModel, SIGNAL(favoriteChanged(RadioStation)), |
64 this, SLOT(notifyFavoriteCount()) ); |
77 this, SLOT(notifyFavoriteCount()) ); |
65 connectAndTest( stationModel, SIGNAL(stationDataChanged(RadioStation)), |
78 Radio::connect( stationModel, SIGNAL(stationDataChanged(RadioStation)), |
66 this, SLOT(notifyStationChange(RadioStation)) ); |
79 this, SLOT(notifyStationChange(RadioStation)) ); |
67 connectAndTest( stationModel, SIGNAL(radioTextReceived(RadioStation)), |
80 Radio::connect( stationModel, SIGNAL(radioTextReceived(RadioStation)), |
68 this, SLOT(notifyStationChange(RadioStation)) ); |
81 this, SLOT(notifyStationChange(RadioStation)) ); |
69 |
82 |
70 RadioUiEngine* uiEngine = &mUiEngine.api(); |
83 RadioUiEngine* uiEngine = &mUiEngine.api(); |
71 connectAndTest( uiEngine, SIGNAL(seekingStarted(int)), |
84 Radio::connect( uiEngine, SIGNAL(seekingStarted(int)), |
72 this, SLOT(notifyRadioStatus()) ); |
85 this, SLOT(notifyRadioStatus()) ); |
73 connectAndTest( uiEngine, SIGNAL(muteChanged(bool)), |
86 Radio::connect( uiEngine, SIGNAL(muteChanged(bool)), |
74 this, SLOT(notifyRadioStatus()) ); |
87 this, SLOT(notifyRadioStatus()) ); |
75 connectAndTest( uiEngine, SIGNAL(antennaStatusChanged(bool)), |
88 Radio::connect( uiEngine, SIGNAL(antennaStatusChanged(bool)), |
76 this, SLOT(notifyRadioStatus()) ); |
89 this, SLOT(notifyRadioStatus()) ); |
|
90 Radio::connect( uiEngine, SIGNAL(powerOffRequested()), |
|
91 this, SLOT(notifyRadioStatus()) ); |
77 |
92 |
78 mUiEngine.wrapper().addObserver( this ); |
93 mUiEngine.wrapper().addObserver( this ); |
79 |
94 |
80 notifyRadioStatus(); |
95 notifyRadioStatus(); |
81 } |
96 } |
82 |
97 |
83 /*! |
98 /*! |
84 * |
|
85 */ |
|
86 void RadioMonitorService::notifySong( const QString& song ) |
|
87 { |
|
88 RUN_NOTIFY( Song, song ); |
|
89 } |
|
90 |
|
91 /*! |
|
92 * Public slot |
99 * Public slot |
93 * |
100 * |
94 */ |
101 */ |
95 void RadioMonitorService::requestNotifications() |
102 void RadioMonitorService::requestNotifications() |
96 { |
103 { |
97 mRequestIndexes.append( setCurrentRequestAsync() ); |
104 //TODO: Uncomment when vendor id can be read from the client |
|
105 // if ( requestInfo().clientVendorId() == NOKIA_VENDORID ) { |
|
106 mRequestIndexes.append( setCurrentRequestAsync() ); |
|
107 // } |
98 } |
108 } |
99 |
109 |
100 /*! |
110 /*! |
101 * Public slot |
111 * Public slot |
102 * |
112 * |
114 notificationList.append( notification ); |
124 notificationList.append( notification ); |
115 |
125 |
116 notification.setValue( RadioNotificationData( RadioServiceNotification::FavoriteCount, stationModel.favoriteCount() ) ); |
126 notification.setValue( RadioNotificationData( RadioServiceNotification::FavoriteCount, stationModel.favoriteCount() ) ); |
117 notificationList.append( notification ); |
127 notificationList.append( notification ); |
118 |
128 |
119 notification.setValue( RadioNotificationData( RadioServiceNotification::Frequency, station.frequency() ) ); |
129 notification.setValue( RadioNotificationData( RadioServiceNotification::Frequency, RadioStation::parseFrequency( station.frequency() ) ) ); |
120 notificationList.append( notification ); |
130 notificationList.append( notification ); |
121 |
131 |
122 if ( !station.name().isEmpty() ) { |
132 if ( !station.name().isEmpty() ) { |
123 notification.setValue( RadioNotificationData( RadioServiceNotification::Name, station.name() ) ); |
133 notification.setValue( RadioNotificationData( RadioServiceNotification::Name, station.name() ) ); |
124 notificationList.append( notification ); |
134 notificationList.append( notification ); |
129 mUiEngine.api().genreToString( station.genre(), GenreTarget::HomeScreen ) ) ); |
139 mUiEngine.api().genreToString( station.genre(), GenreTarget::HomeScreen ) ) ); |
130 notificationList.append( notification ); |
140 notificationList.append( notification ); |
131 } |
141 } |
132 |
142 |
133 if ( !station.radioText().isEmpty() ) { |
143 if ( !station.radioText().isEmpty() ) { |
134 notification.setValue( RadioNotificationData( RadioServiceNotification::RadioText, station.radioText() ) ); |
144 const QString trimmedRadioText = trimHtmlTags( station.radioText() ); |
|
145 notification.setValue( RadioNotificationData( RadioServiceNotification::RadioText, trimmedRadioText ) ); |
135 notificationList.append( notification ); |
146 notificationList.append( notification ); |
136 } |
147 } |
137 |
148 |
138 if ( !station.url().isEmpty() ) { |
149 if ( !station.dynamicPsText().isEmpty() ) { |
139 notification.setValue( RadioNotificationData( RadioServiceNotification::HomePage, station.url() ) ); |
150 notification.setValue( RadioNotificationData( RadioServiceNotification::DynamicPS, station.dynamicPsText() ) ); |
140 notificationList.append( notification ); |
151 notificationList.append( notification ); |
141 } |
152 } |
142 |
153 |
143 //TODO: To be implemented |
154 checkIfCurrentStationIsFavorite(); |
144 // notification.setValue( RadioNotificationData( RadioServiceNotification::Song, ) ); |
|
145 // notificationList.append( notification ); |
|
146 |
155 |
147 completeRequest( setCurrentRequestAsync(), notificationList ); |
156 completeRequest( setCurrentRequestAsync(), notificationList ); |
148 } |
157 } |
149 |
158 |
150 /*! |
159 /*! |
154 { |
163 { |
155 RadioStatus::Status radioStatus = determineRadioStatus(); |
164 RadioStatus::Status radioStatus = determineRadioStatus(); |
156 |
165 |
157 if ( radioStatus != mRadioStatus ) { |
166 if ( radioStatus != mRadioStatus ) { |
158 if ( radioStatus == RadioStatus::Seeking ) { |
167 if ( radioStatus == RadioStatus::Seeking ) { |
159 connectAndTest( mUiEngine.api().scannerEngine(), SIGNAL(destroyed()), |
168 if ( RadioScannerEngine* scannerEngine = mUiEngine.api().scannerEngine() ) { |
160 this, SLOT(notifyRadioStatus()) ); |
169 Radio::connect( scannerEngine, SIGNAL(destroyed()), |
|
170 this, SLOT(notifyRadioStatus()) ); |
|
171 } |
161 } |
172 } |
162 |
173 |
163 mRadioStatus = radioStatus; |
174 mRadioStatus = radioStatus; |
164 RUN_NOTIFY( RadioStatus, radioStatus ); |
175 RUN_NOTIFY( RadioStatus, radioStatus ); |
165 } |
176 } |
193 const QString genre = uiEngine.genreToString( station.genre(), GenreTarget::HomeScreen ); |
208 const QString genre = uiEngine.genreToString( station.genre(), GenreTarget::HomeScreen ); |
194 notification.setValue( RadioNotificationData( RadioServiceNotification::Genre, genre ) ); |
209 notification.setValue( RadioNotificationData( RadioServiceNotification::Genre, genre ) ); |
195 list.append( notification ); |
210 list.append( notification ); |
196 } |
211 } |
197 |
212 |
|
213 if ( station.hasDataChanged( RadioStation::DynamicPsChanged ) ) { |
|
214 notification.setValue( RadioNotificationData( RadioServiceNotification::DynamicPS, station.dynamicPsText() ) ); |
|
215 list.append( notification ); |
|
216 } |
|
217 |
198 if ( station.hasDataChanged( RadioStation::NameChanged ) ) { |
218 if ( station.hasDataChanged( RadioStation::NameChanged ) ) { |
199 notification.setValue( RadioNotificationData( RadioServiceNotification::Name, station.name() ) ); |
219 notification.setValue( RadioNotificationData( RadioServiceNotification::Name, station.name() ) ); |
200 list.append( notification ); |
220 list.append( notification ); |
201 } |
221 } |
202 |
222 |
203 if ( station.hasDataChanged( RadioStation::UrlChanged ) ) { |
223 if ( station.hasDataChanged( RadioStation::RadioTextChanged ) ) { |
204 notification.setValue( RadioNotificationData( RadioServiceNotification::HomePage, station.url() ) ); |
224 const QString trimmedRadioText = trimHtmlTags( station.radioText() ); |
|
225 notification.setValue( RadioNotificationData( RadioServiceNotification::RadioText, trimmedRadioText ) ); |
205 list.append( notification ); |
226 list.append( notification ); |
206 } |
227 } |
207 |
228 |
208 if ( station.hasDataChanged( RadioStation::RadioTextChanged ) ) { |
|
209 notification.setValue( RadioNotificationData( RadioServiceNotification::RadioText, station.radioText() ) ); |
|
210 list.append( notification ); |
|
211 } |
|
212 |
|
213 notifyList( list ); |
229 notifyList( list ); |
|
230 } |
|
231 |
|
232 /*! |
|
233 * Private slot |
|
234 * |
|
235 */ |
|
236 void RadioMonitorService::sendNotifications() |
|
237 { |
|
238 notifyList( mNotificationList ); |
|
239 mNotificationList.clear(); |
214 } |
240 } |
215 |
241 |
216 /*! |
242 /*! |
217 * \reimp |
243 * \reimp |
218 */ |
244 */ |
219 void RadioMonitorService::tunedToFrequency( uint frequency, int reason ) |
245 void RadioMonitorService::tunedToFrequency( uint frequency, int reason ) |
220 { |
246 { |
221 Q_UNUSED( reason ); |
247 Q_UNUSED( reason ); |
222 if ( !mUiEngine.api().isScanning() ) { |
248 if ( !mUiEngine.api().isScanning() ) { |
223 RUN_NOTIFY( Frequency, frequency ); |
249 RUN_NOTIFY( Frequency, RadioStation::parseFrequency( frequency ) ); |
224 RadioStation station; |
250 RadioStation station; |
225 if ( mUiEngine.api().stationModel().findFrequency( frequency, station ) && !station.name().isEmpty() ) { |
251 if ( mUiEngine.api().stationModel().findFrequency( frequency, station ) && !station.name().isEmpty() ) { |
226 RUN_NOTIFY( Name, station.name() ); |
252 RUN_NOTIFY( Name, station.name() ); |
227 } |
253 } |
|
254 |
|
255 const int favoriteCount = mUiEngine.api().stationModel().favoriteCount(); |
|
256 if ( favoriteCount == 1 ) { |
|
257 checkIfCurrentStationIsFavorite(); |
|
258 } |
228 } |
259 } |
229 } |
260 } |
230 |
261 |
231 /*! |
262 /*! |
232 * |
263 * |
233 */ |
264 */ |
234 RadioStatus::Status RadioMonitorService::determineRadioStatus() const |
265 RadioStatus::Status RadioMonitorService::determineRadioStatus() const |
235 { |
266 { |
236 RadioUiEngine& uiEngine = mUiEngine.api(); |
267 RadioUiEngine& uiEngine = mUiEngine.api(); |
237 if ( uiEngine.isScanning() ) { |
268 if ( uiEngine.isPoweringOff() ) { |
|
269 return RadioStatus::PoweringOff; |
|
270 } else if ( uiEngine.isScanning() ) { |
238 return RadioStatus::Seeking; |
271 return RadioStatus::Seeking; |
239 } else if ( !uiEngine.isAntennaAttached() ) { |
272 } else if ( !uiEngine.isAntennaAttached() ) { |
240 return RadioStatus::NoAntenna; |
273 return RadioStatus::NoAntenna; |
241 } else if ( uiEngine.isMuted() ) { |
274 } else if ( uiEngine.isMuted() ) { |
242 return RadioStatus::Muted; |
275 return RadioStatus::Muted; |