radiohswidget/src/radiohswidget.cpp
changeset 32 189d20c34778
child 33 11b6825f0862
equal deleted inserted replaced
28:075425b8d9a4 32:189d20c34778
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  FM Radio home screen widget
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <HbPushButton>
       
    20 #include <HbLabel>
       
    21 #include <HbDocumentLoader>
       
    22 #include <HbFrameDrawer>
       
    23 #include <HbFrameItem>
       
    24 #include <HbIcon>
       
    25 #include <HbIconAnimationManager>
       
    26 #include <HbIconAnimationDefinition>
       
    27 #include <HbColorScheme>
       
    28 #include <HbDeviceMessageBox>
       
    29 #include <QGraphicsLinearLayout>
       
    30 #include <QGraphicsItem>
       
    31 #include <QDesktopServices>
       
    32 #include <QSignalMapper>
       
    33 
       
    34 // User includes
       
    35 #include "radiohswidget.h"
       
    36 #include "radiohswidgetprofilereader.h"
       
    37 #include "radiohswidgetradioserviceclient.h"
       
    38 #include "radioservicedef.h"
       
    39 #include "radio_global.h"
       
    40 #include "radiologger.h"
       
    41 
       
    42 // Constants
       
    43 /** Path to docml file */
       
    44 const QString DOCML(":/ui/resource/fmradiohswidget.docml");
       
    45 /** Path to css file */
       
    46 const QString CSS(":/ui/resource/fmradiohswidget.css");
       
    47 
       
    48 /**  DOCML object name for mainLayout */
       
    49 const QString DOCML_OBJECT_NAME_MAIN_LAYOUT("mainLayout");
       
    50 /**  DOCML object name for contentLayout */
       
    51 const QString DOCML_OBJECT_NAME_CONTENT_LAYOUT("contentLayout");
       
    52 /**  DOCML object name for tunerBackgroundPushButton */
       
    53 const QString DOCML_OBJECT_NAME_TUNER_BACKGROUND_BUTTON(
       
    54     "tunerBackgroundPushButton");
       
    55 /**  DOCML object name for tunerStackedLayout */
       
    56 const QString DOCML_OBJECT_NAME_TUNER_STACKED_LAYOUT("tunerStackedLayout");
       
    57 /**  DOCML object name for tunerInformationStackedLayout */
       
    58 const QString DOCML_OBJECT_NAME_TUNER_INFORMATION_STACKED_LAYOUT(
       
    59     "tunerInformationStackedLayout");
       
    60 /**  DOCML object name for controlButtons */
       
    61 const QString DOCML_OBJECT_NAME_CONTROL_BUTTONS_LAYOUT("controlButtons");
       
    62 /**  DOCML object name for powerToggleButton */
       
    63 const QString DOCML_OBJECT_NAME_POWER_BUTTON("powerButton");
       
    64 /**  DOCML object name for previousPushButton */
       
    65 const QString DOCML_OBJECT_NAME_PREVIOUS_BUTTON("previousPushButton");
       
    66 /**  DOCML object name for nextPushButton */
       
    67 const QString DOCML_OBJECT_NAME_NEXT_BUTTON("nextPushButton");
       
    68 /**  DOCML object name for twoRowsLayout */
       
    69 const QString DOCML_OBJECT_NAME_TWO_ROWS_LAYOUT("twoRowsLayout");
       
    70 /**  DOCML object name for firstRowLabel */
       
    71 const QString DOCML_OBJECT_NAME_FIRST_ROW_LABEL("firstRowLabel");
       
    72 /**  DOCML object name for secondRowLabel */
       
    73 const QString DOCML_OBJECT_NAME_SECOND_ROW_LABEL("secondRowLabel");
       
    74 /**  DOCML object name for lonelyRowLabel */
       
    75 const QString DOCML_OBJECT_NAME_LONELY_ROW_LABEL("lonelyRowLabel");
       
    76 /**  DOCML object name for animationIcon */
       
    77 const QString DOCML_OBJECT_NAME_ANIMATION_ICON("animationIcon");
       
    78 
       
    79 /** Unknown favorite station count. */
       
    80 const int FAVORITE_STATION_COUNT_UNDEFINED(-1);
       
    81 /** One favorite station set. */
       
    82 const int FAVORITE_STATION_COUNT_ONE(1);
       
    83 
       
    84 // Graphics identifiers for different push button states
       
    85 const QString CONTROL_BUTTON_GRAPHICS_NORMAL  ("qtg_fr_hsbutton_normal");
       
    86 const QString CONTROL_BUTTON_GRAPHICS_PRESSED ("qtg_fr_hsbutton_pressed");
       
    87 const QString CONTROL_BUTTON_GRAPHICS_DISABLED("qtg_fr_hsbutton_disabled");
       
    88 const QString CONTROL_BUTTON_GRAPHICS_LATCHED ("qtg_fr_hsbutton_latched");
       
    89 
       
    90 // Push button icon colors for each of the states (normal, pressed, disabled
       
    91 // and latched)
       
    92 const QString CONTROL_BUTTON_ICON_COLOR_NORMAL  ("qtc_button_normal");
       
    93 const QString CONTROL_BUTTON_ICON_COLOR_PRESSED ("qtc_button_pressed");
       
    94 const QString CONTROL_BUTTON_ICON_COLOR_DISABLED("qtc_button_disabled");
       
    95 const QString CONTROL_BUTTON_ICON_COLOR_LATCHED ("qtc_button_latched");
       
    96 
       
    97 // File name suffix lists for push buttons
       
    98 const QStringList POWER_BUTTON_SUFFIX(
       
    99     (QStringList() << "_l" << "_c" << "_cr"));
       
   100 const QStringList PREVIOUS_BUTTON_SUFFIX(
       
   101     (QStringList() << "_cl" << "_c" << "_cr"));
       
   102 const QStringList NEXT_BUTTON_SUFFIX(
       
   103     (QStringList() << "_cl" << "_c" << "_r"));
       
   104 
       
   105 /** Icon for power button off. */
       
   106 const QString POWER_BUTTON_ICON_OFF("qtg_mono_power"); 
       
   107 /** Icon for power button on. */
       
   108 const QString POWER_BUTTON_ICON_ON ("qtg_mono_power"); 
       
   109 
       
   110 // Tuner background button graphics for different states.
       
   111 const QString TUNER_BUTTON_NORMAL_OFF("qtg_fr_tuner");
       
   112 const QString TUNER_BUTTON_NORMAL_ON("qtg_fr_tuner");
       
   113 const QString TUNER_BUTTON_NORMAL_PRESSED("qtg_fr_hsitems2_pressed");
       
   114 
       
   115 /*!
       
   116     \class RadioHsWidget
       
   117     \brief Implementation of FM Radio home screen widget.
       
   118 
       
   119     RadioHsWidget implements needed functions for the FM Radio home screen
       
   120     widget.
       
   121 */
       
   122 
       
   123 // ======== MEMBER FUNCTIONS ========
       
   124 
       
   125 /*!
       
   126     Constructs a widget which is a child of \a parent, with widget flags set
       
   127     to \a flags.
       
   128     
       
   129     Constructor should be empty and all the actual construction should be
       
   130     done in onInitialize().
       
   131  */
       
   132 RadioHsWidget::RadioHsWidget(QGraphicsItem* parent, Qt::WindowFlags flags)
       
   133     : HbWidget(parent, flags),
       
   134       mInformationAreaBackgroundButton(NULL),
       
   135       mPowerButton(NULL),
       
   136       mPreviousButton(NULL),
       
   137       mNextButton(NULL),
       
   138       mInformationAreaTwoRowsLayout(NULL),
       
   139       mInformationLonelyRowLabel(NULL),
       
   140       mInformationFirstRowLabel(NULL),
       
   141       mInformationSecondRowLabel(NULL),
       
   142       mAnimationIcon(NULL),
       
   143       mFmRadioState(FmRadio::StateUndefined),
       
   144       mFavoriteStationCount(FAVORITE_STATION_COUNT_UNDEFINED),
       
   145       mCurrentStationIsFavorite(false),
       
   146       mProfileMonitor(NULL),
       
   147       mRadioServiceClient(NULL)
       
   148 {
       
   149     LOG_METHOD;
       
   150 }
       
   151 
       
   152 /*!
       
   153     Destructor
       
   154  */
       
   155 RadioHsWidget::~RadioHsWidget()
       
   156 {
       
   157     LOG_METHOD;
       
   158 }
       
   159 
       
   160 /*!
       
   161     Handles changes in FM Radio information.
       
   162 
       
   163     \param informationType Type of changed information.
       
   164     \param information Actual information.
       
   165  */
       
   166 void RadioHsWidget::handleRadioInformationChange(const int informationType,
       
   167     const QVariant &information)
       
   168 {
       
   169     LOG_METHOD;
       
   170     LEVEL2(LOG_SLOT_CALLER);
       
   171     if (!information.isValid()) {
       
   172         // informationValue is not valid so return.
       
   173         return;
       
   174     }
       
   175     switch (informationType) {
       
   176 
       
   177     case RadioServiceNotification::FavoriteCount:
       
   178         LEVEL2(LOG("FavoriteCount"));
       
   179         if (information.canConvert(QVariant::Int)) {
       
   180             mFavoriteStationCount = information.toInt();
       
   181             // If there are favorite stations, enable the next/previous
       
   182             // buttons.
       
   183             LEVEL2(LOG_FORMAT("favoriteCount: %d, mFavoriteStations: %d",
       
   184                     mFavoriteStationCount, mFavoriteStations));
       
   185             // Enable or disable buttons only if favoriteCount differs
       
   186             // from 1. CurrentIsFavorite case handles situation when there
       
   187             // is only one favorite station.
       
   188             if (mFavoriteStationCount != FAVORITE_STATION_COUNT_ONE) {
       
   189                 enableStationButtons();
       
   190             }
       
   191         }
       
   192         break;
       
   193 
       
   194     case RadioServiceNotification::CurrentIsFavorite:
       
   195         LEVEL2(LOG("CurrentIsFavorite"));
       
   196         if (information.canConvert(QVariant::Bool)) {
       
   197             mCurrentStationIsFavorite = information.toBool();
       
   198             LEVEL2(LOG_FORMAT("currentIsFavorite: %d", mCurrentStationIsFavorite));
       
   199             // If current station is favorite disable next/prev buttons.
       
   200             // Radio sends this information only when there is only one
       
   201             // favorite station set.
       
   202             enableStationButtons();
       
   203         }
       
   204         break;
       
   205 
       
   206     case RadioServiceNotification::RadioStatus:
       
   207         LEVEL2(LOG("RadioStatus"));
       
   208         if (information.canConvert(QVariant::Int)) {
       
   209             const int status = information.toInt();
       
   210             switch (status) {
       
   211             case RadioStatus::Playing:
       
   212                 LOG("Playing");
       
   213                 //handleRadioStateChange(FmRadio::StateControllingAudio);
       
   214                 //handleRadioStateChange(FmRadio::StateRunning);
       
   215                 break;
       
   216             case RadioStatus::Muted:
       
   217                 LOG("Muted");
       
   218                 //handleRadioStateChange(FmRadio::StateNotControllingAudio);
       
   219                 break;
       
   220             case RadioStatus::Seeking:
       
   221                 LEVEL2(LOG("Seeking"));
       
   222                 handleRadioStateChange(FmRadio::StateSeeking);
       
   223                 break;
       
   224             case RadioStatus::NoAntenna:
       
   225                 LEVEL2(LOG("NoAntenna"));
       
   226                 handleRadioStateChange(FmRadio::StateAntennaNotConnected);
       
   227                 break;
       
   228             case RadioStatus::PoweringOff:
       
   229                 LEVEL2(LOG("PoweringOff"));
       
   230                 handleRadioStateChange(FmRadio::StateClosing);
       
   231                 break;
       
   232             default:
       
   233                 LOG("default case at case RadioStatus");
       
   234                 break;
       
   235             }
       
   236         }
       
   237         break;
       
   238 
       
   239     case RadioServiceNotification::Frequency:
       
   240         LEVEL2(LOG("Frequency"));
       
   241         if (information.canConvert(QVariant::String)) {
       
   242             LEVEL2(LOG_FORMAT("frequency: %s", GETSTRING(information.toString())));
       
   243             // TODO: Remove comment when localisation is working on device.
       
   244             //frequencyString = hbTrId("txt_fmradiohswidget_rad_list_l1_mhz").arg(freqString);
       
   245             bool frequencyCleared = false;
       
   246             // If widget has some frequency information and new frequency
       
   247             // differs from that
       
   248             if (mRadioInformation.contains(Frequency)
       
   249                 && mRadioInformation[Frequency].compare(information.toString()) != 0) {
       
   250                 // Clear all infromation from widget because station has changed.
       
   251                 clearRadioInformation();
       
   252                 frequencyCleared = true;
       
   253             }
       
   254             // If widget do not have any frquency information, update it.
       
   255             bool frequencyUpdated = updateRadioInformation(Frequency,
       
   256                 information.toString());
       
   257             if (frequencyCleared || frequencyUpdated) {
       
   258                 // Information changed, update the UI.
       
   259                 changeInRadioInformation();
       
   260             }
       
   261         }
       
   262         break;
       
   263 
       
   264     case RadioServiceNotification::Name:
       
   265         LEVEL2(LOG("Name"));
       
   266         handleSimilarRadioInformation(StationName, information);
       
   267         break;
       
   268 
       
   269     case RadioServiceNotification::Genre:
       
   270         LEVEL2(LOG("Genre"));
       
   271         handleSimilarRadioInformation(Pty, information);
       
   272         break;
       
   273 
       
   274     case RadioServiceNotification::RadioText:
       
   275         LEVEL2(LOG("RadioText"));
       
   276         handleSimilarRadioInformation(RadioText, information);
       
   277         break;
       
   278 
       
   279     case RadioServiceNotification::DynamicPS:
       
   280         LOG("DynamicPS");
       
   281         handleSimilarRadioInformation(DynamicPsName, information);
       
   282         break;
       
   283 
       
   284     default:
       
   285         LOG("default case at notificationId");
       
   286         break;
       
   287     }
       
   288 }
       
   289 
       
   290 /*!
       
   291     Handles changes in FM Radio state.
       
   292 
       
   293     \param value New state of the radio application.
       
   294 */
       
   295 void RadioHsWidget::handleRadioStateChange(const QVariant &value)
       
   296 {
       
   297     LOG_METHOD;
       
   298     int state;
       
   299     if (value.canConvert(QVariant::Int)) {
       
   300         state = value.toInt();
       
   301     } else {
       
   302         return;
       
   303     }
       
   304 
       
   305     if (state == mFmRadioState) {
       
   306         // State did not change, so return.
       
   307         return;
       
   308     }
       
   309 
       
   310     switch (state) {
       
   311     case FmRadio::StateUndefined:
       
   312         LEVEL2(LOG("FmRadio::StateUndefined"));
       
   313         // Something went wrong. Widget should not be in this state after onInitialize().
       
   314         mFmRadioState = FmRadio::StateUndefined;
       
   315         break;
       
   316     case FmRadio::StateNotRunning:
       
   317         LEVEL2(LOG("FmRadio::StateNotRunning"));
       
   318         mFmRadioState = FmRadio::StateNotRunning;
       
   319         mRadioServiceClient->stopMonitoring();
       
   320         changePowerButtonOn(false);
       
   321         mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
       
   322         mCurrentStationIsFavorite = false;
       
   323         enableStationButtons();
       
   324         clearRadioInformation();
       
   325         mInformationFirstRowLabel->setPlainText("");
       
   326         mInformationSecondRowLabel->setPlainText("");
       
   327         mInformationLonelyRowLabel->setPlainText(hbTrId("txt_fmradiohswidget_rad_list_fm_radio"));
       
   328         changeInformationAreaLayout(OneRow);
       
   329         break;
       
   330     case FmRadio::StateStarting:
       
   331         LEVEL2(LOG("FmRadio::StateStarting"));
       
   332         mFmRadioState = FmRadio::StateStarting;
       
   333         changePowerButtonOn(true);
       
   334         mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
       
   335         mCurrentStationIsFavorite = false;
       
   336         enableStationButtons();
       
   337         changeInformationAreaLayout(Animation);
       
   338         break;
       
   339     case FmRadio::StateRunning:
       
   340         LEVEL2(LOG("FmRadio::StateRunning"));
       
   341         mFmRadioState = FmRadio::StateRunning;
       
   342         // Stop timer if it is running because radio is now running.
       
   343         mRadioServiceClient->startMonitoring(
       
   344             FmRadio::VisibiltyDoNotChange);
       
   345         changePowerButtonOn(true);
       
   346         enableStationButtons();
       
   347         changeInformationAreaLayout(OneRow);
       
   348         break;
       
   349 /*        
       
   350     case FmRadio::StateControllingAudio:
       
   351         LEVEL2(LOG("FmRadio::StateControllingAudio"));
       
   352         mFmRadioState = FmRadio::StateControllingAudio;
       
   353         enableStationButtons();
       
   354         changeInRadioInformation();
       
   355         break;
       
   356     case FmRadio::StateNotControllingAudio:
       
   357         LEVEL2(LOG("FmRadio::StateNotControllingAudio"));
       
   358         mFmRadioState = FmRadio::StateNotControllingAudio;
       
   359         enableStationButtons();
       
   360         changeInRadioInformation();
       
   361         break;
       
   362 */
       
   363     case FmRadio::StateSeeking:
       
   364         LEVEL2(LOG("FmRadio::StateSeeking"));
       
   365         mFmRadioState = FmRadio::StateSeeking;
       
   366         mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
       
   367         mCurrentStationIsFavorite = false;
       
   368         enableStationButtons();
       
   369         changeInformationAreaLayout(Animation);
       
   370         break;
       
   371     case FmRadio::StateAntennaNotConnected:
       
   372         LEVEL2(LOG("FmRadio::StateAntennaNotConnected"));
       
   373         mFmRadioState = FmRadio::StateAntennaNotConnected;
       
   374         mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
       
   375         mCurrentStationIsFavorite = false;
       
   376         enableStationButtons();
       
   377         mInformationFirstRowLabel->setPlainText("");
       
   378         mInformationSecondRowLabel->setPlainText("");
       
   379         mInformationLonelyRowLabel->setPlainText(hbTrId(
       
   380             "txt_fmradiohswidget_rad_info_connect_wired_headset"));
       
   381         changeInformationAreaLayout(OneRow);
       
   382         break;
       
   383     case FmRadio::StateClosing:
       
   384         LEVEL2(LOG("FmRadio::StateClosing"));
       
   385         mFmRadioState = FmRadio::StateClosing;
       
   386         changePowerButtonOn(false);
       
   387         mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
       
   388         mCurrentStationIsFavorite = false;
       
   389         enableStationButtons();
       
   390         clearRadioInformation();
       
   391         mInformationFirstRowLabel->setPlainText("");
       
   392         mInformationSecondRowLabel->setPlainText("");
       
   393         mInformationLonelyRowLabel->setPlainText(hbTrId(
       
   394             "txt_fmradiohswidget_rad_list_fm_radio"));
       
   395         changeInformationAreaLayout(OneRow);
       
   396         break;
       
   397     default:
       
   398         LOG("default case at state");
       
   399         break;
       
   400     }
       
   401 }
       
   402 
       
   403 /*!
       
   404     Called when widget is initialized. Constructs objects and connects them.
       
   405 */
       
   406 void RadioHsWidget::onInitialize()
       
   407 {
       
   408     LOG_METHOD_ENTER;
       
   409     mProfileMonitor = new RadioHsWidgetProfileReader(this);
       
   410     mRadioServiceClient = new RadioHsWidgetRadioServiceClient(this);
       
   411     
       
   412     load(DOCML);
       
   413     
       
   414     // Use signal mapper to indicate button identifiers to button event
       
   415     // slots. 
       
   416     QSignalMapper* signalMapperPressed = new QSignalMapper(this); 
       
   417     signalMapperPressed->setMapping(mPowerButton, Power);
       
   418     signalMapperPressed->setMapping(mPreviousButton, Previous);
       
   419     signalMapperPressed->setMapping(mNextButton, Next);
       
   420 
       
   421     // Need to use different signal mapper for pressed and released events, 
       
   422     // both have same mappings but they are mapped to different slots.
       
   423     QSignalMapper* signalMapperReleased = new QSignalMapper(this);
       
   424     signalMapperReleased->setMapping(mPowerButton, Power);
       
   425     signalMapperReleased->setMapping(mPreviousButton, Previous);
       
   426     signalMapperReleased->setMapping(mNextButton, Next);
       
   427 
       
   428     // Connect button events to signal maps.
       
   429     Radio::connect(mPowerButton, SIGNAL(pressed()), signalMapperPressed, SLOT (map()));
       
   430     Radio::connect(mPowerButton, SIGNAL(released()), signalMapperReleased, SLOT (map()));
       
   431     Radio::connect(mPreviousButton, SIGNAL(pressed()), signalMapperPressed, SLOT (map()));
       
   432     Radio::connect(mPreviousButton, SIGNAL(released()), signalMapperReleased, SLOT (map()));
       
   433     Radio::connect(mNextButton, SIGNAL(pressed()), signalMapperPressed, SLOT (map()));
       
   434     Radio::connect(mNextButton, SIGNAL(released()), signalMapperReleased, SLOT (map()));
       
   435     
       
   436     // Connect mapper signals to self implemented slots.
       
   437     Radio::connect(signalMapperPressed, SIGNAL(mapped(int)), this, SLOT(changeButtonToPressed(int)));
       
   438     Radio::connect(signalMapperReleased, SIGNAL(mapped(int)), this, SLOT(changeButtonToReleased(int)));
       
   439     
       
   440     mProfileMonitor->startMonitoringRadioRunningStatus();
       
   441 }
       
   442 
       
   443 /*!
       
   444     Called when widget is shown in the home screen
       
   445 */
       
   446 void RadioHsWidget::onShow()
       
   447 {
       
   448     LOG_METHOD_ENTER;
       
   449 }
       
   450 
       
   451 /*!
       
   452     Called when widget is hidden from the home screen
       
   453 */
       
   454 void RadioHsWidget::onHide()
       
   455 {
       
   456     LOG_METHOD_ENTER;
       
   457 }
       
   458 
       
   459 /*!
       
   460     Emited from HbPushButton:pressed() signal, changes the button layout to
       
   461     pressed state.
       
   462  
       
   463     \param hsButtonIdentifier Identifies the button which was pressed.
       
   464  */
       
   465 void RadioHsWidget::changeButtonToPressed(int hsButtonIdentifier)
       
   466 {
       
   467     LOG_METHOD;
       
   468     buttonEvent(static_cast<ControlButtonIdentifier>(hsButtonIdentifier), Pressed);
       
   469 }
       
   470 
       
   471 /*!
       
   472     Emited from HbPushButton:released() signal, changes the button layout to
       
   473     normal state.
       
   474  
       
   475     \param hsButtonIdentifier Identifies the button which was released.
       
   476  */
       
   477 void RadioHsWidget::changeButtonToReleased(int hsButtonIdentifier)
       
   478 {
       
   479     LOG_METHOD;
       
   480     buttonEvent(static_cast<ControlButtonIdentifier>(hsButtonIdentifier), Normal);
       
   481 }
       
   482 
       
   483 /*!
       
   484     Slot for closing FM Radio application from power button.
       
   485  */
       
   486 void RadioHsWidget::closeRadio()
       
   487 {
       
   488     LOG_SLOT_CALLER;
       
   489     mRadioServiceClient->commandFmRadio(RadioServiceCommand::PowerOff);
       
   490 }
       
   491 
       
   492 /*!
       
   493     Slot for previous button clicked.
       
   494  */
       
   495 void RadioHsWidget::changeToPreviousStation()
       
   496 {
       
   497     LOG_SLOT_CALLER;
       
   498     clearRadioInformation();
       
   499     mRadioServiceClient->commandFmRadio(RadioServiceCommand::Previous);
       
   500 }
       
   501 
       
   502 /*!
       
   503     Slot for next button clicked.
       
   504  */
       
   505 void RadioHsWidget::changeToNextStation()
       
   506 {
       
   507     LOG_SLOT_CALLER;
       
   508     clearRadioInformation();
       
   509     mRadioServiceClient->commandFmRadio(RadioServiceCommand::Next);
       
   510 
       
   511 }
       
   512 
       
   513 /*!
       
   514     Slot for bringing the radio application to foreground.
       
   515  */
       
   516 void RadioHsWidget::changeRadioToForeground()
       
   517 {
       
   518     LOG_SLOT_CALLER;
       
   519     // If radio is not running start it to foreground by monitor request.
       
   520     if (mFmRadioState == FmRadio::StateNotRunning) {
       
   521         bool okToStartRadio = radioStartPermission();
       
   522         if (okToStartRadio) {
       
   523             handleRadioStateChange(FmRadio::StateStarting);
       
   524             mRadioServiceClient->startMonitoring(
       
   525                 FmRadio::VisibiltyToForeground);
       
   526         }
       
   527     }
       
   528     else {
       
   529         if (mFmRadioState == FmRadio::StateClosing) {
       
   530             // Radio is closing but user wants to power it up again.
       
   531             mRadioServiceClient->commandFmRadio(RadioServiceCommand::PowerOn);
       
   532             // Stop and start monitoring to get refresh.
       
   533             mRadioServiceClient->stopMonitoring();
       
   534             mRadioServiceClient->startMonitoring(
       
   535                 FmRadio::VisibiltyToBackground);
       
   536             handleRadioStateChange(FmRadio::StateRunning);
       
   537         }
       
   538         // If radio is running, bring it to the foreground.
       
   539         mRadioServiceClient->commandFmRadio(RadioServiceCommand::Foreground);
       
   540     }
       
   541 }
       
   542 
       
   543 /*!
       
   544     Slot for putting the radio application to the background.
       
   545  */
       
   546 void RadioHsWidget::changeRadioToBackground()
       
   547 {
       
   548     LOG_SLOT_CALLER;
       
   549     // If radio is not running start it to background by monitor request.
       
   550     if (mFmRadioState == FmRadio::StateNotRunning) {
       
   551         bool okToStartRadio = radioStartPermission();
       
   552         if (okToStartRadio) {
       
   553             handleRadioStateChange(FmRadio::StateStarting);
       
   554             mRadioServiceClient->startMonitoring(
       
   555                 FmRadio::VisibiltyToBackground);
       
   556         }
       
   557     }
       
   558     else if (mFmRadioState == FmRadio::StateStarting) {
       
   559         // Do nothing if radio is starting.
       
   560     }
       
   561     else if (mFmRadioState == FmRadio::StateClosing) {
       
   562         // Radio is closing but user wants to power it up again.
       
   563         mRadioServiceClient->commandFmRadio(RadioServiceCommand::PowerOn);
       
   564         // Stop and start monitoring to get refresh.
       
   565         mRadioServiceClient->stopMonitoring();
       
   566         mRadioServiceClient->startMonitoring(
       
   567             FmRadio::VisibiltyToBackground);
       
   568         handleRadioStateChange(FmRadio::StateRunning);
       
   569     }
       
   570     else {
       
   571         // If radio is running, put it to the background.
       
   572         // This is little bit useless because the radio is in background if
       
   573         // user is able to click the widget.
       
   574         mRadioServiceClient->commandFmRadio(RadioServiceCommand::Background);
       
   575     }
       
   576 }
       
   577 
       
   578 /*!
       
   579     Powering off or on the radio.
       
   580     
       
   581     \param isToggled Whether the button is togled (\c true) or not (\c false).
       
   582  */
       
   583 void RadioHsWidget::toggleRadioPower()
       
   584 {
       
   585     LOG_SLOT_CALLER;
       
   586     // If radio is not running start it to background by monitor request.
       
   587     if (mFmRadioState == FmRadio::StateNotRunning || mFmRadioState == FmRadio::StateClosing) {
       
   588         LEVEL2(LOG("Power on"));
       
   589         // Start radio
       
   590         changeRadioToBackground();
       
   591     } else {
       
   592         LEVEL2(LOG("Power off"));
       
   593         // Close radio
       
   594         closeRadio();
       
   595     }
       
   596 }
       
   597 
       
   598 /*!
       
   599     Loads docml file.
       
   600  
       
   601     \param docml Docml filename to be loaded.
       
   602  */
       
   603 void RadioHsWidget::load(const QString &docml)
       
   604 {
       
   605     LOG_METHOD_ENTER;
       
   606 
       
   607     QScopedPointer<HbDocumentLoader> documentLoader(new HbDocumentLoader());
       
   608     bool loaded = false;
       
   609     documentLoader->load(docml, &loaded);
       
   610     RADIO_ASSERT( loaded , "FMRadioHsWidget", "invalid DocML file" );
       
   611     if (loaded) {
       
   612         // Find mainLayout
       
   613         HbWidget *mainLayout = qobject_cast<HbWidget*> (
       
   614             documentLoader->findWidget(DOCML_OBJECT_NAME_MAIN_LAYOUT));
       
   615 
       
   616         if (mainLayout) {
       
   617             QGraphicsLinearLayout *widgetLayout = new QGraphicsLinearLayout(
       
   618                 Qt::Vertical, this);
       
   619             widgetLayout->addItem(mainLayout);
       
   620             setLayout(widgetLayout);
       
   621         }
       
   622 
       
   623         // Find contentLayout
       
   624         HbWidget *contentLayout = qobject_cast<HbWidget*> (
       
   625             documentLoader->findWidget(DOCML_OBJECT_NAME_CONTENT_LAYOUT));
       
   626         if (contentLayout) {
       
   627 
       
   628             // Find stacked layout for tuner area.
       
   629             HbWidget *tunerStackedLayout = qobject_cast<HbWidget*> (
       
   630                 documentLoader->findWidget(
       
   631                     DOCML_OBJECT_NAME_TUNER_STACKED_LAYOUT));
       
   632             if (tunerStackedLayout) {
       
   633 
       
   634                 // Find stacked layout for information area.
       
   635                 HbWidget *tunerInformationStackedLayout = qobject_cast<
       
   636                     HbWidget*> (documentLoader->findWidget(
       
   637                     DOCML_OBJECT_NAME_TUNER_INFORMATION_STACKED_LAYOUT));
       
   638                 if (tunerInformationStackedLayout) {
       
   639                 }
       
   640 
       
   641                 // Find lonely label
       
   642                 mInformationLonelyRowLabel = qobject_cast<HbLabel *> (
       
   643                     documentLoader->findWidget(
       
   644                         DOCML_OBJECT_NAME_LONELY_ROW_LABEL));
       
   645                 if (mInformationLonelyRowLabel) {
       
   646                     // TODO: Set the color in docml when application designer supports it.
       
   647                     QColor color = HbColorScheme::color(
       
   648                         "qtc_radio_tuner_normal");
       
   649                     mInformationLonelyRowLabel->setTextColor(color);
       
   650                 }
       
   651 
       
   652                 // Find layout for two rows
       
   653                 mInformationAreaTwoRowsLayout = qobject_cast<
       
   654                     QGraphicsWidget *> (documentLoader->findObject(
       
   655                     DOCML_OBJECT_NAME_TWO_ROWS_LAYOUT));
       
   656                 if (mInformationAreaTwoRowsLayout) {
       
   657                     // Find first row
       
   658                     mInformationFirstRowLabel = qobject_cast<HbLabel *> (
       
   659                         documentLoader->findWidget(
       
   660                             DOCML_OBJECT_NAME_FIRST_ROW_LABEL));
       
   661                     if (mInformationFirstRowLabel) {
       
   662                         // TODO: Set the color in docml when application designer supports it.
       
   663                         QColor color = HbColorScheme::color(
       
   664                             "qtc_radio_tuner_normal");
       
   665                         mInformationFirstRowLabel->setTextColor(color);
       
   666                     }
       
   667 
       
   668                     // Find second row
       
   669                     mInformationSecondRowLabel = qobject_cast<HbLabel *> (
       
   670                         documentLoader->findWidget(
       
   671                             DOCML_OBJECT_NAME_SECOND_ROW_LABEL));
       
   672                     if (mInformationSecondRowLabel) {
       
   673                         // TODO: Set the color in docml when application designer supports it.
       
   674                         QColor color = HbColorScheme::color(
       
   675                             "qtc_radio_tuner_normal");
       
   676                         mInformationSecondRowLabel->setTextColor(color);
       
   677                     }
       
   678                 }
       
   679 
       
   680                 mAnimationIcon = qobject_cast<HbLabel *> (
       
   681                     documentLoader->findWidget(
       
   682                         DOCML_OBJECT_NAME_ANIMATION_ICON));
       
   683                 if (mAnimationIcon) {
       
   684                     // Use animation manager to access anim loading animation.
       
   685                     HbIconAnimationManager *animationManager =
       
   686                         HbIconAnimationManager::global();
       
   687                     // TODO: Axml extension can be removed after wk24 release.
       
   688                     animationManager->addDefinitionFile(QLatin1String(
       
   689                         "qtg_anim_loading.axml"));
       
   690                     mAnimationIcon->setIcon(HbIcon("qtg_anim_loading"));
       
   691                 }
       
   692             }
       
   693 
       
   694             // Find push button for tuner area.
       
   695             mInformationAreaBackgroundButton = qobject_cast<HbPushButton*> (
       
   696                 documentLoader->findWidget(
       
   697                     DOCML_OBJECT_NAME_TUNER_BACKGROUND_BUTTON));
       
   698             if (mInformationAreaBackgroundButton) {
       
   699                 // Try css for controlling the appearance.
       
   700                 //bool b = QFile::exists(CSS);
       
   701                 //bool cssLoaded = HbStyleLoader::registerFilePath(CSS);
       
   702                 //HbStyle::setItemName(mInformationAreaBackgroundButton, DOCML_OBJECT_NAME_TUNER_BACKGROUND_BUTTON);
       
   703                 // Use the frame background.
       
   704                 HbFrameDrawer *tunerBackgroundButtonFrameDrawer =
       
   705                     new HbFrameDrawer("qtg_fr_tuner",
       
   706                         HbFrameDrawer::ThreePiecesHorizontal);
       
   707                 tunerBackgroundButtonFrameDrawer->setFillWholeRect(true);
       
   708                 mInformationAreaBackgroundButton->setFrameBackground(
       
   709                     tunerBackgroundButtonFrameDrawer);
       
   710                 // Connect the button's clicked signal. 
       
   711                 Radio::connect(mInformationAreaBackgroundButton,
       
   712                     SIGNAL(clicked()), this, SLOT(changeRadioToForeground()));
       
   713             }
       
   714 
       
   715             // Find layout for control buttons.
       
   716             HbWidget *controlButtonsLayout = qobject_cast<HbWidget*> (
       
   717                 documentLoader->findWidget(
       
   718                     DOCML_OBJECT_NAME_CONTROL_BUTTONS_LAYOUT));
       
   719             if (controlButtonsLayout) {
       
   720 
       
   721                 // Find power button.
       
   722                 mPowerButton
       
   723                     = qobject_cast<HbPushButton *> (
       
   724                         documentLoader->findWidget(
       
   725                             DOCML_OBJECT_NAME_POWER_BUTTON));
       
   726                 if (mPowerButton) {
       
   727                     defineButton(*mPowerButton,
       
   728                         CONTROL_BUTTON_GRAPHICS_NORMAL, POWER_BUTTON_SUFFIX,
       
   729                         POWER_BUTTON_ICON_ON,
       
   730                         CONTROL_BUTTON_ICON_COLOR_NORMAL);
       
   731                     // Connect the button's clicked signal.
       
   732                     Radio::connect(mPowerButton, SIGNAL(clicked()), this,
       
   733                         SLOT(toggleRadioPower()));
       
   734                 }
       
   735 
       
   736                 // Find previous button.
       
   737                 mPreviousButton = qobject_cast<HbPushButton *> (
       
   738                     documentLoader->findWidget(
       
   739                         DOCML_OBJECT_NAME_PREVIOUS_BUTTON));
       
   740                 if (mPreviousButton) {
       
   741                     defineButton(*mPreviousButton,
       
   742                         CONTROL_BUTTON_GRAPHICS_DISABLED,
       
   743                         PREVIOUS_BUTTON_SUFFIX, NULL,
       
   744                         CONTROL_BUTTON_ICON_COLOR_DISABLED);
       
   745                     // Connect the button's clicked signal.
       
   746                     Radio::connect(mPreviousButton, SIGNAL(clicked()), this,
       
   747                         SLOT(changeToPreviousStation()));
       
   748                 }
       
   749 
       
   750                 // Find next button.
       
   751                 mNextButton
       
   752                     = qobject_cast<HbPushButton *> (
       
   753                         documentLoader->findWidget(
       
   754                             DOCML_OBJECT_NAME_NEXT_BUTTON));
       
   755                 if (mNextButton) {
       
   756                     defineButton(*mNextButton,
       
   757                         CONTROL_BUTTON_GRAPHICS_DISABLED, NEXT_BUTTON_SUFFIX,
       
   758                         NULL, CONTROL_BUTTON_ICON_COLOR_DISABLED);
       
   759                     // Connect the button's clicked signal.
       
   760                     Radio::connect(mNextButton, SIGNAL(clicked()), this,
       
   761                         SLOT(changeToNextStation()));
       
   762                 }
       
   763             }
       
   764         }
       
   765     }
       
   766     else {
       
   767         // Docml was not succesfully loaded. UI cannot be displayed.
       
   768         // Emit error to home screen framework, which removes the widget. 
       
   769         emit error();
       
   770     }
       
   771 }
       
   772 
       
   773 /*!
       
   774     Groups handling of similar kind of radio information (textual) to one
       
   775     function.
       
   776 
       
   777     \param informationType Type of changed information.
       
   778     \param information Actual textual information.
       
   779  */
       
   780 void RadioHsWidget::handleSimilarRadioInformation(
       
   781     const FmRadioInformationType informationType, const QVariant &information)
       
   782 {
       
   783     LOG_METHOD;
       
   784     if (information.canConvert(QVariant::String) && updateRadioInformation(
       
   785         informationType, information.toString())) {
       
   786         LEVEL2(LOG_FORMAT("informationType: %d, information: %s", informationType, GETSTRING(information)));
       
   787         changeInRadioInformation();
       
   788     }
       
   789 }
       
   790 
       
   791 /*!
       
   792     Check if the the radio information is changed. If it is changed, it is
       
   793     also updated.
       
   794 
       
   795     \param informationType Type of the information.
       
   796     \param information  Information text.
       
   797 
       
   798     \returns Returns \c true, if information is updated. Returns \c false otherwise.
       
   799  */
       
   800 bool RadioHsWidget::updateRadioInformation(const FmRadioInformationType informationType,
       
   801     const QString &information)
       
   802 {
       
   803     LOG_METHOD_RET("%d");
       
   804     // If hash contains this type of information.
       
   805     if (mRadioInformation.contains(informationType)) {
       
   806         // If new information is empty.
       
   807         if (information.isEmpty()) {
       
   808             // Remove old information from the hash.
       
   809             LEVEL2(LOG_FORMAT("informationType: %s removed", GETSTRING(informationType)));
       
   810             mRadioInformation.remove(informationType);
       
   811             // Return true to indicate the change.
       
   812             return true;
       
   813         }
       
   814         // If new information differs from the old one.
       
   815         if (mRadioInformation[informationType].compare(information) != 0) {
       
   816             // Update the information.
       
   817             LEVEL2(LOG_FORMAT("informationType: %s = %s", GETSTRING(informationType), GETSTRING(information)));
       
   818             mRadioInformation[informationType] = information;
       
   819             // And return true to indicate the change.
       
   820             return true;
       
   821         }
       
   822     } else { // Hash do not contain this type of information.
       
   823         // If new information is not empty.
       
   824         if (!information.isEmpty()) {
       
   825             // Add it to the hash.
       
   826             LEVEL2(LOG_FORMAT("informationType: %s = %s", GETSTRING(informationType), GETSTRING(information)));
       
   827             mRadioInformation[informationType] = information;
       
   828             // Return true to indicate the change.
       
   829             return true;
       
   830         }
       
   831     }
       
   832     // Return false to indicate that nothing changed.
       
   833     return false;
       
   834 }
       
   835 
       
   836 /*!
       
   837     Formatting radio information texts after a change.
       
   838  */
       
   839 void RadioHsWidget::changeInRadioInformation()
       
   840 {
       
   841     LOG_METHOD_ENTER;
       
   842     // Clear the rows.
       
   843     mRadioInformationFirstRow.clear();
       
   844     mRadioInformationSecondRow.clear();
       
   845 
       
   846     // First row contains station name.
       
   847     if (mRadioInformation.contains(StationName)) {
       
   848         mRadioInformationFirstRow.append(mRadioInformation.value(StationName));
       
   849     }
       
   850     else if (mRadioInformation.contains(Frequency)) {
       
   851         // Or frequency.
       
   852         mRadioInformationFirstRow.append(mRadioInformation.value(Frequency));
       
   853     } LEVEL2(LOG_FORMAT("mRadioInformationFirstRow: %s", GETSTRING(mRadioInformationFirstRow)));
       
   854 
       
   855     // Second row of information contains radio text.
       
   856     if (mRadioInformation.contains(RadioText)) {
       
   857         mRadioInformationSecondRow.append(mRadioInformation.value(RadioText));
       
   858     }
       
   859     else if (mRadioInformation.contains(DynamicPsName)) {
       
   860         // Or Dynamic PS name.
       
   861         mRadioInformationSecondRow.append(mRadioInformation.value(DynamicPsName));
       
   862     }
       
   863     else if (mRadioInformation.contains(Pty)) {
       
   864         // Or PTY.
       
   865         mRadioInformationSecondRow.append(mRadioInformation.value(Pty));
       
   866     }
       
   867     LEVEL2(LOG_FORMAT("mRadioInformationSecondRow: %s", GETSTRING(mRadioInformationSecondRow)));
       
   868     
       
   869     // If second row is empty.
       
   870     if (mRadioInformationSecondRow.isEmpty()) {
       
   871         // Show only the lonely row.
       
   872         mInformationLonelyRowLabel->setPlainText(mRadioInformationFirstRow);
       
   873         changeInformationAreaLayout(OneRow);
       
   874     }
       
   875     else {
       
   876         // Else display both rows.
       
   877         mInformationFirstRowLabel->setPlainText(mRadioInformationFirstRow);
       
   878         mInformationSecondRowLabel->setPlainText(mRadioInformationSecondRow);
       
   879         changeInformationAreaLayout(TwoRows);
       
   880     }
       
   881 }
       
   882 
       
   883 /*!
       
   884     Clears the radio station information. For example, when the station is
       
   885     changed, old information should be cleared.
       
   886  */
       
   887 void RadioHsWidget::clearRadioInformation()
       
   888 {
       
   889     LOG_METHOD_ENTER;
       
   890     mRadioInformation.clear();
       
   891 }
       
   892 
       
   893 /*!
       
   894     Changes visible widgets of information area stacked layout.
       
   895 
       
   896     \param layout The layout to switch visible.
       
   897  */
       
   898 void RadioHsWidget::changeInformationAreaLayout(const InformationAreaLayout layout)
       
   899 {
       
   900     LOG_METHOD;
       
   901     mInformationLonelyRowLabel->setVisible(layout == OneRow);
       
   902     mInformationAreaTwoRowsLayout->setVisible(layout == TwoRows);
       
   903     mAnimationIcon->setVisible(layout == Animation);
       
   904 }
       
   905 
       
   906 /*!
       
   907     Changes state of power button.
       
   908     
       
   909     \param isPowerOn \c true the power is on and \c false the power is off.
       
   910  */
       
   911 void RadioHsWidget::changePowerButtonOn(const bool isPowerOn)
       
   912 {
       
   913     LOG_METHOD;
       
   914     if (isPowerOn) {
       
   915         LEVEL2(LOG("Power on"));
       
   916         // Temporarily set the text to clarify the action it performs.
       
   917         // Remove when graphics displays the difference.
       
   918         mPowerButton->setText("Off");
       
   919         buttonEvent(Power, Latched);
       
   920     } else {
       
   921         LEVEL2(LOG("Power off"));
       
   922         // Temporarily set the text to clarify the action it performs.
       
   923         // Remove when graphics displays the difference.
       
   924         mPowerButton->setText("On");
       
   925         buttonEvent(Power, Normal);
       
   926     }
       
   927 }
       
   928 
       
   929 /*!
       
   930     Changes enabled state of station buttons.
       
   931  */
       
   932 void RadioHsWidget::enableStationButtons()
       
   933 {
       
   934     LOG_METHOD_ENTER;
       
   935     if ((mFavoriteStationCount > 1) || (mFavoriteStationCount == 1
       
   936         && !mCurrentStationIsFavorite)) {
       
   937         changeButtonToEnabled(Next);
       
   938         changeButtonToEnabled(Previous);
       
   939     }
       
   940     else if ((mFavoriteStationCount == 1 && mCurrentStationIsFavorite)
       
   941         || (mFavoriteStationCount < 1)) {
       
   942         changeButtonToDisabled(Next);
       
   943         changeButtonToDisabled(Previous);
       
   944     }
       
   945 }
       
   946 
       
   947 /*!
       
   948     Makes homescreen specific push button based on parameters.
       
   949  
       
   950     \param target Target push button to modify. Must not be NULL.
       
   951     \param graphicsId Defines the target button background graphics.
       
   952     \param suffix Defines the suffix for the target button background graphics.
       
   953     \param icon Defines the icon for the target button. 
       
   954     \param iconColor Defines the icon color for the target button. 
       
   955  */
       
   956 void RadioHsWidget::defineButton(HbPushButton &target, const QString &graphicsId,
       
   957     const QStringList &suffix, const QString &icon, const QString &iconColor)
       
   958 {
       
   959     LOG_METHOD;
       
   960     HbFrameDrawer* drawer = NULL;
       
   961 
       
   962     // First check if the drawer is already created for this push button
       
   963     if (!target.frameBackground()) {
       
   964         LEVEL2(LOG("Creating new frame background."));
       
   965         // Nope, create one now
       
   966         drawer = new HbFrameDrawer(graphicsId,
       
   967             HbFrameDrawer::ThreePiecesHorizontal);
       
   968         target.setFrameBackground(drawer);
       
   969     }
       
   970     else {
       
   971         // Frame drawer already created, only need to update frame graphics
       
   972         drawer = target.frameBackground();
       
   973         drawer->setFrameGraphicsName(graphicsId);
       
   974     }
       
   975 
       
   976     // Set file name suffix list, so that drawer can load correct 3-piece graphic files 
       
   977     drawer->setFileNameSuffixList(suffix);
       
   978     
       
   979     // Set the icon, if it is not NULL
       
   980     if (!icon.isNull()) {
       
   981         target.setIcon(HbIcon(icon));
       
   982     }
       
   983 
       
   984     // Update also the icon color
       
   985     QColor color = HbColorScheme::color(iconColor);
       
   986     target.icon().setColor(color);
       
   987 
       
   988     // Lastly, check if the buttton is disabled
       
   989     if (iconColor == CONTROL_BUTTON_ICON_COLOR_DISABLED) {
       
   990         target.setEnabled(false);
       
   991     }
       
   992     else {
       
   993         target.setEnabled(true);
       
   994     }
       
   995 }
       
   996 
       
   997 /*!
       
   998     Prepares the information needed for displaying the button correctly
       
   999     reflecting its state.
       
  1000  
       
  1001     \param buttonId Identifies the button.
       
  1002     \param state Tells in what state the button is.
       
  1003  */
       
  1004 void RadioHsWidget::buttonEvent(ControlButtonIdentifier buttonId,
       
  1005     const ControlButtonState state)
       
  1006 {
       
  1007     LOG_METHOD;
       
  1008     HbPushButton* target = NULL;
       
  1009     QStringList suffix;
       
  1010     QString icon;
       
  1011 
       
  1012     switch (buttonId) {
       
  1013     case Power:
       
  1014         LEVEL2(LOG("Power"));
       
  1015         target = mPowerButton;
       
  1016         icon = POWER_BUTTON_ICON_ON;
       
  1017         suffix = POWER_BUTTON_SUFFIX;
       
  1018         break;
       
  1019     case Previous:
       
  1020         LEVEL2(LOG("Previous"));
       
  1021         target = mPreviousButton;
       
  1022         suffix = PREVIOUS_BUTTON_SUFFIX;
       
  1023         break;
       
  1024     case Next:
       
  1025         LEVEL2(LOG("Next"));
       
  1026         target = mNextButton;
       
  1027         suffix = NEXT_BUTTON_SUFFIX;
       
  1028         break;
       
  1029     default:
       
  1030         LOG("default case at buttonId");
       
  1031         break;
       
  1032     }
       
  1033     
       
  1034     QString buttonBackgroundGraphics;
       
  1035     QString buttonIconColors;
       
  1036     switch (state) {
       
  1037     case Normal:
       
  1038         LEVEL2(LOG("Normal"));
       
  1039         target->setProperty("state", "normal");
       
  1040         buttonBackgroundGraphics = CONTROL_BUTTON_GRAPHICS_NORMAL;
       
  1041         buttonIconColors = CONTROL_BUTTON_ICON_COLOR_NORMAL;
       
  1042         break;
       
  1043     case Pressed:
       
  1044         LEVEL2(LOG("Pressed"));
       
  1045         target->setProperty("state", "pressed");
       
  1046         buttonBackgroundGraphics = CONTROL_BUTTON_GRAPHICS_PRESSED;
       
  1047         buttonIconColors = CONTROL_BUTTON_ICON_COLOR_PRESSED;
       
  1048         break;
       
  1049     case Disabled:
       
  1050         LEVEL2(LOG("Disabled"));
       
  1051         target->setProperty("state", "disabled");
       
  1052         buttonBackgroundGraphics = CONTROL_BUTTON_GRAPHICS_DISABLED;
       
  1053         buttonIconColors = CONTROL_BUTTON_ICON_COLOR_DISABLED;
       
  1054         break;
       
  1055     case Latched:
       
  1056         LEVEL2(LOG("Latched"));
       
  1057         target->setProperty("state", "latched");
       
  1058         buttonBackgroundGraphics = CONTROL_BUTTON_GRAPHICS_LATCHED;
       
  1059         buttonIconColors = CONTROL_BUTTON_ICON_COLOR_LATCHED;
       
  1060         break;
       
  1061     default:
       
  1062         LOG("default case at button state");
       
  1063         break;
       
  1064     }
       
  1065 
       
  1066     RadioHsWidget::defineButton(*target, buttonBackgroundGraphics,
       
  1067         suffix, icon, buttonIconColors);
       
  1068 }
       
  1069 
       
  1070 /*!
       
  1071     Disables specified push button.
       
  1072  
       
  1073     \param hsButtonIdentifier Which button is to be disabled.
       
  1074  */
       
  1075 void RadioHsWidget::changeButtonToDisabled(int hsButtonIdentifier)
       
  1076 {
       
  1077     LOG_METHOD;
       
  1078     buttonEvent(static_cast<ControlButtonIdentifier>(hsButtonIdentifier), Disabled);
       
  1079 }
       
  1080 
       
  1081 /*!
       
  1082     Enabled specified push button.
       
  1083  
       
  1084     \param hsButtonIdentifier Which button is to be enabled.
       
  1085  */
       
  1086 void RadioHsWidget::changeButtonToEnabled(int hsButtonIdentifier)
       
  1087 {
       
  1088     LOG_METHOD;
       
  1089     changeButtonToReleased(hsButtonIdentifier);
       
  1090     //buttonEvent(static_cast<ControlButtonIdentifier>(hsButtonIdentifier), Normal);
       
  1091 }
       
  1092 
       
  1093 /*!
       
  1094     Checks the profile of the device. If profile is offline, user is asked a
       
  1095     permission to start the radio in offline profile. Dialog is shown on
       
  1096     behalf of the radio asking the permission.    
       
  1097     
       
  1098     \returns \c true if radio can be started, \c false if device is in
       
  1099     offline profile and user didn't gave permission to start the radio.  
       
  1100  */
       
  1101 bool RadioHsWidget::radioStartPermission()
       
  1102 {
       
  1103     LOG_METHOD_ENTER;
       
  1104     // This is true by default because we might not be in offline profile and
       
  1105     // starting the radio is allowed in other profiles without asking a
       
  1106     // permission.
       
  1107     bool radioStartPermssion = true;
       
  1108     if (mProfileMonitor->isCurrentProfileOffline()) {
       
  1109         // Device is in offline profile, ask the user for permission to start
       
  1110         HbDeviceMessageBox box(hbTrId(
       
  1111             "txt_radiohswidget_rad_info_activate_radio_in_offline_mode_hs"),
       
  1112             HbMessageBox::MessageTypeQuestion);
       
  1113         box.setTimeout(HbPopup::NoTimeout);
       
  1114         box.exec();
       
  1115         // radioStartPermssion is now true or false, depending what the user
       
  1116         // selected. If user didn't gave permission, then radio is not
       
  1117         // started.
       
  1118         radioStartPermssion = box.isAcceptAction(box.triggeredAction());
       
  1119     }
       
  1120     return radioStartPermssion;
       
  1121 }