qtinternetradio/ui/src/irnowplayingview.cpp
changeset 3 ee64f059b8e1
parent 0 09774dfdd46b
child 5 0930554dc389
equal deleted inserted replaced
2:2e1adbfc62af 3:ee64f059b8e1
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 #include <QPixmap>
    17 #include <QPixmap>
    18 #include <QTimer>
       
    19 #include <hbmenu.h>
       
    20 #include <hbtoolbar.h>
       
    21 #include <hbaction.h>
    18 #include <hbaction.h>
    22 
    19 #include <hblabel.h>
    23 #include "irabstractviewmanager.h"
    20 #include <hbnotificationdialog.h>
       
    21 
       
    22 #include "irviewmanager.h"
    24 #include "irapplication.h"
    23 #include "irapplication.h"
    25 #include "irplaycontroller.h"
    24 #include "irplaycontroller.h"
    26 #include "irnowplayingview.h"
       
    27 #include "irnowplayingcontainer.h"
       
    28 #include "irstationdetailscontainer.h"
       
    29 #include "irqisdsdatastructure.h"
    25 #include "irqisdsdatastructure.h"
    30 #include "irqmetadata.h"
    26 #include "irqmetadata.h"
    31 #include "irqutility.h"
       
    32 #include "irqisdsclient.h"
    27 #include "irqisdsclient.h"
    33 #include "irqfavoritesdb.h"
    28 #include "irqfavoritesdb.h"
    34 #include "irlastplayedstationinfo.h"
    29 #include "irlastplayedstationinfo.h"
    35 #include "irqnetworkcontroller.h" 
    30 #include "irqnetworkcontroller.h" 
    36 #include "irqmusicshop.h"
       
    37 #include "irqstatisticsreporter.h"
    31 #include "irqstatisticsreporter.h"
    38 #include "irqenums.h"
    32 #include "irqenums.h"
    39 #include "irmediakeyobserver.h"
    33 #include "irmediakeyobserver.h"
    40 #include "irqsettings.h"
       
    41 #include "irqstationexporter.h"
       
    42 #include "iruidefines.h"
    34 #include "iruidefines.h"
    43 
    35 #include "irnowplayingview.h"
    44 // Const
    36 #include "irstationshare.h"
       
    37 #include "irqutility.h"
       
    38 #include "irqlogger.h"
       
    39 #include "irplaylist.h"
       
    40 #include "irstationdetailsview.h"
       
    41 
       
    42 #ifdef ADV_ENABLED
       
    43 #include <QTimer>
       
    44 #include <qgraphicssceneevent.h>
       
    45 static const QString KDefaultAdvLink(""); // default advertisement link
       
    46 #endif
       
    47 
    45 const int KNowPlayingLogoSize = 300; // Now playing logo size
    48 const int KNowPlayingLogoSize = 300; // Now playing logo size
    46 const char* NOW_PLAYING_VIEW_OBJECT_NAME = "ex-IRNowPlayingView"; // object name in the XML
    49 static const QString KDefaultStationLogo("qtg_large_internet_radio");
    47 const char* KDefaultAdvertisementLink = ""; // default advertisement link
    50 static const QString KPlayButtonIcon("qtg_mono_play");
    48 
    51 static const QString KStopButtonIcon("qtg_mono_stop");
    49 //                                     public functions
       
    50 
    52 
    51 /*
    53 /*
    52  * Description : constructor
    54  * Description : constructor
    53  */
    55  */
    54 IRNowPlayingView::IRNowPlayingView(IRApplication* aApplication, TIRViewId aViewId) :
    56 IRNowPlayingView::IRNowPlayingView(IRApplication* aApplication, TIRViewId aViewId) :
    55     IRBaseView(aApplication, aViewId),
    57     IRBaseView(aApplication, aViewId),
    56     iLogoPreset(NULL),
    58     iStatisticsReporter(NULL),
    57     iStationDetailsContainer(NULL),
    59     iNetworkController(NULL),
    58     iIdleContainer(NULL),
       
    59     iMusicShop(NULL),
       
    60     iStationExporter(NULL),
       
    61     iStereoAction(NULL),
       
    62     iMusicShopAction(NULL),
       
    63     iPlayStopAction(NULL),
    60     iPlayStopAction(NULL),
    64     iAdd2FavAction(NULL),
    61     iLaunchActionNeeded(false),
    65     iAdvClickThroughUrl(KDefaultAdvertisementLink),
    62     iLogoDownloadState(EIdle),    
    66     iGettingAdv(false),
    63     iSongName(NULL),
       
    64     iArtistName(NULL),
       
    65     iStationName(NULL),
    67     iStationLogo(NULL),
    66     iStationLogo(NULL),
    68     iStereoMode(0),
    67     iLogoNeedUpdate(true),    
    69     iShowStationInfo(FALSE),
       
    70     iLogoStatus(EDefaultLogo),
       
    71     iFindinNmsAllowed(false),
    68     iFindinNmsAllowed(false),
    72     iSongNameAvailable(false)
    69     iSongNameAvailable(false)
    73 {
    70 #ifdef ADV_ENABLED
    74     // Create widget hierarchy
    71     ,iAdvImage(NULL)
       
    72     ,iAdvImageNeedUpdate(true)
       
    73     ,iAdvUrl(KDefaultAdvLink)    
       
    74 #endif
       
    75 {
       
    76     initialize();
       
    77     
       
    78     //if this view is not starting view, finish all initialization in constructor
       
    79     if (getViewManager()->views().count() > 0)
       
    80     {
       
    81         normalInit();
       
    82     }
       
    83 }
       
    84 
       
    85 /*
       
    86  * Description : destructor
       
    87  */
       
    88 IRNowPlayingView::~IRNowPlayingView()
       
    89 {
       
    90     if(iNetworkController)
       
    91     {
       
    92         iNetworkController->closeInstance();
       
    93     }
       
    94     
       
    95     if (iStatisticsReporter)
       
    96     {
       
    97         iStatisticsReporter->closeInstance();
       
    98     }
       
    99 }
       
   100 
       
   101 
       
   102 /*
       
   103  * Description: initializing.
       
   104  */
       
   105 void IRNowPlayingView::initialize()
       
   106 {
    75     setObjectName(NOW_PLAYING_VIEW_OBJECT_NAME);
   107     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;
   108     QObjectList roots;
    80     roots.append(this); // IRNowPlayingView is referred in XML file
   109     roots.append(this);
    81     iLoader.setObjectTree(roots);
   110     iLoader.setObjectTree(roots);
    82 
   111 
    83     // Load XML file
   112     // Load XML file
    84     iLoader.load(NOW_PLAYING_VIEW_LAYOUT_FILENAME);
   113     iLoader.load(NOW_PLAYING_VIEW_LAYOUT_FILENAME);
    85 
   114     
    86     createMenu();
   115     initMenu();
    87     createToolBar();
   116     initToolBar();
    88     initialize();
   117     initWidget();    
    89 
   118 }
    90     connect(iPlayController, SIGNAL(metaDataAvailable(IRQMetaData*)), this, SLOT(updateSongInfo(IRQMetaData*)));
   119 
    91     connect(iPlayController, SIGNAL(initializeLogo()), this, SLOT(initializeLogo()));
   120 /*
    92     connect(iPlayController, SIGNAL(playingStarted()), this, SLOT(playingStarted()));
   121  * Description : create menu for now playing view
    93     connect(iPlayController, SIGNAL(playingStopped()), this, SLOT(playingStopped()));
   122  */
    94 
   123 void IRNowPlayingView::initMenu()
    95     connect(iNetworkController, SIGNAL(networkRequestNotified(IRQNetworkEvent)),
   124 {
    96             this, SLOT(networkRequestNotified(IRQNetworkEvent)));
   125 #ifdef SONGRECOGNITION_ENABLED  
    97     connect(iApplication->getMediaKeyObserver(), SIGNAL(playPausePressed()), 
   126     if(IRQUtility::identifySongAvailable())
    98             this, SLOT(playPressed()));
   127     {
    99     connect(iApplication->getMediaKeyObserver(), SIGNAL(stopPressed()), 
   128         LOG("Song Recognition is Available");
   100             this, SLOT(stop()));
   129         iLoader.load(NOW_PLAYING_VIEW_LAYOUT_FILENAME, NOW_PLAYING_VIEW_SONG_RECOG_YES_SEC);
   101 
   130     }
   102     // Initialize logo
   131     else
   103     QIcon icon(":/playback/default_cd.png");
   132     {
   104     iStationLogo = new HbIcon(icon);
   133         LOG("Song Recognition is NOT Available");
   105 
   134         iLoader.load(NOW_PLAYING_VIEW_LAYOUT_FILENAME, NOW_PLAYING_VIEW_SONG_RECOG_NO_SEC);
   106     // Initialize advertisement image
   135     }
   107     QIcon advIcon(":/playback/default_cd.jpg");
   136 #else
   108     HbIcon advInitialImage(advIcon);
   137     LOG("Song Recognition is Disabled");
   109     iStationExporter = new IRQStationExporter();
   138     iLoader.load(NOW_PLAYING_VIEW_LAYOUT_FILENAME, NOW_PLAYING_VIEW_SONG_RECOG_NO_SEC);
   110     iNowPlayingContainer = new IRNowPlayingContainer(getViewManager());
   139 #endif    
   111     connect(getViewManager(), SIGNAL(orientationChanged(Qt::Orientation)), 
   140     HbAction *openWebAddressAction = qobject_cast<HbAction *> (iLoader.findObject(GO_TO_STATION_ACTION));
   112             iNowPlayingContainer, SLOT(orientationChanged(Qt::Orientation)));
   141     HbAction *shareStationAction = qobject_cast<HbAction *> (iLoader.findObject(NOW_PLAYING_VIEW_OBJECT_SHARE_STATION_ACTION));
   113     connect(iNowPlayingContainer, SIGNAL(volumePressed()), 
   142     HbAction *settings = qobject_cast<HbAction *> (iLoader.findObject(SETTINGS_ACTION));
   114             iApplication->getMediaKeyObserver(), SLOT(showVolumeSlider()));
   143     HbAction *exitAction = qobject_cast<HbAction *> (iLoader.findObject(EXIT_ACTION));
   115     connect(iNowPlayingContainer, SIGNAL(advertisementPressed()), 
   144     HbAction *songRecAction = qobject_cast<HbAction *> (iLoader.findObject(NOW_PLAYING_VIEW_OBJECT_IDENTIFYSONG));
   116                 this, SLOT(openAdvLink()));
   145 
   117     setWidget(iNowPlayingContainer);
   146     connect(openWebAddressAction, SIGNAL(triggered()), this, SLOT(handleGoToStationAction()));
   118     iNowPlayingContainer->setLogo(*iStationLogo);
   147     connect(shareStationAction, SIGNAL(triggered()), this, SLOT(handleShareStationAction()));
   119     iNowPlayingContainer->setAdvImage(advInitialImage);
   148     connect(settings, SIGNAL(triggered()), this, SLOT(handleSettingAction()));
   120 
   149     connect(exitAction, SIGNAL(triggered()), iApplication, SIGNAL(quit()));  
   121     HbEffect::add("nowplaying", ":/effect/view_flip_hide.fxml", "hide");
   150     connect(songRecAction, SIGNAL(triggered()), this, SLOT(handleIdentifySongAction()));    
   122     HbEffect::add("nowplaying", ":/effect/view_flip_show.fxml", "show");
   151 }
   123 }
   152 
   124 
   153 /*
   125 /*
   154  * Description : create tool bar for now playing view
   126  * Description : destructor
   155  */
   127  */
   156 void IRNowPlayingView::initToolBar()
   128 IRNowPlayingView::~IRNowPlayingView()
   157 {
   129 {
   158     HbAction *musicStoreAction = qobject_cast<HbAction *> (iLoader.findObject(NOW_PLAYING_VIEW_OBJECT_MUSICSTORE));
   130     delete iIdleContainer;
   159     iPlayStopAction = qobject_cast<HbAction *> (iLoader.findObject(NOW_PLAYING_VIEW_OBJECT_PLAYSTOP));
   131     iIdleContainer = NULL;
   160     HbAction *add2FavAction = qobject_cast<HbAction *> (iLoader.findObject(NOW_PLAYING_VIEW_OBJECT_ADDTOFAV));
   132 
   161     HbAction *flipAction = qobject_cast<HbAction *> (iLoader.findObject(NOW_PLAYING_VIEW_OBJECT_FLIP));
   133     delete iStationExporter;
   162 
   134     iStationExporter = NULL;
   163     connect(musicStoreAction, SIGNAL(triggered()), this, SLOT(handleMusicStoreAction()));
   135 
   164     connect(iPlayStopAction, SIGNAL(triggered()), this, SLOT(handlePlayStopAction()));
   136     iNowPlayingContainer = NULL;
   165     connect(add2FavAction, SIGNAL(triggered()), this, SLOT(handleAddToFavAction()));
   137     iStationDetailsContainer = NULL;
   166     connect(flipAction, SIGNAL(triggered()), this, SLOT(handleDetailInfoAction()));
   138 
   167 }
   139     delete iLogoPreset;
   168 
   140     iLogoPreset = NULL;
   169 void IRNowPlayingView::initWidget()
   141 
   170 {
   142     delete iStationLogo;
   171     iStationLogo = qobject_cast<HbLabel *> (iLoader.findObject(NOW_PLAYING_VIEW_OBJECT_STATION_LOGO));
   143     iStationLogo = NULL;
   172     iSongName = qobject_cast<HbLabel *> (iLoader.findObject(NOW_PLAYING_VIEW_OBJECT_SONG_NAME));
   144     
   173     iArtistName = qobject_cast<HbLabel *> (iLoader.findObject(NOW_PLAYING_VIEW_OBJECT_ARTIST_NAME));
   145     HbEffect::remove("nowplaying", ":/playback/view_flip_hide.fxml", "hide");
   174     iStationName = qobject_cast<HbLabel *> (iLoader.findObject(NOW_PLAYING_VIEW_OBJECT_STATION_NAME));   
   146     HbEffect::remove("nowplaying", ":/playback/view_flip_show.fxml", "show");
   175     iStationLogo->setIcon(HbIcon(KDefaultStationLogo));   
   147 }
   176     iStationName->setPlainText("");
   148 
   177     iSongName->setPlainText("");
   149 /*
   178     iArtistName->setPlainText("");    
   150  * Description : from base class IRBaseView.
   179 #ifdef ADV_ENABLED
   151  *               handle system events reported by system event collector
   180     iAdvImage = qobject_cast<HbLabel *> (iLoader.findObject( NOW_PLAYING_VIEW_OBJECT_ADVERTISEMENT_IMAGE));
   152  * Parameters  : aEvent : see the definiton of TIRSystemEventType.
   181     iAdvImage->setIcon(HbIcon(KDefaultStationLogo));
   153  * Return      : EIR_DoDefault : caller does default handling
   182 #endif    
   154  *               EIR_NoDefault : caller doesn't do default handling
   183 }
   155  */
   184 
   156 TIRHandleResult IRNowPlayingView::handleSystemEvent(TIRSystemEventType aEvent)
   185 /*
   157 {
   186  * Description : update station name and category according to the information in preset
   158     Q_UNUSED(aEvent);
   187  */
   159     return EIR_DoDefault;
   188 void IRNowPlayingView::updateWidgets()
   160 }
   189 {
       
   190     if(iPlayController->getNowPlayingPreset())
       
   191     {
       
   192         iStationName->setPlainText(iPlayController->getNowPlayingPreset()->name);
       
   193     }
       
   194 }
       
   195 
       
   196 void IRNowPlayingView::updateMusicStoreStatus()
       
   197 {
       
   198     IRQPreset *preset = iPlayController->getNowPlayingPreset();
       
   199     if(preset && (0 == preset->musicStoreStatus.compare("yes",Qt::CaseInsensitive)))
       
   200     {
       
   201         iFindinNmsAllowed = true;
       
   202     }
       
   203     else
       
   204     {
       
   205         iFindinNmsAllowed = false;
       
   206     }
       
   207 }
       
   208 
       
   209 
       
   210 /*
       
   211  * Description : Update logo info
       
   212  */
       
   213 void IRNowPlayingView::updateStationLogo()
       
   214 {    
       
   215     if( !iLogoNeedUpdate
       
   216         || iLogoDownloadState != EIdle )
       
   217     {
       
   218         return;
       
   219     }
       
   220     
       
   221     if( !iNetworkController->getNetworkStatus() )
       
   222     {
       
   223         // when launch as starting view, reach here.
       
   224         // but later, will be invoked again via handlePlayStarted()
       
   225         return;
       
   226     }    
       
   227 
       
   228     IRQPreset *nowPlayingPreset = iPlayController->getNowPlayingPreset();
       
   229     if( 1 == nowPlayingPreset->type )
       
   230     {
       
   231         // isds server channel
       
   232         iLogoDownloadState = EDownloadLogo; 
       
   233         iIsdsClient->isdsLogoDownSendRequest(nowPlayingPreset, 2, KNowPlayingLogoSize, KNowPlayingLogoSize);    
       
   234     }
       
   235     else
       
   236     {
       
   237         iLogoDownloadState = EIdle;
       
   238         iLogoNeedUpdate = false; 
       
   239 #ifdef ADV_ENABLED        
       
   240         iAdvImageNeedUpdate = false;  
       
   241 #endif             
       
   242     }
       
   243 }
       
   244 
       
   245 #ifdef ADV_ENABLED
       
   246 /*
       
   247  * Description : Update advertisement image
       
   248  */
       
   249 void IRNowPlayingView::updateAdvImage()
       
   250 {
       
   251     if( !iAdvImageNeedUpdate
       
   252         || iLogoDownloadState != EIdle )
       
   253     {
       
   254         return;
       
   255     }
       
   256 
       
   257     IRQPreset *nowPlayingPreset = iPlayController->getNowPlayingPreset();
       
   258     if( (1 == nowPlayingPreset->type)  // isds server channel
       
   259         && (nowPlayingPreset->advertisementInUse.size() > 0) )
       
   260     {
       
   261         IRQPreset advPreset;
       
   262         advPreset.imgUrl = nowPlayingPreset->advertisementInUse;
       
   263         advPreset.type = 1;
       
   264         iLogoDownloadState = EDownLoadAdvImage;        
       
   265         iIsdsClient->isdsLogoDownSendRequest(&advPreset);
       
   266     }
       
   267     else
       
   268     {
       
   269         iLogoNeedUpdate = false;
       
   270         iAdvImageNeedUpdate = false;
       
   271         iLogoDownloadState = EIdle;
       
   272     }
       
   273 }
       
   274 #endif
   161 
   275 
   162 /*
   276 /*
   163  * Description : from base class IRBaseView.
   277  * Description : from base class IRBaseView.
   164  *               handle view commands.
   278  *               handle view commands.
   165  * Parameters  : aCommand : see the definition of TIRViewCommand
   279  * Parameters  : aCommand : see the definition of TIRViewCommand
   166  * Return      : EIR_DoDefault : caller does default handling
   280  * Return      : EIR_DoDefault : caller does default handling
   167  *               EIR_NoDefault : caller doesn't do default handling
   281  *               EIR_NoDefault : caller doesn't do default handling
   168  */
   282  */
   169 TIRHandleResult IRNowPlayingView::handleCommand(TIRViewCommand aCommand, TIRViewCommandReason aReason)
   283 TIRHandleResult IRNowPlayingView::handleCommand(TIRViewCommand aCommand, TIRViewCommandReason aReason)
   170 {
   284 {
       
   285     if (!initCompleted())
       
   286     {
       
   287         return EIR_NoDefault;
       
   288     }
       
   289     
   171     Q_UNUSED(aReason);
   290     Q_UNUSED(aReason);
   172     TIRHandleResult ret = EIR_DoDefault;
   291     TIRHandleResult ret = EIR_DoDefault;
   173 
   292 
   174     switch (aCommand)
   293     switch (aCommand)
   175     {
   294     {
       
   295     case EIR_ViewCommand_TOBEACTIVATED:       
       
   296         handleOrientationChanged(getViewManager()->orientation());                 
       
   297         updateMusicStoreStatus();
       
   298         updateWidgets();
       
   299         ret = EIR_NoDefault;
       
   300         break;
       
   301 
   176     case EIR_ViewCommand_ACTIVATED:
   302     case EIR_ViewCommand_ACTIVATED:
   177         connect(iIsdsClient, SIGNAL(presetLogoDownloaded(IRQPreset* )),
   303         connect(iIsdsClient, SIGNAL(presetLogoDownloaded(IRQPreset* )),
   178                 this, SLOT(presetLogoDownload(IRQPreset* )));
   304                 this, SLOT(handleLogoDownloaded(IRQPreset* )));
   179         showWidget();
   305         updateStationLogo();
   180         break;
   306         break;
   181 
   307         
   182     case EIR_ViewCommand_DEACTIVATE:
   308     case EIR_ViewCommand_DEACTIVATE:
   183         if (ERequestIssued == iLogoStatus)
   309         if( iLogoDownloadState != EIdle )
   184         {
   310         {
   185             // cancel downloading logo
   311             // cancel downloading logo
   186             iIsdsClient->isdsLogoDownCancelTransaction();
   312             iIsdsClient->isdsLogoDownCancelTransaction();
   187             iLogoStatus = EDefaultLogo;
   313             iLogoDownloadState = EIdle;            
   188         }
   314         }        
   189         disconnect(iIsdsClient, SIGNAL(presetLogoDownloaded(IRQPreset*)),
   315         disconnect(iIsdsClient, SIGNAL(presetLogoDownloaded(IRQPreset*)),
   190                    this, SLOT(presetLogoDownload(IRQPreset* )));
   316                    this, SLOT(handleLogoDownloaded(IRQPreset* )));
       
   317         ret = EIR_NoDefault;
   191         break;
   318         break;
   192     }
   319     }
   193 
   320 
   194     return ret;
   321     return ret;
   195 }
   322 }
   196 
   323 
   197 /*
   324 /*
   198  * Description : actions when view is launched.
   325  * Description : actions when view is launched.
   199  */
   326  */
   200 void IRNowPlayingView::launchAction()
   327 void IRNowPlayingView::launchAction()
   201 {
   328 {      
   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);
   329     setUseNetworkReason(EIR_UseNetwork_StartingView);
   216     iApplication->verifyNetworkConnectivity();
   330     iApplication->verifyNetworkConnectivity();
   217 }
   331     getViewManager()->pushViewById(EIRView_MainView);
   218 
   332     iLaunchActionNeeded = true;
   219 /*
   333     updateForLauchAction();
   220  * Description : start to converter the downloaded logo.
   334 }
   221  */
   335 
   222 void IRNowPlayingView::presetLogoDownload(IRQPreset* aPreset)
   336 void IRNowPlayingView::lazyInit()
   223 {
   337 {
   224     if (NULL == aPreset)
   338     if (!initCompleted())
       
   339     {       
       
   340         normalInit();
       
   341         
       
   342         //initization from handleCommand()
       
   343         handleCommand(EIR_ViewCommand_TOBEACTIVATED, EIR_ViewCommandReason_Show);
       
   344         handleCommand(EIR_ViewCommand_ACTIVATED, EIR_ViewCommandReason_Show);
       
   345     }
       
   346 }
       
   347 
       
   348 void IRNowPlayingView::normalInit()
       
   349 {
       
   350     if (!initCompleted())
       
   351     {
       
   352         IRBaseView::lazyInit();
       
   353         
       
   354         iStatisticsReporter = IRQStatisticsReporter::openInstance();
       
   355         iNetworkController = IRQNetworkController::openInstance();
       
   356             
       
   357         connect(iPlayController, SIGNAL(metaDataAvailable(IRQMetaData*)), this, SLOT(updateMetaData(IRQMetaData*)));
       
   358         connect(iPlayController, SIGNAL(playingStarted()), this, SLOT(handlePlayStarted()));
       
   359         connect(iPlayController, SIGNAL(playingStopped()), this, SLOT(handlePlayStopped()));
       
   360 
       
   361         connect(iNetworkController, SIGNAL(networkRequestNotified(IRQNetworkEvent)),
       
   362                 this, SLOT(handleNetworkEvent(IRQNetworkEvent)));
       
   363         connect(iApplication->getMediaKeyObserver(), SIGNAL(playPausePressed()), 
       
   364                 this, SLOT(handlePlayPauseMediaKey()));
       
   365         connect(iApplication->getMediaKeyObserver(), SIGNAL(stopPressed()), 
       
   366                 this, SLOT(handleStopMediaKey()));
       
   367         connect( getViewManager(), SIGNAL( orientationChanged(Qt::Orientation) ),
       
   368                  this, SLOT( handleOrientationChanged(Qt::Orientation) ) );
       
   369         
       
   370         setInitCompleted(true);
       
   371     }
       
   372 }
       
   373 
       
   374 void IRNowPlayingView::updateForLauchAction()
       
   375 {
       
   376     //nowplaying view as starting view can have two cases : one is for last played station, the other is for 
       
   377     //the only one item in play list file    
       
   378     IRPlayList *playList = iApplication->getPlayList();
       
   379     if (playList && 1 == playList->getNumberOfEntries())
       
   380     {
       
   381         IRQPreset *preset = playList->getPresetForEntry(0);
       
   382         iStationName->setPlainText(preset->name);
       
   383         iFindinNmsAllowed = (0 == preset->musicStoreStatus.compare("yes",Qt::CaseInsensitive));
       
   384         delete preset;
       
   385     }
       
   386     else
       
   387     {
       
   388         IRLastPlayedStationInfo *lastPlayedStationInfo = iApplication->getLastPlayedStationInfo();
       
   389         IRQPreset *lastPreset = lastPlayedStationInfo->getLastPlayedStation();
       
   390         
       
   391         if (lastPreset)
       
   392         {
       
   393             iStationName->setPlainText(lastPreset->name); 
       
   394             iFindinNmsAllowed = (0 == lastPreset->musicStoreStatus.compare("yes",Qt::CaseInsensitive)); 
       
   395         }
       
   396         else
       
   397         {
       
   398             iFindinNmsAllowed = false;
       
   399         }
       
   400     }
       
   401 }
       
   402 
       
   403 /********************************************************************************************************
       
   404  * SLOTs for Logo Download
       
   405  *******************************************************************************************************
       
   406  */
       
   407 void IRNowPlayingView::handleLogoDownloaded(IRQPreset* aPreset)
       
   408 {
       
   409     if( EIdle == iLogoDownloadState )
       
   410     {        
   225         return;
   411         return;
   226 
   412     } 
   227     // Sometimes the logo downloaded by stationview will reach here because
   413             
   228     // the isdsLogoDownCancelTransaction is delayed. So we judge the imageUrl here.
   414     if( NULL == aPreset )
   229     if (!iGettingAdv && (aPreset->imgUrl != iPlayController->getNowPlayingPreset()->imgUrl))
   415     {        
   230     {
   416         if( EDownloadLogo == iLogoDownloadState )
   231         delete aPreset;
   417         {         
   232         aPreset = NULL;
   418             iLogoNeedUpdate = false;  
       
   419 #ifdef ADV_ENABLED
       
   420             QTimer::singleShot(1, this, SLOT(updateAdvImage()));
       
   421 #endif            
       
   422         }
       
   423 #ifdef ADV_ENABLED      
       
   424         else if( EDownLoadAdvImage == iLogoDownloadState )
       
   425         {
       
   426             iAdvImageNeedUpdate = false;            
       
   427         }
       
   428 #endif
       
   429         iLogoDownloadState = EIdle;      
   233         return;
   430         return;
   234     }
   431     }
       
   432     
   235  
   433  
   236     delete iLogoPreset;
   434     
   237     iLogoPreset = aPreset;
   435     const unsigned char * logoRawData = aPreset->logoData.Ptr();
   238     
   436     QPixmap logoPixmap;
   239     const unsigned char * logoData = iLogoPreset->logoData.Ptr();
   437     if( logoPixmap.loadFromData(logoRawData, aPreset->logoData.Length()) )
   240     QPixmap tempMap;
   438     {
   241     bool ret = tempMap.loadFromData(logoData, iLogoPreset->logoData.Length());
   439         if( EDownloadLogo == iLogoDownloadState )
   242     if( !ret )
   440         {
   243     {
   441             QPixmap newLogoPixmap = 
   244         if (iGettingAdv)
   442                  logoPixmap.scaled(QSize(KNowPlayingLogoSize,KNowPlayingLogoSize),Qt::KeepAspectRatio);      
   245         {
   443             QIcon logoQIcon(newLogoPixmap);
   246             iGettingAdv = false;
   444             HbIcon logoHbIcon(logoQIcon);
   247             QTimer::singleShot(1, this, SLOT(updateLogoInfo()));
   445             iStationLogo->setIcon(logoHbIcon);        
   248         }
   446             iLogoNeedUpdate = false;          
   249         else
   447 #ifdef ADV_ENABLED
   250         {
   448             QTimer::singleShot(1, this, SLOT(updateAdvImage()));
   251             iLogoStatus = ELogoDetermined;
   449 #endif
   252         }
   450         }
       
   451 #ifdef ADV_ENABLED      
       
   452         else if( EDownLoadAdvImage == iLogoDownloadState )
       
   453         {
       
   454             QIcon logoQIcon(logoPixmap);
       
   455             HbIcon logoHbIcon(logoQIcon);            
       
   456             iAdvImage->setIcon(logoHbIcon); 
       
   457             iAdvUrl = iPlayController->getNowPlayingPreset()->advertisementUrl;  
       
   458             iAdvImageNeedUpdate = false;            
       
   459         }
       
   460 #endif
       
   461     }
       
   462     else
       
   463     {
       
   464         if( EDownloadLogo == iLogoDownloadState )
       
   465         {         
       
   466             iLogoNeedUpdate = false;  
       
   467 #ifdef ADV_ENABLED
       
   468             QTimer::singleShot(1, this, SLOT(updateAdvImage()));
       
   469 #endif            
       
   470         }
       
   471 #ifdef ADV_ENABLED      
       
   472         else if( EDownLoadAdvImage == iLogoDownloadState )
       
   473         {
       
   474             iAdvImageNeedUpdate = false;            
       
   475         }
       
   476 #endif        
       
   477     }
       
   478 
       
   479     iLogoDownloadState = EIdle;      
       
   480     
       
   481     delete aPreset;
       
   482     aPreset = NULL;
       
   483 }
       
   484 
       
   485 
       
   486 
       
   487 /********************************************************************************************************
       
   488  * SLOT for Network Event
       
   489  *******************************************************************************************************
       
   490  */
       
   491 void IRNowPlayingView::handleNetworkEvent(IRQNetworkEvent aEvent)
       
   492 {
       
   493     if( this != getViewManager()->currentView() )
       
   494     {
   253         return;
   495         return;
   254     }
   496     }
   255     
   497     
   256     QIcon convertIcon(tempMap);
   498     switch(aEvent)
   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     {
   499     {
   549     case EIRQNetworkConnectionEstablished:
   500     case EIRQNetworkConnectionEstablished:
   550         iApplication->closeConnectingDialog();
   501         {
   551         if (EIR_UseNetwork_StartingView == getUseNetworkReason())
   502             iApplication->closeConnectingDialog();
   552         {
   503             if( EIR_UseNetwork_StartingView == getUseNetworkReason() )
   553             IRLastPlayedStationInfo *lastPlayedStationInfo =
       
   554                     iApplication->getLastPlayedStationInfo();
       
   555             IRQPreset *preset = lastPlayedStationInfo->getLastPlayedStation();
       
   556             if (preset)
       
   557             {
   504             {
   558                 iPlayController->connectToChannel(preset,lastPlayedStationInfo->connectedFrom());
   505                 IRPlayList *playList = iApplication->getPlayList();
       
   506                 if (playList && 1 == playList->getNumberOfEntries())
       
   507                 {
       
   508                     IRQPreset *preset = playList->getPresetForEntry(0);
       
   509                     iPlayController->connectToChannel(preset, EIRQAdhocExternal);
       
   510                     delete preset;
       
   511                 }
       
   512                 else
       
   513                 {
       
   514                     IRLastPlayedStationInfo *lastPlayedStationInfo = iApplication->getLastPlayedStationInfo();
       
   515                     IRQPreset *lastPreset = lastPlayedStationInfo->getLastPlayedStation();
       
   516                     if (lastPreset)
       
   517                     {
       
   518                         iPlayController->connectToChannel( lastPreset, lastPlayedStationInfo->connectedFrom() );
       
   519                     }
       
   520                 }
   559             }
   521             }
   560         }
   522             else if( EIR_UseNetwork_PlayStation == getUseNetworkReason() )
   561         else if (EIR_UseNetwork_PlayStation == getUseNetworkReason())
   523             {
   562         {
   524                 handlePlayStopAction();
   563             playStopControl();
   525             }
   564         }
   526             setUseNetworkReason(EIR_UseNetwork_NoReason);
   565 
   527             break;
   566         setUseNetworkReason(EIR_UseNetwork_NoReason);
   528         }
   567         
       
   568         break;
       
   569         
   529         
   570     case EIRQConnectingCancelled:
   530     case EIRQConnectingCancelled:
   571     case EIRQDisplayNetworkMessageNoConnectivity:
   531     case EIRQDisplayNetworkMessageNoConnectivity:
   572         {
   532         {
   573             IRQPreset *preset = iPlayController->getNowPlayingPreset();
   533             IRQPreset *preset = iPlayController->getNowPlayingPreset();
   574             //if IRPlayController::connectToChannel(IRQPreset*) hasn't been called, back to main view.
   534             if( NULL == preset || preset->name == "" )
   575             //otherwise stay in nowplaying view.
       
   576             if (NULL == preset || preset->name == "")
       
   577             {
   535             {
   578                 getViewManager()->activateView(EIRView_MainView);
   536                 getViewManager()->activateView(EIRView_MainView);
   579             }
   537             }
   580         }
   538         }
   581         break;
   539         break;
   583     default:
   541     default:
   584         break;
   542         break;
   585     }
   543     }
   586 }
   544 }
   587 
   545 
   588 //                                       private functions
   546 /********************************************************************************************************
   589 
   547  * SLOT for Orientation Changed
   590 /*
   548  *******************************************************************************************************
   591  * Description : create menu for now playing view
   549  */
   592  */
   550 
   593 void IRNowPlayingView::createMenu()
   551 void IRNowPlayingView::handleOrientationChanged(Qt::Orientation aOrientation)
   594 {
   552 {
   595     iStereoAction = qobject_cast<HbAction *> (iLoader.findObject("activateStereo"));
   553     if (aOrientation == Qt::Vertical)
   596     iStereoMode = iApplication->getSettings()->getStereoMode();
   554     {
   597     if (iStereoMode == 1)
   555         iLoader.load(NOW_PLAYING_VIEW_LAYOUT_FILENAME, NOW_PLAYING_VIEW_PRT_SEC);
   598     {
   556     }
   599         iStereoAction->setText(hbTrId("txt_irad_opt_deactivate_stereo"));
   557     else
   600     }
   558     {
   601     HbAction *openWebAddressAction = qobject_cast<HbAction *> (iLoader.findObject("openWebAddressAction"));
   559         iLoader.load(NOW_PLAYING_VIEW_LAYOUT_FILENAME, NOW_PLAYING_VIEW_LSC_SEC);      
   602     HbAction *shareStationAction = qobject_cast<HbAction *> (iLoader.findObject("shareStationAction"));
   560     }
   603     HbAction *songRecAction = qobject_cast<HbAction *> (iLoader.findObject("songRecAction"));
   561 }
   604     HbAction *gotoMusicStoreAction = qobject_cast<HbAction *> (iLoader.findObject("gotoMusicStoreAction"));
   562 
   605     HbAction *settings = qobject_cast<HbAction *> (iLoader.findObject("settings"));
   563 /********************************************************************************************************
   606     HbAction *helpAction = qobject_cast<HbAction *> (iLoader.findObject("help"));
   564  * SLOT for Play Controller
   607     HbAction *exitAction = qobject_cast<HbAction *> (iLoader.findObject("exit"));
   565  *******************************************************************************************************
   608 
   566  */
   609     connect(iStereoAction, SIGNAL(triggered()), this, SLOT(stereoControl()));
   567 void IRNowPlayingView::handlePlayStarted()
   610     connect(openWebAddressAction, SIGNAL(triggered()), this, SLOT(openWebAddressControl()));
   568 {
   611     connect(shareStationAction, SIGNAL(triggered()), this, SLOT(shareStationViaMms()));
   569     if(iLaunchActionNeeded)
   612     connect(songRecAction, SIGNAL(triggered()), this, SLOT(recognizeSong()));
   570     {
   613     connect(gotoMusicStoreAction, SIGNAL(triggered()), this, SLOT(gotoMusicStore()));
   571         iLaunchActionNeeded = false;
   614     connect(settings, SIGNAL(triggered()), this, SLOT(launchSettingsView()));
   572         updateStationLogo();
   615     connect(helpAction, SIGNAL(triggered()), this, SLOT(helpAction()));
   573     }
   616     connect(exitAction, SIGNAL(triggered()), iApplication, SIGNAL(quit()));
   574     iPlayStopAction->setIcon(HbIcon(KStopButtonIcon));
   617 
   575 }
   618     HbMenu *viewMenu = menu();
   576 
   619     connect(viewMenu, SIGNAL(aboutToShow()), this, SLOT(prepareMenu()));    
   577 void IRNowPlayingView::handlePlayStopped()
   620 }
   578 {
   621 
   579     iPlayStopAction->setIcon(HbIcon(KPlayButtonIcon));
   622 /*
   580     iSongName->setPlainText("");
   623  * Description : create tool bar for now playing view
   581     iArtistName->setPlainText("");
   624  */
   582     iSongNameAvailable = false;
   625 void IRNowPlayingView::createToolBar()
   583         
   626 {
   584     if( this != getViewManager()->currentView() )
   627     iMusicShopAction = qobject_cast<HbAction *> (iLoader.findObject("musicShop"));
   585     {
   628     iPlayStopAction = qobject_cast<HbAction *> (iLoader.findObject("playStop"));
   586         iStationLogo->setIcon(HbIcon(KDefaultStationLogo));
   629     iAdd2FavAction = qobject_cast<HbAction *> (iLoader.findObject("addToFav"));
   587         iLogoNeedUpdate = true;
   630     iFlipAction = qobject_cast<HbAction *> (iLoader.findObject("flip"));
   588 #ifdef ADV_ENABLED
   631 
   589         iAdvUrl = KDefaultAdvLink;
   632     iMusicShopAction->setAutoRepeat(false);
   590         iAdvImage->setIcon(HbIcon(KDefaultStationLogo));
   633     iPlayStopAction->setAutoRepeat(false);
   591         iAdvImageNeedUpdate = true;  
   634     iAdd2FavAction->setAutoRepeat(false);
   592 #endif        
   635     iFlipAction->setAutoRepeat(false);
   593     }
   636     connect(iMusicShopAction, SIGNAL(triggered()), this, SLOT(findInMusicShop()));
   594 }
   637     connect(iPlayStopAction, SIGNAL(triggered()), this, SLOT(playStopControl()));
   595 
   638     connect(iAdd2FavAction, SIGNAL(triggered()), this, SLOT(add2FavControl()));
   596 void IRNowPlayingView::updateMetaData(IRQMetaData* aMetaData)
   639     connect(iFlipAction, SIGNAL(triggered()), this, SLOT(flipControl()));
   597 {
   640 }
   598     iSongNameAvailable = false;
   641 
   599     if(aMetaData)
   642 /*
   600     {
   643  * Description : update station name and category according to the information in preset
   601         iSongName->setPlainText(aMetaData->getSongName());
   644  */
   602         iArtistName->setPlainText(aMetaData->getArtistName());
   645 void IRNowPlayingView::updateStationInfo()
   603         if(!aMetaData->getSongName().isEmpty() ||
   646 {
   604            !aMetaData->getArtistName().isEmpty())
   647     IRQPreset *nowPlayingPreset = iPlayController->getNowPlayingPreset();
   605         {
   648     const QString &stationName = nowPlayingPreset->name;
   606             iSongNameAvailable = true;
   649     iNowPlayingContainer->setStationName(stationName);
   607         }
   650 
   608     }
   651     QString category = nowPlayingPreset->genreName + " / "
   609     else
   652             + nowPlayingPreset->countryName + " / "
   610     {
   653             + nowPlayingPreset->languageName;
   611         iSongName->setPlainText("");
   654     if (" /  / " == category)
   612         iArtistName->setPlainText("");  
   655     {
   613     }
   656         category = "";
   614 }
   657     }
   615 
   658     iNowPlayingContainer->setCategory(category);
   616 /********************************************************************************************************
   659 }
   617  * SLOT for Media Key
   660 
   618  *******************************************************************************************************
   661 /*
   619  */
   662  * Description : Update advertisement image
   620 void IRNowPlayingView::handlePlayPauseMediaKey()
   663  */
   621 {
   664 void IRNowPlayingView::updateAdvImage()
   622     iPlayController->resume();
   665 {
   623 }
   666     // TODO: in the future, it should judge the change of advertisement url
   624 
   667     if (ELogoDetermined == iLogoStatus || ERequestIssued == iLogoStatus)
   625 void IRNowPlayingView::handleStopMediaKey()
   668     {
   626 {
   669         return;
   627     iPlayController->stop(EIRQUserTerminated);
   670     }
   628 }
   671 
   629 
   672     IRQPreset *nowPlayingPreset = iPlayController->getNowPlayingPreset();
   630 /********************************************************************************************************
   673 
   631  * SLOT for Toolbar Action
   674     // TODO: initialize adv, in the future it will use default adv image
   632  *******************************************************************************************************
   675     QIcon icon(":/playback/default_cd.png");
   633  */
   676     HbIcon hbIcon(icon);
   634 void IRNowPlayingView::handleMusicStoreAction()
   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 {
   635 {
   769     if(!iFindinNmsAllowed)
   636     if(!iFindinNmsAllowed)
   770     {
   637     {
   771         popupNote(hbTrId("txt_irad_info_disallowed_by_this_station"), HbMessageBox::MessageTypeInformation);
   638         popupNote(hbTrId("txt_irad_info_disallowed_by_this_station"), HbMessageBox::MessageTypeInformation);
   772         return;        
   639         return;        
   775     if(!iSongNameAvailable)
   642     if(!iSongNameAvailable)
   776     {
   643     {
   777         popupNote(hbTrId("txt_irad_info_no_song_info"), HbMessageBox::MessageTypeInformation);
   644         popupNote(hbTrId("txt_irad_info_no_song_info"), HbMessageBox::MessageTypeInformation);
   778         return;        
   645         return;        
   779     }
   646     }
   780         
   647     
   781     if(NULL == iMusicShop)
   648     // Need to log the find song in NMS event, iStatisticsReporter->logNmsEvent(IRQStatisticsReporter::EIRFind,channelId);   
   782     {
   649     popupNote(hbTrId("txt_irad_info_music_store_not_available"), HbMessageBox::MessageTypeInformation);
   783         popupNote(hbTrId("txt_irad_info_music_shop_not_available"), HbMessageBox::MessageTypeInformation);
   650 }
       
   651 
       
   652 void IRNowPlayingView::handleIdentifySongAction()
       
   653 {
       
   654     if(IRQUtility::openSongRecognition())
       
   655     {
       
   656         iStatisticsReporter->logSongRecogEvent();
       
   657     }
       
   658 }
       
   659 
       
   660 
       
   661 void IRNowPlayingView::handlePlayStopAction()
       
   662 {
       
   663     setUseNetworkReason(EIR_UseNetwork_PlayStation);
       
   664     if (false == iApplication->verifyNetworkConnectivity())
       
   665     {
   784         return;
   666         return;
   785     }
   667     }
   786     
   668     setUseNetworkReason(EIR_UseNetwork_NoReason);
   787     IRQMetaData *metaData = iPlayController->getMetaData();
   669     
   788     if( iMusicShop->findInMusicShop(metaData->getSongName(), metaData->getArtistName()))
   670     if (iPlayController->isPlaying())
   789     {
   671     {
   790         if(iStatisticsReporter)
   672         iPlayController->stop(EIRQUserTerminated);
   791         {
   673     }
   792             int channelId = iPlayController->getNowPlayingPreset()->presetId;
   674     else
   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     {
   675     {
   811         iPlayController->resume();
   676         iPlayController->resume();
   812     }
   677     }
   813 }
   678 }
   814 
   679 
   815 void IRNowPlayingView::gotoMusicStore()
   680 void IRNowPlayingView::handleAddToFavAction()
   816 {
   681 {
   817     if(IRQMusicShop::launchMusicShop())
   682     IRQPreset *nowPlayingPreset = iPlayController->getNowPlayingPreset();
   818     {
   683     int retValue = iFavorites->addPreset(*nowPlayingPreset);
   819         if(iStatisticsReporter)
   684     HbNotificationDialog *add2FavNote = new HbNotificationDialog();
   820         {
   685     add2FavNote->setModal(true);
   821             int channelId = 0;
   686     add2FavNote->setAttribute(Qt::WA_DeleteOnClose);
   822             if(iPlayController)
   687     switch (retValue)
   823             {
   688     {
   824                 IRQPreset *preset = iPlayController->getNowPlayingPreset();
   689     case EIRQErrorNone:
   825                 if(preset)
   690         add2FavNote->setTitle(hbTrId("txt_irad_info_added_to_favorites"));
   826                 {
   691         //add2FavNote->setIcon(HbIcon( QString("qtg_large_ok")));
   827                     channelId = preset->presetId;
   692         add2FavNote->show();
   828                 }	      
   693         break;
   829             }            
   694 
   830             iStatisticsReporter->logNmsEvent(EIRQLaunch,channelId);
   695     case EIRQErrorOutOfMemory:
   831         }        
   696         add2FavNote->setTitle(hbTrId("txt_irad_info_can_not_add_more"));
   832     }
   697         //add2FavNote->setIcon(HbIcon( QString("qtg_large_ok")));
   833     else
   698         add2FavNote->show();        
   834     {
   699         break;
   835         popupNote(hbTrId("txt_irad_info_music_shop_not_available"), HbMessageBox::MessageTypeInformation);
   700 
   836     }
   701     case EIRQErrorAlreadyExist:
   837 }
   702         add2FavNote->setTitle(hbTrId("txt_irad_info_favorite_updated"));
   838 
   703         //add2FavNote->setIcon(HbIcon( QString("qtg_large_ok")));
   839 void IRNowPlayingView::updateMusicStatus()
   704         add2FavNote->show();           
   840 {
   705         break;
   841     IRQPreset *preset = iPlayController->getNowPlayingPreset();
   706 
   842     if(preset && (0 == preset->musicStoreStatus.compare("yes",Qt::CaseInsensitive)))
   707     default:
   843     {
   708         Q_ASSERT(false);
   844         iFindinNmsAllowed = true;
   709         break;
   845     }
   710     }
   846     else
   711 }
   847     {
   712 
   848         iFindinNmsAllowed = false;
   713 void IRNowPlayingView::handleDetailInfoAction()
   849     }
   714 {
   850 }
   715     getViewManager()->activateView(EIRView_StationDetailsView);
   851 
   716     IRStationDetailsView *channelHistoryView = static_cast<IRStationDetailsView*>(getViewManager()->getView(EIRView_StationDetailsView));
   852 void IRNowPlayingView::recognizeSong()
   717     channelHistoryView->setDetails();
   853 {
   718 
   854     if(IRQMusicShop::launchShazam())
   719 }
   855     {
   720 
   856         if(iStatisticsReporter)
   721 /********************************************************************************************************
   857         {           
   722  * SLOT for Menu Action
   858             iStatisticsReporter->logSongRecogEvent();    
   723  *******************************************************************************************************
   859         }   
   724  */
   860     }
   725 void IRNowPlayingView::handleGoToStationAction()
   861     else
   726 {
   862     {
   727     getViewManager()->activateView(EIRView_OpenWebAddressView);
   863         popupNote(hbTrId("txt_irad_info_song_recognition_not_available"), HbMessageBox::MessageTypeInformation);
   728 }
       
   729 
       
   730 void IRNowPlayingView::handleShareStationAction()
       
   731 {
       
   732     IRStationShare stationShare;
       
   733     stationShare.shareStations(*iPlayController->getNowPlayingPreset());
       
   734 }
       
   735 
       
   736 void IRNowPlayingView::handleSettingAction()
       
   737 {
       
   738     getViewManager()->activateView(EIRView_SettingsView);
       
   739 }
       
   740 
       
   741 #ifdef ADV_ENABLED
       
   742 void IRNowPlayingView::mousePressEvent(QGraphicsSceneMouseEvent *aEvent)
       
   743 {
       
   744     QRectF advRect = iAdvImage->geometry();
       
   745     QPointF pos = aEvent->pos();
       
   746     
       
   747     if (advRect.contains(pos))
       
   748     {
       
   749         openAdvLink();
   864     }
   750     }
   865 }
   751 }
   866 
   752 
   867 void IRNowPlayingView::openAdvLink()
   753 void IRNowPlayingView::openAdvLink()
   868 {
   754 {
   869     IRQUtility::openAdvLink(iAdvClickThroughUrl);
   755     IRQUtility::openAdvLink(iAdvUrl);
   870 }
   756 }
   871 void IRNowPlayingView::shareStationViaMms()
   757 #endif
   872 {
   758 
   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 }