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