qtinternetradio/ui/src/irsearchchannelsview.cpp
changeset 8 3b03c28289e6
parent 5 0930554dc389
child 11 f683e24efca3
--- a/qtinternetradio/ui/src/irsearchchannelsview.cpp	Thu May 27 12:46:34 2010 +0300
+++ b/qtinternetradio/ui/src/irsearchchannelsview.cpp	Fri Jun 11 13:30:40 2010 +0300
@@ -20,7 +20,11 @@
 #include <hbsearchpanel.h>
 #include <hbaction.h>
 #include <hbprogressdialog.h>
-#include <hbscrollbar.h>
+#include <hbscrollbar.h> 
+#include <hbiconitem.h>
+#include <hbiconanimator.h>
+#include <hblabel.h> 
+#include <hbiconanimationmanager.h>
 
 #include "irsearchchannelsview.h"
 #include "iruidefines.h"
@@ -32,13 +36,13 @@
 #include "irqisdsdatastructure.h"
 #include "irplaycontroller.h"
  
-const uint KBitmapSize = 59; 
+const uint KBitmapSize = 59;
 
 IRSearchChannelsView::IRSearchChannelsView(IRApplication* aApplication,
         TIRViewId aViewId): IRBaseView(aApplication, aViewId),
-        iListView(NULL),iSearchPanelWidget(NULL),
-        iSearchState(ESearch_init),iChannelModel(NULL),iSearchingDialog(NULL),
-        iPreset(NULL),iLogoPreset(NULL),iConvertTimer(NULL)
+        iListView(NULL),iSearchPanelWidget(NULL),iSearchState(ESearch_init),
+        iChannelModel(NULL),iPreset(NULL),iLogoPreset(NULL),
+        iConvertTimer(NULL) 
 {
     //if this view is not starting view, finish all initialization in constructor
     if (getViewManager()->views().count() > 0)
@@ -85,15 +89,10 @@
     connect(iConvertTimer, SIGNAL(timeout()), this, SLOT(convertAnother()));
 }
 
+ 
+
 IRSearchChannelsView::~IRSearchChannelsView()
-{
-    if( iSearchingDialog != NULL )
-    {
-        iSearchingDialog->close();
-        delete iSearchingDialog;
-        iSearchingDialog = NULL;
-    }
-    
+{   
     if( iPreset != NULL )
     {
         delete iPreset;
@@ -105,6 +104,12 @@
         delete iLogoPreset;
         iLogoPreset = NULL;
     }
+    
+    if( NULL != iChannelModel )
+    {
+        iChannelModel->save2Cache();
+    }
+ 
 }
 
 void IRSearchChannelsView::loadLayout()
@@ -128,7 +133,8 @@
     iListView->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded);
     
     iChannelModel = new IrChannelModel(this);
-    iListView->setModel(iChannelModel);
+    iChannelModel->initWithCache();
+    iListView->setModel(iChannelModel);    
 }
 
 void IRSearchChannelsView::connectWidget()
@@ -137,6 +143,7 @@
     connect(iChannelModel, SIGNAL(dataAvailable()), this, SLOT(dataChanged()));
     connect(iNetworkController, SIGNAL(networkRequestNotified(IRQNetworkEvent)), this, SLOT(networkRequestNotified(IRQNetworkEvent)));     
     connect(iSearchPanelWidget,SIGNAL(criteriaChanged(const QString&)),this,SLOT(searchTextAlready(const QString&)));
+    connect(iSearchPanelWidget, SIGNAL(exitClicked()), this, SLOT(minimizeSearchPanel()));
 }
 
 void IRSearchChannelsView::connectIsdsClient()
@@ -170,96 +177,43 @@
 }
 
 void IRSearchChannelsView::switch2InitState()
-{
-    iLoader.load(SEARCH_CHANNELS_VIEW_LAYOUT_FILENAME,SEARCH_CHANNELS_VIEW_NO_LISTVIEW_SECTION);    
+{    
     iSearchState = ESearch_init;     
-}
+    iApplication->stopLoadingAnimation();
+} 
 
