qtinternetradio/ui/src/irnowplayingview.cpp
changeset 12 608f67c22514
parent 11 f683e24efca3
child 14 896e9dbc5f19
--- a/qtinternetradio/ui/src/irnowplayingview.cpp	Wed Jun 23 18:04:00 2010 +0300
+++ b/qtinternetradio/ui/src/irnowplayingview.cpp	Tue Jul 06 14:07:20 2010 +0300
@@ -19,6 +19,7 @@
 #include <hbaction.h>
 #include <hblabel.h>
 #include <hbnotificationdialog.h>
+#include <QSettings>
 
 #ifdef NOWPLAYING_VIEW_OPTION_B
 #include <hbframedrawer.h>
@@ -45,6 +46,7 @@
 #include "irqlogger.h"
 #include "irplaylist.h"
 #include "irstationdetailsview.h"
+#include "irservicedef.h"
 
 #ifdef ADV_ENABLED
 #include <QTimer>
@@ -61,6 +63,9 @@
 static const QString KLcdGraphics("qtg_fr_lcd");
 #endif
 
+
+static void saveStationLogo(const QPixmap &aStationLogo);
+
 /*
  * Description : constructor
  */
@@ -215,10 +220,16 @@
  */
 void IRNowPlayingView::updateWidgets()
 {
+    if (iLaunchActionNeeded) // if lunch as starting view, leave the update action to launchAction()
+    {
+        return;
+    }
+    
     if(iPlayController->getNowPlayingPreset())
     {
         iStationName->setPlainText(iPlayController->getNowPlayingPreset()->name);
     }
+    loadStationLogo();
 }
 
 void IRNowPlayingView::updateMusicStoreStatus()
@@ -331,6 +342,7 @@
         connect(iIsdsClient, SIGNAL(presetLogoDownloaded(IRQPreset* )),
                 this, SLOT(handleLogoDownloaded(IRQPreset* )));
         updateStationLogo();
+        getViewManager()->saveScreenShot();
         break;
         
     case EIR_ViewCommand_DEACTIVATE:
@@ -355,14 +367,19 @@
 void IRNowPlayingView::launchAction()
 {      
     setUseNetworkReason(EIR_UseNetwork_StartingView);
+    updateForLauchAction();
+#ifdef HS_WIDGET_ENABLED	
+    iPlayController->setConnectingStationName(iStationName->plainText());
+#endif	
     iApplication->verifyNetworkConnectivity();
     getViewManager()->pushViewById(EIRView_MainView);
-    iLaunchActionNeeded = true;
-    updateForLauchAction();
+    iLaunchActionNeeded = false;
 }
 
 void IRNowPlayingView::lazyInit()
 {
+    iLaunchActionNeeded = true;
+    
     if (!initCompleted())
     {       
         normalInit();
@@ -408,22 +425,33 @@
         IRQPreset *preset = playList->getPresetForEntry(0);
         iStationName->setPlainText(preset->name);
         iFindinNmsAllowed = (0 == preset->musicStoreStatus.compare("yes",Qt::CaseInsensitive));
+#ifdef HS_WIDGET_ENABLED            
+        iPlayController->reloadNowplayingPreset(preset,false,EIRQAdhocExternal);
+#endif
+        iStationLogo->setIcon(HbIcon(KDefaultStationLogo));
+        iLogoNeedUpdate = true;            
+#ifdef ADV_ENABLED
+        iAdvUrl = KDefaultAdvLink; 
+        iAdvImage->setIcon(logoHbIcon);
+        iAdvImageNeedUpdate = true;  
+#endif
         delete preset;
     }
     else
     {
         IRLastPlayedStationInfo *lastPlayedStationInfo = iApplication->getLastPlayedStationInfo();
         IRQPreset *lastPreset = lastPlayedStationInfo->getLastPlayedStation();
-        
         if (lastPreset)
         {
             iStationName->setPlainText(lastPreset->name); 
-            iFindinNmsAllowed = (0 == lastPreset->musicStoreStatus.compare("yes",Qt::CaseInsensitive)); 
+            iFindinNmsAllowed = (0 == lastPreset->musicStoreStatus.compare("yes",Qt::CaseInsensitive));
         }
         else
         {
+            iStationName->setPlainText(QString("")); 
             iFindinNmsAllowed = false;
         }
+        loadStationLogo();
     }
 }
 
