Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(415)

Side by Side Diff: chrome/browser/chromeos/options/wimax_config_view.cc

Issue 10407034: Picked up from stevenjb@: Added WimaxConfigView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review updates Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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(benchan): Update this with the correct minimum length.
66 static const size_t kMinWimaxPasswordLen = 0;
67
68 // If the network requires a passphrase, make sure it is the right length.
69 return passphrase_textfield_ && passphrase_textfield_->text().length() >=
70 kMinWimaxPasswordLen;
71 }
72
73 void WimaxConfigView::UpdateDialogButtons() {
74 parent_->GetDialogClientView()->UpdateDialogButtons();
75 }
76
77 void WimaxConfigView::RefreshShareCheckbox() {
78 if (!share_network_checkbox_)
79 return;
80
81 if (!UserManager::Get()->IsUserLoggedIn()) {
82 // If not logged in, networks must be shared.
83 share_network_checkbox_->SetEnabled(false);
84 share_network_checkbox_->SetChecked(true);
85 } else {
86 share_network_checkbox_->SetEnabled(true);
87 share_network_checkbox_->SetChecked(false); // Default to unshared.
88 }
89 }
90
91 void WimaxConfigView::UpdateErrorLabel() {
92 std::string error_msg;
93 if (!service_path_.empty()) {
94 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
95 const WimaxNetwork* wimax = cros->FindWimaxNetworkByPath(service_path_);
96 if (wimax && wimax->failed()) {
97 bool passphrase_empty = wimax->eap_passphrase().empty();
98 switch (wimax->error()) {
99 case ERROR_BAD_PASSPHRASE:
100 if (!passphrase_empty) {
101 error_msg = l10n_util::GetStringUTF8(
102 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_PASSPHRASE);
103 }
104 break;
105 case ERROR_BAD_WEPKEY:
106 if (!passphrase_empty) {
107 error_msg = l10n_util::GetStringUTF8(
108 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_WEPKEY);
109 }
110 break;
111 default:
112 error_msg = wimax->GetErrorString();
113 break;
114 }
115 }
116 }
117 if (!error_msg.empty()) {
118 error_label_->SetText(UTF8ToUTF16(error_msg));
119 error_label_->SetVisible(true);
120 } else {
121 error_label_->SetVisible(false);
122 }
123 }
124
125 void WimaxConfigView::ContentsChanged(views::Textfield* sender,
126 const string16& new_contents) {
127 UpdateDialogButtons();
128 }
129
130 bool WimaxConfigView::HandleKeyEvent(views::Textfield* sender,
131 const views::KeyEvent& key_event) {
132 if (sender == passphrase_textfield_ &&
133 key_event.key_code() == ui::VKEY_RETURN) {
134 parent_->GetDialogClientView()->AcceptWindow();
135 }
136 return false;
137 }
138
139 void WimaxConfigView::ButtonPressed(views::Button* sender,
140 const views::Event& event) {
141 if (sender == passphrase_visible_button_) {
142 if (passphrase_textfield_) {
143 passphrase_textfield_->SetObscured(!passphrase_textfield_->IsObscured());
144 passphrase_visible_button_->SetToggled(
145 !passphrase_textfield_->IsObscured());
146 }
147 } else {
148 NOTREACHED();
149 }
150 }
151
152 bool WimaxConfigView::Login() {
153 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
154 WimaxNetwork* wimax = cros->FindWimaxNetworkByPath(service_path_);
155 if (!wimax) {
156 // Flimflam no longer knows about this wimax network (edge case).
157 // TODO(stevenjb): Add a notification (chromium-os13225).
158 LOG(WARNING) << "Wimax network: " << service_path_ << " no longer exists.";
159 return true;
160 }
161 wimax->SetEAPIdentity(GetEapIdentity());
162 wimax->SetEAPPassphrase(GetEapPassphrase());
163 bool share_default = (wimax->profile_type() != PROFILE_USER);
164 bool share = GetShareNetwork(share_default);
165 wimax->SetEnrollmentDelegate(
166 CreateEnrollmentDelegate(GetWidget()->GetNativeWindow(),
167 wimax->name(),
168 ProfileManager::GetLastUsedProfile()));
169 cros->ConnectToWimaxNetwork(wimax, share);
170 // Connection failures are responsible for updating the UI, including
171 // reopening dialogs.
172 return true; // dialog will be closed
173 }
174
175 std::string WimaxConfigView::GetEapIdentity() const {
176 DCHECK(identity_textfield_);
177 return UTF16ToUTF8(identity_textfield_->text());
178 }
179
180 std::string WimaxConfigView::GetEapPassphrase() const {
181 return passphrase_textfield_ ? UTF16ToUTF8(passphrase_textfield_->text()) :
182 std::string();
183 }
184
185 bool WimaxConfigView::GetSaveCredentials() const {
186 return save_credentials_checkbox_ ? save_credentials_checkbox_->checked() :
187 true;
188 }
189
190 bool WimaxConfigView::GetShareNetwork(bool share_default) const {
191 return share_network_checkbox_ ? share_network_checkbox_->checked() :
192 share_default;
193 }
194
195 void WimaxConfigView::Cancel() {
196 }
197
198 void WimaxConfigView::Init(WimaxNetwork* wimax) {
199 DCHECK(wimax);
200 WifiConfigView::ParseWiFiEAPUIProperty(
201 &save_credentials_ui_data_, wimax, onc::eap::kSaveCredentials);
202 WifiConfigView::ParseWiFiEAPUIProperty(
203 &identity_ui_data_, wimax, onc::eap::kIdentity);
204 WifiConfigView::ParseWiFiUIProperty(
205 &passphrase_ui_data_, wimax, onc::wifi::kPassphrase);
206
207 views::GridLayout* layout = views::GridLayout::CreatePanel(this);
208 SetLayoutManager(layout);
209
210 int column_view_set_id = 0;
211 views::ColumnSet* column_set = layout->AddColumnSet(column_view_set_id);
212 const int kPasswordVisibleWidth = 20;
213 // Label
214 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1,
215 views::GridLayout::USE_PREF, 0, 0);
216 column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing);
217 // Textfield, combobox.
218 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
219 views::GridLayout::USE_PREF, 0,
220 ChildNetworkConfigView::kInputFieldMinWidth);
221 column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing);
222 // Password visible button / policy indicator.
223 column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, 1,
224 views::GridLayout::USE_PREF, 0, kPasswordVisibleWidth);
225
226 // Netowrk name
227 layout->StartRow(0, column_view_set_id);
228 layout->AddView(new views::Label(l10n_util::GetStringUTF16(
229 IDS_OPTIONS_SETTINGS_INTERNET_TAB_NETWORK)));
230 views::Label* label = new views::Label(UTF8ToUTF16(wimax->name()));
231 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
232 layout->AddView(label);
233 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
234
235 // Identity
236 layout->StartRow(0, column_view_set_id);
237 identity_label_ = new views::Label(l10n_util::GetStringUTF16(
238 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_IDENTITY));
239 layout->AddView(identity_label_);
240 identity_textfield_ = new views::Textfield(
241 views::Textfield::STYLE_DEFAULT);
242 identity_textfield_->SetController(this);
243 const std::string& eap_identity = wimax->eap_identity();
244 identity_textfield_->SetText(UTF8ToUTF16(eap_identity));
245 identity_textfield_->SetEnabled(identity_ui_data_.editable());
246 layout->AddView(identity_textfield_);
247 layout->AddView(new ControlledSettingIndicatorView(identity_ui_data_));
248 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
249
250 // Passphrase input
251 layout->StartRow(0, column_view_set_id);
252 int label_text_id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE;
253 passphrase_label_ = new views::Label(
254 l10n_util::GetStringUTF16(label_text_id));
255 layout->AddView(passphrase_label_);
256 passphrase_textfield_ = new views::Textfield(
257 views::Textfield::STYLE_OBSCURED);
258 passphrase_textfield_->SetController(this);
259 passphrase_label_->SetEnabled(true);
260 passphrase_textfield_->SetEnabled(passphrase_ui_data_.editable());
261 passphrase_textfield_->SetAccessibleName(l10n_util::GetStringUTF16(
262 label_text_id));
263 layout->AddView(passphrase_textfield_);
264
265 if (passphrase_ui_data_.managed()) {
266 layout->AddView(new ControlledSettingIndicatorView(passphrase_ui_data_));
267 } else {
268 // Password visible button.
269 passphrase_visible_button_ = new views::ToggleImageButton(this);
270 passphrase_visible_button_->SetTooltipText(
271 l10n_util::GetStringUTF16(
272 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE_SHOW));
273 passphrase_visible_button_->SetToggledTooltipText(
274 l10n_util::GetStringUTF16(
275 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE_HIDE));
276 passphrase_visible_button_->SetImage(
277 views::ImageButton::BS_NORMAL,
278 ResourceBundle::GetSharedInstance().
279 GetBitmapNamed(IDR_NETWORK_SHOW_PASSWORD_OFF));
280 passphrase_visible_button_->SetImage(
281 views::ImageButton::BS_HOT,
282 ResourceBundle::GetSharedInstance().
283 GetBitmapNamed(IDR_NETWORK_SHOW_PASSWORD_HOVER));
284 passphrase_visible_button_->SetToggledImage(
285 views::ImageButton::BS_NORMAL,
286 ResourceBundle::GetSharedInstance().
287 GetBitmapNamed(IDR_NETWORK_SHOW_PASSWORD_ON));
288 passphrase_visible_button_->SetImageAlignment(
289 views::ImageButton::ALIGN_CENTER, views::ImageButton::ALIGN_MIDDLE);
290 layout->AddView(passphrase_visible_button_);
291 }
292
293 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
294
295 // Checkboxes.
296
297 // Save credentials
298 layout->StartRow(0, column_view_set_id);
299 save_credentials_checkbox_ = new views::Checkbox(
300 l10n_util::GetStringUTF16(
301 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SAVE_CREDENTIALS));
302 save_credentials_checkbox_->SetEnabled(
303 save_credentials_ui_data_.editable());
304 layout->SkipColumns(1);
305 layout->AddView(save_credentials_checkbox_);
306 layout->AddView(
307 new ControlledSettingIndicatorView(save_credentials_ui_data_));
308
309 // Share network
310 if (wimax->profile_type() == PROFILE_NONE && wimax->passphrase_required()) {
311 layout->StartRow(0, column_view_set_id);
312 share_network_checkbox_ = new views::Checkbox(
313 l10n_util::GetStringUTF16(
314 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SHARE_NETWORK));
315 layout->SkipColumns(1);
316 layout->AddView(share_network_checkbox_);
317 }
318 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
319
320 // Create an error label.
321 layout->StartRow(0, column_view_set_id);
322 layout->SkipColumns(1);
323 error_label_ = new views::Label();
324 error_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
325 error_label_->SetEnabledColor(SK_ColorRED);
326 layout->AddView(error_label_);
327
328 RefreshShareCheckbox();
329 UpdateErrorLabel();
330 }
331
332 void WimaxConfigView::InitFocus() {
333 views::View* view_to_focus = GetInitiallyFocusedView();
334 if (view_to_focus)
335 view_to_focus->RequestFocus();
336 }
337
338 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698