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 <QTimer> |
|
20 #include <QSettings> |
|
21 |
|
22 // User includes |
|
23 #include "radioenginewrapper_win32_p.h" |
|
24 #include "radiosettings.h" |
|
25 #include "radiosettings_p.h" |
|
26 #include "radiologger.h" |
|
27 #include "radio_global.h" |
|
28 #include "radiostationhandlerif.h" |
|
29 #include "radioenginewrapperobserver.h" |
|
30 //#include "t_radiodataparser.h" |
|
31 |
|
32 static RadioEngineWrapperPrivate* theInstance = 0; |
|
33 |
|
34 const QString KKeyFrequency = "CurrentFreq"; |
|
35 const QString KKeyOffline = "Offline"; |
|
36 |
|
37 const uint KScanFrequencies[] = { |
|
38 87600000, |
|
39 88000000, |
|
40 89400000, |
|
41 96000000, |
|
42 97600000, |
|
43 100600000, |
|
44 101300000, |
|
45 102600000, |
|
46 103500000, |
|
47 104100000, |
|
48 105500000, |
|
49 107500000 |
|
50 }; |
|
51 |
|
52 const int KScanFrequencyCount = sizeof( KScanFrequencies ) / sizeof( KScanFrequencies[0] ); |
|
53 |
|
54 /*! |
|
55 * |
|
56 */ |
|
57 RadioEngineWrapperPrivate::RadioEngineWrapperPrivate( RadioEngineWrapper* wrapper, |
|
58 RadioStationHandlerIf& stationHandler ) : |
|
59 q_ptr( wrapper ), |
|
60 mStationHandler( stationHandler ), |
|
61 mTuneTimer( new QTimer( this ) ), |
|
62 mTuneReason( 0 ), |
|
63 mUseLoudspeaker( false ), |
|
64 mAntennaAttached( true ), |
|
65 mFrequency( 0 ), |
|
66 mNextFrequency( 0 ), |
|
67 mVolume( 5 ), |
|
68 mMaxVolume( 10000 ), |
|
69 mFrequencyStepSize( 50000 ), |
|
70 mRegionId( RadioRegion::Default ), |
|
71 mMinFrequency( 87500000 ), |
|
72 mMaxFrequency( 108000000 ), |
|
73 mManualSeekMode( false ) |
|
74 { |
|
75 ::theInstance = this; |
|
76 mEngineSettings.reset( new QSettings( "Nokia", "QtFmRadio" ) ); |
|
77 mFrequency = mEngineSettings->value( KKeyFrequency ).toUInt(); |
|
78 if ( mFrequency == 0 ) { |
|
79 mFrequency = mMinFrequency; |
|
80 } |
|
81 |
|
82 Radio::connect( mTuneTimer, SIGNAL(timeout()), this, SLOT(frequencyEvent()) ); |
|
83 mTuneTimer->setSingleShot( true ); |
|
84 } |
|
85 |
|
86 /*! |
|
87 * |
|
88 */ |
|
89 RadioEngineWrapperPrivate::~RadioEngineWrapperPrivate() |
|
90 { |
|
91 // Destructor needs to be defined because some member variables that are forward declared |
|
92 // in the header are managed by QT's smart pointers and they require that the owning class |
|
93 // has a non-inlined destructor. Compiler generates an inlined destructor if it isn't defined. |
|
94 } |
|
95 |
|
96 /*! |
|
97 * |
|
98 */ |
|
99 RadioEngineWrapperPrivate* RadioEngineWrapperPrivate::instance() |
|
100 { |
|
101 return ::theInstance; |
|
102 } |
|
103 |
|
104 /*! |
|
105 * Initializes the private implementation |
|
106 */ |
|
107 bool RadioEngineWrapperPrivate::init() |
|
108 { |
|
109 mUseLoudspeaker = false; |
|
110 if ( !mUseLoudspeaker ) { |
|
111 RUN_NOTIFY_LOOP( mObservers, audioRouteChanged( false ) ); |
|
112 } |
|
113 |
|
114 parseData(); |
|
115 return true; |
|
116 } |
|
117 |
|
118 /*! |
|
119 * Returns the settings handler owned by the engine |
|
120 */ |
|
121 RadioSettingsIf& RadioEngineWrapperPrivate::settings() |
|
122 { |
|
123 if ( !mSettings ) { |
|
124 mSettings.reset( new RadioSettings() ); |
|
125 // mSettings->d_func()->init( &mEngineHandler->ApplicationSettings() ); |
|
126 } |
|
127 return *mSettings; |
|
128 } |
|
129 |
|
130 /*! |
|
131 * Tunes to the given frequency |
|
132 */ |
|
133 void RadioEngineWrapperPrivate::setFrequency( uint frequency, const int reason ) |
|
134 { |
|
135 mNextFrequency = frequency; |
|
136 mTuneReason = reason; |
|
137 |
|
138 mTuneTimer->stop(); |
|
139 if ( !mManualSeekMode ) { |
|
140 mTuneTimer->start( 500 ); |
|
141 } else { |
|
142 frequencyEvent(); |
|
143 } |
|
144 } |
|
145 |
|
146 /*! |
|
147 * |
|
148 */ |
|
149 ObserverList& RadioEngineWrapperPrivate::observers() |
|
150 { |
|
151 return mObservers; |
|
152 } |
|
153 |
|
154 /*! |
|
155 * |
|
156 */ |
|
157 void RadioEngineWrapperPrivate::startSeeking( Seek::Direction direction, const int reason ) |
|
158 { |
|
159 mTuneReason = reason; |
|
160 mNextFrequency = 0; |
|
161 |
|
162 // Find the previous and next favorite from current frequency |
|
163 uint previous = 0; |
|
164 uint next = 0; |
|
165 for( int i = 0; i < KScanFrequencyCount; ++i ) { |
|
166 const uint testFreq = KScanFrequencies[i]; |
|
167 if ( KScanFrequencies[i] > mFrequency ) { |
|
168 next = testFreq; |
|
169 break; |
|
170 } |
|
171 previous = testFreq; |
|
172 } |
|
173 |
|
174 |
|
175 if ( direction == Seek::Up ) { |
|
176 if ( next == 0 ) { |
|
177 next = KScanFrequencies[0]; |
|
178 } |
|
179 mNextFrequency = next; |
|
180 } else { |
|
181 if ( previous == 0 ) { |
|
182 previous = KScanFrequencies[KScanFrequencyCount - 1]; |
|
183 } |
|
184 mNextFrequency = previous; |
|
185 } |
|
186 |
|
187 mTuneTimer->start( 1000 ); |
|
188 } |
|
189 |
|
190 /*! |
|
191 * |
|
192 */ |
|
193 void RadioEngineWrapperPrivate::cancelSeeking() |
|
194 { |
|
195 mTuneTimer->stop(); |
|
196 mNextFrequency = 0; |
|
197 } |
|
198 |
|
199 /*! |
|
200 * |
|
201 */ |
|
202 void RadioEngineWrapperPrivate::toggleAudioRoute() |
|
203 { |
|
204 mUseLoudspeaker = !mUseLoudspeaker; |
|
205 RUN_NOTIFY_LOOP( mObservers, audioRouteChanged( mUseLoudspeaker ) ); |
|
206 } |
|
207 |
|
208 /*! |
|
209 * |
|
210 */ |
|
211 QString RadioEngineWrapperPrivate::dataParsingError() const |
|
212 { |
|
213 return mParsingError; |
|
214 } |
|
215 |
|
216 /*! |
|
217 * |
|
218 */ |
|
219 void RadioEngineWrapperPrivate::setHeadsetStatus( bool connected ) |
|
220 { |
|
221 mAntennaAttached = connected; |
|
222 RUN_NOTIFY_LOOP( mObservers, antennaStatusChanged( mAntennaAttached ) ); |
|
223 } |
|
224 |
|
225 /*! |
|
226 * |
|
227 */ |
|
228 void RadioEngineWrapperPrivate::setVolume( int volume ) |
|
229 { |
|
230 mVolume = volume; |
|
231 RUN_NOTIFY_LOOP( mObservers, volumeChanged( mVolume ) ); |
|
232 } |
|
233 |
|
234 /*! |
|
235 * |
|
236 */ |
|
237 void RadioEngineWrapperPrivate::addSong( const QString& artist, const QString& title ) |
|
238 { |
|
239 QString radioText = QString( "Now Playing: %1 - %2" ).arg( artist ).arg( title ); |
|
240 mArtist = artist; |
|
241 mTitle = title; |
|
242 |
|
243 const uint frequency = mStationHandler.currentFrequency(); |
|
244 mStationHandler.setCurrentRadioText( frequency, radioText ); |
|
245 |
|
246 QTimer::singleShot( 500, this, SLOT(addSongTags()) ); |
|
247 } |
|
248 |
|
249 /*! |
|
250 * |
|
251 */ |
|
252 void RadioEngineWrapperPrivate::clearSong() |
|
253 { |
|
254 mStationHandler.setCurrentRadioText( mStationHandler.currentFrequency(), "" ); |
|
255 } |
|
256 |
|
257 /*! |
|
258 * |
|
259 */ |
|
260 bool RadioEngineWrapperPrivate::isOffline() const |
|
261 { |
|
262 return mEngineSettings->value( KKeyOffline, false ).toBool(); |
|
263 } |
|
264 |
|
265 /*! |
|
266 * |
|
267 */ |
|
268 void RadioEngineWrapperPrivate::setOffline( bool offline ) |
|
269 { |
|
270 mEngineSettings->setValue( KKeyOffline, offline ); |
|
271 } |
|
272 |
|
273 /*! |
|
274 * Private slot |
|
275 */ |
|
276 void RadioEngineWrapperPrivate::frequencyEvent() |
|
277 { |
|
278 if ( mNextFrequency > 0 ) { |
|
279 mFrequency = mNextFrequency; |
|
280 mEngineSettings->setValue( KKeyFrequency, mFrequency ); |
|
281 } |
|
282 |
|
283 if ( !mManualSeekMode ) { |
|
284 RUN_NOTIFY_LOOP( mObservers, tunedToFrequency( mNextFrequency, mTuneReason ) ); |
|
285 } |
|
286 } |
|
287 |
|
288 /*! |
|
289 * Private slot |
|
290 */ |
|
291 void RadioEngineWrapperPrivate::addSongTags() |
|
292 { |
|
293 const uint frequency = mStationHandler.currentFrequency(); |
|
294 mStationHandler.setCurrentRadioTextPlus( frequency, RtPlus::Artist, mArtist ); |
|
295 mStationHandler.setCurrentRadioTextPlus( frequency, RtPlus::Title, mTitle ); |
|
296 mArtist = ""; |
|
297 mTitle = ""; |
|
298 } |
|
299 |
|
300 /*! |
|
301 * |
|
302 */ |
|
303 void RadioEngineWrapperPrivate::parseData() |
|
304 { |
|
305 /* |
|
306 mDataParser.reset( new T_RadioDataParser() ); |
|
307 bool ok = mDataParser->parse(); |
|
308 if ( !ok ) { |
|
309 mParsingError = mDataParser->errorString(); |
|
310 } else { |
|
311 if ( mDataParser->mEngineSettings.mMaxVolume > 0 ) { |
|
312 mMaxVolume = mDataParser->mEngineSettings.mMaxVolume; |
|
313 } |
|
314 |
|
315 if ( mDataParser->mEngineSettings.mFrequencyStepSize > 0 ) { |
|
316 mFrequencyStepSize = mDataParser->mEngineSettings.mFrequencyStepSize; |
|
317 } |
|
318 |
|
319 if ( mDataParser->mEngineSettings.mRegionId >= 0 ) { |
|
320 mRegionId = static_cast<RadioRegion::Region>( mDataParser->mEngineSettings.mRegionId ); |
|
321 } |
|
322 |
|
323 if ( mDataParser->mEngineSettings.mMinFrequency > 0 ) { |
|
324 mMinFrequency = mDataParser->mEngineSettings.mMinFrequency; |
|
325 } |
|
326 |
|
327 if ( mDataParser->mEngineSettings.mMaxFrequency > 0 ) { |
|
328 mMaxFrequency = mDataParser->mEngineSettings.mMaxFrequency; |
|
329 } |
|
330 } |
|
331 */ |
|
332 } |
|