14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 // System includes |
18 // System includes |
|
19 #include <QTimer> |
|
20 #include <HbLabel> |
|
21 #include <HbPushButton> |
|
22 #include <HbMessageBox> |
19 |
23 |
20 // User includes |
24 // User includes |
21 #include "radiomainwindow.h" |
25 #include "radiomainwindow.h" |
22 #include "radiotuningview.h" |
26 #include "radiotuningview.h" |
23 #include "radiofrequencystrip.h" |
27 #include "radiofrequencystrip.h" |
24 #include "radiolocalization.h" |
|
25 #include "radiouiengine.h" |
28 #include "radiouiengine.h" |
26 #include "radiologger.h" |
29 #include "radiologger.h" |
27 #include "radiostationcarousel.h" |
30 #include "radiostationcarousel.h" |
28 #include "radiostationcontrolwidget.h" |
|
29 #include "radioxmluiloader.h" |
31 #include "radioxmluiloader.h" |
30 #include "radiostationmodel.h" |
32 #include "radiostationmodel.h" |
31 |
33 #include "radiofrequencyscanner.h" |
32 /*! |
34 |
33 * |
35 // Constants |
34 */ |
36 |
35 RadioTuningView::RadioTuningView( RadioXmlUiLoader* uiLoader ) : |
37 /*! |
36 RadioViewBase( uiLoader, false ) |
38 * |
|
39 */ |
|
40 RadioTuningView::RadioTuningView() : |
|
41 RadioViewBase( false ), |
|
42 mFrequencyScanner( 0 ), |
|
43 mCarousel( 0 ) |
37 { |
44 { |
38 } |
45 } |
39 |
46 |
40 /*! |
47 /*! |
41 * From RadioViewBase |
48 * From RadioViewBase |
42 * |
49 * |
43 */ |
50 */ |
44 void RadioTuningView::init( RadioMainWindow* aMainWindow, RadioStationModel* aModel ) |
51 void RadioTuningView::setScanningMode( bool scanning ) |
|
52 { |
|
53 HbPushButton* scanButton = mUiLoader->findWidget<HbPushButton>( DOCML::TV_NAME_SCAN_BUTTON ); |
|
54 if ( scanning ) { |
|
55 disconnect( scanButton, SIGNAL(clicked()), |
|
56 this, SLOT(startScanning()) ); |
|
57 connectAndTest( scanButton, SIGNAL(clicked()), |
|
58 mFrequencyScanner, SLOT(scanAndSavePresetsCancelled()) ); |
|
59 loadSection( DOCML::FILE_TUNINGVIEW, DOCML::TV_SECTION_SCANNING ); |
|
60 } else { |
|
61 disconnect( scanButton, SIGNAL(clicked()) ); |
|
62 connectAndTest( scanButton, SIGNAL(clicked()), |
|
63 this, SLOT(startScanning()) ); |
|
64 loadSection( DOCML::FILE_TUNINGVIEW, DOCML::TV_SECTION_NORMAL ); |
|
65 } |
|
66 } |
|
67 |
|
68 /*! |
|
69 * From RadioViewBase |
|
70 * |
|
71 */ |
|
72 void RadioTuningView::init( RadioXmlUiLoader* uiLoader, RadioMainWindow* mainWindow ) |
45 { |
73 { |
46 LOG_METHOD; |
74 LOG_METHOD; |
47 mMainWindow = aMainWindow; |
75 mUiLoader.reset( uiLoader ); |
48 mModel = aModel; |
76 mMainWindow = mainWindow; |
49 |
77 |
50 RadioStationCarousel* carousel = mUiLoader->findObject<RadioStationCarousel>( DOCML_NAME_STATIONCAROUSEL ); |
78 mCarousel = mUiLoader->findObject<RadioStationCarousel>( DOCML::TV_NAME_STATION_CAROUSEL ); |
51 |
79 mCarousel->init( &mMainWindow->uiEngine() ); |
52 RadioStationControlWidget* stationControlWidget = mUiLoader->findObject<RadioStationControlWidget>( DOCML_NAME_STATIONCONTROLWIDGET ); |
|
53 stationControlWidget->init( mMainWindow ); |
|
54 |
80 |
55 // Note! UI connections are already made in the DocML file. Here we need to connect UI to engine |
81 // Note! UI connections are already made in the DocML file. Here we need to connect UI to engine |
56 RadioUiEngine* engine = &mMainWindow->uiEngine(); |
82 RadioUiEngine* engine = &mMainWindow->uiEngine(); |
57 RadioFrequencyStrip* frequencyStrip = mUiLoader->findObject<RadioFrequencyStrip>( DOCML_NAME_FREQUENCYSTRIP ); |
83 RadioFrequencyStrip* frequencyStrip = mUiLoader->findObject<RadioFrequencyStrip>( DOCML::TV_NAME_FREQUENCY_STRIP ); |
58 RadioStationModel* stationModel = &engine->model(); |
84 RadioStationModel* stationModel = &engine->model(); |
59 |
85 |
60 connectAndTest( frequencyStrip, SIGNAL(frequencyChanged(uint,int)), |
86 connectAndTest( frequencyStrip, SIGNAL(frequencyChanged(uint,int)), |
61 engine, SLOT(tuneWithDelay(uint,int)) ); |
87 engine, SLOT(tuneWithDelay(uint,int)) ); |
62 connectAndTest( frequencyStrip, SIGNAL(frequencyChanged(uint,int)), |
88 connectAndTest( frequencyStrip, SIGNAL(frequencyChanged(uint,int)), |
63 carousel, SLOT(setFrequency(uint)) ); |
89 mCarousel, SLOT(setFrequency(uint)) ); |
64 connectAndTest( carousel, SIGNAL(frequencyChanged(uint,int)), |
90 connectAndTest( mCarousel, SIGNAL(frequencyChanged(uint,int)), |
65 frequencyStrip, SLOT(setFrequency(uint,int)) ); |
91 frequencyStrip, SLOT(setFrequency(uint,int)) ); |
66 connectAndTest( engine, SIGNAL(tunedToFrequency(uint,int)), |
92 connectAndTest( engine, SIGNAL(tunedToFrequency(uint,int)), |
67 frequencyStrip, SLOT(setFrequency(uint,int)) ); |
93 frequencyStrip, SLOT(setFrequency(uint,int)) ); |
68 connectAndTest( stationModel, SIGNAL(favoriteChanged(RadioStation)), |
94 connectAndTest( engine, SIGNAL(tunedToFrequency(uint,int)), |
69 frequencyStrip, SLOT(favoriteChanged(RadioStation)) ); |
95 this, SLOT(seekingFinished()) ); |
70 connectAndTest( stationModel, SIGNAL(stationAdded(RadioStation)), |
96 connectAndTest( stationModel, SIGNAL(favoriteChanged(RadioStation)), |
71 frequencyStrip, SLOT(stationAdded(RadioStation)) ); |
97 frequencyStrip, SLOT(favoriteChanged(RadioStation)) ); |
72 connectAndTest( stationModel, SIGNAL(stationRemoved(RadioStation)), |
98 connectAndTest( stationModel, SIGNAL(stationAdded(RadioStation)), |
73 frequencyStrip, SLOT(stationRemoved(RadioStation)) ); |
99 frequencyStrip, SLOT(stationAdded(RadioStation)) ); |
74 connectAndTest( frequencyStrip, SIGNAL(swipedLeft()), |
100 connectAndTest( stationModel, SIGNAL(stationRemoved(RadioStation)), |
75 engine, SLOT(skipNext()) ); |
101 frequencyStrip, SLOT(stationRemoved(RadioStation)) ); |
76 connectAndTest( frequencyStrip, SIGNAL(swipedRight()), |
102 connectAndTest( frequencyStrip, SIGNAL(swipedLeft()), |
77 engine, SLOT(skipPrevious()) ); |
103 engine, SLOT(skipNext()) ); |
78 connectAndTest( engine, SIGNAL(seekingStarted(int)), |
104 connectAndTest( frequencyStrip, SIGNAL(swipedRight()), |
79 carousel, SLOT(setSeekingText()) ); |
105 engine, SLOT(skipPrevious()) ); |
80 connectAndTest( engine, SIGNAL(headsetStatusChanged(bool)), |
106 connectAndTest( engine, SIGNAL(seekingStarted(int)), |
81 carousel, SLOT(updateHeadsetStatus(bool)) ); |
107 this, SLOT(seekingStarted()) ); |
|
108 connectAndTest( engine, SIGNAL(antennaStatusChanged(bool)), |
|
109 mCarousel, SLOT(updateAntennaStatus(bool)) ); |
|
110 connectAndTest( engine, SIGNAL(antennaStatusChanged(bool)), |
|
111 this, SLOT(updateAntennaStatus(bool)) ); |
|
112 connectAndTest( engine, SIGNAL(audioRouteChanged(bool)), |
|
113 this, SLOT(updateAudioRoute(bool)) ); |
|
114 |
|
115 HbPushButton* stationsButton = mUiLoader->findWidget<HbPushButton>( DOCML::TV_NAME_STATIONS_BUTTON ); |
|
116 connectAndTest( stationsButton, SIGNAL(clicked()), |
|
117 mMainWindow, SLOT(activateStationsView()) ); |
|
118 |
|
119 HbPushButton* scanButton = mUiLoader->findWidget<HbPushButton>( DOCML::TV_NAME_SCAN_BUTTON ); |
|
120 connectAndTest( scanButton, SIGNAL(clicked()), |
|
121 this, SLOT(startScanning()) ); |
|
122 |
|
123 HbPushButton* loudspeakerButton = mUiLoader->findWidget<HbPushButton>( DOCML::TV_NAME_SPEAKER_BUTTON ); |
|
124 connectAndTest( loudspeakerButton, SIGNAL(clicked()), |
|
125 engine, SLOT(toggleAudioRoute()) ); |
82 |
126 |
83 frequencyStrip->connectLeftButton( SIGNAL(clicked()), engine, SLOT(skipPrevious()) ); |
127 frequencyStrip->connectLeftButton( SIGNAL(clicked()), engine, SLOT(skipPrevious()) ); |
84 frequencyStrip->connectRightButton( SIGNAL(clicked()), engine, SLOT(skipNext()) ); |
128 frequencyStrip->connectRightButton( SIGNAL(clicked()), engine, SLOT(skipNext()) ); |
|
129 frequencyStrip->connectLeftButton( SIGNAL(clicked()), this, SLOT(buttonPressed()) ); |
|
130 frequencyStrip->connectRightButton( SIGNAL(clicked()), this, SLOT(buttonPressed()) ); |
85 |
131 |
86 frequencyStrip->connectLeftButton( SIGNAL(longPress(QPointF)), engine, SLOT(seekDown()) ); |
132 frequencyStrip->connectLeftButton( SIGNAL(longPress(QPointF)), engine, SLOT(seekDown()) ); |
87 frequencyStrip->connectRightButton( SIGNAL(longPress(QPointF)), engine, SLOT(seekUp()) ); |
133 frequencyStrip->connectRightButton( SIGNAL(longPress(QPointF)), engine, SLOT(seekUp()) ); |
88 |
134 |
89 // "Play log" menu item |
135 // "Play history" menu item |
90 connectViewChangeMenuItem( DOCML_NAME_PLAYLOGVIEWACTION, SLOT(activatePlayLogView()) ); |
136 connectViewChangeMenuItem( DOCML::TV_NAME_HISTORYVIEW_ACTION, SLOT(activateHistoryView()) ); |
91 |
137 |
92 connectCommonMenuItem( MenuItem::UseLoudspeaker ); |
138 const bool firsTimeStart = engine->isFirstTimeStart(); |
|
139 const int rowCount = engine->model().rowCount(); |
|
140 |
|
141 updateAudioRoute( mMainWindow->uiEngine().isUsingLoudspeaker() ); |
|
142 |
|
143 if ( firsTimeStart && rowCount == 0 ){ |
|
144 QTimer::singleShot( 100, this, SLOT(startScanning()) ); |
|
145 } |
93 } |
146 } |
94 |
147 |
95 /*! |
148 /*! |
96 * From RadioViewBase |
149 * From RadioViewBase |
97 * |
150 * |
98 */ |
151 */ |
99 void RadioTuningView::setOrientation() |
152 void RadioTuningView::setOrientation() |
100 { |
153 { |
101 bool ok = false; |
154 loadSection( DOCML::FILE_TUNINGVIEW, mMainWindow->orientationSection() ); |
102 QString section = mMainWindow->orientationSection(); |
|
103 mUiLoader->load( DOCML_TUNINGVIEW_FILE, section, &ok ); |
|
104 // LOG_ASSERT( ok, LOG_FORMAT( "Failed to set orientation %1 from docml %2", section, *DOCML_TUNINGVIEW_FILE ) ); |
|
105 } |
155 } |
106 |
156 |
107 /*! |
157 /*! |
108 * Private slot |
158 * Private slot |
109 */ |
159 */ |
110 void RadioTuningView::toggleFavorite() |
160 void RadioTuningView::toggleFavorite() |
111 { |
161 { |
112 bool favorite = false; |
162 bool favorite = false; |
113 uint frequency = mUiLoader->findObject<RadioFrequencyStrip>( DOCML_NAME_FREQUENCYSTRIP )->frequency( &favorite ); |
163 uint frequency = mUiLoader->findObject<RadioFrequencyStrip>( DOCML::TV_NAME_FREQUENCY_STRIP )->frequency( &favorite ); |
114 mModel->setFavoriteByFrequency( frequency, !favorite ); |
164 mMainWindow->uiEngine().model().setFavoriteByFrequency( frequency, !favorite ); |
115 } |
165 } |
|
166 |
|
167 /*! |
|
168 * Private slot |
|
169 */ |
|
170 void RadioTuningView::startScanning() |
|
171 { |
|
172 const int rowCount = mMainWindow->uiEngine().model().rowCount(); |
|
173 bool scanAllowed = true; |
|
174 if ( rowCount > 0 ) { |
|
175 scanAllowed = HbMessageBox::question( hbTrId( "txt_rad_info_all_stations_in_stations_list_will_be" ) ); |
|
176 } |
|
177 |
|
178 if ( scanAllowed ) { |
|
179 mFrequencyScanner = new RadioFrequencyScanner( mMainWindow->uiEngine(), this ); |
|
180 |
|
181 connectAndTest( mFrequencyScanner, SIGNAL(frequencyScannerFinished() ), |
|
182 this, SLOT(scanningFinished()) ); |
|
183 |
|
184 mFrequencyScanner->startScanning( *mUiLoader ); |
|
185 } |
|
186 } |
|
187 |
|
188 /*! |
|
189 * Private slot |
|
190 */ |
|
191 void RadioTuningView::scanningFinished() |
|
192 { |
|
193 disconnect( mFrequencyScanner, SIGNAL(frequencyScannerFinished() ), |
|
194 this, SLOT(scanningFinished()) ); |
|
195 |
|
196 loadSection( DOCML::FILE_TUNINGVIEW, DOCML::TV_SECTION_NORMAL ); |
|
197 mFrequencyScanner = 0; |
|
198 } |
|
199 |
|
200 /*! |
|
201 * Private slot |
|
202 */ |
|
203 void RadioTuningView::seekingStarted() |
|
204 { |
|
205 mCarousel->cleanRdsData(); |
|
206 loadSection( DOCML::FILE_TUNINGVIEW, DOCML::TV_SECTION_SEEKING ); |
|
207 HbLabel* infoText = mUiLoader->findWidget<HbLabel>( DOCML::TV_NAME_INFO_TEXT ); |
|
208 infoText->setAlignment( Qt::AlignBottom | Qt::AlignHCenter ); |
|
209 } |
|
210 |
|
211 /*! |
|
212 * Private slot |
|
213 */ |
|
214 void RadioTuningView::seekingFinished() |
|
215 { |
|
216 if ( !mFrequencyScanner && mMainWindow->uiEngine().isAntennaAttached() ) { |
|
217 loadSection( DOCML::FILE_TUNINGVIEW, DOCML::TV_SECTION_NORMAL ); |
|
218 } |
|
219 } |
|
220 |
|
221 /*! |
|
222 * Private slot |
|
223 */ |
|
224 void RadioTuningView::updateAntennaStatus( bool connected ) |
|
225 { |
|
226 if ( !connected ) { |
|
227 mCarousel->cleanRdsData(); |
|
228 loadSection( DOCML::FILE_TUNINGVIEW, DOCML::TV_SECTION_NO_ANTENNA ); |
|
229 |
|
230 HbLabel* infoText = mUiLoader->findWidget<HbLabel>( DOCML::TV_NAME_INFO_TEXT ); |
|
231 infoText->setAlignment( Qt::AlignBottom | Qt::AlignHCenter ); |
|
232 infoText->setTextWrapping( Hb::TextWordWrap ); |
|
233 } else { |
|
234 loadSection( DOCML::FILE_TUNINGVIEW, DOCML::TV_SECTION_NORMAL ); |
|
235 } |
|
236 } |
|
237 |
|
238 /*! |
|
239 * Private slot |
|
240 */ |
|
241 void RadioTuningView::updateAudioRoute( bool loudspeaker ) |
|
242 { |
|
243 HbPushButton* loudspeakerButton = mUiLoader->findWidget<HbPushButton>( DOCML::TV_NAME_SPEAKER_BUTTON ); |
|
244 if ( loudspeaker ) { |
|
245 loudspeakerButton->setIcon( HbIcon( "qtg_mono_speaker_off.svg" ) ); |
|
246 loudspeakerButton->setText( hbTrId( "txt_rad_button_deactivate_loudspeaker" ) ); |
|
247 } else { |
|
248 loudspeakerButton->setIcon( HbIcon( "qtg_mono_speaker.svg" ) ); |
|
249 loudspeakerButton->setText( hbTrId( "txt_rad_button_activate_loudspeaker" ) ); |
|
250 } |
|
251 } |
|
252 |
|
253 /*! |
|
254 * Private slot |
|
255 */ |
|
256 void RadioTuningView::buttonPressed() |
|
257 { |
|
258 if ( mMainWindow->uiEngine().model().favoriteCount() == 0 ) { |
|
259 |
|
260 mCarousel->setItemVisibility( false ); |
|
261 |
|
262 loadSection( DOCML::FILE_TUNINGVIEW, DOCML::TV_SECTION_NO_FAVORITES ); |
|
263 HbLabel* infoText = mUiLoader->findWidget<HbLabel>( DOCML::TV_NAME_INFO_TEXT ); |
|
264 infoText->setAlignment( Qt::AlignCenter ); |
|
265 infoText->setTextWrapping( Hb::TextWordWrap ); |
|
266 |
|
267 QTimer::singleShot( 6000, this, SLOT(removeInfoText()) ); |
|
268 } |
|
269 } |
|
270 |
|
271 /*! |
|
272 * Private slot |
|
273 */ |
|
274 void RadioTuningView::removeInfoText() |
|
275 { |
|
276 mCarousel->setItemVisibility( true ); |
|
277 loadSection( DOCML::FILE_TUNINGVIEW, DOCML::TV_SECTION_NORMAL ); |
|
278 } |