38 #include "radioscannerengine.h" |
40 #include "radioscannerengine.h" |
39 #include "radiogenrelocalizer.h" |
41 #include "radiogenrelocalizer.h" |
40 #include "radiologger.h" |
42 #include "radiologger.h" |
41 |
43 |
42 // Constants |
44 // Constants |
43 const uint DEFAULT_MIN_FREQUENCY = 87500000; |
|
44 const uint RADIO_CENREP_UID = 0x2002FF52; |
45 const uint RADIO_CENREP_UID = 0x2002FF52; |
45 const uint RADIO_CENREP_FREQUENCY_KEY = 0x207; |
46 const uint RADIO_CENREP_FREQUENCY_KEY = 0x207; |
46 |
47 const uint RADIO_CENREP_HEADSET_VOLUME = 0x200; |
47 |
48 |
48 /*! |
49 const QLatin1String OVI_STORE_URL( "http://www.music.nokia.co.uk/Touch/Search.aspx?artistsearch=#artist#&titlesearch=#title#" ); |
49 * |
50 const QLatin1String OTHER_STORE_URL( "http://www.amazon.com/gp/search/ref=sr_adv_m_digital/?search-alias=digital-music&field-author=#artist#&field-title=#title#" ); |
50 */ |
51 const QLatin1String OTHER_STORE_ARTIST_TAG( "#artist#" ); |
51 uint RadioUiEngine::lastTunedFrequency() |
52 const QLatin1String OTHER_STORE_TITLE_TAG( "#title#" ); |
52 { |
53 const char WHITESPACE = ' '; |
53 uint frequency = DEFAULT_MIN_FREQUENCY; |
54 const char WHITESPACE_REPLACEMENT = '+'; |
|
55 |
|
56 // Constants used when launching radio server |
|
57 const QLatin1String RADIO_SERVER_NAME( "radioserver.exe" ); |
|
58 const QLatin1String RADIO_RANGE_USEURO( "useuro" ); |
|
59 const QLatin1String RADIO_RANGE_JAPAN( "japan" ); |
|
60 |
|
61 // ====== STATIC FUNCTIONS ======== |
|
62 |
|
63 /*! |
|
64 * Gets the last tuned frequency from central repository |
|
65 */ |
|
66 uint RadioUiEngine::lastTunedFrequency( uint defaultFrequency ) |
|
67 { |
|
68 uint frequency = defaultFrequency; |
54 |
69 |
55 #ifdef BUILD_WIN32 |
70 #ifdef BUILD_WIN32 |
56 QScopedPointer<QSettings> settings( new QSettings( "Nokia", "QtFmRadio" ) ); |
71 QScopedPointer<QSettings> settings( new QSettings( "Nokia", "QtFmRadio" ) ); |
57 frequency = settings->value( "CurrentFreq", DEFAULT_MIN_FREQUENCY ).toUInt(); |
72 frequency = settings->value( "CurrentFreq", DEFAULT_MIN_FREQUENCY ).toUInt(); |
58 if ( frequency == 0 ) { |
73 if ( frequency == 0 ) { |
59 frequency = DEFAULT_MIN_FREQUENCY; |
74 frequency = defaultFrequency; |
60 } |
75 } |
61 #else |
76 #else |
62 QScopedPointer<XQSettingsManager> settings( new XQSettingsManager() ); |
77 QScopedPointer<XQSettingsManager> settings( new XQSettingsManager() ); |
63 XQSettingsKey key( XQSettingsKey::TargetCentralRepository, RADIO_CENREP_UID, RADIO_CENREP_FREQUENCY_KEY ); |
78 XQSettingsKey key( XQSettingsKey::TargetCentralRepository, RADIO_CENREP_UID, RADIO_CENREP_FREQUENCY_KEY ); |
64 frequency = settings->readItemValue( key, XQSettingsManager::TypeInt ).toUInt(); |
79 frequency = settings->readItemValue( key, XQSettingsManager::TypeInt ).toUInt(); |
65 if ( frequency == 0 ) { |
80 if ( frequency == 0 ) { |
66 frequency = DEFAULT_MIN_FREQUENCY; |
81 frequency = defaultFrequency; |
67 } |
82 } |
68 #endif |
83 #endif |
69 |
84 |
70 return frequency; |
85 return frequency; |
71 } |
86 } |
|
87 |
|
88 /*! |
|
89 * Gets the last used volume level |
|
90 */ |
|
91 int RadioUiEngine::lastVolume() |
|
92 { |
|
93 int volume = DEFAULT_VOLUME_LEVEL; |
|
94 |
|
95 #ifndef BUILD_WIN32 |
|
96 QScopedPointer<XQSettingsManager> settings( new XQSettingsManager() ); |
|
97 XQSettingsKey key( XQSettingsKey::TargetCentralRepository, RADIO_CENREP_UID, RADIO_CENREP_HEADSET_VOLUME ); |
|
98 volume = settings->readItemValue( key, XQSettingsManager::TypeInt ).toInt(); |
|
99 if ( volume == 0 ) { |
|
100 volume = DEFAULT_VOLUME_LEVEL; |
|
101 } |
|
102 #endif |
|
103 |
|
104 return volume; |
|
105 } |
|
106 |
|
107 /*! |
|
108 * Launches the radio server process |
|
109 */ |
|
110 void RadioUiEngine::launchRadioServer() |
|
111 { |
|
112 QStringList args; |
|
113 args << RADIO_RANGE_USEURO; //TODO: Determine current region |
|
114 args << QString::number( lastTunedFrequency( 0 ) ); |
|
115 args << QString::number( lastVolume() ); |
|
116 |
|
117 QProcess serverProcess; |
|
118 bool success = serverProcess.startDetached( RADIO_SERVER_NAME, args ); |
|
119 LOG_ASSERT( success, LOG( "Failed to start radio server!" ) ); |
|
120 } |
|
121 |
|
122 // ====== MEMBER FUNCTIONS ======== |
72 |
123 |
73 /*! |
124 /*! |
74 * |
125 * |
75 */ |
126 */ |
76 RadioUiEngine::RadioUiEngine( QObject* parent ) : |
127 RadioUiEngine::RadioUiEngine( QObject* parent ) : |
194 Q_D( RadioUiEngine ); |
244 Q_D( RadioUiEngine ); |
195 return *d->mHistoryModel; |
245 return *d->mHistoryModel; |
196 } |
246 } |
197 |
247 |
198 /*! |
248 /*! |
199 * |
249 * Creates a scanner engine and returns a pointer to it |
200 */ |
250 * The returned pointer is wrapped inside a QScopedPointer to ensure this won't |
201 RadioScannerEngine* RadioUiEngine::createScannerEngine() |
251 * leak memory. The returned engine will be deleted even if the caller ignored |
202 { |
252 * the return value. |
203 Q_D( RadioUiEngine ); |
253 */ |
204 if ( !d->mScannerEngine ) { |
254 RadioScannerEnginePtr RadioUiEngine::createScannerEngine() |
205 d->mScannerEngine = new RadioScannerEngine( *d ); |
255 { |
206 } |
256 Q_D( RadioUiEngine ); |
207 return d->mScannerEngine; |
257 #if defined BUILD_WIN32 || defined __WINS__ |
|
258 Q_ASSERT_X( !d->mScannerEngine, "RadioUiEngine::createScannerEngine", "Previous scanner instance not freed" ); |
|
259 #endif |
|
260 |
|
261 RadioScannerEnginePtr enginePtr( new RadioScannerEngine( *d ) ); |
|
262 d->mScannerEngine = enginePtr; |
|
263 |
|
264 return enginePtr; |
208 } |
265 } |
209 |
266 |
210 /*! |
267 /*! |
211 * |
268 * |
212 */ |
269 */ |
365 /*! |
422 /*! |
366 * |
423 * |
367 */ |
424 */ |
368 void RadioUiEngine::openMusicStore( const RadioHistoryItem& item, MusicStore store ) |
425 void RadioUiEngine::openMusicStore( const RadioHistoryItem& item, MusicStore store ) |
369 { |
426 { |
370 Q_UNUSED( item ); |
427 QString artist = item.artist(); |
371 Q_UNUSED( store ); |
428 artist.replace( WHITESPACE, WHITESPACE_REPLACEMENT ); |
372 //TODO: Integrate to music store |
429 QString title = item.title(); |
|
430 title.replace( WHITESPACE, WHITESPACE_REPLACEMENT ); |
|
431 |
|
432 QString url = store == OviStore ? OVI_STORE_URL : OTHER_STORE_URL; |
|
433 url.replace( OTHER_STORE_ARTIST_TAG, artist ); |
|
434 url.replace( OTHER_STORE_TITLE_TAG, title ); |
|
435 |
|
436 launchBrowser( url ); |
|
437 } |
|
438 |
|
439 /*! |
|
440 * |
|
441 */ |
|
442 void RadioUiEngine::launchBrowser( const QString& url ) |
|
443 { |
|
444 QDesktopServices::openUrl( QUrl( url ) ); |
373 } |
445 } |
374 |
446 |
375 /*! |
447 /*! |
376 * Sets or unsets the engine to manual seek mode |
448 * Sets or unsets the engine to manual seek mode |
377 */ |
449 */ |