qtinternetradio/ui/src/ircategoryview.cpp
changeset 5 0930554dc389
parent 3 ee64f059b8e1
child 8 3b03c28289e6
equal deleted inserted replaced
3:ee64f059b8e1 5:0930554dc389
    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)
    92                     iLoadedSection = ABSTRACT_LIST_VIEW_BASE_NO_TOOLBAR_SECTION;
    90                     iLoadedSection = ABSTRACT_LIST_VIEW_BASE_NO_TOOLBAR_SECTION;
    93                 }
    91                 }
    94             }
    92             }
    95         }
    93         }
    96         break;
    94         break;
    97         
    95 
    98         case EIR_ViewCommand_ACTIVATED:
       
    99         break;
       
   100         
       
   101         case EIR_ViewCommand_DEACTIVATE:
       
   102             if (iWaitDialog)
       
   103             {
       
   104                 iWaitDialog->close();
       
   105                 ret = EIR_NoDefault;
       
   106             }
       
   107             break;
       
   108             
       
   109         default:
    96         default:
   110             break;
    97             break;
   111     }
    98     }
   112     
    99     
   113     return ret;
   100     return ret;
   178         {
   165         {
   179             //the view is used for other categories other than Genre
   166             //the view is used for other categories other than Genre
   180             resetCurrentItem();
   167             resetCurrentItem();
   181         }
   168         }
   182         setViewParameter(EIRViewPara_Genre);
   169         setViewParameter(EIRViewPara_Genre);
   183         setFlag(EViewFlag_ClearStackWhenActivate);
   170         setFlag(EViewFlag_ClearStackWhenActivate|EViewFlag_StickyViewEnabled);
   184         iIsdsClient->isdsCategoryRequest(IRQIsdsClient::EGenre, cache);
   171         iIsdsClient->isdsCategoryRequest(IRQIsdsClient::EGenre, cache);
   185         break;
   172         break;
   186         
   173         
   187     case IRQIsdsClient::ELanguages : 
   174     case IRQIsdsClient::ELanguages : 
   188         setHeadingText(hbTrId("txt_irad_list_stations_by_language"));
   175         setHeadingText(hbTrId("txt_irad_list_stations_by_language"));
   190         {
   177         {
   191             //the view is used for other categories other than Language
   178             //the view is used for other categories other than Language
   192             resetCurrentItem();
   179             resetCurrentItem();
   193         }
   180         }
   194         setViewParameter(EIRViewPara_Language);
   181         setViewParameter(EIRViewPara_Language);
   195         setFlag(EViewFlag_None);
   182         clearFlag(EViewFlag_ClearStackWhenActivate);
       
   183         clearFlag(EViewFlag_StickyViewEnabled);
   196         iIsdsClient->isdsCategoryRequest(IRQIsdsClient::ELanguages, cache);
   184         iIsdsClient->isdsCategoryRequest(IRQIsdsClient::ELanguages, cache);
   197         break;
   185         break;
   198         
   186         
   199     case IRQIsdsClient::ECountries :
   187     case IRQIsdsClient::ECountries :
   200         setHeadingText(hbTrId("txt_irad_list_stations_by_country_region"));
   188         setHeadingText(hbTrId("txt_irad_list_stations_by_country_region"));
   202         {
   190         {
   203             //the view is used for other categories other than Country
   191             //the view is used for other categories other than Country
   204             resetCurrentItem();
   192             resetCurrentItem();
   205         }
   193         }
   206         setViewParameter(EIRViewPara_Country);
   194         setViewParameter(EIRViewPara_Country);
   207         setFlag(EViewFlag_None);
   195         clearFlag(EViewFlag_ClearStackWhenActivate);
       
   196         clearFlag(EViewFlag_StickyViewEnabled);
   208         iIsdsClient->isdsCategoryRequest(IRQIsdsClient::ECountries, cache);
   197         iIsdsClient->isdsCategoryRequest(IRQIsdsClient::ECountries, cache);
   209         break;
   198         break;
   210         
   199         
   211     default:
   200     default:
   212         Q_ASSERT(false);
   201         Q_ASSERT(false);
   213         break;
   202         break;
   214     }
   203     }
   215     
   204     
   216     if (!cache)
   205     if (!cache)
   217     {
   206     {
   218         createWaitDialog(hbTrId("txt_common_info_loading"));
   207         iApplication->createLoadingDialog(this, SLOT(cancelRequest()));
   219     }
   208     }
   220 }
   209 }
   221 
   210 
   222 void IRCategoryView::storeCurrentItem()
   211 void IRCategoryView::storeCurrentItem()
   223 {
   212 {
   273             }
   262             }
   274 
   263 
   275             connectToIsdsClient();
   264             connectToIsdsClient();
   276             bool cache = false;
   265             bool cache = false;
   277             iIsdsClient->isdsCategoryRequest(request, cache);
   266             iIsdsClient->isdsCategoryRequest(request, cache);
       
   267             iApplication->createLoadingDialog(this, SLOT(cancelRequest()));
   278         }
   268         }
   279         //for there may be some cache, and when we click, we need to handle here        
   269         //for there may be some cache, and when we click, we need to handle here        
   280         else if ( EIR_UseNetwork_SelectItem == getUseNetworkReason())
   270         else if ( EIR_UseNetwork_SelectItem == getUseNetworkReason())
   281         {
   271         {
   282             iApplication->closeConnectingDialog();
       
   283             handleItemSelected();               
   272             handleItemSelected();               
   284         }        
   273         }        
   285         
   274         
   286         setUseNetworkReason(EIR_UseNetwork_NoReason);
       
   287         break;
   275         break;
   288        
   276        
   289     case EIRQConnectingCancelled:
   277     case EIRQConnectingCancelled:
   290     case EIRQDisplayNetworkMessageNoConnectivity:
   278     case EIRQDisplayNetworkMessageNoConnectivity:
   291         if (iListView->model()->rowCount() == 0)
   279         if (iListView->model()->rowCount() == 0)
   301         
   289         
   302     default:
   290     default:
   303         setCheckedAction();
   291         setCheckedAction();
   304         break;
   292         break;
   305     }
   293     }
       
   294     
       
   295     setUseNetworkReason(EIR_UseNetwork_NoReason);
   306 }
   296 }
   307 
   297 
   308 
   298 
   309 //                                 slots functions 
   299 //                                 slots functions 
   310 
   300 
   360  * 
   350  * 
   361  */
   351  */
   362 void IRCategoryView::dataChanged()
   352 void IRCategoryView::dataChanged()
   363 {
   353 {
   364     disconnectIsdsClient();
   354     disconnectIsdsClient();
   365     iApplication->closeConnectingDialog();
   355     iApplication->closeLoadingDialog();
   366 
   356 
   367     iListView->reset();
   357     iListView->reset();
   368     iListView->setCurrentIndex(iModel->index(iLastSelectItem));
   358     iListView->setCurrentIndex(iModel->index(iLastSelectItem));
   369     iListView->scrollTo(iModel->index(iLastSelectItem));
   359     iListView->scrollTo(iModel->index(iLastSelectItem));
   370     getViewManager()->activateView(this);
   360     getViewManager()->activateView(this);
   371     
       
   372     if (iWaitDialog)
       
   373     {
       
   374         iWaitDialog->close();
       
   375     }
       
   376 }
   361 }
   377 
   362 
   378 /*
   363 /*
   379  * Description : slot function for canceling request.
   364  * Description : slot function for canceling request.
   380  *               Before data is received, cancel requests through isds client
   365  *               Before data is received, cancel requests through isds client
   381  */
   366  */
   382 void IRCategoryView::cancelRequest()
   367 void IRCategoryView::cancelRequest()
   383 {
   368 {
   384     iIsdsClient->isdsCancelRequest();
   369     iIsdsClient->isdsCancelRequest();
   385     disconnectIsdsClient();
   370     disconnectIsdsClient();
       
   371     iApplication->closeLoadingDialog();
       
   372     
       
   373     //if this function is called and this view is current view, it indicates that this view is starting view and 
       
   374     //data has not been loaded yet, so we need to back to collections view
       
   375     if (getViewManager()->currentView() == this)
       
   376     {
       
   377         getViewManager()->activateView(EIRView_MainView);
       
   378     }
   386 }
   379 }
   387 
   380 
   388 /*
   381 /*
   389  * Description  : slot function for operation failure. The signal is emitted by isds client
   382  * Description  : slot function for operation failure. The signal is emitted by isds client
   390  * Parameters   : aError : see the definition of IRQError
   383  * Parameters   : aError : see the definition of IRQError
   391  */
   384  */
   392 void IRCategoryView::operationException(IRQError aError)
   385 void IRCategoryView::operationException(IRQError aError)
   393 {
   386 {
   394     Q_UNUSED(aError);
   387     Q_UNUSED(aError);
   395     iApplication->closeConnectingDialog();
   388     iApplication->closeLoadingDialog();
   396     
   389 
   397     if (iWaitDialog)
       
   398     {
       
   399         iWaitDialog->close();
       
   400     }
       
   401     
       
   402     disconnectIsdsClient();
   390     disconnectIsdsClient();
   403     
   391     
   404     popupNote(hbTrId("txt_irad_info_failed_to_connect"), HbMessageBox::MessageTypeWarning);
   392     popupNote(hbTrId("txt_irad_info_failed_to_connect"), HbMessageBox::MessageTypeWarning);
   405     
   393     
   406     //if category view is starting view and failed to get data from ISDS server, back to main view
   394     //if category view is starting view and failed to get data from ISDS server, back to main view
   410         getViewManager()->activateView(EIRView_MainView);
   398         getViewManager()->activateView(EIRView_MainView);
   411     }
   399     }
   412 }
   400 }
   413 
   401 
   414 //                                        private functions
   402 //                                        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 
   403 
   437 void IRCategoryView::connectToIsdsClient()
   404 void IRCategoryView::connectToIsdsClient()
   438 {
   405 {
   439     connect(iIsdsClient, SIGNAL(categoryItemsChanged(QList<IRQBrowseCategoryItem *> *)),
   406     connect(iIsdsClient, SIGNAL(categoryItemsChanged(QList<IRQBrowseCategoryItem *> *)),
   440             iModel, SLOT(categoryReceived(QList<IRQBrowseCategoryItem *> *)));
   407             iModel, SLOT(categoryReceived(QList<IRQBrowseCategoryItem *> *)));
   497                 SLOT(networkRequestNotified(IRQNetworkEvent)));
   464                 SLOT(networkRequestNotified(IRQNetworkEvent)));
   498     
   465     
   499         setInitCompleted(true);
   466         setInitCompleted(true);
   500     }
   467     }
   501 }
   468 }
       
   469 
       
   470 void IRCategoryView::initToolBar()
       
   471 {
       
   472     //add HbActions to the toolbar, the HbActions have been created in IrAbstractListViewBase
       
   473     HbToolBar *viewToolBar = toolBar();
       
   474     viewToolBar->addAction(iGenresAction);
       
   475     viewToolBar->addAction(iCollectionsAction);
       
   476     viewToolBar->addAction(iFavoritesAction);
       
   477     viewToolBar->addAction(iSearchAction);
       
   478 }