hswidgetplugin/fmradiohswidgetplugin/src/fmradiohswidget.cpp
changeset 28 075425b8d9a4
parent 24 6df133bd92e1
equal deleted inserted replaced
24:6df133bd92e1 28:075425b8d9a4
    23 #include <HbFrameItem>
    23 #include <HbFrameItem>
    24 #include <HbIcon>
    24 #include <HbIcon>
    25 #include <HbIconAnimationManager>
    25 #include <HbIconAnimationManager>
    26 #include <HbIconAnimationDefinition>
    26 #include <HbIconAnimationDefinition>
    27 #include <HbColorScheme>
    27 #include <HbColorScheme>
    28 #include <HbMarqueeItem>
       
    29 #include <HbStyleLoader>
       
    30 #include <QGraphicsLinearLayout>
    28 #include <QGraphicsLinearLayout>
    31 #include <QGraphicsItem>
    29 #include <QGraphicsItem>
    32 #include <QDesktopServices>
    30 #include <QDesktopServices>
       
    31 #include <QTimer>
    33 
    32 
    34 // User includes
    33 // User includes
    35 #include "fmradiohswidget.h"
    34 #include "fmradiohswidget.h"
    36 #include "fmradiohswidgetprocesshandler.h"
       
    37 #include "fmradiohswidgetprofilereader.h"
    35 #include "fmradiohswidgetprofilereader.h"
    38 #include "fmradiohswidgetradioserviceclient.h"
    36 #include "fmradiohswidgetradioserviceclient.h"
    39 #include "radioservicedef.h"
    37 #include "radioservicedef.h"
    40 #include "radio_global.h"
    38 #include "radio_global.h"
       
    39 #include "radiologger.h"
    41 
    40 
    42 /*!
    41 /*!
    43     \ingroup group_fmradiohs_widget
    42     \ingroup group_fmradiohs_widget
    44     \class FmRadioHsWidget
    43     \class FmRadioHsWidget
    45     \brief Example implementation for home screen widget.
    44     \brief Example implementation for home screen widget.
    46 
    45 
    47     FmRadioHsWidget derived from the HbWidget and implements 
    46     FmRadioHsWidget implements needed functions for the FM Radio home screen
    48     needed functions for the home screen widget. 
    47     widget.
    49 */
    48 */
    50 
    49 
    51 // ======== MEMBER FUNCTIONS ========
    50 // ======== MEMBER FUNCTIONS ========
    52 
    51 
    53 /*!
    52 /*!
    54     Constructs a widget which is a child of \a parent, with widget flags set to \a flags.
    53     Constructs a widget which is a child of \a parent, with widget flags set to \a flags.
       
    54     
       
    55     Constructor should be empty and all the actual construction should be
       
    56     done in onInitialize().
    55 */
    57 */
    56 FmRadioHsWidget::FmRadioHsWidget(QGraphicsItem* parent, Qt::WindowFlags flags)
    58 FmRadioHsWidget::FmRadioHsWidget(QGraphicsItem* parent, Qt::WindowFlags flags)
    57     : HbWidget(parent, flags),
    59     : HbWidget(parent, flags),
    58       mRadioPushButton(0),
    60       mTunerBackgroundPushButton(NULL),
    59       mPreviousPushButton(0),
    61       mPowerToggleButton(NULL),
    60       mPlayPushButton(0),
    62       mPreviousPushButton(NULL),
    61       mNextPushButton(0),
    63       mNextPushButton(NULL),
    62       mInformationFirstRowLabel(0),
    64       mInformationFirstRowLabel(NULL),
    63       mInformationSecondRowLabel(0),
    65       mInformationSecondRowLabel(NULL),
    64       mFmRadioState(Undefined),
    66       mFmRadioState(Undefined),
    65       mPlayButtonState(PlayEnabled),
    67       mFavoriteStations(false),
    66       mIsFavoriteChannels(false),
       
    67       mRadioInformation(QHash<QString, QString>()),
    68       mRadioInformation(QHash<QString, QString>()),
    68       mProcessHandler(0),
    69       mProfileMonitor(NULL),
    69       mProfileMonitor(new FmRadioHsWidgetProfileReader(this)),
    70       mRadioServiceClient(NULL),
    70       mRadioServiceClient(new FmRadioHsWidgetRadioServiceClient(this))
    71       mRadioStartingCancelTimer(NULL)
    71 {
    72 {
       
    73     LOG_METHOD_ENTER;
       
    74 }
       
    75 
       
    76 /*!
       
    77     Destructor
       
    78 */
       
    79 FmRadioHsWidget::~FmRadioHsWidget()
       
    80 {
       
    81     LOG_METHOD;
       
    82 }
       
    83 
       
    84 /*!
       
    85     Getter for /r mRootPath property.
       
    86 */
       
    87 QString FmRadioHsWidget::rootPath()const
       
    88 {
       
    89     LOG_METHOD_ENTER;
       
    90     return mRootPath;
       
    91 }
       
    92 
       
    93 /*!
       
    94     Sets the mRoothPath propertry to /a roothPath.
       
    95 */
       
    96 void FmRadioHsWidget::setRootPath(const QString &rootPath)
       
    97 {
       
    98     LOG_METHOD_ENTER;
       
    99     mRootPath = rootPath;
       
   100 }
       
   101 
       
   102 /*!
       
   103     Called when widget is initialized. Constructs objects and connects them.
       
   104 */
       
   105 void FmRadioHsWidget::onInitialize()
       
   106 {
       
   107     LOG_METHOD_ENTER;
       
   108     mProfileMonitor = new FmRadioHsWidgetProfileReader(this);
       
   109     mRadioServiceClient = new FmRadioHsWidgetRadioServiceClient(this);
       
   110     mRadioStartingCancelTimer = new QTimer(this);
       
   111     
    72     connect(mRadioServiceClient, SIGNAL(radioInformationChanged(int, QVariant)), this,
   112     connect(mRadioServiceClient, SIGNAL(radioInformationChanged(int, QVariant)), this,
    73         SLOT(handleRadioInformationChange(int, QVariant)));
   113         SLOT(handleRadioInformationChange(int, QVariant)));
    74     connect(mRadioServiceClient, SIGNAL(radioStateChanged(QVariant)), this,
   114     connect(mRadioServiceClient, SIGNAL(radioStateChanged(QVariant)), this,
    75         SLOT(handleRadioStateChange(QVariant)));
   115         SLOT(handleRadioStateChange(QVariant)));
    76     connect(mProfileMonitor, SIGNAL(radioRunning(QVariant)), this,
   116     connect(mProfileMonitor, SIGNAL(radioRunning(QVariant)), this,
    77         SLOT(handleRadioStateChange(QVariant)));
   117         SLOT(handleRadioStateChange(QVariant)));
    78     
   118 
    79     load(KDocml);
   119     load(KDocml);
    80     
   120     
    81     handleRadioStateChange(mProfileMonitor->radioStatus());
   121     mProfileMonitor->startMonitoringRadioRunningStatus();
    82 
       
    83     //mRadioServiceClient->init();
       
    84 }
       
    85 
       
    86 /*!
       
    87     Destructor
       
    88 */
       
    89 FmRadioHsWidget::~FmRadioHsWidget()
       
    90 {
       
    91 }
   122 }
    92 
   123 
    93 /*!
   124 /*!
    94     Called when widget is shown in the home screen
   125     Called when widget is shown in the home screen
    95 */
   126 */
    96 void FmRadioHsWidget::onShow()
   127 void FmRadioHsWidget::onShow()
    97 {
   128 {
       
   129     LOG_METHOD_ENTER;
    98 }
   130 }
    99 
   131 
   100 /*!
   132 /*!
   101     Called when widget is hidden from the home screen
   133     Called when widget is hidden from the home screen
   102 */
   134 */
   103 void FmRadioHsWidget::onHide()
   135 void FmRadioHsWidget::onHide()
   104 {
   136 {
       
   137     LOG_METHOD_ENTER;
   105 }
   138 }
   106 
   139 
   107 /*!
   140 /*!
   108     Loads docml files.
   141     Loads docml files.
   109 */
   142 */
   110 void FmRadioHsWidget::load(const QString docml)
   143 void FmRadioHsWidget::load(const QString &docml)
   111 {
   144 {
   112     bool loaded = false;
   145     LOG_METHOD_ENTER;
   113 
   146 
   114     HbDocumentLoader *documentLoader = new HbDocumentLoader();
   147     HbDocumentLoader *documentLoader = new HbDocumentLoader();
   115     documentLoader->reset();
   148     documentLoader->reset();
       
   149     bool loaded = false;
   116     documentLoader->load(docml, &loaded);
   150     documentLoader->load(docml, &loaded);
   117 
   151 
   118     if (loaded) {
   152     if (loaded) {
   119         HbWidget *widget = qobject_cast<HbWidget*> (documentLoader->findWidget(
   153         // Find mainLayout
       
   154         HbWidget *mainLayout = qobject_cast<HbWidget*> (documentLoader->findWidget(
   120             KDocmlObjectNameMainLayout));
   155             KDocmlObjectNameMainLayout));
   121 
   156         // For drawing frame backgrounds
   122         HbFrameItem *frameItem = NULL;
   157         HbFrameItem *frameItem = NULL;
   123 
   158 
   124         if (widget) {
   159         if (mainLayout) {
   125             //HbWidget *view = qobject_cast<HbWidget*> (widget);
       
   126             QGraphicsLinearLayout *mWidgetLayout = new QGraphicsLinearLayout(Qt::Vertical, this);
   160             QGraphicsLinearLayout *mWidgetLayout = new QGraphicsLinearLayout(Qt::Vertical, this);
   127 
   161             
   128             HbFrameDrawer *drawer = new HbFrameDrawer("qtg_fr_hswidget_normal",
   162             // Temporarily use graphics from resources. Change to the system
   129                 HbFrameDrawer::NinePieces);
   163             // graphics when they are available.
   130             frameItem = new HbFrameItem(drawer, widget);
   164             HbFrameDrawer *drawer = new HbFrameDrawer(
   131             frameItem->setPreferredSize(widget->preferredSize());
   165                 ":/ui/resource/qtg_graf_hsradio_bg.png",
   132 
   166                 HbFrameDrawer::OnePiece);
   133             mWidgetLayout->addItem(widget);
   167             //HbFrameDrawer *drawer = new HbFrameDrawer("qtg_fr_hswidget_normal",
       
   168             //    HbFrameDrawer::NinePieces);
       
   169             frameItem = new HbFrameItem(drawer, mainLayout);
       
   170             frameItem->setPreferredSize(mainLayout->preferredSize());
       
   171 
       
   172             mWidgetLayout->addItem(mainLayout);
   134             setLayout(mWidgetLayout);
   173             setLayout(mWidgetLayout);
   135         }
   174         }
   136 
   175         
   137         mRadioPushButton = qobject_cast<HbPushButton*> (documentLoader->findWidget(
   176         // Find stacked layout for tuner area.
   138             KDocmlObjectNameRadioIconPushButton));
   177         HbWidget *tunerStackedLayout = qobject_cast<HbWidget*> (documentLoader->findWidget(
   139         if (mRadioPushButton) {
   178             KDocmlObjectNameTunerStackedLayout));
       
   179         if (tunerStackedLayout) {
       
   180 
       
   181             // Find stacked layout for information area.
       
   182             HbWidget *tunerInformationStackedLayout = qobject_cast<HbWidget*> (documentLoader->findWidget(
       
   183                 KDocmlObjectNameTunerInformationStackedLayout));
       
   184             if (tunerInformationStackedLayout) {
       
   185 
       
   186                 // MarqueeItem tests.
       
   187                     /*
       
   188                     QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical, mInformationAreaOneRowLayout);
       
   189                     mInformationLonelyRowMarquee = new HbMarqueeItem();
       
   190                     mInformationLonelyRowMarquee->setObjectName("marquee3");
       
   191                     HbStyle::setItemName(mInformationLonelyRowMarquee, "marquee3");
       
   192                     mInformationLonelyRowMarquee->setText(
       
   193                         "Long text");
       
   194                     mInformationLonelyRowMarquee->setLoopCount(-1);
       
   195                     mInformationLonelyRowMarquee->startAnimation();
       
   196                     HbFontSpec fs(HbFontSpec::Secondary);
       
   197                     mInformationLonelyRowMarquee->setFontSpec(fs);
       
   198                     mInformationLonelyRowMarquee->setTextColor(HbColorScheme::color("qtc_hs_list_item_title"));
       
   199                     mInformationLonelyRowMarquee->setPreferredSize(layout->preferredSize());
       
   200                     layout->addItem(mInformationLonelyRowMarquee);
       
   201                     */
       
   202                 /*
       
   203                 }
       
   204                 */
       
   205 
       
   206                 // Find lonely label
       
   207                 mInformationLonelyRowLabel = qobject_cast<HbLabel *> (documentLoader->findWidget(
       
   208                     KDocmlObjectNameLonelyRowLabel));
       
   209                 if (mInformationLonelyRowLabel) {
       
   210                     QColor color = HbColorScheme::color("qtc_radio_tuner_normal");
       
   211                     if (color.isValid()) {
       
   212                         mInformationLonelyRowLabel->setTextColor(color);
       
   213                     }
       
   214                 }
       
   215 
       
   216                 // Find layout for two rows
       
   217                 mInformationAreaTwoRowsLayout = qobject_cast<QGraphicsWidget *> (
       
   218                     documentLoader->findObject(KDocmlObjectNameTwoRowsLayout));
       
   219                 if (mInformationAreaTwoRowsLayout) {
       
   220                     // Find first row
       
   221                     mInformationFirstRowLabel = qobject_cast<HbLabel *> (documentLoader->findWidget(
       
   222                         KDocmlObjectNameFirstRowLabel));
       
   223                     if (mInformationFirstRowLabel) {
       
   224                         QColor color = HbColorScheme::color("qtc_radio_tuner_normal");
       
   225                         if (color.isValid()) {
       
   226                             mInformationFirstRowLabel->setTextColor(color);
       
   227                         }
       
   228                     }
       
   229 
       
   230                     // Find second row
       
   231                     mInformationSecondRowLabel = qobject_cast<HbLabel *> (documentLoader->findWidget(
       
   232                         KDocmlObjectNameSecondRowLabel));
       
   233                     if (mInformationSecondRowLabel) {
       
   234                         QColor color = HbColorScheme::color("qtc_radio_tuner_normal");
       
   235                         if (color.isValid()) {
       
   236                             mInformationSecondRowLabel->setTextColor(color);
       
   237                         }
       
   238                     }
       
   239 
       
   240                 }
       
   241 
       
   242 
       
   243                 mAnimationIcon = qobject_cast<HbLabel *> (documentLoader->findWidget(
       
   244                     KDocmlObjectNameAnimationIcon));
       
   245                 if (mAnimationIcon) {
       
   246                     // Use animation manager to define the frame-by-frame animation.
       
   247                     HbIconAnimationManager *animationManager = HbIconAnimationManager::global();
       
   248 
       
   249                     // Create animation definition.
       
   250                     HbIconAnimationDefinition animationDefinition;
       
   251                     QList<HbIconAnimationDefinition::AnimationFrame> animationFrameList;
       
   252 
       
   253                     // This should be probably done by loading axml instead.
       
   254                     HbIconAnimationDefinition::AnimationFrame animationFrame;
       
   255                     QString animationFrameIconName;
       
   256                     QString animationFrameIconNamePrefix = "qtg_anim_loading_";
       
   257                     for (int i = 1; i < 11; i++) {
       
   258                         animationFrame.duration = 100;
       
   259                         animationFrameIconName.clear();
       
   260                         animationFrameIconName.append(animationFrameIconNamePrefix);
       
   261                         animationFrameIconName.append(animationFrameIconName.number(i));
       
   262                         animationFrame.iconName = animationFrameIconName;
       
   263                         animationFrameList.append(animationFrame);
       
   264                     }
       
   265                     animationDefinition.setPlayMode(HbIconAnimationDefinition::Loop);
       
   266                     animationDefinition.setFrameList(animationFrameList);
       
   267                     animationManager->addDefinition("animation", animationDefinition);
       
   268 
       
   269                     // Construct an icon using the animation definition.
       
   270                     HbIcon icon("animation");
       
   271 
       
   272                     mAnimationIcon->setIcon(icon);
       
   273                 }
       
   274 
       
   275             }
       
   276 
       
   277             // Find push button for tuner area.
       
   278             mTunerBackgroundPushButton = qobject_cast<HbPushButton*> (documentLoader->findWidget(
       
   279                 KDocmlObjectNameTunerBackgroundPushButton));
       
   280             if (mTunerBackgroundPushButton) {
       
   281                 // Test different states.
       
   282                 //bool p = mTunerBackgroundPushButton->setProperty("state", "normal");
       
   283                 // Try css for controlling the appearance.
       
   284                 //bool b = QFile::exists(KCss);
       
   285                 //bool cssLoaded = HbStyleLoader::registerFilePath(KCss);
       
   286                 //HbStyle::setItemName(mTunerBackgroundPushButton, KDocmlObjectNameTunerBackgroundPushButton);
       
   287                 // Use the frame background.
       
   288                 HbFrameDrawer *tunerBackgroundButtonFrameDrawer = new HbFrameDrawer(
       
   289                     "qtg_fr_tuner", HbFrameDrawer::ThreePiecesHorizontal);
       
   290                 tunerBackgroundButtonFrameDrawer->setFillWholeRect(true);
       
   291                 mTunerBackgroundPushButton->setFrameBackground(tunerBackgroundButtonFrameDrawer);
       
   292                 
       
   293                 // Connect the button's clicked signal. 
       
   294                 connect(mTunerBackgroundPushButton, SIGNAL(clicked()), this, SLOT(radioToForeground()));
       
   295             }
       
   296 
       
   297         }
       
   298 
       
   299         // Find layout for control buttons.
       
   300         HbWidget *controlButtonsLayout = qobject_cast<HbWidget*> (documentLoader->findWidget(
       
   301             KDocmlObjectNameContolButtonsLayout));
       
   302         if (controlButtonsLayout) {
   140             if (frameItem) {
   303             if (frameItem) {
   141                 frameItem->stackBefore(mRadioPushButton);
   304                 // Stack widget's background behind it.
   142             }
   305                 frameItem->stackBefore(controlButtonsLayout);
   143             mRadioPushButton->setBackground(HbIcon("qtg_large_radio"));
   306             }
   144             mRadioPushButton->icon().setSize(mRadioPushButton->preferredSize());
   307             
   145             QObject::connect(mRadioPushButton, SIGNAL(clicked()), this, SLOT(radioToForeground()));
   308             // Find power button.
       
   309             mPowerToggleButton = qobject_cast<HbPushButton *> (documentLoader->findWidget(
       
   310                 KDocmlObjectNameowerToggleButton));
       
   311             if (mPowerToggleButton) {
       
   312                 // If power button is lathced type, use this.
       
   313                 //mPowerToggleButton->setCheckable(true);
       
   314                 changeControlButtonFrameBackground(false, Left, mPowerToggleButton);
       
   315                 
       
   316                 // Use the graphics from resources until release contains proper graphics. 
       
   317                 mPowerToggleButton->setIcon(HbIcon(":/ui/resource/mono_power.png"));
       
   318                 // Connect the button's clicked signal.
       
   319                 connect(mPowerToggleButton, SIGNAL(clicked()), this, SLOT(radioToBackground()));
       
   320             }
       
   321             
       
   322             // Find previous button.
       
   323             mPreviousPushButton = qobject_cast<HbPushButton *> (documentLoader->findWidget(
       
   324                 KDocmlObjectNamePreviousPushButton));
       
   325             if (mPreviousPushButton) {
       
   326                 changeControlButtonFrameBackground(false, Center, mPreviousPushButton);
       
   327                 // Connect the button's clicked signal.
       
   328                 connect(mPreviousPushButton, SIGNAL(clicked()), this, SLOT(previousChannel()));
       
   329             }
       
   330 
       
   331             // Find next button.
       
   332             mNextPushButton = qobject_cast<HbPushButton *> (documentLoader->findWidget(
       
   333                 KDocmlObjectNameNextPushButton));
       
   334             if (mNextPushButton) {
       
   335                 changeControlButtonFrameBackground(false, Right, mNextPushButton);
       
   336                 // Connect the button's clicked signal.
       
   337                 connect(mNextPushButton, SIGNAL(clicked()), this, SLOT(nextChannel()));
       
   338             }
   146         }
   339         }
   147 
   340 
   148         mVerticalSeparatorLabel = qobject_cast<HbLabel*> (documentLoader->findWidget(
   341     }
   149             KDocmlObjectNameVerticalSeparatorLabel));
   342     // Loader is not needed anymore so it is deleted.
   150         if (mVerticalSeparatorLabel) {
       
   151             mVerticalSeparatorLabel->setIcon(HbIcon("qtg_graf_divider_v_thin"));
       
   152         }
       
   153         
       
   154         HbWidget *controlAreaLayoutWidget = qobject_cast<HbWidget*> (documentLoader->findWidget(
       
   155             KDocmlObjectNameControlAreaLayout));
       
   156         if (controlAreaLayoutWidget) {
       
   157         }
       
   158 
       
   159         mPreviousPushButton = qobject_cast<HbPushButton *> (documentLoader->findWidget(
       
   160             KDocmlObjectNamePreviousPushButton));
       
   161         if (mPreviousPushButton) {
       
   162             changeControlButtonFrameBackground(false, Left, mPreviousPushButton);
       
   163 /*
       
   164             HbFrameDrawer *previousButtonFrameDrawer = new HbFrameDrawer("qtg_fr_hsbutton_disabled",
       
   165                   HbFrameDrawer::ThreePiecesHorizontal);
       
   166             previousButtonFrameDrawer->setFileNameSuffixList(QStringList() << "_l" << "_c" << "_cr");
       
   167             mPreviousPushButton->setFrameBackground(previousButtonFrameDrawer);
       
   168 */            QObject::connect(mPreviousPushButton, SIGNAL(clicked()), this, SLOT(previousChannel()));
       
   169         }
       
   170 
       
   171         mPlayPushButton = qobject_cast<HbPushButton *> (documentLoader->findWidget(
       
   172             KDocmlObjectNamePlayPushButton));
       
   173         if (mPlayPushButton) {
       
   174             changeControlButtonFrameBackground(false, Center, mPlayPushButton);
       
   175 /*            HbFrameDrawer *playButtonFrameDrawer = new HbFrameDrawer("qtg_fr_hsbutton_disabled",
       
   176                   HbFrameDrawer::ThreePiecesHorizontal);
       
   177             playButtonFrameDrawer->setFileNameSuffixList(QStringList() << "_cl" << "_c" << "_cr");
       
   178             mPlayPushButton->setFrameBackground(playButtonFrameDrawer);
       
   179 */            QObject::connect(mPlayPushButton, SIGNAL(clicked()), this, SLOT(radioToBackground()));
       
   180         }
       
   181 
       
   182         mNextPushButton = qobject_cast<HbPushButton *> (documentLoader->findWidget(
       
   183             KDocmlObjectNameNextPushButton));
       
   184         if (mNextPushButton) {
       
   185             changeControlButtonFrameBackground(false, Right, mNextPushButton);
       
   186 /*            HbFrameDrawer *nextButtonFrameDrawer = new HbFrameDrawer("qtg_fr_hsbutton_disabled",
       
   187                   HbFrameDrawer::ThreePiecesHorizontal);
       
   188             nextButtonFrameDrawer->setFileNameSuffixList(QStringList() << "_cl" << "_c" << "_r");
       
   189             mNextPushButton->setFrameBackground(nextButtonFrameDrawer);
       
   190 */            QObject::connect(mNextPushButton, SIGNAL(clicked()), this, SLOT(nextChannel()));
       
   191         }
       
   192         
       
   193         //bool b = QFile::exists(KCss);
       
   194         bool a = HbStyleLoader::registerFilePath(KCss);
       
   195 
       
   196         mInformationAreaTwoRowsLayout = qobject_cast<QGraphicsWidget *> (
       
   197             documentLoader->findObject(KDocmlObjectNameTwoRowsLayout));
       
   198         if (mInformationAreaTwoRowsLayout) {
       
   199             /*
       
   200             QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical, mInformationAreaTwoRowsLayout);
       
   201             mInformationFirstRowMarquee = new HbMarqueeItem();
       
   202             HbStyle::setItemName(mInformationFirstRowMarquee, "marquee1");
       
   203             mInformationFirstRowMarquee->setObjectName("marquee1");
       
   204             mInformationFirstRowMarquee->setText(
       
   205                 "Long text");
       
   206             mInformationFirstRowMarquee->setLoopCount(-1);
       
   207             mInformationFirstRowMarquee->startAnimation();
       
   208             HbFontSpec fs(HbFontSpec::Secondary);
       
   209             mInformationFirstRowMarquee->setFontSpec(fs);
       
   210             mInformationFirstRowMarquee->setTextColor(HbColorScheme::color("qtc_hs_list_item_title"));
       
   211             mInformationFirstRowMarquee->setPreferredSize(layout->preferredSize());
       
   212             layout->addItem(mInformationFirstRowMarquee);
       
   213          
       
   214             mInformationSecondRowMarquee = new HbMarqueeItem();
       
   215             mInformationSecondRowMarquee->setObjectName("marquee2");
       
   216             mInformationSecondRowMarquee->setText(
       
   217                 "Long text to test marquee, Long text to test marquee");
       
   218             mInformationSecondRowMarquee->setLoopCount(-1);
       
   219             mInformationSecondRowMarquee->startAnimation();
       
   220             mInformationSecondRowMarquee->setFontSpec(fs);
       
   221             mInformationSecondRowMarquee->setTextColor(HbColorScheme::color("qtc_hs_list_item_title"));
       
   222             mInformationSecondRowMarquee->setPreferredSize(layout->preferredSize());
       
   223             layout->addItem(mInformationSecondRowMarquee);
       
   224             */
       
   225         }
       
   226 
       
   227         mInformationAreaOneRowLayout = qobject_cast<QGraphicsWidget *> (documentLoader->findObject(
       
   228             KDocmlObjectNameOneRowLayout));
       
   229         if (mInformationAreaOneRowLayout) {
       
   230             /*
       
   231             QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical, mInformationAreaOneRowLayout);
       
   232             mInformationLonelyRowMarquee = new HbMarqueeItem();
       
   233             mInformationLonelyRowMarquee->setObjectName("marquee3");
       
   234             HbStyle::setItemName(mInformationLonelyRowMarquee, "marquee3");
       
   235             mInformationLonelyRowMarquee->setText(
       
   236                 "Long text");
       
   237             mInformationLonelyRowMarquee->setLoopCount(-1);
       
   238             mInformationLonelyRowMarquee->startAnimation();
       
   239             HbFontSpec fs(HbFontSpec::Secondary);
       
   240             mInformationLonelyRowMarquee->setFontSpec(fs);
       
   241             mInformationLonelyRowMarquee->setTextColor(HbColorScheme::color("qtc_hs_list_item_title"));
       
   242             mInformationLonelyRowMarquee->setPreferredSize(layout->preferredSize());
       
   243             layout->addItem(mInformationLonelyRowMarquee);
       
   244             */
       
   245         }
       
   246 
       
   247         mInformationAreaAnimationLayout = qobject_cast<QGraphicsWidget *> (
       
   248             documentLoader->findObject(QString(KDocmlObjectNameAnimationLayout)));
       
   249         if (mInformationAreaAnimationLayout) {
       
   250         }
       
   251         
       
   252         mInformationFirstRowLabel = qobject_cast<HbLabel *> (documentLoader->findWidget(
       
   253             KDocmlObjectNameFirstRowLabel));
       
   254         if (mInformationFirstRowLabel) {
       
   255             mInformationFirstRowLabel->setTextColor(HbColorScheme::color("qtc_hs_list_item_title"));
       
   256         }
       
   257 
       
   258         mInformationSecondRowLabel = qobject_cast<HbLabel *> (documentLoader->findWidget(
       
   259             KDocmlObjectNameSecondRowLabel));
       
   260         if (mInformationSecondRowLabel) {
       
   261             mInformationSecondRowLabel->setTextColor(HbColorScheme::color("qtc_hs_list_item_content"));
       
   262         }
       
   263 
       
   264         mInformationLonelyRowLabel = qobject_cast<HbLabel *> (documentLoader->findWidget(
       
   265             KDocmlObjectNameLonelyRowLabel));
       
   266         if (mInformationLonelyRowLabel) {
       
   267             mInformationLonelyRowLabel->setTextColor(HbColorScheme::color("qtc_hs_list_item_content"));
       
   268         }
       
   269 
       
   270         mAnimationIcon = qobject_cast<HbLabel *> (documentLoader->findWidget(
       
   271             KDocmlObjectNameAnimationIcon));
       
   272         if (mAnimationIcon) {
       
   273             // Use animation manager to define the frame-by-frame animation.
       
   274             HbIconAnimationManager *animationManager = HbIconAnimationManager::global();
       
   275 
       
   276             // Create animation definition.
       
   277             HbIconAnimationDefinition animationDefinition;
       
   278             QList<HbIconAnimationDefinition::AnimationFrame> animationFrameList;
       
   279 
       
   280             HbIconAnimationDefinition::AnimationFrame animationFrame;
       
   281             QString animationFrameIconName;
       
   282             QString animationFrameIconNamePrefix = "qtg_anim_loading_";
       
   283             for (int i = 1; i < 11; i++) {
       
   284                 animationFrame.duration = 100;
       
   285                 animationFrameIconName.clear();
       
   286                 animationFrameIconName.append(animationFrameIconNamePrefix);
       
   287                 animationFrameIconName.append(animationFrameIconName.number(i));
       
   288                 animationFrame.iconName = animationFrameIconName;
       
   289                 animationFrameList.append(animationFrame);
       
   290             }
       
   291             animationDefinition.setPlayMode(HbIconAnimationDefinition::Loop);
       
   292             animationDefinition.setFrameList(animationFrameList);
       
   293             animationManager->addDefinition("animation", animationDefinition);
       
   294 
       
   295             // Construct an icon using the animation definition.
       
   296             HbIcon icon("animation");
       
   297             
       
   298             mAnimationIcon->setIcon(icon);
       
   299         }
       
   300 
       
   301     }
       
   302     delete documentLoader;
   343     delete documentLoader;
   303 }
   344 }
   304 
   345 
   305 /*!
   346 /*!
   306  Slot for grouping events.
   347  Slot for closing FM Radio application from power button.
   307  */
   348  */
   308 bool FmRadioHsWidget::eventFilter(QObject */*target*/, QEvent */*event*/)
   349 void FmRadioHsWidget::closeRadio()
   309  {
   350 {
   310 // This event filter is used to get events from information area layout and from it's components.
   351     LOG_SLOT_CALLER;
   311 // Not yet implemented.   
   352     mRadioServiceClient->doCloseFmRadio();
   312 /*
       
   313     if (target == mFrequencyLabel) {
       
   314         if (event->type() == QEvent::MouseButtonRelease) {
       
   315             qDebug() << "MouseButtonRelease";
       
   316             return true;
       
   317         }
       
   318         else if (event->type() == QEvent::MouseButtonPress) {
       
   319             qDebug() << "MouseButtonPress";
       
   320             return true;
       
   321         }
       
   322         else if (event->type() == QEvent::KeyPress) {
       
   323             qDebug() << "KeyPress";
       
   324             return true;
       
   325         }
       
   326         else {
       
   327             return false;
       
   328         }
       
   329     }
       
   330     else {
       
   331         // pass the event on to the parent class
       
   332         return HbWidget::eventFilter(target, event);
       
   333     }
       
   334 */
       
   335     return false;
       
   336 }
       
   337 
       
   338 /*!
       
   339  Mute FM Radio audio.
       
   340  */
       
   341 void FmRadioHsWidget::mute()
       
   342 {
       
   343     mRadioServiceClient->doControlFmRadioAudio(FmRadioHsWidgetRadioServiceClient::Mute);
       
   344     //handleRadioStateChange(QVariant(NotControllingAudio));
       
   345 }
       
   346 
       
   347 /*!
       
   348  Unmute FM Radio audio.
       
   349  */
       
   350 void FmRadioHsWidget::unMute()
       
   351 {
       
   352     mRadioServiceClient->doControlFmRadioAudio(FmRadioHsWidgetRadioServiceClient::Unmute);
       
   353     //handleRadioStateChange(QVariant(ControllingAudio));
       
   354 }
   353 }
   355 
   354 
   356 /*!
   355 /*!
   357  Slot for previous button clicked.
   356  Slot for previous button clicked.
   358  */
   357  */
   359 void FmRadioHsWidget::previousChannel()
   358 void FmRadioHsWidget::previousChannel()
   360 {
   359 {
   361     mRadioServiceClient->doChangeFmRadioChannel(FmRadioHsWidgetRadioServiceClient::PreviousFavouriteChannel);
   360     LOG_SLOT_CALLER;
       
   361     clearRadioInformation();
       
   362     mRadioServiceClient->doChangeFmRadioStation(FmRadioHsWidgetRadioServiceClient::PreviousFavouriteStation);
   362 }
   363 }
   363 
   364 
   364 /*!
   365 /*!
   365  Slot for next button clicked.
   366  Slot for next button clicked.
   366  */
   367  */
   367 void FmRadioHsWidget::nextChannel()
   368 void FmRadioHsWidget::nextChannel()
   368 {
   369 {
   369     mRadioServiceClient->doChangeFmRadioChannel(FmRadioHsWidgetRadioServiceClient::NextFavouriteChannel);
   370     LOG_SLOT_CALLER;
   370 }
   371     clearRadioInformation();
   371 
   372     mRadioServiceClient->doChangeFmRadioStation(FmRadioHsWidgetRadioServiceClient::NextFavouriteStation);
   372 /*!
   373 }
   373  Slot for radio button clicked.
   374 
       
   375 /*!
       
   376  Slot for bringing the radio application to foreground.
   374  */
   377  */
   375 void FmRadioHsWidget::radioToForeground()
   378 void FmRadioHsWidget::radioToForeground()
   376 {
   379 {
       
   380     LOG_SLOT_CALLER;
       
   381     // If radio is not running start it to foreground by monitor request.
   377     if (mFmRadioState == NotRunning) {
   382     if (mFmRadioState == NotRunning) {
   378         handleRadioStateChange(QVariant(Starting));
   383         handleRadioStateChange(QVariant(Starting));
       
   384         //mRadioServiceClient->doPowerOnFmRadio(FmRadioHsWidgetRadioServiceClient::ToForeground);
   379         mRadioServiceClient->startMonitoring(FmRadioHsWidgetRadioServiceClient::ToForeground);
   385         mRadioServiceClient->startMonitoring(FmRadioHsWidgetRadioServiceClient::ToForeground);
   380     }
   386     }
   381     else {
   387     else {
       
   388         if (mFmRadioState == Closing) {
       
   389             // Radio is closing but user wants to power it up again.
       
   390             mRadioServiceClient->doPowerOnFmRadio();
       
   391             mRadioServiceClient->stopMonitoring();
       
   392             mRadioServiceClient->startMonitoring(FmRadioHsWidgetRadioServiceClient::ToBackground);
       
   393             handleRadioStateChange(QVariant(Running));
       
   394         }
       
   395         // If radio is running, bring it to the foreground.
   382         mRadioServiceClient->doChangeFmRadioVisibility(
   396         mRadioServiceClient->doChangeFmRadioVisibility(
   383             FmRadioHsWidgetRadioServiceClient::ToForeground);
   397             FmRadioHsWidgetRadioServiceClient::ToForeground);
   384     }
   398     }
   385 }
   399 }
   386 
   400 
   387 /*!
   401 /*!
   388  Slot for radio button clicked.
   402  Slot for putting the radio application to the background.
   389  */
   403  */
   390 void FmRadioHsWidget::radioToBackground()
   404 void FmRadioHsWidget::radioToBackground()
   391 {
   405 {
       
   406     LOG_SLOT_CALLER;
       
   407     // If radio is not running start it to background by monitor request.
   392     if (mFmRadioState == NotRunning) {
   408     if (mFmRadioState == NotRunning) {
   393         handleRadioStateChange(QVariant(Starting));
   409         handleRadioStateChange(QVariant(Starting));
   394         mRadioServiceClient->startMonitoring(FmRadioHsWidgetRadioServiceClient::ToBackground);
   410         mRadioServiceClient->startMonitoring(FmRadioHsWidgetRadioServiceClient::ToBackground);
   395     }
   411     }
   396     else if (mFmRadioState == Starting) {
   412     else if (mFmRadioState == Starting) {
   397         
   413         // Do nothing if radio is starting.
       
   414     }
       
   415     else if (mFmRadioState == Closing) {
       
   416         // Radio is closing but user wants to power it up again.
       
   417         mRadioServiceClient->doPowerOnFmRadio();
       
   418         mRadioServiceClient->stopMonitoring();
       
   419         mRadioServiceClient->startMonitoring(FmRadioHsWidgetRadioServiceClient::ToBackground);
       
   420         handleRadioStateChange(QVariant(Running));
   398     }
   421     }
   399     else {
   422     else {
       
   423         // If radio is running, put it to the background.
       
   424         // This is little bit useless because the radio is in background if
       
   425         // user is able to click the widget.
   400         mRadioServiceClient->doChangeFmRadioVisibility(
   426         mRadioServiceClient->doChangeFmRadioVisibility(
   401             FmRadioHsWidgetRadioServiceClient::ToBackground);
   427             FmRadioHsWidgetRadioServiceClient::ToBackground);
   402     }
   428     }
   403 }
   429 }
   404 
   430 
   405 /*!
   431 /*!
   406  Opening of url to the browser.
       
   407  
       
   408  /param url Url to be opened.
       
   409  */
       
   410 bool FmRadioHsWidget::openUrl(QUrl url)
       
   411 {
       
   412     return QDesktopServices::openUrl(url);
       
   413 }
       
   414 
       
   415 /*!
       
   416  Handles changes in FM Radio information.
   432  Handles changes in FM Radio information.
   417  
   433 
   418  /param type Type of changed information.
   434  /param type Type of changed information.
   419  /param value Information content.
   435  /param value Information content.
   420  */
   436  */
   421 void FmRadioHsWidget::handleRadioInformationChange(
   437 void FmRadioHsWidget::handleRadioInformationChange(const int notificationId,
   422     int notificationId, QVariant value)
   438     const QVariant &value)
   423 {
   439 {
       
   440     LOG_METHOD;
       
   441     LEVEL2(LOG_SLOT_CALLER);
   424     if (!value.isValid()) {
   442     if (!value.isValid()) {
       
   443         // Value is not valid so return.
   425         return;
   444         return;
   426     }
   445     }
   427     switch ( notificationId ) {
   446     switch ( notificationId ) {
   428 
   447 
   429         case RadioServiceNotification::FavoriteCount:
   448         case RadioServiceNotification::FavoriteCount:
       
   449             LEVEL2(LOG("FavoriteCount"));
   430             if (value.canConvert(QVariant::Int)) {
   450             if (value.canConvert(QVariant::Int)) {
   431                 int favoriteCount = value.toInt();
   451                 int favoriteCount = value.toInt();
   432                 mIsFavoriteChannels = favoriteCount > 0 ? true : false;
   452                 // If there are favorite stations, enable the next/previous
   433                 changeChannelButtonsEnabledState(mIsFavoriteChannels);
   453                 // buttons.
       
   454                 mFavoriteStations = favoriteCount > 0 ? true : false;
       
   455                 LEVEL2(LOG_FORMAT("favoriteCount: %d, mFavoriteStations: %d",
       
   456                     favoriteCount, mFavoriteStations));
       
   457             changeStationButtonsEnabledState(mFavoriteStations);
   434             }
   458             }
   435             break;
   459             break;
       
   460             
       
   461         case RadioServiceNotification::CurrentIsFavorite:
       
   462             LEVEL2(LOG("CurrentIsFavorite"));
       
   463             if (value.canConvert(QVariant::Bool)) {
       
   464                 bool currentIsFavorite = value.toBool();
       
   465                 LEVEL2(LOG_FORMAT("currentIsFavorite: %d", currentIsFavorite));
       
   466                 // If favorite count is 1 and current station is favorite
       
   467                 // disable next/prev buttons.
       
   468                 if (currentIsFavorite) {
       
   469                     changeStationButtonsEnabledState(false);
       
   470                 } else {
       
   471                     // Else eneble them.
       
   472                     changeStationButtonsEnabledState(true);
       
   473                 }
       
   474             }
       
   475             break;
   436 
   476 
   437         case RadioServiceNotification::RadioStatus:
   477         case RadioServiceNotification::RadioStatus:
       
   478             LEVEL2(LOG("RadioStatus"));
   438             if (value.canConvert(QVariant::Int)) {
   479             if (value.canConvert(QVariant::Int)) {
   439                 int status = value.toInt();
   480                 int status = value.toInt();
   440                 switch (status) {
   481                 switch (status) {
   441                 case RadioStatus::Playing:
   482                 case RadioStatus::Playing:
       
   483                     LEVEL2(LOG("Playing"));
   442                     handleRadioStateChange(QVariant(ControllingAudio));
   484                     handleRadioStateChange(QVariant(ControllingAudio));
   443                     break;
   485                     break;
   444                 case RadioStatus::Muted:
   486                 case RadioStatus::Muted:
       
   487                     LEVEL2(LOG("Muted"));
   445                     handleRadioStateChange(QVariant(NotControllingAudio));
   488                     handleRadioStateChange(QVariant(NotControllingAudio));
   446                     break;
   489                     break;
   447                 case RadioStatus::Seeking:
   490                 case RadioStatus::Seeking:
       
   491                     LEVEL2(LOG("Seeking"));
   448                     handleRadioStateChange(QVariant(Seeking));
   492                     handleRadioStateChange(QVariant(Seeking));
   449                     break;
   493                     break;
   450                 case RadioStatus::NoAntenna:
   494                 case RadioStatus::NoAntenna:
       
   495                     LEVEL2(LOG("NoAntenna"));
   451                     handleRadioStateChange(QVariant(AntennaNotConnected));
   496                     handleRadioStateChange(QVariant(AntennaNotConnected));
   452                     break;                    
   497                     break;                    
       
   498                 case RadioStatus::PoweringOff:
       
   499                     LEVEL2(LOG("PoweringOff"));
       
   500                     handleRadioStateChange(QVariant(Closing));
       
   501                     break;
   453                 default:
   502                 default:
       
   503                     LEVEL2(LOG("default"));
   454                     break;
   504                     break;
   455                 }
   505                 }
   456             }
   506             }
   457             break;
   507             break;
   458 
   508 
   459         case RadioServiceNotification::Frequency:
   509         case RadioServiceNotification::Frequency:
       
   510             LEVEL2(LOG("Frequency"));
   460             if (value.canConvert(QVariant::UInt)) {
   511             if (value.canConvert(QVariant::UInt)) {
   461                 const uint frequency = value.toUInt();
   512                 const uint frequency = value.toUInt();
   462                 QString freqString;
   513                 QString frequencyString;
   463                 freqString.sprintf("%.1f", qreal(frequency) / KFrequencyMultiplier);
   514                 // Format the frequency to human readable text.
       
   515                 frequencyString.sprintf("%.1f", qreal(frequency) / FREQUENCY_MULTIPLIER);
       
   516                 LEVEL2(LOG_FORMAT("frequency: %s", GETSTRING(frequencyString)));
       
   517                 // TODO: Remove comment when localisation is working on device.
       
   518                 //frequencyString = hbTrId("txt_rad_list_l1_mhz").arg(freqString);
   464                 bool frequencyCleared = false;
   519                 bool frequencyCleared = false;
       
   520                 // If widget has some frequency information and new frequency
       
   521                 // differs from that
   465                 if (mRadioInformation.contains(KRadioInformationFrequency)
   522                 if (mRadioInformation.contains(KRadioInformationFrequency)
   466                     && mRadioInformation[KRadioInformationFrequency].compare(freqString) != 0) {
   523                     && mRadioInformation[KRadioInformationFrequency].compare(frequencyString) != 0) {
       
   524                     // Clear all infromation from widget because station has changed.
   467                     clearRadioInformation();
   525                     clearRadioInformation();
   468                     frequencyCleared = true;
   526                     frequencyCleared = true;
   469                 }
   527                 }
   470                 bool frequencyUpdated = updateRadioInformation(KRadioInformationFrequency, freqString);
   528                 // If widget do not have any frquency information, update it.
       
   529                 bool frequencyUpdated = updateRadioInformation(KRadioInformationFrequency, frequencyString);
   471                 if (frequencyCleared || frequencyUpdated) {
   530                 if (frequencyCleared || frequencyUpdated) {
       
   531                     // Information changed, update the UI.
   472                     radioInformationChanged();
   532                     radioInformationChanged();
   473                 }
   533                 }
   474             }
   534             }
   475         break;
   535         break;
   476 
   536 
   477         case RadioServiceNotification::Name:
   537         case RadioServiceNotification::Name:
       
   538             LEVEL2(LOG("Name"));
   478             if (value.canConvert(QVariant::String)) {
   539             if (value.canConvert(QVariant::String)) {
   479                 if (updateRadioInformation(KRadioInformationStationName, value.toString())) {
   540                 if (updateRadioInformation(KRadioInformationStationName, value.toString())) {
       
   541                     LEVEL2(LOG_FORMAT("name: %s", GETSTRING(value.toString())));
   480                     radioInformationChanged();
   542                     radioInformationChanged();
   481                 }
   543                 }
   482             }
   544             }
   483         break;
   545         break;
   484 
   546 
   485         case RadioServiceNotification::Genre:
   547         case RadioServiceNotification::Genre:
       
   548             LEVEL2(LOG("Genre"));
   486             if (value.canConvert(QVariant::String)) {
   549             if (value.canConvert(QVariant::String)) {
   487                 if (updateRadioInformation(KRadioInformationPty, value.toString())) {
   550                 if (updateRadioInformation(KRadioInformationPty, value.toString())) {
       
   551                     LEVEL2(LOG_FORMAT("genre: %s", GETSTRING(value.toString())));
   488                     radioInformationChanged();
   552                     radioInformationChanged();
   489                 }
   553                 }
   490             }
   554             }
   491         break;
   555         break;
   492 
   556 
   493         case RadioServiceNotification::RadioText:
   557         case RadioServiceNotification::RadioText:
       
   558             LEVEL2(LOG("RadioText"));
   494             if (value.canConvert(QVariant::String)) {
   559             if (value.canConvert(QVariant::String)) {
   495                 if (updateRadioInformation(KRadioInformationRt, value.toString())) {
   560                 if (updateRadioInformation(KRadioInformationRt, value.toString())) {
       
   561                     LEVEL2(LOG_FORMAT("radio text: %s", GETSTRING(value.toString())));
   496                     radioInformationChanged();
   562                     radioInformationChanged();
   497                 }
   563                 }
   498             }
   564             }
   499         break;
   565         break;
   500 
   566         
   501         case RadioServiceNotification::HomePage:
   567         case RadioServiceNotification::DynamicPS:
       
   568             LOG("DynamicPS");
   502             if (value.canConvert(QVariant::String)) {
   569             if (value.canConvert(QVariant::String)) {
   503                 if (updateRadioInformation(KRadioInformationHomePage, value.toString())) {
   570                 if (updateRadioInformation(KRadioInformationDynamicPsName, value.toString())) {
       
   571                     LEVEL2(LOG_FORMAT("dynamicPS: %s", GETSTRING(value.toString())));
   504                     radioInformationChanged();
   572                     radioInformationChanged();
   505                 }
   573                 }
   506             }
   574             }
   507         break;
   575         break;
   508         
   576 
   509         case RadioServiceNotification::Song:
       
   510             if (value.canConvert(QVariant::String)) {
       
   511                 if (updateRadioInformation(KRadioInformationSong, value.toString())) {
       
   512                     radioInformationChanged();
       
   513                 }
       
   514             }
       
   515         break;
       
   516 
       
   517 
       
   518 /*    case FmRadioHsWidgetRadioServiceClient::InformationTypeCallSign:
       
   519         if (updateRadioInformation(KRadioInformationCallSign, informationText)) {
       
   520 
       
   521         }
       
   522         break;
       
   523 */
       
   524 /*    case FmRadioHsWidgetRadioServiceClient::InformationTypeDynamicPsName:
       
   525         if (updateRadioInformation(KRadioInformationDynamicPsName,
       
   526             informationText)) {
       
   527 
       
   528         }
       
   529         break;
       
   530         */
       
   531         
       
   532     default:
   577     default:
       
   578         LOG("default");
   533         break;
   579         break;
   534     }
   580     }
   535 }
   581 }
   536 
   582 
   537 /*!
   583 /*!
   538  Check if the the radio information is changed. If it is changed update it.
   584  Check if the the radio information is changed. If it is changed update it.
   539  
   585 
   540  /param informationType Type of the information. 
   586  /param informationType Type of the information.
   541  /param information  Information text.
   587  /param information  Information text.
   542  
   588 
   543  /return bool If information is updated, return true. Return false otherwise.
   589  /return bool If information is updated, return true. Return false otherwise.
   544  */
   590  */
   545 bool FmRadioHsWidget::updateRadioInformation(const QString informationType, QString information)
   591 bool FmRadioHsWidget::updateRadioInformation(const QString &informationType,
   546 {
   592     const QString &information)
   547     // If hash contains this type
   593 {
       
   594     LOG_METHOD_RET("%d");
       
   595     // If hash contains this type of information.
   548     if (mRadioInformation.contains(informationType)) {
   596     if (mRadioInformation.contains(informationType)) {
   549         // If new information is empty
   597         // If new information is empty.
   550         if (information.isEmpty()) {
   598         if (information.isEmpty()) {
   551             // Remove it from the hash
   599             // Remove old information from the hash.
       
   600             LEVEL2(LOG_FORMAT("informationType: %s removed", GETSTRING(informationType)));
   552             mRadioInformation.remove(informationType);
   601             mRadioInformation.remove(informationType);
   553             // Return true to indicate the change
   602             // Return true to indicate the change.
   554             return true;
   603             return true;
   555         }
   604         }
   556         // If new information differs from the old one
   605         // If new information differs from the old one.
   557         if (mRadioInformation[informationType].compare(information) != 0) {
   606         if (mRadioInformation[informationType].compare(information) != 0) {
   558             // Update the information
   607             // Update the information.
       
   608             LEVEL2(LOG_FORMAT("informationType: %s = %s", GETSTRING(informationType), GETSTRING(information)));
   559             mRadioInformation[informationType] = information;
   609             mRadioInformation[informationType] = information;
   560             // And return true to indicate the change
   610             // And return true to indicate the change.
   561             return true;
   611             return true;
   562         }
   612         }
   563     } else { // Hash do not contain the information
   613     } else { // Hash do not contain this type of information.
   564         // If new information is not empty
   614         // If new information is not empty.
   565         if (!information.isEmpty()) {
   615         if (!information.isEmpty()) {
   566             // Add it to the hash
   616             // Add it to the hash.
       
   617             LEVEL2(LOG_FORMAT("informationType: %s = %s", GETSTRING(informationType), GETSTRING(information)));
   567             mRadioInformation[informationType] = information;
   618             mRadioInformation[informationType] = information;
   568             // Return true to indicate the change
   619             // Return true to indicate the change.
   569             return true;
   620             return true;
   570         }
   621         }
   571     }
   622     }
   572     // Return false to indicate that nothing changed
   623     // Return false to indicate that nothing changed.
   573     return false;
   624     return false;
   574 }
   625 }
   575 
   626 
   576 /*!
   627 /*!
   577  Formatting radio information texts after change. 
   628  Formatting radio information texts after a change.
   578  */
   629  */
   579 void FmRadioHsWidget::radioInformationChanged()
   630 void FmRadioHsWidget::radioInformationChanged()
   580 {
   631 {
   581     mRadioInformationFirstRow = "";
   632     LOG_METHOD_ENTER;
   582     mRadioInformationSecondRow = "";
   633     // Clear the rows.
   583 
   634     mRadioInformationFirstRow.clear();
   584     // Lets formulate the first row, first station name
   635     mRadioInformationSecondRow.clear();
       
   636 
       
   637     // First row contains station name.
   585     if (mRadioInformation.contains(KRadioInformationStationName)) {
   638     if (mRadioInformation.contains(KRadioInformationStationName)) {
   586         mRadioInformationFirstRow.append(mRadioInformation.value(KRadioInformationStationName));
   639         mRadioInformationFirstRow.append(mRadioInformation.value(KRadioInformationStationName));
   587     }
   640     } else if (mRadioInformation.contains(KRadioInformationFrequency)) {
   588     // Second call sign
   641         // Or frequency.
   589     if (mRadioInformation.contains(KRadioInformationCallSign)) {
   642         mRadioInformationFirstRow.append(mRadioInformation.value(KRadioInformationFrequency));
   590         mRadioInformationFirstRow.append(" " + mRadioInformation.value(KRadioInformationCallSign));
   643     }
   591     }
   644     LEVEL2(LOG_FORMAT("mRadioInformationFirstRow: %s", GETSTRING(mRadioInformationFirstRow)));
   592     // Third frequency
   645     
   593     if (mRadioInformation.contains(KRadioInformationFrequency)) {
   646     // Second row of information contains radio text.
   594         mRadioInformationFirstRow.append(" " + mRadioInformation.value(KRadioInformationFrequency)
       
   595             + " " + KMhzText);
       
   596     }
       
   597     // Second row of information contains first rt
       
   598     if (mRadioInformation.contains(KRadioInformationRt)) {
   647     if (mRadioInformation.contains(KRadioInformationRt)) {
   599         mRadioInformationSecondRow.append(mRadioInformation.value(KRadioInformationRt));
   648         mRadioInformationSecondRow.append(mRadioInformation.value(KRadioInformationRt));
   600     }
   649     } else if (mRadioInformation.contains(KRadioInformationDynamicPsName)) {
   601     // Second is dynamic ps name
   650         // Or Dynamic PS name.
   602     if (mRadioInformation.contains(KRadioInformationDynamicPsName)) {
   651         mRadioInformationSecondRow.append(mRadioInformation.value(
   603         mRadioInformationSecondRow.append(" " + mRadioInformation.value(
       
   604             KRadioInformationDynamicPsName));
   652             KRadioInformationDynamicPsName));
   605     }
   653     } else if (mRadioInformation.contains(KRadioInformationPty)) {
   606     // Third is pty 
   654         // Or PTY.
   607     if (mRadioInformation.contains(KRadioInformationPty)) {
   655         mRadioInformationSecondRow.append(mRadioInformation.value(KRadioInformationPty));
   608         mRadioInformationSecondRow.append(" " + mRadioInformation.value(KRadioInformationPty));
   656     }
   609     }
   657     LEVEL2(LOG_FORMAT("mRadioInformationSecondRow: %s", GETSTRING(mRadioInformationSecondRow)));
   610 
   658     
       
   659     // If second row is empty.
   611     if (mRadioInformationSecondRow.isEmpty()) {
   660     if (mRadioInformationSecondRow.isEmpty()) {
       
   661         // Show only the lonely row.
   612         mInformationLonelyRowLabel->setPlainText(mRadioInformationFirstRow);
   662         mInformationLonelyRowLabel->setPlainText(mRadioInformationFirstRow);
   613         changeInformationAreaLayout(OneRow);
   663         changeInformationAreaLayout(OneRow);
   614     }
   664     }
   615     else {
   665     else {
       
   666         // Else display both rows.
   616         mInformationFirstRowLabel->setPlainText(mRadioInformationFirstRow);
   667         mInformationFirstRowLabel->setPlainText(mRadioInformationFirstRow);
   617         mInformationSecondRowLabel->setPlainText(mRadioInformationSecondRow);
   668         mInformationSecondRowLabel->setPlainText(mRadioInformationSecondRow);
   618         changeInformationAreaLayout(TwoRows);
   669         changeInformationAreaLayout(TwoRows);
   619     }
   670     }
   620 }
   671 }
   621 
   672 
   622 /*!
   673 /*!
   623  Clears the radio station information. For example, when the channel is
   674  Clears the radio station information. For example, when the station is
   624  changed, old information should be cleared.
   675  changed, old information should be cleared.
   625  */
   676  */
   626 void FmRadioHsWidget::clearRadioInformation()
   677 void FmRadioHsWidget::clearRadioInformation()
   627 {
   678 {
       
   679     LOG_METHOD_ENTER;
   628     if (!mRadioInformation.isEmpty()) {
   680     if (!mRadioInformation.isEmpty()) {
       
   681         LEVEL2(LOG("clear radioInformation"));
   629         mRadioInformation.clear();
   682         mRadioInformation.clear();
   630     }
   683     }
   631 }
   684 }
   632 
   685 
   633 /*!
   686 /*!
   634  Handles changes in FM Radio state.
   687  Handles changes in FM Radio state.
   635  
   688 
   636  /param value Information content.
   689  /param value New state of the radio application.
   637  */
   690  */
   638 void FmRadioHsWidget::handleRadioStateChange(QVariant value)
   691 void FmRadioHsWidget::handleRadioStateChange(const QVariant &value)
   639 {
   692 {
       
   693     LOG_METHOD;
   640     int state;
   694     int state;
   641     if (value.canConvert(QVariant::Int)) {
   695     if (value.canConvert(QVariant::Int)) {
   642         state = value.toInt();
   696         state = value.toInt();
   643     } else {
   697     } else {
   644         return;
   698         return;
   645     }
   699     }
   646     
   700 
   647     if (state == mFmRadioState) {
   701     if (state == mFmRadioState) {
   648         // State did not change, so return.
   702         // State did not change, so return.
   649         return;
   703         return;
   650     }
   704     }
   651     
   705 
   652     switch (state) {
   706     switch (state) {
   653     case Undefined:
   707     case Undefined:
   654         // TODO: Some error occured because we do not have the state information. Handle this.
   708         LEVEL2(LOG("Undefined"));
       
   709         // Something went wrong. Widget should not be in this state after onInitialize().
   655         mFmRadioState = Undefined;
   710         mFmRadioState = Undefined;
   656         break;
   711         break;
   657     case NotRunning:
   712     case NotRunning:
       
   713         LEVEL2(LOG("NotRunning"));
   658         mFmRadioState = NotRunning;
   714         mFmRadioState = NotRunning;
   659         mRadioServiceClient->stopMonitoring();
   715         mRadioServiceClient->stopMonitoring();
   660         //changeControlButtonState(ChannelsDisabledPlay);
   716         changePowerButtonOn(false);
   661         QObject::disconnect(mPlayPushButton, SIGNAL(clicked()), this,
   717         mFavoriteStations = false;
   662             SLOT(unMute()));
   718         changeStationButtonsEnabledState(false);
   663         QObject::disconnect(mPlayPushButton, SIGNAL(clicked()), this,
   719         clearRadioInformation();
   664             SLOT(mute()));
       
   665         QObject::connect(mPlayPushButton, SIGNAL(clicked()), this,
       
   666             SLOT(radioToBackground()));
       
   667         changePlayButtonState(PlayEnabled);
       
   668         mIsFavoriteChannels = false;
       
   669         changeChannelButtonsEnabledState(false);
       
   670         mInformationFirstRowLabel->setPlainText("");
   720         mInformationFirstRowLabel->setPlainText("");
   671         mInformationSecondRowLabel->setPlainText("");
   721         mInformationSecondRowLabel->setPlainText("");
   672         mInformationLonelyRowLabel->setPlainText(KFmRadioText);
   722         mInformationLonelyRowLabel->setPlainText(hbTrId("txt_rad_list_fm_radio"));
   673         changeInformationAreaLayout(OneRow);
   723         changeInformationAreaLayout(OneRow);
   674         break;
   724         break;
   675     case Starting:
   725     case Starting:
       
   726         LEVEL2(LOG("Starting"));
   676         mFmRadioState = Starting;
   727         mFmRadioState = Starting;
   677         //changeControlButtonState(ChannelsDisabledStop);
   728         changePowerButtonOn(true);
   678         changePlayButtonState(StopDisabled);
   729         changeStationButtonsEnabledState(false);
   679         // TODO: What should the stop button do? Should it close the radio?
       
   680         changeChannelButtonsEnabledState(false);
       
   681         changeInformationAreaLayout(Animation);
   730         changeInformationAreaLayout(Animation);
       
   731         // This timer is workaround to recover from situation where radio is
       
   732         // started from widget but user answers no to the offline start dialog.
       
   733         // Stop timer if it is running.
       
   734         stopRadioStartingCancelTimer();
       
   735         // Set timer as single shot.
       
   736         mRadioStartingCancelTimer->setSingleShot(true);
       
   737         // Connect timeout.
       
   738         connect(mRadioStartingCancelTimer, SIGNAL(timeout()), this,
       
   739             SLOT(cancelRadioStartingState()));
       
   740         // Start to timeout after delay.
       
   741         mRadioStartingCancelTimer->start(KRadioStartingStateCancelDelay);
   682         break;
   742         break;
   683     case Running:
   743     case Running:
       
   744         LEVEL2(LOG("Running"));
   684         mFmRadioState = Running;
   745         mFmRadioState = Running;
   685         mRadioServiceClient->startMonitoring(FmRadioHsWidgetRadioServiceClient::DoNotChange);
   746         // Stop timer if it is running because radio is now running.
   686         //changeControlButtonState(ChannelsEnabledStop);
   747         stopRadioStartingCancelTimer();
   687         QObject::disconnect(mPlayPushButton, SIGNAL(clicked()), this,
   748         mRadioServiceClient->startMonitoring(
   688             SLOT(radioToBackground()));
   749             FmRadioHsWidgetRadioServiceClient::DoNotChange);
   689         QObject::disconnect(mPlayPushButton, SIGNAL(clicked()), this,
   750         changePowerButtonOn(true);
   690             SLOT(unMute()));
   751         changeStationButtonsEnabledState(mFavoriteStations);
   691         QObject::connect(mPlayPushButton, SIGNAL(clicked()), this,
       
   692             SLOT(mute()));
       
   693         changePlayButtonState(StopEnabled);
       
   694         changeChannelButtonsEnabledState(mIsFavoriteChannels);
       
   695         changeInformationAreaLayout(OneRow);
   752         changeInformationAreaLayout(OneRow);
   696         break;
   753         break;
   697     case ControllingAudio:
   754     case ControllingAudio:
       
   755         LEVEL2(LOG("ControllingAudio"));
   698         mFmRadioState = ControllingAudio;
   756         mFmRadioState = ControllingAudio;
   699         //changeControlButtonState(ChannelsEnabledStop);
   757         changeStationButtonsEnabledState(mFavoriteStations);
   700         QObject::disconnect(mPlayPushButton, SIGNAL(clicked()), this,
       
   701             SLOT(radioToBackground()));
       
   702         QObject::disconnect(mPlayPushButton, SIGNAL(clicked()), this,
       
   703             SLOT(unMute()));
       
   704         QObject::connect(mPlayPushButton, SIGNAL(clicked()), this,
       
   705             SLOT(mute()));
       
   706         changePlayButtonState(StopEnabled);
       
   707         changeChannelButtonsEnabledState(mIsFavoriteChannels);
       
   708         radioInformationChanged();
   758         radioInformationChanged();
   709         break;
   759         break;
   710     case NotControllingAudio:
   760     case NotControllingAudio:
       
   761         LEVEL2(LOG("NotControllingAudio"));
   711         mFmRadioState = NotControllingAudio;
   762         mFmRadioState = NotControllingAudio;
   712         //changeControlButtonState(ChannelsEnabledPlay);
   763         changeStationButtonsEnabledState(mFavoriteStations);
   713         QObject::disconnect(mPlayPushButton, SIGNAL(clicked()), this,
       
   714             SLOT(radioToBackground()));
       
   715         QObject::disconnect(mPlayPushButton, SIGNAL(clicked()), this,
       
   716             SLOT(mute()));
       
   717         QObject::connect(mPlayPushButton, SIGNAL(clicked()), this,
       
   718             SLOT(unMute()));
       
   719         changePlayButtonState(PlayEnabled);
       
   720         changeChannelButtonsEnabledState(mIsFavoriteChannels);
       
   721         radioInformationChanged();
   764         radioInformationChanged();
   722         break;
   765         break;
   723     case Seeking:
   766     case Seeking:
       
   767         LEVEL2(LOG("Seeking"));
   724         mFmRadioState = Seeking;
   768         mFmRadioState = Seeking;
   725         //changeControlButtonState(AllDisabledStop);
   769         changeStationButtonsEnabledState(false);
   726         changePlayButtonState(StopDisabled);
       
   727         changeChannelButtonsEnabledState(false);
       
   728         changeInformationAreaLayout(Animation);
   770         changeInformationAreaLayout(Animation);
   729         break;
   771         break;
   730     case AntennaNotConnected:
   772     case AntennaNotConnected:
       
   773         LEVEL2(LOG("AntennaNotConnected"));
   731         mFmRadioState = AntennaNotConnected;
   774         mFmRadioState = AntennaNotConnected;
   732         //changeControlButtonState(AllDisabledPlay);
   775         changeStationButtonsEnabledState(false);
   733         changePlayButtonState(StopDisabled);
       
   734         changeChannelButtonsEnabledState(false);
       
   735         mInformationFirstRowLabel->setPlainText("");
   776         mInformationFirstRowLabel->setPlainText("");
   736         mInformationSecondRowLabel->setPlainText("");
   777         mInformationSecondRowLabel->setPlainText("");
   737         mInformationLonelyRowLabel->setPlainText(KConnectHeadsetText);
   778         mInformationLonelyRowLabel->setPlainText(hbTrId("txt_rad_info_connect_wired_headset"));
   738         changeInformationAreaLayout(OneRow);
   779         changeInformationAreaLayout(OneRow);
   739         break;
   780         break;
       
   781     case Closing:
       
   782         LEVEL2(LOG("Closing"));
       
   783         mFmRadioState = Closing;
       
   784         changePowerButtonOn(false);
       
   785         changeStationButtonsEnabledState(false);
       
   786         clearRadioInformation();
       
   787         mInformationFirstRowLabel->setPlainText("");
       
   788         mInformationSecondRowLabel->setPlainText("");
       
   789         mInformationLonelyRowLabel->setPlainText(hbTrId("txt_rad_list_fm_radio"));
       
   790         changeInformationAreaLayout(OneRow);
       
   791         break;
   740     default:
   792     default:
   741         break;
   793         LOG("default");
   742     }
   794         break;
   743 }
   795     }
   744 
   796 }
   745 /*!
   797 
   746  Changes visible layout of information area.
   798 /*!
   747  
   799  Changes visible widgets of information area stacked layout.
       
   800 
   748  /param InformationAreaLayout The layout to switch visible.
   801  /param InformationAreaLayout The layout to switch visible.
   749  */
   802  */
   750 void FmRadioHsWidget::changeInformationAreaLayout(InformationAreaLayout layout)
   803 void FmRadioHsWidget::changeInformationAreaLayout(const InformationAreaLayout layout)
   751 {
   804 {
       
   805     LOG_METHOD;
   752     switch (layout) {
   806     switch (layout) {
   753     case OneRow:
   807     case OneRow:
   754         mInformationAreaOneRowLayout->show();
   808         LEVEL2(LOG("OneRow"));
   755         ((QGraphicsWidget*) mInformationAreaTwoRowsLayout)->hide();
   809         mInformationLonelyRowLabel->show();
   756         mInformationAreaAnimationLayout->hide();
   810         mInformationAreaTwoRowsLayout->hide();
       
   811         mAnimationIcon->hide();
   757         break;
   812         break;
   758     case TwoRows:
   813     case TwoRows:
   759         mInformationAreaOneRowLayout->hide();
   814         LEVEL2(LOG("TwoRows"));
   760         ((QGraphicsWidget*) mInformationAreaTwoRowsLayout)->show();
   815         mInformationLonelyRowLabel->hide();
   761         mInformationAreaAnimationLayout->hide();
   816         mInformationAreaTwoRowsLayout->show();
       
   817         mAnimationIcon->hide();
   762         break;
   818         break;
   763     case Animation:
   819     case Animation:
   764         mInformationAreaOneRowLayout->hide();
   820         LEVEL2(LOG("Animation"));
   765         ((QGraphicsWidget*) mInformationAreaTwoRowsLayout)->hide();
   821         mInformationLonelyRowLabel->hide();
   766         mInformationAreaAnimationLayout->show();
   822         mInformationAreaTwoRowsLayout->hide();
       
   823         mAnimationIcon->show();
   767         break;
   824         break;
   768     default:
   825     default:
   769         break;
   826         LOG("default");
   770     }
   827         break;
   771 }
   828     }
   772 
   829 }
   773 /*!
   830 
   774  Changes state of the control buttons.
   831 /*!
   775  
   832  Changes state of power button.
   776  /param ControlButtonState State of the control buttons.
   833 
   777  */
   834  */
   778 void FmRadioHsWidget::changeControlButtonState(ControlButtonState buttonState)
   835 void FmRadioHsWidget::changePowerButtonOn(const bool isPowerOn)
   779 {
   836 {
       
   837     LOG_METHOD;
   780     QString iconName;
   838     QString iconName;
   781     switch (buttonState) {
   839     if (isPowerOn) {
   782     case AllDisabledPlay:
   840         LEVEL2(LOG("Power on"));
   783         changeControlButtonFrameBackground(false, Left, mPreviousPushButton);
   841         // Change icon to reflect power on state.
   784         iconName.append("qtg_mono_play");
   842         iconName.append("qtg_mono_power");
   785         mPlayPushButton->setIcon(HbIcon(iconName));
   843         mPowerToggleButton->setIcon(HbIcon(":/ui/resource/mono_power.png"));
   786         changeControlButtonFrameBackground(false, Center, mPlayPushButton);
   844         mPowerToggleButton->setText("Off");
   787         changeControlButtonFrameBackground(false, Right, mNextPushButton);
   845         // Connect clicked to closeRadio slot.
   788         break;
   846         disconnect(mPowerToggleButton, SIGNAL(clicked()), this,
   789     case AllDisabledStop:
       
   790         changeControlButtonFrameBackground(false, Left, mPreviousPushButton);
       
   791         iconName.append("qtg_mono_stop");
       
   792         mPlayPushButton->setIcon(HbIcon(iconName));
       
   793         changeControlButtonFrameBackground(false, Center, mPlayPushButton);
       
   794         changeControlButtonFrameBackground(false, Right, mNextPushButton);
       
   795         break;
       
   796     case ChannelsDisabledPlay:
       
   797         changeControlButtonFrameBackground(false, Left, mPreviousPushButton);
       
   798         QObject::disconnect(mPlayPushButton, SIGNAL(clicked()), this,
       
   799             SLOT(unMute()));
       
   800         QObject::disconnect(mPlayPushButton, SIGNAL(clicked()), this,
       
   801             SLOT(mute()));
       
   802         QObject::connect(mPlayPushButton, SIGNAL(clicked()), this,
       
   803             SLOT(radioToBackground()));
   847             SLOT(radioToBackground()));
   804         iconName.append("qtg_mono_play");
   848         connect(mPowerToggleButton, SIGNAL(clicked()), this,
   805         mPlayPushButton->setIcon(HbIcon(iconName));
   849             SLOT(closeRadio()));
   806         changeControlButtonFrameBackground(true, Center, mPlayPushButton);
   850     } else {
   807         changeControlButtonFrameBackground(false, Right, mNextPushButton);
   851         LEVEL2(LOG("Power off"));
   808         break;
   852         // Change icon to reflect power off state.
   809     case ChannelsDisabledStop:
   853         iconName.append("qtg_mono_power");
   810         changeControlButtonFrameBackground(false, Left, mPreviousPushButton);
   854         mPowerToggleButton->setIcon(HbIcon(":/ui/resource/mono_power.png"));
   811         iconName.append("qtg_mono_stop");
   855         mPowerToggleButton->setText("On");
   812         mPlayPushButton->setIcon(HbIcon(iconName));
   856         // Connect clicked to radioToBackground slot.
   813         changeControlButtonFrameBackground(true, Center, mPlayPushButton);
   857         disconnect(mPowerToggleButton, SIGNAL(clicked()), this,
   814         changeControlButtonFrameBackground(false, Right, mNextPushButton);
   858             SLOT(closeRadio()));
   815         break;
   859         connect(mPowerToggleButton, SIGNAL(clicked()), this,
   816     case ChannelsEnabledPlay:
       
   817         changeControlButtonFrameBackground(true, Left, mPreviousPushButton);
       
   818         QObject::disconnect(mPlayPushButton, SIGNAL(clicked()), this,
       
   819             SLOT(radioToBackground()));
   860             SLOT(radioToBackground()));
   820         QObject::disconnect(mPlayPushButton, SIGNAL(clicked()), this,
   861     }
   821             SLOT(mute()));
   862     changeControlButtonFrameBackground(true, Left, mPowerToggleButton);
   822         QObject::connect(mPlayPushButton, SIGNAL(clicked()), this,
   863 }
   823             SLOT(unMute()));
   864 
   824         iconName.append("qtg_mono_play");
   865 /*!
   825         mPlayPushButton->setIcon(HbIcon(iconName));
   866  Changes enabled state of station buttons.
   826         changeControlButtonFrameBackground(true, Center, mPlayPushButton);
   867 
   827         changeControlButtonFrameBackground(true, Right, mNextPushButton);
   868  */
   828         break;
   869 void FmRadioHsWidget::changeStationButtonsEnabledState(const bool enabled)
   829     case ChannelsEnabledStop:
   870 {
   830         changeControlButtonFrameBackground(true, Left, mPreviousPushButton);
   871     LOG_METHOD_ENTER;
   831         QObject::disconnect(mPlayPushButton, SIGNAL(clicked()), this,
   872     changeControlButtonFrameBackground(enabled, Center, mPreviousPushButton);
   832             SLOT(radioToBackground()));
       
   833         QObject::disconnect(mPlayPushButton, SIGNAL(clicked()), this,
       
   834             SLOT(unMute()));
       
   835         QObject::connect(mPlayPushButton, SIGNAL(clicked()), this,
       
   836             SLOT(mute()));
       
   837         iconName.append("qtg_mono_stop");
       
   838         mPlayPushButton->setIcon(HbIcon(iconName));
       
   839         changeControlButtonFrameBackground(true, Center, mPlayPushButton);
       
   840         changeControlButtonFrameBackground(true, Right, mNextPushButton);
       
   841         break;
       
   842     default:
       
   843         break;
       
   844     }
       
   845 }
       
   846 
       
   847 /*!
       
   848  Changes enabled state of channel buttons.
       
   849  
       
   850  */
       
   851 void FmRadioHsWidget::changePlayButtonState(PlayButtonState buttonState)
       
   852 {
       
   853     QString iconName;
       
   854     bool enabled = false;
       
   855     switch (buttonState) {
       
   856     case PlayDisabled:
       
   857         iconName.append("qtg_mono_play");
       
   858         mPlayPushButton->setIcon(HbIcon(iconName));
       
   859         enabled = false;
       
   860         break;
       
   861     case PlayEnabled:
       
   862         iconName.append("qtg_mono_play");
       
   863         mPlayPushButton->setIcon(HbIcon(iconName));
       
   864         enabled = true;
       
   865         break;
       
   866     case StopDisabled:
       
   867         iconName.append("qtg_mono_stop");
       
   868         mPlayPushButton->setIcon(HbIcon(iconName));
       
   869         enabled = false;
       
   870         break;
       
   871     case StopEnabled:
       
   872         iconName.append("qtg_mono_stop");
       
   873         mPlayPushButton->setIcon(HbIcon(iconName));
       
   874         enabled = true;
       
   875         break;
       
   876     default:
       
   877         break;
       
   878     }
       
   879     changeControlButtonFrameBackground(enabled, Center, mPlayPushButton);
       
   880 }
       
   881 
       
   882 /*!
       
   883  Changes enabled state of channel buttons.
       
   884  
       
   885  */
       
   886 void FmRadioHsWidget::changeChannelButtonsEnabledState(bool enabled)
       
   887 {
       
   888     changeControlButtonFrameBackground(enabled, Left, mPreviousPushButton);
       
   889     changeControlButtonFrameBackground(enabled, Right, mNextPushButton);
   873     changeControlButtonFrameBackground(enabled, Right, mNextPushButton);
   890 }
   874 }
   891 
   875 
   892 /*!
   876 /*!
   893  Changes background of control button.
   877  Changes background of control button.
   894  
   878 
   895  /param enabled Is button enabled or disabled.
   879  /param enabled Is button enabled or disabled.
   896  /param position Position of the control button in button group.
   880  /param position Position of the control button in button group.
   897  /param button The button to change the background.
   881  /param button The button to change the background.
   898  */
   882  */
   899 void FmRadioHsWidget::changeControlButtonFrameBackground(bool enabled,
   883 void FmRadioHsWidget::changeControlButtonFrameBackground(const bool enabled,
   900     ControlButtonPosition position, HbPushButton *button)
   884     const ControlButtonPosition position, HbPushButton *button)
   901 {
   885 {
       
   886     LOG_METHOD_ENTER;
   902     QString frameGraphicsName("qtg_fr_hsbutton_");
   887     QString frameGraphicsName("qtg_fr_hsbutton_");
   903     if (enabled) {
   888     if (enabled) {
   904         frameGraphicsName.append("normal");
   889         frameGraphicsName.append("normal");
   905     } else {
   890     } else {
   906         frameGraphicsName.append("disabled");
   891         frameGraphicsName.append("disabled");
   907     }
   892     }
       
   893     LEVEL2(LOG_FORMAT("frameGraphicsName: %s", GETSTRING(frameGraphicsName)));
   908     HbFrameDrawer *frameDrawer = new HbFrameDrawer(frameGraphicsName,
   894     HbFrameDrawer *frameDrawer = new HbFrameDrawer(frameGraphicsName,
   909         HbFrameDrawer::ThreePiecesHorizontal);
   895         HbFrameDrawer::ThreePiecesHorizontal);
   910     switch (position) {
   896     switch (position) {
   911     case Left:
   897     case Left:
       
   898         LEVEL2(LOG("Left"));
   912         frameDrawer->setFileNameSuffixList(QStringList() << "_l" << "_c" << "_cr");
   899         frameDrawer->setFileNameSuffixList(QStringList() << "_l" << "_c" << "_cr");
   913         break;
   900         break;
   914     case Center:
   901     case Center:
       
   902         LEVEL2(LOG("Center"));
   915         frameDrawer->setFileNameSuffixList(QStringList() << "_cl" << "_c" << "_cr");
   903         frameDrawer->setFileNameSuffixList(QStringList() << "_cl" << "_c" << "_cr");
   916         break;
   904         break;
   917     case Right:
   905     case Right:
       
   906         LEVEL2(LOG("Right"));
   918         frameDrawer->setFileNameSuffixList(QStringList() << "_cl" << "_c" << "_r");
   907         frameDrawer->setFileNameSuffixList(QStringList() << "_cl" << "_c" << "_r");
   919         break;
   908         break;
   920     default:
   909     default:
       
   910         LOG("default");
   921         break;
   911         break;
   922     }
   912     }
   923     button->setFrameBackground(frameDrawer);
   913     button->setFrameBackground(frameDrawer);
   924     button->setEnabled(enabled);
   914     button->setEnabled(enabled);
   925 }
   915 }
       
   916 
       
   917 /*!
       
   918  Radio did not start on time. Let's reset the widget's state.
       
   919 
       
   920  */
       
   921 void FmRadioHsWidget::cancelRadioStartingState()
       
   922 {
       
   923     LOG_SLOT_CALLER;
       
   924     handleRadioStateChange(QVariant(NotRunning));
       
   925 }
       
   926 
       
   927 /*!
       
   928  Stop the timer canceling radio starting state.
       
   929 
       
   930  */
       
   931 void FmRadioHsWidget::stopRadioStartingCancelTimer()
       
   932 {
       
   933     LOG_METHOD_ENTER;
       
   934     if (mRadioStartingCancelTimer->isActive()) {
       
   935          mRadioStartingCancelTimer->stop();
       
   936      }
       
   937 }