qtinternetradio/ui/src/irsearchchannelsview.cpp
changeset 8 3b03c28289e6
parent 5 0930554dc389
child 11 f683e24efca3
equal deleted inserted replaced
5:0930554dc389 8:3b03c28289e6
    18 #include <qtimer.h>
    18 #include <qtimer.h>
    19 #include <hblistview.h>
    19 #include <hblistview.h>
    20 #include <hbsearchpanel.h>
    20 #include <hbsearchpanel.h>
    21 #include <hbaction.h>
    21 #include <hbaction.h>
    22 #include <hbprogressdialog.h>
    22 #include <hbprogressdialog.h>
    23 #include <hbscrollbar.h>
    23 #include <hbscrollbar.h> 
       
    24 #include <hbiconitem.h>
       
    25 #include <hbiconanimator.h>
       
    26 #include <hblabel.h> 
       
    27 #include <hbiconanimationmanager.h>
    24 
    28 
    25 #include "irsearchchannelsview.h"
    29 #include "irsearchchannelsview.h"
    26 #include "iruidefines.h"
    30 #include "iruidefines.h"
    27 #include "irqisdsclient.h"
    31 #include "irqisdsclient.h"
    28 #include "irapplication.h"
    32 #include "irapplication.h"
    30 #include "irqnetworkcontroller.h"
    34 #include "irqnetworkcontroller.h"
    31 #include "irchannelmodel.h"
    35 #include "irchannelmodel.h"
    32 #include "irqisdsdatastructure.h"
    36 #include "irqisdsdatastructure.h"
    33 #include "irplaycontroller.h"
    37 #include "irplaycontroller.h"
    34  
    38  
    35 const uint KBitmapSize = 59; 
    39 const uint KBitmapSize = 59;
    36 
    40 
    37 IRSearchChannelsView::IRSearchChannelsView(IRApplication* aApplication,
    41 IRSearchChannelsView::IRSearchChannelsView(IRApplication* aApplication,
    38         TIRViewId aViewId): IRBaseView(aApplication, aViewId),
    42         TIRViewId aViewId): IRBaseView(aApplication, aViewId),
    39         iListView(NULL),iSearchPanelWidget(NULL),
    43         iListView(NULL),iSearchPanelWidget(NULL),iSearchState(ESearch_init),
    40         iSearchState(ESearch_init),iChannelModel(NULL),iSearchingDialog(NULL),
    44         iChannelModel(NULL),iPreset(NULL),iLogoPreset(NULL),
    41         iPreset(NULL),iLogoPreset(NULL),iConvertTimer(NULL)
    45         iConvertTimer(NULL) 
    42 {
    46 {
    43     //if this view is not starting view, finish all initialization in constructor
    47     //if this view is not starting view, finish all initialization in constructor
    44     if (getViewManager()->views().count() > 0)
    48     if (getViewManager()->views().count() > 0)
    45     {
    49     {
    46         if (!initCompleted())
    50         if (!initCompleted())
    83     iConvertTimer->setInterval(10); 
    87     iConvertTimer->setInterval(10); 
    84     
    88     
    85     connect(iConvertTimer, SIGNAL(timeout()), this, SLOT(convertAnother()));
    89     connect(iConvertTimer, SIGNAL(timeout()), this, SLOT(convertAnother()));
    86 }
    90 }
    87 
    91 
       
    92  
       
    93 
    88 IRSearchChannelsView::~IRSearchChannelsView()
    94 IRSearchChannelsView::~IRSearchChannelsView()
    89 {
    95 {   
    90     if( iSearchingDialog != NULL )
       
    91     {
       
    92         iSearchingDialog->close();
       
    93         delete iSearchingDialog;
       
    94         iSearchingDialog = NULL;
       
    95     }
       
    96     
       
    97     if( iPreset != NULL )
    96     if( iPreset != NULL )
    98     {
    97     {
    99         delete iPreset;
    98         delete iPreset;
   100         iPreset = NULL;
    99         iPreset = NULL;
   101     }
   100     }
   103     if( iLogoPreset != NULL )
   102     if( iLogoPreset != NULL )
   104     {
   103     {
   105         delete iLogoPreset;
   104         delete iLogoPreset;
   106         iLogoPreset = NULL;
   105         iLogoPreset = NULL;
   107     }
   106     }
       
   107     
       
   108     if( NULL != iChannelModel )
       
   109     {
       
   110         iChannelModel->save2Cache();
       
   111     }
       
   112  
   108 }
   113 }
   109 
   114 
   110 void IRSearchChannelsView::loadLayout()
   115 void IRSearchChannelsView::loadLayout()
   111 {
   116 {
   112     // Create widget hierarchy
   117     // Create widget hierarchy
   126     scrollbar->setVisible(true);
   131     scrollbar->setVisible(true);
   127     scrollbar->setInteractive(true);
   132     scrollbar->setInteractive(true);
   128     iListView->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded);
   133     iListView->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded);
   129     
   134     
   130     iChannelModel = new IrChannelModel(this);
   135     iChannelModel = new IrChannelModel(this);
   131     iListView->setModel(iChannelModel);
   136     iChannelModel->initWithCache();
       
   137     iListView->setModel(iChannelModel);    
   132 }
   138 }
   133 
   139 
   134 void IRSearchChannelsView::connectWidget()
   140 void IRSearchChannelsView::connectWidget()
   135 {     
   141 {     
   136     connect(iListView, SIGNAL(activated(const QModelIndex&)), this, SLOT(clickItem(const QModelIndex&)));
   142     connect(iListView, SIGNAL(activated(const QModelIndex&)), this, SLOT(clickItem(const QModelIndex&)));
   137     connect(iChannelModel, SIGNAL(dataAvailable()), this, SLOT(dataChanged()));
   143     connect(iChannelModel, SIGNAL(dataAvailable()), this, SLOT(dataChanged()));
   138     connect(iNetworkController, SIGNAL(networkRequestNotified(IRQNetworkEvent)), this, SLOT(networkRequestNotified(IRQNetworkEvent)));     
   144     connect(iNetworkController, SIGNAL(networkRequestNotified(IRQNetworkEvent)), this, SLOT(networkRequestNotified(IRQNetworkEvent)));     
   139     connect(iSearchPanelWidget,SIGNAL(criteriaChanged(const QString&)),this,SLOT(searchTextAlready(const QString&)));
   145     connect(iSearchPanelWidget,SIGNAL(criteriaChanged(const QString&)),this,SLOT(searchTextAlready(const QString&)));
       
   146     connect(iSearchPanelWidget, SIGNAL(exitClicked()), this, SLOT(minimizeSearchPanel()));
   140 }
   147 }
   141 
   148 
   142 void IRSearchChannelsView::connectIsdsClient()
   149 void IRSearchChannelsView::connectIsdsClient()
   143 {
   150 {
   144     connect(iIsdsClient, SIGNAL(channelItemsChanged(QList<IRQChannelItem *> *)),
   151     connect(iIsdsClient, SIGNAL(channelItemsChanged(QList<IRQChannelItem *> *)),
   168     disconnect(iIsdsClient, SIGNAL(presetLogoDownloadError()),
   175     disconnect(iIsdsClient, SIGNAL(presetLogoDownloadError()),
   169                        this, SLOT(presetLogoDownloadError()));  
   176                        this, SLOT(presetLogoDownloadError()));  
   170 }
   177 }
   171 
   178 
   172 void IRSearchChannelsView::switch2InitState()
   179 void IRSearchChannelsView::switch2InitState()
   173 {
   180 {    
   174     iLoader.load(SEARCH_CHANNELS_VIEW_LAYOUT_FILENAME,SEARCH_CHANNELS_VIEW_NO_LISTVIEW_SECTION);    
       
   175     iSearchState = ESearch_init;     
   181     iSearchState = ESearch_init;     
   176 }
   182     iApplication->stopLoadingAnimation();
   177 
   183 } 
   178 void IRSearchChannelsView::switch2SearchedState()
   184 
   179 {
   185 void IRSearchChannelsView::switch2LoadingState()
   180     iSearchState = ESearch_Searched;     
   186 {   
   181 }
       
   182 
       
   183 void IRSearchChannelsView::switch2SearchingState()
       
   184 {    
       
   185     iLoader.load(SEARCH_CHANNELS_VIEW_LAYOUT_FILENAME,SEARCH_CHANNELS_VIEW_LISTVIEW_SECTION);
       
   186     iSearchPanelWidget->clearFocus();
   187     iSearchPanelWidget->clearFocus();
   187     iListView->setFocus();
   188     iListView->setFocus();
   188     iSearchState = ESearch_Searching;     
   189     iSearchState = ESearch_Loading;
   189     startSearchingAnimation();
   190     
   190 }
   191     QSizeF searchPanelSize = iSearchPanelWidget->size();
   191  
   192     QSizeF windowSize = getViewManager()->size();
   192 void IRSearchChannelsView::createSearchingDialog()
   193     QPointF pos(windowSize.width()/2,(windowSize.height() - searchPanelSize.height())/2);
   193 {
   194     QPointF iconPos(LOADING_ANIMATION_ICON_SIZE/2, LOADING_ANIMATION_ICON_SIZE/2);
   194     if ( NULL == iSearchingDialog)
   195     pos -= iconPos;
   195     {
   196     iApplication->startLoadingAnimation(pos);
   196         //needs to add this , otherwise memory leak
   197 }
   197         iSearchingDialog = new HbProgressDialog(HbProgressDialog::WaitDialog);
       
   198         iSearchingDialog->setModal(true);
       
   199         iSearchingDialog->setTimeout(HbPopup::NoTimeout);
       
   200         QAction *cancelAction = iSearchingDialog->actions().at(0);
       
   201         cancelAction->setText(hbTrId("txt_common_button_cancel"));
       
   202         connect(cancelAction, SIGNAL(triggered()), this, SLOT(cancelRequest()));
       
   203     }
       
   204     
       
   205     iSearchingDialog->setText(hbTrId("txt_common_info_searching"));
       
   206     iSearchingDialog->show();
       
   207 }
       
   208 
       
   209 void IRSearchChannelsView::closeSearchingDialog()
       
   210 {
       
   211     if( iSearchingDialog )
       
   212     {
       
   213         iSearchingDialog->close();
       
   214         iSearchingDialog->deleteLater();
       
   215         iSearchingDialog = NULL;
       
   216     }
       
   217 }
       
   218 
       
   219 void IRSearchChannelsView::startSearchingAnimation()
       
   220 {
       
   221     
       
   222 }
       
   223 
       
   224 void IRSearchChannelsView::stopSearchingAnimation()
       
   225 {
       
   226     
       
   227 }
       
   228 
       
   229 
   198 
   230 void IRSearchChannelsView::handleItemSelected()
   199 void IRSearchChannelsView::handleItemSelected()
   231 {
   200 {
   232     if (iListView)
   201     if (iListView)
   233     {
   202     {
   234         int index = iListView->currentIndex().row();
   203         int index = iListView->currentIndex().row();
   235         if (index != -1)  
   204         IRQChannelItem* aItem = iChannelModel->getChannelItemByIndex(index);
       
   205         if( NULL != aItem )
   236         {
   206         {
   237             if (iIsdsClient)
   207             iIsdsClient->isdsListenRequest(aItem->channelID,true);
   238             {              
   208         }        
   239                 //once an item is selected, we show a dialog to prevent user from clicking the
   209     }
   240                 //item again
   210  
   241                 iApplication->createLoadingDialog(this, SLOT(cancelRequest()));
       
   242                 
       
   243                 if (iIsdsClient->isdsIsChannelBanner())
       
   244                 {
       
   245                     iIsdsClient->isdsListenRequest(index + 1);
       
   246                 }
       
   247                 else
       
   248                 {
       
   249                     iIsdsClient->isdsListenRequest(index);
       
   250                 }
       
   251             }
       
   252         }
       
   253     }
       
   254 }
   211 }
   255 
   212 
   256 void IRSearchChannelsView::cancelRequest()
   213 void IRSearchChannelsView::cancelRequest()
   257 {
   214 {     
   258     iSearchState = ESearch_init;
       
   259     iIsdsClient->isdsCancelRequest();    
   215     iIsdsClient->isdsCancelRequest();    
   260     stopSearchingAnimation();    
   216     switch2InitState(); 
   261     //the following will remove into the stopSearchingAnimation() function
       
   262     closeSearchingDialog();
       
   263 } 
   217 } 
   264 
   218 
   265 void IRSearchChannelsView::networkRequestNotified(IRQNetworkEvent aEvent)
   219 void IRSearchChannelsView::networkRequestNotified(IRQNetworkEvent aEvent)
   266 {        
   220 {        
   267     if (getViewManager()->currentView() != this)
   221     if (getViewManager()->currentView() != this)
   274     case EIRQNetworkConnectionEstablished:
   228     case EIRQNetworkConnectionEstablished:
   275          
   229          
   276         if(EIR_UseNetwork_StartSearch == getUseNetworkReason())
   230         if(EIR_UseNetwork_StartSearch == getUseNetworkReason())
   277         {
   231         {
   278             Q_ASSERT( !iKeyText.isEmpty() );
   232             Q_ASSERT( !iKeyText.isEmpty() );
   279             iIsdsClient->isdsSearchRequest(iKeyText);
   233             iIsdsClient->isdsSearchRequest(iKeyText);             
   280             iApplication->createLoadingDialog(this, SLOT(cancelRequest()));
       
   281         }
   234         }
   282         else if( EIR_UseNetwork_SelectItem == getUseNetworkReason() )
   235         else if( EIR_UseNetwork_SelectItem == getUseNetworkReason() )
   283         {            
   236         {            
   284             handleItemSelected();
   237             handleItemSelected();
   285         }
   238         }
   286         setUseNetworkReason(EIR_UseNetwork_NoReason);
   239         setUseNetworkReason(EIR_UseNetwork_NoReason);
   287         break;        
   240         break;        
   288      
   241      
   289     default:             
   242     default:             
   290         stopSearchingAnimation();
   243         switch2InitState();         
   291         //the following will remove into the stopSearchingAnimation() function
   244         setUseNetworkReason(EIR_UseNetwork_NoReason);        
   292         closeSearchingDialog();
       
   293         setUseNetworkReason(EIR_UseNetwork_NoReason);
       
   294         iSearchState = ESearch_init;
       
   295         break;
   245         break;
   296     }   
   246     }   
   297 } 
   247 } 
   298 
   248 
   299 void IRSearchChannelsView::searchTextAlready(const QString& aSearchCriteria)
   249 void IRSearchChannelsView::searchTextAlready(const QString& aSearchCriteria)
   304     {
   254     {
   305         //show some error info here to let user input some criteria
   255         //show some error info here to let user input some criteria
   306         return;
   256         return;
   307     }  
   257     }  
   308     
   258     
   309     setUseNetworkReason(EIR_UseNetwork_StartSearch);
   259     setUseNetworkReason(EIR_UseNetwork_StartSearch);     
   310     if (false == iApplication->verifyNetworkConnectivity(hbTrId("txt_common_info_searching")))
   260     if (false == iApplication->verifyNetworkConnectivity())
   311     {        
   261     {        
   312         switch2SearchingState();
   262         switch2LoadingState();
   313         return;
   263         return;
   314     }
   264     }
   315     
   265     
       
   266     //if previouse request is in progress, cancel it
       
   267     if( ESearch_Loading == iSearchState )
       
   268     {
       
   269         iIsdsClient->isdsCancelRequest();            
       
   270         iConvertTimer->stop();
       
   271         iIsdsClient->isdsLogoDownCancelTransaction();
       
   272     }
       
   273  
       
   274     
   316     setUseNetworkReason(EIR_UseNetwork_NoReason);    
   275     setUseNetworkReason(EIR_UseNetwork_NoReason);    
   317     switch2SearchingState();
   276     switch2LoadingState();
   318     iIsdsClient->isdsSearchRequest(iKeyText);     
   277     iIsdsClient->isdsSearchRequest(iKeyText);    
   319     createSearchingDialog();
       
   320 }
   278 }
   321 
   279 
   322 void IRSearchChannelsView::operationException(IRQError aError)
   280 void IRSearchChannelsView::operationException(IRQError aError)
   323 {    
   281 {        
   324     iApplication->closeLoadingDialog(); 
   282     switch2InitState();
   325     closeSearchingDialog();
   283     
   326     stopSearchingAnimation();     
   284     QString errStr;    
   327     iSearchState = ESearch_init;
       
   328     
       
   329     QString errStr;
       
   330     
       
   331     switch(aError)
   285     switch(aError)
   332     {
   286     {
   333     case EIRQErrorNotFound:
   287     case EIRQErrorNotFound:
   334         errStr = hbTrId("txt_irad_info_no_matching_stations_found");
   288         errStr = hbTrId("txt_irad_info_no_matching_stations_found");
   335         break;
   289         break;
   336     default:
   290     default:
   337         errStr = hbTrId("txt_irad_info_failed_to_connect");
   291         errStr = hbTrId("txt_irad_info_failed_to_connect");
   338         break;   
   292         break;   
   339     }
   293     }
       
   294     
   340     popupNote(errStr, HbMessageBox::MessageTypeWarning);     
   295     popupNote(errStr, HbMessageBox::MessageTypeWarning);     
   341 }
   296 }
   342 
   297 
   343 void IRSearchChannelsView::clickItem(const QModelIndex&)
   298 void IRSearchChannelsView::clickItem(const QModelIndex&)
   344 {
   299 {
   345     setUseNetworkReason(EIR_UseNetwork_SelectItem);
   300     setUseNetworkReason(EIR_UseNetwork_SelectItem);
   346     if (false == iApplication->verifyNetworkConnectivity())
   301     if (false == iApplication->verifyNetworkConnectivity())
   347     {
   302     {
       
   303         switch2LoadingState();
   348         return;
   304         return;
   349     }
   305     }
   350     setUseNetworkReason(EIR_UseNetwork_NoReason);
   306     setUseNetworkReason(EIR_UseNetwork_NoReason);
       
   307     
       
   308     switch2LoadingState();
   351     handleItemSelected();
   309     handleItemSelected();
   352 }
   310 }
   353 
   311 
   354 
   312 
   355 void IRSearchChannelsView::presetResponse(IRQPreset *aPreset)
   313 void IRSearchChannelsView::presetResponse(IRQPreset *aPreset)
   374     }
   332     }
   375 }
   333 }
   376 
   334 
   377 void IRSearchChannelsView::dataChanged()
   335 void IRSearchChannelsView::dataChanged()
   378 {
   336 {
   379     iApplication->closeLoadingDialog();     
   337     switch2InitState(); 
   380     stopSearchingAnimation();
       
   381     
       
   382     //the following will remove into the stopSearchingAnimation() function
       
   383     closeSearchingDialog();    
       
   384     switch2SearchedState(); 
       
   385     iListView->reset();
   338     iListView->reset();
   386     iListView->setCurrentIndex(iChannelModel->index(0));
   339     iListView->setCurrentIndex(iChannelModel->index(0));
   387     iListView->scrollTo(iChannelModel->index(0)); 
   340     iListView->scrollTo(iChannelModel->index(0)); 
   388  
   341  
   389     //we move the focus to the listview and the search panel will
   342     //we move the focus to the listview and the search panel will
   402     
   355     
   403     if( iIconIndexArray.count() > 0 )
   356     if( iIconIndexArray.count() > 0 )
   404     {
   357     {
   405         iConvertTimer->start();        
   358         iConvertTimer->start();        
   406     } 
   359     } 
       
   360     
       
   361     iSearchPanelWidget->setPlaceholderText(iKeyText); 
   407 }
   362 }
   408 
   363 
   409 void IRSearchChannelsView::startConvert(int aIndex)
   364 void IRSearchChannelsView::startConvert(int aIndex)
   410 {
   365 {
   411     QString url = iChannelModel->imageUrl(aIndex);
   366     QString url = iChannelModel->imageUrl(aIndex);
   478     {
   433     {
   479         iConvertTimer->start();
   434         iConvertTimer->start();
   480     }     
   435     }     
   481 }
   436 }
   482 
   437 
   483 TIRHandleResult IRSearchChannelsView::handleCommand(TIRViewCommand aCommand, TIRViewCommandReason aReason)
   438 void IRSearchChannelsView::minimizeSearchPanel()
       
   439 {
       
   440     if( ESearch_Loading == iSearchState )
       
   441     {
       
   442         if( ! ( iPlayController->isStopped() || iPlayController->isIdle() ) )
       
   443         {
       
   444             //cancel buffering
       
   445             iPlayController->cancelBuffering();
       
   446         }
       
   447          
       
   448         disconnectIsdsClient();
       
   449         iIsdsClient->isdsCancelRequest();
       
   450         iConvertTimer->stop();
       
   451         iIsdsClient->isdsLogoDownCancelTransaction();
       
   452         switch2InitState();      
       
   453     }
       
   454     
       
   455     int count = iChannelModel->rowCount();
       
   456     if (0 == count)
       
   457     {         
       
   458         iSearchPanelWidget->clearFocus();
       
   459         iListView->setFocus();        
       
   460         getViewManager()->backToPreviousView();
       
   461     }
       
   462     else
       
   463     {
       
   464         iSearchPanelWidget->clearFocus();
       
   465         iListView->setFocus();        
       
   466     }
       
   467 }
       
   468  
       
   469 
       
   470 TIRHandleResult IRSearchChannelsView::handleCommand(TIRViewCommand aCommand,
       
   471         TIRViewCommandReason aReason)
   484 {
   472 {
   485     TIRHandleResult ret = IRBaseView::handleCommand(aCommand, aReason);
   473     TIRHandleResult ret = IRBaseView::handleCommand(aCommand, aReason);
   486     
   474     
   487     switch (aCommand)
   475     switch (aCommand)
   488     {   
   476     {   
   489     case EIR_ViewCommand_ACTIVATED:
   477     case EIR_ViewCommand_ACTIVATED:         
   490         //wether to start logo downloading when activated needs more discussing and testing, future.
   478         iIconIndexArray.clear();        
   491         iIconIndexArray.clear();
   479         iListView->clearFocus();
   492         connectIsdsClient(); 
   480         iSearchPanelWidget->setFocus();        
       
   481         connectIsdsClient();
   493         break;
   482         break;
   494         
   483         
   495     case EIR_ViewCommand_DEACTIVATE:     
   484     case EIR_ViewCommand_DEACTIVATE:     
   496         disconnectIsdsClient();
   485         disconnectIsdsClient();
   497         iIsdsClient->isdsCancelRequest();            
   486         iIsdsClient->isdsCancelRequest();            
   498         iConvertTimer->stop();
   487         iConvertTimer->stop();
   499         iIsdsClient->isdsLogoDownCancelTransaction(); 
   488         iIsdsClient->isdsLogoDownCancelTransaction();
       
   489         switch2InitState();
   500         break;
   490         break;
   501 
   491 
   502     default:
   492     default:
   503         break;
   493         break;
   504     }
   494     }