radiohswidget/src/radiohswidget.cpp
changeset 47 74b7c6e79031
parent 44 0a3ad94fc71c
child 54 a8ba0c289b44
equal deleted inserted replaced
44:0a3ad94fc71c 47:74b7c6e79031
    72 const QString DOCML_OBJECT_NAME_LONELY_ROW_LABEL("lonelyRowLabel");
    72 const QString DOCML_OBJECT_NAME_LONELY_ROW_LABEL("lonelyRowLabel");
    73 /**  DOCML object name for animationIcon */
    73 /**  DOCML object name for animationIcon */
    74 const QString DOCML_OBJECT_NAME_ANIMATION_ICON("animationIcon");
    74 const QString DOCML_OBJECT_NAME_ANIMATION_ICON("animationIcon");
    75 
    75 
    76 /** Unknown favorite station count. */
    76 /** Unknown favorite station count. */
    77 const int FAVORITE_STATION_COUNT_UNDEFINED(-1);
    77 const int FAVORITE_STATION_COUNT_UNDEFINED(0);
    78 /** One favorite station set. */
    78 /** Unknown local station count. */
    79 const int FAVORITE_STATION_COUNT_ONE(1);
    79 const int LOCAL_STATION_COUNT_UNDEFINED(0);
    80 /** Favorite station count lower boundary including this number. */
    80 /** Favorite station count lower boundary including this number. */
    81 const int FAVORITE_STATION_COUNT_LOWER_BOUNDARY(0);
    81 const int FAVORITE_STATION_COUNT_LOWER_BOUNDARY(0);
    82 /** Favorite station count upper boundary including this number. */
    82 /** Favorite station count upper boundary including this number. */
    83 const int FAVORITE_STATION_COUNT_UPPER_BOUNDARY(100);
    83 const int FAVORITE_STATION_COUNT_UPPER_BOUNDARY(100);
    84 
    84 
   141       mInformationFirstRowLabel(NULL),
   141       mInformationFirstRowLabel(NULL),
   142       mInformationSecondRowLabel(NULL),
   142       mInformationSecondRowLabel(NULL),
   143       mAnimationIcon(NULL),
   143       mAnimationIcon(NULL),
   144       mFmRadioState(FmRadio::StateUndefined),
   144       mFmRadioState(FmRadio::StateUndefined),
   145       mFavoriteStationCount(FAVORITE_STATION_COUNT_UNDEFINED),
   145       mFavoriteStationCount(FAVORITE_STATION_COUNT_UNDEFINED),
       
   146       mLocalStationCount(LOCAL_STATION_COUNT_UNDEFINED),
   146       mCurrentStationIsFavorite(false),
   147       mCurrentStationIsFavorite(false),
   147       mProfileMonitor(NULL),
   148       mProfileMonitor(NULL),
   148       mRadioServiceClient(NULL)
   149       mRadioServiceClient(NULL)
   149 {
   150 {
   150     LOG_METHOD;
   151     LOG_METHOD;
   174         LOG("FavoriteCount");
   175         LOG("FavoriteCount");
   175         if (information.canConvert(QVariant::Int) &&
   176         if (information.canConvert(QVariant::Int) &&
   176             information.toInt() >= FAVORITE_STATION_COUNT_LOWER_BOUNDARY &&
   177             information.toInt() >= FAVORITE_STATION_COUNT_LOWER_BOUNDARY &&
   177             information.toInt() <= FAVORITE_STATION_COUNT_UPPER_BOUNDARY) {
   178             information.toInt() <= FAVORITE_STATION_COUNT_UPPER_BOUNDARY) {
   178             mFavoriteStationCount = information.toInt();
   179             mFavoriteStationCount = information.toInt();
   179             // If there are favorite stations, enable the next/previous
   180             LOG_FORMAT("mFavoriteStationCount: %d", mFavoriteStationCount);
       
   181             enableStationButtons();
       
   182         }
       
   183         break;
       
   184 
       
   185     case RadioServiceNotification::LocalCount:
       
   186         LOG("LocalCount");
       
   187         if (information.canConvert(QVariant::Int) &&
       
   188             information.toInt() >= FAVORITE_STATION_COUNT_LOWER_BOUNDARY &&
       
   189             information.toInt() <= FAVORITE_STATION_COUNT_UPPER_BOUNDARY) {
       
   190             mLocalStationCount = information.toInt();
       
   191             // If there are local stations, enable the next/previous
   180             // buttons.
   192             // buttons.
   181             LOG_FORMAT("mFavoriteStationCount: %d", mFavoriteStationCount);
   193             LOG_FORMAT("mLocalStationCount: %d", mLocalStationCount);
   182             // Enable or disable buttons only if favoriteCount differs
   194             // Enable or disable buttons only if localCount differs
   183             // from 1. CurrentIsFavorite case handles situation when there
   195             // from 1.
   184             // is only one favorite station.
   196             enableStationButtons();
   185             if (mFavoriteStationCount != FAVORITE_STATION_COUNT_ONE) {
       
   186                 enableStationButtons();
       
   187             }
       
   188         } else {
       
   189             mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
       
   190         }
   197         }
   191         break;
   198         break;
   192 
   199 
   193     case RadioServiceNotification::CurrentIsFavorite:
   200     case RadioServiceNotification::CurrentIsFavorite:
   194         LOG("CurrentIsFavorite");
   201         LOG("CurrentIsFavorite");
   195         if (information.canConvert(QVariant::Bool)) {
   202         if (information.canConvert(QVariant::Bool)) {
   196             mCurrentStationIsFavorite = information.toBool();
   203             mCurrentStationIsFavorite = information.toBool();
   197             LOG_FORMAT("currentIsFavorite: %d", mCurrentStationIsFavorite);
   204             LOG_FORMAT("currentIsFavorite: %d", mCurrentStationIsFavorite);
   198             // If current station is favorite disable next/prev buttons.
       
   199             // Radio sends this information only when there is only one
       
   200             // favorite station set.
       
   201             enableStationButtons();
       
   202         }
   205         }
   203         break;
   206         break;
   204 
   207 
   205     case RadioServiceNotification::RadioStatus:
   208     case RadioServiceNotification::RadioStatus:
   206         LOG("RadioStatus");
   209         LOG("RadioStatus");
   314         LOG("FmRadio::StateNotRunning");
   317         LOG("FmRadio::StateNotRunning");
   315         mFmRadioState = FmRadio::StateNotRunning;
   318         mFmRadioState = FmRadio::StateNotRunning;
   316         mRadioServiceClient->stopMonitoring();
   319         mRadioServiceClient->stopMonitoring();
   317         changePowerButtonOn(false);
   320         changePowerButtonOn(false);
   318         mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
   321         mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
       
   322         mLocalStationCount = LOCAL_STATION_COUNT_UNDEFINED;
   319         mCurrentStationIsFavorite = false;
   323         mCurrentStationIsFavorite = false;
   320         enableStationButtons();
   324         enableStationButtons();
   321         clearRadioInformation();
   325         clearRadioInformation();
   322         mInformationFirstRowLabel->setPlainText("");
   326         mInformationFirstRowLabel->setPlainText("");
   323         mInformationSecondRowLabel->setPlainText("");
   327         mInformationSecondRowLabel->setPlainText("");
   327     case FmRadio::StateStarting:
   331     case FmRadio::StateStarting:
   328         LOG("FmRadio::StateStarting");
   332         LOG("FmRadio::StateStarting");
   329         mFmRadioState = FmRadio::StateStarting;
   333         mFmRadioState = FmRadio::StateStarting;
   330         changePowerButtonOn(true);
   334         changePowerButtonOn(true);
   331         mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
   335         mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
       
   336         mLocalStationCount = LOCAL_STATION_COUNT_UNDEFINED;
   332         mCurrentStationIsFavorite = false;
   337         mCurrentStationIsFavorite = false;
   333         enableStationButtons();
   338         enableStationButtons();
   334         changeInformationAreaLayout(Animation);
   339         changeInformationAreaLayout(Animation);
   335         break;
   340         break;
   336     case FmRadio::StateRunning:
   341     case FmRadio::StateRunning:
   365     case FmRadio::StateClosing:
   370     case FmRadio::StateClosing:
   366         LOG("FmRadio::StateClosing");
   371         LOG("FmRadio::StateClosing");
   367         mFmRadioState = FmRadio::StateClosing;
   372         mFmRadioState = FmRadio::StateClosing;
   368         changePowerButtonOn(false);
   373         changePowerButtonOn(false);
   369         mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
   374         mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
       
   375         mLocalStationCount = LOCAL_STATION_COUNT_UNDEFINED;
   370         mCurrentStationIsFavorite = false;
   376         mCurrentStationIsFavorite = false;
   371         enableStationButtons();
   377         enableStationButtons();
   372         clearRadioInformation();
   378         clearRadioInformation();
   373         mInformationFirstRowLabel->setPlainText("");
   379         mInformationFirstRowLabel->setPlainText("");
   374         mInformationSecondRowLabel->setPlainText("");
   380         mInformationSecondRowLabel->setPlainText("");
   476  */
   482  */
   477 void RadioHsWidget::changeToPreviousStation()
   483 void RadioHsWidget::changeToPreviousStation()
   478 {
   484 {
   479     LOG_SLOT_CALLER;
   485     LOG_SLOT_CALLER;
   480     clearRadioInformation();
   486     clearRadioInformation();
   481     mRadioServiceClient->commandFmRadio(RadioServiceCommand::Previous);
   487     if (mFavoriteStationCount > 1) {
       
   488         mRadioServiceClient->commandFmRadio(RadioServiceCommand::PreviousFavorite);
       
   489     }
       
   490     else {
       
   491         mRadioServiceClient->commandFmRadio(RadioServiceCommand::Previous);
       
   492     }
   482 }
   493 }
   483 
   494 
   484 /*!
   495 /*!
   485     Slot for next button clicked.
   496     Slot for next button clicked.
   486  */
   497  */
   487 void RadioHsWidget::changeToNextStation()
   498 void RadioHsWidget::changeToNextStation()
   488 {
   499 {
   489     LOG_SLOT_CALLER;
   500     LOG_SLOT_CALLER;
   490     clearRadioInformation();
   501     clearRadioInformation();
   491     mRadioServiceClient->commandFmRadio(RadioServiceCommand::Next);
   502     if (mFavoriteStationCount > 1) {
       
   503         mRadioServiceClient->commandFmRadio(RadioServiceCommand::NextFavorite);
       
   504     }
       
   505     else {
       
   506         mRadioServiceClient->commandFmRadio(RadioServiceCommand::Next);
       
   507     }
   492 
   508 
   493 }
   509 }
   494 
   510 
   495 /*!
   511 /*!
   496     Slot for bringing the radio application to foreground.
   512     Slot for bringing the radio application to foreground.
   906     Changes enabled state of station buttons.
   922     Changes enabled state of station buttons.
   907  */
   923  */
   908 void RadioHsWidget::enableStationButtons()
   924 void RadioHsWidget::enableStationButtons()
   909 {
   925 {
   910     LEVEL2(LOG_METHOD_ENTER);
   926     LEVEL2(LOG_METHOD_ENTER);
   911     LOG_FORMAT("RadioHsWidget::enableStationButtons count: %d", mFavoriteStationCount);
   927     LOG_FORMAT("RadioHsWidget::enableStationButtons count: %d", mLocalStationCount);
   912     if (mFmRadioState == FmRadio::StateAntennaNotConnected){
   928     if (mFmRadioState == FmRadio::StateAntennaNotConnected){
   913         changeButtonToDisabled(Next);
   929         changeButtonToDisabled(Next);
   914         changeButtonToDisabled(Previous);
   930         changeButtonToDisabled(Previous);
   915     }
   931     }
   916     else if ((mFavoriteStationCount > 1) || (mFavoriteStationCount == 1
   932     else if (mLocalStationCount + mFavoriteStationCount > 1) {
   917         && !mCurrentStationIsFavorite)) {
       
   918         changeButtonToEnabled(Next);
   933         changeButtonToEnabled(Next);
   919         changeButtonToEnabled(Previous);
   934         changeButtonToEnabled(Previous);
   920     }
   935     }
   921     else if ((mFavoriteStationCount == 1 && mCurrentStationIsFavorite)
   936     else {
   922         || (mFavoriteStationCount < 1)) {
       
   923         changeButtonToDisabled(Next);
   937         changeButtonToDisabled(Next);
   924         changeButtonToDisabled(Previous);
   938         changeButtonToDisabled(Previous);
   925     }
   939     }
   926 }
   940 }
   927 
   941