23 |
23 |
24 // User includes |
24 // User includes |
25 #include "radiowindow.h" |
25 #include "radiowindow.h" |
26 #include "radiomainview.h" |
26 #include "radiomainview.h" |
27 #include "radiostationsview.h" |
27 #include "radiostationsview.h" |
|
28 #include "radiohistoryview.h" |
28 #include "radiouiengine.h" |
29 #include "radiouiengine.h" |
29 #include "radiostationmodel.h" |
30 #include "radiostationmodel.h" |
30 #include "radiologger.h" |
31 #include "radiologger.h" |
31 #include "radiouiloader.h" |
32 #include "radiouiloader.h" |
32 |
33 |
33 // Constants |
34 // Constants |
34 |
35 |
35 /** |
36 /** |
36 * Desired amount of delay of volumesliderpopup |
37 * Timeout for volumesliderpopup |
37 */ |
38 */ |
38 const int KVolumeSliderDelay = 5000; |
39 const int VOLUME_POPUP_TIMEOUT = 5000; |
39 |
40 |
40 /*! |
41 /*! |
41 * |
42 * |
42 */ |
43 */ |
43 RadioWindow::RadioWindow( QWidget* parent ) : |
44 RadioWindow::RadioWindow( QWidget* parent ) : |
44 HbMainWindow( parent ), |
45 HbMainWindow( parent ) |
45 mUiEngine( new RadioUiEngine( this ) ) |
|
46 { |
46 { |
47 } |
47 } |
48 |
48 |
49 /*! |
49 /*! |
50 * |
50 * |
60 void RadioWindow::showErrorMessage( const QString& text ) |
60 void RadioWindow::showErrorMessage( const QString& text ) |
61 { |
61 { |
62 HbDeviceMessageBox box( text, HbMessageBox::MessageTypeWarning ); |
62 HbDeviceMessageBox box( text, HbMessageBox::MessageTypeWarning ); |
63 box.setTimeout( HbPopup::NoTimeout ); |
63 box.setTimeout( HbPopup::NoTimeout ); |
64 box.setDismissPolicy( HbPopup::NoDismiss ); |
64 box.setDismissPolicy( HbPopup::NoDismiss ); |
65 box.exec(); |
65 box.show(); |
66 } |
66 } |
67 |
67 |
68 /*! |
68 /*! |
69 * |
69 * |
70 */ |
70 */ |
71 void RadioWindow::init() |
71 void RadioWindow::init( QSystemDeviceInfo* deviceInfo ) |
72 { |
72 { |
73 connectAndTest( this, SIGNAL(viewReady()), |
73 mDeviceInfo.reset( deviceInfo ); |
74 this, SLOT(initView()) ); |
74 |
|
75 Radio::connect( this, SIGNAL(viewReady()), |
|
76 this, SLOT(initView()) ); |
|
77 Radio::connect( mDeviceInfo.data(), SIGNAL(currentProfileChanged(QSystemDeviceInfo::Profile)), |
|
78 this, SLOT(queryOfflineUsage(QSystemDeviceInfo::Profile)) ); |
75 |
79 |
76 activateMainView(); |
80 activateMainView(); |
77 } |
81 } |
78 |
82 |
79 /*! |
83 /*! |
80 * |
|
81 */ |
|
82 RadioUiEngine& RadioWindow::uiEngine() |
|
83 { |
|
84 return *mUiEngine; |
|
85 } |
|
86 |
|
87 /*! |
|
88 * Returns the XML layout section that corresponds to the view orientation |
84 * Returns the XML layout section that corresponds to the view orientation |
89 */ |
85 */ |
90 QString RadioWindow::orientationSection() |
86 QString RadioWindow::orientationSection() |
91 { |
87 { |
92 return orientation() == Qt::Vertical ? DOCML::SECTION_PORTRAIT : DOCML::SECTION_LANDSCAPE; |
88 return orientation() == Qt::Vertical ? DOCML::SECTION_PORTRAIT : DOCML::SECTION_LANDSCAPE; |
95 /*! |
91 /*! |
96 * |
92 * |
97 */ |
93 */ |
98 void RadioWindow::activateMainView() |
94 void RadioWindow::activateMainView() |
99 { |
95 { |
100 activateView( mMainView, DOCML::FILE_MAINVIEW, Hb::ViewSwitchUseBackAnim ); |
96 if ( !mMainView ) { |
|
97 mMainView = ViewPtr( new RadioMainView() ); |
|
98 } |
|
99 activateView( mMainView.data(), DOCML::FILE_MAINVIEW, Hb::ViewSwitchUseBackAnim ); |
101 } |
100 } |
102 |
101 |
103 /*! |
102 /*! |
104 * |
103 * |
105 */ |
104 */ |
106 void RadioWindow::activateStationsView() |
105 void RadioWindow::activateStationsView() |
107 { |
106 { |
108 activateView( mStationsView, DOCML::FILE_STATIONSVIEW ); |
107 if ( !mStationsView ) { |
|
108 mStationsView = ViewPtr( new RadioStationsView() ); |
|
109 } |
|
110 activateView( mStationsView.data(), DOCML::FILE_STATIONSVIEW ); |
109 } |
111 } |
110 |
112 |
111 /*! |
113 /*! |
112 * |
114 * |
113 */ |
115 */ |
114 void RadioWindow::activateHistoryView() |
116 void RadioWindow::activateHistoryView() |
115 { |
117 { |
116 activateView( mHistoryView, DOCML::FILE_HISTORYVIEW ); |
118 if ( !mHistoryView ) { |
|
119 mHistoryView = ViewPtr( new RadioHistoryView() ); |
|
120 } |
|
121 activateView( mHistoryView.data(), DOCML::FILE_HISTORYVIEW ); |
117 } |
122 } |
118 |
123 |
119 /*! |
124 /*! |
120 * Private slot |
125 * Private slot |
121 * |
126 * |
122 */ |
127 */ |
123 void RadioWindow::initView() |
128 void RadioWindow::initView() |
124 { |
129 { |
125 if ( !mUiEngine->isInitialized() ) { |
130 if ( !mUiEngine ) { |
|
131 mUiEngine = QSharedPointer<RadioUiEngine>( new RadioUiEngine( this ) ); |
|
132 |
126 // Start the engine |
133 // Start the engine |
127 if ( !mUiEngine->init() ) { |
134 if ( !mUiEngine->init() ) { |
128 showErrorMessage( hbTrId( "txt_fmradio_info_fm_radio_could_not_be_started" ) ); |
135 showErrorMessage( hbTrId( "txt_fmradio_info_fm_radio_could_not_be_started" ) ); |
129 qApp->quit(); |
136 qApp->quit(); |
130 return; |
137 return; |
131 } |
138 } |
132 |
139 |
133 // MainWindow is the one that always listens for orientation changes and then delegates |
140 // MainWindow is the one that always listens for orientation changes and then delegates |
134 // the updates to the views |
141 // the updates to the views |
135 connectAndTest( this, SIGNAL(orientationChanged(Qt::Orientation)), |
142 Radio::connect( this, SIGNAL(orientationChanged(Qt::Orientation)), |
136 this, SLOT(updateOrientation(Qt::Orientation)) ); |
143 this, SLOT(updateOrientation(Qt::Orientation)) ); |
137 |
144 |
138 connectAndTest( mUiEngine.data(), SIGNAL(volumeChanged(int)), |
145 Radio::connect( mUiEngine.data(), SIGNAL(volumeChanged(int)), |
139 this, SLOT(showVolumeLevel(int)) ); |
146 this, SLOT(showVolumeLevel(int)) ); |
140 connectAndTest( mUiEngine.data(), SIGNAL(antennaStatusChanged(bool)), |
147 Radio::connect( mUiEngine.data(), SIGNAL(antennaStatusChanged(bool)), |
141 this, SLOT(updateAntennaStatus(bool)) ); |
148 this, SLOT(updateAntennaStatus(bool)) ); |
|
149 Radio::connect( mUiEngine.data(), SIGNAL(powerOffRequested()), |
|
150 qApp, SLOT(quit()) ); |
142 } |
151 } |
143 |
152 |
144 RadioViewBase* view = static_cast<RadioViewBase*>( currentView() ); |
153 RadioViewBase* view = static_cast<RadioViewBase*>( currentView() ); |
145 if ( !view->isInitialized() ) { |
154 if ( !view->isInitialized() ) { |
146 view->init(); |
155 view->initialize( mUiEngine ); |
147 } |
156 } |
148 } |
157 } |
149 |
158 |
150 /*! |
159 /*! |
151 * Private slot |
160 * Private slot |
166 */ |
175 */ |
167 void RadioWindow::showVolumeLevel( int volume ) |
176 void RadioWindow::showVolumeLevel( int volume ) |
168 { |
177 { |
169 if ( !mVolSlider ) { |
178 if ( !mVolSlider ) { |
170 mVolSlider.reset( new HbVolumeSliderPopup() ); |
179 mVolSlider.reset( new HbVolumeSliderPopup() ); |
171 mVolSlider->setRange( 0, KMaximumVolumeLevel ); |
180 mVolSlider->setRange( 0, MAXIMUM_VOLUME_LEVEL ); |
172 mVolSlider->setSingleStep( 1 ); |
181 mVolSlider->setSingleStep( 1 ); |
173 mVolSlider->setTimeout( KVolumeSliderDelay ); |
182 mVolSlider->setTimeout( VOLUME_POPUP_TIMEOUT ); |
174 connectAndTest( mVolSlider.data(), SIGNAL(valueChanged(int)), |
183 Radio::connect( mVolSlider.data(), SIGNAL(valueChanged(int)), |
175 mUiEngine.data(), SLOT(setVolume(int)) ); |
184 mUiEngine.data(), SLOT(setVolume(int)) ); |
176 } |
185 } |
177 |
186 |
178 mVolSlider->setValue( volume ); |
187 mVolSlider->setValue( volume ); |
179 mVolSlider->setText( QString( "%L1%" ).arg( volume * 100 / KMaximumVolumeLevel ) ); |
188 //TODO: Check if this should be localized |
|
189 mVolSlider->setText( QString( "%L1%" ).arg( volume * 100 / MAXIMUM_VOLUME_LEVEL ) ); |
180 mVolSlider->show(); |
190 mVolSlider->show(); |
181 } |
191 } |
182 |
192 |
183 /*! |
193 /*! |
184 * Private slot |
194 * Private slot |
185 * |
195 * |
186 */ |
196 */ |
187 void RadioWindow::updateAntennaStatus( bool connected ) |
197 void RadioWindow::updateAntennaStatus( bool connected ) |
188 { |
198 { |
189 if ( !connected ) { |
199 if ( !connected ) { |
190 HbMessageBox::information( hbTrId( "txt_rad_dpophead_connect_wired_headset" ) ); |
200 if ( !mMessageBox ) { |
191 } |
201 mMessageBox.reset( new HbMessageBox() ); |
192 } |
202 } |
193 |
203 mMessageBox->setText( hbTrId( "txt_rad_dpophead_connect_wired_headset" ) ); |
194 /*! |
204 mMessageBox->setDismissPolicy( HbPopup::NoDismiss ); |
195 * |
205 mMessageBox->setTimeout( HbPopup::NoTimeout ); |
196 */ |
206 // mMessageBox->setAttribute( Qt::WA_DeleteOnClose, true ); |
197 void RadioWindow::activateView( ViewPtr& aMember, const QString& docmlFile, Hb::ViewSwitchFlags flags ) |
207 mMessageBox->open(); |
|
208 } else { |
|
209 mMessageBox.reset(); |
|
210 } |
|
211 } |
|
212 |
|
213 /*! |
|
214 * Private slot |
|
215 * |
|
216 */ |
|
217 void RadioWindow::queryOfflineUsage( QSystemDeviceInfo::Profile profile ) |
|
218 { |
|
219 if ( profile == QSystemDeviceInfo::OfflineProfile ) { |
|
220 bool okToContinue = false; |
|
221 HbDeviceMessageBox box( hbTrId( "txt_rad_info_continue_using_the_radio_in_offline" ), HbMessageBox::MessageTypeQuestion ); |
|
222 box.setTimeout( HbPopup::NoTimeout ); |
|
223 box.exec(); |
|
224 |
|
225 okToContinue = box.isAcceptAction( box.triggeredAction() ); |
|
226 |
|
227 if ( okToContinue ) { |
|
228 // Radio stays on |
|
229 } else { |
|
230 qApp->quit(); // Close radio |
|
231 } |
|
232 } // other profiles are not interesting |
|
233 } |
|
234 |
|
235 /*! |
|
236 * |
|
237 */ |
|
238 void RadioWindow::activateView( RadioViewBase* aMember, const QString& docmlFile, Hb::ViewSwitchFlags flags ) |
198 { |
239 { |
199 LOG_METHOD; |
240 LOG_METHOD; |
200 if ( aMember && aMember == currentView() ) { |
241 if ( aMember && aMember == currentView() ) { |
201 return; |
242 return; |
202 } |
243 } |
206 removeView( previousView ); |
247 removeView( previousView ); |
207 previousView->deleteLater(); |
248 previousView->deleteLater(); |
208 } |
249 } |
209 |
250 |
210 bool viewCreated = false; |
251 bool viewCreated = false; |
211 if ( !aMember ) { |
252 if ( !aMember->isInitialized() ) { |
212 viewCreated = true; |
253 viewCreated = true; |
213 |
254 |
214 RadioUiLoader* uiLoader = new RadioUiLoader(); |
255 QScopedPointer<RadioUiLoader> uiLoader( new RadioUiLoader() ); |
|
256 |
|
257 // By default the document loader would create a new HbView instance for our view so we need |
|
258 // to use a silly little hack to prevent it. We call our view "view" and pass it to the document loader |
|
259 // so it already exists. |
|
260 aMember->setObjectName( DOCML::NAME_VIEW ); |
|
261 QObjectList objectList; |
|
262 objectList.append( aMember ); |
|
263 uiLoader->setObjectTree( objectList ); |
|
264 |
215 bool ok = false; |
265 bool ok = false; |
216 |
266 uiLoader->load( docmlFile, &ok ); |
217 // View takes ownership of the ui loader when it is created inside the load function |
|
218 QObjectList objectList = uiLoader->load( docmlFile, &ok ); |
|
219 |
267 |
220 RADIO_ASSERT( ok , "FMRadio", "invalid DocML file" ); |
268 RADIO_ASSERT( ok , "FMRadio", "invalid DocML file" ); |
221 if ( !ok ) { |
269 if ( !ok ) { |
222 delete uiLoader; |
270 uiLoader.reset(); |
223 uiLoader = 0; |
|
224 return; |
271 return; |
225 } |
272 } |
226 |
273 |
227 aMember = ViewPtr( uiLoader->findObject<RadioViewBase>( DOCML::NAME_VIEW ) ); |
274 aMember->setMembers( this, uiLoader.take() ); |
228 |
275 aMember->preLazyLoadInit(); |
229 foreach( QObject* object, objectList ) { |
|
230 const QString className = object->metaObject()->className(); |
|
231 if ( !object->parent() && object != aMember.data() ) { |
|
232 object->setParent( aMember.data() ); |
|
233 } |
|
234 } |
|
235 |
|
236 aMember->setMembers( uiLoader, this ); |
|
237 |
276 |
238 addView( aMember ); |
277 addView( aMember ); |
239 } |
278 } |
240 |
279 |
241 aMember->updateOrientation( orientation(), viewCreated ); |
280 aMember->updateOrientation( orientation(), viewCreated ); |