|
1 /* |
|
2 * Copyright (c) 2006-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: This is the implementation of main container. It contains |
|
15 * all necessary AVKON components and handles user inputs. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <centralrepository.h> |
|
21 #include <barsread.h> // Resource reader |
|
22 #include <BtuiViewResources.rsg> // Compiled resource ids |
|
23 #include <btfeaturescfg.h> // For EnterpriseEnablementL() |
|
24 #include "BTUIMainContainer.h" |
|
25 #include "debug.h" // Global declarations |
|
26 #include "btui.h" |
|
27 #ifdef __SERIES60_HELP |
|
28 #include <csxhelp/bt.hlp.hrh> // Help ids |
|
29 #endif |
|
30 |
|
31 // --------------------------------------------------------- |
|
32 // CBTUIMainContainer::ConstructL |
|
33 // Symbian OS 2nd phase constructor can leave |
|
34 // --------------------------------------------------------- |
|
35 // |
|
36 void CBTUIMainContainer::ConstructL(const TRect& aRect, CBTUIMainView* aMainView ) |
|
37 { |
|
38 TRACE_FUNC_ENTRY |
|
39 |
|
40 CreateWindowL(); |
|
41 |
|
42 iMainView = aMainView; |
|
43 |
|
44 // Check if listbox is empty |
|
45 __ASSERT_DEBUG(iBtMainListBox==0, PANIC( EBTMainListNotEmpty )); |
|
46 __ASSERT_DEBUG(iBtAllItemsArray==0, PANIC( EBTAllFormatStingsArrayNotEmpty )); |
|
47 __ASSERT_DEBUG(iBtListItemArray==0, PANIC( EBTFormatStingsArrayNotEmpty )); |
|
48 |
|
49 // Create main itemlist |
|
50 iBtMainListBox = new (ELeave) CAknSettingStyleListBox; |
|
51 iBtMainListBox->SetContainerWindowL( *this ); |
|
52 iBtMainListBox->ConstructL( this, EAknListBoxMarkableList ); |
|
53 |
|
54 |
|
55 // Update settings from original sources via model |
|
56 iBtEngSettingsRef = iMainView->GetBtSettingsReference(); |
|
57 |
|
58 __ASSERT_DEBUG(iBtEngSettingsRef!=0, PANIC(EBTPanicIllegalValue)); |
|
59 |
|
60 // Read all format strings from resources and create array for them |
|
61 iBtAllItemsArray = iCoeEnv->ReadDesCArrayResourceL( R_BT_LABEL_STRINGS ); |
|
62 iBtListItemArray = new (ELeave) TMainListItemArray( |
|
63 iBtAllItemsArray, aMainView, iBtEngSettingsRef ); |
|
64 |
|
65 // Set up/down arrows at bottom of the screen (scrollbar) |
|
66 iBtMainListBox->CreateScrollBarFrameL( ETrue ); |
|
67 iBtMainListBox->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
68 CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto ); |
|
69 |
|
70 // Set text labels for list items again (overwriting resource definitions) |
|
71 iBtMainListBox->Model()->SetItemTextArray( iBtListItemArray ); |
|
72 iBtMainListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray ); // Does not delete items array |
|
73 |
|
74 // Set up the observer (events listener) |
|
75 iBtMainListBox->SetListBoxObserver( this ); |
|
76 |
|
77 |
|
78 |
|
79 SetRect(aRect); |
|
80 ActivateL(); |
|
81 |
|
82 TRACE_FUNC_EXIT |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------- |
|
86 // Destructor |
|
87 // --------------------------------------------------------- |
|
88 // |
|
89 CBTUIMainContainer::~CBTUIMainContainer() |
|
90 { |
|
91 TRACE_FUNC_ENTRY |
|
92 delete iBtMainListBox; |
|
93 delete iBtAllItemsArray; |
|
94 delete iBtListItemArray; |
|
95 TRACE_FUNC_EXIT |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------- |
|
99 // CBTUIMainContainer::SizeChanged() |
|
100 // From CCoeControl |
|
101 // Called by framework when the view size is changed |
|
102 // --------------------------------------------------------- |
|
103 // |
|
104 void CBTUIMainContainer::SizeChanged() |
|
105 { |
|
106 TRACE_FUNC_ENTRY |
|
107 iBtMainListBox->SetRect(Rect()); // Mandatory, otherwise not drawn |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------- |
|
111 // From CCoeControl |
|
112 // CBTUIMainContainer::CountComponentControls() const |
|
113 // --------------------------------------------------------- |
|
114 // |
|
115 TInt CBTUIMainContainer::CountComponentControls() const |
|
116 { |
|
117 TRACE_FUNC_ENTRY |
|
118 if(iBtMainListBox ) |
|
119 return 1; |
|
120 else |
|
121 return 0; // return nbr of controls inside this container |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------- |
|
125 // From CCoeControl |
|
126 // CBTUIMainContainer::ComponentControl(TInt aIndex) const |
|
127 // --------------------------------------------------------- |
|
128 // |
|
129 CCoeControl* CBTUIMainContainer::ComponentControl(TInt aIndex) const |
|
130 { |
|
131 TRACE_FUNC_ENTRY |
|
132 if( aIndex ==0 ) |
|
133 { |
|
134 return iBtMainListBox; |
|
135 } |
|
136 return NULL; |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------- |
|
140 // From CCoeControl |
|
141 // CBTUIMainContainer::Draw |
|
142 // --------------------------------------------------------- |
|
143 // |
|
144 void CBTUIMainContainer::Draw(const TRect& /* aRect */) const |
|
145 { |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------- |
|
149 // From CoeControl |
|
150 // CBTUIMainContainer::HandleControlEventL |
|
151 // --------------------------------------------------------- |
|
152 // |
|
153 void CBTUIMainContainer::HandleControlEventL( CCoeControl* /* aControl */, TCoeEvent /* aEventType */) |
|
154 { |
|
155 } |
|
156 |
|
157 // --------------------------------------------------------- |
|
158 // From CoeControl |
|
159 // CBTUIMainContainer::OfferKeyEventL |
|
160 // Redirect keypresses to the listbox |
|
161 // --------------------------------------------------------- |
|
162 // |
|
163 TKeyResponse CBTUIMainContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
|
164 { |
|
165 TRACE_FUNC_ENTRY |
|
166 if(( iBtMainListBox ) && ( aKeyEvent.iCode != EKeyLeftArrow ) |
|
167 && (aKeyEvent.iCode != EKeyRightArrow )) |
|
168 { |
|
169 TKeyResponse res = iBtMainListBox->OfferKeyEventL( aKeyEvent, aType ); |
|
170 |
|
171 // Store current item index for options list usage later |
|
172 // |
|
173 iCurrentItemIndex = iBtMainListBox->CurrentItemIndex(); |
|
174 return res; |
|
175 } |
|
176 return EKeyWasNotConsumed; |
|
177 } |
|
178 |
|
179 // --------------------------------------------------------- |
|
180 // From MEikListBoxObserver |
|
181 // CBTUIMainContainer::HandleListBoxEventL |
|
182 // --------------------------------------------------------- |
|
183 // |
|
184 void CBTUIMainContainer::HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType) |
|
185 { |
|
186 TRACE_FUNC_ENTRY |
|
187 |
|
188 __ASSERT_DEBUG(iMainView!=0, PANIC(EBTPanicIllegalValue)); |
|
189 |
|
190 // this is no longer called, unless MSK is disabled. |
|
191 // if msk is not disabled, then |
|
192 // BTMainView::HandleCommand(EBTUICmdMSK) is called instead |
|
193 if( aEventType == EEventEnterKeyPressed |
|
194 || aEventType == EEventItemSingleClicked ) // Selection key pressed, or item clicked |
|
195 { |
|
196 TInt currentHighLightPosition = aListBox->CurrentItemIndex(); |
|
197 switch(currentHighLightPosition) |
|
198 { |
|
199 case EBTMainListItemPowerMode: |
|
200 iMainView->HandleCommandL( EBTUICmdChangePowerStateSelect ); |
|
201 break; |
|
202 case EBTMainListItemVisibilityMode: |
|
203 iMainView->HandleCommandL( EBTUICmdChangeVisibilitySelect ); |
|
204 break; |
|
205 case EBTMainListItemNameSetting: |
|
206 iMainView->HandleCommandL( EBTUICmdChangeBTNameSelect ); |
|
207 break; |
|
208 |
|
209 // For Bluetooth SIM Access Profile feature |
|
210 // |
|
211 case EBTMainListItemSapMode: |
|
212 iMainView->HandleCommandL( EBTUICmdChangeSapStateSelect ); |
|
213 break; |
|
214 default: |
|
215 break; |
|
216 } |
|
217 aListBox->DrawItem(currentHighLightPosition); // Redraw item only to the screen |
|
218 } |
|
219 } |
|
220 |
|
221 // ---------------------------------------------------- |
|
222 // From CEikListBox |
|
223 // CBTUIMainContainer::CurrentItemIndex |
|
224 // ---------------------------------------------------- |
|
225 // |
|
226 TInt CBTUIMainContainer::CurrentItemIndex() |
|
227 { |
|
228 TRACE_FUNC_ENTRY |
|
229 |
|
230 return iBtMainListBox->CurrentItemIndex(); |
|
231 } |
|
232 |
|
233 // ---------------------------------------------------- |
|
234 // CBTUIMainContainer::SettingChangedL |
|
235 // ---------------------------------------------------- |
|
236 // |
|
237 void CBTUIMainContainer::SettingChanged( TBTMainListItemIndexes /* aListItem */ ) |
|
238 { |
|
239 TRACE_FUNC_ENTRY |
|
240 |
|
241 iBtMainListBox->DrawDeferred(); |
|
242 } |
|
243 |
|
244 #ifdef __SERIES60_HELP |
|
245 |
|
246 // --------------------------------------------------------- |
|
247 // From CCoeControl |
|
248 // CBTUIMainContainer::GetHelpContext |
|
249 // --------------------------------------------------------- |
|
250 // |
|
251 void CBTUIMainContainer::GetHelpContext(TCoeHelpContext& aContext) const |
|
252 { |
|
253 TRACE_FUNC_ENTRY |
|
254 |
|
255 aContext.iMajor = KBtuiUid3; |
|
256 aContext.iContext = KBT_HLP_MAIN; |
|
257 } |
|
258 |
|
259 #else |
|
260 |
|
261 // --------------------------------------------------------- |
|
262 // From CCoeControl |
|
263 // CBTUIMainContainer::GetHelpContext |
|
264 // --------------------------------------------------------- |
|
265 // |
|
266 void CBTUIMainContainer::GetHelpContext(TCoeHelpContext& /*aContext*/) const |
|
267 { |
|
268 TRACE_FUNC_ENTRY |
|
269 } |
|
270 |
|
271 #endif |
|
272 |
|
273 // --------------------------------------------------------- |
|
274 // From CCoeControl |
|
275 // CBTUIMainContainer::HandleResourceChange |
|
276 // --------------------------------------------------------- |
|
277 // |
|
278 void CBTUIMainContainer::HandleResourceChange( TInt aType ) |
|
279 { |
|
280 TRACE_FUNC_ENTRY |
|
281 //Pass the event to base class, so whenever resource changing happened, |
|
282 //this control will be considered to be re-drawed by base class, therefore |
|
283 //no specific DrawNow() function call is needed here. |
|
284 CCoeControl::HandleResourceChange(aType); |
|
285 |
|
286 //Handle change in layout orientation |
|
287 //aType == KAknsMessageSkinChange is handled by base class. |
|
288 if (aType == KEikDynamicLayoutVariantSwitch) |
|
289 { |
|
290 //"TRect rect = iAvkonAppUi->ClientRect();" |
|
291 // The line above provides to big rectangle in the bottom causing cba's overdrawn by by blank area. |
|
292 // Correct way to do this is below. |
|
293 TRect mainPaneRect; |
|
294 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect); |
|
295 SetRect(mainPaneRect); |
|
296 } |
|
297 } |
|
298 |
|
299 // --------------------------------------------------------- |
|
300 // From CCoeControl |
|
301 // CBTUIMainContainer::FocusChanged |
|
302 // --------------------------------------------------------- |
|
303 // |
|
304 void CBTUIMainContainer::FocusChanged(TDrawNow /*aDrawNow*/) |
|
305 { |
|
306 TRACE_FUNC_ENTRY |
|
307 if( iBtMainListBox) |
|
308 { |
|
309 iBtMainListBox->SetFocus( IsFocused() ); |
|
310 } |
|
311 } |
|
312 |
|
313 |
|
314 // ******************************************* |
|
315 // Nested class function implemenations: |
|
316 // ******************************************* |
|
317 |
|
318 // ---------------------------------------------------- |
|
319 // CBTUIMainContainer::TMainListItemArray::TMainListItemArray |
|
320 // Initialize friend class |
|
321 // ---------------------------------------------------- |
|
322 CBTUIMainContainer::TMainListItemArray::TMainListItemArray( CDesCArray* aBtAllItemsArray, |
|
323 CBTUIMainView* aMainView, CBTEngSettings* aBtEngSettings) |
|
324 |
|
325 : iArray( *aBtAllItemsArray ), // Store references |
|
326 iMainView( aMainView ), |
|
327 iBtEngSettingsRef( aBtEngSettings ) |
|
328 |
|
329 { |
|
330 TRACE_FUNC_ENTRY |
|
331 } |
|
332 |
|
333 // ---------------------------------------------------- |
|
334 // CBTUIMainContainer::TMainListItemArray::MdcaCount() |
|
335 // ---------------------------------------------------- |
|
336 // |
|
337 TInt CBTUIMainContainer::TMainListItemArray::MdcaCount() const |
|
338 { |
|
339 TRACE_FUNC_ENTRY |
|
340 return KNumberOfMainViewItems; |
|
341 } |
|
342 |
|
343 // ---------------------------------------------------- |
|
344 // CBTUIMainContainer::TMainListItemArray::MdcaPointL |
|
345 // Main view listbox item formatter: |
|
346 // Returns the current format string depending value |
|
347 // of the item concerned. |
|
348 // ---------------------------------------------------- |
|
349 // |
|
350 TPtrC CBTUIMainContainer::TMainListItemArray::MdcaPoint( TInt aIndex ) const |
|
351 { |
|
352 TRACE_FUNC_ENTRY |
|
353 _LIT(KBTUIEmptyFormatString, " \t \t\t "); // Empty format string if illegal indexing |
|
354 TPtrC chosen; |
|
355 |
|
356 switch ( aIndex ) |
|
357 { |
|
358 case EBTMainListItemPowerMode: |
|
359 { |
|
360 TBTPowerStateValue powerState; |
|
361 iBtEngSettingsRef->GetPowerState(powerState); |
|
362 if( powerState==EBTPowerOn ) |
|
363 chosen.Set( iArray.MdcaPoint( EBTUISettModulePowerOn )); |
|
364 else |
|
365 chosen.Set( iArray.MdcaPoint( EBTUISettModulePowerOff )); |
|
366 break; |
|
367 } |
|
368 |
|
369 case EBTMainListItemVisibilityMode: |
|
370 { |
|
371 TBTVisibilityMode mode; |
|
372 iBtEngSettingsRef->GetVisibilityMode(mode); |
|
373 |
|
374 switch(mode) |
|
375 { |
|
376 case EBTVisibilityModeGeneral: |
|
377 chosen.Set( iArray.MdcaPoint( EBTUISettVisibilityModeGeneral )); |
|
378 break; |
|
379 |
|
380 case EBTVisibilityModeHidden: |
|
381 chosen.Set( iArray.MdcaPoint( EBTUISettVisibilityModeHidden )); |
|
382 break; |
|
383 |
|
384 case EBTVisibilityModeTemporary: |
|
385 chosen.Set( iArray.MdcaPoint( EBTUISettVisibilityModeTemp )); |
|
386 break; |
|
387 |
|
388 default: |
|
389 break; |
|
390 } |
|
391 break; |
|
392 } |
|
393 |
|
394 case EBTMainListItemNameSetting: |
|
395 { |
|
396 TDes &buf = MUTABLE_CAST(TBuf<KBTUIMaxFormattedNameLength>&,iItemText); |
|
397 buf.Zero(); |
|
398 buf.Append( iArray.MdcaPoint( EBTUISettBTNameHeader ) ); |
|
399 buf.Append( *iMainView->GetBTLocalName() ); |
|
400 chosen.Set( iItemText ); |
|
401 break; |
|
402 } |
|
403 |
|
404 // For Bluetooth SIM Access Profile feature |
|
405 case EBTMainListItemSapMode: |
|
406 { |
|
407 BluetoothFeatures::TEnterpriseEnablementMode mode = BluetoothFeatures::EEnabled; |
|
408 TRAPD(err, mode = BluetoothFeatures::EnterpriseEnablementL()); |
|
409 if ( err == KErrNone ) |
|
410 { |
|
411 if ( mode == BluetoothFeatures::EDataProfilesDisabled ) |
|
412 { |
|
413 chosen.Set( iArray.MdcaPoint( EBTUISettSapDisabled )); |
|
414 break; |
|
415 } |
|
416 } |
|
417 |
|
418 TInt sapStatus; |
|
419 TRAP_IGNORE(GetSapStatusL(sapStatus);); |
|
420 |
|
421 if(sapStatus==EBTSapEnabled) |
|
422 { |
|
423 chosen.Set( iArray.MdcaPoint( EBTUISettSapEnabled )); |
|
424 } |
|
425 else |
|
426 { |
|
427 chosen.Set( iArray.MdcaPoint( EBTUISettSapDisabled )); |
|
428 } |
|
429 |
|
430 TInt sapMode = KErrNone; |
|
431 TRAP_IGNORE(sapMode = iMainView->GetSapStatusL()); |
|
432 |
|
433 |
|
434 if(sapMode==EBTSapEnabled) |
|
435 { |
|
436 if ( sapMode ) |
|
437 { |
|
438 chosen.Set( iArray.MdcaPoint( EBTUISettSapEnabled )); |
|
439 } |
|
440 else |
|
441 { |
|
442 chosen.Set( iArray.MdcaPoint( EBTUISettSapDisabled )); |
|
443 } |
|
444 } |
|
445 |
|
446 break; |
|
447 } |
|
448 default: |
|
449 chosen.Set( KBTUIEmptyFormatString ); |
|
450 break; |
|
451 } |
|
452 |
|
453 return chosen; |
|
454 } |
|
455 |
|
456 // ---------------------------------------------------------------------- |
|
457 // CBTUIMainContainer::TMainListItemArray::GetSapStatusL(TInt& aStatus) |
|
458 // ---------------------------------------------------------------------- |
|
459 // |
|
460 void CBTUIMainContainer::TMainListItemArray::GetSapStatusL( TInt& aStatus ) |
|
461 { |
|
462 CRepository* repository = CRepository::NewL(KCRUidBTEngPrivateSettings); |
|
463 CleanupStack::PushL(repository); |
|
464 repository->Get(KBTSapEnabled, aStatus); |
|
465 CleanupStack::PopAndDestroy(repository); |
|
466 } |