qtinternetradio/ui/src/irmainview.cpp
changeset 0 09774dfdd46b
child 3 ee64f059b8e1
equal deleted inserted replaced
-1:000000000000 0:09774dfdd46b
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 #include <hbaction.h>
       
    18 #include <hblistview.h>
       
    19 
       
    20 #include "irapplication.h"
       
    21 #include "irabstractviewmanager.h"
       
    22 #include "irmainview.h"
       
    23 #include "ircategoryview.h"
       
    24 #include "irstationsview.h"
       
    25 #include "irqnetworkcontroller.h"
       
    26 #include "irmainmodel.h"
       
    27 #include "irqenums.h"
       
    28 
       
    29 //                                          public functions
       
    30 
       
    31 /*
       
    32  * Description : constructor
       
    33  */
       
    34 IRMainView::IRMainView(IRApplication* aApplication, TIRViewId aViewId) : 
       
    35                                                       IrAbstractListViewBase(aApplication, aViewId),
       
    36                                                       iMainModel(NULL)
       
    37 {
       
    38     setFlag(EViewFlag_ClearStackWhenActivate);
       
    39     
       
    40 	connect(iNetworkController, SIGNAL(networkRequestNotified(IRQNetworkEvent)),
       
    41 	        this, SLOT(networkRequestNotified(IRQNetworkEvent)));
       
    42 	setHeadingText(tr("Collections"));
       
    43 	
       
    44 	iMainModel = new IRMainModel(this);
       
    45 	iListView->setModel(iMainModel);
       
    46 }
       
    47 
       
    48 /*
       
    49  * Description : destructor
       
    50  */
       
    51 IRMainView::~IRMainView()
       
    52 {
       
    53 }
       
    54 
       
    55 /*
       
    56  * Description : virtual function from base class IRBaseView.
       
    57  *               handle view commands.
       
    58  * Parameters  : aCommand : see the definition of TIRViewCommand
       
    59  * Return      : EIR_DoDefault : caller does default handling
       
    60  *               EIR_NoDefault : caller doesn't do default handling
       
    61  */
       
    62 TIRHandleResult IRMainView::handleCommand(TIRViewCommand aCommand, TIRViewCommandReason aReason)
       
    63 {
       
    64     TIRHandleResult ret = IrAbstractListViewBase::handleCommand(aCommand, aReason);
       
    65     switch (aCommand)
       
    66     {
       
    67     case EIR_ViewCommand_ACTIVATED:
       
    68         updateView();
       
    69         ret = EIR_NoDefault;
       
    70         break;
       
    71         
       
    72     default:
       
    73         break;
       
    74     }
       
    75     
       
    76     return ret;
       
    77 }
       
    78 
       
    79 //                                       slots functions
       
    80 
       
    81 /*
       
    82  * Description : slot function when an item in a list is clicked. if network is not opened yet,
       
    83  *               choose access point firstly. Afterwards, issue a request through isds client
       
    84  *               to get category list or popular stations
       
    85  * Parameters  : aItem : pointer to the clicked item
       
    86  */
       
    87 void IRMainView::handleItemSelected()
       
    88 { 
       
    89     QModelIndex index = iListView->currentIndex();
       
    90     int currentRow = index.row();
       
    91     
       
    92     IRCategoryView *categoryView = NULL;
       
    93     
       
    94 	if (ERecentlyPlayedStations == currentRow)
       
    95 	{
       
    96         getViewManager()->activateView(EIRView_HistoryView);
       
    97 	}
       
    98 	else if (EBrowseByLanguage == currentRow)
       
    99 	{
       
   100 	    categoryView = static_cast<IRCategoryView*>(getViewManager()->getView(EIRView_CategoryView, true));
       
   101 	    categoryView->loadCategory(IRQIsdsClient::ELanguages);
       
   102 	}
       
   103 	else if (EBrowseByCountry == currentRow)
       
   104 	{
       
   105 	    categoryView = static_cast<IRCategoryView*>(getViewManager()->getView(EIRView_CategoryView, true));
       
   106 	    categoryView->loadCategory(IRQIsdsClient::ECountries);
       
   107 	}
       
   108 	else if (ESongsPlayed == currentRow)
       
   109 	{
       
   110 	    getViewManager()->activateView(EIRView_SongHistoryView);
       
   111 	}
       
   112 	else if (EPlayList == currentRow)
       
   113 	{
       
   114 	    getViewManager()->activateView(EIRView_PlsView);
       
   115 	}
       
   116 }
       
   117 
       
   118 /*
       
   119  * Description : set the checked action in toolbar. For main view, iCollectionsAction should
       
   120  *               be checked
       
   121  */
       
   122 void IRMainView::setCheckedAction()
       
   123 {
       
   124     iCollectionsAction->setChecked(true);
       
   125 }
       
   126 
       
   127 /*
       
   128  * Description : slot function for active network event
       
   129  * Parameters  : aEvent, see the definition of IRQNetworkEvent
       
   130  */
       
   131 void IRMainView::networkRequestNotified(IRQNetworkEvent aEvent)
       
   132 {
       
   133     //simulate the item is clicked
       
   134     if (getViewManager()->currentView() != this)
       
   135     {
       
   136         return;
       
   137     }
       
   138     
       
   139     switch (aEvent)
       
   140     {
       
   141     case EIRQNetworkConnectionEstablished:
       
   142         iApplication->closeConnectingDialog();
       
   143         
       
   144         if (EIR_UseNetwork_SelectItem == getUseNetworkReason())
       
   145         {
       
   146             handleItemSelected();
       
   147         }
       
   148         setUseNetworkReason(EIR_UseNetwork_NoReason);
       
   149         
       
   150         break;
       
   151         
       
   152     default:
       
   153         setCheckedAction();
       
   154         break;
       
   155     }
       
   156 }
       
   157 
       
   158 /*
       
   159  * Description : check wether the content we need is already cached
       
   160  *  
       
   161  */
       
   162 void IRMainView::itemAboutToBeSelected(bool& aNeedNetwork)
       
   163 {
       
   164     QModelIndex index = iListView->currentIndex();
       
   165     int currentRow = index.row();    
       
   166     
       
   167     if (EBrowseByLanguage == currentRow)
       
   168     {
       
   169         aNeedNetwork = !iIsdsClient->isdsIsCategoryCached(IRQIsdsClient::ELanguages);
       
   170     }
       
   171     else if (EBrowseByCountry == currentRow)
       
   172     {        
       
   173         aNeedNetwork = !iIsdsClient->isdsIsCategoryCached(IRQIsdsClient::ECountries);
       
   174     }     
       
   175     else if( ESongsPlayed == currentRow )
       
   176     {
       
   177         aNeedNetwork = false;
       
   178     }
       
   179     else if( ERecentlyPlayedStations == currentRow)
       
   180     {
       
   181         aNeedNetwork = false;
       
   182     }
       
   183     else if (EPlayList == currentRow)
       
   184     {
       
   185         aNeedNetwork = false;
       
   186     }
       
   187     else  
       
   188     {
       
   189         aNeedNetwork = true;         
       
   190     }         
       
   191 }
       
   192 
       
   193 void IRMainView::updateView()
       
   194 {
       
   195     IrAbstractListViewBase::updateView();
       
   196     iMainModel->checkUpdate();
       
   197 }