|
1 /* |
|
2 * Copyright (c) 2010 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 // System includes |
|
20 |
|
21 #include <HbGlobal> |
|
22 #include <HbDataFormModelItem> |
|
23 #include <HbLineEdit> |
|
24 #include <HbValidator> |
|
25 #include <HbMessageBox> |
|
26 #include <QStringList> |
|
27 #include <cpsettingformitemdata.h> |
|
28 |
|
29 // User includes |
|
30 |
|
31 #include "cpwlansettingsgroupitemdata.h" |
|
32 #include "wlansettings.h" |
|
33 |
|
34 #include "OstTraceDefinitions.h" |
|
35 #ifdef OST_TRACE_COMPILER_IN_USE |
|
36 #include "cpwlansettingsgroupitemdataTraces.h" |
|
37 #endif |
|
38 |
|
39 /*! |
|
40 \class CpWlanSettingsGroupItemData |
|
41 \brief CpWlanSettingsGroupItemData class creates all widgets required for Manage |
|
42 WLAN Settings. |
|
43 */ |
|
44 |
|
45 // External function prototypes |
|
46 |
|
47 // Local constants |
|
48 /** Maximum Value for Scan Interval. */ |
|
49 const int KMaximumScanInterval = 30; |
|
50 /** Minimum Value for Scan Interval. */ |
|
51 const int KMinimumScanInterval = 0; |
|
52 /** To Enable the setting of a widget propery. */ |
|
53 const int KEnableOption = 1; |
|
54 /** Maximum widgets allowed for this Item Data. */ |
|
55 const int KMaxWidgets = 4; |
|
56 /** Index of Slider widget for Scan Interval. */ |
|
57 const int KSliderIndex = 2; |
|
58 |
|
59 // ======== MEMBER FUNCTIONS ======== |
|
60 |
|
61 /*! |
|
62 Constructor. |
|
63 */ |
|
64 |
|
65 CpWlanSettingsGroupItemData::CpWlanSettingsGroupItemData( |
|
66 CpItemDataHelper &itemDataHelper) : |
|
67 CpSettingFormItemData(HbDataFormModelItem::GroupItem, hbTrId( |
|
68 "txt_occ_subhead_wlan_settings")), |
|
69 mItemDataHelper(itemDataHelper) |
|
70 { |
|
71 OstTraceFunctionEntry1(CPWLANSETTINGSGROUPITEMDATA_CPWLANSETTINGSGROUPITEMDATA_ENTRY, this); |
|
72 |
|
73 initialise(); |
|
74 |
|
75 createWlanSettingItems(); |
|
76 |
|
77 OstTraceFunctionExit1(CPWLANSETTINGSGROUPITEMDATA_CPWLANSETTINGSGROUPITEMDATA_EXIT, this); |
|
78 } |
|
79 |
|
80 /*! |
|
81 Destructor. |
|
82 */ |
|
83 |
|
84 CpWlanSettingsGroupItemData::~CpWlanSettingsGroupItemData() |
|
85 { |
|
86 OstTraceFunctionEntry1(DUP1_CPWLANSETTINGSGROUPITEMDATA_CPWLANSETTINGSGROUPITEMDATA_ENTRY, this); |
|
87 OstTraceFunctionExit1(DUP1_CPWLANSETTINGSGROUPITEMDATA_CPWLANSETTINGSGROUPITEMDATA_EXIT, this); |
|
88 } |
|
89 |
|
90 /*! |
|
91 Initialises the member variables and reads the values of WLAN Settings. |
|
92 */ |
|
93 |
|
94 void CpWlanSettingsGroupItemData::initialise() |
|
95 { |
|
96 OstTraceFunctionEntry1(CPWLANSETTINGSGROUPITEMDATA_INITIALISE_ENTRY, this); |
|
97 |
|
98 mWlanSettings.reset(new WlanSettings); |
|
99 |
|
100 //Error needs to be handled. |
|
101 int error = mWlanSettings->init(); |
|
102 |
|
103 //Error needs to be handled. |
|
104 error = mWlanSettings->loadSettings(); |
|
105 |
|
106 mUserDefinedItem = NULL; |
|
107 |
|
108 OstTraceFunctionExit1(CPWLANSETTINGSGROUPITEMDATA_INITIALISE_EXIT, this); |
|
109 } |
|
110 |
|
111 /*! |
|
112 Creates the Widgets for displaying WLAN Settings. |
|
113 */ |
|
114 |
|
115 void CpWlanSettingsGroupItemData::createWlanSettingItems() |
|
116 { |
|
117 OstTraceFunctionEntry1(CPWLANSETTINGSGROUPITEMDATA_CREATEWLANSETTINITEMS_ENTRY, this); |
|
118 |
|
119 mJoinWlanItem = new CpSettingFormItemData( |
|
120 HbDataFormModelItem::ComboBoxItem, hbTrId( |
|
121 "txt_occ_setlabel_join_wlan_networks"), this); |
|
122 |
|
123 QStringList joinWlanItems; |
|
124 |
|
125 joinWlanItems.append(hbTrId( |
|
126 "txt_occ_setlabel_join_wlan_networks_val_known")); |
|
127 |
|
128 joinWlanItems.append(hbTrId( |
|
129 "txt_occ_setlabel_join_wlan_networks_val_manual")); |
|
130 |
|
131 mJoinWlanItem->setContentWidgetData("items", joinWlanItems); |
|
132 |
|
133 mItemDataHelper.addConnection(mJoinWlanItem, |
|
134 SIGNAL(currentIndexChanged (int)), this, |
|
135 SLOT(joinWlanItemChanged (int))); |
|
136 |
|
137 mJoinWlanItem->setContentWidgetData("currentIndex", |
|
138 mWlanSettings->joinWlanMode()); |
|
139 |
|
140 this->appendChild(mJoinWlanItem); |
|
141 |
|
142 mScanNetworkItem = new CpSettingFormItemData( |
|
143 HbDataFormModelItem::ComboBoxItem, hbTrId( |
|
144 "txt_occ_setlabel_scan_for_networks"), this); |
|
145 |
|
146 QStringList scanNetworkItems; |
|
147 |
|
148 scanNetworkItems.append(hbTrId( |
|
149 "txt_occ_setlabel_scan_for_networks_val_automatic")); |
|
150 |
|
151 scanNetworkItems.append(hbTrId( |
|
152 "txt_occ_setlabel_scan_for_networks_val_userdefine")); |
|
153 |
|
154 mScanNetworkItem->setContentWidgetData("items", scanNetworkItems); |
|
155 |
|
156 mItemDataHelper.addConnection(mScanNetworkItem, |
|
157 SIGNAL(currentIndexChanged (const QString &)), this, |
|
158 SLOT(scanItemChanged (const QString &))); |
|
159 |
|
160 this->appendChild(mScanNetworkItem); |
|
161 |
|
162 WlanSettings::ScanNetworkType scanType = mWlanSettings->scanNetworkType(); |
|
163 |
|
164 mScanNetworkItem->setContentWidgetData("currentIndex", scanType); |
|
165 |
|
166 if (scanType == WlanSettings::EScanNetworkUserDefined) { |
|
167 createScanIntervalItem(); |
|
168 this->appendChild(mUserDefinedItem); |
|
169 } |
|
170 |
|
171 mPowerSavingItem = new CpSettingFormItemData( |
|
172 HbDataFormModelItem::ComboBoxItem, hbTrId( |
|
173 "txt_occ_setlabel_power_saving"), this); |
|
174 |
|
175 QStringList powerSavingItems; |
|
176 |
|
177 powerSavingItems.append(hbTrId( |
|
178 "txt_occ_setlabel_power_saving_val_disabled")); |
|
179 |
|
180 powerSavingItems.append(hbTrId( |
|
181 "txt_occ_setlabel_power_saving_val_enabled")); |
|
182 |
|
183 mPowerSavingItem->setContentWidgetData("items", powerSavingItems); |
|
184 |
|
185 mPowerSavingItem->setContentWidgetData("currentIndex", |
|
186 mWlanSettings->isPowerSavingEnabled()); |
|
187 |
|
188 mItemDataHelper.addConnection(mPowerSavingItem, |
|
189 SIGNAL(currentIndexChanged (int)), this, |
|
190 SLOT(powerSavingItemChanged (int))); |
|
191 |
|
192 this->appendChild(mPowerSavingItem); |
|
193 |
|
194 OstTraceFunctionExit1(CPWLANSETTINGSGROUPITEMDATA_CREATEWLANSETTINITEMS_EXIT, this); |
|
195 } |
|
196 |
|
197 /*! |
|
198 Creates the slider widget for displaying scan interval value. |
|
199 */ |
|
200 |
|
201 void CpWlanSettingsGroupItemData::createScanIntervalItem() |
|
202 { |
|
203 OstTraceFunctionEntry1(CPWLANSETTINGSGROUPITEMDATA_CREATESCANINTERVALITEM_ENTRY, this); |
|
204 |
|
205 mUserDefinedItem = new CpSettingFormItemData( |
|
206 HbDataFormModelItem::SliderItem, hbTrId( |
|
207 "txt_occ_setlabel_scan_interval_minutes"), this); |
|
208 |
|
209 mUserDefinedItem->setContentWidgetData("maximum", KMaximumScanInterval); |
|
210 mUserDefinedItem->setContentWidgetData("minimum", KMinimumScanInterval); |
|
211 mUserDefinedItem->setContentWidgetData("toolTipVisible", KEnableOption); |
|
212 mUserDefinedItem->setContentWidgetData("tracking", KEnableOption); |
|
213 |
|
214 mItemDataHelper.addConnection(mUserDefinedItem, |
|
215 SIGNAL(valueChanged (int)), this, SLOT(scanValueChanged (int))); |
|
216 |
|
217 mItemDataHelper.addConnection(mUserDefinedItem, |
|
218 SIGNAL(sliderReleased ()), this, SLOT(scanSliderReleased ())); |
|
219 |
|
220 mItemDataHelper.addConnection(mUserDefinedItem, SIGNAL(sliderPressed ()), |
|
221 this, SLOT(scanSliderPressed ())); |
|
222 |
|
223 mScanInterval = mWlanSettings->scanInterval(); |
|
224 |
|
225 mUserDefinedItem->setContentWidgetData("value", mScanInterval); |
|
226 |
|
227 OstTraceFunctionExit1(CPWLANSETTINGSGROUPITEMDATA_CREATESCANINTERVALITEM_EXIT, this); |
|
228 } |
|
229 |
|
230 /*! |
|
231 Slot for handling pressed singal of scan interval slider widget. |
|
232 */ |
|
233 |
|
234 void CpWlanSettingsGroupItemData::scanSliderPressed() |
|
235 { |
|
236 OstTraceFunctionEntry1(CPWLANSETTINGSGROUPITEMDATA_SCANSLIDERPRESSED_ENTRY, this); |
|
237 |
|
238 mUserDefinedItem->setContentWidgetData("text",QString("%1").arg(mScanInterval)); |
|
239 |
|
240 OstTraceFunctionExit1(CPWLANSETTINGSGROUPITEMDATA_SCANSLIDERPRESSED_EXIT, this); |
|
241 } |
|
242 |
|
243 /*! |
|
244 Slot for handling value changed singal of scan interval slider widget. |
|
245 */ |
|
246 |
|
247 void CpWlanSettingsGroupItemData::scanValueChanged(int value) |
|
248 { |
|
249 OstTraceFunctionEntry1(CPWLANSETTINGSGROUPITEMDATA_SCANVALUECHANGED_ENTRY, this); |
|
250 |
|
251 mUserDefinedItem->setContentWidgetData("text",QString("%1").arg(value)); |
|
252 mScanInterval = value; |
|
253 |
|
254 OstTraceFunctionExit1(CPWLANSETTINGSGROUPITEMDATA_SCANVALUECHANGED_EXIT, this); |
|
255 } |
|
256 |
|
257 /*! |
|
258 Slot for handling Released singal of scan interval slider widget. |
|
259 Current value will be commited to database. |
|
260 */ |
|
261 |
|
262 void CpWlanSettingsGroupItemData::scanSliderReleased() |
|
263 { |
|
264 OstTraceFunctionEntry1(CPWLANSETTINGSGROUPITEMDATA_SCANSLIDERRELEASED_ENTRY, this); |
|
265 |
|
266 mWlanSettings->setWlanScanInterval(mScanInterval); |
|
267 |
|
268 OstTraceFunctionExit1(CPWLANSETTINGSGROUPITEMDATA_SCANSLIDERRELEASED_EXIT, this); |
|
269 } |
|
270 |
|
271 /*! |
|
272 Slot for handling item changed singal of Scan for network combo box widget. |
|
273 */ |
|
274 |
|
275 void CpWlanSettingsGroupItemData::scanItemChanged(const QString &text) |
|
276 { |
|
277 OstTraceFunctionEntry1(CPWLANSETTINGSGROUPITEMDATA_SCANITEMCHANGED_ENTRY, this); |
|
278 |
|
279 if (hbTrId("txt_occ_setlabel_scan_for_networks_val_userdefine") == text) { |
|
280 //In case of PSM mode for device user-defined value is not |
|
281 //allowed,make it automatic forcefully. |
|
282 if (mWlanSettings->isPsmEnabled()) { |
|
283 //Need to check for dimming of the combobox option. |
|
284 mScanNetworkItem->setContentWidgetData("currentIndex", |
|
285 WlanSettings::EScanNetworkAuto); |
|
286 } |
|
287 else { |
|
288 //Add Scan Interval Slider, if it was not added. |
|
289 if (this->childCount() < KMaxWidgets) { |
|
290 createScanIntervalItem(); |
|
291 this->insertChild(KSliderIndex,mUserDefinedItem); |
|
292 mWlanSettings->setWlanScanInterval(mWlanSettings->scanInterval()); |
|
293 } |
|
294 } |
|
295 } |
|
296 else { |
|
297 //Remove Scan Interval slider, if user selects automatic option |
|
298 //for Scan network setting and if slider was added earlier. |
|
299 if (KMaxWidgets == this->childCount()) { |
|
300 this->removeChild(KSliderIndex); |
|
301 mUserDefinedItem = NULL; //removeChild() will delete the item. |
|
302 mWlanSettings->setWlanScanInterval(KWlanSettingsScanNetworkAuto); |
|
303 } |
|
304 } |
|
305 |
|
306 OstTraceFunctionExit1(CPWLANSETTINGSGROUPITEMDATA_SCANITEMCHANGED_EXIT, this); |
|
307 } |
|
308 |
|
309 /*! |
|
310 Slot for handling item changed singal of Power saving combo box widget. |
|
311 */ |
|
312 |
|
313 void CpWlanSettingsGroupItemData::powerSavingItemChanged(int index) |
|
314 { |
|
315 OstTraceFunctionEntry1(CPWLANSETTINGSGROUPITEMDATA_POWERSAVINGITEMCHANGED_ENTRY, this); |
|
316 |
|
317 mWlanSettings->setWlanPowerSaving(index); |
|
318 |
|
319 OstTraceFunctionExit1(CPWLANSETTINGSGROUPITEMDATA_POWERSAVINGITEMCHANGED_EXIT, this); |
|
320 } |
|
321 |
|
322 /*! |
|
323 Slot for handling item changed singal of Join WLAN networks combo box widget. |
|
324 */ |
|
325 |
|
326 void CpWlanSettingsGroupItemData::joinWlanItemChanged(int index) |
|
327 { |
|
328 OstTraceFunctionEntry1(CPWLANSETTINGSGROUPITEMDATA_JOINWLANITEMCHANGED_ENTRY, this); |
|
329 |
|
330 mWlanSettings->setJoinWlanMode(index); |
|
331 |
|
332 OstTraceFunctionExit1(CPWLANSETTINGSGROUPITEMDATA_JOINWLANITEMCHANGED_EXIT, this); |
|
333 } |