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> |
|
26 #include <HbMenu> |
24 |
27 |
25 // User includes |
28 // User includes |
26 #include "radiostationsview.h" |
29 #include "radiostationsview.h" |
27 #include "radiologger.h" |
30 #include "radiologger.h" |
28 #include "radiomainwindow.h" |
31 #include "radiomainwindow.h" |
29 #include "radiolocalization.h" |
|
30 #include "radiouiengine.h" |
32 #include "radiouiengine.h" |
31 #include "radiobannerlabel.h" |
33 #include "radiobannerlabel.h" |
32 #include "radiofrequencyscanner.h" |
34 #include "radiofrequencyscanner.h" |
33 #include "radiocontextmenu.h" |
|
34 #include "radioxmluiloader.h" |
35 #include "radioxmluiloader.h" |
35 #include "radiostationmodel.h" |
36 #include "radiostationmodel.h" |
|
37 #include "radiostation.h" |
36 #include "radiostationfiltermodel.h" |
38 #include "radiostationfiltermodel.h" |
37 |
39 |
38 const char* SECTION_SHOW_ALL_STATIONS = "show_all_stations"; |
40 /*! |
39 const char* SECTION_SHOW_FAVORITES = "show_favorites"; |
41 * |
40 const char* SECTION_SHOW_SCAN_TEXT = "show_scan_text"; |
42 */ |
41 const char* SECTION_HIDE_SCAN_TEXT = "hide_scan_text"; |
43 RadioStationsView::RadioStationsView() : |
42 |
44 RadioViewBase( false ), |
43 /*! |
45 mModel( 0 ), |
44 * |
46 mFilterModel( 0 ), |
45 */ |
47 mScanStationsAction( 0 ), |
46 RadioStationsView::RadioStationsView( RadioXmlUiLoader* uiLoader ) : |
48 mClearListAction( 0 ), |
47 RadioViewBase( uiLoader, false ), |
|
48 mStationsList( 0 ), |
49 mStationsList( 0 ), |
49 mHeadingBanner( 0 ), |
50 mHeadingBanner( 0 ), |
50 mFavoritesButton( 0 ), |
51 mFavoritesButton( 0 ), |
51 mLocalStationsButton( 0 ) |
52 mLocalStationsButton( 0 ), |
|
53 mSelectedStation( new RadioStation ) |
|
54 { |
|
55 } |
|
56 |
|
57 /*! |
|
58 * |
|
59 */ |
|
60 RadioStationsView::~RadioStationsView() |
52 { |
61 { |
53 } |
62 } |
54 |
63 |
55 /*! |
64 /*! |
56 * |
65 * |
90 */ |
99 */ |
91 void RadioStationsView::listItemClicked( const QModelIndex& index ) |
100 void RadioStationsView::listItemClicked( const QModelIndex& index ) |
92 { |
101 { |
93 LOG_TIMESTAMP( "Channel change started" ); |
102 LOG_TIMESTAMP( "Channel change started" ); |
94 QModelIndex sourceIndex = mFilterModel->mapToSource( index ); |
103 QModelIndex sourceIndex = mFilterModel->mapToSource( index ); |
95 RadioStation station = mModel->stationAt( sourceIndex.row() ); |
104 *mSelectedStation = mModel->stationAt( sourceIndex.row() ); |
96 RADIO_ASSERT( station.isValid(), "FMRadio", "invalid RadioStation"); |
105 RADIO_ASSERT( station.isValid(), "FMRadio", "invalid RadioStation"); |
97 mMainWindow->uiEngine().tunePreset( station.presetIndex() ); |
106 mMainWindow->uiEngine().tunePreset( mSelectedStation->presetIndex() ); |
98 } |
107 } |
99 |
108 |
100 /*! |
109 /*! |
101 * Private slot |
110 * Private slot |
102 * |
111 * |
103 */ |
112 */ |
104 void RadioStationsView::listItemLongPressed( HbAbstractViewItem* item, const QPointF& coords ) |
113 void RadioStationsView::listItemLongPressed( HbAbstractViewItem* item, const QPointF& coords ) |
105 { |
114 { |
106 QModelIndex sourceIndex = mFilterModel->mapToSource( item->modelIndex() ); |
115 Q_UNUSED( item ); |
107 RadioStation station = mModel->stationAt( sourceIndex.row() ); |
116 |
108 RADIO_ASSERT( station.isValid() , "FMRadio", "invalid RadioStation"); |
117 HbMenu* menu = mUiLoader->findObject<HbMenu>( DOCML::NAME_CONTEXT_MENU ); |
109 |
118 |
110 //TODO: Remove this. This is a temporary workaround for an Orbit bug in HbMenu |
119 *mSelectedStation = mFilterModel->data( item->modelIndex(), RadioStationModel::RadioStationRole ).value<RadioStation>(); |
111 // RadioContextMenu* menu = new RadioContextMenu( mMainWindow->uiEngine() ); |
120 |
112 // menu->init( station, QPointF( size().width() / 2, coords.y() ) ); |
121 HbAction* favoriteAction = mUiLoader->findObject<HbAction>( DOCML::NAME_CONTEXT_FAVORITE ); |
113 |
122 if ( mSelectedStation->isFavorite() ) { |
114 RadioContextMenu* menu = mUiLoader->findObject<RadioContextMenu>( DOCML_NAME_CONTEXT_MENU ); |
123 favoriteAction->setText( hbTrId( "txt_rad_menu_remove_favourite" ) ); |
115 menu->init( station, *mUiLoader ); |
124 } else { |
|
125 favoriteAction->setText( hbTrId( "txt_rad_menu_add_to_favourites" ) ); |
|
126 } |
|
127 |
116 menu->setPreferredPos( QPointF( size().width() / 2 - menu->size().width() / 2, coords.y() - menu->size().height() / 2 ) ); |
128 menu->setPreferredPos( QPointF( size().width() / 2 - menu->size().width() / 2, coords.y() - menu->size().height() / 2 ) ); |
117 menu->show(); |
129 menu->show(); |
118 } |
130 } |
119 |
131 |
120 /*! |
132 /*! |
121 * Private slot |
133 * Private slot |
122 * |
134 * |
123 */ |
135 */ |
124 void RadioStationsView::updateHeadsetStatus( bool connected ) |
136 void RadioStationsView::updateAntennaStatus( bool connected ) |
125 { |
137 { |
126 Q_UNUSED( connected ); |
138 Q_UNUSED( connected ); |
127 updateControlVisibilities(); |
139 updateControlVisibilities(); |
128 } |
140 } |
129 |
141 |
178 LOG_SLOT_CALLER; |
198 LOG_SLOT_CALLER; |
179 const bool listEmpty = mModel->rowCount() == 0; |
199 const bool listEmpty = mModel->rowCount() == 0; |
180 const bool localStationsMode = !mFavoritesButton->isChecked(); |
200 const bool localStationsMode = !mFavoritesButton->isChecked(); |
181 |
201 |
182 mScanStationsAction->setVisible( mMainWindow->uiEngine().isAntennaAttached() |
202 mScanStationsAction->setVisible( mMainWindow->uiEngine().isAntennaAttached() |
183 && localStationsMode |
203 && localStationsMode ); |
184 && !mMainWindow->uiEngine().isScanning() ); |
204 mClearListAction->setVisible( !listEmpty && localStationsMode ); |
185 mRemoveAllPresetsAction->setVisible( !listEmpty && localStationsMode ); |
205 |
186 |
206 HbPushButton* scanButton = mUiLoader->findWidget<HbPushButton>( DOCML::SV_NAME_SCAN_BUTTON ); |
187 bool ok = false; |
207 |
188 mUiLoader->load( DOCML_STATIONSVIEW_FILE, listEmpty ? SECTION_SHOW_SCAN_TEXT : SECTION_HIDE_SCAN_TEXT, &ok ); |
208 if ( !mMainWindow->uiEngine().isAntennaAttached() ) { |
|
209 scanButton->setEnabled( false ); |
|
210 } else { |
|
211 scanButton->setEnabled( true ); |
|
212 } |
|
213 |
|
214 loadSection( DOCML::FILE_STATIONSVIEW, listEmpty ? DOCML::SV_SECTION_SHOW_SCAN_TEXT : DOCML::SV_SECTION_HIDE_SCAN_TEXT ); |
|
215 } |
|
216 |
|
217 /*! |
|
218 * Private slot |
|
219 * |
|
220 */ |
|
221 void RadioStationsView::rename() |
|
222 { |
|
223 HbInputDialog nameQuery; |
|
224 nameQuery.setPromptText( hbTrId( "txt_rad_dialog_new_name" ) ); |
|
225 nameQuery.setInputMode( HbInputDialog::TextInput ); |
|
226 nameQuery.setValue( mSelectedStation->name() ); |
|
227 nameQuery.setObjectName( DOCML::NAME_INPUT_QUERY ); |
|
228 |
|
229 if ( nameQuery.exec() == nameQuery.primaryAction() ) { |
|
230 mModel->renameStation( mSelectedStation->presetIndex(), nameQuery.value().toString() ); |
|
231 } |
|
232 } |
|
233 |
|
234 /*! |
|
235 * Private slot |
|
236 * |
|
237 */ |
|
238 void RadioStationsView::toggleFavorite() |
|
239 { |
|
240 if ( 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 } |
|
250 |
|
251 /*! |
|
252 * Private slot |
|
253 * |
|
254 */ |
|
255 void RadioStationsView::deleteStation() |
|
256 { |
|
257 const bool answer = HbMessageBox::question( hbTrId( "txt_rad_menu_delete_station" ) ); |
|
258 |
|
259 if ( answer ) { |
|
260 mModel->removeStation( mModel->currentStation() ); |
|
261 } |
189 } |
262 } |
190 |
263 |
191 /*! |
264 /*! |
192 * From RadioViewBase |
265 * From RadioViewBase |
193 * |
266 * |
194 */ |
267 */ |
195 void RadioStationsView::init( RadioMainWindow* aMainWindow, RadioStationModel* aModel ) |
268 void RadioStationsView::init( RadioXmlUiLoader* uiLoader, RadioMainWindow* mainWindow ) |
196 { |
269 { |
197 LOG_METHOD; |
270 LOG_METHOD; |
198 mMainWindow = aMainWindow; |
271 mUiLoader.reset( uiLoader ); |
199 mModel = aModel; |
272 mMainWindow = mainWindow; |
|
273 mModel = &mMainWindow->uiEngine().model(); |
200 |
274 |
201 RadioUiEngine* engine = &mMainWindow->uiEngine(); |
275 RadioUiEngine* engine = &mMainWindow->uiEngine(); |
202 |
276 |
203 mFilterModel = engine->createNewFilterModel( this ); |
277 mFilterModel = engine->createNewFilterModel( this ); |
204 mFilterModel->setTypeFilter( RadioStation::LocalStation ); |
278 mFilterModel->setTypeFilter( RadioStation::LocalStation ); |
205 |
279 |
|
280 loadSection( DOCML::FILE_STATIONSVIEW, DOCML::SV_SECTION_SHOW_ALL_STATIONS ); |
|
281 |
206 if ( !mFavoriteIcon.isNull() && !mNowPlayingIcon.isNull() ) { |
282 if ( !mFavoriteIcon.isNull() && !mNowPlayingIcon.isNull() ) { |
207 mModel->setIcons( mFavoriteIcon.qicon(), mNowPlayingIcon.qicon() ); |
283 mModel->setIcons( mFavoriteIcon.qicon(), mNowPlayingIcon.qicon() ); |
208 } |
284 } |
209 mModel->setDetail( RadioStationModel::ShowIcons | RadioStationModel::ShowGenre ); |
285 mModel->setDetail( RadioStationModel::ShowIcons | RadioStationModel::ShowGenre ); |
210 |
286 |
211 mStationsList = mUiLoader->findObject<HbListView>( DOCML_NAME_STATIONSLIST ); |
287 mStationsList = mUiLoader->findObject<HbListView>( DOCML::SV_NAME_STATIONS_LIST ); |
212 mHeadingBanner = mUiLoader->findWidget<RadioBannerLabel>( DOCML_NAME_HEADINGBANNER ); |
288 mHeadingBanner = mUiLoader->findWidget<RadioBannerLabel>( DOCML::SV_NAME_HEADING_BANNER ); |
213 mFavoritesButton = mUiLoader->findObject<HbAction>( DOCML_NAME_FAVORITESBUTTON ); |
289 mFavoritesButton = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_FAVORITES_BUTTON ); |
214 mLocalStationsButton = mUiLoader->findObject<HbAction>( DOCML_NAME_LOCALSBUTTON ); |
290 mLocalStationsButton = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_LOCALS_BUTTON ); |
215 |
291 |
216 connectAndTest( engine, SIGNAL(headsetStatusChanged(bool)), |
292 connectAndTest( engine, SIGNAL(antennaStatusChanged(bool)), |
217 this, SLOT(updateHeadsetStatus(bool)) ); |
293 this, SLOT(updateAntennaStatus(bool)) ); |
218 connectAndTest( mModel, SIGNAL(rowsInserted(QModelIndex,int,int)), |
294 connectAndTest( mModel, SIGNAL(rowsInserted(QModelIndex,int,int)), |
219 this, SLOT(updateControlVisibilities() ) ); |
295 this, SLOT(updateControlVisibilities() ) ); |
220 connectAndTest( mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), |
296 connectAndTest( mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), |
221 this, SLOT(updateControlVisibilities()) ); |
297 this, SLOT(updateControlVisibilities()) ); |
222 connectAndTest( mModel, SIGNAL(modelReset() ), |
298 connectAndTest( mModel, SIGNAL(modelReset() ), |
226 connectAndTest( mLocalStationsButton, SIGNAL(triggered() ), |
302 connectAndTest( mLocalStationsButton, SIGNAL(triggered() ), |
227 this, SLOT(deckButtonPressed() ) ); |
303 this, SLOT(deckButtonPressed() ) ); |
228 |
304 |
229 connectAndTest( engine, SIGNAL(tunedToFrequency(uint,int)), this, SLOT(updateCurrentStation()) ); |
305 connectAndTest( engine, SIGNAL(tunedToFrequency(uint,int)), this, SLOT(updateCurrentStation()) ); |
230 |
306 |
231 // "Go to tuning view" menu item |
|
232 connectViewChangeMenuItem( DOCML_NAME_TUNINGVIEWACTION, SLOT(activateTuningView()) ); |
|
233 |
|
234 // "Scan local stations" menu item |
307 // "Scan local stations" menu item |
235 mScanStationsAction = mUiLoader->findObject<HbAction>( DOCML_NAME_SCANSTATIONSACTION ); |
308 mScanStationsAction = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_SCAN_ACTION ); |
236 |
309 |
237 // "Remove all presets" menu item |
310 // "Remove all presets" menu item |
238 mRemoveAllPresetsAction = mUiLoader->findObject<HbAction>( DOCML_NAME_REMOVESTATIONSACTION ); |
311 mClearListAction = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_CLEAR_LIST_ACTION ); |
|
312 connectAndTest( mClearListAction, SIGNAL(triggered() ), |
|
313 mModel, SLOT(removeAll() ) ); |
239 |
314 |
240 connectCommonMenuItem( MenuItem::UseLoudspeaker ); |
315 connectCommonMenuItem( MenuItem::UseLoudspeaker ); |
241 |
|
242 // Connect the "Remove all presets" menu item |
|
243 connectXmlElement( DOCML_NAME_REMOVESTATIONSACTION, SIGNAL(triggered()), mModel, SLOT(removeAll()) ); |
|
244 |
316 |
245 initListView(); |
317 initListView(); |
246 |
318 |
247 initBackAction(); |
319 initBackAction(); |
248 } |
320 } |