@@ -464,13 +492,16 @@
     if( logoPixmap.loadFromData(logoRawData, aPreset->logoData.Length()) )
     {
         if( EDownloadLogo == iLogoDownloadState )
-        {
+        {		
+            saveStationLogo(logoPixmap);
             QPixmap newLogoPixmap = 
-                 logoPixmap.scaled(QSize(KNowPlayingLogoSize,KNowPlayingLogoSize),Qt::KeepAspectRatio);      
+                 logoPixmap.scaled(QSize(KNowPlayingLogoSize,KNowPlayingLogoSize),Qt::KeepAspectRatio);
             QIcon logoQIcon(newLogoPixmap);
             HbIcon logoHbIcon(logoQIcon);
-            iStationLogo->setIcon(logoHbIcon);        
+            iStationLogo->setIcon(logoHbIcon);
+            iPlayController->emitStationLogoUpdated(true);
             iLogoNeedUpdate = false;          
+            getViewManager()->saveScreenShot();
 #ifdef ADV_ENABLED
             QTimer::singleShot(1, this, SLOT(updateAdvImage()));
 #endif
@@ -547,7 +578,7 @@
             }
             else if( EIR_UseNetwork_PlayStation == getUseNetworkReason() )
             {
-                handlePlayStopAction();
+                iPlayController->resume();
             }
             break;
         }
@@ -581,11 +612,6 @@
  */
 void IRNowPlayingView::handlePlayStarted()
 {
-    if(iLaunchActionNeeded)
-    {
-        iLaunchActionNeeded = false;
-        updateStationLogo();
-    }
     iPlayStopAction->setIcon(HbIcon(KStopButtonIcon));
 }
 
@@ -595,17 +621,6 @@
     iSongName->setPlainText("");
     iArtistName->setPlainText("");
     iSongNameAvailable = false;
-        
-    if( this != getViewManager()->currentView() )
-    {
-        iStationLogo->setIcon(HbIcon(KDefaultStationLogo));
-        iLogoNeedUpdate = true;
-#ifdef ADV_ENABLED
-        iAdvUrl = KDefaultAdvLink;
-        iAdvImage->setIcon(HbIcon(KDefaultStationLogo));
-        iAdvImageNeedUpdate = true;  
-#endif        
-    }
 }
 
 void IRNowPlayingView::updateMetaData(IRQMetaData* aMetaData)
@@ -650,7 +665,11 @@
 {
     if(!iFindinNmsAllowed)
     {
-        popupNote(hbTrId("txt_irad_info_disallowed_by_this_station"), HbMessageBox::MessageTypeInformation);
+#ifdef SUBTITLE_STR_BY_LOCID
+        popupNote(hbTrId("txt_irad_info_not_allowed_by_this_station"), HbMessageBox::MessageTypeInformation);
+#else
+        popupNote(hbTrId("Not allowed by this station"), HbMessageBox::MessageTypeInformation);        
+#endif
         return;        
     }
     
@@ -660,8 +679,12 @@
         return;        
     }
     
-    // Need to log the find song in NMS event, iStatisticsReporter->logNmsEvent(IRQStatisticsReporter::EIRFind,channelId);   
+    // Need to log the find song in NMS event, iStatisticsReporter->logNmsEvent(IRQStatisticsReporter::EIRFind,channelId); 
+#ifdef SUBTITLE_STR_BY_LOCID
     popupNote(hbTrId("txt_irad_info_music_store_not_available"), HbMessageBox::MessageTypeInformation);
+#else
+    popupNote(hbTrId("Music store not available"), HbMessageBox::MessageTypeInformation);    
+#endif
 }
 
 void IRNowPlayingView::handleIdentifySongAction()
