21 #include <HbPushButton> |
21 #include <HbPushButton> |
22 #include <HbEffect> |
22 #include <HbEffect> |
23 #include <HbAction> |
23 #include <HbAction> |
24 #include <HbInputDialog> |
24 #include <HbInputDialog> |
25 #include <HbMenu> |
25 #include <HbMenu> |
|
26 #include <QSortFilterProxyModel> |
26 |
27 |
27 // User includes |
28 // User includes |
28 #include "radiostationsview.h" |
29 #include "radiostationsview.h" |
29 #include "radiologger.h" |
30 #include "radiologger.h" |
30 #include "radiowindow.h" |
31 #include "radiowindow.h" |
31 #include "radiouiengine.h" |
32 #include "radiouiengine.h" |
32 #include "radiobannerlabel.h" |
|
33 #include "radiofrequencyscanner.h" |
33 #include "radiofrequencyscanner.h" |
34 #include "radiouiloader.h" |
34 #include "radiouiloader.h" |
35 #include "radiostationmodel.h" |
35 #include "radiostationmodel.h" |
36 #include "radiostation.h" |
36 #include "radiostation.h" |
37 #include "radiostationfiltermodel.h" |
37 |
|
38 // Constants |
|
39 const char* REGEX_SHOW_FAVORITES = "true"; |
|
40 const char* REGEX_SHOW_ALL = ".+"; |
38 |
41 |
39 /*! |
42 /*! |
40 * |
43 * |
41 */ |
44 */ |
42 RadioStationsView::RadioStationsView() : |
45 RadioStationsView::RadioStationsView() : |
43 RadioViewBase( false ), |
46 RadioViewBase( false ), |
44 mModel( 0 ), |
47 mModel( 0 ), |
45 mFilterModel( 0 ), |
|
46 mScanStationsAction( 0 ), |
48 mScanStationsAction( 0 ), |
47 mClearListAction( 0 ), |
49 mClearListAction( 0 ), |
48 mStationsList( 0 ), |
50 mStationsList( 0 ), |
49 mHeadingBanner( 0 ), |
|
50 mFavoritesButton( 0 ), |
51 mFavoritesButton( 0 ), |
51 mLocalStationsButton( 0 ), |
52 mLocalStationsButton( 0 ), |
52 mSelectedStation( new RadioStation ), |
53 mSelectedStation( new RadioStation ), |
53 mCurrentQuestion( NoQuestion ) |
54 mCurrentQuestion( NoQuestion ) |
54 { |
55 { |
95 |
96 |
96 /*! |
97 /*! |
97 * Private slot |
98 * Private slot |
98 * |
99 * |
99 */ |
100 */ |
100 void RadioStationsView::listItemClicked( const QModelIndex& index ) |
101 void RadioStationsView::handleClick( const QModelIndex& index ) |
101 { |
102 { |
102 LOG_TIMESTAMP( "Channel change started" ); |
103 LOG_TIMESTAMP( "Channel change started" ); |
103 QModelIndex sourceIndex = mFilterModel->mapToSource( index ); |
104 QModelIndex sourceIndex = mFilterModel->mapToSource( index ); |
104 *mSelectedStation = mModel->stationAt( sourceIndex.row() ); |
105 *mSelectedStation = mModel->stationAt( sourceIndex.row() ); |
105 mMainWindow->uiEngine().tuneFrequency( mSelectedStation->frequency(), TuneReason::StationsList ); |
106 mUiEngine->setFrequency( mSelectedStation->frequency(), TuneReason::StationsList ); |
106 } |
107 } |
107 |
108 |
108 /*! |
109 /*! |
109 * Private slot |
110 * Private slot |
110 * |
111 * |
111 */ |
112 */ |
112 void RadioStationsView::listItemLongPressed( HbAbstractViewItem* item, const QPointF& coords ) |
113 void RadioStationsView::handleLongPress( HbAbstractViewItem* item, const QPointF& coords ) |
113 { |
114 { |
114 Q_UNUSED( item ); |
115 Q_UNUSED( item ); |
115 |
116 |
116 HbMenu* menu = mUiLoader->findObject<HbMenu>( DOCML::NAME_CONTEXT_MENU ); |
117 HbMenu* menu = mUiLoader->findObject<HbMenu>( DOCML::NAME_CONTEXT_MENU ); |
117 |
118 |
118 *mSelectedStation = mFilterModel->data( item->modelIndex(), RadioStationModel::RadioStationRole ).value<RadioStation>(); |
119 *mSelectedStation = mFilterModel->data( item->modelIndex(), RadioRole::RadioStationRole ).value<RadioStation>(); |
119 |
120 |
120 HbAction* favoriteAction = mUiLoader->findObject<HbAction>( DOCML::NAME_CONTEXT_FAVORITE ); |
121 HbAction* favoriteAction = mUiLoader->findObject<HbAction>( DOCML::NAME_CONTEXT_FAVORITE ); |
|
122 |
121 if ( mSelectedStation->isFavorite() ) { |
123 if ( mSelectedStation->isFavorite() ) { |
122 favoriteAction->setText( hbTrId( "txt_rad_menu_remove_favourite" ) ); |
124 favoriteAction->setText( hbTrId( "txt_rad_menu_remove_favourite" ) ); |
123 } else { |
125 } else { |
124 favoriteAction->setText( hbTrId( "txt_rad_menu_add_to_favourites" ) ); |
126 favoriteAction->setText( hbTrId( "txt_rad_menu_add_to_favourites" ) ); |
125 } |
127 } |
126 |
128 |
|
129 HbAction* playAction = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_PLAY_ACTION ); |
|
130 |
|
131 if ( mSelectedStation->frequency() == mUiEngine->currentFrequency() ) { |
|
132 playAction->setVisible( false ); |
|
133 } else { |
|
134 playAction->setVisible( true ); |
|
135 } |
|
136 |
127 menu->setPreferredPos( QPointF( size().width() / 2 - menu->size().width() / 2, coords.y() - menu->size().height() / 2 ) ); |
137 menu->setPreferredPos( QPointF( size().width() / 2 - menu->size().width() / 2, coords.y() - menu->size().height() / 2 ) ); |
128 menu->show(); |
138 menu->show(); |
129 } |
139 } |
130 |
140 |
131 /*! |
141 /*! |
133 * |
143 * |
134 */ |
144 */ |
135 void RadioStationsView::updateAntennaStatus( bool connected ) |
145 void RadioStationsView::updateAntennaStatus( bool connected ) |
136 { |
146 { |
137 Q_UNUSED( connected ); |
147 Q_UNUSED( connected ); |
138 updateControlVisibilities(); |
148 updateVisibilities(); |
139 } |
149 } |
140 |
150 |
141 /*! |
151 /*! |
142 * Private slot |
152 * Private slot |
143 * |
153 * |
144 */ |
154 */ |
145 void RadioStationsView::updateCurrentStation() |
155 void RadioStationsView::updateViewMode() |
146 { |
156 { |
147 mFilterModel->invalidate(); |
157 QString section = DOCML::SV_SECTION_SHOW_ALL_STATIONS; |
148 } |
158 QString filter = REGEX_SHOW_ALL; |
149 |
159 |
150 /*! |
160 if ( sender() == mFavoritesButton ) { |
151 * Private slot |
161 section = DOCML::SV_SECTION_SHOW_FAVORITES; |
152 * |
162 filter = REGEX_SHOW_FAVORITES; |
153 */ |
163 } |
154 void RadioStationsView::deckButtonPressed() |
164 |
155 { |
165 loadSection( DOCML::FILE_STATIONSVIEW, section ); |
156 const bool showFavorites = mFavoritesButton->isChecked(); |
166 mFilterModel->setFilterRegExp( filter ); |
157 if ( showFavorites ) { |
167 |
158 loadSection( DOCML::FILE_STATIONSVIEW, DOCML::SV_SECTION_SHOW_FAVORITES ); |
168 updateVisibilities(); |
159 } else { |
|
160 loadSection( DOCML::FILE_STATIONSVIEW, DOCML::SV_SECTION_SHOW_ALL_STATIONS ); |
|
161 } |
|
162 |
|
163 mFilterModel->setTypeFilter( showFavorites ? RadioStation::Favorite |
|
164 : RadioStation::LocalStation ); |
|
165 |
|
166 updateControlVisibilities(); |
|
167 } |
169 } |
168 |
170 |
169 /*! |
171 /*! |
170 * Private slot |
172 * Private slot |
171 * |
173 * |
172 */ |
174 */ |
173 void RadioStationsView::startScanning() |
175 void RadioStationsView::startScanning() |
174 { |
176 { |
175 const int rowCount = mMainWindow->uiEngine().stationModel().rowCount(); |
177 const int rowCount = mUiEngine->stationModel().rowCount(); |
176 mCurrentQuestion = StartScanning; |
178 mCurrentQuestion = StartScanning; |
177 if ( rowCount > 0 ) { |
179 if ( rowCount > 0 ) { |
178 askQuestion( hbTrId( "txt_rad_info_all_stations_in_stations_list_will_be" ) ); |
180 askQuestion( hbTrId( "txt_rad_info_all_stations_in_stations_list_will_be" ) ); |
179 } else { |
181 } else { |
180 userAccepted(); |
182 userAccepted(); |
280 * |
292 * |
281 */ |
293 */ |
282 void RadioStationsView::init() |
294 void RadioStationsView::init() |
283 { |
295 { |
284 LOG_METHOD; |
296 LOG_METHOD; |
285 mInitialized = true; |
297 mModel = &mUiEngine->stationModel(); |
286 mModel = &mMainWindow->uiEngine().stationModel(); |
298 |
287 |
299 mFilterModel = new QSortFilterProxyModel( this ); |
288 RadioUiEngine* engine = &mMainWindow->uiEngine(); |
300 mFilterModel->setDynamicSortFilter( true ); |
289 |
301 mFilterModel->setFilterRole( RadioRole::IsFavoriteRole ); |
290 mFilterModel = engine->createNewFilterModel( this ); |
302 mFilterModel->setSourceModel( &mUiEngine->stationModel() ); |
291 mFilterModel->setTypeFilter( RadioStation::LocalStation ); |
|
292 |
303 |
293 loadSection( DOCML::FILE_STATIONSVIEW, DOCML::SV_SECTION_SHOW_ALL_STATIONS ); |
304 loadSection( DOCML::FILE_STATIONSVIEW, DOCML::SV_SECTION_SHOW_ALL_STATIONS ); |
294 |
305 |
295 if ( !mFavoriteIcon.isNull() && !mNowPlayingIcon.isNull() ) { |
306 if ( !mFavoriteIcon.isNull() && !mNowPlayingIcon.isNull() ) { |
296 mModel->setIcons( mFavoriteIcon.qicon(), mNowPlayingIcon.qicon() ); |
307 mModel->setIcons( mFavoriteIcon.qicon(), mNowPlayingIcon.qicon() ); |
297 } |
308 } |
298 mModel->setDetail( RadioStationModel::ShowIcons | RadioStationModel::ShowGenre ); |
309 mModel->setDetail( RadioStationModel::ShowIcons | RadioStationModel::ShowGenre ); |
299 |
310 |
300 mStationsList = mUiLoader->findObject<HbListView>( DOCML::SV_NAME_STATIONS_LIST ); |
311 mStationsList = mUiLoader->findObject<HbListView>( DOCML::SV_NAME_STATIONS_LIST ); |
301 mHeadingBanner = mUiLoader->findWidget<RadioBannerLabel>( DOCML::SV_NAME_HEADING_BANNER ); |
|
302 mFavoritesButton = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_FAVORITES_BUTTON ); |
312 mFavoritesButton = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_FAVORITES_BUTTON ); |
303 mLocalStationsButton = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_LOCALS_BUTTON ); |
313 mLocalStationsButton = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_LOCALS_BUTTON ); |
304 |
314 |
305 connectAndTest( engine, SIGNAL(antennaStatusChanged(bool)), |
315 Radio::connect( mUiEngine.data(), SIGNAL(antennaStatusChanged(bool)), |
306 this, SLOT(updateAntennaStatus(bool)) ); |
316 this, SLOT(updateAntennaStatus(bool)) ); |
307 connectAndTest( mModel, SIGNAL(rowsInserted(QModelIndex,int,int)), |
317 Radio::connect( mModel, SIGNAL(rowsInserted(QModelIndex,int,int)), |
308 this, SLOT(updateControlVisibilities() ) ); |
318 this, SLOT(updateVisibilities()) ); |
309 connectAndTest( mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), |
319 Radio::connect( mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), |
310 this, SLOT(updateControlVisibilities()) ); |
320 this, SLOT(updateVisibilities()) ); |
311 connectAndTest( mModel, SIGNAL(modelReset() ), |
321 Radio::connect( mModel, SIGNAL(modelReset()), |
312 this, SLOT(updateControlVisibilities() ) ); |
322 this, SLOT(updateVisibilities()) ); |
313 connectAndTest( mFavoritesButton, SIGNAL(triggered() ), |
323 Radio::connect( mFavoritesButton, SIGNAL(triggered()), |
314 this, SLOT(deckButtonPressed() ) ); |
324 this, SLOT(updateViewMode()) ); |
315 connectAndTest( mLocalStationsButton, SIGNAL(triggered() ), |
325 Radio::connect( mLocalStationsButton, SIGNAL(triggered() ), |
316 this, SLOT(deckButtonPressed() ) ); |
326 this, SLOT(updateViewMode()) ); |
317 |
327 Radio::connect( mStationsList, SIGNAL(activated(QModelIndex)), |
318 connectAndTest( engine, SIGNAL(tunedToFrequency(uint,int)), this, SLOT(updateCurrentStation()) ); |
328 this, SLOT(handleClick(QModelIndex)) ); |
|
329 Radio::connect( mStationsList, SIGNAL(longPressed(HbAbstractViewItem*,QPointF)), |
|
330 this, SLOT(handleLongPress(HbAbstractViewItem*,QPointF)) ); |
|
331 |
|
332 connectCommonMenuItem( MenuItem::Exit ); |
|
333 connectXmlElement( DOCML::SV_NAME_SCAN_BUTTON, SIGNAL(clicked()), |
|
334 this, SLOT(startScanning()) ); |
|
335 |
|
336 // Context menu actions |
|
337 connectXmlElement( DOCML::SV_NAME_PLAY_ACTION, SIGNAL(triggered()), |
|
338 this, SLOT(play()) ); |
|
339 connectXmlElement( DOCML::SV_NAME_RENAME_ACTION, SIGNAL(triggered()), |
|
340 this, SLOT(rename()) ); |
|
341 connectXmlElement( DOCML::SV_NAME_FAVORITE_ACTION, SIGNAL(triggered()), |
|
342 this, SLOT(toggleFavorite()) ); |
|
343 connectXmlElement( DOCML::SV_NAME_DELETE_ACTION, SIGNAL(triggered()), |
|
344 this, SLOT(deleteStation()) ); |
319 |
345 |
320 // "Scan local stations" menu item |
346 // "Scan local stations" menu item |
321 mScanStationsAction = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_SCAN_ACTION ); |
347 mScanStationsAction = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_SCAN_ACTION ); |
322 |
348 Radio::connect( mScanStationsAction, SIGNAL(triggered() ), |
|
349 this, SLOT(startScanning() ) ); |
|
350 |
323 // "Remove all presets" menu item |
351 // "Remove all presets" menu item |
324 mClearListAction = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_CLEAR_LIST_ACTION ); |
352 mClearListAction = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_CLEAR_LIST_ACTION ); |
325 connectAndTest( mClearListAction, SIGNAL(triggered() ), |
353 Radio::connect( mClearListAction, SIGNAL(triggered() ), |
326 this, SLOT(clearList() ) ); |
354 this, SLOT(clearList() ) ); |
327 |
355 |
328 connectCommonMenuItem( MenuItem::UseLoudspeaker ); |
356 connectCommonMenuItem( MenuItem::UseLoudspeaker ); |
329 |
357 |
330 initListView(); |
358 initListView(); |
331 |
359 |
332 initBackAction(); |
360 initBackAction(); |
333 |
361 |
334 updateControlVisibilities(); |
362 updateViewMode(); |
335 } |
363 } |
336 |
364 |
337 /*! |
365 /*! |
338 * \reimp |
366 * \reimp |
339 */ |
367 */ |
340 void RadioStationsView::userAccepted() |
368 void RadioStationsView::userAccepted() |
341 { |
369 { |
342 if ( mCurrentQuestion == StartScanning ) { |
370 if ( mCurrentQuestion == StartScanning ) { |
343 mFrequencyScanner.reset( new RadioFrequencyScanner( mMainWindow->uiEngine(), this ) ); |
371 mFrequencyScanner.reset( new RadioFrequencyScanner( *mUiEngine, this ) ); |
344 |
372 |
345 connectAndTest( mFrequencyScanner.data(), SIGNAL(frequencyScannerFinished()), |
373 Radio::connect( mFrequencyScanner.data(), SIGNAL(frequencyScannerFinished()), |
346 this, SLOT(finishScanning()) ); |
374 this, SLOT(finishScanning()) ); |
347 |
375 |
348 mFrequencyScanner->startScanning(); |
376 mFrequencyScanner->startScanning(); |
349 } else if ( mCurrentQuestion == ClearList ){ |
377 } else if ( mCurrentQuestion == ClearList ){ |
350 const bool favoriteMode = mFavoritesButton->isChecked(); |
378 const bool favoriteMode = mFavoritesButton->isChecked(); |
351 mModel->removeAll( favoriteMode ? RadioStationModel::RemoveFavorites : RadioStationModel::RemoveAll ); |
379 mModel->removeAll( favoriteMode ? RadioStationModel::RemoveFavorites : RadioStationModel::RemoveAll ); |
352 updateControlVisibilities(); |
380 updateVisibilities(); |
353 } else if ( mCurrentQuestion == DeleteStation ) { |
381 } else if ( mCurrentQuestion == DeleteStation ) { |
354 mModel->removeStation( mModel->currentStation() ); |
382 mModel->removeStation( *mSelectedStation ); |
355 } |
383 } |
356 |
384 |
357 mCurrentQuestion = NoQuestion; |
385 mCurrentQuestion = NoQuestion; |
358 } |
|
359 |
|
360 /*! |
|
361 * \reimp |
|
362 */ |
|
363 void RadioStationsView::showEvent( QShowEvent* event ) |
|
364 { |
|
365 RadioViewBase::showEvent( event ); |
|
366 } |
386 } |
367 |
387 |
368 /*! |
388 /*! |
369 * |
389 * |
370 */ |
390 */ |