radioapp/radiowidgets/src/radiohistoryview.cpp
branchGCC_SURGE
changeset 37 451b2e1545b2
parent 19 afea38384506
parent 32 189d20c34778
equal deleted inserted replaced
26:6bcf277166c1 37:451b2e1545b2
    54 
    54 
    55 /*!
    55 /*!
    56  *
    56  *
    57  */
    57  */
    58 RadioHistoryView::RadioHistoryView() :
    58 RadioHistoryView::RadioHistoryView() :
    59     RadioViewBase( false ),
    59     RadioViewBase(),
    60     mHistoryList( 0 ),
    60     mHistoryList( 0 ),
    61     mAllSongsButton( 0 ),
    61     mAllSongsButton( 0 ),
    62     mTaggedSongsButton( 0 ),
    62     mTaggedSongsButton( 0 ),
    63     mSelectedItem( new RadioHistoryItem() ),
    63     mSelectedItem( new RadioHistoryItem() ),
    64     mCurrentRow( -1 ),
    64     mCurrentRow( -1 ),
   108 
   108 
   109 /*!
   109 /*!
   110  * Private slot
   110  * Private slot
   111  *
   111  *
   112  */
   112  */
   113 void RadioHistoryView::deckButtonPressed()
   113 void RadioHistoryView::updateViewMode()
   114 {
   114 {
       
   115     QString section = DOCML::HV_SECTION_HISTORY_MODE;
       
   116     bool showTagged = false;
       
   117 
   115     if ( sender() == mTaggedSongsButton ) {
   118     if ( sender() == mTaggedSongsButton ) {
   116         loadSection( DOCML::FILE_HISTORYVIEW, DOCML::HV_SECTION_FAVORITE_MODE );
   119         section = DOCML::HV_SECTION_FAVORITE_MODE;
   117     } else {
   120         showTagged = true;
   118         loadSection( DOCML::FILE_HISTORYVIEW, DOCML::HV_SECTION_HISTORY_MODE );
   121     }
   119     }
   122 
   120 
   123     loadSection( DOCML::FILE_HISTORYVIEW, section );
   121     const bool showTagged = mTaggedSongsButton->isChecked();
       
   122     historyModel().setShowTagged( showTagged );
   124     historyModel().setShowTagged( showTagged );
   123 
   125 
   124     updateVisibilities();
   126     updateVisibilities();
   125 }
   127 }
   126 
   128 
   139  * Private slot
   141  * Private slot
   140  *
   142  *
   141  */
   143  */
   142 void RadioHistoryView::updateVisibilities()
   144 void RadioHistoryView::updateVisibilities()
   143 {
   145 {
   144     const int itemCount = mMainWindow->uiEngine().historyModel().rowCount();
   146     const int itemCount = mUiEngine->historyModel().rowCount();
   145     loadSection( DOCML::FILE_HISTORYVIEW, itemCount ? DOCML::HV_SECTION_SHOW_LIST : DOCML::HV_SECTION_HIDE_LIST );
   147     loadSection( DOCML::FILE_HISTORYVIEW, itemCount ? DOCML::HV_SECTION_SHOW_LIST : DOCML::HV_SECTION_HIDE_LIST );
   146 }
   148 }
   147 
   149 
   148 /*!
   150 /*!
   149  * Private slot
   151  * Private slot
   163             tagAction->setText( hbTrId( "txt_rad_menu_tag_song" ) );
   165             tagAction->setText( hbTrId( "txt_rad_menu_tag_song" ) );
   164         }
   166         }
   165     }
   167     }
   166 
   168 
   167     if ( HbAction* searchAction = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_CONTEXT_SEARCH ) ) {
   169     if ( HbAction* searchAction = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_CONTEXT_SEARCH ) ) {
   168         //TODO: Check if "search from other store" should be available
   170         //TODO: Add support for other music store
   169         searchAction->setVisible( false );
   171         searchAction->setVisible( false );
   170     }
   172     }
   171 
   173 
   172     HbAbstractViewItem* item =  mHistoryList->itemByIndex( index );
   174     HbAbstractViewItem* item =  mHistoryList->itemByIndex( index );
   173     QPointF coords = item->pos();
   175     QPointF coords = item->pos();
   179 
   181 
   180 /*!
   182 /*!
   181  * Private slot
   183  * Private slot
   182  *
   184  *
   183  */
   185  */
       
   186 void RadioHistoryView::handleLongPress( HbAbstractViewItem* item )
       
   187 {
       
   188     showContextMenu( item->modelIndex() );
       
   189 }
       
   190 
       
   191 /*!
       
   192  * Private slot
       
   193  *
       
   194  */
   184 void RadioHistoryView::toggleTagging()
   195 void RadioHistoryView::toggleTagging()
   185 {
   196 {
   186     historyModel().toggleTagging( *mSelectedItem, mCurrentRow );
   197     historyModel().toggleTagging( *mSelectedItem, mCurrentRow );
   187     mSelectedItem->reset();
   198     mSelectedItem->reset();
   188     mCurrentRow = -1;
   199     mCurrentRow = -1;
       
   200     updateVisibilities();
   189 }
   201 }
   190 
   202 
   191 /*!
   203 /*!
   192  * Private slot
   204  * Private slot
   193  *
   205  *
   194  */
   206  */
   195 void RadioHistoryView::openOviStore()
   207 void RadioHistoryView::openOviStore()
   196 {
   208 {
   197     QString msg = "To be implemented: Open ovi store. Artist: %1, Title: %2";
   209     QString msg = "To be implemented: Open ovi store. Artist: %1, Title: %2";
   198     HbMessageBox::information( msg.arg( mSelectedItem->artist() ).arg( mSelectedItem->title() ) );
   210     HbMessageBox::information( msg.arg( mSelectedItem->artist() ).arg( mSelectedItem->title() ) );
   199     mMainWindow->uiEngine().openMusicStore( *mSelectedItem );
   211     mUiEngine->openMusicStore( *mSelectedItem );
   200 }
   212 }
   201 
   213 
   202 /*!
   214 /*!
   203  * Private slot
   215  * Private slot
   204  *
   216  *
   205  */
   217  */
   206 void RadioHistoryView::openOtherStore()
   218 void RadioHistoryView::openOtherStore()
   207 {
   219 {
   208     QString msg = "To be implemented: Open other store. Artist: %1, Title: %2";
   220     mUiEngine->openMusicStore( *mSelectedItem, RadioUiEngine::OtherStore );
   209     HbMessageBox::information( msg.arg( mSelectedItem->artist() ).arg( mSelectedItem->title() ) );
       
   210     mMainWindow->uiEngine().openMusicStore( *mSelectedItem, RadioUiEngine::OtherStore );
       
   211 }
   221 }
   212 
   222 
   213 /*!
   223 /*!
   214  * Private slot
   224  * Private slot
   215  * TEMPORARY TEST CODE
   225  * TEMPORARY TEST CODE
   228 void RadioHistoryView::addOneSong()
   238 void RadioHistoryView::addOneSong()
   229 {
   239 {
   230     Song song = KRecognizedSongs[mSongIndex++];
   240     Song song = KRecognizedSongs[mSongIndex++];
   231     mSongIndex %= KSongsCount;
   241     mSongIndex %= KSongsCount;
   232 
   242 
   233     RadioStation station = mMainWindow->uiEngine().stationModel().currentStation();
   243     RadioStation station = mUiEngine->stationModel().currentStation();
   234     mMainWindow->uiEngine().historyModel().addItem( song.mArtist, song.mTitle, station );
   244     mUiEngine->historyModel().addItem( song.mArtist, song.mTitle, station );
   235 }
   245 }
   236 
   246 
   237 /*!
   247 /*!
   238  * \reimp
   248  * \reimp
   239  *
   249  *
   240  */
   250  */
   241 void RadioHistoryView::init()
   251 void RadioHistoryView::init()
   242 {
   252 {
   243     LOG_METHOD;
   253     LOG_METHOD;
   244     mInitialized = true;
   254     loadSection( DOCML::FILE_HISTORYVIEW, DOCML::SECTION_LAZY_LOAD );
   245 
   255 
   246     RadioHistoryModel* historyModel = &mMainWindow->uiEngine().historyModel();
   256     RadioHistoryModel* historyModel = &mUiEngine->historyModel();
   247     historyModel->setShowDetails( mOrientation == Qt::Horizontal );
   257     historyModel->setShowDetails( mOrientation == Qt::Horizontal );
   248 
   258 
   249     if ( !mNonTaggedIcon.isNull() && !mTaggedIcon.isNull() ) {
   259     if ( !mNonTaggedIcon.isNull() && !mTaggedIcon.isNull() ) {
   250         historyModel->setIcons( mNonTaggedIcon.qicon(), mTaggedIcon.qicon() );
   260         historyModel->setIcons( mNonTaggedIcon.qicon(), mTaggedIcon.qicon() );
   251     }
   261     }
   258 
   268 
   259     mAllSongsButton = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_ALL_SONGS_BUTTON );
   269     mAllSongsButton = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_ALL_SONGS_BUTTON );
   260     mTaggedSongsButton = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_TAGGED_SONGS_BUTTON );
   270     mTaggedSongsButton = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_TAGGED_SONGS_BUTTON );
   261 
   271 
   262     if ( HbAction* clearListAction = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_CLEAR_LIST_ACTION ) ) {
   272     if ( HbAction* clearListAction = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_CLEAR_LIST_ACTION ) ) {
   263         connectAndTest( clearListAction,    SIGNAL(triggered()),
   273         Radio::connect( clearListAction,    SIGNAL(triggered()),
   264                         this,               SLOT(clearList()) );
   274                         this,               SLOT(clearList()) );
   265     }
   275     }
   266 
   276 
   267     connectAndTest( mTaggedSongsButton,     SIGNAL(triggered() ),
   277     Radio::connect( mTaggedSongsButton,     SIGNAL(triggered()),
   268                     this,                   SLOT(deckButtonPressed() ) );
   278                     this,                   SLOT(updateViewMode()) );
   269     connectAndTest( mAllSongsButton,        SIGNAL(triggered() ),
   279     Radio::connect( mAllSongsButton,        SIGNAL(triggered()),
   270                     this,                   SLOT(deckButtonPressed() ) );
   280                     this,                   SLOT(updateViewMode()) );
   271     connectAndTest( historyModel,           SIGNAL(itemAdded() ),
   281     Radio::connect( historyModel,           SIGNAL(itemAdded()),
   272                     this,                   SLOT(updateVisibilities() ) );
   282                     this,                   SLOT(updateVisibilities()) );
   273 
   283     Radio::connect( mHistoryList,           SIGNAL(activated(QModelIndex)),
   274     loadSection( DOCML::FILE_HISTORYVIEW, DOCML::HV_SECTION_HISTORY_MODE );
   284                     this,                   SLOT(showContextMenu(QModelIndex)) );
   275     updateVisibilities();
   285     Radio::connect( mHistoryList,           SIGNAL(longPressed(HbAbstractViewItem*,QPointF)),
   276     
   286                     this,                   SLOT(handleLongPress(HbAbstractViewItem*)) );
       
   287 
       
   288     connectCommonMenuItem( MenuItem::Exit );
   277     connectCommonMenuItem( MenuItem::UseLoudspeaker );
   289     connectCommonMenuItem( MenuItem::UseLoudspeaker );
   278 
   290 
       
   291     // Context menu actions
       
   292     connectXmlElement( DOCML::HV_NAME_TOGGLE_TAG_ACTION,    SIGNAL(triggered()),
       
   293                        this,                                SLOT(toggleTagging()) );
       
   294     connectXmlElement( DOCML::HV_NAME_OVI_STORE_ACTION,     SIGNAL(triggered()),
       
   295                        this,                                SLOT(openOviStore()) );
       
   296     connectXmlElement( DOCML::HV_NAME_OTHER_STORE_ACTION,   SIGNAL(triggered()),
       
   297                        this,                                SLOT(openOtherStore()) );
   279     initBackAction();
   298     initBackAction();
       
   299 
       
   300     updateViewMode();
   280 
   301 
   281     // BEGIN TEMPORARY TEST CODE
   302     // BEGIN TEMPORARY TEST CODE
   282     if ( HbAction* addSongsAction = mUiLoader->findObject<HbAction>( "hv:add_songs_action" ) ) {
   303     if ( HbAction* addSongsAction = mUiLoader->findObject<HbAction>( "hv:add_songs_action" ) ) {
   283         connectAndTest( addSongsAction,     SIGNAL(triggered()),
   304         Radio::connect( addSongsAction,     SIGNAL(triggered()),
   284                         this,               SLOT(addSongs()) );
   305                         this,               SLOT(addSongs()) );
   285     }
   306     }
   286     // END TEMPORARY TEST CODE
   307     // END TEMPORARY TEST CODE
   287 }
   308 }
   288 
   309 
   290  * \reimp
   311  * \reimp
   291  *
   312  *
   292  */
   313  */
   293 void RadioHistoryView::setOrientation()
   314 void RadioHistoryView::setOrientation()
   294 {
   315 {
   295     RadioHistoryModel& model = mMainWindow->uiEngine().historyModel();
   316     if ( mUiEngine ) {
   296     model.setShowDetails( mOrientation == Qt::Horizontal );
   317         RadioHistoryModel& model = mUiEngine->historyModel();
       
   318         model.setShowDetails( mOrientation == Qt::Horizontal );
       
   319     }
   297 }
   320 }
   298 
   321 
   299 /*!
   322 /*!
   300  * \reimp
   323  * \reimp
   301  *
   324  *
   302  */
   325  */
   303 void RadioHistoryView::userAccepted()
   326 void RadioHistoryView::userAccepted()
   304 {
   327 {
   305     mMainWindow->uiEngine().historyModel().removeAll();
   328     const bool removeTagged = mTaggedSongsButton->isChecked();
       
   329     mUiEngine->historyModel().removeAll( removeTagged );
   306     updateVisibilities();
   330     updateVisibilities();
   307 }
   331 }
   308 
   332 
   309 /*!
   333 /*!
   310  *
   334  *