@@ -675,27 +698,28 @@
 
 void IRNowPlayingView::handlePlayStopAction()
 {
-    if(iPlayController->isIdle())
+    switch (iPlayController->state())
     {
-        setUseNetworkReason(EIR_UseNetwork_StartingView);
-    }
-    else
-    {
-        setUseNetworkReason(EIR_UseNetwork_PlayStation);
+        case IRPlayController::EPlaying:
+            iPlayController->stop(EIRQUserTerminated);
+            return;
+                    
+        case IRPlayController::EStopped:
+            setUseNetworkReason(EIR_UseNetwork_PlayStation);
+            break;
+            
+        default:
+            return;
     }
     
-    if (false == iApplication->verifyNetworkConnectivity())
+ 
+#ifdef HS_WIDGET_ENABLED		
+    iPlayController->setConnectingStationName(iStationName->plainText());         
+#endif
+		
+    if (iApplication->verifyNetworkConnectivity())
     {
-        return;
-    }
-    setUseNetworkReason(EIR_UseNetwork_NoReason);
-    
-    if (iPlayController->isPlaying())
-    {
-        iPlayController->stop(EIRQUserTerminated);
-    }
-    else
-    {
+        setUseNetworkReason(EIR_UseNetwork_NoReason);
         iPlayController->resume();
     }
 }
@@ -710,19 +734,31 @@
     switch (retValue)
     {
     case EIRQErrorNone:
+#ifdef SUBTITLE_STR_BY_LOCID       
         add2FavNote->setTitle(hbTrId("txt_irad_info_added_to_favorites"));
+#else
+        add2FavNote->setTitle(hbTrId("Added to Favorites"));         
+#endif
         //add2FavNote->setIcon(HbIcon( QString("qtg_large_ok")));
         add2FavNote->show();
         break;
 
     case EIRQErrorOutOfMemory:
+#ifdef SUBTITLE_STR_BY_LOCID 
         add2FavNote->setTitle(hbTrId("txt_irad_info_can_not_add_more"));
+#else
+        add2FavNote->setTitle(hbTrId("Can't add more"));        
+#endif
         //add2FavNote->setIcon(HbIcon( QString("qtg_large_ok")));
         add2FavNote->show();        
         break;
 
     case EIRQErrorAlreadyExist:
+#ifdef SUBTITLE_STR_BY_LOCID 
         add2FavNote->setTitle(hbTrId("txt_irad_info_favorite_updated"));
+#else
+        add2FavNote->setTitle(hbTrId("Favorite updated"));        
+#endif
         //add2FavNote->setIcon(HbIcon( QString("qtg_large_ok")));
         add2FavNote->show();           
         break;
@@ -782,3 +818,42 @@
 }
 #endif
 
+void IRNowPlayingView::loadStationLogo()
+{
+    if (iPlayController->isStationLogoAvailable())    
+    { 
+        QSettings settings(KIrSettingOrganization, KIrSettingApplication);
+        if (settings.value(KIrSettingStationLogo).canConvert<QPixmap>())
+        {
+            QPixmap logoPixmap = settings.value(KIrSettingStationLogo).value<QPixmap>();
+            QPixmap newLogoPixmap = 
+                 logoPixmap.scaled(QSize(KNowPlayingLogoSize,KNowPlayingLogoSize),Qt::KeepAspectRatio);
+            QIcon logoQIcon(newLogoPixmap);
+            HbIcon logoHbIcon(logoQIcon);
+            iStationLogo->setIcon(logoHbIcon);
+            iLogoNeedUpdate = false;            
+#ifdef ADV_ENABLED
+            iAdvUrl = iPlayController->getNowPlayingPreset()->advertisementUrl; 
+            iAdvImage->setIcon(logoHbIcon);
+            iAdvImageNeedUpdate = false;  
+#endif            	
+            return;
+        }  
+    }
+
+    iStationLogo->setIcon(HbIcon(KDefaultStationLogo));
+    iLogoNeedUpdate = true;            
+#ifdef ADV_ENABLED
+    iAdvUrl = KDefaultAdvLink; 
+    iAdvImage->setIcon(logoHbIcon);
+    iAdvImageNeedUpdate = true;  
+#endif
+}
+
+void saveStationLogo(const QPixmap &aStationLogo)
+{
+    QSettings settings(KIrSettingOrganization, KIrSettingApplication);
+    QVariant logoData(QVariant::Pixmap);
+    logoData.setValue(aStationLogo);
+    settings.setValue(KIrSettingStationLogo,logoData);    
+}