qtinternetradio/ui/src/irnowplayingview.cpp
changeset 0 09774dfdd46b
child 3 ee64f059b8e1
equal deleted inserted replaced
-1:000000000000 0:09774dfdd46b
       
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 *
       
    16 */
       
    17 #include <QPixmap>
       
    18 #include <QTimer>
       
    19 #include <hbmenu.h>
       
    20 #include <hbtoolbar.h>
       
    21 #include <hbaction.h>
       
    22 
       
    23 #include "irabstractviewmanager.h"
       
    24 #include "irapplication.h"
       
    25 #include "irplaycontroller.h"
       
    26 #include "irnowplayingview.h"
       
    27 #include "irnowplayingcontainer.h"
       
    28 #include "irstationdetailscontainer.h"
       
    29 #include "irqisdsdatastructure.h"
       
    30 #include "irqmetadata.h"
       
    31 #include "irqutility.h"
       
    32 #include "irqisdsclient.h"
       
    33 #include "irqfavoritesdb.h"
       
    34 #include "irlastplayedstationinfo.h"
       
    35 #include "irqnetworkcontroller.h" 
       
    36 #include "irqmusicshop.h"
       
    37 #include "irqstatisticsreporter.h"
       
    38 #include "irqenums.h"
       
    39 #include "irmediakeyobserver.h"
       
    40 #include "irqsettings.h"
       
    41 #include "irqstationexporter.h"
       
    42 #include "iruidefines.h"
       
    43 
       
    44 // Const
       
    45 const int KNowPlayingLogoSize = 300; // Now playing logo size
       
    46 const char* NOW_PLAYING_VIEW_OBJECT_NAME = "ex-IRNowPlayingView"; // object name in the XML
       
    47 const char* KDefaultAdvertisementLink = ""; // default advertisement link
       
    48 
       
    49 //                                     public functions
       
    50 
       
    51 /*
       
    52  * Description : constructor
       
    53  */
       
    54 IRNowPlayingView::IRNowPlayingView(IRApplication* aApplication, TIRViewId aViewId) :
       
    55     IRBaseView(aApplication, aViewId),
       
    56     iLogoPreset(NULL),
       
    57     iStationDetailsContainer(NULL),
       
    58     iIdleContainer(NULL),
       
    59     iMusicShop(NULL),
       
    60     iStationExporter(NULL),
       
    61     iStereoAction(NULL),
       
    62     iMusicShopAction(NULL),
       
    63     iPlayStopAction(NULL),
       
    64     iAdd2FavAction(NULL),
       
    65     iAdvClickThroughUrl(KDefaultAdvertisementLink),
       
    66     iGettingAdv(false),
       
    67     iStationLogo(NULL),
       
    68     iStereoMode(0),
       
    69     iShowStationInfo(FALSE),
       
    70     iLogoStatus(EDefaultLogo),
       
    71     iFindinNmsAllowed(false),
       
    72     iSongNameAvailable(false)
       
    73 {
       
    74     // Create widget hierarchy
       
    75     setObjectName(NOW_PLAYING_VIEW_OBJECT_NAME);
       
    76 
       
    77     // List existing root elements - this allows us to refer to objects in the XML 
       
    78     // which are created outside the document.
       
    79     QObjectList roots;
       
    80     roots.append(this); // IRNowPlayingView is referred in XML file
       
    81     iLoader.setObjectTree(roots);
       
    82 
       
    83     // Load XML file
       
    84     iLoader.load(NOW_PLAYING_VIEW_LAYOUT_FILENAME);
       
    85 
       
    86     createMenu();
       
    87     createToolBar();
       
    88     initialize();
       
    89 
       
    90     connect(iPlayController, SIGNAL(metaDataAvailable(IRQMetaData*)), this, SLOT(updateSongInfo(IRQMetaData*)));
       
    91     connect(iPlayController, SIGNAL(initializeLogo()), this, SLOT(initializeLogo()));
       
    92     connect(iPlayController, SIGNAL(playingStarted()), this, SLOT(playingStarted()));
       
    93     connect(iPlayController, SIGNAL(playingStopped()), this, SLOT(playingStopped()));
       
    94 
       
    95     connect(iNetworkController, SIGNAL(networkRequestNotified(IRQNetworkEvent)),
       
    96             this, SLOT(networkRequestNotified(IRQNetworkEvent)));
       
    97     connect(iApplication->getMediaKeyObserver(), SIGNAL(playPausePressed()), 
       
    98             this, SLOT(playPressed()));
       
    99     connect(iApplication->getMediaKeyObserver(), SIGNAL(stopPressed()), 
       
   100             this, SLOT(stop()));
       
   101 
       
   102     // Initialize logo
       
   103     QIcon icon(":/playback/default_cd.png");
       
   104     iStationLogo = new HbIcon(icon);
       
   105 
       
   106     // Initialize advertisement image
       
   107     QIcon advIcon(":/playback/default_cd.jpg");
       
   108     HbIcon advInitialImage(advIcon);
       
   109     iStationExporter = new IRQStationExporter();
       
   110     iNowPlayingContainer = new IRNowPlayingContainer(getViewManager());
       
   111     connect(getViewManager(), SIGNAL(orientationChanged(Qt::Orientation)), 
       
   112             iNowPlayingContainer, SLOT(orientationChanged(Qt::Orientation)));
       
   113     connect(iNowPlayingContainer, SIGNAL(volumePressed()), 
       
   114             iApplication->getMediaKeyObserver(), SLOT(showVolumeSlider()));
       
   115     connect(iNowPlayingContainer, SIGNAL(advertisementPressed()), 
       
   116                 this, SLOT(openAdvLink()));
       
   117     setWidget(iNowPlayingContainer);
       
   118     iNowPlayingContainer->setLogo(*iStationLogo);
       
   119     iNowPlayingContainer->setAdvImage(advInitialImage);
       
   120 
       
   121     HbEffect::add("nowplaying", ":/effect/view_flip_hide.fxml", "hide");
       
   122     HbEffect::add("nowplaying", ":/effect/view_flip_show.fxml", "show");
       
   123 }
       
   124 
       
   125 /*
       
   126  * Description : destructor
       
   127  */
       
   128 IRNowPlayingView::~IRNowPlayingView()
       
   129 {
       
   130     delete iIdleContainer;
       
   131     iIdleContainer = NULL;
       
   132 
       
   133     delete iStationExporter;
       
   134     iStationExporter = NULL;
       
   135 
       
   136     iNowPlayingContainer = NULL;
       
   137     iStationDetailsContainer = NULL;
       
   138 
       
   139     delete iLogoPreset;
       
   140     iLogoPreset = NULL;
       
   141 
       
   142     delete iStationLogo;
       
   143     iStationLogo = NULL;
       
   144     
       
   145     HbEffect::remove("nowplaying", ":/playback/view_flip_hide.fxml", "hide");
       
   146     HbEffect::remove("nowplaying", ":/playback/view_flip_show.fxml", "show");
       
   147 }
       
   148 
       
   149 /*
       
   150  * Description : from base class IRBaseView.
       
   151  *               handle system events reported by system event collector
       
   152  * Parameters  : aEvent : see the definiton of TIRSystemEventType.
       
   153  * Return      : EIR_DoDefault : caller does default handling
       
   154  *               EIR_NoDefault : caller doesn't do default handling
       
   155  */
       
   156 TIRHandleResult IRNowPlayingView::handleSystemEvent(TIRSystemEventType aEvent)
       
   157 {
       
   158     Q_UNUSED(aEvent);
       
   159     return EIR_DoDefault;
       
   160 }
       
   161 
       
   162 /*
       
   163  * Description : from base class IRBaseView.
       
   164  *               handle view commands.
       
   165  * Parameters  : aCommand : see the definition of TIRViewCommand
       
   166  * Return      : EIR_DoDefault : caller does default handling
       
   167  *               EIR_NoDefault : caller doesn't do default handling
       
   168  */
       
   169 TIRHandleResult IRNowPlayingView::handleCommand(TIRViewCommand aCommand, TIRViewCommandReason aReason)
       
   170 {
       
   171     Q_UNUSED(aReason);
       
   172     TIRHandleResult ret = EIR_DoDefault;
       
   173 
       
   174     switch (aCommand)
       
   175     {
       
   176     case EIR_ViewCommand_ACTIVATED:
       
   177         connect(iIsdsClient, SIGNAL(presetLogoDownloaded(IRQPreset* )),
       
   178                 this, SLOT(presetLogoDownload(IRQPreset* )));
       
   179         showWidget();
       
   180         break;
       
   181 
       
   182     case EIR_ViewCommand_DEACTIVATE:
       
   183         if (ERequestIssued == iLogoStatus)
       
   184         {
       
   185             // cancel downloading logo
       
   186             iIsdsClient->isdsLogoDownCancelTransaction();
       
   187             iLogoStatus = EDefaultLogo;
       
   188         }
       
   189         disconnect(iIsdsClient, SIGNAL(presetLogoDownloaded(IRQPreset*)),
       
   190                    this, SLOT(presetLogoDownload(IRQPreset* )));
       
   191         break;
       
   192     }
       
   193 
       
   194     return ret;
       
   195 }
       
   196 
       
   197 /*
       
   198  * Description : actions when view is launched.
       
   199  */
       
   200 void IRNowPlayingView::launchAction()
       
   201 {
       
   202     IRLastPlayedStationInfo *lastPlayedStationInfo =
       
   203             iApplication->getLastPlayedStationInfo();
       
   204     IRQPreset *preset = lastPlayedStationInfo->getLastPlayedStation();
       
   205     if ( preset && (0 == preset->musicStoreStatus.compare("yes",Qt::CaseInsensitive)))
       
   206     {
       
   207         iFindinNmsAllowed = true;        
       
   208     }
       
   209     else
       
   210     {
       
   211         iFindinNmsAllowed = false;
       
   212     }
       
   213           
       
   214     iShowStationInfo = true;
       
   215     setUseNetworkReason(EIR_UseNetwork_StartingView);
       
   216     iApplication->verifyNetworkConnectivity();
       
   217 }
       
   218 
       
   219 /*
       
   220  * Description : start to converter the downloaded logo.
       
   221  */
       
   222 void IRNowPlayingView::presetLogoDownload(IRQPreset* aPreset)
       
   223 {
       
   224     if (NULL == aPreset)
       
   225         return;
       
   226 
       
   227     // Sometimes the logo downloaded by stationview will reach here because
       
   228     // the isdsLogoDownCancelTransaction is delayed. So we judge the imageUrl here.
       
   229     if (!iGettingAdv && (aPreset->imgUrl != iPlayController->getNowPlayingPreset()->imgUrl))
       
   230     {
       
   231         delete aPreset;
       
   232         aPreset = NULL;
       
   233         return;
       
   234     }
       
   235  
       
   236     delete iLogoPreset;
       
   237     iLogoPreset = aPreset;
       
   238     
       
   239     const unsigned char * logoData = iLogoPreset->logoData.Ptr();
       
   240     QPixmap tempMap;
       
   241     bool ret = tempMap.loadFromData(logoData, iLogoPreset->logoData.Length());
       
   242     if( !ret )
       
   243     {
       
   244         if (iGettingAdv)
       
   245         {
       
   246             iGettingAdv = false;
       
   247             QTimer::singleShot(1, this, SLOT(updateLogoInfo()));
       
   248         }
       
   249         else
       
   250         {
       
   251             iLogoStatus = ELogoDetermined;
       
   252         }
       
   253         return;
       
   254     }
       
   255     
       
   256     QIcon convertIcon(tempMap);
       
   257     HbIcon hbIcon(convertIcon);   
       
   258     
       
   259     if (iGettingAdv)
       
   260     {
       
   261         iNowPlayingContainer->setAdvImage(hbIcon);
       
   262         iAdvClickThroughUrl = iTempAdvClickThroughUrl;
       
   263         iGettingAdv = false;
       
   264         QTimer::singleShot(1, this, SLOT(updateLogoInfo()));
       
   265     }
       
   266     else
       
   267     {
       
   268         *iStationLogo = hbIcon;
       
   269 
       
   270         // update the logo
       
   271         iNowPlayingContainer->setLogo(hbIcon);
       
   272         // temp solution, it will be deleted once there's adv info in preset
       
   273         iNowPlayingContainer->setAdvImage(*iStationLogo);
       
   274 
       
   275         if (iStationDetailsContainer)
       
   276         {
       
   277             iStationDetailsContainer->setLogo(hbIcon);
       
   278         }
       
   279         iLogoStatus = ELogoDetermined;
       
   280     } 
       
   281 }
       
   282 
       
   283 /*
       
   284  * Description: slot function for signal triggered() of iPlayStopAction and
       
   285  *              playStopPressed() of irmediakeyobserver.
       
   286  *              According to the playing state, play or stop.
       
   287  */
       
   288 void IRNowPlayingView::playStopControl()
       
   289 {
       
   290     setUseNetworkReason(EIR_UseNetwork_PlayStation);
       
   291     if (false == iApplication->verifyNetworkConnectivity())
       
   292     {
       
   293         return;
       
   294     }
       
   295     setUseNetworkReason(EIR_UseNetwork_NoReason);
       
   296     
       
   297     if (iPlayController->isPlaying())
       
   298     {
       
   299         iPlayController->stop(EIRQUserTerminated);
       
   300     }
       
   301     else
       
   302     {
       
   303         iPlayController->resume();
       
   304     }
       
   305 }
       
   306 
       
   307 /*
       
   308  * Description: slot function for signal stopPressed() of irmediakeyobserver.
       
   309  */
       
   310 void IRNowPlayingView::stop()
       
   311 {
       
   312     iPlayController->stop(EIRQUserTerminated);
       
   313 }
       
   314 
       
   315 /*
       
   316  * Description : update station info and now playing view
       
   317  */
       
   318 void IRNowPlayingView::playingStarted()
       
   319 {
       
   320     if (iShowStationInfo)
       
   321     {
       
   322         updateSongInfo(iPlayController->getMetaData());
       
   323         updateAdvImage();
       
   324         updateStationInfo();
       
   325         iShowStationInfo = false;
       
   326     }
       
   327     updateMusicStatus();
       
   328     HbIcon icon(QString("qtg_mono_stop"));
       
   329     iPlayStopAction->setIcon(icon);
       
   330 }
       
   331 
       
   332 /*
       
   333  * Description : update now playing view
       
   334  */
       
   335 void IRNowPlayingView::playingStopped()
       
   336 {
       
   337     HbIcon icon(QString("qtg_mono_play"));
       
   338     iPlayStopAction->setIcon(icon);
       
   339 }
       
   340 
       
   341 /*
       
   342  * Description: slot function for signal triggered() of iAdd2FavAction.
       
   343  *              add this preset to favorites
       
   344  */
       
   345 void IRNowPlayingView::add2FavControl()
       
   346 {
       
   347     IRQPreset *nowPlayingPreset = iPlayController->getNowPlayingPreset();
       
   348     int retValue = iFavorites->addPreset(*nowPlayingPreset);
       
   349     // show the information from favorites DB
       
   350     switch (retValue)
       
   351     {
       
   352     case EIRQErrorNone:
       
   353         popupNote(hbTrId("txt_irad_info_added_to_favorites"), HbMessageBox::MessageTypeInformation);
       
   354         break;
       
   355 
       
   356     case EIRQErrorOutOfMemory:
       
   357         popupNote(hbTrId("txt_irad_info_can_not_add_more"), HbMessageBox::MessageTypeInformation);
       
   358         break;
       
   359 
       
   360     case EIRQErrorAlreadyExist:
       
   361         popupNote(hbTrId("txt_irad_info_favorite_updated"), HbMessageBox::MessageTypeInformation);
       
   362         break;
       
   363 
       
   364     default:
       
   365         Q_ASSERT(false);
       
   366         break;
       
   367     }
       
   368 }
       
   369 
       
   370 /*
       
   371  * Description: slot function for signal triggered() of flip action.
       
   372  *              change the container of now playing view.
       
   373  */
       
   374 void IRNowPlayingView::flipControl()
       
   375 {
       
   376     // disconnect the signal to avoid users to click several times quickly.
       
   377     iFlipAction->disconnect(SIGNAL(triggered()));
       
   378     if (iIdleContainer == iStationDetailsContainer)
       
   379     {
       
   380         if (NULL == iStationDetailsContainer)
       
   381         {
       
   382             iStationDetailsContainer = new IRStationDetailsContainer(getViewManager());
       
   383         }
       
   384 
       
   385         IRQPreset *nowPlayingPreset = iPlayController->getNowPlayingPreset();
       
   386         iStationDetailsContainer->setDetails(nowPlayingPreset, *iStationLogo);
       
   387 
       
   388         HbEffect::start(iNowPlayingContainer, "nowplaying", QString("hide"), this, "hidePlayingWidgetComplete");
       
   389     }
       
   390     else
       
   391     {
       
   392         HbEffect::start(iStationDetailsContainer, "nowplaying", QString("hide"), this, "hideDetailsWidgetComplete");
       
   393     }
       
   394 }
       
   395 
       
   396 // ---------------------------------------------------------------------------
       
   397 // Slot: Handle animation completion on main widget
       
   398 // ---------------------------------------------------------------------------
       
   399 //
       
   400 void IRNowPlayingView::hidePlayingWidgetComplete(HbEffect::EffectStatus status)
       
   401 {
       
   402     Q_UNUSED(status);
       
   403     iIdleContainer = takeWidget();
       
   404     setWidget(iStationDetailsContainer);
       
   405     iFlipAction->setToolTip(hbTrId("txt_irad_tooltip_tiny_now_playing"));
       
   406     HbEffect::start(iStationDetailsContainer, "nowplaying", QString("show"));
       
   407 
       
   408     // reconnect the signal
       
   409     iFlipAction->disconnect(SIGNAL(triggered()));
       
   410     connect(iFlipAction, SIGNAL(triggered()), this, SLOT(flipControl()));
       
   411 }
       
   412 
       
   413 // ---------------------------------------------------------------------------
       
   414 // Slot: Handle animation completion on list widget
       
   415 // ---------------------------------------------------------------------------
       
   416 //
       
   417 void IRNowPlayingView::hideDetailsWidgetComplete(HbEffect::EffectStatus status)
       
   418 {
       
   419     Q_UNUSED(status);
       
   420     iIdleContainer = takeWidget();
       
   421     setWidget(iNowPlayingContainer);
       
   422     iFlipAction->setToolTip(hbTrId("txt_irad_tooltip_tiny_details"));
       
   423     HbEffect::start(iNowPlayingContainer, "nowplaying", QString("show"));
       
   424 
       
   425     // reconnect the signal
       
   426     iFlipAction->disconnect(SIGNAL(triggered()));
       
   427     connect(iFlipAction, SIGNAL(triggered()), this, SLOT(flipControl()));
       
   428 }
       
   429 
       
   430 /*
       
   431  * Description: slot function for signal triggered() of iStereoAction.
       
   432  *              According to the stereo state.
       
   433  */
       
   434 void IRNowPlayingView::stereoControl()
       
   435 {
       
   436     if (iStereoMode)
       
   437     {
       
   438         iPlayController->disableStereo();
       
   439         iStereoAction->setText(hbTrId("txt_irad_opt_activate_stereo"));
       
   440         iStereoMode = 0;
       
   441     }
       
   442     else
       
   443     {
       
   444         iPlayController->enableStereo();
       
   445         iStereoAction->setText(hbTrId("txt_irad_opt_deactivate_stereo"));
       
   446         iStereoMode = 1;
       
   447     }
       
   448 
       
   449     iApplication->getSettings()->setStereoMode(iStereoMode);
       
   450 }
       
   451 
       
   452 /*
       
   453  * Description: active open web address view
       
   454  */
       
   455 void IRNowPlayingView::openWebAddressControl()
       
   456 {
       
   457     getViewManager()->activateView(EIRView_OpenWebAddressView);
       
   458 }
       
   459 
       
   460 /*
       
   461  * Description: active settings view
       
   462  */
       
   463 void IRNowPlayingView::launchSettingsView()
       
   464 {
       
   465     getViewManager()->activateView(EIRView_SettingsView);
       
   466 }
       
   467 
       
   468 /*
       
   469  * Description : slot function for signal metaDataAvailable(IRQMetaData*) of play controller.
       
   470  *               If metadata is available, update the text
       
   471  */
       
   472 void IRNowPlayingView::updateSongInfo(IRQMetaData* aMetaData)
       
   473 {
       
   474 #ifdef _DEBUG
       
   475     if (iApplication->iTestPreferredBitrate)
       
   476     {
       
   477         IRQPreset *nowPlayingPreset = iPlayController->getNowPlayingPreset();
       
   478         QList<int> bitRateList;
       
   479         bitRateList.clear();
       
   480         nowPlayingPreset->getAvailableBitrates(bitRateList);
       
   481         QString songName;
       
   482         QString bitrate;
       
   483         for(int i=0; i<bitRateList.count(); i++)
       
   484         {
       
   485             songName = songName + bitrate.setNum(bitRateList[i]) + " : ";
       
   486         }
       
   487         songName = songName + " = " + bitrate.setNum(iPlayController->bitrateTrying());
       
   488         iNowPlayingContainer->setSongName(songName);
       
   489         return;
       
   490     }
       
   491 #endif
       
   492     iSongNameAvailable = false;
       
   493     if (aMetaData)
       
   494     {
       
   495         iNowPlayingContainer->setSongName(aMetaData->getArtistSongName());
       
   496         if(!aMetaData->getSongName().isEmpty() ||
       
   497            !aMetaData->getArtistName().isEmpty())
       
   498         {
       
   499             iSongNameAvailable = true;
       
   500         }
       
   501     }
       
   502     else
       
   503     {
       
   504         iNowPlayingContainer->setSongName("");
       
   505     }
       
   506     
       
   507     if(iFindinNmsAllowed && iSongNameAvailable)
       
   508     {
       
   509         iMusicShopAction->setIcon(HbIcon(":/playback/icon_musicshop_enable.png"));
       
   510     }
       
   511     else
       
   512     {
       
   513         iMusicShopAction->setIcon(HbIcon(":/playback/icon_musicshop_disable.png"));
       
   514     }    
       
   515 }
       
   516 
       
   517 // ---------------------------------------------------------------------------
       
   518 // IRNowPlayingView::initializeLogo()
       
   519 // Initialize the logo
       
   520 //---------------------------------------------------------------------------
       
   521 void IRNowPlayingView::initializeLogo()
       
   522 {
       
   523     QIcon icon(":/playback/default_cd.png");
       
   524     HbIcon hbIcon(icon);
       
   525     *iStationLogo = hbIcon;
       
   526     iLogoStatus = EDefaultLogo;
       
   527 
       
   528     // While starting to play a new station, the container should be NowPlayingContainer
       
   529     if (iStationDetailsContainer == widget())
       
   530     {
       
   531         flipControl();
       
   532     }
       
   533 }
       
   534 
       
   535 /*
       
   536  * Description : slot function for active network event
       
   537  * Parameters  : aEvent, see the definition of IRQNetworkEvent
       
   538  */
       
   539 void IRNowPlayingView::networkRequestNotified(IRQNetworkEvent aEvent)
       
   540 {
       
   541     //when we get here, it means that current view is the first view 
       
   542     if (getViewManager()->currentView() != this)
       
   543     {
       
   544         return;
       
   545     }
       
   546     
       
   547     switch (aEvent)
       
   548     {
       
   549     case EIRQNetworkConnectionEstablished:
       
   550         iApplication->closeConnectingDialog();
       
   551         if (EIR_UseNetwork_StartingView == getUseNetworkReason())
       
   552         {
       
   553             IRLastPlayedStationInfo *lastPlayedStationInfo =
       
   554                     iApplication->getLastPlayedStationInfo();
       
   555             IRQPreset *preset = lastPlayedStationInfo->getLastPlayedStation();
       
   556             if (preset)
       
   557             {
       
   558                 iPlayController->connectToChannel(preset,lastPlayedStationInfo->connectedFrom());
       
   559             }
       
   560         }
       
   561         else if (EIR_UseNetwork_PlayStation == getUseNetworkReason())
       
   562         {
       
   563             playStopControl();
       
   564         }
       
   565 
       
   566         setUseNetworkReason(EIR_UseNetwork_NoReason);
       
   567         
       
   568         break;
       
   569         
       
   570     case EIRQConnectingCancelled:
       
   571     case EIRQDisplayNetworkMessageNoConnectivity:
       
   572         {
       
   573             IRQPreset *preset = iPlayController->getNowPlayingPreset();
       
   574             //if IRPlayController::connectToChannel(IRQPreset*) hasn't been called, back to main view.
       
   575             //otherwise stay in nowplaying view.
       
   576             if (NULL == preset || preset->name == "")
       
   577             {
       
   578                 getViewManager()->activateView(EIRView_MainView);
       
   579             }
       
   580         }
       
   581         break;
       
   582         
       
   583     default:
       
   584         break;
       
   585     }
       
   586 }
       
   587 
       
   588 //                                       private functions
       
   589 
       
   590 /*
       
   591  * Description : create menu for now playing view
       
   592  */
       
   593 void IRNowPlayingView::createMenu()
       
   594 {
       
   595     iStereoAction = qobject_cast<HbAction *> (iLoader.findObject("activateStereo"));
       
   596     iStereoMode = iApplication->getSettings()->getStereoMode();
       
   597     if (iStereoMode == 1)
       
   598     {
       
   599         iStereoAction->setText(hbTrId("txt_irad_opt_deactivate_stereo"));
       
   600     }
       
   601     HbAction *openWebAddressAction = qobject_cast<HbAction *> (iLoader.findObject("openWebAddressAction"));
       
   602     HbAction *shareStationAction = qobject_cast<HbAction *> (iLoader.findObject("shareStationAction"));
       
   603     HbAction *songRecAction = qobject_cast<HbAction *> (iLoader.findObject("songRecAction"));
       
   604     HbAction *gotoMusicStoreAction = qobject_cast<HbAction *> (iLoader.findObject("gotoMusicStoreAction"));
       
   605     HbAction *settings = qobject_cast<HbAction *> (iLoader.findObject("settings"));
       
   606     HbAction *helpAction = qobject_cast<HbAction *> (iLoader.findObject("help"));
       
   607     HbAction *exitAction = qobject_cast<HbAction *> (iLoader.findObject("exit"));
       
   608 
       
   609     connect(iStereoAction, SIGNAL(triggered()), this, SLOT(stereoControl()));
       
   610     connect(openWebAddressAction, SIGNAL(triggered()), this, SLOT(openWebAddressControl()));
       
   611     connect(shareStationAction, SIGNAL(triggered()), this, SLOT(shareStationViaMms()));
       
   612     connect(songRecAction, SIGNAL(triggered()), this, SLOT(recognizeSong()));
       
   613     connect(gotoMusicStoreAction, SIGNAL(triggered()), this, SLOT(gotoMusicStore()));
       
   614     connect(settings, SIGNAL(triggered()), this, SLOT(launchSettingsView()));
       
   615     connect(helpAction, SIGNAL(triggered()), this, SLOT(helpAction()));
       
   616     connect(exitAction, SIGNAL(triggered()), iApplication, SIGNAL(quit()));
       
   617 
       
   618     HbMenu *viewMenu = menu();
       
   619     connect(viewMenu, SIGNAL(aboutToShow()), this, SLOT(prepareMenu()));    
       
   620 }
       
   621 
       
   622 /*
       
   623  * Description : create tool bar for now playing view
       
   624  */
       
   625 void IRNowPlayingView::createToolBar()
       
   626 {
       
   627     iMusicShopAction = qobject_cast<HbAction *> (iLoader.findObject("musicShop"));
       
   628     iPlayStopAction = qobject_cast<HbAction *> (iLoader.findObject("playStop"));
       
   629     iAdd2FavAction = qobject_cast<HbAction *> (iLoader.findObject("addToFav"));
       
   630     iFlipAction = qobject_cast<HbAction *> (iLoader.findObject("flip"));
       
   631 
       
   632     iMusicShopAction->setAutoRepeat(false);
       
   633     iPlayStopAction->setAutoRepeat(false);
       
   634     iAdd2FavAction->setAutoRepeat(false);
       
   635     iFlipAction->setAutoRepeat(false);
       
   636     connect(iMusicShopAction, SIGNAL(triggered()), this, SLOT(findInMusicShop()));
       
   637     connect(iPlayStopAction, SIGNAL(triggered()), this, SLOT(playStopControl()));
       
   638     connect(iAdd2FavAction, SIGNAL(triggered()), this, SLOT(add2FavControl()));
       
   639     connect(iFlipAction, SIGNAL(triggered()), this, SLOT(flipControl()));
       
   640 }
       
   641 
       
   642 /*
       
   643  * Description : update station name and category according to the information in preset
       
   644  */
       
   645 void IRNowPlayingView::updateStationInfo()
       
   646 {
       
   647     IRQPreset *nowPlayingPreset = iPlayController->getNowPlayingPreset();
       
   648     const QString &stationName = nowPlayingPreset->name;
       
   649     iNowPlayingContainer->setStationName(stationName);
       
   650 
       
   651     QString category = nowPlayingPreset->genreName + " / "
       
   652             + nowPlayingPreset->countryName + " / "
       
   653             + nowPlayingPreset->languageName;
       
   654     if (" /  / " == category)
       
   655     {
       
   656         category = "";
       
   657     }
       
   658     iNowPlayingContainer->setCategory(category);
       
   659 }
       
   660 
       
   661 /*
       
   662  * Description : Update advertisement image
       
   663  */
       
   664 void IRNowPlayingView::updateAdvImage()
       
   665 {
       
   666     // TODO: in the future, it should judge the change of advertisement url
       
   667     if (ELogoDetermined == iLogoStatus || ERequestIssued == iLogoStatus)
       
   668     {
       
   669         return;
       
   670     }
       
   671 
       
   672     IRQPreset *nowPlayingPreset = iPlayController->getNowPlayingPreset();
       
   673 
       
   674     // TODO: initialize adv, in the future it will use default adv image
       
   675     QIcon icon(":/playback/default_cd.png");
       
   676     HbIcon hbIcon(icon);
       
   677     iNowPlayingContainer->setAdvImage(hbIcon);
       
   678 
       
   679     if (nowPlayingPreset->type)
       
   680     {
       
   681         // isds server channel
       
   682         // TODO: it should use adv in preset, now the variants is not clear
       
   683         if (nowPlayingPreset->advertisementInUse.size() > 0
       
   684                 && iAdvImageUrl != nowPlayingPreset->advertisementInUse)
       
   685         {
       
   686             iAdvImageUrl = nowPlayingPreset->advertisementInUse;
       
   687             iTempAdvClickThroughUrl = nowPlayingPreset->advertisementUrl;
       
   688             IRQPreset advPreset;
       
   689             advPreset.imgUrl = iAdvImageUrl;
       
   690             advPreset.type = 1;
       
   691             iGettingAdv = true;
       
   692             iIsdsClient->isdsLogoDownSendRequest(&advPreset);
       
   693         }
       
   694         else
       
   695         {
       
   696             updateLogoInfo();
       
   697         }
       
   698     }
       
   699     else
       
   700     {
       
   701         updateLogoInfo();
       
   702     }
       
   703 }
       
   704 
       
   705 /*
       
   706  * Description : Update logo info
       
   707  */
       
   708 void IRNowPlayingView::updateLogoInfo()
       
   709 {
       
   710     if (ELogoDetermined == iLogoStatus || ERequestIssued == iLogoStatus
       
   711             || iGettingAdv)
       
   712     {
       
   713         return;
       
   714     }
       
   715 
       
   716     IRQPreset *nowPlayingPreset = iPlayController->getNowPlayingPreset();
       
   717 
       
   718     iNowPlayingContainer->setLogo(*iStationLogo);
       
   719     if (nowPlayingPreset->type)
       
   720     {
       
   721         // isds server channel
       
   722         iLogoStatus = ERequestIssued;
       
   723         iIsdsClient->isdsLogoDownSendRequest(nowPlayingPreset, 2, KNowPlayingLogoSize, KNowPlayingLogoSize);
       
   724     }
       
   725     else
       
   726     {
       
   727         // users defined channel
       
   728         if (iStationDetailsContainer)
       
   729         {
       
   730             iStationDetailsContainer->setLogo(*iStationLogo);
       
   731         }
       
   732         iLogoStatus = ELogoDetermined;
       
   733     }
       
   734 }
       
   735 
       
   736 /*
       
   737  * Description: show container
       
   738  */
       
   739 void IRNowPlayingView::showWidget()
       
   740 {
       
   741     if (iStationDetailsContainer)
       
   742     {
       
   743         IRQPreset *nowPlayingPreset = iPlayController->getNowPlayingPreset();
       
   744         iStationDetailsContainer->setDetails(nowPlayingPreset, *iStationLogo);
       
   745     }
       
   746 
       
   747     updateMusicStatus();
       
   748     updateStationInfo();
       
   749     updateSongInfo(iPlayController->getMetaData());
       
   750     updateAdvImage();
       
   751 }
       
   752 
       
   753 /*
       
   754  * Description: initializing.
       
   755  */
       
   756 void IRNowPlayingView::initialize()
       
   757 {
       
   758     iMusicShop = iApplication->getMusicShop();
       
   759     iStatisticsReporter = iApplication->getStatisticsReporter();
       
   760 }
       
   761 
       
   762 
       
   763 
       
   764 /*
       
   765 * Description : slot function for music shop button in toolbar
       
   766 */
       
   767 void IRNowPlayingView::findInMusicShop()
       
   768 {
       
   769     if(!iFindinNmsAllowed)
       
   770     {
       
   771         popupNote(hbTrId("txt_irad_info_disallowed_by_this_station"), HbMessageBox::MessageTypeInformation);
       
   772         return;        
       
   773     }
       
   774     
       
   775     if(!iSongNameAvailable)
       
   776     {
       
   777         popupNote(hbTrId("txt_irad_info_no_song_info"), HbMessageBox::MessageTypeInformation);
       
   778         return;        
       
   779     }
       
   780         
       
   781     if(NULL == iMusicShop)
       
   782     {
       
   783         popupNote(hbTrId("txt_irad_info_music_shop_not_available"), HbMessageBox::MessageTypeInformation);
       
   784         return;
       
   785     }
       
   786     
       
   787     IRQMetaData *metaData = iPlayController->getMetaData();
       
   788     if( iMusicShop->findInMusicShop(metaData->getSongName(), metaData->getArtistName()))
       
   789     {
       
   790         if(iStatisticsReporter)
       
   791         {
       
   792             int channelId = iPlayController->getNowPlayingPreset()->presetId;
       
   793             iStatisticsReporter->logNmsEvent(EIRQFind,channelId);
       
   794         }
       
   795     }
       
   796     else
       
   797     {
       
   798         popupNote(hbTrId("txt_irad_info_music_shop_not_available"), HbMessageBox::MessageTypeInformation);
       
   799     }
       
   800 }
       
   801 
       
   802 void IRNowPlayingView::helpAction()
       
   803 {
       
   804     popupNote(hbTrId("Not Ready"), HbMessageBox::MessageTypeInformation);
       
   805 }
       
   806 
       
   807 void IRNowPlayingView::playPressed()
       
   808 {
       
   809     if (getViewManager()->currentView() == this)
       
   810     {
       
   811         iPlayController->resume();
       
   812     }
       
   813 }
       
   814 
       
   815 void IRNowPlayingView::gotoMusicStore()
       
   816 {
       
   817     if(IRQMusicShop::launchMusicShop())
       
   818     {
       
   819         if(iStatisticsReporter)
       
   820         {
       
   821             int channelId = 0;
       
   822             if(iPlayController)
       
   823             {
       
   824                 IRQPreset *preset = iPlayController->getNowPlayingPreset();
       
   825                 if(preset)
       
   826                 {
       
   827                     channelId = preset->presetId;
       
   828                 }	      
       
   829             }            
       
   830             iStatisticsReporter->logNmsEvent(EIRQLaunch,channelId);
       
   831         }        
       
   832     }
       
   833     else
       
   834     {
       
   835         popupNote(hbTrId("txt_irad_info_music_shop_not_available"), HbMessageBox::MessageTypeInformation);
       
   836     }
       
   837 }
       
   838 
       
   839 void IRNowPlayingView::updateMusicStatus()
       
   840 {
       
   841     IRQPreset *preset = iPlayController->getNowPlayingPreset();
       
   842     if(preset && (0 == preset->musicStoreStatus.compare("yes",Qt::CaseInsensitive)))
       
   843     {
       
   844         iFindinNmsAllowed = true;
       
   845     }
       
   846     else
       
   847     {
       
   848         iFindinNmsAllowed = false;
       
   849     }
       
   850 }
       
   851 
       
   852 void IRNowPlayingView::recognizeSong()
       
   853 {
       
   854     if(IRQMusicShop::launchShazam())
       
   855     {
       
   856         if(iStatisticsReporter)
       
   857         {           
       
   858             iStatisticsReporter->logSongRecogEvent();    
       
   859         }   
       
   860     }
       
   861     else
       
   862     {
       
   863         popupNote(hbTrId("txt_irad_info_song_recognition_not_available"), HbMessageBox::MessageTypeInformation);
       
   864     }
       
   865 }
       
   866 
       
   867 void IRNowPlayingView::openAdvLink()
       
   868 {
       
   869     IRQUtility::openAdvLink(iAdvClickThroughUrl);
       
   870 }
       
   871 void IRNowPlayingView::shareStationViaMms()
       
   872 {
       
   873     popupNote(hbTrId("Not Ready"), HbMessageBox::MessageTypeInformation);
       
   874 }
       
   875 
       
   876 void IRNowPlayingView::prepareMenu()
       
   877 {
       
   878     HbAction *songRecAction = qobject_cast<HbAction *> (iLoader.findObject("songRecAction"));
       
   879     songRecAction->setEnabled(iPlayController->isPlaying());
       
   880 }