-void IRSearchChannelsView::switch2SearchedState()
-{
-    iSearchState = ESearch_Searched;     
-}
-
-void IRSearchChannelsView::switch2SearchingState()
-{    
-    iLoader.load(SEARCH_CHANNELS_VIEW_LAYOUT_FILENAME,SEARCH_CHANNELS_VIEW_LISTVIEW_SECTION);
+void IRSearchChannelsView::switch2LoadingState()
+{   
     iSearchPanelWidget->clearFocus();
     iListView->setFocus();
-    iSearchState = ESearch_Searching;     
-    startSearchingAnimation();
-}
- 
-void IRSearchChannelsView::createSearchingDialog()
-{
-    if ( NULL == iSearchingDialog)
-    {
-        //needs to add this , otherwise memory leak
-        iSearchingDialog = new HbProgressDialog(HbProgressDialog::WaitDialog);
-        iSearchingDialog->setModal(true);
-        iSearchingDialog->setTimeout(HbPopup::NoTimeout);
-        QAction *cancelAction = iSearchingDialog->actions().at(0);
-        cancelAction->setText(hbTrId("txt_common_button_cancel"));
-        connect(cancelAction, SIGNAL(triggered()), this, SLOT(cancelRequest()));
-    }
+    iSearchState = ESearch_Loading;
     
-    iSearchingDialog->setText(hbTrId("txt_common_info_searching"));
-    iSearchingDialog->show();
+    QSizeF searchPanelSize = iSearchPanelWidget->size();
+    QSizeF windowSize = getViewManager()->size();
+    QPointF pos(windowSize.width()/2,(windowSize.height() - searchPanelSize.height())/2);
+    QPointF iconPos(LOADING_ANIMATION_ICON_SIZE/2, LOADING_ANIMATION_ICON_SIZE/2);
+    pos -= iconPos;
+    iApplication->startLoadingAnimation(pos);
 }
 
-void IRSearchChannelsView::closeSearchingDialog()
-{
-    if( iSearchingDialog )
-    {
-        iSearchingDialog->close();
-        iSearchingDialog->deleteLater();
-        iSearchingDialog = NULL;
-    }
-}
-
-void IRSearchChannelsView::startSearchingAnimation()
-{
-    
-}
-
-void IRSearchChannelsView::stopSearchingAnimation()
-{
-    
-}
-
-
 void IRSearchChannelsView::handleItemSelected()
 {
     if (iListView)
     {
         int index = iListView->currentIndex().row();
-        if (index != -1)  
+        IRQChannelItem* aItem = iChannelModel->getChannelItemByIndex(index);
+        if( NULL != aItem )
         {
-            if (iIsdsClient)
-            {              
-                //once an item is selected, we show a dialog to prevent user from clicking the
-                //item again
-                iApplication->createLoadingDialog(this, SLOT(cancelRequest()));
-                
-                if (iIsdsClient->isdsIsChannelBanner())
-                {
-                    iIsdsClient->isdsListenRequest(index + 1);
-                }
-                else
-                {
-                    iIsdsClient->isdsListenRequest(index);
-                }
-            }
-        }
+            iIsdsClient->isdsListenRequest(aItem->channelID,true);
+        }        
     }
+ 
 }
 
 void IRSearchChannelsView::cancelRequest()
-{
-    iSearchState = ESearch_init;
+{     
     iIsdsClient->isdsCancelRequest();    
-    stopSearchingAnimation();    
-    //the following will remove into the stopSearchingAnimation() function
-    closeSearchingDialog();
+    switch2InitState(); 
 } 
 
 void IRSearchChannelsView::networkRequestNotified(IRQNetworkEvent aEvent)
@@ -276,8 +230,7 @@
         if(EIR_UseNetwork_StartSearch == getUseNetworkReason())
         {
             Q_ASSERT( !iKeyText.isEmpty() );
-            iIsdsClient->isdsSearchRequest(iKeyText);
-            iApplication->createLoadingDialog(this, SLOT(cancelRequest()));
+            iIsdsClient->isdsSearchRequest(iKeyText);             
         }
         else if( EIR_UseNetwork_SelectItem == getUseNetworkReason() )
         {            
@@ -287,11 +240,8 @@
         break;        
      
     default:             
-        stopSearchingAnimation();
-        //the following will remove into the stopSearchingAnimation() function
-        closeSearchingDialog();
-        setUseNetworkReason(EIR_UseNetwork_NoReason);
-        iSearchState = ESearch_init;
+        switch2InitState();         
+        setUseNetworkReason(EIR_UseNetwork_NoReason);        
         break;
     }   
 } 
@@ -306,28 +256,32 @@
         return;
     }  
     
-    setUseNetworkReason(EIR_UseNetwork_StartSearch);
-    if (false == iApplication->verifyNetworkConnectivity(hbTrId("txt_common_info_searching")))
+    setUseNetworkReason(EIR_UseNetwork_StartSearch);     
+    if (false == iApplication->verifyNetworkConnectivity())
     {        
-        switch2SearchingState();
+        switch2LoadingState();
         return;
     }
     
