qtinternetradio/ui/src/irsonghistoryview.cpp
changeset 3 ee64f059b8e1
parent 2 2e1adbfc62af
child 5 0930554dc389
equal deleted inserted replaced
2:2e1adbfc62af 3:ee64f059b8e1
    18 #include <hbmenu.h>
    18 #include <hbmenu.h>
    19 #include <hbaction.h>
    19 #include <hbaction.h>
    20 #include <hbicon.h>
    20 #include <hbicon.h>
    21 #include <QTimer> 
    21 #include <QTimer> 
    22 
    22 
    23 #include "irabstractviewmanager.h"
    23 #include "irviewmanager.h"
    24 #include "irapplication.h" 
    24 #include "irapplication.h" 
    25 #include "irplaycontroller.h"
    25 #include "irplaycontroller.h"
    26 #include "irsonghistoryview.h" 
    26 #include "irsonghistoryview.h" 
    27 #include "irsonghistorymodel.h"
    27 #include "irsonghistorymodel.h"
    28 #include "irqsonghistoryinfo.h" 
    28 #include "irqsonghistoryinfo.h" 
    29 #include "irqenums.h"
    29 #include "irqenums.h"
    30 #include "irqmusicshop.h"
       
    31 #include "irqstatisticsreporter.h"
    30 #include "irqstatisticsreporter.h"
    32 #include "irqsettings.h"
    31 #include "irqsettings.h"
       
    32 #include "iruidefines.h"
    33 
    33 
    34  
    34  
    35 
    35 
    36 //                                         public functions
    36 //                                         public functions
    37 
    37 
    39  * Description : constructor
    39  * Description : constructor
    40  */
    40  */
    41 IRSongHistoryView::IRSongHistoryView(IRApplication *aApplication, TIRViewId aViewId) :
    41 IRSongHistoryView::IRSongHistoryView(IRApplication *aApplication, TIRViewId aViewId) :
    42     IrAbstractListViewBase(aApplication, aViewId), iClearSongHistoryAction(NULL),
    42     IrAbstractListViewBase(aApplication, aViewId), iClearSongHistoryAction(NULL),
    43     iShowPrompt(false)
    43     iShowPrompt(false)
    44     
       
    45 {         
    44 {         
       
    45     //this view won't be starting view, don't need lazy init
       
    46     IrAbstractListViewBase::lazyInit();
       
    47     setInitCompleted(true);
       
    48         
    46     iModel = new IRSongHistoryModel(this);
    49     iModel = new IRSongHistoryModel(this);
       
    50     iModel->setOrientation(getViewManager()->orientation());
    47     iListView->setModel(iModel);
    51     iListView->setModel(iModel);
    48     iListView->setCurrentIndex(iModel->index(0));
    52     iListView->setCurrentIndex(iModel->index(0));
    49     
    53     
    50     iClearSongHistoryAction = new HbAction(hbTrId("txt_irad_opt_clear_song_history"), this);
    54     iClearSongHistoryAction = new HbAction(hbTrId("txt_irad_opt_clear_song_history"), this);
    51     iMusicShop = iApplication->getMusicShop();
    55     iStatisticsReporter = IRQStatisticsReporter::openInstance();
    52     iStatisticsReporter = iApplication->getStatisticsReporter();
    56     
    53     
       
    54     iStationHistoryAction = new HbAction(hbTrId("txt_irad_opt_recently_played_stations"), this);	 
       
    55     menu()->insertAction(iOpenWebAddressAction, iStationHistoryAction);
       
    56     connect(iStationHistoryAction, SIGNAL(triggered()), this, SLOT(gotoStationHistory()));
       
    57     
    57     
    58     iShowPrompt = iSettings->getSongHistoryShow();    
    58     iShowPrompt = iSettings->getSongHistoryShow();    
    59     if( iShowPrompt )
    59     if( iShowPrompt )
    60     {
    60     {
    61         iSettings->setSongHistoryShow(0);
    61         iSettings->setSongHistoryShow(0);
    68 /* 
    68 /* 
    69  * Description : destructor
    69  * Description : destructor
    70  */
    70  */
    71 IRSongHistoryView::~IRSongHistoryView()
    71 IRSongHistoryView::~IRSongHistoryView()
    72 {
    72 {
    73  
    73     if (iStatisticsReporter)
       
    74     {
       
    75         iStatisticsReporter->closeInstance();
       
    76     }
    74 }
    77 }
    75 
    78 
    76 /*
    79 /*
    77  * Description : virtual functions from base class IRBaseView. 
    80  * Description : virtual functions from base class IRBaseView. 
    78  *               handle view commands
    81  *               handle view commands
   120  * Parameters  : aItem : pointer to the clicked item.
   123  * Parameters  : aItem : pointer to the clicked item.
   121  */
   124  */
   122 void IRSongHistoryView::handleItemSelected()
   125 void IRSongHistoryView::handleItemSelected()
   123 {     
   126 {     
   124     int index = iListView->currentIndex().row();
   127     int index = iListView->currentIndex().row();
   125     IRQSongInfo *hisInfo = iModel->getSongHistoryInfo(index);
   128     IRQSongInfo *hisInfo = iModel->getSongHistoryInfo(index); 
   126      
       
   127 
       
   128     if(NULL == iMusicShop)
       
   129     {
       
   130         popupNote(hbTrId("txt_irad_info_music_shop_not_available"), HbMessageBox::MessageTypeInformation);
       
   131         return;
       
   132     }   
       
   133     
   129     
   134     if( (NULL == hisInfo) ||    
   130     if( (NULL == hisInfo) ||    
   135         ( hisInfo->getSongName().isEmpty() &&  
   131         ( hisInfo->getSongName().isEmpty() &&  
   136           hisInfo->getArtistName().isEmpty()
   132           hisInfo->getArtistName().isEmpty()
   137         )
   133         )
   139     {
   135     {
   140         popupNote(hbTrId("txt_irad_info_no_song_info"), HbMessageBox::MessageTypeInformation);
   136         popupNote(hbTrId("txt_irad_info_no_song_info"), HbMessageBox::MessageTypeInformation);
   141         return;
   137         return;
   142     }
   138     }
   143 
   139 
   144 
   140     // TODO : Add the report in future. Add the channel id in the song info db
   145     if( iMusicShop->findInMusicShop(hisInfo->getSongName(), hisInfo->getArtistName()))
   141     // iStatisticsReporter->logNmsEvents(EIRQFind,channelId);
   146     {
   142     popupNote(hbTrId("txt_irad_info_music_store_not_available"), HbMessageBox::MessageTypeInformation);    
   147         if(iStatisticsReporter)
       
   148         {
       
   149             //we will add the report in future. Add the channel id in the song info db
       
   150             //iStatisticsReporter->logNmsEvents(EIRQFind,channelId);
       
   151         }
       
   152     }
       
   153     else
       
   154     {
       
   155         popupNote(hbTrId("txt_irad_info_music_shop_not_available"), HbMessageBox::MessageTypeInformation);
       
   156     }     
       
   157 }
   143 }
   158    
   144    
   159 
   145 
   160 // ---------------------------------------------------------------------------
   146 // ---------------------------------------------------------------------------
   161 // IRSongHistoryView::showSongHistory()
   147 // IRSongHistoryView::showSongHistory()
   168         iListView->reset();
   154         iListView->reset();
   169         iListView->setCurrentIndex(iModel->index(0));        
   155         iListView->setCurrentIndex(iModel->index(0));        
   170     }
   156     }
   171 }
   157 }
   172 
   158 
   173 // ---------------------------------------------------------------------------
       
   174 // IRSongHistoryView::clearAllList()
       
   175 // gets the List which was stored earlier
       
   176 //---------------------------------------------------------------------------
       
   177 void IRSongHistoryView::clearAllList()
       
   178 {        
       
   179     iModel->clearAllList();
       
   180     iListView->reset();
       
   181     updateView();     
       
   182 }
       
   183 
       
   184 void IRSongHistoryView::prepareMenu()
   159 void IRSongHistoryView::prepareMenu()
   185 {
   160 {
   186     HbMenu *viewMenu = menu();
   161     HbMenu *viewMenu = menu();
   187 
   162 
   188     viewMenu->removeAction(iClearSongHistoryAction);
   163     viewMenu->removeAction(iClearSongHistoryAction);
       
   164 
       
   165     HbAction * settingAction = qobject_cast<HbAction *>(iLoader.findObject(SETTINGS_ACTION));
       
   166     
   189     if (iModel->rowCount() > 0)
   167     if (iModel->rowCount() > 0)
   190     {
   168     {
   191         viewMenu->insertAction(iOpenWebAddressAction, iClearSongHistoryAction);
   169         viewMenu->insertAction(settingAction, iClearSongHistoryAction);
   192     }
   170     }
   193 }
   171 }
   194     
   172     
   195 void IRSongHistoryView::modelChanged()
   173 void IRSongHistoryView::modelChanged()
   196 {    
   174 {    
   197     iListView->reset();
   175     iListView->reset();
   198     QString headingStr = hbTrId("txt_irad_list_recently_played_songs") + " (" + QString::number(iModel->rowCount()) + ")";    
   176     QString headingStr = hbTrId("txt_irad_list_recently_played_songs") + " (" + QString::number(iModel->rowCount()) + ")";    
   199     setHeadingText(headingStr);
   177     setHeadingText(headingStr);   
   200  
       
   201     //the case is that, we active the song history view with no items
       
   202     //but immediately, we get the metadata and show it on the list,
       
   203     //then we need to remove the "no content" label
       
   204     if( 1 == iListView->model()->rowCount())
       
   205     {
       
   206         updateView();
       
   207     }     
       
   208 }
   178 }
   209 
   179 
   210 void IRSongHistoryView::newMetadataAdded(IRQMetaData *aMetadata)
   180 void IRSongHistoryView::newMetadataAdded(IRQMetaData *aMetadata)
   211 {
   181 {
   212     Q_UNUSED(aMetadata);     
   182     Q_UNUSED(aMetadata);     
   214      
   184      
   215 }
   185 }
   216 
   186 
   217 void IRSongHistoryView::clearHisotrySongDB()
   187 void IRSongHistoryView::clearHisotrySongDB()
   218 {
   188 {
   219     iModel->clearHisotrySongDB(); 
   189     iModel->clearHisotrySongDB();  
   220     updateView();    
       
   221 }
   190 }
   222 
   191 
   223 void IRSongHistoryView::showPrompt()
   192 void IRSongHistoryView::showPrompt()
   224 {
   193 {
   225     QString str = hbTrId("txt_irad_info_click_the_song_and_find_it_in_nokia_music_store");
   194     QString str = hbTrId("txt_irad_info_click_the_song_and_find_it_in_nokia_music_store");
   234  
   203  
   235 void IRSongHistoryView::gotoStationHistory()
   204 void IRSongHistoryView::gotoStationHistory()
   236 {
   205 {
   237 	  getViewManager()->activateView(EIRView_HistoryView);
   206 	  getViewManager()->activateView(EIRView_HistoryView);
   238 }
   207 }
       
   208 
       
   209 void IRSongHistoryView::handleOrientationChanged(Qt::Orientation aOrientation)
       
   210 {
       
   211     IrAbstractListViewBase::handleOrientationChanged(aOrientation);
       
   212     iModel->setOrientation(aOrientation);
       
   213     iListView->reset();
       
   214 }