|
1 /* |
|
2 * Copyright (c) 2007 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 |
|
19 #include <aknnavide.h> |
|
20 #include <texttospeech.rsg> |
|
21 |
|
22 #include "texttospeechappui.h" |
|
23 #include "texttospeechengine.h" |
|
24 #include "texttospeechsettingitemlistview.h" |
|
25 #include "texttospeechsettingitemlist.h" |
|
26 #include "texttospeechsettingitemlistsettings.h" |
|
27 |
|
28 #include "texttospeech.hrh" |
|
29 |
|
30 const TInt KMaxVolumeInUI = 10; |
|
31 |
|
32 /** |
|
33 * First phase of Symbian two-phase construction. Should not contain any |
|
34 * code that could leave. |
|
35 */ |
|
36 CTextToSpeechSettingItemListView::CTextToSpeechSettingItemListView() |
|
37 { |
|
38 } |
|
39 |
|
40 /** |
|
41 * The view's destructor removes the container from the control |
|
42 * stack and destroys it. |
|
43 */ |
|
44 CTextToSpeechSettingItemListView::~CTextToSpeechSettingItemListView() |
|
45 { |
|
46 } |
|
47 |
|
48 /** |
|
49 * Symbian two-phase constructor. |
|
50 * This creates an instance then calls the second-phase constructor |
|
51 * without leaving the instance on the cleanup stack. |
|
52 * @return new instance of CTextToSpeechSettingItemListView |
|
53 */ |
|
54 CTextToSpeechSettingItemListView* CTextToSpeechSettingItemListView::NewL() |
|
55 { |
|
56 CTextToSpeechSettingItemListView* self = |
|
57 CTextToSpeechSettingItemListView::NewLC(); |
|
58 |
|
59 CleanupStack::Pop( self ); |
|
60 |
|
61 return self; |
|
62 } |
|
63 |
|
64 /** |
|
65 * Symbian two-phase constructor. |
|
66 * This creates an instance, pushes it on the cleanup stack, |
|
67 * then calls the second-phase constructor. |
|
68 * @return new instance of CTextToSpeechSettingItemListView |
|
69 */ |
|
70 CTextToSpeechSettingItemListView* CTextToSpeechSettingItemListView::NewLC() |
|
71 { |
|
72 CTextToSpeechSettingItemListView* self = |
|
73 new (ELeave) CTextToSpeechSettingItemListView(); |
|
74 |
|
75 CleanupStack::PushL( self ); |
|
76 self->ConstructL(); |
|
77 |
|
78 return self; |
|
79 } |
|
80 |
|
81 /** |
|
82 * Second-phase constructor for view. |
|
83 * Initialize contents from resource. |
|
84 */ |
|
85 void CTextToSpeechSettingItemListView::ConstructL() |
|
86 { |
|
87 BaseConstructL( |
|
88 R_TEXT_TO_SPEECH_SETTING_ITEM_LIST_TEXT_TO_SPEECH_SETTING_ITEM_LIST_VIEW ); |
|
89 } |
|
90 |
|
91 /** |
|
92 * @return The UID for this view |
|
93 */ |
|
94 TUid CTextToSpeechSettingItemListView::Id() const |
|
95 { |
|
96 return TUid::Uid( ETextToSpeechSettingItemListViewId ); |
|
97 } |
|
98 |
|
99 /** |
|
100 * Handle a command for this view (override) |
|
101 * @param aCommand command id to be handled |
|
102 */ |
|
103 void CTextToSpeechSettingItemListView::HandleCommandL( TInt aCommand ) |
|
104 { |
|
105 TBool commandHandled( ETrue ); |
|
106 CAknVolumeControl* control( NULL ); |
|
107 |
|
108 switch ( aCommand ) |
|
109 { // code to dispatch to the AknView's menu and CBA commands is generated here |
|
110 |
|
111 case ETextToSpeechSettingItemListViewMenuItem1Command: |
|
112 case EAknSoftkeyChange: |
|
113 |
|
114 iTextToSpeechSettingItemList->ChangeSelectedItemL(); |
|
115 |
|
116 break; |
|
117 |
|
118 case ETextToSpeechSettingItemListViewSynthesiseMenuItemCommand: |
|
119 |
|
120 iEngine->SetSpeakingRateL( iSettings->Slider1() ); |
|
121 iEngine->SetVoiceL( iSettings->iVoice ); |
|
122 iEngine->InitAndPlayText( iSettings->Edit1() ); |
|
123 |
|
124 break; |
|
125 |
|
126 case ETextToSpeechSettingItemListViewExitMenuItemCommand: |
|
127 |
|
128 AppUi()->HandleCommandL( EEikCmdExit ); |
|
129 |
|
130 break; |
|
131 |
|
132 case EKeyIncVolume: |
|
133 |
|
134 iEngine->SetVolumeL( iSettings->iVolume + |
|
135 iSettings->iMaxVolume / KMaxVolumeInUI ); |
|
136 |
|
137 iSettings->iVolume = iSettings->iVolume + |
|
138 iSettings->iMaxVolume / KMaxVolumeInUI; |
|
139 |
|
140 control = static_cast< CAknVolumeControl* >( |
|
141 iVolumeControl->DecoratedControl() ); |
|
142 |
|
143 control->SetValue( KMaxVolumeInUI * |
|
144 iSettings->iVolume / iSettings->iMaxVolume ); |
|
145 |
|
146 break; |
|
147 |
|
148 case EKeyDecVolume: |
|
149 |
|
150 iEngine->SetVolumeL( iSettings->iVolume - |
|
151 iSettings->iMaxVolume / KMaxVolumeInUI ); |
|
152 |
|
153 iSettings->iVolume = iSettings->iVolume - |
|
154 iSettings->iMaxVolume / KMaxVolumeInUI; |
|
155 |
|
156 control = static_cast< CAknVolumeControl* >( |
|
157 iVolumeControl->DecoratedControl() ); |
|
158 |
|
159 control->SetValue( KMaxVolumeInUI * |
|
160 iSettings->iVolume / iSettings->iMaxVolume ); |
|
161 |
|
162 break; |
|
163 |
|
164 default: |
|
165 |
|
166 commandHandled = EFalse; |
|
167 |
|
168 break; |
|
169 |
|
170 } |
|
171 |
|
172 if ( !commandHandled && aCommand == EAknSoftkeyExit ) |
|
173 { |
|
174 AppUi()->HandleCommandL( EEikCmdExit ); |
|
175 } |
|
176 } |
|
177 |
|
178 /** |
|
179 * Handles Navidecorator events (Arrow left and arrow right) |
|
180 * @param aEventID ID of event to be handled |
|
181 */ |
|
182 void CTextToSpeechSettingItemListView::HandleNaviDecoratorEventL( TInt aEventID ) |
|
183 { |
|
184 CAknVolumeControl* control( NULL ); |
|
185 |
|
186 switch ( aEventID ) |
|
187 { |
|
188 case EAknNaviDecoratorEventRightTabArrow: |
|
189 |
|
190 HandleCommandL( EKeyIncVolume ); |
|
191 |
|
192 break; |
|
193 |
|
194 case EAknNaviDecoratorEventLeftTabArrow: |
|
195 |
|
196 HandleCommandL( EKeyDecVolume ); |
|
197 |
|
198 break; |
|
199 |
|
200 case EAknNaviDecoratorEventNaviLabel: |
|
201 |
|
202 control = static_cast< CAknVolumeControl* >( |
|
203 iVolumeControl->DecoratedControl() ); |
|
204 |
|
205 if ( control ) |
|
206 { |
|
207 TInt value = control->Value(); |
|
208 |
|
209 iEngine->SetVolumeL( value * |
|
210 iSettings->iMaxVolume / KMaxVolumeInUI ); |
|
211 |
|
212 iSettings->iVolume = value * |
|
213 iSettings->iMaxVolume / KMaxVolumeInUI ; |
|
214 } |
|
215 |
|
216 break; |
|
217 |
|
218 } |
|
219 } |
|
220 |
|
221 /** |
|
222 * Activate view |
|
223 * @param aPrevViewId |
|
224 * @param aCustomMessageId |
|
225 * @param aCustomMessage |
|
226 */ |
|
227 void CTextToSpeechSettingItemListView::DoActivateL( const TVwsViewId& /*aPrevViewId*/, |
|
228 TUid /*aCustomMessageId*/, |
|
229 const TDesC8& /*aCustomMessage*/ ) |
|
230 { |
|
231 CEikButtonGroupContainer *cba = AppUi()->Cba(); |
|
232 if ( cba ) |
|
233 { |
|
234 cba->MakeVisible( EFalse ); |
|
235 } |
|
236 |
|
237 if ( !iTextToSpeechSettingItemList ) |
|
238 { |
|
239 iEngine = (((CTextToSpeechAppUi*)AppUi())->AppEngine()); |
|
240 |
|
241 iSettings = CTextToSpeechSettingItemListSettings::NewL(); |
|
242 |
|
243 iTextToSpeechSettingItemList = |
|
244 new (ELeave) CTextToSpeechSettingItemList( *iSettings, this ); |
|
245 |
|
246 iTextToSpeechSettingItemList->SetMopParent( this ); |
|
247 iTextToSpeechSettingItemList->ConstructFromResourceL( |
|
248 R_TEXT_TO_SPEECH_SETTING_ITEM_LIST_TEXT_TO_SPEECH_SETTING_ITEM_LIST ); |
|
249 |
|
250 iTextToSpeechSettingItemList->ActivateL(); |
|
251 iTextToSpeechSettingItemList->LoadSettingValuesL(); |
|
252 iTextToSpeechSettingItemList->LoadSettingsL(); |
|
253 |
|
254 AppUi()->AddToStackL( *this, iTextToSpeechSettingItemList ); |
|
255 |
|
256 SetupStatusPaneL(); |
|
257 } |
|
258 } |
|
259 |
|
260 /** |
|
261 * Deactivate view |
|
262 */ |
|
263 void CTextToSpeechSettingItemListView::DoDeactivate() |
|
264 { |
|
265 CleanupStatusPane(); |
|
266 |
|
267 CEikButtonGroupContainer *cba = AppUi()->Cba(); |
|
268 if ( cba ) |
|
269 { |
|
270 cba->MakeVisible( ETrue ); |
|
271 cba->DrawDeferred(); |
|
272 } |
|
273 |
|
274 if ( iTextToSpeechSettingItemList ) |
|
275 { |
|
276 AppUi()->RemoveFromStack( iTextToSpeechSettingItemList ); |
|
277 |
|
278 delete iTextToSpeechSettingItemList; |
|
279 iTextToSpeechSettingItemList = NULL; |
|
280 |
|
281 delete iSettings; |
|
282 iSettings = NULL; |
|
283 } |
|
284 } |
|
285 |
|
286 /** |
|
287 * Show volume indicator in status pane |
|
288 */ |
|
289 void CTextToSpeechSettingItemListView::SetupStatusPaneL() |
|
290 { |
|
291 if ( !iVolumeControl ) |
|
292 { |
|
293 CAknNavigationControlContainer* naviPane = |
|
294 static_cast< CAknNavigationControlContainer* >( |
|
295 iEikonEnv->AppUiFactory()->StatusPane()->ControlL( |
|
296 TUid::Uid( EEikStatusPaneUidNavi ) ) ); |
|
297 |
|
298 iVolumeControl = |
|
299 naviPane->CreateVolumeIndicatorL( R_AVKON_NAVI_PANE_VOLUME_INDICATOR ); |
|
300 |
|
301 // Subscribe for changes in volume indicator |
|
302 iVolumeControl->SetNaviDecoratorObserver( this ); |
|
303 iVolumeControl->SetControlType( CAknNavigationDecorator::ENaviLabel ); |
|
304 |
|
305 CAknVolumeControl* control = |
|
306 static_cast< CAknVolumeControl* >( iVolumeControl->DecoratedControl() ); |
|
307 |
|
308 control->SetValue( KMaxVolumeInUI * |
|
309 iSettings->iVolume / iSettings->iMaxVolume ); |
|
310 |
|
311 naviPane->PushL( *iVolumeControl ); |
|
312 } |
|
313 } |
|
314 |
|
315 /** |
|
316 * Delete volume indicator |
|
317 */ |
|
318 void CTextToSpeechSettingItemListView::CleanupStatusPane() |
|
319 { |
|
320 delete iVolumeControl; |
|
321 iVolumeControl = NULL; |
|
322 } |
|
323 |
|
324 /** |
|
325 * Handle status pane size change for this view (override) |
|
326 */ |
|
327 void CTextToSpeechSettingItemListView::HandleStatusPaneSizeChange() |
|
328 { |
|
329 CAknView::HandleStatusPaneSizeChange(); |
|
330 |
|
331 // this may fail, but we're not able to propagate exceptions here |
|
332 TRAP_IGNORE( SetupStatusPaneL() ); |
|
333 } |
|
334 |
|
335 // End of file |