qtinternetradio/ui/src/irfavoritesview.cpp
changeset 3 ee64f059b8e1
parent 0 09774dfdd46b
child 5 0930554dc389
equal deleted inserted replaced
2:2e1adbfc62af 3:ee64f059b8e1
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 #include <hblistview.h>
    17 #include <hblistview.h>
       
    18 #include <hbtoolbar.h>
    18 #include <hbaction.h>
    19 #include <hbaction.h>
    19 #include <hbmenu.h>
    20 #include <hbmenu.h>
    20 #include <QPixmap>
    21 #include <QPixmap>
    21 #include <QTimer>
    22 #include <QTimer>
    22 
    23 
    23 #include "irabstractviewmanager.h"
    24 #include "irviewmanager.h"
    24 #include "irfavoritesview.h"
    25 #include "irfavoritesview.h"
    25 #include "irapplication.h"
    26 #include "irapplication.h"
    26 #include "irqfavoritesdb.h"
    27 #include "irqfavoritesdb.h"
    27 #include "irqisdsclient.h"
    28 #include "irqisdsclient.h"
    28 #include "irqnetworkcontroller.h"
    29 #include "irqnetworkcontroller.h"
    29 #include "irplaycontroller.h"
    30 #include "irplaycontroller.h"
    30 #include "irfavoritesmodel.h"
    31 #include "irfavoritesmodel.h"
    31 #include "irqenums.h"
    32 #include "irqenums.h"
    32 #include "irqisdsdatastructure.h"
    33 #include "irqisdsdatastructure.h"
    33 #include "irqutility.h"
    34 #include "irqutility.h"
       
    35 #include "iruidefines.h"
    34 
    36 
    35 const int KBitmapSize = 59;
    37 const int KBitmapSize = 59;
       
    38 
       
    39 const QString KActionShareName("Share");
       
    40 const QString KActionDeleteName("Delete");
       
    41 const QString KActionRenameName("Rename");
       
    42 const QString KActionDetailsName("Details");
       
    43 
    36 //                                        public functions
    44 //                                        public functions
    37 
    45 
    38 /*
    46 /*
    39  * Description : constructor
    47  * Description : constructor
    40  */
    48  */
    41 IRFavoritesView::IRFavoritesView(IRApplication *aApplication, TIRViewId aViewId) 
    49 IRFavoritesView::IRFavoritesView(IRApplication *aApplication, TIRViewId aViewId) 
    42                                  : IrAbstractListViewBase(aApplication, aViewId),
    50                                  : IrAbstractListViewBase(aApplication, aViewId),
    43                                    iClearFavoriteAction(NULL),iLogoPreset(NULL)
    51                                    iClearFavoriteAction(NULL),iLogoPreset(NULL)								  
    44 								  
       
    45 {    
    52 {    
    46     iClearFavoriteAction = new HbAction(hbTrId("txt_irad_opt_clear_favorites"), menu());
    53     setFlag(EViewFlag_ClearStackWhenActivate);
    47     connect(iClearFavoriteAction, SIGNAL(triggered()), this, SLOT(clearAllFavorites()));    
    54     
    48   
    55     //if this view is not starting view, finish all initialization in constructor
    49     iModel = new IRFavoritesModel(iFavorites, this);
    56     if (getViewManager()->views().count() > 0)
    50     iListView->setModel(iModel);
    57     {
    51     iListView->setCurrentIndex(iModel->index(0));
    58         normalInit();
    52     
    59     }
    53     iConvertTimer = new QTimer(this);
       
    54     iConvertTimer->setInterval(10);
       
    55     
       
    56     connect(iModel, SIGNAL(modelChanged()), this, SLOT(modelChanged()));
       
    57     connect(iNetworkController, SIGNAL(networkRequestNotified(IRQNetworkEvent)),
       
    58             this, SLOT(networkRequestNotified(IRQNetworkEvent))); 
       
    59     connect(iConvertTimer, SIGNAL(timeout()), this, SLOT(convertAnother()));
       
    60 }
    60 }
    61 
    61 
    62 /*
    62 /*
    63  * Description : destructor
    63  * Description : destructor
    64  */
    64  */
    69 }
    69 }
    70 
    70 
    71 TIRHandleResult IRFavoritesView::handleCommand(TIRViewCommand aCommand, TIRViewCommandReason aReason)
    71 TIRHandleResult IRFavoritesView::handleCommand(TIRViewCommand aCommand, TIRViewCommandReason aReason)
    72 {
    72 {
    73     Q_UNUSED(aReason);
    73     Q_UNUSED(aReason);
       
    74     
       
    75     if (!initCompleted())
       
    76     {
       
    77         return EIR_DoDefault;
       
    78     }
       
    79     
    74     TIRHandleResult ret = IrAbstractListViewBase::handleCommand(aCommand, aReason);
    80     TIRHandleResult ret = IrAbstractListViewBase::handleCommand(aCommand, aReason);
    75     int leftCount = 0;
    81     int leftCount = 0;
    76     
    82     
    77     switch (aCommand)
    83     switch (aCommand)
    78     {
    84     {
    80         connect(iIsdsClient, SIGNAL(presetLogoDownloaded(IRQPreset* )),
    86         connect(iIsdsClient, SIGNAL(presetLogoDownloaded(IRQPreset* )),
    81                 this, SLOT(presetLogoDownload(IRQPreset* )));
    87                 this, SLOT(presetLogoDownload(IRQPreset* )));
    82         connect(iIsdsClient, SIGNAL(presetLogoDownloadError()),
    88         connect(iIsdsClient, SIGNAL(presetLogoDownloadError()),
    83                 this, SLOT(presetLogoDownloadError()));
    89                 this, SLOT(presetLogoDownloadError()));
    84         
    90         
    85         
    91         iModel->checkFavoritesUpdate();
    86         iModel->checkFavoritesUpdate();          
    92         
       
    93         leftCount = iIconIndexArray.count();
       
    94         if( leftCount > 0 )
       
    95         {
       
    96             iConvertTimer->start();
       
    97         }
    87         ret = EIR_NoDefault;
    98         ret = EIR_NoDefault;
    88         break;
    99         break;
    89 
   100 
    90     case EIR_ViewCommand_DEACTIVATE:        		 
   101     case EIR_ViewCommand_DEACTIVATE:        		 
    91         
   102         
   101         disconnect(iIsdsClient, SIGNAL(presetLogoDownloadError()),
   112         disconnect(iIsdsClient, SIGNAL(presetLogoDownloadError()),
   102                    this, SLOT(presetLogoDownloadError()));
   113                    this, SLOT(presetLogoDownloadError()));
   103 
   114 
   104         ret = EIR_NoDefault;
   115         ret = EIR_NoDefault;
   105         break;
   116         break;
   106      
       
   107     case EIR_ViewCommand_EffectFinished:
       
   108         
       
   109         /* when the effect is finished, we start showing the logos  */
       
   110         leftCount = iIconIndexArray.count();
       
   111         if( leftCount > 0 )
       
   112         {
       
   113             iConvertTimer->start();
       
   114         }
       
   115         break;
       
   116 
   117 
   117     default:
   118     default:
   118         break;
   119         break;
   119     }
   120     }
   120 
   121 
   121     return ret;
   122     return ret;
       
   123 }
       
   124 
       
   125 void IRFavoritesView::lazyInit()
       
   126 {
       
   127     if (!initCompleted())
       
   128     {
       
   129         normalInit();
       
   130         
       
   131         //initialization from handleCommand()
       
   132         handleCommand(EIR_ViewCommand_TOBEACTIVATED, EIR_ViewCommandReason_Show);
       
   133         handleCommand(EIR_ViewCommand_ACTIVATED, EIR_ViewCommandReason_Show);
       
   134     }
       
   135 }
       
   136 
       
   137 void IRFavoritesView::normalInit()
       
   138 {
       
   139     if (!initCompleted())
       
   140     {
       
   141         IrAbstractListViewBase::lazyInit();
       
   142         initToolBar();
       
   143         
       
   144         iModel = new IRFavoritesModel(iFavorites, this);
       
   145         iListView->setModel(iModel);
       
   146         
       
   147         iConvertTimer = new QTimer(this);
       
   148         iConvertTimer->setInterval(10);
       
   149         
       
   150         connect(iModel, SIGNAL(modelChanged()), this, SLOT(modelChanged()));
       
   151         connect(iNetworkController, SIGNAL(networkRequestNotified(IRQNetworkEvent)),
       
   152                 this, SLOT(networkRequestNotified(IRQNetworkEvent))); 
       
   153         connect(iConvertTimer, SIGNAL(timeout()), this, SLOT(convertAnother()));
       
   154         
       
   155         setInitCompleted(true);
       
   156     }
   122 }
   157 }
   123 
   158 
   124 void IRFavoritesView::handleItemSelected()
   159 void IRFavoritesView::handleItemSelected()
   125 {
   160 {
   126     int currentIndex = iListView->currentIndex().row();
   161     int currentIndex = iListView->currentIndex().row();
   146 {
   181 {
   147     iIconIndexArray.clear();
   182     iIconIndexArray.clear();
   148     iModel->clearFavoriteDB();   
   183     iModel->clearFavoriteDB();   
   149     iIsdsClient->isdsLogoDownCancelTransaction();
   184     iIsdsClient->isdsLogoDownCancelTransaction();
   150     iConvertTimer->stop();
   185     iConvertTimer->stop();
   151     updateView();
       
   152 }
   186 }
   153 
   187 
   154 void IRFavoritesView::networkRequestNotified(IRQNetworkEvent aEvent)
   188 void IRFavoritesView::networkRequestNotified(IRQNetworkEvent aEvent)
   155 {
   189 {
   156     if (getViewManager()->currentView() != this)
   190     if (getViewManager()->currentView() != this)
   176     }
   210     }
   177 }
   211 }
   178 
   212 
   179 void IRFavoritesView::prepareMenu()
   213 void IRFavoritesView::prepareMenu()
   180 {
   214 {
       
   215     if (NULL == iClearFavoriteAction)
       
   216     {
       
   217         iClearFavoriteAction = new HbAction(hbTrId("txt_irad_opt_clear_favorites"), menu());
       
   218         connect(iClearFavoriteAction, SIGNAL(triggered()), this, SLOT(clearAllFavorites()));    
       
   219     }
       
   220     
   181     HbMenu *viewMenu = menu();
   221     HbMenu *viewMenu = menu();
   182     
   222     
   183     viewMenu->removeAction(iClearFavoriteAction);
   223     viewMenu->removeAction(iClearFavoriteAction);
       
   224 
       
   225     HbAction * settingAction = qobject_cast<HbAction *>(iLoader.findObject(SETTINGS_ACTION));
       
   226     
   184     if (iModel->rowCount() > 0)
   227     if (iModel->rowCount() > 0)
   185     {
   228     {
   186         viewMenu->insertAction(iOpenWebAddressAction, iClearFavoriteAction);
   229         viewMenu->insertAction(settingAction, iClearFavoriteAction);
   187     }
   230     }
   188 }
   231 }
   189 
   232 
   190 void IRFavoritesView::startConvert(int aIndex)
   233 void IRFavoritesView::startConvert(int aIndex)
   191 {     
   234 {     
   257     }
   300     }
   258 }
   301 }
   259 
   302 
   260 void IRFavoritesView::modelChanged()
   303 void IRFavoritesView::modelChanged()
   261 {
   304 {
   262     QString headingStr = tr("Favorites") + " (" + QString::number(iModel->rowCount()) + ")";
   305     QString headingStr = QString::number(iModel->rowCount()) + QString(" ") + hbTrId("txt_irad_subtitle_stations");
   263     setHeadingText(headingStr);
   306     setHeadingText(headingStr);
   264     iIconIndexArray.clear();
   307     iIconIndexArray.clear();
   265     
   308     
   266     for (int i = 0; i < iModel->rowCount(); ++i)
   309     for (int i = 0; i < iModel->rowCount(); ++i)
   267     {
   310     {
   271         }
   314         }
   272     }
   315     }
   273     
   316     
   274     iListView->reset();
   317     iListView->reset();
   275     iListView->setCurrentIndex(iModel->index(0));
   318     iListView->setCurrentIndex(iModel->index(0));
       
   319 }
       
   320 
       
   321 void IRFavoritesView::actionClicked(HbAction *aAction)
       
   322 {
       
   323     if ( aAction )
       
   324     {
       
   325         QString objectName = aAction->objectName();
       
   326         if (objectName == KActionShareName)
       
   327         {
       
   328             shareContextAction();
       
   329         }
       
   330         else if ( objectName == KActionDeleteName)
       
   331         {
       
   332             deleteContextAction();                            
       
   333         }
       
   334         else if (objectName == KActionRenameName)
       
   335         {
       
   336             renameContextAction();
       
   337         }
       
   338         else if (objectName == KActionDetailsName)
       
   339         {
       
   340             detailsContextAction();
       
   341         }
       
   342     } 
   276 }
   343 }
   277 
   344 
   278 /*
   345 /*
   279  * Description : set the checked action in toolbar. for favoritesview, iFavoritesAction should
   346  * Description : set the checked action in toolbar. for favoritesview, iFavoritesAction should
   280  *               be checked
   347  *               be checked
   284     iFavoritesAction->setChecked(true);
   351     iFavoritesAction->setChecked(true);
   285 }
   352 }
   286 
   353 
   287 void IRFavoritesView::listViewLongPressed(HbAbstractViewItem *aItem, const QPointF& aCoords)
   354 void IRFavoritesView::listViewLongPressed(HbAbstractViewItem *aItem, const QPointF& aCoords)
   288 {
   355 {
   289     Q_UNUSED(aItem);             
   356     Q_UNUSED(aItem);         
   290     HbMenu *contextMenu = 0;
   357     Q_UNUSED(aCoords);
   291     HbAction *action = 0;
   358     
   292     
   359     HbAction *action = NULL;
   293     contextMenu = new HbMenu(); 
   360     
   294     action = contextMenu->addAction(QString(hbTrId("txt_common_menu_delete")));
   361     HbMenu *contextMenu = new HbMenu(); 
   295     action->setObjectName("delete");
   362     contextMenu->setAttribute(Qt::WA_DeleteOnClose);
   296     action = contextMenu->exec(aCoords);
   363     connect(contextMenu, SIGNAL(triggered(HbAction*)), this, SLOT(actionClicked(HbAction*)));
   297     
   364     
   298     if( action )
   365     action = contextMenu->addAction(hbTrId("txt_irad_opt_share_station"));
   299     {
   366     action->setObjectName(KActionShareName);
   300         QString objectName = action->objectName();      
   367     action = contextMenu->addAction(hbTrId("txt_common_menu_delete"));
   301         if( objectName == "delete")
   368     action->setObjectName(KActionDeleteName);
   302         {
   369     action = contextMenu->addAction(hbTrId("txt_common_menu_rename_item"));
   303             deleteContextAction();                            
   370     action->setObjectName(KActionRenameName);
   304         }
   371     action = contextMenu->addAction(hbTrId("txt_common_menu_details"));
   305     }          
   372     action->setObjectName(KActionDetailsName);
       
   373     
       
   374     contextMenu->open();         
   306 } 
   375 } 
       
   376 
       
   377 void IRFavoritesView::shareContextAction()
       
   378 {
       
   379     
       
   380 }
       
   381 
       
   382 void IRFavoritesView::renameContextAction()
       
   383 {
       
   384     
       
   385 }
       
   386 
       
   387 void IRFavoritesView::detailsContextAction()
       
   388 {
       
   389     
       
   390 }
   307 
   391 
   308 void IRFavoritesView::deleteContextAction()
   392 void IRFavoritesView::deleteContextAction()
   309 {
   393 {
   310     int current = iListView->currentIndex().row();
   394     int current = iListView->currentIndex().row();
   311     bool ret = iModel->deleteOneFavorite(current);   
   395     bool ret = iModel->deleteOneFavorite(current);   
   312 	  if( !ret )
   396 	if ( !ret )
   313 	  {
   397 	{
   314 	    popupNote(hbTrId("txt_irad_info_operation_failed"), HbMessageBox::MessageTypeWarning);
   398 	    popupNote(hbTrId("txt_irad_info_operation_failed"), HbMessageBox::MessageTypeWarning);
   315 	  }
   399 	}
   316 }
   400 }
   317  
   401 
       
   402 void IRFavoritesView::initToolBar()
       
   403 {
       
   404     //add HbActions to the toolbar, the HbActions have been created in IrAbstractListViewBase
       
   405     HbToolBar *viewToolBar = toolBar();
       
   406     viewToolBar->addAction(iGenresAction);
       
   407     viewToolBar->addAction(iCollectionsAction);
       
   408     viewToolBar->addAction(iFavoritesAction);
       
   409     viewToolBar->addAction(iSearchAction);
       
   410 }