+    //if previouse request is in progress, cancel it
+    if( ESearch_Loading == iSearchState )
+    {
+        iIsdsClient->isdsCancelRequest();            
+        iConvertTimer->stop();
+        iIsdsClient->isdsLogoDownCancelTransaction();
+    }
+ 
+    
     setUseNetworkReason(EIR_UseNetwork_NoReason);    
-    switch2SearchingState();
-    iIsdsClient->isdsSearchRequest(iKeyText);     
-    createSearchingDialog();
+    switch2LoadingState();
+    iIsdsClient->isdsSearchRequest(iKeyText);    
 }
 
 void IRSearchChannelsView::operationException(IRQError aError)
-{    
-    iApplication->closeLoadingDialog(); 
-    closeSearchingDialog();
-    stopSearchingAnimation();     
-    iSearchState = ESearch_init;
+{        
+    switch2InitState();
     
-    QString errStr;
-    
+    QString errStr;    
     switch(aError)
     {
     case EIRQErrorNotFound:
@@ -337,6 +291,7 @@
         errStr = hbTrId("txt_irad_info_failed_to_connect");
         break;   
     }
+    
     popupNote(errStr, HbMessageBox::MessageTypeWarning);     
 }
 
@@ -345,9 +300,12 @@
     setUseNetworkReason(EIR_UseNetwork_SelectItem);
     if (false == iApplication->verifyNetworkConnectivity())
     {
+        switch2LoadingState();
         return;
     }
     setUseNetworkReason(EIR_UseNetwork_NoReason);
+    
+    switch2LoadingState();
     handleItemSelected();
 }
 
@@ -376,12 +334,7 @@
 
 void IRSearchChannelsView::dataChanged()
 {
-    iApplication->closeLoadingDialog();     
-    stopSearchingAnimation();
-    
-    //the following will remove into the stopSearchingAnimation() function
-    closeSearchingDialog();    
-    switch2SearchedState(); 
+    switch2InitState(); 
     iListView->reset();
     iListView->setCurrentIndex(iChannelModel->index(0));
     iListView->scrollTo(iChannelModel->index(0)); 
@@ -404,6 +357,8 @@
     {
         iConvertTimer->start();        
     } 
+    
+    iSearchPanelWidget->setPlaceholderText(iKeyText); 
 }
 
 void IRSearchChannelsView::startConvert(int aIndex)
@@ -480,23 +435,58 @@
     }     
 }
 
-TIRHandleResult IRSearchChannelsView::handleCommand(TIRViewCommand aCommand, TIRViewCommandReason aReason)
+void IRSearchChannelsView::minimizeSearchPanel()
+{
+    if( ESearch_Loading == iSearchState )
+    {
+        if( ! ( iPlayController->isStopped() || iPlayController->isIdle() ) )
+        {
+            //cancel buffering
+            iPlayController->cancelBuffering();
+        }
+         
+        disconnectIsdsClient();
+        iIsdsClient->isdsCancelRequest();
+        iConvertTimer->stop();
+        iIsdsClient->isdsLogoDownCancelTransaction();
+        switch2InitState();      
+    }
+    
+    int count = iChannelModel->rowCount();
+    if (0 == count)
+    {         
+        iSearchPanelWidget->clearFocus();
+        iListView->setFocus();        
+        getViewManager()->backToPreviousView();
+    }
+    else
+    {
+        iSearchPanelWidget->clearFocus();
+        iListView->setFocus();        
+    }
+}
+ 
+
+TIRHandleResult IRSearchChannelsView::handleCommand(TIRViewCommand aCommand,
+        TIRViewCommandReason aReason)
 {
     TIRHandleResult ret = IRBaseView::handleCommand(aCommand, aReason);
     
     switch (aCommand)
     {   
-    case EIR_ViewCommand_ACTIVATED:
-        //wether to start logo downloading when activated needs more discussing and testing, future.
-        iIconIndexArray.clear();
-        connectIsdsClient(); 
+    case EIR_ViewCommand_ACTIVATED:         
+        iIconIndexArray.clear();        
+        iListView->clearFocus();
+        iSearchPanelWidget->setFocus();        
+        connectIsdsClient();
         break;
         
     case EIR_ViewCommand_DEACTIVATE:     
         disconnectIsdsClient();
         iIsdsClient->isdsCancelRequest();            
         iConvertTimer->stop();
-        iIsdsClient->isdsLogoDownCancelTransaction(); 
+        iIsdsClient->isdsLogoDownCancelTransaction();
+        switch2InitState();
         break;
 
     default: