radioapp/radiouiengine/src/radiouiengine.cpp
changeset 32 189d20c34778
parent 28 075425b8d9a4
child 33 11b6825f0862
equal deleted inserted replaced
28:075425b8d9a4 32:189d20c34778
    18 // System includes
    18 // System includes
    19 #include <QScopedPointer>
    19 #include <QScopedPointer>
    20 #include <QProcess>
    20 #include <QProcess>
    21 #include <QFile>
    21 #include <QFile>
    22 #include <QTimer>
    22 #include <QTimer>
       
    23 #include <QDesktopServices>
       
    24 #include <QUrl>
    23 
    25 
    24 #ifdef BUILD_WIN32
    26 #ifdef BUILD_WIN32
    25 #   include <QSettings>
    27 #   include <QSettings>
    26 #else
    28 #else
    27 #   include <XQSettingsManager>
    29 #   include <XQSettingsManager>
    42 // Constants
    44 // Constants
    43 const uint DEFAULT_MIN_FREQUENCY = 87500000;
    45 const uint DEFAULT_MIN_FREQUENCY = 87500000;
    44 const uint RADIO_CENREP_UID = 0x2002FF52;
    46 const uint RADIO_CENREP_UID = 0x2002FF52;
    45 const uint RADIO_CENREP_FREQUENCY_KEY = 0x207;
    47 const uint RADIO_CENREP_FREQUENCY_KEY = 0x207;
    46 
    48 
       
    49 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 const QLatin1String OTHER_STORE_ARTIST_TAG( "#artist#" );
       
    51 const QLatin1String OTHER_STORE_TITLE_TAG( "#title#" );
       
    52 const char WHITESPACE = ' ';
       
    53 const char WHITESPACE_REPLACEMENT = '+';
    47 
    54 
    48 /*!
    55 /*!
    49  *
    56  *
    50  */
    57  */
    51 uint RadioUiEngine::lastTunedFrequency()
    58 uint RadioUiEngine::lastTunedFrequency()
    82 /*!
    89 /*!
    83  *
    90  *
    84  */
    91  */
    85 RadioUiEngine::~RadioUiEngine()
    92 RadioUiEngine::~RadioUiEngine()
    86 {
    93 {
    87     delete d_ptr;
       
    88 }
    94 }
    89 
    95 
    90 /*!
    96 /*!
    91  *
    97  *
    92  */
    98  */
   194     Q_D( RadioUiEngine );
   200     Q_D( RadioUiEngine );
   195     return *d->mHistoryModel;
   201     return *d->mHistoryModel;
   196 }
   202 }
   197 
   203 
   198 /*!
   204 /*!
   199  *
   205  * Creates a scanner engine and returns a pointer to it
   200  */
   206  * The returned pointer is wrapped inside a QScopedPointer to ensure this won't
   201 RadioScannerEngine* RadioUiEngine::createScannerEngine()
   207  * leak memory. The returned engine will be deleted even if the caller ignored
       
   208  * the return value.
       
   209  */
       
   210 RadioScannerEnginePtr RadioUiEngine::createScannerEngine()
   202 {
   211 {
   203     Q_D( RadioUiEngine );
   212     Q_D( RadioUiEngine );
   204     if ( !d->mScannerEngine ) {
   213     if ( !d->mScannerEngine ) {
   205         d->mScannerEngine = new RadioScannerEngine( *d );
   214         d->mScannerEngine = RadioScannerEnginePtr( new RadioScannerEngine( *d ) );
   206     }
   215     }
   207     return d->mScannerEngine;
   216     return d->mScannerEngine;
   208 }
   217 }
   209 
   218 
   210 /*!
   219 /*!
   230  */
   239  */
   231 bool RadioUiEngine::isScanning() const
   240 bool RadioUiEngine::isScanning() const
   232 {
   241 {
   233     Q_D( const RadioUiEngine );
   242     Q_D( const RadioUiEngine );
   234     if ( d->mScannerEngine ) {
   243     if ( d->mScannerEngine ) {
   235         return d->mScannerEngine->isScanning();
   244         return d->mScannerEngine.data()->isScanning();
   236     }
   245     }
   237     return false;
   246     return false;
   238 }
   247 }
   239 
   248 
   240 /*!
   249 /*!
   365 /*!
   374 /*!
   366  *
   375  *
   367  */
   376  */
   368 void RadioUiEngine::openMusicStore( const RadioHistoryItem& item, MusicStore store )
   377 void RadioUiEngine::openMusicStore( const RadioHistoryItem& item, MusicStore store )
   369 {
   378 {
   370     Q_UNUSED( item );
   379     if ( store == OviStore ) {
   371     Q_UNUSED( store );
   380         //TODO: Integrate to music store
   372     //TODO: Integrate to music store
   381     } else if ( store == OtherStore ) {
       
   382         QString artist = item.artist();
       
   383         artist.replace( WHITESPACE, WHITESPACE_REPLACEMENT );
       
   384         QString title = item.title();
       
   385         title.replace( WHITESPACE, WHITESPACE_REPLACEMENT );
       
   386 
       
   387         QString url( OTHER_STORE_URL );
       
   388         url.replace( OTHER_STORE_ARTIST_TAG, artist );
       
   389         url.replace( OTHER_STORE_TITLE_TAG, title );
       
   390 
       
   391         launchBrowser( url );
       
   392     }
       
   393 }
       
   394 
       
   395 /*!
       
   396  *
       
   397  */
       
   398 void RadioUiEngine::launchBrowser( const QString& url )
       
   399 {
       
   400     QDesktopServices::openUrl( QUrl( url ) );
   373 }
   401 }
   374 
   402 
   375 /*!
   403 /*!
   376  * Sets or unsets the engine to manual seek mode
   404  * Sets or unsets the engine to manual seek mode
   377  */
   405  */