hswidgetplugin/fmradiohswidgetplugin/src/fmradiohswidget.cpp
branchGCC_SURGE
changeset 37 451b2e1545b2
parent 26 6bcf277166c1
parent 33 11b6825f0862
equal deleted inserted replaced
26:6bcf277166c1 37:451b2e1545b2
     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 <HbMarqueeItem>
       
    29 #include <HbStyleLoader>
       
    30 #include <QGraphicsLinearLayout>
       
    31 #include <QGraphicsItem>
       
    32 #include <QDesktopServices>
       
    33 
       
    34 // User includes
       
    35 #include "fmradiohswidget.h"
       
    36 #include "fmradiohswidgetprocesshandler.h"
       
    37 #include "fmradiohswidgetprofilereader.h"
       
    38 #include "fmradiohswidgetradioserviceclient.h"
       
    39 #include "radioservicedef.h"
       
    40 #include "radio_global.h"
       
    41 
       
    42 /*!
       
    43     \ingroup group_fmradiohs_widget
       
    44     \class FmRadioHsWidget
       
    45     \brief Example implementation for home screen widget.
       
    46 
       
    47     FmRadioHsWidget derived from the HbWidget and implements 
       
    48     needed functions for the home screen widget. 
       
    49 */
       
    50 
       
    51 // ======== MEMBER FUNCTIONS ========
       
    52 
       
    53 /*!
       
    54     Constructs a widget which is a child of \a parent, with widget flags set to \a flags.
       
    55 */
       
    56 FmRadioHsWidget::FmRadioHsWidget(QGraphicsItem* parent, Qt::WindowFlags flags)
       
    57     : HbWidget(parent, flags),
       
    58       mRadioPushButton(0),
       
    59       mPreviousPushButton(0),
       
    60       mPlayPushButton(0),
       
    61       mNextPushButton(0),
       
    62       mInformationFirstRowLabel(0),
       
    63       mInformationSecondRowLabel(0),
       
    64       mFmRadioState(Undefined),
       
    65       mPlayButtonState(PlayEnabled),
       
    66       mIsFavoriteChannels(false),
       
    67       mRadioInformation(QHash<QString, QString>()),
       
    68       mProcessHandler(0),
       
    69       mProfileMonitor(new FmRadioHsWidgetProfileReader(this)),
       
    70       mRadioServiceClient(new FmRadioHsWidgetRadioServiceClient(this))
       
    71 {
       
    72     connect(mRadioServiceClient, SIGNAL(radioInformationChanged(int, QVariant)), this,
       
    73         SLOT(handleRadioInformationChange(int, QVariant)));
       
    74     connect(mRadioServiceClient, SIGNAL(radioStateChanged(QVariant)), this,
       
    75         SLOT(handleRadioStateChange(QVariant)));
       
    76     connect(mProfileMonitor, SIGNAL(radioRunning(QVariant)), this,
       
    77         SLOT(handleRadioStateChange(QVariant)));
       
    78     
       
    79     load(KDocml);
       
    80     
       
    81     handleRadioStateChange(mProfileMonitor->radioStatus());
       
    82 
       
    83     //mRadioServiceClient->init();
       
    84 }
       
    85 
       
    86 /*!
       
    87     Destructor
       
    88 */
       
    89 FmRadioHsWidget::~FmRadioHsWidget()
       
    90 {
       
    91 }
       
    92 
       
    93 /*!
       
    94     Called when widget is shown in the home screen
       
    95 */
       
    96 void FmRadioHsWidget::onShow()
       
    97 {
       
    98 }
       
    99 
       
   100 /*!
       
   101     Called when widget is hidden from the home screen
       
   102 */
       
   103 void FmRadioHsWidget::onHide()
       
   104 {
       
   105 }
       
   106 
       
   107 /*!
       
   108     Loads docml files.
       
   109 */
       
   110 void FmRadioHsWidget::load(const QString docml)
       
   111 {
       
   112     bool loaded = false;
       
   113 
       
   114     HbDocumentLoader *documentLoader = new HbDocumentLoader();
       
   115     documentLoader->reset();
       
   116     documentLoader->load(docml, &loaded);
       
   117 
       
   118     if (loaded) {
       
   119         HbWidget *widget = qobject_cast<HbWidget*> (documentLoader->findWidget(
       
   120             KDocmlObjectNameMainLayout));
       
   121 
       
   122         HbFrameItem *frameItem = NULL;
       
   123 
       
   124         if (widget) {
       
   125             //HbWidget *view = qobject_cast<HbWidget*> (widget);
       
   126             QGraphicsLinearLayout *mWidgetLayout = new QGraphicsLinearLayout(Qt::Vertical, this);
       
   127 
       
   128             HbFrameDrawer *drawer = new HbFrameDrawer("qtg_fr_hswidget_normal",
       
   129                 HbFrameDrawer::NinePieces);
       
   130             frameItem = new HbFrameItem(drawer, widget);
       
   131             frameItem->setPreferredSize(widget->preferredSize());
       
   132 
       
   133             mWidgetLayout->addItem(widget);
       
   134             setLayout(mWidgetLayout);
       
   135         }
       
   136 
       
   137         mRadioPushButton = qobject_cast<HbPushButton*> (documentLoader->findWidget(
       
   138             KDocmlObjectNameRadioIconPushButton));
       
   139         if (mRadioPushButton) {
       
   140             if (frameItem) {
       
   141                 frameItem->stackBefore(mRadioPushButton);
       
   142             }
       
   143             mRadioPushButton->setBackground(HbIcon("qtg_large_radio"));
       
   144             mRadioPushButton->icon().setSize(mRadioPushButton->preferredSize());
       
   145             QObject::connect(mRadioPushButton, SIGNAL(clicked()), this, SLOT(radioToForeground()));
       
   146         }
       
   147 
       
   148         mVerticalSeparatorLabel = qobject_cast<HbLabel*> (documentLoader->findWidget(
       
   149             KDocmlObjectNameVerticalSeparatorLabel));
       
   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;
       
   303 }
       
   304 
       
   305 /*!
       
   306  Slot for grouping events.
       
   307  */
       
   308 bool FmRadioHsWidget::eventFilter(QObject */*target*/, QEvent */*event*/)
       
   309  {
       
   310 // This event filter is used to get events from information area layout and from it's components.
       
   311 // Not yet implemented.   
       
   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 }
       
   355 
       
   356 /*!
       
   357  Slot for previous button clicked.
       
   358  */
       
   359 void FmRadioHsWidget::previousChannel()
       
   360 {
       
   361     mRadioServiceClient->doChangeFmRadioChannel(FmRadioHsWidgetRadioServiceClient::PreviousFavouriteChannel);
       
   362 }
       
   363 
       
   364 /*!
       
   365  Slot for next button clicked.
       
   366  */
       
   367 void FmRadioHsWidget::nextChannel()
       
   368 {
       
   369     mRadioServiceClient->doChangeFmRadioChannel(FmRadioHsWidgetRadioServiceClient::NextFavouriteChannel);
       
   370 }
       
   371 
       
   372 /*!
       
   373  Slot for radio button clicked.
       
   374  */
       
   375 void FmRadioHsWidget::radioToForeground()
       
   376 {
       
   377     if (mFmRadioState == NotRunning) {
       
   378         handleRadioStateChange(QVariant(Starting));
       
   379         mRadioServiceClient->startMonitoring(FmRadioHsWidgetRadioServiceClient::ToForeground);
       
   380     }
       
   381     else {
       
   382         mRadioServiceClient->doChangeFmRadioVisibility(
       
   383             FmRadioHsWidgetRadioServiceClient::ToForeground);
       
   384     }
       
   385 }
       
   386 
       
   387 /*!
       
   388  Slot for radio button clicked.
       
   389  */
       
   390 void FmRadioHsWidget::radioToBackground()
       
   391 {
       
   392     if (mFmRadioState == NotRunning) {
       
   393         handleRadioStateChange(QVariant(Starting));
       
   394         mRadioServiceClient->startMonitoring(FmRadioHsWidgetRadioServiceClient::ToBackground);
       
   395     }
       
   396     else if (mFmRadioState == Starting) {
       
   397         
       
   398     }
       
   399     else {
       
   400         mRadioServiceClient->doChangeFmRadioVisibility(
       
   401             FmRadioHsWidgetRadioServiceClient::ToBackground);
       
   402     }
       
   403 }
       
   404 
       
   405 /*!
       
   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.
       
   417  
       
   418  /param type Type of changed information.
       
   419  /param value Information content.
       
   420  */
       
   421 void FmRadioHsWidget::handleRadioInformationChange(
       
   422     int notificationId, QVariant value)
       
   423 {
       
   424     if (!value.isValid()) {
       
   425         return;
       
   426     }
       
   427     switch ( notificationId ) {
       
   428 
       
   429         case RadioServiceNotification::FavoriteCount:
       
   430             if (value.canConvert(QVariant::Int)) {
       
   431                 int favoriteCount = value.toInt();
       
   432                 mIsFavoriteChannels = favoriteCount > 0 ? true : false;
       
   433                 changeChannelButtonsEnabledState(mIsFavoriteChannels);
       
   434             }
       
   435             break;
       
   436 
       
   437         case RadioServiceNotification::RadioStatus:
       
   438             if (value.canConvert(QVariant::Int)) {
       
   439                 int status = value.toInt();
       
   440                 switch (status) {
       
   441                 case RadioStatus::Playing:
       
   442                     handleRadioStateChange(QVariant(ControllingAudio));
       
   443                     break;
       
   444                 case RadioStatus::Muted:
       
   445                     handleRadioStateChange(QVariant(NotControllingAudio));
       
   446                     break;
       
   447                 case RadioStatus::Seeking:
       
   448                     handleRadioStateChange(QVariant(Seeking));
       
   449                     break;
       
   450                 case RadioStatus::NoAntenna:
       
   451                     handleRadioStateChange(QVariant(AntennaNotConnected));
       
   452                     break;                    
       
   453                 default:
       
   454                     break;
       
   455                 }
       
   456             }
       
   457             break;
       
   458 
       
   459         case RadioServiceNotification::Frequency:
       
   460             if (value.canConvert(QVariant::UInt)) {
       
   461                 const uint frequency = value.toUInt();
       
   462                 QString freqString;
       
   463                 freqString.sprintf("%.1f", qreal(frequency) / KFrequencyMultiplier);
       
   464                 bool frequencyCleared = false;
       
   465                 if (mRadioInformation.contains(KRadioInformationFrequency)
       
   466                     && mRadioInformation[KRadioInformationFrequency].compare(freqString) != 0) {
       
   467                     clearRadioInformation();
       
   468                     frequencyCleared = true;
       
   469                 }
       
   470                 bool frequencyUpdated = updateRadioInformation(KRadioInformationFrequency, freqString);
       
   471                 if (frequencyCleared || frequencyUpdated) {
       
   472                     radioInformationChanged();
       
   473                 }
       
   474             }
       
   475         break;
       
   476 
       
   477         case RadioServiceNotification::Name:
       
   478             if (value.canConvert(QVariant::String)) {
       
   479                 if (updateRadioInformation(KRadioInformationStationName, value.toString())) {
       
   480                     radioInformationChanged();
       
   481                 }
       
   482             }
       
   483         break;
       
   484 
       
   485         case RadioServiceNotification::Genre:
       
   486             if (value.canConvert(QVariant::String)) {
       
   487                 if (updateRadioInformation(KRadioInformationPty, value.toString())) {
       
   488                     radioInformationChanged();
       
   489                 }
       
   490             }
       
   491         break;
       
   492 
       
   493         case RadioServiceNotification::RadioText:
       
   494             if (value.canConvert(QVariant::String)) {
       
   495                 if (updateRadioInformation(KRadioInformationRt, value.toString())) {
       
   496                     radioInformationChanged();
       
   497                 }
       
   498             }
       
   499         break;
       
   500 
       
   501         case RadioServiceNotification::HomePage:
       
   502             if (value.canConvert(QVariant::String)) {
       
   503                 if (updateRadioInformation(KRadioInformationHomePage, value.toString())) {
       
   504                     radioInformationChanged();
       
   505                 }
       
   506             }
       
   507         break;
       
   508         
       
   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:
       
   533         break;
       
   534     }
       
   535 }
       
   536 
       
   537 /*!
       
   538  Check if the the radio information is changed. If it is changed update it.
       
   539  
       
   540  /param informationType Type of the information. 
       
   541  /param information  Information text.
       
   542  
       
   543  /return bool If information is updated, return true. Return false otherwise.
       
   544  */
       
   545 bool FmRadioHsWidget::updateRadioInformation(const QString informationType, QString information)
       
   546 {
       
   547     // If hash contains this type
       
   548     if (mRadioInformation.contains(informationType)) {
       
   549         // If new information is empty
       
   550         if (information.isEmpty()) {
       
   551             // Remove it from the hash
       
   552             mRadioInformation.remove(informationType);
       
   553             // Return true to indicate the change
       
   554             return true;
       
   555         }
       
   556         // If new information differs from the old one
       
   557         if (mRadioInformation[informationType].compare(information) != 0) {
       
   558             // Update the information
       
   559             mRadioInformation[informationType] = information;
       
   560             // And return true to indicate the change
       
   561             return true;
       
   562         }
       
   563     } else { // Hash do not contain the information
       
   564         // If new information is not empty
       
   565         if (!information.isEmpty()) {
       
   566             // Add it to the hash
       
   567             mRadioInformation[informationType] = information;
       
   568             // Return true to indicate the change
       
   569             return true;
       
   570         }
       
   571     }
       
   572     // Return false to indicate that nothing changed
       
   573     return false;
       
   574 }
       
   575 
       
   576 /*!
       
   577  Formatting radio information texts after change. 
       
   578  */
       
   579 void FmRadioHsWidget::radioInformationChanged()
       
   580 {
       
   581     mRadioInformationFirstRow = "";
       
   582     mRadioInformationSecondRow = "";
       
   583 
       
   584     // Lets formulate the first row, first station name
       
   585     if (mRadioInformation.contains(KRadioInformationStationName)) {
       
   586         mRadioInformationFirstRow.append(mRadioInformation.value(KRadioInformationStationName));
       
   587     }
       
   588     // Second call sign
       
   589     if (mRadioInformation.contains(KRadioInformationCallSign)) {
       
   590         mRadioInformationFirstRow.append(" " + mRadioInformation.value(KRadioInformationCallSign));
       
   591     }
       
   592     // Third frequency
       
   593     if (mRadioInformation.contains(KRadioInformationFrequency)) {
       
   594         mRadioInformationFirstRow.append(" " + mRadioInformation.value(KRadioInformationFrequency)
       
   595             + " " + KMhzText);
       
   596     }
       
   597     // Second row of information contains first rt
       
   598     if (mRadioInformation.contains(KRadioInformationRt)) {
       
   599         mRadioInformationSecondRow.append(mRadioInformation.value(KRadioInformationRt));
       
   600     }
       
   601     // Second is dynamic ps name
       
   602     if (mRadioInformation.contains(KRadioInformationDynamicPsName)) {
       
   603         mRadioInformationSecondRow.append(" " + mRadioInformation.value(
       
   604             KRadioInformationDynamicPsName));
       
   605     }
       
   606     // Third is pty 
       
   607     if (mRadioInformation.contains(KRadioInformationPty)) {
       
   608         mRadioInformationSecondRow.append(" " + mRadioInformation.value(KRadioInformationPty));
       
   609     }
       
   610 
       
   611     if (mRadioInformationSecondRow.isEmpty()) {
       
   612         mInformationLonelyRowLabel->setPlainText(mRadioInformationFirstRow);
       
   613         changeInformationAreaLayout(OneRow);
       
   614     }
       
   615     else {
       
   616         mInformationFirstRowLabel->setPlainText(mRadioInformationFirstRow);
       
   617         mInformationSecondRowLabel->setPlainText(mRadioInformationSecondRow);
       
   618         changeInformationAreaLayout(TwoRows);
       
   619     }
       
   620 }
       
   621 
       
   622 /*!
       
   623  Clears the radio station information. For example, when the channel is
       
   624  changed, old information should be cleared.
       
   625  */
       
   626 void FmRadioHsWidget::clearRadioInformation()
       
   627 {
       
   628     if (!mRadioInformation.isEmpty()) {
       
   629         mRadioInformation.clear();
       
   630     }
       
   631 }
       
   632 
       
   633 /*!
       
   634  Handles changes in FM Radio state.
       
   635  
       
   636  /param value Information content.
       
   637  */
       
   638 void FmRadioHsWidget::handleRadioStateChange(QVariant value)
       
   639 {
       
   640     int state;
       
   641     if (value.canConvert(QVariant::Int)) {
       
   642         state = value.toInt();
       
   643     } else {
       
   644         return;
       
   645     }
       
   646     
       
   647     if (state == mFmRadioState) {
       
   648         // State did not change, so return.
       
   649         return;
       
   650     }
       
   651     
       
   652     switch (state) {
       
   653     case Undefined:
       
   654         // TODO: Some error occured because we do not have the state information. Handle this.
       
   655         mFmRadioState = Undefined;
       
   656         break;
       
   657     case NotRunning:
       
   658         mFmRadioState = NotRunning;
       
   659         mRadioServiceClient->stopMonitoring();
       
   660         //changeControlButtonState(ChannelsDisabledPlay);
       
   661         QObject::disconnect(mPlayPushButton, SIGNAL(clicked()), this,
       
   662             SLOT(unMute()));
       
   663         QObject::disconnect(mPlayPushButton, SIGNAL(clicked()), this,
       
   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("");
       
   671         mInformationSecondRowLabel->setPlainText("");
       
   672         mInformationLonelyRowLabel->setPlainText(KFmRadioText);
       
   673         changeInformationAreaLayout(OneRow);
       
   674         break;
       
   675     case Starting:
       
   676         mFmRadioState = Starting;
       
   677         //changeControlButtonState(ChannelsDisabledStop);
       
   678         changePlayButtonState(StopDisabled);
       
   679         // TODO: What should the stop button do? Should it close the radio?
       
   680         changeChannelButtonsEnabledState(false);
       
   681         changeInformationAreaLayout(Animation);
       
   682         break;
       
   683     case Running:
       
   684         mFmRadioState = Running;
       
   685         mRadioServiceClient->startMonitoring(FmRadioHsWidgetRadioServiceClient::DoNotChange);
       
   686         //changeControlButtonState(ChannelsEnabledStop);
       
   687         QObject::disconnect(mPlayPushButton, SIGNAL(clicked()), this,
       
   688             SLOT(radioToBackground()));
       
   689         QObject::disconnect(mPlayPushButton, SIGNAL(clicked()), this,
       
   690             SLOT(unMute()));
       
   691         QObject::connect(mPlayPushButton, SIGNAL(clicked()), this,
       
   692             SLOT(mute()));
       
   693         changePlayButtonState(StopEnabled);
       
   694         changeChannelButtonsEnabledState(mIsFavoriteChannels);
       
   695         changeInformationAreaLayout(OneRow);
       
   696         break;
       
   697     case ControllingAudio:
       
   698         mFmRadioState = ControllingAudio;
       
   699         //changeControlButtonState(ChannelsEnabledStop);
       
   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();
       
   709         break;
       
   710     case NotControllingAudio:
       
   711         mFmRadioState = NotControllingAudio;
       
   712         //changeControlButtonState(ChannelsEnabledPlay);
       
   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();
       
   722         break;
       
   723     case Seeking:
       
   724         mFmRadioState = Seeking;
       
   725         //changeControlButtonState(AllDisabledStop);
       
   726         changePlayButtonState(StopDisabled);
       
   727         changeChannelButtonsEnabledState(false);
       
   728         changeInformationAreaLayout(Animation);
       
   729         break;
       
   730     case AntennaNotConnected:
       
   731         mFmRadioState = AntennaNotConnected;
       
   732         //changeControlButtonState(AllDisabledPlay);
       
   733         changePlayButtonState(StopDisabled);
       
   734         changeChannelButtonsEnabledState(false);
       
   735         mInformationFirstRowLabel->setPlainText("");
       
   736         mInformationSecondRowLabel->setPlainText("");
       
   737         mInformationLonelyRowLabel->setPlainText(KConnectHeadsetText);
       
   738         changeInformationAreaLayout(OneRow);
       
   739         break;
       
   740     default:
       
   741         break;
       
   742     }
       
   743 }
       
   744 
       
   745 /*!
       
   746  Changes visible layout of information area.
       
   747  
       
   748  /param InformationAreaLayout The layout to switch visible.
       
   749  */
       
   750 void FmRadioHsWidget::changeInformationAreaLayout(InformationAreaLayout layout)
       
   751 {
       
   752     switch (layout) {
       
   753     case OneRow:
       
   754         mInformationAreaOneRowLayout->show();
       
   755         ((QGraphicsWidget*) mInformationAreaTwoRowsLayout)->hide();
       
   756         mInformationAreaAnimationLayout->hide();
       
   757         break;
       
   758     case TwoRows:
       
   759         mInformationAreaOneRowLayout->hide();
       
   760         ((QGraphicsWidget*) mInformationAreaTwoRowsLayout)->show();
       
   761         mInformationAreaAnimationLayout->hide();
       
   762         break;
       
   763     case Animation:
       
   764         mInformationAreaOneRowLayout->hide();
       
   765         ((QGraphicsWidget*) mInformationAreaTwoRowsLayout)->hide();
       
   766         mInformationAreaAnimationLayout->show();
       
   767         break;
       
   768     default:
       
   769         break;
       
   770     }
       
   771 }
       
   772 
       
   773 /*!
       
   774  Changes state of the control buttons.
       
   775  
       
   776  /param ControlButtonState State of the control buttons.
       
   777  */
       
   778 void FmRadioHsWidget::changeControlButtonState(ControlButtonState buttonState)
       
   779 {
       
   780     QString iconName;
       
   781     switch (buttonState) {
       
   782     case AllDisabledPlay:
       
   783         changeControlButtonFrameBackground(false, Left, mPreviousPushButton);
       
   784         iconName.append("qtg_mono_play");
       
   785         mPlayPushButton->setIcon(HbIcon(iconName));
       
   786         changeControlButtonFrameBackground(false, Center, mPlayPushButton);
       
   787         changeControlButtonFrameBackground(false, Right, mNextPushButton);
       
   788         break;
       
   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()));
       
   804         iconName.append("qtg_mono_play");
       
   805         mPlayPushButton->setIcon(HbIcon(iconName));
       
   806         changeControlButtonFrameBackground(true, Center, mPlayPushButton);
       
   807         changeControlButtonFrameBackground(false, Right, mNextPushButton);
       
   808         break;
       
   809     case ChannelsDisabledStop:
       
   810         changeControlButtonFrameBackground(false, Left, mPreviousPushButton);
       
   811         iconName.append("qtg_mono_stop");
       
   812         mPlayPushButton->setIcon(HbIcon(iconName));
       
   813         changeControlButtonFrameBackground(true, Center, mPlayPushButton);
       
   814         changeControlButtonFrameBackground(false, Right, mNextPushButton);
       
   815         break;
       
   816     case ChannelsEnabledPlay:
       
   817         changeControlButtonFrameBackground(true, Left, mPreviousPushButton);
       
   818         QObject::disconnect(mPlayPushButton, SIGNAL(clicked()), this,
       
   819             SLOT(radioToBackground()));
       
   820         QObject::disconnect(mPlayPushButton, SIGNAL(clicked()), this,
       
   821             SLOT(mute()));
       
   822         QObject::connect(mPlayPushButton, SIGNAL(clicked()), this,
       
   823             SLOT(unMute()));
       
   824         iconName.append("qtg_mono_play");
       
   825         mPlayPushButton->setIcon(HbIcon(iconName));
       
   826         changeControlButtonFrameBackground(true, Center, mPlayPushButton);
       
   827         changeControlButtonFrameBackground(true, Right, mNextPushButton);
       
   828         break;
       
   829     case ChannelsEnabledStop:
       
   830         changeControlButtonFrameBackground(true, Left, mPreviousPushButton);
       
   831         QObject::disconnect(mPlayPushButton, SIGNAL(clicked()), this,
       
   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);
       
   890 }
       
   891 
       
   892 /*!
       
   893  Changes background of control button.
       
   894  
       
   895  /param enabled Is button enabled or disabled.
       
   896  /param position Position of the control button in button group.
       
   897  /param button The button to change the background.
       
   898  */
       
   899 void FmRadioHsWidget::changeControlButtonFrameBackground(bool enabled,
       
   900     ControlButtonPosition position, HbPushButton *button)
       
   901 {
       
   902     QString frameGraphicsName("qtg_fr_hsbutton_");
       
   903     if (enabled) {
       
   904         frameGraphicsName.append("normal");
       
   905     } else {
       
   906         frameGraphicsName.append("disabled");
       
   907     }
       
   908     HbFrameDrawer *frameDrawer = new HbFrameDrawer(frameGraphicsName,
       
   909         HbFrameDrawer::ThreePiecesHorizontal);
       
   910     switch (position) {
       
   911     case Left:
       
   912         frameDrawer->setFileNameSuffixList(QStringList() << "_l" << "_c" << "_cr");
       
   913         break;
       
   914     case Center:
       
   915         frameDrawer->setFileNameSuffixList(QStringList() << "_cl" << "_c" << "_cr");
       
   916         break;
       
   917     case Right:
       
   918         frameDrawer->setFileNameSuffixList(QStringList() << "_cl" << "_c" << "_r");
       
   919         break;
       
   920     default:
       
   921         break;
       
   922     }
       
   923     button->setFrameBackground(frameDrawer);
       
   924     button->setEnabled(enabled);
       
   925 }