16 */ |
16 */ |
17 |
17 |
18 // User includes |
18 // User includes |
19 #include "radiomonitorservice.h" |
19 #include "radiomonitorservice.h" |
20 #include "radiouiengine.h" |
20 #include "radiouiengine.h" |
21 #include "radioserviceconst.h" |
21 #include "radiostationmodel.h" |
|
22 #include "radiostation.h" |
|
23 #include "radioservicedef.h" |
|
24 #include "radionotificationdata.h" |
|
25 |
|
26 #define RUN_NOTIFY( type, data ) \ |
|
27 do { \ |
|
28 QVariant variant; \ |
|
29 variant.setValue( RadioNotificationData( RadioServiceNotification::type, data ) ); \ |
|
30 notify( variant ); \ |
|
31 } while ( 0 ) |
22 |
32 |
23 /*! |
33 /*! |
24 * |
34 * |
25 */ |
35 */ |
26 RadioMonitorService::RadioMonitorService( RadioUiEngine& engine ) : |
36 RadioMonitorService::RadioMonitorService( RadioUiEngine& engine ) : |
27 XQServiceProvider( RADIO_MONITOR_SERVICE, &engine ), |
37 XQServiceProvider( RADIO_MONITOR_SERVICE, &engine ), |
28 mUiEngine( engine ), |
38 mUiEngine( engine ) |
29 mRequestIndex( 0 ) |
|
30 { |
39 { |
31 publishAll(); |
40 publishAll(); |
32 } |
41 } |
33 |
42 |
34 /*! |
43 /*! |
39 } |
48 } |
40 |
49 |
41 /*! |
50 /*! |
42 * |
51 * |
43 */ |
52 */ |
|
53 void RadioMonitorService::notifyFavoriteCount( const int favoriteCount ) |
|
54 { |
|
55 RUN_NOTIFY( FavoriteCount, favoriteCount ); |
|
56 } |
|
57 |
|
58 /*! |
|
59 * |
|
60 */ |
|
61 void RadioMonitorService::notifyAntennaStatus( bool connected ) |
|
62 { |
|
63 RUN_NOTIFY( AntennaConnected, connected ); |
|
64 } |
|
65 |
|
66 /*! |
|
67 * |
|
68 */ |
|
69 void RadioMonitorService::notifyRadioStatus( RadioStatus::Status radioStatus ) |
|
70 { |
|
71 RUN_NOTIFY( RadioStatus, radioStatus ); |
|
72 } |
|
73 |
|
74 /*! |
|
75 * |
|
76 */ |
|
77 void RadioMonitorService::notifyFrequency( const uint frequency ) |
|
78 { |
|
79 RUN_NOTIFY( Frequency, frequency ); |
|
80 } |
|
81 |
|
82 /*! |
|
83 * |
|
84 */ |
44 void RadioMonitorService::notifyName( const QString& name ) |
85 void RadioMonitorService::notifyName( const QString& name ) |
45 { |
86 { |
46 notify( RadioServiceNotification::Name, name ); |
87 RUN_NOTIFY( Name, name ); |
47 } |
88 } |
48 |
89 |
49 /*! |
90 /*! |
50 * |
91 * |
51 */ |
92 */ |
52 void RadioMonitorService::notifyGenre( const QString& genre ) |
93 void RadioMonitorService::notifyGenre( const QString& genre ) |
53 { |
94 { |
54 notify( RadioServiceNotification::Genre, genre ); |
95 RUN_NOTIFY( Genre, genre ); |
55 } |
96 } |
56 |
97 |
57 /*! |
98 /*! |
58 * |
99 * |
59 */ |
100 */ |
60 void RadioMonitorService::notifyRadioText( const QString& radioText ) |
101 void RadioMonitorService::notifyRadioText( const QString& radioText ) |
61 { |
102 { |
62 notify( RadioServiceNotification::RadioText, radioText ); |
103 RUN_NOTIFY( RadioText, radioText ); |
63 } |
104 } |
64 |
105 |
65 /*! |
106 /*! |
66 * |
107 * |
67 */ |
108 */ |
68 void RadioMonitorService::notifyHomepage( const QString& homepage ) |
109 void RadioMonitorService::notifyHomePage( const QString& homePage ) |
69 { |
110 { |
70 notify( RadioServiceNotification::Homepage, homepage ); |
111 RUN_NOTIFY( HomePage, homePage ); |
71 } |
112 } |
72 |
113 |
73 /*! |
114 /*! |
74 * |
115 * |
75 */ |
116 */ |
76 void RadioMonitorService::notifySong( const QString& song ) |
117 void RadioMonitorService::notifySong( const QString& song ) |
77 { |
118 { |
78 notify( RadioServiceNotification::Song, song ); |
119 RUN_NOTIFY( Song, song ); |
79 } |
120 } |
80 |
121 |
81 /*! |
122 /*! |
82 * Public slot |
123 * Public slot |
83 * |
124 * |
84 */ |
125 */ |
85 void RadioMonitorService::requestNotifications() |
126 void RadioMonitorService::requestNotifications() |
86 { |
127 { |
87 mRequestIndex = setCurrentRequestAsync(); |
128 mRequestIndexes.append( setCurrentRequestAsync() ); |
|
129 } |
|
130 |
|
131 /*! |
|
132 * Public slot |
|
133 * |
|
134 */ |
|
135 void RadioMonitorService::requestAllData() |
|
136 { |
|
137 const RadioStation station = mUiEngine.model().currentStation(); |
|
138 |
|
139 QVariantList notificationList; |
|
140 |
|
141 QVariant notification; |
|
142 notification.setValue( RadioNotificationData( RadioServiceNotification::FavoriteCount, mUiEngine.model().favoriteCount() ) ); |
|
143 notificationList.append( notification ); |
|
144 |
|
145 notification.setValue( RadioNotificationData( RadioServiceNotification::Frequency, station.frequency() ) ); |
|
146 notificationList.append( notification ); |
|
147 |
|
148 if ( !station.name().isEmpty() ) { |
|
149 notification.setValue( RadioNotificationData( RadioServiceNotification::Name, station.name() ) ); |
|
150 notificationList.append( notification ); |
|
151 } |
|
152 |
|
153 if ( station.genre() > 0 ) { |
|
154 notification.setValue( RadioNotificationData( RadioServiceNotification::Genre, mUiEngine.genreToString( station.genre(), GenreTarget::HomeScreen ) ) ); |
|
155 notificationList.append( notification ); |
|
156 } |
|
157 |
|
158 if ( !station.radioText().isEmpty() ) { |
|
159 notification.setValue( RadioNotificationData( RadioServiceNotification::RadioText, station.radioText() ) ); |
|
160 notificationList.append( notification ); |
|
161 } |
|
162 |
|
163 if ( !station.url().isEmpty() ) { |
|
164 notification.setValue( RadioNotificationData( RadioServiceNotification::HomePage, station.url() ) ); |
|
165 notificationList.append( notification ); |
|
166 } |
|
167 |
|
168 //TODO: To be implemented |
|
169 // notification.setValue( RadioNotificationData( RadioServiceNotification::Song, ) ); |
|
170 // notificationList.append( notification ); |
|
171 |
|
172 completeRequest( setCurrentRequestAsync(), notificationList ); |
88 } |
173 } |
89 |
174 |
90 /*! |
175 /*! |
91 * |
176 * |
92 */ |
177 */ |
93 void RadioMonitorService::notify( int notificationId, const QString& message ) |
178 void RadioMonitorService::notify( const QVariant& notification ) |
94 { |
179 { |
95 if ( mRequestIndex > 0 ) { |
180 QVariantList list; |
96 completeRequest( mRequestIndex, QString( "%1 %2" ).arg( notificationId ).arg( message ) ); |
181 list.append( notification ); |
97 mRequestIndex = 0; |
182 notifyList( list ); |
|
183 } |
|
184 |
|
185 /*! |
|
186 * |
|
187 */ |
|
188 void RadioMonitorService::notifyList( const QVariantList& list ) |
|
189 { |
|
190 if ( mRequestIndexes.count() > 0 ) { |
|
191 foreach ( int requestIndex, mRequestIndexes ) { |
|
192 completeRequest( requestIndex, list ); |
|
193 } |
|
194 mRequestIndexes.clear(); |
98 } |
195 } |
99 } |
196 } |