|
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 "texttospeechappui.h" |
|
20 #include "texttospeechengine.h" |
|
21 #include "texttospeechsettingitemlist.h" |
|
22 #include "texttospeechsettingitemlistsettings.h" |
|
23 #include "texttospeech.hrh" |
|
24 |
|
25 /** |
|
26 * Construct the CTextToSpeechSettingItemList instance |
|
27 * @param aCommandObserver command observer |
|
28 */ |
|
29 CTextToSpeechSettingItemList::CTextToSpeechSettingItemList( |
|
30 CTextToSpeechSettingItemListSettings& aSettings, |
|
31 MEikCommandObserver* aCommandObserver ) : |
|
32 iSettings( aSettings ), |
|
33 iCommandObserver( aCommandObserver ) |
|
34 { |
|
35 } |
|
36 |
|
37 /** |
|
38 * Destroy any instance variables |
|
39 */ |
|
40 CTextToSpeechSettingItemList::~CTextToSpeechSettingItemList() |
|
41 { |
|
42 } |
|
43 |
|
44 /** |
|
45 * Handle system notification that the container's size has changed. |
|
46 */ |
|
47 void CTextToSpeechSettingItemList::SizeChanged() |
|
48 { |
|
49 if ( ListBox() ) |
|
50 { |
|
51 ListBox()->SetRect( Rect() ); |
|
52 } |
|
53 } |
|
54 |
|
55 /** |
|
56 * Create one setting item at a time, identified by id. |
|
57 * CAknSettingItemList calls this method and takes ownership |
|
58 * of the returned value. The CAknSettingItem object owns |
|
59 * a reference to the underlying data, which EditItemL() uses |
|
60 * to edit and store the value. |
|
61 */ |
|
62 CAknSettingItem* CTextToSpeechSettingItemList::CreateSettingItemL( TInt aId ) |
|
63 { |
|
64 CAknSettingItem* item( NULL ); |
|
65 |
|
66 switch ( aId ) |
|
67 { |
|
68 case ETextToSpeechSettingItemListViewEdit1: |
|
69 { |
|
70 item = new (ELeave) CAknTextSettingItem( aId, iSettings.Edit1() ); |
|
71 |
|
72 break; |
|
73 } |
|
74 case ETextToSpeechSettingItemListViewEnumeratedTextPopup1: |
|
75 { |
|
76 item = new (ELeave) CAknEnumeratedTextPopupSettingItem( |
|
77 aId, iSettings.EnumeratedTextPopup1() ); |
|
78 |
|
79 break; |
|
80 } |
|
81 case ETextToSpeechSettingItemListViewEnumeratedTextPopup2: |
|
82 { |
|
83 item = new (ELeave) CAknEnumeratedTextPopupSettingItem( |
|
84 aId, iSettings.EnumeratedTextPopup2() ); |
|
85 |
|
86 break; |
|
87 } |
|
88 case ETextToSpeechSettingItemListViewSlider1: |
|
89 { |
|
90 item = new (ELeave) CAknSliderSettingItem( |
|
91 aId, iSettings.Slider1() ); |
|
92 |
|
93 break; |
|
94 } |
|
95 } |
|
96 |
|
97 return item; |
|
98 } |
|
99 |
|
100 /** |
|
101 * Edit the setting item identified by the given id and store |
|
102 * the changes into the store. |
|
103 * @param aIndex the index of the setting item in SettingItemArray() |
|
104 * @param aCalledFromMenu true: a menu item invoked editing, thus |
|
105 * always show the edit page and interactively edit the item; |
|
106 * false: change the item in place if possible, else show the edit page |
|
107 */ |
|
108 void CTextToSpeechSettingItemList::EditItemL ( TInt aIndex, TBool aCalledFromMenu ) |
|
109 { |
|
110 CAknSettingItemList::EditItemL( aIndex, aCalledFromMenu ); |
|
111 |
|
112 CAknSettingItem* item = ( *SettingItemArray() )[aIndex]; |
|
113 |
|
114 TInt tmp1; |
|
115 TInt tmp2; |
|
116 |
|
117 switch ( item->Identifier() ) |
|
118 { |
|
119 case ETextToSpeechSettingItemListViewEnumeratedTextPopup1: |
|
120 |
|
121 tmp1 = iSettings.EnumeratedTextPopup1(); |
|
122 item->StoreL(); |
|
123 tmp2 = iSettings.EnumeratedTextPopup1(); |
|
124 |
|
125 if ( tmp1 != tmp2 ) |
|
126 { |
|
127 TLanguage lang = |
|
128 iSettings.iLanguages[iSettings.EnumeratedTextPopup1()]; |
|
129 |
|
130 iSettings.iVoices.Reset(); |
|
131 iEngine->GetVoicesL( iSettings.iVoices, lang ); |
|
132 |
|
133 LoadVoicesL( ETrue ); |
|
134 |
|
135 iSettings.iVoice = |
|
136 iSettings.iVoices[iSettings.EnumeratedTextPopup2()]; |
|
137 |
|
138 HandleSliderVisibility(); |
|
139 HandleChangeInItemArrayOrVisibilityL(); |
|
140 } |
|
141 |
|
142 break; |
|
143 |
|
144 case ETextToSpeechSettingItemListViewEnumeratedTextPopup2: |
|
145 |
|
146 tmp1 = iSettings.EnumeratedTextPopup2(); |
|
147 item->StoreL(); |
|
148 tmp2 = iSettings.EnumeratedTextPopup2(); |
|
149 |
|
150 if ( tmp1 != tmp2 ) |
|
151 { |
|
152 iSettings.iVoice = |
|
153 iSettings.iVoices[iSettings.EnumeratedTextPopup2()]; |
|
154 } |
|
155 |
|
156 HandleSliderVisibility(); |
|
157 HandleChangeInItemArrayOrVisibilityL(); |
|
158 |
|
159 break; |
|
160 |
|
161 default: |
|
162 |
|
163 break; |
|
164 |
|
165 } |
|
166 |
|
167 item->StoreL(); |
|
168 } |
|
169 |
|
170 /** |
|
171 * Handle the "Change" option on the Options menu. This is an |
|
172 * alternative to the Selection key that forces the settings page |
|
173 * to come up rather than changing the value in place (if possible). |
|
174 */ |
|
175 void CTextToSpeechSettingItemList::ChangeSelectedItemL() |
|
176 { |
|
177 if ( ListBox()->CurrentItemIndex() >= 0 ) |
|
178 { |
|
179 EditItemL( ListBox()->CurrentItemIndex(), ETrue ); |
|
180 } |
|
181 } |
|
182 |
|
183 /** |
|
184 * Load the initial contents of the setting items. By default, |
|
185 * the setting items are populated with the default values from |
|
186 * the design. You can override those values here. |
|
187 * <p> |
|
188 * Note: this call alone does not update the UI. |
|
189 * LoadSettingsL() must be called afterwards. |
|
190 */ |
|
191 void CTextToSpeechSettingItemList::LoadSettingValuesL() |
|
192 { |
|
193 |
|
194 iEngine = (((CTextToSpeechAppUi*)iEikonEnv->AppUi())->AppEngine()); |
|
195 |
|
196 iSettings.iVolume = iEngine->VolumeL(); |
|
197 iSettings.iMaxVolume = iEngine->MaxVolumeL(); |
|
198 iSettings.iVoice = iEngine->VoiceL(); |
|
199 |
|
200 iSettings.iLanguages.Reset(); |
|
201 iEngine->GetLanguagesL( iSettings.iLanguages ); |
|
202 |
|
203 iSettings.iVoices.Reset(); |
|
204 iEngine->GetVoicesL( iSettings.iVoices, iSettings.iVoice.iLanguage ); |
|
205 |
|
206 LoadLanguagesL(); |
|
207 LoadVoicesL( EFalse ); |
|
208 |
|
209 iSettings.SetSlider1( iEngine->SpeakingRateL() ); |
|
210 CAknSettingItem* sliderItem = ( *SettingItemArray() )[3]; |
|
211 sliderItem->LoadL(); |
|
212 |
|
213 HandleSliderVisibility(); |
|
214 |
|
215 // Required when there is only one setting item. |
|
216 SettingItemArray()->RecalculateVisibleIndicesL(); |
|
217 |
|
218 HandleChangeInItemArrayOrVisibilityL(); |
|
219 } |
|
220 |
|
221 /** |
|
222 * Add correct languages to popup list |
|
223 */ |
|
224 void CTextToSpeechSettingItemList::LoadLanguagesL() |
|
225 { |
|
226 CAknSettingItemArray* itemArray = SettingItemArray(); |
|
227 CAknEnumeratedTextPopupSettingItem* item = |
|
228 (CAknEnumeratedTextPopupSettingItem*) (*itemArray)[1]; |
|
229 |
|
230 // Load texts dynamically. |
|
231 CArrayPtr<CAknEnumeratedText>* texts = item->EnumeratedTextArray(); |
|
232 texts->ResetAndDestroy(); |
|
233 |
|
234 CAknEnumeratedText* enumText( NULL ); |
|
235 |
|
236 TInt selectedItem( 0 ); |
|
237 |
|
238 for ( TInt i( 0 ); i < iSettings.iLanguages.Count(); i++ ) |
|
239 { |
|
240 TLanguage lang( iSettings.iLanguages[i] ); |
|
241 |
|
242 TBuf<8> tmp; |
|
243 tmp.Num( (TInt)lang ); |
|
244 |
|
245 HBufC* text = tmp.AllocLC(); |
|
246 |
|
247 enumText = new (ELeave) CAknEnumeratedText( i, text ); |
|
248 |
|
249 CleanupStack::PushL( enumText ); |
|
250 texts->AppendL( enumText ); |
|
251 CleanupStack::Pop( enumText ); |
|
252 |
|
253 CleanupStack::Pop( text ); |
|
254 |
|
255 if ( lang == iSettings.iVoice.iLanguage ) |
|
256 { |
|
257 selectedItem = i; |
|
258 } |
|
259 } |
|
260 |
|
261 iSettings.SetEnumeratedTextPopup1( selectedItem ); |
|
262 item->LoadL(); |
|
263 } |
|
264 |
|
265 /** |
|
266 * Add correct voice names to popup list |
|
267 */ |
|
268 void CTextToSpeechSettingItemList::LoadVoicesL( TBool aResetSelection ) |
|
269 { |
|
270 CAknSettingItemArray* itemArray = SettingItemArray(); |
|
271 CAknEnumeratedTextPopupSettingItem* item = |
|
272 (CAknEnumeratedTextPopupSettingItem*) (*itemArray)[2]; |
|
273 |
|
274 // Load texts dynamically. |
|
275 CArrayPtr<CAknEnumeratedText>* texts = item->EnumeratedTextArray(); |
|
276 texts->ResetAndDestroy(); |
|
277 |
|
278 CAknEnumeratedText* enumText( NULL ); |
|
279 |
|
280 TInt selectedItem( 0 ); |
|
281 |
|
282 for ( TInt i( 0 ); i < iSettings.iVoices.Count(); i++ ) |
|
283 { |
|
284 HBufC* text = iSettings.iVoices[i].iVoiceName.AllocLC(); |
|
285 enumText = new (ELeave) CAknEnumeratedText( i, text ); |
|
286 CleanupStack::Pop( text ); |
|
287 |
|
288 CleanupStack::PushL( enumText ); |
|
289 texts->AppendL( enumText ); |
|
290 CleanupStack::Pop( enumText ); |
|
291 |
|
292 if ( !aResetSelection && |
|
293 iSettings.iVoices[i].iVoiceName == iSettings.iVoice.iVoiceName ) |
|
294 { |
|
295 selectedItem = i; |
|
296 } |
|
297 } |
|
298 |
|
299 iSettings.SetEnumeratedTextPopup2( selectedItem ); |
|
300 item->LoadL(); |
|
301 } |
|
302 |
|
303 /** |
|
304 * Hide slider if current voice doesn't support speaking rate, |
|
305 * otherwise show it. |
|
306 */ |
|
307 void CTextToSpeechSettingItemList::HandleSliderVisibility() |
|
308 { |
|
309 CAknSettingItem* sliderItem = ( *SettingItemArray() )[3]; |
|
310 |
|
311 if ( iSettings.iVoice.iVoiceName == _L("DefaultMale") || |
|
312 iSettings.iVoice.iVoiceName == _L("DefaultFemale") ) |
|
313 { |
|
314 sliderItem->SetHidden( ETrue ); |
|
315 } |
|
316 else |
|
317 { |
|
318 sliderItem->SetHidden( EFalse ); |
|
319 } |
|
320 } |
|
321 |
|
322 /** |
|
323 * Handle key event (override) |
|
324 * @param aKeyEvent key event |
|
325 * @param aType event code |
|
326 * @return EKeyWasConsumed if the event was handled, else EKeyWasNotConsumed |
|
327 */ |
|
328 TKeyResponse CTextToSpeechSettingItemList::OfferKeyEventL( const TKeyEvent& aKeyEvent, |
|
329 TEventCode aType ) |
|
330 { |
|
331 TKeyResponse response( EKeyWasConsumed ); |
|
332 |
|
333 if ( aKeyEvent.iCode == EKeyLeftArrow ) |
|
334 { |
|
335 iCommandObserver->ProcessCommandL( EKeyDecVolume ); |
|
336 } |
|
337 else if ( aKeyEvent.iCode == EKeyRightArrow ) |
|
338 { |
|
339 iCommandObserver->ProcessCommandL( EKeyIncVolume ); |
|
340 } |
|
341 else |
|
342 { |
|
343 response = CAknSettingItemList::OfferKeyEventL( aKeyEvent, aType ); |
|
344 } |
|
345 |
|
346 return response; |
|
347 } |
|
348 |
|
349 // End of file |