qtinternetradio/ui/src/irstationsview.cpp
changeset 5 0930554dc389
parent 3 ee64f059b8e1
child 8 3b03c28289e6
equal deleted inserted replaced
3:ee64f059b8e1 5:0930554dc389
    16 */
    16 */
    17 #include <QPixmap>
    17 #include <QPixmap>
    18 #include <hblistview.h>
    18 #include <hblistview.h>
    19 #include <hbaction.h>
    19 #include <hbaction.h>
    20 #include <QTimer>
    20 #include <QTimer>
    21 #include <hbprogressdialog.h>
       
    22 
    21 
    23 #include "irviewmanager.h"
    22 #include "irviewmanager.h"
    24 #include "irstationsview.h"
    23 #include "irstationsview.h"
    25 #include "irapplication.h"
    24 #include "irapplication.h"
    26 #include "irplaycontroller.h"
    25 #include "irplaycontroller.h"
    40  * Description : constructor
    39  * Description : constructor
    41  */
    40  */
    42 IRStationsView::IRStationsView(IRApplication* aApplication, TIRViewId aViewId) 
    41 IRStationsView::IRStationsView(IRApplication* aApplication, TIRViewId aViewId) 
    43                                : IrAbstractListViewBase(aApplication, aViewId),
    42                                : IrAbstractListViewBase(aApplication, aViewId),
    44                                iLogoPreset(NULL),  iPreset(NULL), 
    43                                iLogoPreset(NULL),  iPreset(NULL), 
    45                                iWaitDialog(NULL),
    44                                iLastSelectitem(0)                        
    46                                iLastSelectitem(0),
       
    47                                iLastPopularItem(0)                          
       
    48 {       
    45 {       
    49     //this view won't be starting view, don't need lazy init
    46     //this view won't be starting view, don't need lazy init
    50     IrAbstractListViewBase::lazyInit();
    47     IrAbstractListViewBase::lazyInit();
    51     setInitCompleted(true);
    48     setInitCompleted(true);
    52         
    49         
    76     delete iPreset;
    73     delete iPreset;
    77     iPreset = NULL;
    74     iPreset = NULL;
    78 
    75 
    79     delete iLogoPreset;
    76     delete iLogoPreset;
    80     iLogoPreset = NULL;
    77     iLogoPreset = NULL;
    81 
       
    82     delete iWaitDialog;
       
    83     iWaitDialog = NULL;
       
    84     
       
    85  
       
    86  
       
    87 }
    78 }
    88 
    79 
    89 void IRStationsView::loadCategoryStations(int aIndex, const QString &aHeadingText)
    80 void IRStationsView::loadCategoryStations(int aIndex, const QString &aHeadingText)
    90 {
    81 {
    91     connectToIsdsClient();
    82     connectToIsdsClient();
    92     setHeadingText(aHeadingText);
    83     setHeadingText(aHeadingText);
    93     setViewParameter(EIRViewPara_CategoryStations);
       
    94     
    84     
    95     bool cache = false;
    85     bool cache = false;
    96     iIsdsClient->isdsChannelRequest(aIndex, cache);
    86     iIsdsClient->isdsChannelRequest(aIndex, cache);
    97     
    87     
    98     if (!cache)
    88     if (!cache)
    99     {
    89     {
   100         createWaitDialog(hbTrId("txt_common_info_loading"));
    90         iApplication->createLoadingDialog(this, SLOT(cancelRequest()));
   101     }
    91     }
   102 }
       
   103 
       
   104 void IRStationsView::loadPopularStations(bool aShowWaitDialog)
       
   105 {
       
   106     connectToIsdsClient();
       
   107     setViewParameter(EIRViewPara_PopularStations);
       
   108     setHeadingText(tr("Popular stations"));
       
   109     bool cache = false;
       
   110     iIsdsClient->isdsCategoryRequest(IRQIsdsClient::Ehotpicks, cache);
       
   111      
       
   112     if (!cache && aShowWaitDialog)
       
   113     {
       
   114         createWaitDialog(hbTrId("txt_common_info_loading"));
       
   115     }
       
   116 }
       
   117 
       
   118 void IRStationsView::loadSearchResult(const QString &aStr)
       
   119 {
       
   120     connectToIsdsClient();
       
   121     setViewParameter(EIRViewPara_SearchResults);
       
   122     setHeadingText(hbTrId("txt_irad_subtitle_search_result"));
       
   123     iIsdsClient->isdsSearchRequest(aStr);    
       
   124     if( iConnectTimer->isActive() )
       
   125     {
       
   126         iConnectTimer->stop();
       
   127     }
       
   128     
       
   129     iConnectTimer->start();
       
   130     createWaitDialog(hbTrId("txt_common_info_searching"));
       
   131 }
    92 }
   132 
    93 
   133 void IRStationsView::storeCurrentItem()
    94 void IRStationsView::storeCurrentItem()
   134 {
    95 {
   135     switch (getViewParameter())
    96     iLastSelectitem = iListView->currentIndex().row();
   136     {
       
   137     case EIRViewPara_PopularStations:
       
   138         iLastPopularItem = iListView->currentIndex().row();
       
   139         break;
       
   140     case EIRViewPara_CategoryStations:
       
   141         iLastSelectitem = iListView->currentIndex().row();
       
   142         break;
       
   143     default:
       
   144         break;
       
   145     }
       
   146 }
    97 }
   147 
    98 
   148 void IRStationsView::resetCurrentItem()
    99 void IRStationsView::resetCurrentItem()
   149 {
   100 {
   150     iLastSelectitem = 0;
   101     iLastSelectitem = 0;
   204     }
   155     }
   205     
   156     
   206     return ret;
   157     return ret;
   207 }
   158 }
   208 
   159 
   209 void IRStationsView::launchAction()
       
   210 {
       
   211     setUseNetworkReason(EIR_UseNetwork_StartingView);
       
   212     iApplication->verifyNetworkConnectivity();
       
   213 }
       
   214 
       
   215 //                                      slots functions
   160 //                                      slots functions
   216 
   161 
   217 /*
   162 /*
   218  * Description : slot function when an item in a list is clicked.
   163  * Description : slot function when an item in a list is clicked.
   219  *               issue a listen request to isds client
   164  *               issue a listen request to isds client
   231                 connect(iIsdsClient, SIGNAL(operationException(IRQError)),
   176                 connect(iIsdsClient, SIGNAL(operationException(IRQError)),
   232                         this, SLOT(operationException(IRQError)));
   177                         this, SLOT(operationException(IRQError)));
   233                 
   178                 
   234                 //once an item is selected, we show a dialog to prevent user from clicking the
   179                 //once an item is selected, we show a dialog to prevent user from clicking the
   235                 //item again
   180                 //item again
   236                 iPlayController->createBufferingDialog(this, SLOT(cancelRequest()));
   181                 iApplication->createLoadingDialog(this, SLOT(cancelRequest()));
   237                 
   182                 
   238                 if (iIsdsClient->isdsIsChannelBanner())
   183                 if (iIsdsClient->isdsIsChannelBanner())
   239                 {
   184                 {
   240                     iIsdsClient->isdsListenRequest(index + 1);
   185                     iIsdsClient->isdsListenRequest(index + 1);
   241                 }
   186                 }
   252  * Description : data is received from isds client. Load the data to the list widget and display
   197  * Description : data is received from isds client. Load the data to the list widget and display
   253  *               the stations view
   198  *               the stations view
   254  */
   199  */
   255 void IRStationsView::dataChanged()
   200 void IRStationsView::dataChanged()
   256 {
   201 {
   257 	
       
   258 	int currentItem = 0;
       
   259     iApplication->closeConnectingDialog();
       
   260     iConnectTimer->stop();
   202     iConnectTimer->stop();
   261     
   203     
   262     disconnectIsdsClient();
   204     disconnectIsdsClient();
   263     cleanupResource();
   205     cleanupResource();
   264  
   206 
   265     
       
   266     switch (getViewParameter())
       
   267     {
       
   268     case EIRViewPara_SearchResults:
       
   269         currentItem = 0;
       
   270         break;
       
   271     case EIRViewPara_PopularStations:
       
   272         currentItem = iLastPopularItem;
       
   273         break;
       
   274     case EIRViewPara_CategoryStations:
       
   275         currentItem = iLastSelectitem;
       
   276         break;
       
   277 	  default:
       
   278         break;
       
   279     }
       
   280     iListView->reset();
   207     iListView->reset();
   281     iListView->setCurrentIndex(iChannelModel->index(currentItem));
   208     iListView->setCurrentIndex(iChannelModel->index(iLastSelectitem));
   282     iListView->scrollTo(iChannelModel->index(currentItem));
   209     iListView->scrollTo(iChannelModel->index(iLastSelectitem));
   283 
   210 
   284     //initialize the iconindices
   211     //initialize the iconindices
   285     for (int i = 0; i < iChannelModel->rowCount(); ++i)
   212     for (int i = 0; i < iChannelModel->rowCount(); ++i)
   286     {
   213     {
   287         if (iChannelModel->imageUrl(i) != "")
   214         if (iChannelModel->imageUrl(i) != "")
   289             iIconIndexArray.append(i);
   216             iIconIndexArray.append(i);
   290         }
   217         }
   291     }
   218     }
   292 
   219 
   293     getViewManager()->activateView(this);
   220     getViewManager()->activateView(this);
   294     if (iWaitDialog)
   221     iApplication->closeLoadingDialog();
   295     {
       
   296         iWaitDialog->close();
       
   297     }
       
   298 }
   222 }
   299 
   223 
   300 /*
   224 /*
   301  * Description : the preset of the selected station is received from isds client.
   225  * Description : the preset of the selected station is received from isds client.
   302  *               application is responsible for deleting old preset.
   226  *               application is responsible for deleting old preset.
   322  * Description  : slot function for operation failure. The signal is emitted by isds client
   246  * Description  : slot function for operation failure. The signal is emitted by isds client
   323  * Parameters   : aError : see the definition of IRQError
   247  * Parameters   : aError : see the definition of IRQError
   324  */
   248  */
   325 void IRStationsView::operationException(IRQError aError)
   249 void IRStationsView::operationException(IRQError aError)
   326 {
   250 {
   327     iApplication->closeConnectingDialog();
   251     iApplication->closeLoadingDialog();
   328     iPlayController->closeBufferingDialog();
   252 
   329     
       
   330     if (iWaitDialog)
       
   331     {
       
   332         iWaitDialog->close();
       
   333     }
       
   334     
       
   335     disconnectIsdsClient();
   253     disconnectIsdsClient();
   336     QString errorString = hbTrId("txt_irad_info_failed_to_connect");
   254     QString errorString = hbTrId("txt_irad_info_failed_to_connect");
   337     
   255     
   338     switch (aError)
   256     switch (aError)
   339     {   
   257     {   
   351     popupNote(errorString, HbMessageBox::MessageTypeWarning);
   269     popupNote(errorString, HbMessageBox::MessageTypeWarning);
   352 }
   270 }
   353 
   271 
   354 void IRStationsView::cancelRequest()
   272 void IRStationsView::cancelRequest()
   355 {
   273 {
   356     if( iWaitDialog )
       
   357     {
       
   358         iWaitDialog->close();
       
   359     }
       
   360     
       
   361     if( iConnectTimer->isActive())
   274     if( iConnectTimer->isActive())
   362     {
   275     {
   363         iConnectTimer->stop();
   276         iConnectTimer->stop();
   364     }    
   277     }    
   365     iIsdsClient->isdsCancelRequest();
   278     iIsdsClient->isdsCancelRequest();
   366     disconnectIsdsClient();
   279     disconnectIsdsClient();
       
   280     iApplication->closeLoadingDialog();
   367 }
   281 }
   368 
   282 
   369 void IRStationsView::startConvert(int aIndex)
   283 void IRStationsView::startConvert(int aIndex)
   370 {
   284 {
   371     QString url = iChannelModel->imageUrl(aIndex);
   285     QString url = iChannelModel->imageUrl(aIndex);
   372  
   286  
   373     IRQPreset tempPreset;
   287     IRQPreset tempPreset;
   374     tempPreset.imgUrl = url;
   288     tempPreset.imgUrl = url;
   375     tempPreset.type = IRQPreset::EIsds;
   289     tempPreset.type = IRQPreset::EIsds;
   376     
       
   377     bool cached = iIsdsClient->isdsIsLogoCached(&tempPreset, KBitmapSize, KBitmapSize);
       
   378     
       
   379     if( !cached )
       
   380     {
       
   381         bool network = iApplication->verifyNetworkConnectivity(hbTrId("txt_irad_info_downloading_logos"));
       
   382         if( !network )
       
   383         {
       
   384             //if user has clicked an item and the connection is being setup, we don't change the reason
       
   385             if (EIR_UseNetwork_NoReason == getUseNetworkReason())
       
   386             {
       
   387                 setUseNetworkReason(EIR_UseNetwork_DownloadLogo);
       
   388             }
       
   389             iConvertTimer->stop();
       
   390             return;
       
   391         }        
       
   392     }
       
   393     
   290     
   394     iIsdsClient->isdsLogoDownSendRequest(&tempPreset, 0, KBitmapSize, KBitmapSize); 
   291     iIsdsClient->isdsLogoDownSendRequest(&tempPreset, 0, KBitmapSize, KBitmapSize); 
   395 }
   292 }
   396 
   293 
   397  
   294  
   461     }
   358     }
   462     
   359     
   463     switch (aEvent)
   360     switch (aEvent)
   464     {
   361     {
   465     case EIRQNetworkConnectionEstablished:
   362     case EIRQNetworkConnectionEstablished:
   466         if (EIR_UseNetwork_StartingView == getUseNetworkReason())
   363         if (EIR_UseNetwork_SelectItem == getUseNetworkReason())
   467         {
   364         {
   468             //when stations view is starting view(used to show popular stations), don't show wait dialog 
       
   469             loadPopularStations(false);
       
   470         }
       
   471         else if(EIR_UseNetwork_DownloadLogo == getUseNetworkReason())
       
   472         {
       
   473             iApplication->closeConnectingDialog();
       
   474             int leftCount = iIconIndexArray.count();
       
   475             if(0 != leftCount)
       
   476             {
       
   477             	  iConvertTimer->start();
       
   478             }            
       
   479         }
       
   480         else if (EIR_UseNetwork_SelectItem == getUseNetworkReason())
       
   481         {
       
   482             iApplication->closeConnectingDialog();
       
   483             handleItemSelected();
   365             handleItemSelected();
   484             int leftCount = iIconIndexArray.count();
   366             int leftCount = iIconIndexArray.count();
   485             if(0 != leftCount)
   367             if(0 != leftCount)
   486             {
   368             {
   487                 iConvertTimer->start();
   369                 iConvertTimer->start();
   488             }
   370             }
   489         }
   371         }
   490         setUseNetworkReason(EIR_UseNetwork_NoReason);
   372         
   491         
       
   492         break;
       
   493         
       
   494     case EIRQConnectingCancelled:
       
   495     case EIRQDisplayNetworkMessageNoConnectivity:
       
   496         if (iListView->model()->rowCount() == 0)
       
   497         {
       
   498             getViewManager()->activateView(EIRView_MainView);
       
   499         }
       
   500         else
       
   501         {
       
   502             setCheckedAction();
       
   503         }
       
   504         setUseNetworkReason(EIR_UseNetwork_NoReason);
       
   505         break;
   373         break;
   506         
   374         
   507     default:
   375     default:
   508         setCheckedAction();
   376         setCheckedAction();       
   509         setUseNetworkReason(EIR_UseNetwork_NoReason);
   377         break;
   510         break;
   378     }
   511     }
   379     
       
   380     setUseNetworkReason(EIR_UseNetwork_NoReason);
   512 }
   381 }
   513 
   382 
   514 void IRStationsView::connectToIsdsClient()
   383 void IRStationsView::connectToIsdsClient()
   515 {
   384 {
   516     connect(iIsdsClient, SIGNAL(channelItemsChanged(QList<IRQChannelItem *> *)),
   385     connect(iIsdsClient, SIGNAL(channelItemsChanged(QList<IRQChannelItem *> *)),
   525     disconnect(iIsdsClient, SIGNAL(channelItemsChanged(QList<IRQChannelItem *> *)),
   394     disconnect(iIsdsClient, SIGNAL(channelItemsChanged(QList<IRQChannelItem *> *)),
   526                iChannelModel, SLOT(updateData(QList<IRQChannelItem *> *)));
   395                iChannelModel, SLOT(updateData(QList<IRQChannelItem *> *)));
   527     
   396     
   528     disconnect(iIsdsClient, SIGNAL(operationException(IRQError)),
   397     disconnect(iIsdsClient, SIGNAL(operationException(IRQError)),
   529                this, SLOT(operationException(IRQError)));
   398                this, SLOT(operationException(IRQError)));
   530 }
       
   531 
       
   532 void IRStationsView::createWaitDialog(const QString &aStr)
       
   533 {
       
   534     if (!iWaitDialog)
       
   535     {
       
   536         iWaitDialog = new HbProgressDialog(HbProgressDialog::WaitDialog);
       
   537         iWaitDialog->setTimeout(HbPopup::NoTimeout);
       
   538         iWaitDialog->setModal(true);
       
   539         iWaitDialog->setDismissPolicy(HbPopup::NoDismiss);
       
   540         QList<QAction*> actionsList = iWaitDialog->actions();
       
   541         QAction *action = actionsList.at(0);
       
   542         action->setText(hbTrId("txt_common_button_cancel"));
       
   543         connect(action, SIGNAL(triggered()), this, SLOT(cancelRequest()));
       
   544     }
       
   545 
       
   546     iWaitDialog->setText(aStr);
       
   547     iWaitDialog->open();
       
   548 }
   399 }
   549 
   400 
   550 void IRStationsView::convertAnother()
   401 void IRStationsView::convertAnother()
   551 {
   402 {
   552     iConvertTimer->stop();
   403     iConvertTimer->stop();