|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <HbListView> |
|
20 #include <HbAbstractViewItem> |
|
21 #include <HbPushButton> |
|
22 #include <HbEffect> |
|
23 #include <HbAction> |
|
24 #include <HbInputDialog> |
|
25 #include <HbMenu> |
|
26 |
|
27 // User includes |
|
28 #include "radiostationsview.h" |
|
29 #include "radiologger.h" |
|
30 #include "radiowindow.h" |
|
31 #include "radiouiengine.h" |
|
32 #include "radiobannerlabel.h" |
|
33 #include "radiofrequencyscanner.h" |
|
34 #include "radiouiloader.h" |
|
35 #include "radiostationmodel.h" |
|
36 #include "radiostation.h" |
|
37 #include "radiostationfiltermodel.h" |
|
38 |
|
39 /*! |
|
40 * |
|
41 */ |
|
42 RadioStationsView::RadioStationsView() : |
|
43 RadioViewBase( false ), |
|
44 mModel( 0 ), |
|
45 mFilterModel( 0 ), |
|
46 mScanStationsAction( 0 ), |
|
47 mClearListAction( 0 ), |
|
48 mStationsList( 0 ), |
|
49 mHeadingBanner( 0 ), |
|
50 mFavoritesButton( 0 ), |
|
51 mLocalStationsButton( 0 ), |
|
52 mSelectedStation( new RadioStation ), |
|
53 mCurrentQuestion( NoQuestion ) |
|
54 { |
|
55 } |
|
56 |
|
57 /*! |
|
58 * |
|
59 */ |
|
60 RadioStationsView::~RadioStationsView() |
|
61 { |
|
62 } |
|
63 |
|
64 /*! |
|
65 * |
|
66 */ |
|
67 void RadioStationsView::setNowPlayingIcon( const HbIcon& nowPlayingIcon ) |
|
68 { |
|
69 mNowPlayingIcon = nowPlayingIcon; |
|
70 } |
|
71 |
|
72 /*! |
|
73 * |
|
74 */ |
|
75 HbIcon RadioStationsView::nowPlayingIcon() const |
|
76 { |
|
77 return mNowPlayingIcon; |
|
78 } |
|
79 |
|
80 /*! |
|
81 * |
|
82 */ |
|
83 void RadioStationsView::setFavoriteIcon( const HbIcon& favoriteIcon ) |
|
84 { |
|
85 mFavoriteIcon = favoriteIcon; |
|
86 } |
|
87 |
|
88 /*! |
|
89 * |
|
90 */ |
|
91 HbIcon RadioStationsView::favoriteIcon() const |
|
92 { |
|
93 return mFavoriteIcon; |
|
94 } |
|
95 |
|
96 /*! |
|
97 * Private slot |
|
98 * |
|
99 */ |
|
100 void RadioStationsView::listItemClicked( const QModelIndex& index ) |
|
101 { |
|
102 LOG_TIMESTAMP( "Channel change started" ); |
|
103 QModelIndex sourceIndex = mFilterModel->mapToSource( index ); |
|
104 *mSelectedStation = mModel->stationAt( sourceIndex.row() ); |
|
105 mMainWindow->uiEngine().tuneFrequency( mSelectedStation->frequency(), TuneReason::StationsList ); |
|
106 } |
|
107 |
|
108 /*! |
|
109 * Private slot |
|
110 * |
|
111 */ |
|
112 void RadioStationsView::listItemLongPressed( HbAbstractViewItem* item, const QPointF& coords ) |
|
113 { |
|
114 Q_UNUSED( item ); |
|
115 |
|
116 HbMenu* menu = mUiLoader->findObject<HbMenu>( DOCML::NAME_CONTEXT_MENU ); |
|
117 |
|
118 *mSelectedStation = mFilterModel->data( item->modelIndex(), RadioStationModel::RadioStationRole ).value<RadioStation>(); |
|
119 |
|
120 HbAction* favoriteAction = mUiLoader->findObject<HbAction>( DOCML::NAME_CONTEXT_FAVORITE ); |
|
121 if ( mSelectedStation->isFavorite() ) { |
|
122 favoriteAction->setText( hbTrId( "txt_rad_menu_remove_favourite" ) ); |
|
123 } else { |
|
124 favoriteAction->setText( hbTrId( "txt_rad_menu_add_to_favourites" ) ); |
|
125 } |
|
126 |
|
127 menu->setPreferredPos( QPointF( size().width() / 2 - menu->size().width() / 2, coords.y() - menu->size().height() / 2 ) ); |
|
128 menu->show(); |
|
129 } |
|
130 |
|
131 /*! |
|
132 * Private slot |
|
133 * |
|
134 */ |
|
135 void RadioStationsView::updateAntennaStatus( bool connected ) |
|
136 { |
|
137 Q_UNUSED( connected ); |
|
138 updateControlVisibilities(); |
|
139 } |
|
140 |
|
141 /*! |
|
142 * Private slot |
|
143 * |
|
144 */ |
|
145 void RadioStationsView::updateCurrentStation() |
|
146 { |
|
147 mFilterModel->invalidate(); |
|
148 } |
|
149 |
|
150 /*! |
|
151 * Private slot |
|
152 * |
|
153 */ |
|
154 void RadioStationsView::deckButtonPressed() |
|
155 { |
|
156 const bool showFavorites = mFavoritesButton->isChecked(); |
|
157 if ( showFavorites ) { |
|
158 loadSection( DOCML::FILE_STATIONSVIEW, DOCML::SV_SECTION_SHOW_FAVORITES ); |
|
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 } |
|
168 |
|
169 /*! |
|
170 * Private slot |
|
171 * |
|
172 */ |
|
173 void RadioStationsView::startScanning() |
|
174 { |
|
175 const int rowCount = mMainWindow->uiEngine().stationModel().rowCount(); |
|
176 mCurrentQuestion = StartScanning; |
|
177 if ( rowCount > 0 ) { |
|
178 askQuestion( hbTrId( "txt_rad_info_all_stations_in_stations_list_will_be" ) ); |
|
179 } else { |
|
180 userAccepted(); |
|
181 } |
|
182 } |
|
183 |
|
184 /*! |
|
185 * Private slot |
|
186 * |
|
187 */ |
|
188 void RadioStationsView::finishScanning() |
|
189 { |
|
190 updateControlVisibilities(); |
|
191 mFrequencyScanner.take(); |
|
192 } |
|
193 |
|
194 /*! |
|
195 * Private slot |
|
196 * |
|
197 */ |
|
198 void RadioStationsView::updateControlVisibilities() |
|
199 { |
|
200 LOG_SLOT_CALLER; |
|
201 bool listEmpty = mModel->rowCount() == 0; |
|
202 const bool localStationsMode = !mFavoritesButton->isChecked(); |
|
203 |
|
204 if ( !localStationsMode ) { |
|
205 listEmpty = mModel->favoriteCount() == 0; |
|
206 } |
|
207 |
|
208 mClearListAction->setVisible( !listEmpty ); |
|
209 |
|
210 const bool scanAvailable = mMainWindow->uiEngine().isAntennaAttached() && localStationsMode; |
|
211 mScanStationsAction->setVisible( scanAvailable ); |
|
212 HbPushButton* scanButton = mUiLoader->findWidget<HbPushButton>( DOCML::SV_NAME_SCAN_BUTTON ); |
|
213 scanButton->setEnabled( scanAvailable ); |
|
214 |
|
215 loadSection( DOCML::FILE_STATIONSVIEW, listEmpty ? DOCML::SV_SECTION_SHOW_SCAN_TEXT : DOCML::SV_SECTION_HIDE_SCAN_TEXT ); |
|
216 } |
|
217 |
|
218 /*! |
|
219 * Private slot |
|
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 */ |
|
234 void RadioStationsView::rename() |
|
235 { |
|
236 HbInputDialog* nameQuery = new HbInputDialog(); |
|
237 nameQuery->setAttribute( Qt::WA_DeleteOnClose, true ); |
|
238 nameQuery->setDismissPolicy( HbDialog::NoDismiss ); |
|
239 nameQuery->setPromptText( hbTrId( "txt_rad_dialog_new_name" ) ); |
|
240 nameQuery->setInputMode( HbInputDialog::TextInput ); |
|
241 nameQuery->setValue( mSelectedStation->name() ); |
|
242 nameQuery->setObjectName( DOCML::NAME_INPUT_QUERY ); |
|
243 nameQuery->open( this, SLOT(renameDone(HbAction* )) ); |
|
244 } |
|
245 |
|
246 /*! |
|
247 * Private slot |
|
248 * |
|
249 */ |
|
250 void RadioStationsView::toggleFavorite() |
|
251 { |
|
252 mModel->setFavoriteByPreset( mSelectedStation->presetIndex(), !mSelectedStation->isFavorite() ); |
|
253 } |
|
254 |
|
255 /*! |
|
256 * Private slot |
|
257 * |
|
258 */ |
|
259 void RadioStationsView::deleteStation() |
|
260 { |
|
261 mCurrentQuestion = DeleteStation; |
|
262 askQuestion( hbTrId( "txt_rad_menu_delete_station" ) ); |
|
263 } |
|
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() ); |
|
275 } |
|
276 } |
|
277 |
|
278 /*! |
|
279 * From RadioViewBase |
|
280 * |
|
281 */ |
|
282 void RadioStationsView::init() |
|
283 { |
|
284 LOG_METHOD; |
|
285 mInitialized = true; |
|
286 mModel = &mMainWindow->uiEngine().stationModel(); |
|
287 |
|
288 RadioUiEngine* engine = &mMainWindow->uiEngine(); |
|
289 |
|
290 mFilterModel = engine->createNewFilterModel( this ); |
|
291 mFilterModel->setTypeFilter( RadioStation::LocalStation ); |
|
292 |
|
293 loadSection( DOCML::FILE_STATIONSVIEW, DOCML::SV_SECTION_SHOW_ALL_STATIONS ); |
|
294 |
|
295 if ( !mFavoriteIcon.isNull() && !mNowPlayingIcon.isNull() ) { |
|
296 mModel->setIcons( mFavoriteIcon.qicon(), mNowPlayingIcon.qicon() ); |
|
297 } |
|
298 mModel->setDetail( RadioStationModel::ShowIcons | RadioStationModel::ShowGenre ); |
|
299 |
|
300 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 ); |
|
303 mLocalStationsButton = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_LOCALS_BUTTON ); |
|
304 |
|
305 connectAndTest( engine, SIGNAL(antennaStatusChanged(bool)), |
|
306 this, SLOT(updateAntennaStatus(bool)) ); |
|
307 connectAndTest( mModel, SIGNAL(rowsInserted(QModelIndex,int,int)), |
|
308 this, SLOT(updateControlVisibilities() ) ); |
|
309 connectAndTest( mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), |
|
310 this, SLOT(updateControlVisibilities()) ); |
|
311 connectAndTest( mModel, SIGNAL(modelReset() ), |
|
312 this, SLOT(updateControlVisibilities() ) ); |
|
313 connectAndTest( mFavoritesButton, SIGNAL(triggered() ), |
|
314 this, SLOT(deckButtonPressed() ) ); |
|
315 connectAndTest( mLocalStationsButton, SIGNAL(triggered() ), |
|
316 this, SLOT(deckButtonPressed() ) ); |
|
317 |
|
318 connectAndTest( engine, SIGNAL(tunedToFrequency(uint,int)), this, SLOT(updateCurrentStation()) ); |
|
319 |
|
320 // "Scan local stations" menu item |
|
321 mScanStationsAction = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_SCAN_ACTION ); |
|
322 |
|
323 // "Remove all presets" menu item |
|
324 mClearListAction = mUiLoader->findObject<HbAction>( DOCML::SV_NAME_CLEAR_LIST_ACTION ); |
|
325 connectAndTest( mClearListAction, SIGNAL(triggered() ), |
|
326 this, SLOT(clearList() ) ); |
|
327 |
|
328 connectCommonMenuItem( MenuItem::UseLoudspeaker ); |
|
329 |
|
330 initListView(); |
|
331 |
|
332 initBackAction(); |
|
333 |
|
334 updateControlVisibilities(); |
|
335 } |
|
336 |
|
337 /*! |
|
338 * \reimp |
|
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 */ |
|
363 void RadioStationsView::showEvent( QShowEvent* event ) |
|
364 { |
|
365 RadioViewBase::showEvent( event ); |
|
366 } |
|
367 |
|
368 /*! |
|
369 * |
|
370 */ |
|
371 void RadioStationsView::initListView() |
|
372 { |
|
373 mStationsList->setScrollingStyle( HbListView::PanOrFlick ); |
|
374 mStationsList->setModel( mFilterModel ); |
|
375 mStationsList->setSelectionMode( HbListView::NoSelection ); |
|
376 mStationsList->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); |
|
377 } |