radioapp/radiouiengine/src/radiostation.cpp
changeset 41 3a6b55c6390c
parent 33 11b6825f0862
child 50 c44f9bb56771
equal deleted inserted replaced
33:11b6825f0862 41:3a6b55c6390c
   180  */
   180  */
   181 void RadioStation::setName( const QString& name )
   181 void RadioStation::setName( const QString& name )
   182 {
   182 {
   183     // Name emptiness is checked because this name setter is used by incoming RDS PS name
   183     // Name emptiness is checked because this name setter is used by incoming RDS PS name
   184     // and empty names should be ignored
   184     // and empty names should be ignored
   185     if ( !name.isEmpty() && !mData->mRenamedByUser && mData->mName.compare( name ) != 0 ) {
   185     if ( !name.isEmpty() && !mData->isRenamedByUser() && mData->mName.compare( name ) != 0 ) {
   186         mData->mName = name.trimmed();
   186         mData->mName = name.trimmed();
   187         mData->mChangeFlags |= RadioStation::PersistentDataChanged | RadioStation::NameChanged;
   187         mData->mChangeFlags |= RadioStation::PersistentDataChanged | RadioStation::NameChanged;
       
   188         mData->setStationHasSentRds( true );
   188 
   189 
   189         // Save the time when PS name changed and if the last change was too close to the current time
   190         // Save the time when PS name changed and if the last change was too close to the current time
   190         // change the PS type to dynamic if it has already been incorrectly determined to be static.
   191         // change the PS type to dynamic if it has already been incorrectly determined to be static.
   191         QTime previousChange = mData->mLastPsNameChangeTime;
   192         QTime previousChange = mData->mLastPsNameChangeTime;
   192         mData->mLastPsNameChangeTime = QTime::currentTime();
   193         mData->mLastPsNameChangeTime = QTime::currentTime();
   195             LOG( "Station changed PS name too often. PS type changed to Dynamic" );
   196             LOG( "Station changed PS name too often. PS type changed to Dynamic" );
   196             mData->mPsType = RadioStation::Dynamic;
   197             mData->mPsType = RadioStation::Dynamic;
   197             mData->mDynamicPsText = mData->mName;
   198             mData->mDynamicPsText = mData->mName;
   198             mData->mName = "";
   199             mData->mName = "";
   199             mData->mChangeFlags |= RadioStation::PsTypeChanged | RadioStation::DynamicPsChanged;
   200             mData->mChangeFlags |= RadioStation::PsTypeChanged | RadioStation::DynamicPsChanged;
   200             mData->mCallSignCheckDone = false;
   201             mData->setCallSignCheckDone( false );
   201         }
   202         }
   202 
   203 
   203         //TODO: This is a temporary thing to see some URL. Remove this
   204         //TODO: This is a temporary thing to see some URL. Remove this
   204         if ( !mData->mName.isEmpty() ) {
   205         if ( !mData->mName.isEmpty() ) {
   205             QString url = mData->mName.toLower().remove( " " );
   206             QString url = mData->mName.toLower().remove( " " );
   206             mData->mUrl = "www." + url + ".fi";
   207             mData->mUrl = "http://www." + url + ".fi";
   207         } else {
   208         } else {
   208             mData->mUrl = "";
   209             mData->mUrl = "";
   209         }
   210         }
   210         mData->mChangeFlags |= RadioStation::UrlChanged;
   211         mData->mChangeFlags |= RadioStation::UrlChanged;
   211         ASSERT_SHARED_NULL_IS_INTACT
   212         ASSERT_SHARED_NULL_IS_INTACT
   218 void RadioStation::setGenre( const int genre )
   219 void RadioStation::setGenre( const int genre )
   219 {
   220 {
   220     if ( mData->mGenre != genre ) {
   221     if ( mData->mGenre != genre ) {
   221         mData->mGenre = genre;
   222         mData->mGenre = genre;
   222         mData->mChangeFlags |= RadioStation::PersistentDataChanged | RadioStation::GenreChanged;
   223         mData->mChangeFlags |= RadioStation::PersistentDataChanged | RadioStation::GenreChanged;
       
   224 
       
   225         // Note that setStationHasSentRds() is not set when genre or pi code arrives.
       
   226 
   223         ASSERT_SHARED_NULL_IS_INTACT
   227         ASSERT_SHARED_NULL_IS_INTACT
   224     }
   228     }
   225 }
   229 }
   226 
   230 
   227 /*!
   231 /*!
   230 void RadioStation::setUrl( const QString& url )
   234 void RadioStation::setUrl( const QString& url )
   231 {
   235 {
   232     if ( mData->mUrl.compare( url ) != 0 ) {
   236     if ( mData->mUrl.compare( url ) != 0 ) {
   233         mData->mUrl = url;
   237         mData->mUrl = url;
   234         mData->mChangeFlags |= RadioStation::PersistentDataChanged | RadioStation::UrlChanged;
   238         mData->mChangeFlags |= RadioStation::PersistentDataChanged | RadioStation::UrlChanged;
       
   239         mData->setStationHasSentRds( true );
   235         ASSERT_SHARED_NULL_IS_INTACT
   240         ASSERT_SHARED_NULL_IS_INTACT
   236     }
   241     }
   237 }
   242 }
   238 
   243 
   239 /*!
   244 /*!
   247     if ( region != RadioRegion::America ) {
   252     if ( region != RadioRegion::America ) {
   248         piCode &= ~DISABLE_LOCAL_AREA_COVERAGE_MASK;
   253         piCode &= ~DISABLE_LOCAL_AREA_COVERAGE_MASK;
   249     }
   254     }
   250 
   255 
   251     LOG_FORMAT( "stored PI: %d", mData->mPiCode );
   256     LOG_FORMAT( "stored PI: %d", mData->mPiCode );
   252     LOG_FORMAT( "call sign check done: %d", mData->mCallSignCheckDone );
   257     LOG_FORMAT( "call sign check done: %d", mData->isCallSignCheckDone() );
   253     //prevent executing the below code when unnessesary
   258     //prevent executing the below code when unnessesary
   254     if ( mData->mPiCode != piCode || !mData->mCallSignCheckDone ) {
   259     if ( mData->mPiCode != piCode || !mData->isCallSignCheckDone() ) {
   255         mData->mPiCode = piCode;
   260         mData->mPiCode = piCode;
   256         mData->mChangeFlags |= RadioStation::PersistentDataChanged | RadioStation::PiCodeChanged;
   261         mData->mChangeFlags |= RadioStation::PersistentDataChanged | RadioStation::PiCodeChanged;
       
   262         // Note that setStationHasSentRds() is not set when genre or pi code arrives.
       
   263 
   257         // call sign not calculated for clear channel stations
   264         // call sign not calculated for clear channel stations
   258 		//TODO: Remove magic numbers
   265 		//TODO: Remove magic numbers
   259         if ( ( (mData->mPiCode & 0xF000 ) >> 12 ) == 0x1 ) {
   266         if ( ( (mData->mPiCode & 0xF000 ) >> 12 ) == 0x1 ) {
   260             LOG( "Clear channel station" );
   267             LOG( "Clear channel station" );
   261             mData->mCallSignCheckDone = true;
   268             mData->setCallSignCheckDone( true );
   262         } else if ( region == RadioRegion::America && mData->mName.isEmpty() && !isRenamed() ) {
   269         } else if ( region == RadioRegion::America && mData->mName.isEmpty() && !isRenamed() ) {
   263             LOG( "Calculate call sign" );
   270             LOG( "Calculate call sign" );
   264             mData->mName = piCodeToCallSign( mData->mPiCode );
   271             mData->mName = piCodeToCallSign( mData->mPiCode );
   265             mData->mChangeFlags |= RadioStation::NameChanged;
   272             mData->mChangeFlags |= RadioStation::NameChanged;
   266         }
   273         }
   267 
   274 
   268         if ( mData->mChangeFlags.testFlag( RadioStation::PsTypeChanged ) ) {
   275         if ( mData->mChangeFlags.testFlag( RadioStation::PsTypeChanged ) ) {
   269             LOG( "Call sign check done" );
   276             LOG( "Call sign check done" );
   270             mData->mCallSignCheckDone = true;
   277             mData->setCallSignCheckDone( true );
   271         }
   278         }
   272 
   279 
   273         ASSERT_SHARED_NULL_IS_INTACT
   280         ASSERT_SHARED_NULL_IS_INTACT
   274         return true;
   281         return true;
   275     }
   282     }
   294 void RadioStation::setRadioText( const QString& radioText )
   301 void RadioStation::setRadioText( const QString& radioText )
   295 {
   302 {
   296     if ( mData->mRadioText.compare( radioText ) != 0 ) {
   303     if ( mData->mRadioText.compare( radioText ) != 0 ) {
   297         mData->mRadioText = radioText.isEmpty() ? "" : radioText.trimmed();
   304         mData->mRadioText = radioText.isEmpty() ? "" : radioText.trimmed();
   298         mData->mChangeFlags |= RadioStation::RadioTextChanged;
   305         mData->mChangeFlags |= RadioStation::RadioTextChanged;
       
   306         mData->setStationHasSentRds( true );
   299         ASSERT_SHARED_NULL_IS_INTACT
   307         ASSERT_SHARED_NULL_IS_INTACT
   300     }
   308     }
   301 }
   309 }
   302 
   310 
   303 /*!
   311 /*!
   357 {
   365 {
   358     // We don't check for name emptiness because this setter is used also to remove the renaming
   366     // We don't check for name emptiness because this setter is used also to remove the renaming
   359     // of a station by setting an empty name
   367     // of a station by setting an empty name
   360     if ( mData->mName.compare( name ) != 0 ) {
   368     if ( mData->mName.compare( name ) != 0 ) {
   361         mData->mName = name;
   369         mData->mName = name;
   362         mData->mRenamedByUser = !name.isEmpty();
   370         mData->setRenamedByUser( !name.isEmpty() );
   363         mData->mChangeFlags |= RadioStation::PersistentDataChanged | RadioStation::NameChanged;
   371         mData->mChangeFlags |= RadioStation::PersistentDataChanged | RadioStation::NameChanged;
   364     }
   372     }
   365 }
   373 }
   366 
   374 
   367 /*!
   375 /*!
   368  *
   376  *
   369  */
   377  */
   370 bool RadioStation::isRenamed() const
   378 bool RadioStation::isRenamed() const
   371 {
   379 {
   372     return mData->mRenamedByUser;
   380     return mData->isRenamedByUser();
   373 }
   381 }
   374 
   382 
   375 /*!
   383 /*!
   376  *
   384  *
   377  */
   385  */
   538 void RadioStation::resetChangeFlags()
   546 void RadioStation::resetChangeFlags()
   539 {
   547 {
   540     if ( mData->mChangeFlags != RadioStation::NoChange ) {
   548     if ( mData->mChangeFlags != RadioStation::NoChange ) {
   541         mData->mChangeFlags = RadioStation::NoChange;
   549         mData->mChangeFlags = RadioStation::NoChange;
   542     }
   550     }
       
   551 }
       
   552 
       
   553 /*!
       
   554  *
       
   555  */
       
   556 bool RadioStation::hasSentRds() const
       
   557 {
       
   558     return mData->hasStationSentRds();
   543 }
   559 }
   544 
   560 
   545 /*!
   561 /*!
   546  *
   562  *
   547  */
   563  */