|
1 /* |
|
2 * Copyright (c) 2002 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 the License "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: CAknSettingItemList compliant setting item class for Advanced bandwidth settings.* |
|
15 */ |
|
16 |
|
17 |
|
18 // Version : %version: 4 % |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 // INCLUDE FILES |
|
24 #include <AknQueryDialog.h> |
|
25 #include <aknradiobuttonsettingpage.h> |
|
26 #include <eikenv.h> |
|
27 #include <MediaSettings.rsg> |
|
28 #include <StringLoader.h> |
|
29 #include <AknUtils.h> |
|
30 |
|
31 #include "MPSettingsAdvancedBwSettingItem.h" |
|
32 #include "mpxlog.h" |
|
33 |
|
34 |
|
35 // ============================ MEMBER FUNCTIONS =============================== |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CMPSettingsAdvancedBwSettingItem::CMPSettingsAdvancedBwSettingItem |
|
39 // C++ default constructor can NOT contain any code, that |
|
40 // might leave. |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 CMPSettingsAdvancedBwSettingItem::CMPSettingsAdvancedBwSettingItem( |
|
44 TInt aIdentifier, |
|
45 RArray<TInt>& aValueArray, |
|
46 TInt& aValue, |
|
47 TInt& aListValue, |
|
48 TInt aQueryRes) : |
|
49 CAknEnumeratedTextPopupSettingItem(aIdentifier, aListValue), |
|
50 iValueArray(aValueArray), |
|
51 iValue(aValue), |
|
52 iQueryRes(aQueryRes), |
|
53 iEnv(CEikonEnv::Static()) |
|
54 { |
|
55 MPX_FUNC("#MS# CMPSettingsAdvancedBwSettingItem::CMPSettingsAdvancedBwSettingItem()"); |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CMPSettingsAdvancedBwSettingItem::~CMPSettingsAdvancedBwSettingItem |
|
60 // Destructor |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 CMPSettingsAdvancedBwSettingItem::~CMPSettingsAdvancedBwSettingItem() |
|
64 { |
|
65 MPX_FUNC("#MS# CMPSettingsAdvancedBwSettingItem::~CMPSettingsAdvancedBwSettingItem()"); |
|
66 if (iSettingText) |
|
67 { |
|
68 delete iSettingText; |
|
69 } |
|
70 |
|
71 if (iEnumTextArray) |
|
72 { |
|
73 iEnumTextArray->ResetAndDestroy(); |
|
74 delete iEnumTextArray; |
|
75 } |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CMPSettingsAdvancedBwSettingItem::SettingTextL |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 const TDesC& CMPSettingsAdvancedBwSettingItem::SettingTextL() |
|
83 { |
|
84 MPX_FUNC("#MS# CMPSettingsAdvancedBwSettingItem::SettingTextL()"); |
|
85 delete iSettingText; |
|
86 iSettingText = NULL; |
|
87 |
|
88 iSettingText = CreateValueTextL(iValue); |
|
89 |
|
90 return *iSettingText; |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CMPSettingsAdvancedBwSettingItem::EditItemL |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 void CMPSettingsAdvancedBwSettingItem::EditItemL(TBool aCalledFromMenu) |
|
98 { |
|
99 MPX_DEBUG2(_L("#MS# CMPSettingsAdvancedBwSettingItem::EditItemL(%d)"),aCalledFromMenu); |
|
100 CAknEnumeratedTextPopupSettingItem::EditItemL(aCalledFromMenu); |
|
101 |
|
102 TInt count = iValueArray.Count(); |
|
103 |
|
104 for (TInt index = 0; index < count; ++index) |
|
105 { |
|
106 if (iValueArray[index] == iValue) |
|
107 { |
|
108 SetInternalValue(index); |
|
109 SetSelectedIndex(IndexFromValue(index)); |
|
110 break; |
|
111 } |
|
112 } |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CMPSettingsAdvancedBwSettingItem::CompleteConstructionL |
|
117 // ----------------------------------------------------------------------------- |
|
118 // |
|
119 void CMPSettingsAdvancedBwSettingItem::CompleteConstructionL() |
|
120 { |
|
121 MPX_FUNC("#MS# CMPSettingsAdvancedBwSettingItem::CompleteConstructionL()"); |
|
122 __ASSERT_DEBUG(!iEnumTextArray, User::Leave(KErrAlreadyExists)); |
|
123 |
|
124 TInt count = iValueArray.Count(); |
|
125 iEnumTextArray = new(ELeave) CArrayPtrFlat<CAknEnumeratedText>(count + 1); |
|
126 CAknEnumeratedText* enumText = NULL; |
|
127 HBufC* text = NULL; |
|
128 |
|
129 for (TInt index = 0; index < count; ++index) |
|
130 { |
|
131 text = CreateValueTextL(iValueArray[index]); |
|
132 CleanupStack::PushL(text); |
|
133 enumText = new(ELeave) CAknEnumeratedText(index, text); |
|
134 CleanupStack::Pop(); // text |
|
135 text = NULL; |
|
136 CleanupStack::PushL(enumText); |
|
137 iEnumTextArray->AppendL(enumText); |
|
138 CleanupStack::Pop(); //enumText |
|
139 enumText = NULL; |
|
140 } |
|
141 |
|
142 // Append "User defined" to the end of the array |
|
143 text = StringLoader::LoadLC(R_MPSETT_USER_DEFINED); |
|
144 enumText = new(ELeave) CAknEnumeratedText(count, text); |
|
145 CleanupStack::Pop(); // text |
|
146 CleanupStack::PushL(enumText); |
|
147 iEnumTextArray->AppendL(enumText); |
|
148 CleanupStack::Pop(); //enumText |
|
149 |
|
150 // poppedTextArray should be left empty! Magic number: array granularity |
|
151 CArrayPtr<HBufC>* poppedTextArray = new(ELeave) CArrayPtrFlat<HBufC>(1); |
|
152 // The ownership of both arrays is transferred to the base class. |
|
153 SetEnumeratedTextArrays(iEnumTextArray, poppedTextArray); |
|
154 iEnumTextArray = NULL; |
|
155 poppedTextArray = NULL; |
|
156 |
|
157 HandleTextArrayUpdateL(); |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CMPSettingsAdvancedBwSettingItem::HandleSettingPageEventL |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 void CMPSettingsAdvancedBwSettingItem::HandleSettingPageEventL(CAknSettingPage* aSettingPage, |
|
165 TAknSettingPageEvent aEventType) |
|
166 { |
|
167 MPX_FUNC("#MS# CMPSettingsAdvancedBwSettingItem::HandleSettingPageEventL()"); |
|
168 if (aEventType != EEventSettingCancelled) |
|
169 { |
|
170 CEikListBox* listbox = static_cast<CAknRadioButtonSettingPage*>(aSettingPage)->ListBoxControl(); |
|
171 |
|
172 TInt current = listbox->CurrentItemIndex(); |
|
173 TInt count = listbox->Model()->NumberOfItems(); |
|
174 |
|
175 if (current == count - 1) |
|
176 { |
|
177 ShowAdvancedBwQueryL(); |
|
178 } |
|
179 else |
|
180 { |
|
181 iValue = iValueArray[current]; |
|
182 } |
|
183 } |
|
184 |
|
185 CAknSettingItem::HandleSettingPageEventL(aSettingPage, aEventType); |
|
186 } |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // CMPSettingsAdvancedBwSettingItem::ShowAdvancedBwQueryL |
|
190 // ----------------------------------------------------------------------------- |
|
191 // |
|
192 void CMPSettingsAdvancedBwSettingItem::ShowAdvancedBwQueryL() |
|
193 { |
|
194 MPX_FUNC("#MS# CMPSettingsAdvancedBwSettingItem::ShowAdvancedBwQueryL()"); |
|
195 TReal value = static_cast<TReal>(iValue) / 1000; |
|
196 CAknFloatingPointQueryDialog* dlg = new (ELeave) CAknFloatingPointQueryDialog(value); |
|
197 if (dlg->ExecuteLD(iQueryRes)) |
|
198 { |
|
199 iValue = static_cast<TInt>(value * 1000); |
|
200 } |
|
201 } |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CMPSettingsAdvancedBwSettingItem::CreateValueTextL |
|
205 // ----------------------------------------------------------------------------- |
|
206 // |
|
207 HBufC* CMPSettingsAdvancedBwSettingItem::CreateValueTextL(TInt aValue) |
|
208 { |
|
209 MPX_DEBUG2(_L("#MS# CMPSettingsAdvancedBwSettingItem::CreateValueTextL(%d)"),aValue); |
|
210 TRealFormat format(10, 2); |
|
211 TBuf<10> valueString; |
|
212 HBufC* convert; |
|
213 TReal value = static_cast<TReal>(aValue) / 1000; |
|
214 |
|
215 if (value >= 1000) |
|
216 { |
|
217 User::LeaveIfError(valueString.Num(value/1000, format)); |
|
218 convert = StringLoader::LoadL(R_MPSETT_ADVANCED_BW_VALUE_MBIT, valueString); |
|
219 } |
|
220 else |
|
221 { |
|
222 User::LeaveIfError(valueString.Num(value, format)); |
|
223 convert = StringLoader::LoadL(R_MPSETT_ADVANCED_BW_VALUE, valueString); |
|
224 } |
|
225 |
|
226 TPtr tmp( convert->Des() ); |
|
227 AknTextUtils::LanguageSpecificNumberConversion(tmp); |
|
228 MPX_DEBUG2(_L("#MS# CMPSettingsAdvancedBwSettingItem::CreateValueTextL() ret (%S)"),&tmp); |
|
229 return convert; |
|
230 |
|
231 } |
|
232 |
|
233 // End of File |