radioapp/radiowidgets/src/radiohistoryview.cpp
changeset 19 afea38384506
parent 16 f54ebcfc1b80
child 37 451b2e1545b2
equal deleted inserted replaced
16:f54ebcfc1b80 19:afea38384506
    22 #include <HbMenu>
    22 #include <HbMenu>
    23 #include <HbMessageBox>
    23 #include <HbMessageBox>
    24 
    24 
    25 // User includes
    25 // User includes
    26 #include "radiohistoryview.h"
    26 #include "radiohistoryview.h"
    27 #include "radiomainwindow.h"
    27 #include "radiowindow.h"
    28 #include "radiologger.h"
    28 #include "radiologger.h"
    29 #include "radioxmluiloader.h"
    29 #include "radiouiloader.h"
    30 #include "radiouiengine.h"
    30 #include "radiouiengine.h"
    31 #include "radiostationfiltermodel.h"
       
    32 #include "radiohistorymodel.h"
    31 #include "radiohistorymodel.h"
       
    32 #include "radiohistoryitem.h"
       
    33 
       
    34 // BEGIN TEMPORARY TEST CODE CODE
       
    35 #include <QTimer>
       
    36 #include "radiostationmodel.h"
       
    37 
       
    38 struct Song
       
    39 {
       
    40     const char* mArtist;
       
    41     const char* mTitle;
       
    42 };
       
    43 const Song KRecognizedSongs[] = {
       
    44     { "Red Hot Chili Peppers", "Under The Bridge" },
       
    45     { "Queens Of The Stone Age", "No One Knows" },
       
    46     { "The Presidents of the United States of America", "Dune Buggy" },
       
    47     { "System of a Down", "Aerials" },
       
    48     { "The White Stripes", "Seven Nation Army" },
       
    49     { "Alice In Chains", "When The Sun Rose Again" },
       
    50     { "Bullet For My Valentine", "Tears Don't Fall" }
       
    51 };
       
    52 const int KSongsCount = sizeof( KRecognizedSongs ) / sizeof( KRecognizedSongs[0] );
       
    53 // END TEMPORARY TEST CODE CODE
    33 
    54 
    34 /*!
    55 /*!
    35  *
    56  *
    36  */
    57  */
    37 RadioHistoryView::RadioHistoryView() :
    58 RadioHistoryView::RadioHistoryView() :
    38     RadioViewBase(),
    59     RadioViewBase( false ),
    39     mHistoryList( 0 ),
    60     mHistoryList( 0 ),
    40     mAllSongsButton( 0 ),
    61     mAllSongsButton( 0 ),
    41     mTaggedSongsButton( 0 ),
    62     mTaggedSongsButton( 0 ),
    42     mFilterModel( 0 )
    63     mSelectedItem( new RadioHistoryItem() ),
    43 {
    64     mCurrentRow( -1 ),
       
    65     mSongIndex( 0 )
       
    66 {
       
    67 }
       
    68 
       
    69 /*!
       
    70  *
       
    71  */
       
    72 RadioHistoryView::~RadioHistoryView()
       
    73 {
       
    74 }
       
    75 
       
    76 /*!
       
    77  *
       
    78  */
       
    79 void RadioHistoryView::setNonTaggedIcon( const HbIcon& nonTaggedIcon )
       
    80 {
       
    81     mNonTaggedIcon = nonTaggedIcon;
       
    82     mNonTaggedIcon.setColor( Qt::white );
       
    83 }
       
    84 
       
    85 /*!
       
    86  *
       
    87  */
       
    88 HbIcon RadioHistoryView::nonTaggedIcon() const
       
    89 {
       
    90     return mNonTaggedIcon;
       
    91 }
       
    92 
       
    93 /*!
       
    94  *
       
    95  */
       
    96 void RadioHistoryView::setTaggedIcon( const HbIcon& taggedIcon )
       
    97 {
       
    98     mTaggedIcon = taggedIcon;
       
    99 }
       
   100 
       
   101 /*!
       
   102  *
       
   103  */
       
   104 HbIcon RadioHistoryView::taggedIcon() const
       
   105 {
       
   106     return mTaggedIcon;
    44 }
   107 }
    45 
   108 
    46 /*!
   109 /*!
    47  * Private slot
   110  * Private slot
    48  *
   111  *
    53         loadSection( DOCML::FILE_HISTORYVIEW, DOCML::HV_SECTION_FAVORITE_MODE );
   116         loadSection( DOCML::FILE_HISTORYVIEW, DOCML::HV_SECTION_FAVORITE_MODE );
    54     } else {
   117     } else {
    55         loadSection( DOCML::FILE_HISTORYVIEW, DOCML::HV_SECTION_HISTORY_MODE );
   118         loadSection( DOCML::FILE_HISTORYVIEW, DOCML::HV_SECTION_HISTORY_MODE );
    56     }
   119     }
    57 
   120 
    58     const bool showFavorites = mTaggedSongsButton->isChecked();
   121     const bool showTagged = mTaggedSongsButton->isChecked();
    59 //    mFilterModel->setTypeFilter( showFavorites ? RadioStation::Favorite
   122     historyModel().setShowTagged( showTagged );
    60 //                                               : RadioStation::LocalStation );
       
    61 
   123 
    62     updateVisibilities();
   124     updateVisibilities();
    63 }
   125 }
    64 
   126 
    65 /*!
   127 /*!
    66  * Private slot
   128  * Private slot
    67  *
   129  *
    68  */
   130  */
    69 void RadioHistoryView::clearList()
   131 void RadioHistoryView::clearList()
    70 {
   132 {
    71     const bool answer = HbMessageBox::question( hbTrId( "txt_rad_info_clear_recently_played_songs_list" ) );
   133     const bool showingTagged = mTaggedSongsButton->isChecked();
    72 
   134     askQuestion( hbTrId( showingTagged ? "txt_rad_info_clear_tagged_songs_list" :
    73     if ( answer ) {
   135                                          "txt_rad_info_clear_recently_played_songs_list" ) );
    74         mMainWindow->uiEngine().historyModel().removeAll();
       
    75         updateVisibilities();
       
    76     }
       
    77 }
   136 }
    78 
   137 
    79 /*!
   138 /*!
    80  * Private slot
   139  * Private slot
    81  *
   140  *
    88 
   147 
    89 /*!
   148 /*!
    90  * Private slot
   149  * Private slot
    91  *
   150  *
    92  */
   151  */
    93 void RadioHistoryView::listItemClicked( const QModelIndex& index )
   152 void RadioHistoryView::showContextMenu( const QModelIndex& index )
    94 {
   153 {
    95     showContextMenu( index );
   154     *mSelectedItem = historyModel().itemAtIndex( index );
    96 }
   155     mCurrentRow = index.row();
    97 
   156 
    98 /*!
   157     HbMenu* menu = mUiLoader->findObject<HbMenu>( DOCML::HV_NAME_CONTEXT_MENU );
    99  * Private slot
   158 
   100  *
   159     if ( HbAction* tagAction = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_CONTEXT_TAG ) ) {
   101  */
   160         if ( mSelectedItem->isTagged() ) {
   102 void RadioHistoryView::listItemLongPressed( HbAbstractViewItem* item, const QPointF& coords )
   161             tagAction->setText( hbTrId( "txt_rad_menu_remove_tag" ) );
   103 {
   162         } else {
   104     Q_UNUSED( coords );
   163             tagAction->setText( hbTrId( "txt_rad_menu_tag_song" ) );
   105     showContextMenu( item->modelIndex() );
   164         }
       
   165     }
       
   166 
       
   167     if ( HbAction* searchAction = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_CONTEXT_SEARCH ) ) {
       
   168         //TODO: Check if "search from other store" should be available
       
   169         searchAction->setVisible( false );
       
   170     }
       
   171 
       
   172     HbAbstractViewItem* item =  mHistoryList->itemByIndex( index );
       
   173     QPointF coords = item->pos();
       
   174     coords.setY( mHistoryList->contentWidget()->pos().y() + coords.y() );
       
   175     menu->setPreferredPos( QPointF( size().width() / 2 - menu->size().width() / 2, coords.y() + menu->size().height() / 2 ) );
       
   176 
       
   177     menu->show();
       
   178 }
       
   179 
       
   180 /*!
       
   181  * Private slot
       
   182  *
       
   183  */
       
   184 void RadioHistoryView::toggleTagging()
       
   185 {
       
   186     historyModel().toggleTagging( *mSelectedItem, mCurrentRow );
       
   187     mSelectedItem->reset();
       
   188     mCurrentRow = -1;
       
   189 }
       
   190 
       
   191 /*!
       
   192  * Private slot
       
   193  *
       
   194  */
       
   195 void RadioHistoryView::openOviStore()
       
   196 {
       
   197     QString msg = "To be implemented: Open ovi store. Artist: %1, Title: %2";
       
   198     HbMessageBox::information( msg.arg( mSelectedItem->artist() ).arg( mSelectedItem->title() ) );
       
   199     mMainWindow->uiEngine().openMusicStore( *mSelectedItem );
       
   200 }
       
   201 
       
   202 /*!
       
   203  * Private slot
       
   204  *
       
   205  */
       
   206 void RadioHistoryView::openOtherStore()
       
   207 {
       
   208     QString msg = "To be implemented: Open other store. Artist: %1, Title: %2";
       
   209     HbMessageBox::information( msg.arg( mSelectedItem->artist() ).arg( mSelectedItem->title() ) );
       
   210     mMainWindow->uiEngine().openMusicStore( *mSelectedItem, RadioUiEngine::OtherStore );
       
   211 }
       
   212 
       
   213 /*!
       
   214  * Private slot
       
   215  * TEMPORARY TEST CODE
       
   216  */
       
   217 void RadioHistoryView::addSongs()
       
   218 {
       
   219     for ( int i = 0; i < KSongsCount; ++i ) {
       
   220         QTimer::singleShot( 1000 + i * 1500, this, SLOT(addOneSong()) );
       
   221     }
       
   222 }
       
   223 
       
   224 /*!
       
   225  * Private slot
       
   226  * TEMPORARY TEST CODE
       
   227  */
       
   228 void RadioHistoryView::addOneSong()
       
   229 {
       
   230     Song song = KRecognizedSongs[mSongIndex++];
       
   231     mSongIndex %= KSongsCount;
       
   232 
       
   233     RadioStation station = mMainWindow->uiEngine().stationModel().currentStation();
       
   234     mMainWindow->uiEngine().historyModel().addItem( song.mArtist, song.mTitle, station );
   106 }
   235 }
   107 
   236 
   108 /*!
   237 /*!
   109  * \reimp
   238  * \reimp
   110  *
   239  *
   111  */
   240  */
   112 void RadioHistoryView::init( RadioXmlUiLoader* uiLoader, RadioMainWindow* mainWindow )
   241 void RadioHistoryView::init()
   113 {
   242 {
   114     LOG_METHOD;
   243     LOG_METHOD;
   115     mUiLoader.reset( uiLoader );
   244     mInitialized = true;
   116     mMainWindow = mainWindow;
       
   117 
   245 
   118     RadioHistoryModel* historyModel = &mMainWindow->uiEngine().historyModel();
   246     RadioHistoryModel* historyModel = &mMainWindow->uiEngine().historyModel();
   119     historyModel->setShowDetails( mOrientation == Qt::Horizontal );
   247     historyModel->setShowDetails( mOrientation == Qt::Horizontal );
   120 
   248 
       
   249     if ( !mNonTaggedIcon.isNull() && !mTaggedIcon.isNull() ) {
       
   250         historyModel->setIcons( mNonTaggedIcon.qicon(), mTaggedIcon.qicon() );
       
   251     }
       
   252 
   121     mHistoryList = mUiLoader->findObject<HbListView>( DOCML::HV_NAME_HISTORY_LIST );
   253     mHistoryList = mUiLoader->findObject<HbListView>( DOCML::HV_NAME_HISTORY_LIST );
   122     mHistoryList->setScrollingStyle( HbListView::PanOrFlick );
   254     mHistoryList->setScrollingStyle( HbListView::PanOrFlick );
   123     mFilterModel = mMainWindow->uiEngine().createNewFilterModel( this );
   255     mHistoryList->setModel( historyModel );
   124     mFilterModel->setSourceModel( historyModel );
       
   125     mHistoryList->setModel( mFilterModel );
       
   126     mHistoryList->setSelectionMode( HbListView::NoSelection );
   256     mHistoryList->setSelectionMode( HbListView::NoSelection );
   127     mHistoryList->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
   257     mHistoryList->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
   128 
   258 
   129     mAllSongsButton     = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_ALL_SONGS_BUTTON );
   259     mAllSongsButton = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_ALL_SONGS_BUTTON );
   130     mTaggedSongsButton    = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_TAGGED_SONGS_BUTTON );
   260     mTaggedSongsButton = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_TAGGED_SONGS_BUTTON );
   131 
   261 
   132     HbAction* clearListAction = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_CLEAR_LIST_ACTION );
   262     if ( HbAction* clearListAction = mUiLoader->findObject<HbAction>( DOCML::HV_NAME_CLEAR_LIST_ACTION ) ) {
   133     connectAndTest( clearListAction, SIGNAL(triggered()), this, SLOT(clearList()) );
   263         connectAndTest( clearListAction,    SIGNAL(triggered()),
       
   264                         this,               SLOT(clearList()) );
       
   265     }
   134 
   266 
   135     connectAndTest( mTaggedSongsButton,     SIGNAL(triggered() ),
   267     connectAndTest( mTaggedSongsButton,     SIGNAL(triggered() ),
   136                     this,                   SLOT(deckButtonPressed() ) );
   268                     this,                   SLOT(deckButtonPressed() ) );
   137     connectAndTest( mAllSongsButton,        SIGNAL(triggered() ),
   269     connectAndTest( mAllSongsButton,        SIGNAL(triggered() ),
   138                     this,                   SLOT(deckButtonPressed() ) );
   270                     this,                   SLOT(deckButtonPressed() ) );
   139     connectAndTest( historyModel,           SIGNAL(itemAdded() ),
   271     connectAndTest( historyModel,           SIGNAL(itemAdded() ),
   140                     this,                   SLOT(updateVisibilities() ) );
   272                     this,                   SLOT(updateVisibilities() ) );
       
   273 
       
   274     loadSection( DOCML::FILE_HISTORYVIEW, DOCML::HV_SECTION_HISTORY_MODE );
   141     updateVisibilities();
   275     updateVisibilities();
   142     
   276     
       
   277     connectCommonMenuItem( MenuItem::UseLoudspeaker );
       
   278 
   143     initBackAction();
   279     initBackAction();
       
   280 
       
   281     // BEGIN TEMPORARY TEST CODE
       
   282     if ( HbAction* addSongsAction = mUiLoader->findObject<HbAction>( "hv:add_songs_action" ) ) {
       
   283         connectAndTest( addSongsAction,     SIGNAL(triggered()),
       
   284                         this,               SLOT(addSongs()) );
       
   285     }
       
   286     // END TEMPORARY TEST CODE
   144 }
   287 }
   145 
   288 
   146 /*!
   289 /*!
   147  * \reimp
   290  * \reimp
   148  *
   291  *
   155 
   298 
   156 /*!
   299 /*!
   157  * \reimp
   300  * \reimp
   158  *
   301  *
   159  */
   302  */
   160 void RadioHistoryView::showContextMenu( const QModelIndex& index )
   303 void RadioHistoryView::userAccepted()
   161 {
   304 {
   162     QModelIndex sourceIndex = mFilterModel->mapToSource( index );
   305     mMainWindow->uiEngine().historyModel().removeAll();
   163 
   306     updateVisibilities();
   164     HbMenu* menu = new HbMenu();
   307 }
   165     HbAction* action = menu->addAction( "Set favorite" );
   308 
   166     menu->exec();
   309 /*!
   167 
   310  *
   168 //    RadioHistoryItem item = mFilterModel->data( index, )
   311  */
   169 }
   312 RadioHistoryModel& RadioHistoryView::historyModel() const
       
   313 {
       
   314     return *static_cast<RadioHistoryModel*>( mHistoryList->model() );
       
   315 }