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

Side by Side Diff: chrome/browser/chromeos/settings_contents_view.cc

Issue 231014: Add wifi menu button in status bar. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/settings_contents_view.h" 5 #include "chrome/browser/chromeos/settings_contents_view.h"
6 6
7 #include <map> 7 #include <map>
8 #include <vector> 8 #include <vector>
9 9
10 #include "app/combobox_model.h" 10 #include "app/combobox_model.h"
11 #include "app/l10n_util.h" 11 #include "app/l10n_util.h"
12 #include "app/resource_bundle.h" 12 #include "app/resource_bundle.h"
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "chrome/browser/chromeos/password_dialog_view.h"
15 #include "chrome/common/pref_member.h" 16 #include "chrome/common/pref_member.h"
16 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
17 #include "grit/chromium_strings.h" 18 #include "grit/chromium_strings.h"
18 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
19 #include "grit/locale_settings.h"
20 #include "views/background.h" 20 #include "views/background.h"
21 #include "views/controls/button/checkbox.h" 21 #include "views/controls/button/checkbox.h"
22 #include "views/controls/combobox/combobox.h" 22 #include "views/controls/combobox/combobox.h"
23 #include "views/controls/slider/slider.h" 23 #include "views/controls/slider/slider.h"
24 #include "views/controls/textfield/textfield.h"
25 #include "views/grid_layout.h" 24 #include "views/grid_layout.h"
26 #include "views/standard_layout.h" 25 #include "views/standard_layout.h"
27 #include "views/window/dialog_delegate.h"
28 #include "views/window/window.h" 26 #include "views/window/window.h"
29 27
30 using views::GridLayout; 28 using views::GridLayout;
31 using views::ColumnSet; 29 using views::ColumnSet;
32 30
33 namespace { 31 namespace {
34 32
35 //////////////////////////////////////////////////////////////////////////////// 33 ////////////////////////////////////////////////////////////////////////////////
36 // WifiSSIDComboModel 34 // WifiSSIDComboModel
37 35
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 int strength) { 117 int strength) {
120 ssids_.push_back(ssid); 118 ssids_.push_back(ssid);
121 ssids_map_[ssid] = NetworkData(encryption, strength); 119 ssids_map_[ssid] = NetworkData(encryption, strength);
122 } 120 }
123 121
124 //////////////////////////////////////////////////////////////////////////////// 122 ////////////////////////////////////////////////////////////////////////////////
125 // NetworkSection 123 // NetworkSection
126 124
127 // Network section for wifi settings 125 // Network section for wifi settings
128 class NetworkSection : public OptionsPageView, 126 class NetworkSection : public OptionsPageView,
129 public views::Combobox::Listener { 127 public views::Combobox::Listener,
128 public PasswordDialogDelegate {
130 public: 129 public:
131 explicit NetworkSection(Profile* profile); 130 explicit NetworkSection(Profile* profile);
132 virtual ~NetworkSection() {} 131 virtual ~NetworkSection() {}
133 132
134 // Overridden from views::Combobox::Listener: 133 // Overridden from views::Combobox::Listener:
135 virtual void ItemChanged(views::Combobox* sender, 134 virtual void ItemChanged(views::Combobox* sender,
136 int prev_index, 135 int prev_index,
137 int new_index); 136 int new_index);
138 137
139 bool OnPasswordWindowCancel(); 138 // PasswordDialogDelegate implementation.
140 bool OnPasswordWindowAccept(const string16& password); 139 virtual bool OnPasswordDialogCancel();
140 virtual bool OnPasswordDialogAccept(const string16& password);
141
141 bool ConnectToWifi(const string16& ssid, const string16& password); 142 bool ConnectToWifi(const string16& ssid, const string16& password);
142 143
143 protected: 144 protected:
144 // OptionsPageView overrides: 145 // OptionsPageView overrides:
145 virtual void InitControlLayout(); 146 virtual void InitControlLayout();
146 virtual void InitContents(); 147 virtual void InitContents();
147 148
148 private: 149 private:
149 // The View that contains the contents of the section. 150 // The View that contains the contents of the section.
150 views::View* contents_; 151 views::View* contents_;
151 152
152 // Controls for this section: 153 // Controls for this section:
153 views::Combobox* wifi_ssid_combobox_; 154 views::Combobox* wifi_ssid_combobox_;
154 155
155 // Used to store the index (in combobox) of the currently connected wifi. 156 // Used to store the index (in combobox) of the currently connected wifi.
156 int last_selected_wifi_ssid_index_; 157 int last_selected_wifi_ssid_index_;
157 158
158 // Dummy for now. Used to populate wifi ssid models. 159 // Dummy for now. Used to populate wifi ssid models.
159 WifiSSIDComboModel wifi_ssid_model_; 160 WifiSSIDComboModel wifi_ssid_model_;
160 161
161 DISALLOW_COPY_AND_ASSIGN(NetworkSection); 162 DISALLOW_COPY_AND_ASSIGN(NetworkSection);
162 }; 163 };
163 164
164 //////////////////////////////////////////////////////////////////////////////// 165 ////////////////////////////////////////////////////////////////////////////////
165 // PasswordWindowView
166
167 static const int kDialogPadding = 7;
168
169 // A view for showing a password textfield
170 class PasswordWindowView : public views::View,
171 public views::DialogDelegate {
172 public:
173 PasswordWindowView(NetworkSection* network_delegate, Profile* profile);
174 views::Window* container() const { return container_; }
175 void set_container(views::Window* container) {
176 container_ = container;
177 }
178
179 // views::DialogDelegate methods.
180 virtual bool Cancel();
181 virtual bool Accept();
182 virtual std::wstring GetWindowTitle() const;
183
184 // views::WindowDelegate method.
185 virtual bool IsModal() const { return true; }
186 virtual views::View* GetContentsView() { return this; }
187
188 // views::View overrides.
189 virtual void Layout();
190 virtual gfx::Size GetPreferredSize();
191
192 protected:
193 virtual void ViewHierarchyChanged(bool is_add, views::View* parent,
194 views::View* child);
195
196 private:
197 void Init();
198
199 // The Options dialog window.
200 views::Window* container_;
201
202 // Used for Call back to NetworkSection that password has been entered.
203 NetworkSection* network_delegate_;
204
205 // Combobox and its corresponding model.
206 views::Textfield* password_textfield_;
207
208 DISALLOW_COPY_AND_ASSIGN(PasswordWindowView);
209 };
210
211 PasswordWindowView::PasswordWindowView(
212 NetworkSection* network_delegate,
213 Profile* profile)
214 : network_delegate_(network_delegate),
215 password_textfield_(NULL) {
216 Init();
217 }
218
219 std::wstring PasswordWindowView::GetWindowTitle() const {
220 return l10n_util::GetString(IDS_OPTIONS_SETTINGS_SECTION_TITLE_PASSWORD);
221 }
222
223 bool PasswordWindowView::Cancel() {
224 return network_delegate_->OnPasswordWindowCancel();
225 }
226
227 bool PasswordWindowView::Accept() {
228 // TODO(chocobo): we should not need to call SyncText ourself here.
229 password_textfield_->SyncText();
230 return network_delegate_->OnPasswordWindowAccept(password_textfield_->text());
231 }
232
233 void PasswordWindowView::Layout() {
234 gfx::Size sz = password_textfield_->GetPreferredSize();
235 password_textfield_->SetBounds(kDialogPadding, kDialogPadding,
236 width() - 2*kDialogPadding,
237 sz.height());
238 }
239
240 gfx::Size PasswordWindowView::GetPreferredSize() {
241 // TODO(chocobo): Create our own localized content size once the UI is done.
242 return gfx::Size(views::Window::GetLocalizedContentsSize(
243 IDS_ABOUT_DIALOG_WIDTH_CHARS,
244 IDS_ABOUT_DIALOG_MINIMUM_HEIGHT_LINES));
245 }
246
247 void PasswordWindowView::ViewHierarchyChanged(bool is_add,
248 views::View* parent,
249 views::View* child) {
250 if (is_add && child == this)
251 Init();
252 }
253
254 void PasswordWindowView::Init() {
255 password_textfield_ = new views::Textfield(views::Textfield::STYLE_PASSWORD);
256 AddChildView(password_textfield_);
257 }
258
259 ////////////////////////////////////////////////////////////////////////////////
260 // NetworkSection 166 // NetworkSection
261 167
262 NetworkSection::NetworkSection(Profile* profile) 168 NetworkSection::NetworkSection(Profile* profile)
263 : OptionsPageView(profile), 169 : OptionsPageView(profile),
264 contents_(NULL), 170 contents_(NULL),
265 wifi_ssid_combobox_(NULL), 171 wifi_ssid_combobox_(NULL),
266 last_selected_wifi_ssid_index_(0) { 172 last_selected_wifi_ssid_index_(0) {
267 } 173 }
268 174
269 void NetworkSection::ItemChanged(views::Combobox* sender, 175 void NetworkSection::ItemChanged(views::Combobox* sender,
270 int prev_index, 176 int prev_index,
271 int new_index) { 177 int new_index) {
272 if (new_index == prev_index) 178 if (new_index == prev_index)
273 return; 179 return;
274 if (sender == wifi_ssid_combobox_) { 180 if (sender == wifi_ssid_combobox_) {
275 last_selected_wifi_ssid_index_ = prev_index; 181 last_selected_wifi_ssid_index_ = prev_index;
276 string16 ssid = wifi_ssid_model_.GetSSIDAt(new_index); 182 string16 ssid = wifi_ssid_model_.GetSSIDAt(new_index);
277 // Connect to wifi here. Open password page if appropriate 183 // Connect to wifi here. Open password page if appropriate
278 if (wifi_ssid_model_.RequiresPassword(ssid)) { 184 if (wifi_ssid_model_.RequiresPassword(ssid)) {
279 views::Window* window = views::Window::CreateChromeWindow( 185 views::Window* window = views::Window::CreateChromeWindow(
280 NULL, 186 NULL,
281 gfx::Rect(), 187 gfx::Rect(),
282 new PasswordWindowView(this, profile())); 188 new PasswordDialogView(this));
189 window->SetIsAlwaysOnTop(true);
283 window->Show(); 190 window->Show();
284 } else { 191 } else {
285 ConnectToWifi(ssid, string16()); 192 ConnectToWifi(ssid, string16());
286 } 193 }
287 } 194 }
288 } 195 }
289 196
290 bool NetworkSection::OnPasswordWindowCancel() { 197 bool NetworkSection::OnPasswordDialogCancel() {
291 // Change combobox to previous setting 198 // Change combobox to previous setting
292 wifi_ssid_combobox_->SetSelectedItem(last_selected_wifi_ssid_index_); 199 wifi_ssid_combobox_->SetSelectedItem(last_selected_wifi_ssid_index_);
293 return true; 200 return true;
294 } 201 }
295 202
296 bool NetworkSection::OnPasswordWindowAccept(const string16& password) { 203 bool NetworkSection::OnPasswordDialogAccept(const string16& password) {
297 // Try connecting to wifi 204 // Try connecting to wifi
298 return ConnectToWifi(wifi_ssid_model_.GetSSIDAt( 205 return ConnectToWifi(wifi_ssid_model_.GetSSIDAt(
299 wifi_ssid_combobox_->selected_item()), password); 206 wifi_ssid_combobox_->selected_item()), password);
300 } 207 }
301 208
302 bool NetworkSection::ConnectToWifi(const string16& ssid, 209 bool NetworkSection::ConnectToWifi(const string16& ssid,
303 const string16& password) { 210 const string16& password) {
304 // TODO(chocobo): Connect to wifi 211 // TODO(chocobo): Connect to wifi
305 return password == ASCIIToUTF16("chronos"); 212 return password == ASCIIToUTF16("chronos");
306 } 213 }
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, 472 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
566 GridLayout::USE_PREF, 0, 0); 473 GridLayout::USE_PREF, 0, 0);
567 474
568 layout->StartRow(0, single_column_view_set_id); 475 layout->StartRow(0, single_column_view_set_id);
569 layout->AddView(new NetworkSection(profile())); 476 layout->AddView(new NetworkSection(profile()));
570 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); 477 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
571 layout->StartRow(0, single_column_view_set_id); 478 layout->StartRow(0, single_column_view_set_id);
572 layout->AddView(new TouchpadSection(profile())); 479 layout->AddView(new TouchpadSection(profile()));
573 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); 480 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
574 } 481 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/password_dialog_view.cc ('k') | chrome/browser/chromeos/status_area_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698