|
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 * WLAN Wizard Page: Network mode Selection. |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <HbDocumentLoader> |
|
20 #include <HbWidget> |
|
21 #include <HbRadioButtonList> |
|
22 #include <HbMainWindow> |
|
23 #include <HbLabel> |
|
24 #include <cmmanagerdefines_shim.h> |
|
25 |
|
26 // User includes |
|
27 #include "wlanwizard_p.h" |
|
28 #include "wlanwizard.h" |
|
29 #include "wlanwizardpagenetworkmode.h" |
|
30 #include "wlanwizardscanlist.h" |
|
31 #include "OstTraceDefinitions.h" |
|
32 #ifdef OST_TRACE_COMPILER_IN_USE |
|
33 #include "wlanwizardpagenetworkmodeTraces.h" |
|
34 #endif |
|
35 |
|
36 // Local constants |
|
37 |
|
38 /*! |
|
39 * Constructor method for the network mode view object |
|
40 * @param parent [in] pointer to parent object. |
|
41 */ |
|
42 WlanWizardPageNetworkMode::WlanWizardPageNetworkMode( |
|
43 WlanWizardPrivate* parent) : |
|
44 WlanWizardPageInternal(parent), |
|
45 mWidget(NULL), |
|
46 mList(NULL), |
|
47 mLabel(NULL), |
|
48 mLoader(NULL), |
|
49 mValid(false) |
|
50 { |
|
51 OstTraceFunctionEntry0( WLANWIZARDPAGENETWORKMODE_WLANWIZARDPAGENETWORKMODE_ENTRY ); |
|
52 OstTraceFunctionExit0( WLANWIZARDPAGENETWORKMODE_WLANWIZARDPAGENETWORKMODE_EXIT ); |
|
53 } |
|
54 |
|
55 /*! |
|
56 * Destructor. Loader widget is deleted. |
|
57 * All document widgets are deleted by wlanwizard_p destructor. |
|
58 */ |
|
59 WlanWizardPageNetworkMode::~WlanWizardPageNetworkMode() |
|
60 { |
|
61 OstTraceFunctionEntry0( DUP1_WLANWIZARDPAGENETWORKMODE_WLANWIZARDPAGENETWORKMODE_ENTRY ); |
|
62 delete mLoader; |
|
63 OstTraceFunctionExit0( DUP1_WLANWIZARDPAGENETWORKMODE_WLANWIZARDPAGENETWORKMODE_EXIT ); |
|
64 } |
|
65 |
|
66 /*! |
|
67 * Page initialization. If view is already loaded, does nothing. |
|
68 * Inherited from WlanWizardPage. |
|
69 */ |
|
70 HbWidget* WlanWizardPageNetworkMode::initializePage() |
|
71 { |
|
72 OstTraceFunctionEntry0( WLANWIZARDPAGENETWORKMODE_INITIALIZEPAGE_ENTRY ); |
|
73 OstTrace0( TRACE_NORMAL, WLANWIZARDPAGENETWORKMODE_INITIALIZEPAGE, |
|
74 "WlanWizardPageNetworkMode::initializePage" ); |
|
75 |
|
76 if (mWidget == NULL) { |
|
77 mLoader = new HbDocumentLoader(mWizard->mainWindow()); |
|
78 |
|
79 bool ok; |
|
80 |
|
81 mLoader->load(":/docml/occ_add_wlan_02_03.docml", &ok); |
|
82 Q_ASSERT(ok); |
|
83 |
|
84 loadDocmlSection(mWizard->mainWindow()->orientation()); |
|
85 |
|
86 mWidget = qobject_cast<HbWidget*> (mLoader->findWidget( |
|
87 "occ_add_wlan_02")); |
|
88 Q_ASSERT(mWidget != NULL); |
|
89 |
|
90 mList = qobject_cast<HbRadioButtonList*> (mLoader->findWidget("list")); |
|
91 Q_ASSERT(mList != NULL); |
|
92 |
|
93 mLabel = qobject_cast<HbLabel*> (mLoader->findWidget("dialog_6")); |
|
94 Q_ASSERT(mLabel != NULL); |
|
95 |
|
96 // Connect document loading to main window orientation changes. |
|
97 ok = connect(mWizard->mainWindow(), |
|
98 SIGNAL(orientationChanged(Qt::Orientation)), this, |
|
99 SLOT(loadDocmlSection(Qt::Orientation))); |
|
100 Q_ASSERT(ok); |
|
101 |
|
102 // Connect a function to a radio button selection. |
|
103 ok = connect(mList, SIGNAL(itemSelected(int)), this, |
|
104 SLOT(itemSelected())); |
|
105 Q_ASSERT(ok); |
|
106 |
|
107 mLabel->setPlainText(hbTrId( |
|
108 "txt_occ_dialog_select_network_mode_and_status")); |
|
109 } |
|
110 |
|
111 QStringList items; |
|
112 |
|
113 populateRadioButtonList(items); |
|
114 |
|
115 mList->setItems(items); |
|
116 |
|
117 OstTraceFunctionExit0( WLANWIZARDPAGENETWORKMODE_INITIALIZEPAGE_EXIT ); |
|
118 return mWidget; |
|
119 } |
|
120 |
|
121 /*! |
|
122 * Evaluates the network mode selection and sets the configuration in |
|
123 * the wlanwizard. |
|
124 * @param [out] removeFromStack always returns false. |
|
125 * @return WlanWizardPageSecurityMode page id. |
|
126 */ |
|
127 int WlanWizardPageNetworkMode::nextId(bool &removeFromStack) const |
|
128 { |
|
129 OstTraceFunctionEntry0( WLANWIZARDPAGENETWORKMODE_NEXTID_ENTRY ); |
|
130 removeFromStack = false; |
|
131 WlanNetworkSetting setting; |
|
132 int index = mList->selected(); |
|
133 int nextPage = WlanWizardPageInternal::PageNetworkSecurity; |
|
134 |
|
135 if (mWpsSupported.at(index)) { |
|
136 nextPage = WlanWizardPageInternal::PageWpsStart; |
|
137 } |
|
138 else { |
|
139 setting.mode = mNetworkModes.at(index); |
|
140 setting.hidden = mIsHidden.at(index); |
|
141 setting.wpsSupported = mWpsSupported.at(index); |
|
142 |
|
143 mWizard->setConfiguration( |
|
144 WlanWizardPrivate::ConfNetworkMode, |
|
145 setting.mode); |
|
146 |
|
147 mWizard->setConfiguration( |
|
148 WlanWizardPrivate::ConfWlanScanSSID, |
|
149 setting.hidden); |
|
150 |
|
151 mWizard->setConfiguration( |
|
152 WlanWizardPrivate::ConfWpsSupported, |
|
153 setting.wpsSupported); |
|
154 |
|
155 if (mWizard->configurationExists(WlanWizardPrivate::ConfAvailableNetworkOptions)) { |
|
156 nextPage = selectNextPage(setting); |
|
157 } |
|
158 } |
|
159 OstTraceFunctionExit0( WLANWIZARDPAGENETWORKMODE_NEXTID_EXIT ); |
|
160 return nextPage; |
|
161 } |
|
162 |
|
163 /*! |
|
164 * This method is overrides the default implementation from WlanWizardPage. |
|
165 * It indicates whether the Next-button should be enabled or not. |
|
166 * @return mValid, which is true if a radio button has been selected. |
|
167 */ |
|
168 bool WlanWizardPageNetworkMode::showPage() |
|
169 { |
|
170 OstTraceFunctionEntry0( WLANWIZARDPAGENETWORKMODE_SHOWPAGE_ENTRY ); |
|
171 OstTraceFunctionExit0( WLANWIZARDPAGENETWORKMODE_SHOWPAGE_EXIT ); |
|
172 return mValid; |
|
173 } |
|
174 |
|
175 /*! |
|
176 * This function is invoked when user selects a mode from the radio button list. |
|
177 * (HbRadioButtonList's itemSelected-signal) |
|
178 */ |
|
179 void WlanWizardPageNetworkMode::itemSelected() |
|
180 { |
|
181 OstTraceFunctionEntry0( WLANWIZARDPAGENETWORKMODE_ITEMSELECTED_ENTRY ); |
|
182 OstTrace0( TRACE_BORDER, WLANWIZARDPAGENETWORKMODE_ITEMSELECTED, |
|
183 "WlanWizardPageNetworkMode::itemSelected" ); |
|
184 |
|
185 mValid = true; |
|
186 mWizard->enableNextButton(mValid); |
|
187 OstTraceFunctionExit0( WLANWIZARDPAGENETWORKMODE_ITEMSELECTED_EXIT ); |
|
188 } |
|
189 |
|
190 /*! |
|
191 * Loads the document orientation information from occ_add_wlan_02_03.docml. |
|
192 * This is called each time phone orientation changes. |
|
193 * @param [in] orientation indicates whether the phone is in portrait or |
|
194 * landscape mode. |
|
195 */ |
|
196 void WlanWizardPageNetworkMode::loadDocmlSection(Qt::Orientation orientation) |
|
197 { |
|
198 OstTraceFunctionEntry0( WLANWIZARDPAGENETWORKMODE_LOADDOCMLSECTION_ENTRY ); |
|
199 OstTrace1( TRACE_NORMAL, WLANWIZARDPAGENETWORKMODE_LOADDOCML, |
|
200 "WlanWizardPageNetworkMode::loadDocml - Orientation;orientation=%x", |
|
201 ( TUint )( orientation ) ); |
|
202 |
|
203 WlanWizardPageInternal::loadDocmlSection( |
|
204 mLoader, |
|
205 orientation, |
|
206 ":/docml/occ_add_wlan_02_03.docml", |
|
207 "portrait_section", |
|
208 "landscape_section"); |
|
209 OstTraceFunctionExit0( WLANWIZARDPAGENETWORKMODE_LOADDOCMLSECTION_EXIT ); |
|
210 } |
|
211 |
|
212 /*! |
|
213 * A support function to map the radio button list to a generic network |
|
214 * mode list. This enables the changing of button order without it |
|
215 * affecting the entire class. |
|
216 * In case previous scan has revealed multiple results with the same ssid, only |
|
217 * available network mode options are shown in the radio button list. |
|
218 * @param [out] list is the list of captions used for the radio buttons. |
|
219 * @param [in] item is the caption to be added. |
|
220 * @param [in] mode is the network mode to be added. |
|
221 * @param [in] isHidden is the visibility status of the network. |
|
222 * @param [in] wpsSupported is the possibility for wps support. |
|
223 */ |
|
224 void WlanWizardPageNetworkMode::addToList( |
|
225 QStringList &list, |
|
226 const QString &item, |
|
227 int mode, |
|
228 bool isHidden, |
|
229 bool wpsSupported) |
|
230 { |
|
231 OstTraceFunctionEntry0( WLANWIZARDPAGENETWORKMODE_ADDTOLIST_ENTRY ); |
|
232 |
|
233 if (mWizard->configurationExists(WlanWizardHelper::ConfAvailableNetworkOptions)) { |
|
234 WlanWizardScanList networkOptions = mWizard->configuration( |
|
235 WlanWizardHelper::ConfAvailableNetworkOptions).value<WlanWizardScanList> (); |
|
236 |
|
237 QList<WlanNetworkSetting> modes = networkOptions.getNetModes(); |
|
238 |
|
239 for (int i = 0; i < modes.size(); i++) { |
|
240 if ( (modes[i].mode == mode |
|
241 && modes[i].hidden == isHidden |
|
242 && modes[i].wpsSupported == wpsSupported) |
|
243 || (modes[i].wpsSupported && wpsSupported) ) { |
|
244 list << item; |
|
245 mNetworkModes.append(mode); |
|
246 mIsHidden.append(isHidden); |
|
247 mWpsSupported.append(wpsSupported); |
|
248 } |
|
249 } |
|
250 } |
|
251 else { |
|
252 list << item; |
|
253 mNetworkModes.append(mode); |
|
254 mIsHidden.append(isHidden); |
|
255 // If there are no known network options, WPS is not allowed to be |
|
256 // selected. |
|
257 mWpsSupported.append(false); |
|
258 } |
|
259 OstTraceFunctionExit0( WLANWIZARDPAGENETWORKMODE_ADDTOLIST_EXIT ); |
|
260 } |
|
261 |
|
262 /*! |
|
263 * This function checks the sets up the radio button list for user input. |
|
264 * @param [out] list is the list of captions used for the radio buttons. |
|
265 */ |
|
266 void WlanWizardPageNetworkMode::populateRadioButtonList(QStringList &list) |
|
267 { |
|
268 OstTraceFunctionEntry0( WLANWIZARDPAGENETWORKMODE_POPULATERADIOBUTTONLIST_ENTRY ); |
|
269 list.clear(); |
|
270 mNetworkModes.clear(); |
|
271 mIsHidden.clear(); |
|
272 mWpsSupported.clear(); |
|
273 |
|
274 // A list is created. Since there is no practical way of knowing whether |
|
275 // the new contents are different from the previous contents (if there |
|
276 // even were any in the first place) the validity is always reset. |
|
277 mValid = false; |
|
278 |
|
279 addToList(list, hbTrId("txt_occ_dblist_val_infrastructure_public"), |
|
280 CMManagerShim::Infra, false, false); |
|
281 |
|
282 addToList(list, hbTrId("txt_occ_list_infrastructure_hidden"), |
|
283 CMManagerShim::Infra, true, false); |
|
284 |
|
285 addToList(list, hbTrId("txt_occ_list_adhoc_1"), CMManagerShim::Adhoc, |
|
286 false, false); |
|
287 |
|
288 if (mWizard->configurationExists(WlanWizardHelper::ConfAvailableNetworkOptions)) { |
|
289 // addToList with wpsSupported=true is only called, when there are available |
|
290 // scan result options. If no network options exist, the user can not get to |
|
291 // wps wizard from this view. Also, mode and isHidden are "don't care". |
|
292 addToList(list, hbTrId("txt_occ_list_wifi_protected_setup"), NetworkModeNone, false, true); |
|
293 } |
|
294 OstTraceFunctionExit0( WLANWIZARDPAGENETWORKMODE_POPULATERADIOBUTTONLIST_EXIT ); |
|
295 } |
|
296 |
|
297 /*! |
|
298 * This function selects the next page. Security mode may be skipped in case |
|
299 * scan results exist and only single option remains. |
|
300 * @param [in] setting indicates the selected network mode. |
|
301 * @return Security mode query page identifier unless it can be skipped. |
|
302 */ |
|
303 int WlanWizardPageNetworkMode::selectNextPage(const WlanNetworkSetting &setting) const |
|
304 { |
|
305 OstTraceFunctionEntry0( WLANWIZARDPAGENETWORKMODE_SELECTNEXTPAGE_ENTRY ); |
|
306 |
|
307 int nextPage = WlanWizardPageInternal::PageNetworkSecurity; |
|
308 |
|
309 WlanWizardScanList networkOptions = mWizard->configuration( |
|
310 WlanWizardHelper::ConfAvailableNetworkOptions).value<WlanWizardScanList>(); |
|
311 |
|
312 if (networkOptions.secModes(setting) == SingleResult) { |
|
313 WlanSecuritySetting secMode = networkOptions.getSecMode(setting); |
|
314 mWizard->setConfiguration(WlanWizardHelper::ConfSecurityMode, secMode.mode); |
|
315 mWizard->setConfiguration(WlanWizardHelper::ConfUsePsk, secMode.usePsk); |
|
316 nextPage = secMode.nextPageId; |
|
317 } |
|
318 |
|
319 OstTraceFunctionExit0( DUP1_WLANWIZARDPAGENETWORKMODE_SELECTNEXTPAGE_EXIT ); |
|
320 return nextPage; |
|
321 } |