qtinternetradio/ui/src/irnowplayingview.cpp
changeset 12 608f67c22514
parent 11 f683e24efca3
child 14 896e9dbc5f19
equal deleted inserted replaced
11:f683e24efca3 12:608f67c22514
    17 #include <hbtoolbar.h>
    17 #include <hbtoolbar.h>
    18 #include <QPixmap>
    18 #include <QPixmap>
    19 #include <hbaction.h>
    19 #include <hbaction.h>
    20 #include <hblabel.h>
    20 #include <hblabel.h>
    21 #include <hbnotificationdialog.h>
    21 #include <hbnotificationdialog.h>
       
    22 #include <QSettings>
    22 
    23 
    23 #ifdef NOWPLAYING_VIEW_OPTION_B
    24 #ifdef NOWPLAYING_VIEW_OPTION_B
    24 #include <hbframedrawer.h>
    25 #include <hbframedrawer.h>
    25 #include <hbframeitem.h>
    26 #include <hbframeitem.h>
    26 #endif
    27 #endif
    43 #include "irstationshare.h"
    44 #include "irstationshare.h"
    44 #include "irqutility.h"
    45 #include "irqutility.h"
    45 #include "irqlogger.h"
    46 #include "irqlogger.h"
    46 #include "irplaylist.h"
    47 #include "irplaylist.h"
    47 #include "irstationdetailsview.h"
    48 #include "irstationdetailsview.h"
       
    49 #include "irservicedef.h"
    48 
    50 
    49 #ifdef ADV_ENABLED
    51 #ifdef ADV_ENABLED
    50 #include <QTimer>
    52 #include <QTimer>
    51 #include <qgraphicssceneevent.h>
    53 #include <qgraphicssceneevent.h>
    52 static const QString KDefaultAdvLink(""); // default advertisement link
    54 static const QString KDefaultAdvLink(""); // default advertisement link
    58 static const QString KStopButtonIcon("qtg_mono_stop");
    60 static const QString KStopButtonIcon("qtg_mono_stop");
    59 
    61 
    60 #ifdef NOWPLAYING_VIEW_OPTION_B
    62 #ifdef NOWPLAYING_VIEW_OPTION_B
    61 static const QString KLcdGraphics("qtg_fr_lcd");
    63 static const QString KLcdGraphics("qtg_fr_lcd");
    62 #endif
    64 #endif
       
    65 
       
    66 
       
    67 static void saveStationLogo(const QPixmap &aStationLogo);
    63 
    68 
    64 /*
    69 /*
    65  * Description : constructor
    70  * Description : constructor
    66  */
    71  */
    67 IRNowPlayingView::IRNowPlayingView(IRApplication* aApplication, TIRViewId aViewId) :
    72 IRNowPlayingView::IRNowPlayingView(IRApplication* aApplication, TIRViewId aViewId) :
   213 /*
   218 /*
   214  * Description : update station name and category according to the information in preset
   219  * Description : update station name and category according to the information in preset
   215  */
   220  */
   216 void IRNowPlayingView::updateWidgets()
   221 void IRNowPlayingView::updateWidgets()
   217 {
   222 {
       
   223     if (iLaunchActionNeeded) // if lunch as starting view, leave the update action to launchAction()
       
   224     {
       
   225         return;
       
   226     }
       
   227     
   218     if(iPlayController->getNowPlayingPreset())
   228     if(iPlayController->getNowPlayingPreset())
   219     {
   229     {
   220         iStationName->setPlainText(iPlayController->getNowPlayingPreset()->name);
   230         iStationName->setPlainText(iPlayController->getNowPlayingPreset()->name);
   221     }
   231     }
       
   232     loadStationLogo();
   222 }
   233 }
   223 
   234 
   224 void IRNowPlayingView::updateMusicStoreStatus()
   235 void IRNowPlayingView::updateMusicStoreStatus()
   225 {
   236 {
   226     IRQPreset *preset = iPlayController->getNowPlayingPreset();
   237     IRQPreset *preset = iPlayController->getNowPlayingPreset();
   329 
   340 
   330     case EIR_ViewCommand_ACTIVATED:
   341     case EIR_ViewCommand_ACTIVATED:
   331         connect(iIsdsClient, SIGNAL(presetLogoDownloaded(IRQPreset* )),
   342         connect(iIsdsClient, SIGNAL(presetLogoDownloaded(IRQPreset* )),
   332                 this, SLOT(handleLogoDownloaded(IRQPreset* )));
   343                 this, SLOT(handleLogoDownloaded(IRQPreset* )));
   333         updateStationLogo();
   344         updateStationLogo();
       
   345         getViewManager()->saveScreenShot();
   334         break;
   346         break;
   335         
   347         
   336     case EIR_ViewCommand_DEACTIVATE:
   348     case EIR_ViewCommand_DEACTIVATE:
   337         if( iLogoDownloadState != EIdle )
   349         if( iLogoDownloadState != EIdle )
   338         {
   350         {
   353  * Description : actions when view is launched.
   365  * Description : actions when view is launched.
   354  */
   366  */
   355 void IRNowPlayingView::launchAction()
   367 void IRNowPlayingView::launchAction()
   356 {      
   368 {      
   357     setUseNetworkReason(EIR_UseNetwork_StartingView);
   369     setUseNetworkReason(EIR_UseNetwork_StartingView);
       
   370     updateForLauchAction();
       
   371 #ifdef HS_WIDGET_ENABLED	
       
   372     iPlayController->setConnectingStationName(iStationName->plainText());
       
   373 #endif	
   358     iApplication->verifyNetworkConnectivity();
   374     iApplication->verifyNetworkConnectivity();
   359     getViewManager()->pushViewById(EIRView_MainView);
   375     getViewManager()->pushViewById(EIRView_MainView);
       
   376     iLaunchActionNeeded = false;
       
   377 }
       
   378 
       
   379 void IRNowPlayingView::lazyInit()
       
   380 {
   360     iLaunchActionNeeded = true;
   381     iLaunchActionNeeded = true;
   361     updateForLauchAction();
   382     
   362 }
       
   363 
       
   364 void IRNowPlayingView::lazyInit()
       
   365 {
       
   366     if (!initCompleted())
   383     if (!initCompleted())
   367     {       
   384     {       
   368         normalInit();
   385         normalInit();
   369         
   386         
   370         //initization from handleCommand()
   387         //initization from handleCommand()
   406     if (playList && 1 == playList->getNumberOfEntries())
   423     if (playList && 1 == playList->getNumberOfEntries())
   407     {
   424     {
   408         IRQPreset *preset = playList->getPresetForEntry(0);
   425         IRQPreset *preset = playList->getPresetForEntry(0);
   409         iStationName->setPlainText(preset->name);
   426         iStationName->setPlainText(preset->name);
   410         iFindinNmsAllowed = (0 == preset->musicStoreStatus.compare("yes",Qt::CaseInsensitive));
   427         iFindinNmsAllowed = (0 == preset->musicStoreStatus.compare("yes",Qt::CaseInsensitive));
       
   428 #ifdef HS_WIDGET_ENABLED            
       
   429         iPlayController->reloadNowplayingPreset(preset,false,EIRQAdhocExternal);
       
   430 #endif
       
   431         iStationLogo->setIcon(HbIcon(KDefaultStationLogo));
       
   432         iLogoNeedUpdate = true;            
       
   433 #ifdef ADV_ENABLED
       
   434         iAdvUrl = KDefaultAdvLink; 
       
   435         iAdvImage->setIcon(logoHbIcon);
       
   436         iAdvImageNeedUpdate = true;  
       
   437 #endif
   411         delete preset;
   438         delete preset;
   412     }
   439     }
   413     else
   440     else
   414     {
   441     {
   415         IRLastPlayedStationInfo *lastPlayedStationInfo = iApplication->getLastPlayedStationInfo();
   442         IRLastPlayedStationInfo *lastPlayedStationInfo = iApplication->getLastPlayedStationInfo();
   416         IRQPreset *lastPreset = lastPlayedStationInfo->getLastPlayedStation();
   443         IRQPreset *lastPreset = lastPlayedStationInfo->getLastPlayedStation();
   417         
       
   418         if (lastPreset)
   444         if (lastPreset)
   419         {
   445         {
   420             iStationName->setPlainText(lastPreset->name); 
   446             iStationName->setPlainText(lastPreset->name); 
   421             iFindinNmsAllowed = (0 == lastPreset->musicStoreStatus.compare("yes",Qt::CaseInsensitive)); 
   447             iFindinNmsAllowed = (0 == lastPreset->musicStoreStatus.compare("yes",Qt::CaseInsensitive));
   422         }
   448         }
   423         else
   449         else
   424         {
   450         {
       
   451             iStationName->setPlainText(QString("")); 
   425             iFindinNmsAllowed = false;
   452             iFindinNmsAllowed = false;
   426         }
   453         }
       
   454         loadStationLogo();
   427     }
   455     }
   428 }
   456 }
   429 
   457 
   430 /********************************************************************************************************
   458 /********************************************************************************************************
   431  * SLOTs for Logo Download
   459  * SLOTs for Logo Download
   462     const unsigned char * logoRawData = aPreset->logoData.Ptr();
   490     const unsigned char * logoRawData = aPreset->logoData.Ptr();
   463     QPixmap logoPixmap;
   491     QPixmap logoPixmap;
   464     if( logoPixmap.loadFromData(logoRawData, aPreset->logoData.Length()) )
   492     if( logoPixmap.loadFromData(logoRawData, aPreset->logoData.Length()) )
   465     {
   493     {
   466         if( EDownloadLogo == iLogoDownloadState )
   494         if( EDownloadLogo == iLogoDownloadState )
   467         {
   495         {		
       
   496             saveStationLogo(logoPixmap);
   468             QPixmap newLogoPixmap = 
   497             QPixmap newLogoPixmap = 
   469                  logoPixmap.scaled(QSize(KNowPlayingLogoSize,KNowPlayingLogoSize),Qt::KeepAspectRatio);      
   498                  logoPixmap.scaled(QSize(KNowPlayingLogoSize,KNowPlayingLogoSize),Qt::KeepAspectRatio);
   470             QIcon logoQIcon(newLogoPixmap);
   499             QIcon logoQIcon(newLogoPixmap);
   471             HbIcon logoHbIcon(logoQIcon);
   500             HbIcon logoHbIcon(logoQIcon);
   472             iStationLogo->setIcon(logoHbIcon);        
   501             iStationLogo->setIcon(logoHbIcon);
       
   502             iPlayController->emitStationLogoUpdated(true);
   473             iLogoNeedUpdate = false;          
   503             iLogoNeedUpdate = false;          
       
   504             getViewManager()->saveScreenShot();
   474 #ifdef ADV_ENABLED
   505 #ifdef ADV_ENABLED
   475             QTimer::singleShot(1, this, SLOT(updateAdvImage()));
   506             QTimer::singleShot(1, this, SLOT(updateAdvImage()));
   476 #endif
   507 #endif
   477         }
   508         }
   478 #ifdef ADV_ENABLED      
   509 #ifdef ADV_ENABLED      
   545                     }
   576                     }
   546                 }
   577                 }
   547             }
   578             }
   548             else if( EIR_UseNetwork_PlayStation == getUseNetworkReason() )
   579             else if( EIR_UseNetwork_PlayStation == getUseNetworkReason() )
   549             {
   580             {
   550                 handlePlayStopAction();
   581                 iPlayController->resume();
   551             }
   582             }
   552             break;
   583             break;
   553         }
   584         }
   554     default:
   585     default:
   555         break;
   586         break;
   579  * SLOT for Play Controller
   610  * SLOT for Play Controller
   580  *******************************************************************************************************
   611  *******************************************************************************************************
   581  */
   612  */
   582 void IRNowPlayingView::handlePlayStarted()
   613 void IRNowPlayingView::handlePlayStarted()
   583 {
   614 {
   584     if(iLaunchActionNeeded)
       
   585     {
       
   586         iLaunchActionNeeded = false;
       
   587         updateStationLogo();
       
   588     }
       
   589     iPlayStopAction->setIcon(HbIcon(KStopButtonIcon));
   615     iPlayStopAction->setIcon(HbIcon(KStopButtonIcon));
   590 }
   616 }
   591 
   617 
   592 void IRNowPlayingView::handlePlayStopped()
   618 void IRNowPlayingView::handlePlayStopped()
   593 {
   619 {
   594     iPlayStopAction->setIcon(HbIcon(KPlayButtonIcon));
   620     iPlayStopAction->setIcon(HbIcon(KPlayButtonIcon));
   595     iSongName->setPlainText("");
   621     iSongName->setPlainText("");
   596     iArtistName->setPlainText("");
   622     iArtistName->setPlainText("");
   597     iSongNameAvailable = false;
   623     iSongNameAvailable = false;
   598         
       
   599     if( this != getViewManager()->currentView() )
       
   600     {
       
   601         iStationLogo->setIcon(HbIcon(KDefaultStationLogo));
       
   602         iLogoNeedUpdate = true;
       
   603 #ifdef ADV_ENABLED
       
   604         iAdvUrl = KDefaultAdvLink;
       
   605         iAdvImage->setIcon(HbIcon(KDefaultStationLogo));
       
   606         iAdvImageNeedUpdate = true;  
       
   607 #endif        
       
   608     }
       
   609 }
   624 }
   610 
   625 
   611 void IRNowPlayingView::updateMetaData(IRQMetaData* aMetaData)
   626 void IRNowPlayingView::updateMetaData(IRQMetaData* aMetaData)
   612 {
   627 {
   613     iSongNameAvailable = false;
   628     iSongNameAvailable = false;
   648  */
   663  */
   649 void IRNowPlayingView::handleMusicStoreAction()
   664 void IRNowPlayingView::handleMusicStoreAction()
   650 {
   665 {
   651     if(!iFindinNmsAllowed)
   666     if(!iFindinNmsAllowed)
   652     {
   667     {
   653         popupNote(hbTrId("txt_irad_info_disallowed_by_this_station"), HbMessageBox::MessageTypeInformation);
   668 #ifdef SUBTITLE_STR_BY_LOCID
       
   669         popupNote(hbTrId("txt_irad_info_not_allowed_by_this_station"), HbMessageBox::MessageTypeInformation);
       
   670 #else
       
   671         popupNote(hbTrId("Not allowed by this station"), HbMessageBox::MessageTypeInformation);        
       
   672 #endif
   654         return;        
   673         return;        
   655     }
   674     }
   656     
   675     
   657     if(!iSongNameAvailable)
   676     if(!iSongNameAvailable)
   658     {
   677     {
   659         popupNote(hbTrId("txt_irad_info_no_song_info"), HbMessageBox::MessageTypeInformation);
   678         popupNote(hbTrId("txt_irad_info_no_song_info"), HbMessageBox::MessageTypeInformation);
   660         return;        
   679         return;        
   661     }
   680     }
   662     
   681     
   663     // Need to log the find song in NMS event, iStatisticsReporter->logNmsEvent(IRQStatisticsReporter::EIRFind,channelId);   
   682     // Need to log the find song in NMS event, iStatisticsReporter->logNmsEvent(IRQStatisticsReporter::EIRFind,channelId); 
       
   683 #ifdef SUBTITLE_STR_BY_LOCID
   664     popupNote(hbTrId("txt_irad_info_music_store_not_available"), HbMessageBox::MessageTypeInformation);
   684     popupNote(hbTrId("txt_irad_info_music_store_not_available"), HbMessageBox::MessageTypeInformation);
       
   685 #else
       
   686     popupNote(hbTrId("Music store not available"), HbMessageBox::MessageTypeInformation);    
       
   687 #endif
   665 }
   688 }
   666 
   689 
   667 void IRNowPlayingView::handleIdentifySongAction()
   690 void IRNowPlayingView::handleIdentifySongAction()
   668 {
   691 {
   669     if(IRQUtility::openSongRecognition())
   692     if(IRQUtility::openSongRecognition())
   673 }
   696 }
   674 
   697 
   675 
   698 
   676 void IRNowPlayingView::handlePlayStopAction()
   699 void IRNowPlayingView::handlePlayStopAction()
   677 {
   700 {
   678     if(iPlayController->isIdle())
   701     switch (iPlayController->state())
   679     {
   702     {
   680         setUseNetworkReason(EIR_UseNetwork_StartingView);
   703         case IRPlayController::EPlaying:
   681     }
   704             iPlayController->stop(EIRQUserTerminated);
   682     else
   705             return;
   683     {
   706                     
   684         setUseNetworkReason(EIR_UseNetwork_PlayStation);
   707         case IRPlayController::EStopped:
   685     }
   708             setUseNetworkReason(EIR_UseNetwork_PlayStation);
   686     
   709             break;
   687     if (false == iApplication->verifyNetworkConnectivity())
   710             
   688     {
   711         default:
   689         return;
   712             return;
   690     }
   713     }
   691     setUseNetworkReason(EIR_UseNetwork_NoReason);
   714     
   692     
   715  
   693     if (iPlayController->isPlaying())
   716 #ifdef HS_WIDGET_ENABLED		
   694     {
   717     iPlayController->setConnectingStationName(iStationName->plainText());         
   695         iPlayController->stop(EIRQUserTerminated);
   718 #endif
   696     }
   719 		
   697     else
   720     if (iApplication->verifyNetworkConnectivity())
   698     {
   721     {
       
   722         setUseNetworkReason(EIR_UseNetwork_NoReason);
   699         iPlayController->resume();
   723         iPlayController->resume();
   700     }
   724     }
   701 }
   725 }
   702 
   726 
   703 void IRNowPlayingView::handleAddToFavAction()
   727 void IRNowPlayingView::handleAddToFavAction()
   708     add2FavNote->setModal(true);
   732     add2FavNote->setModal(true);
   709     add2FavNote->setAttribute(Qt::WA_DeleteOnClose);
   733     add2FavNote->setAttribute(Qt::WA_DeleteOnClose);
   710     switch (retValue)
   734     switch (retValue)
   711     {
   735     {
   712     case EIRQErrorNone:
   736     case EIRQErrorNone:
       
   737 #ifdef SUBTITLE_STR_BY_LOCID       
   713         add2FavNote->setTitle(hbTrId("txt_irad_info_added_to_favorites"));
   738         add2FavNote->setTitle(hbTrId("txt_irad_info_added_to_favorites"));
       
   739 #else
       
   740         add2FavNote->setTitle(hbTrId("Added to Favorites"));         
       
   741 #endif
   714         //add2FavNote->setIcon(HbIcon( QString("qtg_large_ok")));
   742         //add2FavNote->setIcon(HbIcon( QString("qtg_large_ok")));
   715         add2FavNote->show();
   743         add2FavNote->show();
   716         break;
   744         break;
   717 
   745 
   718     case EIRQErrorOutOfMemory:
   746     case EIRQErrorOutOfMemory:
       
   747 #ifdef SUBTITLE_STR_BY_LOCID 
   719         add2FavNote->setTitle(hbTrId("txt_irad_info_can_not_add_more"));
   748         add2FavNote->setTitle(hbTrId("txt_irad_info_can_not_add_more"));
       
   749 #else
       
   750         add2FavNote->setTitle(hbTrId("Can't add more"));        
       
   751 #endif
   720         //add2FavNote->setIcon(HbIcon( QString("qtg_large_ok")));
   752         //add2FavNote->setIcon(HbIcon( QString("qtg_large_ok")));
   721         add2FavNote->show();        
   753         add2FavNote->show();        
   722         break;
   754         break;
   723 
   755 
   724     case EIRQErrorAlreadyExist:
   756     case EIRQErrorAlreadyExist:
       
   757 #ifdef SUBTITLE_STR_BY_LOCID 
   725         add2FavNote->setTitle(hbTrId("txt_irad_info_favorite_updated"));
   758         add2FavNote->setTitle(hbTrId("txt_irad_info_favorite_updated"));
       
   759 #else
       
   760         add2FavNote->setTitle(hbTrId("Favorite updated"));        
       
   761 #endif
   726         //add2FavNote->setIcon(HbIcon( QString("qtg_large_ok")));
   762         //add2FavNote->setIcon(HbIcon( QString("qtg_large_ok")));
   727         add2FavNote->show();           
   763         add2FavNote->show();           
   728         break;
   764         break;
   729 
   765 
   730     default:
   766     default:
   780 {
   816 {
   781     IRQUtility::openAdvLink(iAdvUrl);
   817     IRQUtility::openAdvLink(iAdvUrl);
   782 }
   818 }
   783 #endif
   819 #endif
   784 
   820 
       
   821 void IRNowPlayingView::loadStationLogo()
       
   822 {
       
   823     if (iPlayController->isStationLogoAvailable())    
       
   824     { 
       
   825         QSettings settings(KIrSettingOrganization, KIrSettingApplication);
       
   826         if (settings.value(KIrSettingStationLogo).canConvert<QPixmap>())
       
   827         {
       
   828             QPixmap logoPixmap = settings.value(KIrSettingStationLogo).value<QPixmap>();
       
   829             QPixmap newLogoPixmap = 
       
   830                  logoPixmap.scaled(QSize(KNowPlayingLogoSize,KNowPlayingLogoSize),Qt::KeepAspectRatio);
       
   831             QIcon logoQIcon(newLogoPixmap);
       
   832             HbIcon logoHbIcon(logoQIcon);
       
   833             iStationLogo->setIcon(logoHbIcon);
       
   834             iLogoNeedUpdate = false;            
       
   835 #ifdef ADV_ENABLED
       
   836             iAdvUrl = iPlayController->getNowPlayingPreset()->advertisementUrl; 
       
   837             iAdvImage->setIcon(logoHbIcon);
       
   838             iAdvImageNeedUpdate = false;  
       
   839 #endif            	
       
   840             return;
       
   841         }  
       
   842     }
       
   843 
       
   844     iStationLogo->setIcon(HbIcon(KDefaultStationLogo));
       
   845     iLogoNeedUpdate = true;            
       
   846 #ifdef ADV_ENABLED
       
   847     iAdvUrl = KDefaultAdvLink; 
       
   848     iAdvImage->setIcon(logoHbIcon);
       
   849     iAdvImageNeedUpdate = true;  
       
   850 #endif
       
   851 }
       
   852 
       
   853 void saveStationLogo(const QPixmap &aStationLogo)
       
   854 {
       
   855     QSettings settings(KIrSettingOrganization, KIrSettingApplication);
       
   856     QVariant logoData(QVariant::Pixmap);
       
   857     logoData.setValue(aStationLogo);
       
   858     settings.setValue(KIrSettingStationLogo,logoData);    
       
   859 }