19 #include <HbListView> |
19 #include <HbListView> |
20 #include <HbAbstractViewItem> |
20 #include <HbAbstractViewItem> |
21 #include <HbPushButton> |
21 #include <HbPushButton> |
22 #include <HbEffect> |
22 #include <HbEffect> |
23 #include <HbAction> |
23 #include <HbAction> |
24 #include <HbMessageBox> |
|
25 #include <HbInputDialog> |
24 #include <HbInputDialog> |
26 #include <HbMenu> |
25 #include <HbMenu> |
27 |
26 |
28 // User includes |
27 // User includes |
29 #include "radiostationsview.h" |
28 #include "radiostationsview.h" |
30 #include "radiologger.h" |
29 #include "radiologger.h" |
31 #include "radiomainwindow.h" |
30 #include "radiowindow.h" |
32 #include "radiouiengine.h" |
31 #include "radiouiengine.h" |
33 #include "radiobannerlabel.h" |
32 #include "radiobannerlabel.h" |
34 #include "radiofrequencyscanner.h" |
33 #include "radiofrequencyscanner.h" |
35 #include "radioxmluiloader.h" |
34 #include "radiouiloader.h" |
36 #include "radiostationmodel.h" |
35 #include "radiostationmodel.h" |
37 #include "radiostation.h" |
36 #include "radiostation.h" |
38 #include "radiostationfiltermodel.h" |
37 #include "radiostationfiltermodel.h" |
39 |
38 |
40 /*! |
39 /*! |
171 * Private slot |
170 * Private slot |
172 * |
171 * |
173 */ |
172 */ |
174 void RadioStationsView::startScanning() |
173 void RadioStationsView::startScanning() |
175 { |
174 { |
176 const int rowCount = mMainWindow->uiEngine().model().rowCount(); |
175 const int rowCount = mMainWindow->uiEngine().stationModel().rowCount(); |
177 bool scanAllowed = true; |
176 mCurrentQuestion = StartScanning; |
178 if ( rowCount > 0 ) { |
177 if ( rowCount > 0 ) { |
179 scanAllowed = HbMessageBox::question( hbTrId( "txt_rad_info_all_stations_in_stations_list_will_be" ) ); |
178 askQuestion( hbTrId( "txt_rad_info_all_stations_in_stations_list_will_be" ) ); |
180 } |
179 } else { |
181 |
180 userAccepted(); |
182 if ( scanAllowed ) { |
181 } |
183 RadioFrequencyScanner* scanner = new RadioFrequencyScanner( mMainWindow->uiEngine(), this ); |
182 } |
184 |
183 |
185 connectAndTest( scanner, SIGNAL(frequencyScannerFinished()), |
184 /*! |
186 this, SLOT(updateControlVisibilities()) ); |
185 * Private slot |
187 |
186 * |
188 scanner->startScanning( *mUiLoader ); |
187 */ |
189 } |
188 void RadioStationsView::finishScanning() |
|
189 { |
|
190 updateControlVisibilities(); |
|
191 mFrequencyScanner.take(); |
190 } |
192 } |
191 |
193 |
192 /*! |
194 /*! |
193 * Private slot |
195 * Private slot |
194 * |
196 * |
195 */ |
197 */ |
196 void RadioStationsView::updateControlVisibilities() |
198 void RadioStationsView::updateControlVisibilities() |
197 { |
199 { |
198 LOG_SLOT_CALLER; |
200 LOG_SLOT_CALLER; |
199 const bool listEmpty = mModel->rowCount() == 0; |
201 bool listEmpty = mModel->rowCount() == 0; |
200 const bool localStationsMode = !mFavoritesButton->isChecked(); |
202 const bool localStationsMode = !mFavoritesButton->isChecked(); |
201 |
203 |
202 mScanStationsAction->setVisible( mMainWindow->uiEngine().isAntennaAttached() |
204 if ( !localStationsMode ) { |
203 && localStationsMode ); |
205 listEmpty = mModel->favoriteCount() == 0; |
204 mClearListAction->setVisible( !listEmpty && localStationsMode ); |
206 } |
205 |
207 |
|
208 mClearListAction->setVisible( !listEmpty ); |
|
209 |
|
210 const bool scanAvailable = mMainWindow->uiEngine().isAntennaAttached() && localStationsMode; |
|
211 mScanStationsAction->setVisible( scanAvailable ); |
206 HbPushButton* scanButton = mUiLoader->findWidget<HbPushButton>( DOCML::SV_NAME_SCAN_BUTTON ); |
212 HbPushButton* scanButton = mUiLoader->findWidget<HbPushButton>( DOCML::SV_NAME_SCAN_BUTTON ); |
207 |
213 scanButton->setEnabled( scanAvailable ); |
208 if ( !mMainWindow->uiEngine().isAntennaAttached() ) { |
|
209 scanButton->setEnabled( false ); |
|
210 } else { |
|
211 scanButton->setEnabled( true ); |
|
212 } |
|
213 |
214 |
214 loadSection( DOCML::FILE_STATIONSVIEW, listEmpty ? DOCML::SV_SECTION_SHOW_SCAN_TEXT : DOCML::SV_SECTION_HIDE_SCAN_TEXT ); |
215 loadSection( DOCML::FILE_STATIONSVIEW, listEmpty ? DOCML::SV_SECTION_SHOW_SCAN_TEXT : DOCML::SV_SECTION_HIDE_SCAN_TEXT ); |
215 } |
216 } |
216 |
217 |
217 /*! |
218 /*! |
218 * Private slot |
219 * Private slot |
219 * |
220 * |
220 */ |
221 */ |
|
222 void RadioStationsView::clearList() |
|
223 { |
|
224 const bool favoriteMode = mFavoritesButton->isChecked(); |
|
225 mCurrentQuestion = ClearList; |
|
226 askQuestion( hbTrId( favoriteMode ? "txt_rad_info_clear_favourite_stations_list" |
|
227 : "txt_rad_info_clear_all_stations_list" ) ); |
|
228 } |
|
229 |
|
230 /*! |
|
231 * Private slot |
|
232 * |
|
233 */ |
221 void RadioStationsView::rename() |
234 void RadioStationsView::rename() |
222 { |
235 { |
223 HbInputDialog nameQuery; |
236 HbInputDialog* nameQuery = new HbInputDialog(); |
224 nameQuery.setPromptText( hbTrId( "txt_rad_dialog_new_name" ) ); |
237 nameQuery->setAttribute( Qt::WA_DeleteOnClose, true ); |
225 nameQuery.setInputMode( HbInputDialog::TextInput ); |
238 nameQuery->setDismissPolicy( HbDialog::NoDismiss ); |
226 nameQuery.setValue( mSelectedStation->name() ); |
239 nameQuery->setPromptText( hbTrId( "txt_rad_dialog_new_name" ) ); |
227 nameQuery.setObjectName( DOCML::NAME_INPUT_QUERY ); |
240 nameQuery->setInputMode( HbInputDialog::TextInput ); |
228 |
241 nameQuery->setValue( mSelectedStation->name() ); |
229 if ( nameQuery.exec() == nameQuery.primaryAction() ) { |
242 nameQuery->setObjectName( DOCML::NAME_INPUT_QUERY ); |
230 mModel->renameStation( mSelectedStation->presetIndex(), nameQuery.value().toString() ); |
243 nameQuery->open( this, SLOT(renameDone(HbAction* )) ); |
231 } |
|
232 } |
244 } |
233 |
245 |
234 /*! |
246 /*! |
235 * Private slot |
247 * Private slot |
236 * |
248 * |
237 */ |
249 */ |
238 void RadioStationsView::toggleFavorite() |
250 void RadioStationsView::toggleFavorite() |
239 { |
251 { |
240 if ( mSelectedStation->isFavorite() ) { |
252 mModel->setFavoriteByPreset( mSelectedStation->presetIndex(), !mSelectedStation->isFavorite() ); |
241 const bool answer = HbMessageBox::question( hbTrId( "txt_rad_info_remove_station_from_favorites" ) ); |
|
242 |
|
243 if ( answer ){ |
|
244 mModel->setFavoriteByPreset( mSelectedStation->presetIndex(), !mSelectedStation->isFavorite() ); |
|
245 } |
|
246 } else { |
|
247 mModel->setFavoriteByPreset( mSelectedStation->presetIndex(), !mSelectedStation->isFavorite() ); |
|
248 } |
|
249 } |
253 } |
250 |
254 |
251 /*! |
255 /*! |
252 * Private slot |
256 * Private slot |
253 * |
257 * |
254 */ |
258 */ |
255 void RadioStationsView::deleteStation() |
259 void RadioStationsView::deleteStation() |
256 { |
260 { |
257 const bool answer = HbMessageBox::question( hbTrId( "txt_rad_menu_delete_station" ) ); |
261 mCurrentQuestion = DeleteStation; |
258 |
262 askQuestion( hbTrId( "txt_rad_menu_delete_station" ) ); |
259 if ( answer ) { |
263 } |
260 mModel->removeStation( mModel->currentStation() ); |
264 |
|
265 /*! |
|
266 * Private slot |
|
267 * |
|
268 */ |
|
269 void RadioStationsView::renameDone( HbAction* action ) |
|
270 { |
|
271 HbInputDialog* dlg = static_cast<HbInputDialog*>( sender() ); |
|
272 |
|
273 if( action == dlg->primaryAction() ) { |
|
274 mModel->renameStation( mSelectedStation->presetIndex(), dlg->value().toString() ); |
261 } |
275 } |
262 } |
276 } |
263 |
277 |
264 /*! |
278 /*! |
265 * From RadioViewBase |
279 * From RadioViewBase |
266 * |
280 * |
267 */ |
281 */ |
268 void RadioStationsView::init( RadioXmlUiLoader* uiLoader, RadioMainWindow* mainWindow ) |
282 void RadioStationsView::init() |
269 { |
283 { |
270 LOG_METHOD; |
284 LOG_METHOD; |
271 mUiLoader.reset( uiLoader ); |
285 mInitialized = true; |
272 mMainWindow = mainWindow; |
286 mModel = &mMainWindow->uiEngine().stationModel(); |
273 mModel = &mMainWindow->uiEngine().model(); |
|
274 |
287 |
275 RadioUiEngine* engine = &mMainWindow->uiEngine(); |
288 RadioUiEngine* engine = &mMainWindow->uiEngine(); |
276 |
289 |
277 mFilterModel = engine->createNewFilterModel( this ); |
290 mFilterModel = engine->createNewFilterModel( this ); |
278 mFilterModel->setTypeFilter( RadioStation::LocalStation ); |
291 mFilterModel->setTypeFilter( RadioStation::LocalStation ); |
308 mScanStationsAction = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_SCAN_ACTION ); |
321 mScanStationsAction = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_SCAN_ACTION ); |
309 |
322 |
310 // "Remove all presets" menu item |
323 // "Remove all presets" menu item |
311 mClearListAction = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_CLEAR_LIST_ACTION ); |
324 mClearListAction = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_CLEAR_LIST_ACTION ); |
312 connectAndTest( mClearListAction, SIGNAL(triggered() ), |
325 connectAndTest( mClearListAction, SIGNAL(triggered() ), |
313 mModel, SLOT(removeAll() ) ); |
326 this, SLOT(clearList() ) ); |
314 |
327 |
315 connectCommonMenuItem( MenuItem::UseLoudspeaker ); |
328 connectCommonMenuItem( MenuItem::UseLoudspeaker ); |
316 |
329 |
317 initListView(); |
330 initListView(); |
318 |
331 |
319 initBackAction(); |
332 initBackAction(); |
|
333 |
|
334 updateControlVisibilities(); |
320 } |
335 } |
321 |
336 |
322 /*! |
337 /*! |
323 * \reimp |
338 * \reimp |
324 */ |
339 */ |
|
340 void RadioStationsView::userAccepted() |
|
341 { |
|
342 if ( mCurrentQuestion == StartScanning ) { |
|
343 mFrequencyScanner.reset( new RadioFrequencyScanner( mMainWindow->uiEngine(), this ) ); |
|
344 |
|
345 connectAndTest( mFrequencyScanner.data(), SIGNAL(frequencyScannerFinished()), |
|
346 this, SLOT(finishScanning()) ); |
|
347 |
|
348 mFrequencyScanner->startScanning(); |
|
349 } else if ( mCurrentQuestion == ClearList ){ |
|
350 const bool favoriteMode = mFavoritesButton->isChecked(); |
|
351 mModel->removeAll( favoriteMode ? RadioStationModel::RemoveFavorites : RadioStationModel::RemoveAll ); |
|
352 updateControlVisibilities(); |
|
353 } else if ( mCurrentQuestion == DeleteStation ) { |
|
354 mModel->removeStation( mModel->currentStation() ); |
|
355 } |
|
356 |
|
357 mCurrentQuestion = NoQuestion; |
|
358 } |
|
359 |
|
360 /*! |
|
361 * \reimp |
|
362 */ |
325 void RadioStationsView::showEvent( QShowEvent* event ) |
363 void RadioStationsView::showEvent( QShowEvent* event ) |
326 { |
364 { |
327 RadioViewBase::showEvent( event ); |
365 RadioViewBase::showEvent( event ); |
328 mModel->setDetail( RadioStationModel::ShowIcons | RadioStationModel::ShowGenre ); |
|
329 updateControlVisibilities(); |
|
330 } |
366 } |
331 |
367 |
332 /*! |
368 /*! |
333 * |
369 * |
334 */ |
370 */ |