OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/chromeos/options/wimax_config_view.h" | |
6 | |
7 #include "base/string_util.h" | |
8 #include "base/stringprintf.h" | |
9 #include "base/utf_string_conversions.h" | |
10 #include "chrome/browser/chromeos/cros/cros_library.h" | |
11 #include "chrome/browser/chromeos/cros/network_library.h" | |
12 #include "chrome/browser/chromeos/cros/onc_constants.h" | |
13 #include "chrome/browser/chromeos/enrollment_dialog_view.h" | |
14 #include "chrome/browser/chromeos/login/user_manager.h" | |
15 #include "chrome/browser/profiles/profile_manager.h" | |
16 #include "grit/chromium_strings.h" | |
17 #include "grit/generated_resources.h" | |
18 #include "grit/locale_settings.h" | |
19 #include "grit/theme_resources.h" | |
20 #include "ui/base/l10n/l10n_util.h" | |
21 #include "ui/base/resource/resource_bundle.h" | |
22 #include "ui/views/controls/button/checkbox.h" | |
23 #include "ui/views/controls/button/image_button.h" | |
24 #include "ui/views/controls/label.h" | |
25 #include "ui/views/controls/textfield/textfield.h" | |
26 #include "ui/views/layout/grid_layout.h" | |
27 #include "ui/views/layout/layout_constants.h" | |
28 #include "ui/views/widget/widget.h" | |
29 | |
30 namespace chromeos { | |
31 | |
32 WimaxConfigView::WimaxConfigView(NetworkConfigView* parent, WimaxNetwork* wimax) | |
33 : ChildNetworkConfigView(parent, wimax), | |
34 identity_label_(NULL), | |
35 identity_textfield_(NULL), | |
36 save_credentials_checkbox_(NULL), | |
37 share_network_checkbox_(NULL), | |
38 shared_network_label_(NULL), | |
39 passphrase_label_(NULL), | |
40 passphrase_textfield_(NULL), | |
41 passphrase_visible_button_(NULL), | |
42 error_label_(NULL) { | |
43 Init(wimax); | |
44 } | |
45 | |
46 WimaxConfigView::~WimaxConfigView() { | |
47 } | |
48 | |
49 string16 WimaxConfigView::GetTitle() { | |
50 // TODO(stevenjb): Replace this generic "Connect to network..." string with | |
51 // WiMAX-specific one. | |
52 return l10n_util::GetStringUTF16( | |
53 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CONNECT_TITLE); | |
54 } | |
55 | |
56 views::View* WimaxConfigView::GetInitiallyFocusedView() { | |
57 if (identity_textfield_ && identity_textfield_->enabled()) | |
58 return identity_textfield_; | |
59 if (passphrase_textfield_ && passphrase_textfield_->enabled()) | |
60 return passphrase_textfield_; | |
61 return NULL; | |
62 } | |
63 | |
64 bool WimaxConfigView::CanLogin() { | |
65 // TODO(stevenjb): Update this with the correct minimum length. | |
66 static const size_t kMinWimaxPasswordLen = 0; | |
zel
2012/05/18 01:17:41
Ben, if there are limit on WiMAX password side at
Ben Chan
2012/05/18 01:25:42
I don't see any information about the minimum pass
zel
2012/05/18 01:27:25
So, zero it is until you tell us otherwise.
| |
67 | |
68 // If the network requires a passphrase, make sure it is the right length. | |
69 if (passphrase_textfield_ != NULL | |
70 && passphrase_textfield_->text().length() < kMinWimaxPasswordLen) | |
oshima
2012/05/18 01:03:15
move && to previous line
can this simply be
retur
zel
2012/05/18 01:17:41
Done.
| |
71 return false; | |
72 | |
73 return true; | |
74 } | |
75 | |
76 void WimaxConfigView::UpdateDialogButtons() { | |
77 parent_->GetDialogClientView()->UpdateDialogButtons(); | |
78 } | |
79 | |
80 void WimaxConfigView::RefreshShareCheckbox() { | |
81 if (!share_network_checkbox_) | |
82 return; | |
83 | |
84 if (!UserManager::Get()->IsUserLoggedIn()) { | |
85 // If not logged in, networks must be shared. | |
86 share_network_checkbox_->SetEnabled(false); | |
87 share_network_checkbox_->SetChecked(true); | |
88 } else { | |
89 share_network_checkbox_->SetEnabled(true); | |
90 share_network_checkbox_->SetChecked(false); // Default to unshared. | |
91 } | |
92 } | |
93 | |
94 void WimaxConfigView::UpdateErrorLabel() { | |
95 std::string error_msg; | |
96 if (error_msg.empty() && !service_path_.empty()) { | |
oshima
2012/05/18 01:03:15
isn't error_msg always empty?
zel
2012/05/18 01:17:41
Done.
| |
97 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | |
98 const WimaxNetwork* wimax = cros->FindWimaxNetworkByPath(service_path_); | |
99 if (wimax && wimax->failed()) { | |
100 bool passphrase_empty = wimax->eap_passphrase().empty(); | |
101 switch (wimax->error()) { | |
102 case ERROR_BAD_PASSPHRASE: | |
103 if (!passphrase_empty) { | |
104 error_msg = l10n_util::GetStringUTF8( | |
105 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_PASSPHRASE); | |
106 } | |
107 break; | |
108 case ERROR_BAD_WEPKEY: | |
109 if (!passphrase_empty) { | |
110 error_msg = l10n_util::GetStringUTF8( | |
111 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_WEPKEY); | |
112 } | |
113 break; | |
114 default: | |
115 error_msg = wimax->GetErrorString(); | |
116 break; | |
117 } | |
118 } | |
119 } | |
120 if (!error_msg.empty()) { | |
121 error_label_->SetText(UTF8ToUTF16(error_msg)); | |
122 error_label_->SetVisible(true); | |
123 } else { | |
124 error_label_->SetVisible(false); | |
125 } | |
126 } | |
127 | |
128 void WimaxConfigView::ContentsChanged(views::Textfield* sender, | |
129 const string16& new_contents) { | |
oshima
2012/05/18 01:03:15
indent
zel
2012/05/18 01:17:41
Done.
| |
130 UpdateDialogButtons(); | |
131 } | |
132 | |
133 bool WimaxConfigView::HandleKeyEvent(views::Textfield* sender, | |
134 const views::KeyEvent& key_event) { | |
oshima
2012/05/18 01:03:15
indent
zel
2012/05/18 01:17:41
Done.
| |
135 if (sender == passphrase_textfield_ && | |
136 key_event.key_code() == ui::VKEY_RETURN) { | |
137 parent_->GetDialogClientView()->AcceptWindow(); | |
138 } | |
139 return false; | |
140 } | |
141 | |
142 void WimaxConfigView::ButtonPressed(views::Button* sender, | |
143 const views::Event& event) { | |
144 if (sender == passphrase_visible_button_) { | |
145 if (passphrase_textfield_) { | |
146 passphrase_textfield_->SetObscured(!passphrase_textfield_->IsObscured()); | |
147 passphrase_visible_button_->SetToggled( | |
148 !passphrase_textfield_->IsObscured()); | |
149 } | |
150 } else { | |
151 NOTREACHED(); | |
152 } | |
153 } | |
154 | |
155 bool WimaxConfigView::Login() { | |
156 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | |
157 WimaxNetwork* wimax = cros->FindWimaxNetworkByPath(service_path_); | |
158 if (!wimax) { | |
159 // Flimflam no longer knows about this wimax network (edge case). | |
160 // TODO(stevenjb): Add a notification (chromium-os13225). | |
161 LOG(WARNING) << "Wimax network: " << service_path_ << " no longer exists."; | |
162 return true; | |
163 } | |
164 wimax->SetEAPIdentity(GetEapIdentity()); | |
165 wimax->SetEAPPassphrase(GetEapPassphrase()); | |
166 bool share_default = (wimax->profile_type() != PROFILE_USER); | |
oshima
2012/05/18 01:03:15
nit: no need for ().
zel
2012/05/18 01:17:41
I like () for bool expressions.
| |
167 bool share = GetShareNetwork(share_default); | |
168 wimax->SetEnrollmentDelegate( | |
169 CreateEnrollmentDelegate(GetWidget()->GetNativeWindow(), | |
170 wimax->name(), | |
171 ProfileManager::GetLastUsedProfile())); | |
172 cros->ConnectToWimaxNetwork(wimax, share); | |
173 // Connection failures are responsible for updating the UI, including | |
174 // reopening dialogs. | |
175 return true; // dialog will be closed | |
176 } | |
177 | |
178 std::string WimaxConfigView::GetEapIdentity() const { | |
179 DCHECK(identity_textfield_); | |
180 return UTF16ToUTF8(identity_textfield_->text()); | |
181 } | |
182 | |
183 std::string WimaxConfigView::GetEapPassphrase() const { | |
184 std::string result; | |
185 if (passphrase_textfield_ != NULL) | |
186 result = UTF16ToUTF8(passphrase_textfield_->text()); | |
187 return result; | |
oshima
2012/05/18 01:03:15
this one is up to you. can be just
return passphr
zel
2012/05/18 01:17:41
Done.
| |
188 } | |
189 | |
190 bool WimaxConfigView::GetSaveCredentials() const { | |
191 if (!save_credentials_checkbox_) | |
192 return true; // share networks by default (e.g. non 8021x). | |
193 return save_credentials_checkbox_->checked(); | |
oshima
2012/05/18 01:03:15
ditto
zel
2012/05/18 01:17:41
Done.
| |
194 } | |
195 | |
196 bool WimaxConfigView::GetShareNetwork(bool share_default) const { | |
197 if (!share_network_checkbox_) | |
198 return share_default; | |
199 return share_network_checkbox_->checked(); | |
oshima
2012/05/18 01:03:15
ditto
zel
2012/05/18 01:17:41
Done.
| |
200 } | |
201 | |
202 void WimaxConfigView::Cancel() { | |
203 } | |
204 | |
205 void WimaxConfigView::Init(WimaxNetwork* wimax) { | |
206 DCHECK(wimax); | |
207 WifiConfigView::ParseWiFiEAPUIProperty( | |
208 &save_credentials_ui_data_, wimax, onc::eap::kSaveCredentials); | |
209 WifiConfigView::ParseWiFiEAPUIProperty( | |
210 &identity_ui_data_, wimax, onc::eap::kIdentity); | |
211 WifiConfigView::ParseWiFiUIProperty( | |
212 &passphrase_ui_data_, wimax, onc::wifi::kPassphrase); | |
213 | |
214 views::GridLayout* layout = views::GridLayout::CreatePanel(this); | |
215 SetLayoutManager(layout); | |
216 | |
217 int column_view_set_id = 0; | |
218 views::ColumnSet* column_set = layout->AddColumnSet(column_view_set_id); | |
219 const int kPasswordVisibleWidth = 20; | |
220 // Label | |
221 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, | |
222 views::GridLayout::USE_PREF, 0, 0); | |
223 column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing); | |
224 // Textfield, combobox. | |
225 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | |
226 views::GridLayout::USE_PREF, 0, | |
227 ChildNetworkConfigView::kInputFieldMinWidth); | |
228 column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing); | |
229 // Password visible button / policy indicator. | |
230 column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, 1, | |
231 views::GridLayout::USE_PREF, 0, kPasswordVisibleWidth); | |
232 | |
233 // Netowrk name | |
234 layout->StartRow(0, column_view_set_id); | |
235 layout->AddView(new views::Label(l10n_util::GetStringUTF16( | |
236 IDS_OPTIONS_SETTINGS_INTERNET_TAB_NETWORK))); | |
237 views::Label* label = new views::Label(UTF8ToUTF16(wimax->name())); | |
238 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
239 layout->AddView(label); | |
240 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
241 | |
242 // Identity | |
243 layout->StartRow(0, column_view_set_id); | |
244 identity_label_ = new views::Label(l10n_util::GetStringUTF16( | |
245 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_IDENTITY)); | |
246 layout->AddView(identity_label_); | |
247 identity_textfield_ = new views::Textfield( | |
248 views::Textfield::STYLE_DEFAULT); | |
249 identity_textfield_->SetController(this); | |
250 const std::string& eap_identity = wimax->eap_identity(); | |
251 identity_textfield_->SetText(UTF8ToUTF16(eap_identity)); | |
252 identity_textfield_->SetEnabled(identity_ui_data_.editable()); | |
253 layout->AddView(identity_textfield_); | |
254 layout->AddView(new ControlledSettingIndicatorView(identity_ui_data_)); | |
255 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
256 | |
257 // Passphrase input | |
258 layout->StartRow(0, column_view_set_id); | |
259 int label_text_id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE; | |
260 passphrase_label_ = new views::Label( | |
261 l10n_util::GetStringUTF16(label_text_id)); | |
262 layout->AddView(passphrase_label_); | |
263 passphrase_textfield_ = new views::Textfield( | |
264 views::Textfield::STYLE_OBSCURED); | |
265 passphrase_textfield_->SetController(this); | |
266 if (!wimax->eap_passphrase().empty()) | |
267 passphrase_textfield_->SetText(UTF8ToUTF16(wimax->eap_passphrase())); | |
268 passphrase_label_->SetEnabled(true); | |
269 passphrase_textfield_->SetEnabled(passphrase_ui_data_.editable()); | |
270 passphrase_textfield_->SetAccessibleName(l10n_util::GetStringUTF16( | |
271 label_text_id)); | |
272 layout->AddView(passphrase_textfield_); | |
273 | |
274 if (passphrase_ui_data_.managed()) { | |
275 layout->AddView(new ControlledSettingIndicatorView(passphrase_ui_data_)); | |
276 } else { | |
277 // Password visible button. | |
278 passphrase_visible_button_ = new views::ToggleImageButton(this); | |
279 passphrase_visible_button_->SetTooltipText( | |
280 l10n_util::GetStringUTF16( | |
281 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE_SHOW)); | |
282 passphrase_visible_button_->SetToggledTooltipText( | |
283 l10n_util::GetStringUTF16( | |
284 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE_HIDE)); | |
285 passphrase_visible_button_->SetImage( | |
286 views::ImageButton::BS_NORMAL, | |
287 ResourceBundle::GetSharedInstance(). | |
288 GetBitmapNamed(IDR_NETWORK_SHOW_PASSWORD_OFF)); | |
289 passphrase_visible_button_->SetImage( | |
290 views::ImageButton::BS_HOT, | |
291 ResourceBundle::GetSharedInstance(). | |
292 GetBitmapNamed(IDR_NETWORK_SHOW_PASSWORD_HOVER)); | |
293 passphrase_visible_button_->SetToggledImage( | |
294 views::ImageButton::BS_NORMAL, | |
295 ResourceBundle::GetSharedInstance(). | |
296 GetBitmapNamed(IDR_NETWORK_SHOW_PASSWORD_ON)); | |
297 passphrase_visible_button_->SetImageAlignment( | |
298 views::ImageButton::ALIGN_CENTER, views::ImageButton::ALIGN_MIDDLE); | |
299 layout->AddView(passphrase_visible_button_); | |
300 } | |
301 | |
302 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
303 | |
304 // Checkboxes. | |
305 | |
306 // Save credentials | |
307 layout->StartRow(0, column_view_set_id); | |
308 save_credentials_checkbox_ = new views::Checkbox( | |
309 l10n_util::GetStringUTF16( | |
310 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SAVE_CREDENTIALS)); | |
311 save_credentials_checkbox_->SetEnabled( | |
312 save_credentials_ui_data_.editable()); | |
313 layout->SkipColumns(1); | |
314 layout->AddView(save_credentials_checkbox_); | |
315 layout->AddView( | |
316 new ControlledSettingIndicatorView(save_credentials_ui_data_)); | |
317 | |
318 // Share network | |
319 if (wimax->profile_type() == PROFILE_NONE && wimax->passphrase_required()) { | |
320 layout->StartRow(0, column_view_set_id); | |
321 share_network_checkbox_ = new views::Checkbox( | |
322 l10n_util::GetStringUTF16( | |
323 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SHARE_NETWORK)); | |
324 layout->SkipColumns(1); | |
325 layout->AddView(share_network_checkbox_); | |
326 } | |
327 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
328 | |
329 // Create an error label. | |
330 layout->StartRow(0, column_view_set_id); | |
331 layout->SkipColumns(1); | |
332 error_label_ = new views::Label(); | |
333 error_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
334 error_label_->SetEnabledColor(SK_ColorRED); | |
335 layout->AddView(error_label_); | |
336 | |
337 RefreshShareCheckbox(); | |
338 UpdateErrorLabel(); | |
339 } | |
340 | |
341 void WimaxConfigView::InitFocus() { | |
342 views::View* view_to_focus = GetInitiallyFocusedView(); | |
343 if (view_to_focus) | |
344 view_to_focus->RequestFocus(); | |
345 } | |
346 | |
347 } // namespace chromeos | |
OLD | NEW |