qtinternetradio/ui/src/irhistoryview.cpp
changeset 3 ee64f059b8e1
parent 0 09774dfdd46b
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 <QPixmap>
    20 #include <QPixmap>
    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 "irqisdsclient.h"
    25 #include "irqisdsclient.h"
    26 #include "irplaycontroller.h"
    26 #include "irplaycontroller.h"
    27 #include "irhistoryview.h"
    27 #include "irhistoryview.h"
    28 #include "irqisdsdatastructure.h"
    28 #include "irqisdsdatastructure.h"
    30 #include "irqsonghistoryinfo.h"
    30 #include "irqsonghistoryinfo.h"
    31 #include "irqnetworkcontroller.h" 
    31 #include "irqnetworkcontroller.h" 
    32 #include "irqutility.h"
    32 #include "irqutility.h"
    33 #include "irqenums.h"
    33 #include "irqenums.h"
    34 #include "irqfavoritesdb.h"
    34 #include "irqfavoritesdb.h"
       
    35 #include "irstationdetailsview.h"
       
    36 #include "iruidefines.h"
       
    37 
    35 
    38 
    36 const int KBitmapSize = 59;
    39 const int KBitmapSize = 59;
       
    40 const QString KActionAddName("Add");
       
    41 const QString KActionDeleteName("Delete");
       
    42 const QString KActionDetailsName("Details");
    37 
    43 
    38 //                                         public functions
    44 //                                         public functions
    39 
    45 
    40 /*
    46 /*
    41  * Description : constructor
    47  * Description : constructor
    42  */
    48  */
    43 IRHistoryView::IRHistoryView(IRApplication *aApplication, TIRViewId aViewId) :
    49 IRHistoryView::IRHistoryView(IRApplication *aApplication, TIRViewId aViewId) :
    44     IrAbstractListViewBase(aApplication, aViewId), iClearHistoryAction(NULL),
    50     IrAbstractListViewBase(aApplication, aViewId), iClearHistoryAction(NULL),
    45     iLogoPreset(NULL)
    51     iLogoPreset(NULL)
    46 {
    52 {
       
    53     //this view won't be starting view, don't need lazy init
       
    54     IrAbstractListViewBase::lazyInit();
       
    55     setInitCompleted(true);
    47     
    56     
    48     iModel = new IRHistoryModel(this);
    57     iModel = new IRHistoryModel(this);
    49     iListView->setModel(iModel);
    58     iListView->setModel(iModel);
    50     iListView->setCurrentIndex(iModel->index(0));
    59     iListView->setCurrentIndex(iModel->index(0));
    51     
    60     
    52     iClearHistoryAction = new HbAction(hbTrId("txt_irad_opt_clear_station_history"), menu());
    61     iClearHistoryAction = new HbAction(hbTrId("txt_irad_opt_clear_station_history"), menu());
    53     iSongHistoryAction = new HbAction(hbTrId("txt_irad_opt_recently_played_songs"), menu());	 
    62 
    54     menu()->insertAction(iOpenWebAddressAction, iSongHistoryAction);
       
    55     
    63     
    56     iConvertTimer = new QTimer(this);
    64     iConvertTimer = new QTimer(this);
    57     iConvertTimer->setInterval(10);
    65     iConvertTimer->setInterval(10);
    58     
    66     
    59     connect(iClearHistoryAction, SIGNAL(triggered()), this, SLOT(clearAllList()));
    67     connect(iClearHistoryAction, SIGNAL(triggered()), this, SLOT(clearAllList()));
    60     connect(iNetworkController, SIGNAL(networkRequestNotified(IRQNetworkEvent)),
    68     connect(iNetworkController, SIGNAL(networkRequestNotified(IRQNetworkEvent)),
    61     this, SLOT(networkRequestNotified(IRQNetworkEvent)));
    69     this, SLOT(networkRequestNotified(IRQNetworkEvent)));
    62     connect(iModel, SIGNAL(modelChanged()), this, SLOT(modelChanged()));
    70     connect(iModel, SIGNAL(modelChanged()), this, SLOT(modelChanged()));
    63     connect(iSongHistoryAction, SIGNAL(triggered()), this, SLOT(gotoSongHistory()));
       
    64     connect(iConvertTimer, SIGNAL(timeout()), this, SLOT(convertAnother()));
    71     connect(iConvertTimer, SIGNAL(timeout()), this, SLOT(convertAnother()));
    65 }
    72 }
    66 
    73 
    67 void IRHistoryView::gotoSongHistory()
    74 void IRHistoryView::gotoSongHistory()
    68 {
    75 {
   102                 this, SLOT(presetLogoDownload(IRQPreset* )));
   109                 this, SLOT(presetLogoDownload(IRQPreset* )));
   103         connect(iIsdsClient, SIGNAL(presetLogoDownloadError()),
   110         connect(iIsdsClient, SIGNAL(presetLogoDownloadError()),
   104                 this, SLOT(presetLogoDownloadError()));
   111                 this, SLOT(presetLogoDownloadError()));
   105         
   112         
   106         showHistory();
   113         showHistory();
       
   114         leftCount = iIconIndexArray.count();
       
   115         if( leftCount > 0 )
       
   116         {
       
   117             iConvertTimer->start();
       
   118         }
   107         ret = EIR_NoDefault;
   119         ret = EIR_NoDefault;
   108         break;
   120         break;
   109 
   121 
   110     case EIR_ViewCommand_DEACTIVATE:
   122     case EIR_ViewCommand_DEACTIVATE:
   111 
   123 
   125                    this, SLOT(presetLogoDownload(IRQPreset* )));
   137                    this, SLOT(presetLogoDownload(IRQPreset* )));
   126         disconnect(iIsdsClient, SIGNAL(presetLogoDownloadError()),
   138         disconnect(iIsdsClient, SIGNAL(presetLogoDownloadError()),
   127                    this, SLOT(presetLogoDownloadError()));
   139                    this, SLOT(presetLogoDownloadError()));
   128         ret = EIR_NoDefault;
   140         ret = EIR_NoDefault;
   129         break;
   141         break;
   130     
       
   131     case EIR_ViewCommand_EffectFinished:
       
   132         /* when the effect is finished, we start showing the logos  */
       
   133         leftCount = iIconIndexArray.count();
       
   134         if( leftCount > 0 )
       
   135         {
       
   136             iConvertTimer->start();
       
   137         }
       
   138         break;
       
   139 
   142 
   140     default:
   143     default:
   141         break;
   144         break;
   142     }
   145     }
   143 
   146 
   268     iIconIndexArray.clear();
   271     iIconIndexArray.clear();
   269     iModel->clearAllList();
   272     iModel->clearAllList();
   270     iConvertTimer->stop();
   273     iConvertTimer->stop();
   271     iIsdsClient->isdsLogoDownCancelTransaction();
   274     iIsdsClient->isdsLogoDownCancelTransaction();
   272     iListView->reset();
   275     iListView->reset();
   273     updateView();
       
   274 }
   276 }
   275 
   277 
   276 void IRHistoryView::prepareMenu()
   278 void IRHistoryView::prepareMenu()
   277 {
   279 {
   278     HbMenu *viewMenu = menu();
   280     HbMenu *viewMenu = menu();
   279     
   281     
   280     viewMenu->removeAction(iClearHistoryAction);
   282     viewMenu->removeAction(iClearHistoryAction);
       
   283 
       
   284     HbAction * settingAction = qobject_cast<HbAction *>(iLoader.findObject(SETTINGS_ACTION));
       
   285 
   281     if (iModel->rowCount() > 0)
   286     if (iModel->rowCount() > 0)
   282     {
   287     {
   283         viewMenu->insertAction(iOpenWebAddressAction, iClearHistoryAction);
   288         viewMenu->insertAction(settingAction, iClearHistoryAction);
   284     }
   289     }
   285 } 
   290 } 
   286 
   291 
   287 void IRHistoryView::startConvert(int aIndex)
   292 void IRHistoryView::startConvert(int aIndex)
   288 {
   293 {
   361 {
   366 {
   362     QString headingStr = hbTrId("Station History") + " (" + QString::number(iModel->rowCount()) + ")";  
   367     QString headingStr = hbTrId("Station History") + " (" + QString::number(iModel->rowCount()) + ")";  
   363     setHeadingText(headingStr);
   368     setHeadingText(headingStr);
   364 }
   369 }
   365  
   370  
   366  
   371 void IRHistoryView::actionClicked(HbAction *aAction)
       
   372 {
       
   373     if ( aAction )
       
   374     {
       
   375         QString objectName = aAction->objectName();
       
   376         if ( objectName == KActionAddName )
       
   377         {
       
   378             addContextAction();
       
   379         }
       
   380         else if( objectName == KActionDeleteName)
       
   381         {
       
   382             deleteContextAction();
       
   383         }
       
   384         else if( objectName == KActionDetailsName)
       
   385         {
       
   386             detailContextAction();
       
   387         }
       
   388     }
       
   389 }
       
   390 
   367 void IRHistoryView::addContextAction()
   391 void IRHistoryView::addContextAction()
   368 {        
   392 {        
   369     QModelIndex current = iListView->currentIndex();     
   393     QModelIndex current = iListView->currentIndex();     
   370     IRQSongHistoryInfo * currentInfo = iModel->getHistoryInfo(current.row());
   394     IRQSongHistoryInfo * currentInfo = iModel->getHistoryInfo(current.row());
   371     IRQPreset preset;
   395     IRQPreset preset;
   399     if( !ret )
   423     if( !ret )
   400 	  {
   424 	  {
   401 	    popupNote(hbTrId("txt_irad_info_operation_failed"), HbMessageBox::MessageTypeWarning);
   425 	    popupNote(hbTrId("txt_irad_info_operation_failed"), HbMessageBox::MessageTypeWarning);
   402 	  }
   426 	  }
   403 }
   427 }
   404  
   428 void IRHistoryView::detailContextAction()
   405  
   429 {
   406  
   430     getViewManager()->activateView(EIRView_StationDetailsView);
       
   431     IRStationDetailsView *channelHistoryView = static_cast<IRStationDetailsView*>(getViewManager()->getView(EIRView_StationDetailsView));
       
   432     int selectedItemIndex = iListView->currentIndex().row();
       
   433     IRQSongHistoryInfo *channelDetailInfo = iModel->getHistoryInfo(selectedItemIndex);
       
   434     channelHistoryView->setDetails(channelDetailInfo);
       
   435 }
       
   436 
   407 void IRHistoryView::listViewLongPressed(HbAbstractViewItem *aItem, const QPointF& aCoords)
   437 void IRHistoryView::listViewLongPressed(HbAbstractViewItem *aItem, const QPointF& aCoords)
   408 {
   438 {
   409     Q_UNUSED(aItem);             
   439     Q_UNUSED(aItem);
   410     HbMenu *contextMenu = 0;
   440     Q_UNUSED(aCoords);
   411     HbAction *action = 0;
   441     
   412     
   442     HbAction *action = NULL;
   413     contextMenu = new HbMenu();
   443     HbMenu *contextMenu = new HbMenu;
   414     action = contextMenu->addAction(QString(hbTrId("txt_irad_menu_add_to_favorite")));
   444     contextMenu->setAttribute(Qt::WA_DeleteOnClose);
   415     action->setObjectName("add");
   445     connect(contextMenu, SIGNAL(triggered(HbAction*)), this, SLOT(actionClicked(HbAction*)));
   416     action = contextMenu->addAction(QString(hbTrId("txt_common_menu_delete")));
   446     
   417     action->setObjectName("delete");
   447     action = contextMenu->addAction(hbTrId("txt_irad_menu_add_to_favorite"));
   418     action = contextMenu->exec(aCoords);
   448     action->setObjectName(KActionAddName);
   419     
   449     action = contextMenu->addAction(hbTrId("txt_common_menu_delete"));
   420     if( action )
   450     action->setObjectName(KActionDeleteName);
   421     {
   451     action = contextMenu->addAction(hbTrId("txt_common_menu_details"));
   422         QString objectName = action->objectName();
   452     action->setObjectName(KActionDetailsName);
   423         if ( objectName == "add" )
   453     
   424         {
   454     contextMenu->open();
   425             addContextAction();                          	        	            
   455 }
   426         }
       
   427         else if( objectName == "delete")
       
   428         {
       
   429             deleteContextAction();                            
       
   430         }
       
   431     }          
       
   432 } 
       
   433 
   456 
   434 void IRHistoryView::convertStationHistory2Preset(const IRQSongHistoryInfo& aHistoryInfo, IRQPreset& aPreset)
   457 void IRHistoryView::convertStationHistory2Preset(const IRQSongHistoryInfo& aHistoryInfo, IRQPreset& aPreset)
   435 {
   458 {
   436     IRQChannelServerURL url;
   459     IRQChannelServerURL url;
   437     url.url = aHistoryInfo.getStreamUrl();
   460     url.url = aHistoryInfo.getStreamUrl();