radiohswidget/src/radiohswidget.cpp
changeset 57 21be958eb3ce
parent 54 a8ba0c289b44
equal deleted inserted replaced
56:04837bf3a628 57:21be958eb3ce
    33 // User includes
    33 // User includes
    34 #include "radiohswidget.h"
    34 #include "radiohswidget.h"
    35 #include "radiohswidgetprofilereader.h"
    35 #include "radiohswidgetprofilereader.h"
    36 #include "radiohswidgetradioserviceclient.h"
    36 #include "radiohswidgetradioserviceclient.h"
    37 #include "radioservicedef.h"
    37 #include "radioservicedef.h"
    38 #include "radio_global.h"
    38 #include "radiogenrelocalizer.h"
    39 #include "radiologger.h"
    39 #include "radiologger.h"
    40 
    40 
    41 // Constants
    41 // Constants
    42 /** Path to docml file */
    42 /** Path to docml file */
    43 const QString DOCML(":/ui/resource/fmradiohswidget.docml");
    43 const QString DOCML(":/ui/resource/fmradiohswidget.docml");
    49 /**  DOCML object name for tunerBackgroundPushButton */
    49 /**  DOCML object name for tunerBackgroundPushButton */
    50 const QString DOCML_OBJECT_NAME_TUNER_BACKGROUND_BUTTON(
    50 const QString DOCML_OBJECT_NAME_TUNER_BACKGROUND_BUTTON(
    51     "tunerBackgroundPushButton");
    51     "tunerBackgroundPushButton");
    52 /**  DOCML object name for tunerStackedLayout */
    52 /**  DOCML object name for tunerStackedLayout */
    53 const QString DOCML_OBJECT_NAME_TUNER_STACKED_LAYOUT("tunerStackedLayout");
    53 const QString DOCML_OBJECT_NAME_TUNER_STACKED_LAYOUT("tunerStackedLayout");
       
    54 /**  DOCML object name for favoriteIconLayout */
       
    55 const QString DOCML_OBJECT_NAME_FAVORITE_ICON_LAYOUT("favoriteIconLayout");
       
    56 /**  DOCML object name for favoriteIcon */
       
    57 const QString DOCML_OBJECT_NAME_FAVORITE_ICON("favoriteIcon");
    54 /**  DOCML object name for tunerInformationStackedLayout */
    58 /**  DOCML object name for tunerInformationStackedLayout */
    55 const QString DOCML_OBJECT_NAME_TUNER_INFORMATION_STACKED_LAYOUT(
    59 const QString DOCML_OBJECT_NAME_TUNER_INFORMATION_STACKED_LAYOUT(
    56     "tunerInformationStackedLayout");
    60     "tunerInformationStackedLayout");
       
    61 /**  DOCML object name for lonelyRowLabel */
       
    62 const QString DOCML_OBJECT_NAME_LONELY_ROW_LABEL("lonelyRowLabel");
       
    63 /**  DOCML object name for animationIcon */
       
    64 const QString DOCML_OBJECT_NAME_ANIMATION_ICON("animationIcon");
       
    65 /**  DOCML object name for oneRowWithFavoriteLayout */
       
    66 const QString DOCML_OBJECT_NAME_ONE_ROW_WITH_FAVORITE_LAYOUT("oneRowWithFavoriteLayout");
       
    67 /**  DOCML object name for oneRowWithFavoriteLabel */
       
    68 const QString DOCML_OBJECT_NAME_ONE_ROW_WITH_FAVORITE_LABEL("oneRowWithFavoriteLabel");
       
    69 /**  DOCML object name for twoRowsLayout */
       
    70 const QString DOCML_OBJECT_NAME_TWO_ROWS_LAYOUT("twoRowsLayout");
       
    71 /**  DOCML object name for firstRowWithFavoriteLabel */
       
    72 const QString DOCML_OBJECT_NAME_FIRST_ROW_WITH_FAVORITE_LABEL("firstRowWithFavoriteLabel");
       
    73 /**  DOCML object name for secondRowLabel */
       
    74 const QString DOCML_OBJECT_NAME_SECOND_ROW_LABEL("secondRowLabel");
    57 /**  DOCML object name for controlButtons */
    75 /**  DOCML object name for controlButtons */
    58 const QString DOCML_OBJECT_NAME_CONTROL_BUTTONS_LAYOUT("controlButtons");
    76 const QString DOCML_OBJECT_NAME_CONTROL_BUTTONS_LAYOUT("controlButtons");
    59 /**  DOCML object name for powerToggleButton */
    77 /**  DOCML object name for powerToggleButton */
    60 const QString DOCML_OBJECT_NAME_POWER_BUTTON("powerButton");
    78 const QString DOCML_OBJECT_NAME_POWER_BUTTON("powerButton");
    61 /**  DOCML object name for previousPushButton */
    79 /**  DOCML object name for previousPushButton */
    62 const QString DOCML_OBJECT_NAME_PREVIOUS_BUTTON("previousPushButton");
    80 const QString DOCML_OBJECT_NAME_PREVIOUS_BUTTON("previousPushButton");
    63 /**  DOCML object name for nextPushButton */
    81 /**  DOCML object name for nextPushButton */
    64 const QString DOCML_OBJECT_NAME_NEXT_BUTTON("nextPushButton");
    82 const QString DOCML_OBJECT_NAME_NEXT_BUTTON("nextPushButton");
    65 /**  DOCML object name for twoRowsLayout */
       
    66 const QString DOCML_OBJECT_NAME_TWO_ROWS_LAYOUT("twoRowsLayout");
       
    67 /**  DOCML object name for firstRowLabel */
       
    68 const QString DOCML_OBJECT_NAME_FIRST_ROW_LABEL("firstRowLabel");
       
    69 /**  DOCML object name for secondRowLabel */
       
    70 const QString DOCML_OBJECT_NAME_SECOND_ROW_LABEL("secondRowLabel");
       
    71 /**  DOCML object name for lonelyRowLabel */
       
    72 const QString DOCML_OBJECT_NAME_LONELY_ROW_LABEL("lonelyRowLabel");
       
    73 /**  DOCML object name for animationIcon */
       
    74 const QString DOCML_OBJECT_NAME_ANIMATION_ICON("animationIcon");
       
    75 
    83 
    76 /** Unknown favorite station count. */
    84 /** Unknown favorite station count. */
    77 const int FAVORITE_STATION_COUNT_UNDEFINED(0);
    85 const int FAVORITE_STATION_COUNT_UNDEFINED(0);
    78 /** Unknown local station count. */
    86 /** Unknown local station count. */
    79 const int LOCAL_STATION_COUNT_UNDEFINED(0);
    87 const int LOCAL_STATION_COUNT_UNDEFINED(0);
   111 // Tuner background button graphics for different states.
   119 // Tuner background button graphics for different states.
   112 const QString TUNER_BUTTON_NORMAL_OFF("qtg_fr_tuner");
   120 const QString TUNER_BUTTON_NORMAL_OFF("qtg_fr_tuner");
   113 const QString TUNER_BUTTON_NORMAL_ON("qtg_fr_tuner");
   121 const QString TUNER_BUTTON_NORMAL_ON("qtg_fr_tuner");
   114 const QString TUNER_BUTTON_NORMAL_PRESSED("qtg_fr_hsitems2_pressed");
   122 const QString TUNER_BUTTON_NORMAL_PRESSED("qtg_fr_hsitems2_pressed");
   115 
   123 
       
   124 // Favorite icon graphics names for favorite and non-favorite names
       
   125 const QString FAVORITE_ICON_NAME("qtg_small_favorite");
       
   126 const QString NON_FAVORITE_ICON_NAME("qtg_small_star_non_favourited");
       
   127 
   116 /*!
   128 /*!
   117     \class RadioHsWidget
   129     \class RadioHsWidget
   118     \brief Implementation of FM Radio home screen widget.
   130     \brief Implementation of FM Radio home screen widget.
   119 
   131 
   120     RadioHsWidget implements needed functions for the FM Radio home screen
   132     RadioHsWidget implements needed functions for the FM Radio home screen
   136       mPowerButton(NULL),
   148       mPowerButton(NULL),
   137       mPreviousButton(NULL),
   149       mPreviousButton(NULL),
   138       mNextButton(NULL),
   150       mNextButton(NULL),
   139       mInformationAreaTwoRowsLayout(NULL),
   151       mInformationAreaTwoRowsLayout(NULL),
   140       mInformationLonelyRowLabel(NULL),
   152       mInformationLonelyRowLabel(NULL),
   141       mInformationFirstRowLabel(NULL),
   153       mInformationFirstRowWithFavoriteLabel(NULL),
   142       mInformationSecondRowLabel(NULL),
   154       mInformationSecondRowLabel(NULL),
   143       mAnimationIcon(NULL),
   155       mAnimationIcon(NULL),
       
   156       mFavoriteIcon(NULL),
   144       mFmRadioState(FmRadio::StateUndefined),
   157       mFmRadioState(FmRadio::StateUndefined),
       
   158       mRadioRegion(RadioRegion::None),
   145       mFavoriteStationCount(FAVORITE_STATION_COUNT_UNDEFINED),
   159       mFavoriteStationCount(FAVORITE_STATION_COUNT_UNDEFINED),
   146       mLocalStationCount(LOCAL_STATION_COUNT_UNDEFINED),
   160       mLocalStationCount(LOCAL_STATION_COUNT_UNDEFINED),
   147       mCurrentStationIsFavorite(false),
   161       mCurrentStationIsFavorite(false),
   148       mProfileMonitor(NULL),
   162       mProfileMonitor(NULL),
   149       mRadioServiceClient(NULL)
   163       mRadioServiceClient(NULL)
   167  */
   181  */
   168 void RadioHsWidget::handleRadioInformationChange(const int informationType,
   182 void RadioHsWidget::handleRadioInformationChange(const int informationType,
   169     const QVariant &information)
   183     const QVariant &information)
   170 {
   184 {
   171     LOG_METHOD;
   185     LOG_METHOD;
       
   186     
       
   187     if ((informationType == RadioServiceNotification::RadioText
       
   188         || informationType == RadioServiceNotification::DynamicPS) 
       
   189         && !mRadioInformation.contains(Frequency))
       
   190     {
       
   191         // there's not yet station set in widget, the information is most likely from the previous station 
       
   192         LOG("RadioHsWidget::handleRadioInformationChange: transitioning between stations, discarding update");
       
   193         return;
       
   194     }
       
   195     
   172     switch (informationType) {
   196     switch (informationType) {
   173 
   197 
   174     case RadioServiceNotification::FavoriteCount:
   198     case RadioServiceNotification::FavoriteCount:
   175         LOG("FavoriteCount");
   199         LOG("FavoriteCount");
   176         if (information.canConvert(QVariant::Int) &&
   200         if (information.canConvert(QVariant::Int) &&
   200     case RadioServiceNotification::CurrentIsFavorite:
   224     case RadioServiceNotification::CurrentIsFavorite:
   201         LOG("CurrentIsFavorite");
   225         LOG("CurrentIsFavorite");
   202         if (information.canConvert(QVariant::Bool)) {
   226         if (information.canConvert(QVariant::Bool)) {
   203             mCurrentStationIsFavorite = information.toBool();
   227             mCurrentStationIsFavorite = information.toBool();
   204             LOG_FORMAT("currentIsFavorite: %d", mCurrentStationIsFavorite);
   228             LOG_FORMAT("currentIsFavorite: %d", mCurrentStationIsFavorite);
       
   229             if (mFavoriteIcon->isVisible()) {
       
   230                 changeFavoriteIcon(true);
       
   231             } else {
       
   232                 changeFavoriteIcon(false);
       
   233             }
   205         }
   234         }
   206         break;
   235         break;
   207 
   236 
   208     case RadioServiceNotification::RadioStatus:
   237     case RadioServiceNotification::RadioStatus:
   209         LOG("RadioStatus");
   238         LOG("RadioStatus");
   210         if (information.canConvert(QVariant::Int)) {
   239         if (information.canConvert(QVariant::Int)) {
   211             const int status = information.toInt();
   240             const int status = information.toInt();
   212             switch (status) {
   241             switch (status) {
   213             case RadioStatus::Playing:
   242             case RadioStatus::Playing:
   214                 LOG("Playing");
   243                 LEVEL2(LOG("RadioStatus::Playing"));
   215                 handleRadioStateChange(FmRadio::StateRunning);
   244                 handleRadioStateChange(FmRadio::StateRunning);
   216                 break;
   245                 break;
   217             case RadioStatus::Muted:
   246             case RadioStatus::Muted:
   218                 LOG("Muted");
   247                 LEVEL2(LOG("RadioStatus::Muted"));
   219                 break;
   248                 break;
   220             case RadioStatus::Seeking:
   249             case RadioStatus::Seeking:
   221                 LEVEL2(LOG("Seeking"));
   250                 LEVEL2(LOG("RadioStatus::Seeking"));
   222                 handleRadioStateChange(FmRadio::StateSeeking);
   251                 handleRadioStateChange(FmRadio::StateSeeking);
   223                 break;
   252                 break;
   224             case RadioStatus::NoAntenna:
   253             case RadioStatus::NoAntenna:
   225                 LEVEL2(LOG("NoAntenna"));
   254                 LEVEL2(LOG("RadioStatus::NoAntenna"));
   226                 handleRadioStateChange(FmRadio::StateAntennaNotConnected);
   255                 handleRadioStateChange(FmRadio::StateAntennaNotConnected);
   227                 break;
   256                 break;
   228             case RadioStatus::PoweringOff:
   257             case RadioStatus::PoweringOff:
   229                 LEVEL2(LOG("PoweringOff"));
   258                 LEVEL2(LOG("RadioStatus::PoweringOff"));
   230                 handleRadioStateChange(FmRadio::StateClosing);
   259                 handleRadioStateChange(FmRadio::StateClosing);
   231                 break;
   260                 break;
   232             default:
   261             default:
   233                 LOG("default case at case RadioStatus");
   262                 LOG("default case at case RadioStatus");
   234                 break;
   263                 break;
   238 
   267 
   239     case RadioServiceNotification::Frequency:
   268     case RadioServiceNotification::Frequency:
   240         LOG("Frequency");
   269         LOG("Frequency");
   241         // TODO: Should information.toString() be checked for too many characters? What's the limit?
   270         // TODO: Should information.toString() be checked for too many characters? What's the limit?
   242         if (information.canConvert(QVariant::String)) {
   271         if (information.canConvert(QVariant::String)) {
   243             LOG_FORMAT("frequency: %s", GETSTRING(information.toString()));
   272             LEVEL2(LOG_FORMAT("frequency: %s", GETSTRING(information.toString())));
   244             // TODO: Remove comment when localisation is working on device.
       
   245             //frequencyString = hbTrId("txt_fmradiohswidget_rad_list_l1_mhz").arg(freqString);
       
   246             bool frequencyCleared = false;
   273             bool frequencyCleared = false;
   247 
       
   248             if (mRadioInformation.contains(Frequency)) {
   274             if (mRadioInformation.contains(Frequency)) {
   249                 // Clear all infromation.
   275                 // Clear all infromation.
   250                 clearRadioInformation();
   276                 clearRadioInformation();
   251                 frequencyCleared = true;
   277                 frequencyCleared = true;
   252             }
   278             }
   253             // If widget do not have any frquency information, update it.
   279             // If widget do not have any frquency information, update it.
   254             bool frequencyUpdated = updateRadioInformation(Frequency,
   280             QString frequencyString = hbTrId("txt_fmradiohswidget_rad_list_l1_mhz").arg(information.toString());
   255                 information.toString());
   281             bool frequencyUpdated = updateRadioInformation(Frequency, frequencyString);
   256             if (frequencyCleared || frequencyUpdated) {
   282             if (frequencyCleared || frequencyUpdated) {
   257                 // Information changed, update the UI.
   283                 // Information changed, update the UI.
   258                 changeInRadioInformation();
   284                 changeInRadioInformation();
   259                 mFmRadioState = FmRadio::StateRunning;
   285                 mFmRadioState = FmRadio::StateRunning;
   260             }
   286             }
   266         handleSimilarRadioInformation(StationName, information);
   292         handleSimilarRadioInformation(StationName, information);
   267         break;
   293         break;
   268 
   294 
   269     case RadioServiceNotification::Genre:
   295     case RadioServiceNotification::Genre:
   270         LOG("Genre");
   296         LOG("Genre");
   271         handleSimilarRadioInformation(Pty, information);
   297         if (information.canConvert(QVariant::Int) &&
       
   298             mRadioRegion != RadioRegion::None) {
       
   299             const int genre = information.toInt();
       
   300             QString localizedGenre(RadioGenreLocalizer::genreToString(
       
   301                 mRadioRegion, genre, GenreTarget::HomeScreen));
       
   302             handleSimilarRadioInformation(Pty, localizedGenre);
       
   303         }
   272         break;
   304         break;
   273 
   305 
   274     case RadioServiceNotification::RadioText:
   306     case RadioServiceNotification::RadioText:
   275         LOG("RadioText");
   307         LOG("RadioText");
   276         handleSimilarRadioInformation(RadioText, information);
   308         handleSimilarRadioInformation(RadioText, information);
   279     case RadioServiceNotification::DynamicPS:
   311     case RadioServiceNotification::DynamicPS:
   280         LOG("DynamicPS");
   312         LOG("DynamicPS");
   281         handleSimilarRadioInformation(DynamicPsName, information);
   313         handleSimilarRadioInformation(DynamicPsName, information);
   282         break;
   314         break;
   283 
   315 
       
   316     case RadioServiceNotification::Region:
       
   317         LOG("Region");
       
   318         if (information.canConvert(QVariant::Int)) {
       
   319             const int region = information.toInt();
       
   320             switch (region) {
       
   321             case RadioRegion::None:
       
   322                 LEVEL2(LOG("RadioRegion::None"));
       
   323                 mRadioRegion = RadioRegion::None;
       
   324                 break;
       
   325             case RadioRegion::Default:
       
   326                 LEVEL2(LOG("RadioRegion::Default"));
       
   327                 mRadioRegion = RadioRegion::Default;
       
   328                 break;
       
   329             case RadioRegion::Japan:
       
   330                 LEVEL2(LOG("RadioRegion::Japan"));
       
   331                 mRadioRegion = RadioRegion::Japan;
       
   332                 break;
       
   333             case RadioRegion::America:
       
   334                 LEVEL2(LOG("RadioRegion::America"));
       
   335                 mRadioRegion = RadioRegion::America;
       
   336                 break;
       
   337             case RadioRegion::Poland:
       
   338                 LEVEL2(LOG("RadioRegion::Poland"));
       
   339                 mRadioRegion = RadioRegion::Poland;
       
   340                 break;
       
   341             default:
       
   342                 LOG("default case at case RadioRegion");
       
   343                 break;
       
   344             }
       
   345         }
       
   346         break;
       
   347         
   284     default:
   348     default:
   285         LOG("default case at notificationId");
   349         LOG("default case at notificationId");
   286         break;
   350         break;
   287     }
   351     }
   288 }
   352 }
   321         mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
   385         mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
   322         mLocalStationCount = LOCAL_STATION_COUNT_UNDEFINED;
   386         mLocalStationCount = LOCAL_STATION_COUNT_UNDEFINED;
   323         mCurrentStationIsFavorite = false;
   387         mCurrentStationIsFavorite = false;
   324         enableStationButtons();
   388         enableStationButtons();
   325         clearRadioInformation();
   389         clearRadioInformation();
   326         mInformationFirstRowLabel->setPlainText("");
   390         mInformationFirstRowWithFavoriteLabel->setPlainText("");
   327         mInformationSecondRowLabel->setPlainText("");
   391         mInformationSecondRowLabel->setPlainText("");
   328         mInformationLonelyRowLabel->setPlainText(hbTrId("txt_fmradiohswidget_rad_list_fm_radio"));
   392         mInformationLonelyRowLabel->setPlainText(hbTrId("txt_fmradiohswidget_rad_list_fm_radio"));
   329         changeInformationAreaLayout(OneRow);
   393         changeInformationAreaLayout(OneRow);
   330         break;
   394         break;
   331     case FmRadio::StateStarting:
   395     case FmRadio::StateStarting:
   339         changeInformationAreaLayout(Animation);
   403         changeInformationAreaLayout(Animation);
   340         break;
   404         break;
   341     case FmRadio::StateRunning:
   405     case FmRadio::StateRunning:
   342         LOG("FmRadio::StateRunning");
   406         LOG("FmRadio::StateRunning");
   343         mFmRadioState = FmRadio::StateRunning;
   407         mFmRadioState = FmRadio::StateRunning;
   344         // Stop timer if it is running because radio is now running.
   408         mRadioServiceClient->stopMonitoring();
   345         mRadioServiceClient->startMonitoring(
   409         mRadioServiceClient->startMonitoring(
   346             FmRadio::VisibiltyDoNotChange);
   410             FmRadio::VisibiltyDoNotChange);
   347         changeInRadioInformation();
   411         changeInRadioInformation();
   348         changePowerButtonOn(true);
   412         changePowerButtonOn(true);
   349         enableStationButtons();
   413         enableStationButtons();
   350         changeInformationAreaLayout(OneRow);
   414         changeInformationAreaLayout(OneRowWithFavorite);
   351         break;
   415         break;
   352     case FmRadio::StateSeeking:
   416     case FmRadio::StateSeeking:
   353         LOG("FmRadio::StateSeeking");
   417         LOG("FmRadio::StateSeeking");
   354         mFmRadioState = FmRadio::StateSeeking;
   418         mFmRadioState = FmRadio::StateSeeking;
   355         mCurrentStationIsFavorite = false;
   419         mCurrentStationIsFavorite = false;
   359     case FmRadio::StateAntennaNotConnected:
   423     case FmRadio::StateAntennaNotConnected:
   360         LOG("FmRadio::StateAntennaNotConnected");
   424         LOG("FmRadio::StateAntennaNotConnected");
   361         mFmRadioState = FmRadio::StateAntennaNotConnected;
   425         mFmRadioState = FmRadio::StateAntennaNotConnected;
   362         mCurrentStationIsFavorite = false;
   426         mCurrentStationIsFavorite = false;
   363         enableStationButtons();
   427         enableStationButtons();
   364         mInformationFirstRowLabel->setPlainText("");
   428         mInformationFirstRowWithFavoriteLabel->setPlainText("");
   365         mInformationSecondRowLabel->setPlainText("");
   429         mInformationSecondRowLabel->setPlainText("");
   366         mInformationLonelyRowLabel->setPlainText(hbTrId(
   430         mInformationLonelyRowLabel->setPlainText(hbTrId(
   367             "txt_fmradiohswidget_rad_info_connect_wired_headset"));
   431             "txt_fmradiohswidget_rad_info_connect_wired_headset"));
   368         changeInformationAreaLayout(OneRow);
   432         changeInformationAreaLayout(OneRow);
   369         break;
   433         break;
   374         mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
   438         mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
   375         mLocalStationCount = LOCAL_STATION_COUNT_UNDEFINED;
   439         mLocalStationCount = LOCAL_STATION_COUNT_UNDEFINED;
   376         mCurrentStationIsFavorite = false;
   440         mCurrentStationIsFavorite = false;
   377         enableStationButtons();
   441         enableStationButtons();
   378         clearRadioInformation();
   442         clearRadioInformation();
   379         mInformationFirstRowLabel->setPlainText("");
   443         mInformationFirstRowWithFavoriteLabel->setPlainText("");
   380         mInformationSecondRowLabel->setPlainText("");
   444         mInformationSecondRowLabel->setPlainText("");
   381         mInformationLonelyRowLabel->setPlainText(hbTrId(
   445         mInformationLonelyRowLabel->setPlainText(hbTrId(
   382             "txt_fmradiohswidget_rad_list_fm_radio"));
   446             "txt_fmradiohswidget_rad_list_fm_radio"));
   383         changeInformationAreaLayout(OneRow);
   447         changeInformationAreaLayout(OneRow);
   384         break;
   448         break;
   630                 HbWidget *tunerInformationStackedLayout = qobject_cast<
   694                 HbWidget *tunerInformationStackedLayout = qobject_cast<
   631                     HbWidget*> (documentLoader->findWidget(
   695                     HbWidget*> (documentLoader->findWidget(
   632                     DOCML_OBJECT_NAME_TUNER_INFORMATION_STACKED_LAYOUT));
   696                     DOCML_OBJECT_NAME_TUNER_INFORMATION_STACKED_LAYOUT));
   633                 if (tunerInformationStackedLayout) {
   697                 if (tunerInformationStackedLayout) {
   634                 }
   698                 }
       
   699                 
       
   700                 // Find favorite icon.
       
   701                 mFavoriteIcon = qobject_cast<HbLabel *> (
       
   702                     documentLoader->findWidget(
       
   703                         DOCML_OBJECT_NAME_FAVORITE_ICON));
       
   704                 if (mFavoriteIcon) {
       
   705                     mFavoriteIcon->setIcon(HbIcon(NON_FAVORITE_ICON_NAME));
       
   706                     mFavoriteIcon->setVisible(false);
       
   707                 }
   635 
   708 
   636                 // Find lonely label
   709                 // Find lonely label
   637                 mInformationLonelyRowLabel = qobject_cast<HbLabel *> (
   710                 mInformationLonelyRowLabel = qobject_cast<HbLabel *> (
   638                     documentLoader->findWidget(
   711                     documentLoader->findWidget(
   639                         DOCML_OBJECT_NAME_LONELY_ROW_LABEL));
   712                         DOCML_OBJECT_NAME_LONELY_ROW_LABEL));
   641                     // TODO: Set the color in docml when application designer supports it.
   714                     // TODO: Set the color in docml when application designer supports it.
   642                     QColor color = HbColorScheme::color(
   715                     QColor color = HbColorScheme::color(
   643                         "qtc_radio_tuner_normal");
   716                         "qtc_radio_tuner_normal");
   644                     mInformationLonelyRowLabel->setTextColor(color);
   717                     mInformationLonelyRowLabel->setTextColor(color);
   645                 }
   718                 }
   646 
   719                 
   647                 // Find layout for two rows
       
   648                 mInformationAreaTwoRowsLayout = qobject_cast<
       
   649                     QGraphicsWidget *> (documentLoader->findObject(
       
   650                     DOCML_OBJECT_NAME_TWO_ROWS_LAYOUT));
       
   651                 if (mInformationAreaTwoRowsLayout) {
       
   652                     // Find first row
       
   653                     mInformationFirstRowLabel = qobject_cast<HbLabel *> (
       
   654                         documentLoader->findWidget(
       
   655                             DOCML_OBJECT_NAME_FIRST_ROW_LABEL));
       
   656                     if (mInformationFirstRowLabel) {
       
   657                         // TODO: Set the color in docml when application designer supports it.
       
   658                         QColor color = HbColorScheme::color(
       
   659                             "qtc_radio_tuner_normal");
       
   660                         mInformationFirstRowLabel->setTextColor(color);
       
   661                     }
       
   662 
       
   663                     // Find second row
       
   664                     mInformationSecondRowLabel = qobject_cast<HbLabel *> (
       
   665                         documentLoader->findWidget(
       
   666                             DOCML_OBJECT_NAME_SECOND_ROW_LABEL));
       
   667                     if (mInformationSecondRowLabel) {
       
   668                         // TODO: Set the color in docml when application designer supports it.
       
   669                         QColor color = HbColorScheme::color(
       
   670                             "qtc_radio_tuner_normal");
       
   671                         mInformationSecondRowLabel->setTextColor(color);
       
   672                     }
       
   673                 }
       
   674 
       
   675                 mAnimationIcon = qobject_cast<HbLabel *> (
   720                 mAnimationIcon = qobject_cast<HbLabel *> (
   676                     documentLoader->findWidget(
   721                     documentLoader->findWidget(
   677                         DOCML_OBJECT_NAME_ANIMATION_ICON));
   722                         DOCML_OBJECT_NAME_ANIMATION_ICON));
   678                 if (mAnimationIcon) {
   723                 if (mAnimationIcon) {
   679                     // Use animation manager to access anim loading animation.
   724                     // Use animation manager to access anim loading animation.
   682                     // TODO: Axml extension can be removed after wk24 release.
   727                     // TODO: Axml extension can be removed after wk24 release.
   683                     animationManager->addDefinitionFile(QLatin1String(
   728                     animationManager->addDefinitionFile(QLatin1String(
   684                         "qtg_anim_loading.axml"));
   729                         "qtg_anim_loading.axml"));
   685                     mAnimationIcon->setIcon(HbIcon("qtg_anim_loading"));
   730                     mAnimationIcon->setIcon(HbIcon("qtg_anim_loading"));
   686                 }
   731                 }
   687             }
   732 
   688 
   733                 // Find layout for one row with favorite icon
   689             // Find push button for tuner area.
   734                 mInformationAreaOneRowWithFavoriteLayout = qobject_cast<
   690             mInformationAreaBackgroundButton = qobject_cast<HbPushButton*> (
   735                         QGraphicsWidget *> (documentLoader->findObject(
   691                 documentLoader->findWidget(
   736                         DOCML_OBJECT_NAME_ONE_ROW_WITH_FAVORITE_LAYOUT));
   692                     DOCML_OBJECT_NAME_TUNER_BACKGROUND_BUTTON));
   737                 if (mInformationAreaOneRowWithFavoriteLayout) {
   693             if (mInformationAreaBackgroundButton) {
   738                     // Find one row
   694                 // Use the frame background.
   739                     mInformationOneRowWithFavoriteLabel = qobject_cast<
   695                 HbFrameDrawer *tunerBackgroundButtonFrameDrawer =
   740                         HbLabel *> (documentLoader->findWidget(
   696                     new HbFrameDrawer("qtg_fr_tuner",
   741                         DOCML_OBJECT_NAME_ONE_ROW_WITH_FAVORITE_LABEL));
   697                         HbFrameDrawer::ThreePiecesHorizontal);
   742                     if (mInformationOneRowWithFavoriteLabel) {
   698                 tunerBackgroundButtonFrameDrawer->setFillWholeRect(true);
   743                         // TODO: Set the color in docml when application designer supports it.
   699                 mInformationAreaBackgroundButton->setFrameBackground(
   744                         QColor color = HbColorScheme::color(
   700                     tunerBackgroundButtonFrameDrawer);
   745                             "qtc_radio_tuner_normal");
   701                 // Connect the button's clicked signal. 
   746                         mInformationOneRowWithFavoriteLabel->setTextColor(color);
   702                 Radio::connect(mInformationAreaBackgroundButton,
   747                     }
   703                     SIGNAL(clicked()), this, SLOT(changeRadioToForeground()));
   748                 }
       
   749 
       
   750                 // Find layout for two rows
       
   751                 mInformationAreaTwoRowsLayout = qobject_cast<
       
   752                     QGraphicsWidget *> (documentLoader->findObject(
       
   753                     DOCML_OBJECT_NAME_TWO_ROWS_LAYOUT));
       
   754                 if (mInformationAreaTwoRowsLayout) {
       
   755                     // Find first row
       
   756                     mInformationFirstRowWithFavoriteLabel = qobject_cast<HbLabel *> (
       
   757                         documentLoader->findWidget(
       
   758                             DOCML_OBJECT_NAME_FIRST_ROW_WITH_FAVORITE_LABEL));
       
   759                     if (mInformationFirstRowWithFavoriteLabel) {
       
   760                         // TODO: Set the color in docml when application designer supports it.
       
   761                         QColor color = HbColorScheme::color(
       
   762                             "qtc_radio_tuner_normal");
       
   763                         mInformationFirstRowWithFavoriteLabel->setTextColor(color);
       
   764                     }
       
   765 
       
   766                     // Find second row
       
   767                     mInformationSecondRowLabel = qobject_cast<HbLabel *> (
       
   768                         documentLoader->findWidget(
       
   769                             DOCML_OBJECT_NAME_SECOND_ROW_LABEL));
       
   770                     if (mInformationSecondRowLabel) {
       
   771                         // TODO: Set the color in docml when application designer supports it.
       
   772                         QColor color = HbColorScheme::color(
       
   773                             "qtc_radio_tuner_normal");
       
   774                         mInformationSecondRowLabel->setTextColor(color);
       
   775                     }
       
   776                 }
       
   777 
       
   778                 // Find push button for tuner area.
       
   779                 mInformationAreaBackgroundButton = qobject_cast<HbPushButton*> (
       
   780                     documentLoader->findWidget(
       
   781                         DOCML_OBJECT_NAME_TUNER_BACKGROUND_BUTTON));
       
   782                 if (mInformationAreaBackgroundButton) {
       
   783                     // Use the frame background.
       
   784                     HbFrameDrawer *tunerBackgroundButtonFrameDrawer =
       
   785                         new HbFrameDrawer("qtg_fr_tuner",
       
   786                             HbFrameDrawer::ThreePiecesHorizontal);
       
   787                     tunerBackgroundButtonFrameDrawer->setFillWholeRect(true);
       
   788                     mInformationAreaBackgroundButton->setFrameBackground(
       
   789                         tunerBackgroundButtonFrameDrawer);
       
   790                     // Connect the button's clicked signal. 
       
   791                     Radio::connect(mInformationAreaBackgroundButton,
       
   792                         SIGNAL(clicked()), this, SLOT(changeRadioToForeground()));
       
   793                 }
       
   794                 
   704             }
   795             }
   705 
   796 
   706             // Find layout for control buttons.
   797             // Find layout for control buttons.
   707             HbWidget *controlButtonsLayout = qobject_cast<HbWidget*> (
   798             HbWidget *controlButtonsLayout = qobject_cast<HbWidget*> (
   708                 documentLoader->findWidget(
   799                 documentLoader->findWidget(
   858     }
   949     }
   859     LEVEL2(LOG_FORMAT("mRadioInformationSecondRow: %s", GETSTRING(mRadioInformationSecondRow)));
   950     LEVEL2(LOG_FORMAT("mRadioInformationSecondRow: %s", GETSTRING(mRadioInformationSecondRow)));
   860     
   951     
   861     // If second row is empty.
   952     // If second row is empty.
   862     if (mRadioInformationSecondRow.isEmpty()) {
   953     if (mRadioInformationSecondRow.isEmpty()) {
   863         // Show only the lonely row.
   954         if (mCurrentStationIsFavorite) {
   864         mInformationLonelyRowLabel->setPlainText(mRadioInformationFirstRow);
   955             // Show favorite icon and one row.
   865         changeInformationAreaLayout(OneRow);
   956             mInformationOneRowWithFavoriteLabel->setPlainText(mRadioInformationFirstRow);
   866     }
   957             qreal width = mInformationOneRowWithFavoriteLabel->rect().width();
   867     else {
   958             QFont font = mInformationOneRowWithFavoriteLabel->font();
       
   959             QFontMetrics fm(font);
       
   960             int textWidth = fm.width(mRadioInformationFirstRow);
       
   961             if (width < textWidth) {
       
   962                 int a = 4;
       
   963             }
       
   964             changeInformationAreaLayout(OneRowWithFavorite);
       
   965         } else {
       
   966             // Show only the lonely row.
       
   967             mInformationLonelyRowLabel->setPlainText(mRadioInformationFirstRow);
       
   968             changeInformationAreaLayout(OneRowWithFavorite);
       
   969         }
       
   970     } else {
   868         // Else display both rows.
   971         // Else display both rows.
   869         mInformationFirstRowLabel->setPlainText(mRadioInformationFirstRow);
   972         mInformationFirstRowWithFavoriteLabel->setPlainText(mRadioInformationFirstRow);
   870         mInformationSecondRowLabel->setPlainText(mRadioInformationSecondRow);
   973         mInformationSecondRowLabel->setPlainText(mRadioInformationSecondRow);
   871         changeInformationAreaLayout(TwoRows);
   974         changeInformationAreaLayout(TwoRowsWithFavorite);
   872     }
   975     }
   873 }
   976 }
   874 
   977 
   875 /*!
   978 /*!
   876     Clears the radio station information. For example, when the station is
   979     Clears the radio station information. For example, when the station is
   888     \param layout The layout to switch visible.
   991     \param layout The layout to switch visible.
   889  */
   992  */
   890 void RadioHsWidget::changeInformationAreaLayout(const InformationAreaLayout layout)
   993 void RadioHsWidget::changeInformationAreaLayout(const InformationAreaLayout layout)
   891 {
   994 {
   892     LOG_METHOD_ENTER;
   995     LOG_METHOD_ENTER;
       
   996     if (layout == OneRowWithFavorite || layout == TwoRowsWithFavorite) {
       
   997         changeFavoriteIcon(true);
       
   998     } else {
       
   999         changeFavoriteIcon(false);
       
  1000     }
   893     mInformationLonelyRowLabel->setVisible(layout == OneRow);
  1001     mInformationLonelyRowLabel->setVisible(layout == OneRow);
   894     mInformationAreaTwoRowsLayout->setVisible(layout == TwoRows);
  1002     mInformationAreaOneRowWithFavoriteLayout->setVisible(layout == OneRowWithFavorite);
       
  1003     mInformationAreaTwoRowsLayout->setVisible(layout == TwoRowsWithFavorite);
   895     mAnimationIcon->setVisible(layout == Animation);
  1004     mAnimationIcon->setVisible(layout == Animation);
       
  1005 }
       
  1006 
       
  1007 /*!
       
  1008     Changes visibility of favorite icon. Changes also the icon between
       
  1009     favorite and unfavorite.
       
  1010 
       
  1011     \param visibility \c true favorite icon is visible and \c false the icon
       
  1012     is invisible.
       
  1013  */
       
  1014 void RadioHsWidget::changeFavoriteIcon(bool visibility)
       
  1015 {
       
  1016     LEVEL2(LOG_METHOD);
       
  1017     if (mCurrentStationIsFavorite) {
       
  1018         mFavoriteIcon->setIcon(HbIcon(FAVORITE_ICON_NAME));
       
  1019     } else {
       
  1020         mFavoriteIcon->setIcon(HbIcon(NON_FAVORITE_ICON_NAME));
       
  1021     }
       
  1022     mFavoriteIcon->setVisible(visibility);
   896 }
  1023 }
   897 
  1024 
   898 /*!
  1025 /*!
   899     Changes state of power button.
  1026     Changes state of power button.
   900     
  1027     
   903 void RadioHsWidget::changePowerButtonOn(const bool isPowerOn)
  1030 void RadioHsWidget::changePowerButtonOn(const bool isPowerOn)
   904 {
  1031 {
   905     LEVEL2(LOG_METHOD);
  1032     LEVEL2(LOG_METHOD);
   906     if (isPowerOn) {
  1033     if (isPowerOn) {
   907         LEVEL2(LOG("Power on"));
  1034         LEVEL2(LOG("Power on"));
       
  1035         // TODO: Temporarily set the text to clarify the action it performs.
       
  1036         // Remove when graphics displays the difference.
       
  1037         mPowerButton->setText("Off");
   908         buttonEvent(Power, Latched);
  1038         buttonEvent(Power, Latched);
   909     } else {
  1039     } else {
   910         LEVEL2(LOG("Power off"));
  1040         LEVEL2(LOG("Power off"));
       
  1041         // TODO: Temporarily set the text to clarify the action it performs.
       
  1042         // Remove when graphics displays the difference.
       
  1043         mPowerButton->setText("On");
   911         buttonEvent(Power, Normal);
  1044         buttonEvent(Power, Normal);
   912     }
  1045     }
   913 }
  1046 }
   914 
  1047 
   915 /*!
  1048 /*!