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 { |
133 * |
134 * |
134 */ |
135 */ |
135 void RadioStationsView::updateAntennaStatus( bool connected ) |
136 void RadioStationsView::updateAntennaStatus( bool connected ) |
136 { |
137 { |
137 Q_UNUSED( connected ); |
138 Q_UNUSED( connected ); |
138 updateControlVisibilities(); |
139 updateVisibilities(); |
139 } |
140 } |
140 |
141 |
141 /*! |
142 /*! |
142 * Private slot |
143 * Private slot |
143 * |
144 * |
144 */ |
145 */ |
145 void RadioStationsView::updateCurrentStation() |
146 void RadioStationsView::updateViewMode() |
146 { |
147 { |
147 mFilterModel->invalidate(); |
148 QString section = DOCML::SV_SECTION_SHOW_ALL_STATIONS; |
148 } |
149 QString filter = REGEX_SHOW_ALL; |
149 |
150 |
150 /*! |
151 if ( sender() == mFavoritesButton ) { |
151 * Private slot |
152 section = DOCML::SV_SECTION_SHOW_FAVORITES; |
152 * |
153 filter = REGEX_SHOW_FAVORITES; |
153 */ |
154 } |
154 void RadioStationsView::deckButtonPressed() |
155 |
155 { |
156 loadSection( DOCML::FILE_STATIONSVIEW, section ); |
156 const bool showFavorites = mFavoritesButton->isChecked(); |
157 mFilterModel->setFilterRegExp( filter ); |
157 if ( showFavorites ) { |
158 |
158 loadSection( DOCML::FILE_STATIONSVIEW, DOCML::SV_SECTION_SHOW_FAVORITES ); |
159 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 } |
160 } |
168 |
161 |
169 /*! |
162 /*! |
170 * Private slot |
163 * Private slot |
171 * |
164 * |
172 */ |
165 */ |
173 void RadioStationsView::startScanning() |
166 void RadioStationsView::startScanning() |
174 { |
167 { |
175 const int rowCount = mMainWindow->uiEngine().stationModel().rowCount(); |
168 const int rowCount = mUiEngine->stationModel().rowCount(); |
176 mCurrentQuestion = StartScanning; |
169 mCurrentQuestion = StartScanning; |
177 if ( rowCount > 0 ) { |
170 if ( rowCount > 0 ) { |
178 askQuestion( hbTrId( "txt_rad_info_all_stations_in_stations_list_will_be" ) ); |
171 askQuestion( hbTrId( "txt_rad_info_all_stations_in_stations_list_will_be" ) ); |
179 } else { |
172 } else { |
180 userAccepted(); |
173 userAccepted(); |
280 * |
273 * |
281 */ |
274 */ |
282 void RadioStationsView::init() |
275 void RadioStationsView::init() |
283 { |
276 { |
284 LOG_METHOD; |
277 LOG_METHOD; |
285 mInitialized = true; |
278 mModel = &mUiEngine->stationModel(); |
286 mModel = &mMainWindow->uiEngine().stationModel(); |
279 |
287 |
280 mFilterModel = new QSortFilterProxyModel( this ); |
288 RadioUiEngine* engine = &mMainWindow->uiEngine(); |
281 mFilterModel->setDynamicSortFilter( true ); |
289 |
282 mFilterModel->setFilterRole( RadioRole::IsFavoriteRole ); |
290 mFilterModel = engine->createNewFilterModel( this ); |
283 mFilterModel->setSourceModel( &mUiEngine->stationModel() ); |
291 mFilterModel->setTypeFilter( RadioStation::LocalStation ); |
|
292 |
284 |
293 loadSection( DOCML::FILE_STATIONSVIEW, DOCML::SV_SECTION_SHOW_ALL_STATIONS ); |
285 loadSection( DOCML::FILE_STATIONSVIEW, DOCML::SV_SECTION_SHOW_ALL_STATIONS ); |
294 |
286 |
295 if ( !mFavoriteIcon.isNull() && !mNowPlayingIcon.isNull() ) { |
287 if ( !mFavoriteIcon.isNull() && !mNowPlayingIcon.isNull() ) { |
296 mModel->setIcons( mFavoriteIcon.qicon(), mNowPlayingIcon.qicon() ); |
288 mModel->setIcons( mFavoriteIcon.qicon(), mNowPlayingIcon.qicon() ); |
297 } |
289 } |
298 mModel->setDetail( RadioStationModel::ShowIcons | RadioStationModel::ShowGenre ); |
290 mModel->setDetail( RadioStationModel::ShowIcons | RadioStationModel::ShowGenre ); |
299 |
291 |
300 mStationsList = mUiLoader->findObject<HbListView>( DOCML::SV_NAME_STATIONS_LIST ); |
292 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 ); |
293 mFavoritesButton = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_FAVORITES_BUTTON ); |
303 mLocalStationsButton = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_LOCALS_BUTTON ); |
294 mLocalStationsButton = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_LOCALS_BUTTON ); |
304 |
295 |
305 connectAndTest( engine, SIGNAL(antennaStatusChanged(bool)), |
296 Radio::connect( mUiEngine.data(), SIGNAL(antennaStatusChanged(bool)), |
306 this, SLOT(updateAntennaStatus(bool)) ); |
297 this, SLOT(updateAntennaStatus(bool)) ); |
307 connectAndTest( mModel, SIGNAL(rowsInserted(QModelIndex,int,int)), |
298 Radio::connect( mModel, SIGNAL(rowsInserted(QModelIndex,int,int)), |
308 this, SLOT(updateControlVisibilities() ) ); |
299 this, SLOT(updateVisibilities()) ); |
309 connectAndTest( mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), |
300 Radio::connect( mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), |
310 this, SLOT(updateControlVisibilities()) ); |
301 this, SLOT(updateVisibilities()) ); |
311 connectAndTest( mModel, SIGNAL(modelReset() ), |
302 Radio::connect( mModel, SIGNAL(modelReset()), |
312 this, SLOT(updateControlVisibilities() ) ); |
303 this, SLOT(updateVisibilities()) ); |
313 connectAndTest( mFavoritesButton, SIGNAL(triggered() ), |
304 Radio::connect( mFavoritesButton, SIGNAL(triggered()), |
314 this, SLOT(deckButtonPressed() ) ); |
305 this, SLOT(updateViewMode()) ); |
315 connectAndTest( mLocalStationsButton, SIGNAL(triggered() ), |
306 Radio::connect( mLocalStationsButton, SIGNAL(triggered() ), |
316 this, SLOT(deckButtonPressed() ) ); |
307 this, SLOT(updateViewMode()) ); |
317 |
308 Radio::connect( mStationsList, SIGNAL(activated(QModelIndex)), |
318 connectAndTest( engine, SIGNAL(tunedToFrequency(uint,int)), this, SLOT(updateCurrentStation()) ); |
309 this, SLOT(handleClick(QModelIndex)) ); |
|
310 Radio::connect( mStationsList, SIGNAL(longPressed(HbAbstractViewItem*,QPointF)), |
|
311 this, SLOT(handleLongPress(HbAbstractViewItem*,QPointF)) ); |
|
312 |
|
313 connectCommonMenuItem( MenuItem::Exit ); |
|
314 connectXmlElement( DOCML::SV_NAME_SCAN_BUTTON, SIGNAL(clicked()), |
|
315 this, SLOT(startScanning()) ); |
|
316 |
|
317 // Context menu actions |
|
318 connectXmlElement( DOCML::SV_NAME_RENAME_ACTION, SIGNAL(triggered()), |
|
319 this, SLOT(rename()) ); |
|
320 connectXmlElement( DOCML::SV_NAME_FAVORITE_ACTION, SIGNAL(triggered()), |
|
321 this, SLOT(toggleFavorite()) ); |
|
322 connectXmlElement( DOCML::SV_NAME_DELETE_ACTION, SIGNAL(triggered()), |
|
323 this, SLOT(deleteStation()) ); |
319 |
324 |
320 // "Scan local stations" menu item |
325 // "Scan local stations" menu item |
321 mScanStationsAction = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_SCAN_ACTION ); |
326 mScanStationsAction = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_SCAN_ACTION ); |
322 |
327 Radio::connect( mScanStationsAction, SIGNAL(triggered() ), |
|
328 this, SLOT(startScanning() ) ); |
|
329 |
323 // "Remove all presets" menu item |
330 // "Remove all presets" menu item |
324 mClearListAction = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_CLEAR_LIST_ACTION ); |
331 mClearListAction = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_CLEAR_LIST_ACTION ); |
325 connectAndTest( mClearListAction, SIGNAL(triggered() ), |
332 Radio::connect( mClearListAction, SIGNAL(triggered() ), |
326 this, SLOT(clearList() ) ); |
333 this, SLOT(clearList() ) ); |
327 |
334 |
328 connectCommonMenuItem( MenuItem::UseLoudspeaker ); |
335 connectCommonMenuItem( MenuItem::UseLoudspeaker ); |
329 |
336 |
330 initListView(); |
337 initListView(); |
331 |
338 |
332 initBackAction(); |
339 initBackAction(); |
333 |
340 |
334 updateControlVisibilities(); |
341 updateViewMode(); |
335 } |
342 } |
336 |
343 |
337 /*! |
344 /*! |
338 * \reimp |
345 * \reimp |
339 */ |
346 */ |
340 void RadioStationsView::userAccepted() |
347 void RadioStationsView::userAccepted() |
341 { |
348 { |
342 if ( mCurrentQuestion == StartScanning ) { |
349 if ( mCurrentQuestion == StartScanning ) { |
343 mFrequencyScanner.reset( new RadioFrequencyScanner( mMainWindow->uiEngine(), this ) ); |
350 mFrequencyScanner.reset( new RadioFrequencyScanner( *mUiEngine, this ) ); |
344 |
351 |
345 connectAndTest( mFrequencyScanner.data(), SIGNAL(frequencyScannerFinished()), |
352 Radio::connect( mFrequencyScanner.data(), SIGNAL(frequencyScannerFinished()), |
346 this, SLOT(finishScanning()) ); |
353 this, SLOT(finishScanning()) ); |
347 |
354 |
348 mFrequencyScanner->startScanning(); |
355 mFrequencyScanner->startScanning(); |
349 } else if ( mCurrentQuestion == ClearList ){ |
356 } else if ( mCurrentQuestion == ClearList ){ |
350 const bool favoriteMode = mFavoritesButton->isChecked(); |
357 const bool favoriteMode = mFavoritesButton->isChecked(); |
351 mModel->removeAll( favoriteMode ? RadioStationModel::RemoveFavorites : RadioStationModel::RemoveAll ); |
358 mModel->removeAll( favoriteMode ? RadioStationModel::RemoveFavorites : RadioStationModel::RemoveAll ); |
352 updateControlVisibilities(); |
359 updateVisibilities(); |
353 } else if ( mCurrentQuestion == DeleteStation ) { |
360 } else if ( mCurrentQuestion == DeleteStation ) { |
354 mModel->removeStation( mModel->currentStation() ); |
361 mModel->removeStation( mModel->currentStation() ); |
355 } |
362 } |
356 |
363 |
357 mCurrentQuestion = NoQuestion; |
364 mCurrentQuestion = NoQuestion; |
358 } |
|
359 |
|
360 /*! |
|
361 * \reimp |
|
362 */ |
|
363 void RadioStationsView::showEvent( QShowEvent* event ) |
|
364 { |
|
365 RadioViewBase::showEvent( event ); |
|
366 } |
365 } |
367 |
366 |
368 /*! |
367 /*! |
369 * |
368 * |
370 */ |
369 */ |