qtinternetradio/ui/src/ircategoryview.cpp
branchGCC_SURGE
changeset 13 c9471d26c7f2
parent 12 608f67c22514
child 14 896e9dbc5f19
equal deleted inserted replaced
9:bfc95e24a059 13:c9471d26c7f2
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 
    17 
       
    18 #include <hbtoolbar.h>
    18 #include <hbaction.h>
    19 #include <hbaction.h>
    19 #include <hblistview.h>
    20 #include <hblistview.h>
    20 #include <hbprogressdialog.h>
       
    21 
    21 
    22 #include "irapplication.h"
    22 #include "irapplication.h"
    23 #include "irviewmanager.h"
    23 #include "irviewmanager.h"
    24 #include "ircategoryview.h"
    24 #include "ircategoryview.h"
    25 #include "irstationsview.h"
    25 #include "irstationsview.h"
    32 /*
    32 /*
    33  * Description : constructor
    33  * Description : constructor
    34  */
    34  */
    35 IRCategoryView::IRCategoryView(IRApplication* aApplication, TIRViewId aViewId) 
    35 IRCategoryView::IRCategoryView(IRApplication* aApplication, TIRViewId aViewId) 
    36                                : IrAbstractListViewBase(aApplication, aViewId),
    36                                : IrAbstractListViewBase(aApplication, aViewId),
    37                                  iWaitDialog(NULL),
       
    38                                  iLastSelectItem(0)
    37                                  iLastSelectItem(0)
    39 {	
    38 {	
    40     setViewParameter(EIRViewPara_Genre);
    39     setViewParameter(EIRViewPara_Genre);
    41     setFlag(EViewFlag_ClearStackWhenActivate);
    40     setFlag(EViewFlag_ClearStackWhenActivate|EViewFlag_StickyViewEnabled);
    42     
    41     
    43     //if this view is not starting view, finish all initialization in constructor
    42     //if this view is not starting view, finish all initialization in constructor
    44     if (getViewManager()->views().count() > 0)
    43     if (getViewManager()->views().count() > 0)
    45     {
    44     {
    46         normalInit();
    45         normalInit();
    50 /*
    49 /*
    51  * Description : destructor
    50  * Description : destructor
    52  */
    51  */
    53 IRCategoryView::~IRCategoryView()
    52 IRCategoryView::~IRCategoryView()
    54 {
    53 {
    55     delete iWaitDialog;
       
    56     iWaitDialog = NULL;
       
    57 }
    54 }
    58 
    55 
    59 /*
    56 /*
    60  * Description : virtual functions from base class IRBaseView. 
    57  * Description : virtual functions from base class IRBaseView. 
    61  *               handle view commands
    58  *               handle view commands
    80             {
    77             {
    81                 if (ABSTRACT_LIST_VIEW_BASE_WITH_TOOLBAR_SECTION != iLoadedSection)
    78                 if (ABSTRACT_LIST_VIEW_BASE_WITH_TOOLBAR_SECTION != iLoadedSection)
    82                 {
    79                 {
    83                     iLoader.load(ABSTRACT_LIST_VIEW_BASE_LAYOUT_FILENAME, ABSTRACT_LIST_VIEW_BASE_WITH_TOOLBAR_SECTION);
    80                     iLoader.load(ABSTRACT_LIST_VIEW_BASE_LAYOUT_FILENAME, ABSTRACT_LIST_VIEW_BASE_WITH_TOOLBAR_SECTION);
    84                     iLoadedSection = ABSTRACT_LIST_VIEW_BASE_WITH_TOOLBAR_SECTION;
    81                     iLoadedSection = ABSTRACT_LIST_VIEW_BASE_WITH_TOOLBAR_SECTION;
       
    82                     initToolBar();
    85                 }
    83                 }
    86             }
    84             }
    87             else
    85             else
    88             {
    86             {
    89                 if (ABSTRACT_LIST_VIEW_BASE_NO_TOOLBAR_SECTION != iLoadedSection)
    87                 if (ABSTRACT_LIST_VIEW_BASE_NO_TOOLBAR_SECTION != iLoadedSection)
    90                 {
    88                 {
    91                     iLoader.load(ABSTRACT_LIST_VIEW_BASE_LAYOUT_FILENAME, ABSTRACT_LIST_VIEW_BASE_NO_TOOLBAR_SECTION);
    89                     iLoader.load(ABSTRACT_LIST_VIEW_BASE_LAYOUT_FILENAME, ABSTRACT_LIST_VIEW_BASE_NO_TOOLBAR_SECTION);
    92                     iLoadedSection = ABSTRACT_LIST_VIEW_BASE_NO_TOOLBAR_SECTION;
    90                     iLoadedSection = ABSTRACT_LIST_VIEW_BASE_NO_TOOLBAR_SECTION;
       
    91                     setToolBar(NULL);
    93                 }
    92                 }
    94             }
    93             }
    95         }
    94         }
    96         break;
    95         break;
    97         
    96 
    98         case EIR_ViewCommand_ACTIVATED:
    97         case EIR_ViewCommand_ACTIVATED:
    99         break;
    98             if (EIRViewPara_Genre == getViewParameter())
   100         
       
   101         case EIR_ViewCommand_DEACTIVATE:
       
   102             if (iWaitDialog)
       
   103             {
    99             {
   104                 iWaitDialog->close();
   100                 getViewManager()->saveScreenShot();
   105                 ret = EIR_NoDefault;
       
   106             }
   101             }
   107             break;
   102             break;
   108             
   103             
   109         default:
   104         default:
   110             break;
   105             break;
   113     return ret;
   108     return ret;
   114 }
   109 }
   115 
   110 
   116 void IRCategoryView::launchAction()
   111 void IRCategoryView::launchAction()
   117 {    
   112 {    
   118     bool ret = false;
   113     Q_ASSERT(EIRViewPara_Genre == iViewParameter);
   119     switch(iViewParameter)
   114     bool ret = iIsdsClient->isdsIsCategoryCached(IRQIsdsClient::EGenre);
   120     {
   115 
   121         case EIRViewPara_Genre:
       
   122             ret = iIsdsClient->isdsIsCategoryCached(IRQIsdsClient::EGenre);
       
   123             break;
       
   124         case EIRViewPara_Language:
       
   125             ret = iIsdsClient->isdsIsCategoryCached(IRQIsdsClient::ELanguages);
       
   126             break;
       
   127         case EIRViewPara_Country:
       
   128             ret = iIsdsClient->isdsIsCategoryCached(IRQIsdsClient::ECountries);
       
   129             break;
       
   130 
       
   131         default:
       
   132             break;
       
   133     }
       
   134     
       
   135     if ( !ret )
   116     if ( !ret )
   136     {
   117     {
   137         setUseNetworkReason(EIR_UseNetwork_StartingView);
   118         setUseNetworkReason(EIR_UseNetwork_StartingView);
   138         iApplication->verifyNetworkConnectivity();
   119         iApplication->verifyNetworkConnectivity();
   139     }   
   120     }   
   178         {
   159         {
   179             //the view is used for other categories other than Genre
   160             //the view is used for other categories other than Genre
   180             resetCurrentItem();
   161             resetCurrentItem();
   181         }
   162         }
   182         setViewParameter(EIRViewPara_Genre);
   163         setViewParameter(EIRViewPara_Genre);
   183         setFlag(EViewFlag_ClearStackWhenActivate);
   164         setFlag(EViewFlag_ClearStackWhenActivate|EViewFlag_StickyViewEnabled);
   184         iIsdsClient->isdsCategoryRequest(IRQIsdsClient::EGenre, cache);
   165         iIsdsClient->isdsCategoryRequest(IRQIsdsClient::EGenre, cache);
   185         break;
   166         break;
   186         
   167         
   187     case IRQIsdsClient::ELanguages : 
   168     case IRQIsdsClient::ELanguages : 
       
   169 #ifdef SUBTITLE_STR_BY_LOCID
   188         setHeadingText(hbTrId("txt_irad_list_stations_by_language"));
   170         setHeadingText(hbTrId("txt_irad_list_stations_by_language"));
       
   171 #else
       
   172         setHeadingText(hbTrId("Stations by language"));        
       
   173 #endif
   189         if (EIRViewPara_Language != getViewParameter())
   174         if (EIRViewPara_Language != getViewParameter())
   190         {
   175         {
   191             //the view is used for other categories other than Language
   176             //the view is used for other categories other than Language
   192             resetCurrentItem();
   177             resetCurrentItem();
   193         }
   178         }
   194         setViewParameter(EIRViewPara_Language);
   179         setViewParameter(EIRViewPara_Language);
   195         setFlag(EViewFlag_None);
   180         clearFlag(EViewFlag_ClearStackWhenActivate);
       
   181         clearFlag(EViewFlag_StickyViewEnabled);
   196         iIsdsClient->isdsCategoryRequest(IRQIsdsClient::ELanguages, cache);
   182         iIsdsClient->isdsCategoryRequest(IRQIsdsClient::ELanguages, cache);
   197         break;
   183         break;
   198         
   184         
   199     case IRQIsdsClient::ECountries :
   185     case IRQIsdsClient::ECountries :
       
   186 #ifdef SUBTITLE_STR_BY_LOCID
   200         setHeadingText(hbTrId("txt_irad_list_stations_by_country_region"));
   187         setHeadingText(hbTrId("txt_irad_list_stations_by_country_region"));
       
   188 #else
       
   189         setHeadingText(hbTrId("Stations by country/region"));        
       
   190 #endif
   201         if (EIRViewPara_Country != getViewParameter())
   191         if (EIRViewPara_Country != getViewParameter())
   202         {
   192         {
   203             //the view is used for other categories other than Country
   193             //the view is used for other categories other than Country
   204             resetCurrentItem();
   194             resetCurrentItem();
   205         }
   195         }
   206         setViewParameter(EIRViewPara_Country);
   196         setViewParameter(EIRViewPara_Country);
   207         setFlag(EViewFlag_None);
   197         clearFlag(EViewFlag_ClearStackWhenActivate);
       
   198         clearFlag(EViewFlag_StickyViewEnabled);
   208         iIsdsClient->isdsCategoryRequest(IRQIsdsClient::ECountries, cache);
   199         iIsdsClient->isdsCategoryRequest(IRQIsdsClient::ECountries, cache);
   209         break;
   200         break;
   210         
   201         
   211     default:
   202     default:
   212         Q_ASSERT(false);
   203         Q_ASSERT(false);
   213         break;
   204         break;
   214     }
   205     }
   215     
   206     
   216     if (!cache)
   207     if (!cache)
   217     {
   208     {
   218         createWaitDialog(hbTrId("txt_common_info_loading"));
   209         iApplication->startLoadingAnimation(this, SLOT(cancelRequest()));
   219     }
   210     }
   220 }
   211 }
   221 
   212 
   222 void IRCategoryView::storeCurrentItem()
   213 void IRCategoryView::storeCurrentItem()
   223 {
   214 {
   273             }
   264             }
   274 
   265 
   275             connectToIsdsClient();
   266             connectToIsdsClient();
   276             bool cache = false;
   267             bool cache = false;
   277             iIsdsClient->isdsCategoryRequest(request, cache);
   268             iIsdsClient->isdsCategoryRequest(request, cache);
       
   269             iApplication->startLoadingAnimation(this, SLOT(cancelRequest()));
   278         }
   270         }
   279         //for there may be some cache, and when we click, we need to handle here        
   271         //for there may be some cache, and when we click, we need to handle here        
   280         else if ( EIR_UseNetwork_SelectItem == getUseNetworkReason())
   272         else if ( EIR_UseNetwork_SelectItem == getUseNetworkReason())
   281         {
   273         {
   282             iApplication->closeConnectingDialog();
       
   283             handleItemSelected();               
   274             handleItemSelected();               
   284         }        
   275         }        
   285         
   276         
   286         setUseNetworkReason(EIR_UseNetwork_NoReason);
       
   287         break;
   277         break;
   288        
   278        
   289     case EIRQConnectingCancelled:
   279     case EIRQConnectingCancelled:
   290     case EIRQDisplayNetworkMessageNoConnectivity:
   280     case EIRQDisplayNetworkMessageNoConnectivity:
   291         if (iListView->model()->rowCount() == 0)
   281         if (iListView->model()->rowCount() == 0)
   301         
   291         
   302     default:
   292     default:
   303         setCheckedAction();
   293         setCheckedAction();
   304         break;
   294         break;
   305     }
   295     }
       
   296     
       
   297     setUseNetworkReason(EIR_UseNetwork_NoReason);
   306 }
   298 }
   307 
   299 
   308 
   300 
   309 //                                 slots functions 
   301 //                                 slots functions 
   310 
   302 
   360  * 
   352  * 
   361  */
   353  */
   362 void IRCategoryView::dataChanged()
   354 void IRCategoryView::dataChanged()
   363 {
   355 {
   364     disconnectIsdsClient();
   356     disconnectIsdsClient();
   365     iApplication->closeConnectingDialog();
   357     iApplication->stopLoadingAnimation();
   366 
   358 
   367     iListView->reset();
   359     iListView->reset();
   368     iListView->setCurrentIndex(iModel->index(iLastSelectItem));
   360     iListView->setCurrentIndex(iModel->index(iLastSelectItem));
   369     iListView->scrollTo(iModel->index(iLastSelectItem));
   361     iListView->scrollTo(iModel->index(iLastSelectItem));
   370     getViewManager()->activateView(this);
   362     getViewManager()->activateView(this);
   371     
       
   372     if (iWaitDialog)
       
   373     {
       
   374         iWaitDialog->close();
       
   375     }
       
   376 }
   363 }
   377 
   364 
   378 /*
   365 /*
   379  * Description : slot function for canceling request.
   366  * Description : slot function for canceling request.
   380  *               Before data is received, cancel requests through isds client
   367  *               Before data is received, cancel requests through isds client
   381  */
   368  */
   382 void IRCategoryView::cancelRequest()
   369 void IRCategoryView::cancelRequest()
   383 {
   370 {
   384     iIsdsClient->isdsCancelRequest();
   371     iIsdsClient->isdsCancelRequest();
   385     disconnectIsdsClient();
   372     disconnectIsdsClient();
       
   373     iApplication->stopLoadingAnimation();
       
   374     
       
   375     //if this function is called and this view is current view, it indicates that this view is starting view and 
       
   376     //data has not been loaded yet, so we need to back to collections view
       
   377     if (getViewManager()->currentView() == this)
       
   378     {
       
   379         getViewManager()->activateView(EIRView_MainView);
       
   380     }
   386 }
   381 }
   387 
   382 
   388 /*
   383 /*
   389  * Description  : slot function for operation failure. The signal is emitted by isds client
   384  * Description  : slot function for operation failure. The signal is emitted by isds client
   390  * Parameters   : aError : see the definition of IRQError
   385  * Parameters   : aError : see the definition of IRQError
   391  */
   386  */
   392 void IRCategoryView::operationException(IRQError aError)
   387 void IRCategoryView::operationException(IRQError aError)
   393 {
   388 {
   394     Q_UNUSED(aError);
   389     Q_UNUSED(aError);
   395     iApplication->closeConnectingDialog();
   390     iApplication->stopLoadingAnimation();
   396     
   391 
   397     if (iWaitDialog)
       
   398     {
       
   399         iWaitDialog->close();
       
   400     }
       
   401     
       
   402     disconnectIsdsClient();
   392     disconnectIsdsClient();
   403     
   393     
       
   394 #ifdef SUBTITLE_STR_BY_LOCID
   404     popupNote(hbTrId("txt_irad_info_failed_to_connect"), HbMessageBox::MessageTypeWarning);
   395     popupNote(hbTrId("txt_irad_info_failed_to_connect"), HbMessageBox::MessageTypeWarning);
       
   396 #else
       
   397     popupNote(hbTrId("Connecting failed"), HbMessageBox::MessageTypeWarning);
       
   398 #endif
   405     
   399     
   406     //if category view is starting view and failed to get data from ISDS server, back to main view
   400     //if category view is starting view and failed to get data from ISDS server, back to main view
   407     if (getViewManager()->currentView() == this &&
   401     if (getViewManager()->currentView() == this &&
   408         iListView->model()->rowCount() == 0)
   402         iListView->model()->rowCount() == 0)
   409     {
   403     {
   410         getViewManager()->activateView(EIRView_MainView);
   404         getViewManager()->activateView(EIRView_MainView);
   411     }
   405     }
   412 }
   406 }
   413 
   407 
   414 //                                        private functions
   408 //                                        private functions
   415 
       
   416 /*
       
   417  * Description : Show a wait dialog to inform user that data is being loaded. If wait dialog doesn't
       
   418  *               exist yet, create first
       
   419  */
       
   420 void IRCategoryView::createWaitDialog(const QString &aText)
       
   421 {
       
   422     if (!iWaitDialog)
       
   423     {
       
   424         iWaitDialog = new HbProgressDialog(HbProgressDialog::WaitDialog);
       
   425         iWaitDialog->setTimeout(HbPopup::NoTimeout);
       
   426         iWaitDialog->setModal(true);
       
   427         iWaitDialog->setDismissPolicy(HbPopup::NoDismiss);
       
   428         QAction *action = iWaitDialog->actions().at(0);
       
   429         action->setText(hbTrId("txt_common_button_cancel"));
       
   430         connect(action, SIGNAL(triggered()), this, SLOT(cancelRequest()));
       
   431     }
       
   432     
       
   433     iWaitDialog->setText(aText);
       
   434     iWaitDialog->open();
       
   435 }
       
   436 
   409 
   437 void IRCategoryView::connectToIsdsClient()
   410 void IRCategoryView::connectToIsdsClient()
   438 {
   411 {
   439     connect(iIsdsClient, SIGNAL(categoryItemsChanged(QList<IRQBrowseCategoryItem *> *)),
   412     connect(iIsdsClient, SIGNAL(categoryItemsChanged(QList<IRQBrowseCategoryItem *> *)),
   440             iModel, SLOT(categoryReceived(QList<IRQBrowseCategoryItem *> *)));
   413             iModel, SLOT(categoryReceived(QList<IRQBrowseCategoryItem *> *)));
   497                 SLOT(networkRequestNotified(IRQNetworkEvent)));
   470                 SLOT(networkRequestNotified(IRQNetworkEvent)));
   498     
   471     
   499         setInitCompleted(true);
   472         setInitCompleted(true);
   500     }
   473     }
   501 }
   474 }
       
   475 
       
   476 void IRCategoryView::initToolBar()
       
   477 {
       
   478     //add HbActions to the toolbar, the HbActions have been created in IrAbstractListViewBase
       
   479     HbToolBar *viewToolBar = toolBar();
       
   480     viewToolBar->clearActions();
       
   481     viewToolBar->addAction(iGenresAction);
       
   482     viewToolBar->addAction(iCollectionsAction);
       
   483     viewToolBar->addAction(iFavoritesAction);
       
   484     viewToolBar->addAction(iSearchAction);
       
   485     viewToolBar->setVisible(true);
       
   486 }