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

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

Issue 341044: Move chromeos code to namespace chromeos. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 1 month 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 <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "app/combobox_model.h" 11 #include "app/combobox_model.h"
12 #include "app/l10n_util.h" 12 #include "app/l10n_util.h"
13 #include "app/resource_bundle.h" 13 #include "app/resource_bundle.h"
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/stl_util-inl.h" 15 #include "base/stl_util-inl.h"
16 #include "base/string_util.h" 16 #include "base/string_util.h"
17 #include "chrome/browser/chromeos/cros_network_library.h" 17 #include "chrome/browser/chromeos/network_library.h"
18 #include "chrome/browser/chromeos/password_dialog_view.h" 18 #include "chrome/browser/chromeos/password_dialog_view.h"
19 #include "chrome/common/pref_member.h" 19 #include "chrome/common/pref_member.h"
20 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
21 #include "grit/chromium_strings.h" 21 #include "grit/chromium_strings.h"
22 #include "grit/generated_resources.h" 22 #include "grit/generated_resources.h"
23 #include "unicode/strenum.h" 23 #include "unicode/strenum.h"
24 #include "unicode/timezone.h" 24 #include "unicode/timezone.h"
25 #include "views/background.h" 25 #include "views/background.h"
26 #include "views/controls/button/checkbox.h" 26 #include "views/controls/button/checkbox.h"
27 #include "views/controls/combobox/combobox.h" 27 #include "views/controls/combobox/combobox.h"
28 #include "views/controls/slider/slider.h" 28 #include "views/controls/slider/slider.h"
29 #include "views/grid_layout.h" 29 #include "views/grid_layout.h"
30 #include "views/standard_layout.h" 30 #include "views/standard_layout.h"
31 #include "views/window/window.h" 31 #include "views/window/window.h"
32 32
33 using views::GridLayout; 33 using views::GridLayout;
34 using views::ColumnSet; 34 using views::ColumnSet;
35 35
36 namespace { 36 namespace chromeos {
37 37
38 //////////////////////////////////////////////////////////////////////////////// 38 ////////////////////////////////////////////////////////////////////////////////
39 // SettingsContentsSection 39 // SettingsContentsSection
40 40
41 // Base section class settings 41 // Base section class settings
42 class SettingsContentsSection : public OptionsPageView { 42 class SettingsContentsSection : public OptionsPageView {
43 public: 43 public:
44 explicit SettingsContentsSection(Profile* profile, int title_msg_id); 44 explicit SettingsContentsSection(Profile* profile, int title_msg_id);
45 virtual ~SettingsContentsSection() {} 45 virtual ~SettingsContentsSection() {}
46 46
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 } 248 }
249 } 249 }
250 250
251 //////////////////////////////////////////////////////////////////////////////// 251 ////////////////////////////////////////////////////////////////////////////////
252 // NetworkSection 252 // NetworkSection
253 253
254 // Network section for wifi settings 254 // Network section for wifi settings
255 class NetworkSection : public SettingsContentsSection, 255 class NetworkSection : public SettingsContentsSection,
256 public views::Combobox::Listener, 256 public views::Combobox::Listener,
257 public PasswordDialogDelegate, 257 public PasswordDialogDelegate,
258 public CrosNetworkLibrary::Observer { 258 public NetworkLibrary::Observer {
259 public: 259 public:
260 explicit NetworkSection(Profile* profile); 260 explicit NetworkSection(Profile* profile);
261 virtual ~NetworkSection(); 261 virtual ~NetworkSection();
262 262
263 // Overridden from views::Combobox::Listener: 263 // Overridden from views::Combobox::Listener:
264 virtual void ItemChanged(views::Combobox* sender, 264 virtual void ItemChanged(views::Combobox* sender,
265 int prev_index, 265 int prev_index,
266 int new_index); 266 int new_index);
267 267
268 // PasswordDialogDelegate implementation. 268 // PasswordDialogDelegate implementation.
269 virtual bool OnPasswordDialogCancel(); 269 virtual bool OnPasswordDialogCancel();
270 virtual bool OnPasswordDialogAccept(const std::string& ssid, 270 virtual bool OnPasswordDialogAccept(const std::string& ssid,
271 const string16& password); 271 const string16& password);
272 272
273 // CrosNetworkLibrary::Observer implementation. 273 // NetworkLibrary::Observer implementation.
274 virtual void NetworkChanged(CrosNetworkLibrary* obj); 274 virtual void NetworkChanged(NetworkLibrary* obj);
275 virtual void NetworkTraffic(CrosNetworkLibrary* obj, 275 virtual void NetworkTraffic(NetworkLibrary* obj, int traffic_type) {}
276 int traffic_type) {}
277 276
278 protected: 277 protected:
279 // SettingsContentsSection overrides: 278 // SettingsContentsSection overrides:
280 virtual void InitContents(GridLayout* layout); 279 virtual void InitContents(GridLayout* layout);
281 280
282 private: 281 private:
283 // The Combobox model for the list of wifi networks 282 // The Combobox model for the list of wifi networks
284 class WifiNetworkComboModel : public ComboboxModel { 283 class WifiNetworkComboModel : public ComboboxModel {
285 public: 284 public:
286 WifiNetworkComboModel() { 285 WifiNetworkComboModel() {
287 wifi_networks_ = CrosNetworkLibrary::Get()->wifi_networks(); 286 wifi_networks_ = NetworkLibrary::Get()->wifi_networks();
288 } 287 }
289 288
290 virtual int GetItemCount() { 289 virtual int GetItemCount() {
291 // Item count is always 1 more than number of networks. 290 // Item count is always 1 more than number of networks.
292 // If there are no networks, then we show a message stating that. 291 // If there are no networks, then we show a message stating that.
293 // If there are networks, the first item is empty. 292 // If there are networks, the first item is empty.
294 return static_cast<int>(wifi_networks_.size()) + 1; 293 return static_cast<int>(wifi_networks_.size()) + 1;
295 } 294 }
296 295
297 virtual std::wstring GetItemAt(int index) { 296 virtual std::wstring GetItemAt(int index) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 WifiNetworkComboModel wifi_ssid_model_; 334 WifiNetworkComboModel wifi_ssid_model_;
336 335
337 DISALLOW_COPY_AND_ASSIGN(NetworkSection); 336 DISALLOW_COPY_AND_ASSIGN(NetworkSection);
338 }; 337 };
339 338
340 NetworkSection::NetworkSection(Profile* profile) 339 NetworkSection::NetworkSection(Profile* profile)
341 : SettingsContentsSection(profile, 340 : SettingsContentsSection(profile,
342 IDS_OPTIONS_SETTINGS_SECTION_TITLE_NETWORK), 341 IDS_OPTIONS_SETTINGS_SECTION_TITLE_NETWORK),
343 wifi_ssid_combobox_(NULL), 342 wifi_ssid_combobox_(NULL),
344 last_selected_wifi_ssid_index_(0) { 343 last_selected_wifi_ssid_index_(0) {
345 CrosNetworkLibrary::Get()->AddObserver(this); 344 NetworkLibrary::Get()->AddObserver(this);
346 } 345 }
347 346
348 NetworkSection::~NetworkSection() { 347 NetworkSection::~NetworkSection() {
349 CrosNetworkLibrary::Get()->RemoveObserver(this); 348 NetworkLibrary::Get()->RemoveObserver(this);
350 } 349 }
351 350
352 void NetworkSection::ItemChanged(views::Combobox* sender, 351 void NetworkSection::ItemChanged(views::Combobox* sender,
353 int prev_index, 352 int prev_index,
354 int new_index) { 353 int new_index) {
355 if (new_index == prev_index) 354 if (new_index == prev_index)
356 return; 355 return;
357 356
358 // Don't allow switching to the first item (which is empty). 357 // Don't allow switching to the first item (which is empty).
359 if (new_index == 0) { 358 if (new_index == 0) {
360 wifi_ssid_combobox_->SetSelectedItem(prev_index); 359 wifi_ssid_combobox_->SetSelectedItem(prev_index);
361 return; 360 return;
362 } 361 }
363 362
364 if (!wifi_ssid_model_.HasWifiNetworks()) 363 if (!wifi_ssid_model_.HasWifiNetworks())
365 return; 364 return;
366 365
367 last_selected_wifi_ssid_index_ = prev_index; 366 last_selected_wifi_ssid_index_ = prev_index;
368 activated_wifi_network_ = wifi_ssid_model_.GetWifiNetworkAt(new_index); 367 activated_wifi_network_ = wifi_ssid_model_.GetWifiNetworkAt(new_index);
369 // Connect to wifi here. Open password page if appropriate. 368 // Connect to wifi here. Open password page if appropriate.
370 if (activated_wifi_network_.encrypted) { 369 if (activated_wifi_network_.encrypted) {
371 views::Window* window = views::Window::CreateChromeWindow( 370 views::Window* window = views::Window::CreateChromeWindow(
372 NULL, 371 NULL,
373 gfx::Rect(), 372 gfx::Rect(),
374 new PasswordDialogView(this, activated_wifi_network_.ssid)); 373 new PasswordDialogView(this, activated_wifi_network_.ssid));
375 window->SetIsAlwaysOnTop(true); 374 window->SetIsAlwaysOnTop(true);
376 window->Show(); 375 window->Show();
377 } else { 376 } else {
378 CrosNetworkLibrary::Get()->ConnectToWifiNetwork(activated_wifi_network_, 377 NetworkLibrary::Get()->ConnectToWifiNetwork(activated_wifi_network_,
379 string16()); 378 string16());
380 } 379 }
381 } 380 }
382 381
383 bool NetworkSection::OnPasswordDialogCancel() { 382 bool NetworkSection::OnPasswordDialogCancel() {
384 // Change combobox to previous setting. 383 // Change combobox to previous setting.
385 wifi_ssid_combobox_->SetSelectedItem(last_selected_wifi_ssid_index_); 384 wifi_ssid_combobox_->SetSelectedItem(last_selected_wifi_ssid_index_);
386 return true; 385 return true;
387 } 386 }
388 387
389 bool NetworkSection::OnPasswordDialogAccept(const std::string& ssid, 388 bool NetworkSection::OnPasswordDialogAccept(const std::string& ssid,
390 const string16& password) { 389 const string16& password) {
391 CrosNetworkLibrary::Get()->ConnectToWifiNetwork(activated_wifi_network_, 390 NetworkLibrary::Get()->ConnectToWifiNetwork(activated_wifi_network_,
392 password); 391 password);
393 return true; 392 return true;
394 } 393 }
395 394
396 void NetworkSection::NetworkChanged(CrosNetworkLibrary* obj) { 395 void NetworkSection::NetworkChanged(NetworkLibrary* obj) {
397 SelectWifi(obj->wifi_ssid()); 396 SelectWifi(obj->wifi_ssid());
398 } 397 }
399 398
400 void NetworkSection::InitContents(GridLayout* layout) { 399 void NetworkSection::InitContents(GridLayout* layout) {
401 wifi_ssid_combobox_ = new views::Combobox(&wifi_ssid_model_); 400 wifi_ssid_combobox_ = new views::Combobox(&wifi_ssid_model_);
402 wifi_ssid_combobox_->SetSelectedItem(last_selected_wifi_ssid_index_); 401 wifi_ssid_combobox_->SetSelectedItem(last_selected_wifi_ssid_index_);
403 wifi_ssid_combobox_->set_listener(this); 402 wifi_ssid_combobox_->set_listener(this);
404 403
405 layout->StartRow(0, single_column_view_set_id()); 404 layout->StartRow(0, single_column_view_set_id());
406 layout->AddView(wifi_ssid_combobox_); 405 layout->AddView(wifi_ssid_combobox_);
407 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); 406 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
408 407
409 // Select the initial connected wifi network. 408 // Select the initial connected wifi network.
410 SelectWifi(CrosNetworkLibrary::Get()->wifi_ssid()); 409 SelectWifi(NetworkLibrary::Get()->wifi_ssid());
411 } 410 }
412 411
413 void NetworkSection::SelectWifi(const std::string& wifi_ssid) { 412 void NetworkSection::SelectWifi(const std::string& wifi_ssid) {
414 if (wifi_ssid_model_.HasWifiNetworks() && wifi_ssid_combobox_) { 413 if (wifi_ssid_model_.HasWifiNetworks() && wifi_ssid_combobox_) {
415 // If we are not connected to any wifi network, wifi_ssid will be empty. 414 // If we are not connected to any wifi network, wifi_ssid will be empty.
416 // So we select the first item. 415 // So we select the first item.
417 if (wifi_ssid.empty()) { 416 if (wifi_ssid.empty()) {
418 wifi_ssid_combobox_->SetSelectedItem(0); 417 wifi_ssid_combobox_->SetSelectedItem(0);
419 } else { 418 } else {
420 // Loop through the list and select the ssid that matches. 419 // Loop through the list and select the ssid that matches.
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 if (!pref_name || *pref_name == prefs::kTouchpadSpeedFactor) { 572 if (!pref_name || *pref_name == prefs::kTouchpadSpeedFactor) {
574 double value = speed_factor_.GetValue(); 573 double value = speed_factor_.GetValue();
575 speed_factor_slider_->SetValue(value); 574 speed_factor_slider_->SetValue(value);
576 } 575 }
577 if (!pref_name || *pref_name == prefs::kTouchpadSensitivity) { 576 if (!pref_name || *pref_name == prefs::kTouchpadSensitivity) {
578 double value = sensitivity_.GetValue(); 577 double value = sensitivity_.GetValue();
579 sensitivity_slider_->SetValue(value); 578 sensitivity_slider_->SetValue(value);
580 } 579 }
581 } 580 }
582 581
583 } // namespace
584
585 //////////////////////////////////////////////////////////////////////////////// 582 ////////////////////////////////////////////////////////////////////////////////
586 // SettingsContentsView 583 // SettingsContentsView
587 584
588 //////////////////////////////////////////////////////////////////////////////// 585 ////////////////////////////////////////////////////////////////////////////////
589 // SettingsContentsView, OptionsPageView implementation: 586 // SettingsContentsView, OptionsPageView implementation:
590 587
591 void SettingsContentsView::InitControlLayout() { 588 void SettingsContentsView::InitControlLayout() {
592 GridLayout* layout = CreatePanelGridLayout(this); 589 GridLayout* layout = CreatePanelGridLayout(this);
593 SetLayoutManager(layout); 590 SetLayoutManager(layout);
594 591
595 int single_column_view_set_id = 0; 592 int single_column_view_set_id = 0;
596 ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); 593 ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id);
597 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, 594 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
598 GridLayout::USE_PREF, 0, 0); 595 GridLayout::USE_PREF, 0, 0);
599 596
600 layout->StartRow(0, single_column_view_set_id); 597 layout->StartRow(0, single_column_view_set_id);
601 layout->AddView(new DateTimeSection(profile())); 598 layout->AddView(new DateTimeSection(profile()));
602 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); 599 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
603 layout->StartRow(0, single_column_view_set_id); 600 layout->StartRow(0, single_column_view_set_id);
604 layout->AddView(new NetworkSection(profile())); 601 layout->AddView(new NetworkSection(profile()));
605 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); 602 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
606 layout->StartRow(0, single_column_view_set_id); 603 layout->StartRow(0, single_column_view_set_id);
607 layout->AddView(new TouchpadSection(profile())); 604 layout->AddView(new TouchpadSection(profile()));
608 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); 605 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
609 } 606 }
607
608 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698