| OLD | NEW |
| 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/options/internet_page_view.h" | 5 #include "chrome/browser/chromeos/options/internet_page_view.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "app/combobox_model.h" | 9 #include "app/combobox_model.h" |
| 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 10 #include "chrome/browser/chromeos/cros/network_library.h" | 11 #include "chrome/browser/chromeos/cros/network_library.h" |
| 11 #include "chrome/browser/chromeos/options/network_config_view.h" | 12 #include "chrome/browser/chromeos/options/network_config_view.h" |
| 12 #include "chrome/browser/chromeos/status/network_menu_button.h" | 13 #include "chrome/browser/chromeos/status/network_menu_button.h" |
| 13 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 14 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
| 15 #include "views/controls/button/native_button.h" | 16 #include "views/controls/button/native_button.h" |
| 16 #include "views/controls/combobox/combobox.h" | 17 #include "views/controls/combobox/combobox.h" |
| 17 #include "views/controls/image_view.h" | 18 #include "views/controls/image_view.h" |
| 18 #include "views/window/window.h" | 19 #include "views/window/window.h" |
| 19 | 20 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 45 | 46 |
| 46 protected: | 47 protected: |
| 47 // SettingsPageSection overrides: | 48 // SettingsPageSection overrides: |
| 48 virtual void InitContents(GridLayout* layout); | 49 virtual void InitContents(GridLayout* layout); |
| 49 | 50 |
| 50 private: | 51 private: |
| 51 // The Combobox model for the list of wifi networks | 52 // The Combobox model for the list of wifi networks |
| 52 class WifiNetworkComboModel : public ComboboxModel { | 53 class WifiNetworkComboModel : public ComboboxModel { |
| 53 public: | 54 public: |
| 54 WifiNetworkComboModel() { | 55 WifiNetworkComboModel() { |
| 55 wifi_networks_ = NetworkLibrary::Get()->wifi_networks(); | 56 wifi_networks_ = |
| 57 CrosLibrary::Get()->GetNetworkLibrary()->wifi_networks(); |
| 56 } | 58 } |
| 57 | 59 |
| 58 virtual int GetItemCount() { | 60 virtual int GetItemCount() { |
| 59 // Item count is always 1 more than number of networks. | 61 // Item count is always 1 more than number of networks. |
| 60 // If there are no networks, then we show a message stating that. | 62 // If there are no networks, then we show a message stating that. |
| 61 // If there are networks, the first item is empty. | 63 // If there are networks, the first item is empty. |
| 62 return static_cast<int>(wifi_networks_.size()) + 1; | 64 return static_cast<int>(wifi_networks_.size()) + 1; |
| 63 } | 65 } |
| 64 | 66 |
| 65 virtual std::wstring GetItemAt(int index) { | 67 virtual std::wstring GetItemAt(int index) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 // The wifi ssid models. | 119 // The wifi ssid models. |
| 118 WifiNetworkComboModel wifi_ssid_model_; | 120 WifiNetworkComboModel wifi_ssid_model_; |
| 119 | 121 |
| 120 DISALLOW_COPY_AND_ASSIGN(NetworkSection); | 122 DISALLOW_COPY_AND_ASSIGN(NetworkSection); |
| 121 }; | 123 }; |
| 122 | 124 |
| 123 NetworkSection::NetworkSection(Profile* profile) | 125 NetworkSection::NetworkSection(Profile* profile) |
| 124 : SettingsPageSection(profile, IDS_OPTIONS_SETTINGS_SECTION_TITLE_NETWORK), | 126 : SettingsPageSection(profile, IDS_OPTIONS_SETTINGS_SECTION_TITLE_NETWORK), |
| 125 wifi_ssid_combobox_(NULL), | 127 wifi_ssid_combobox_(NULL), |
| 126 last_selected_wifi_ssid_index_(0) { | 128 last_selected_wifi_ssid_index_(0) { |
| 127 NetworkLibrary::Get()->AddObserver(this); | 129 CrosLibrary::Get()->GetNetworkLibrary()->AddObserver(this); |
| 128 } | 130 } |
| 129 | 131 |
| 130 NetworkSection::~NetworkSection() { | 132 NetworkSection::~NetworkSection() { |
| 131 NetworkLibrary::Get()->RemoveObserver(this); | 133 CrosLibrary::Get()->GetNetworkLibrary()->RemoveObserver(this); |
| 132 } | 134 } |
| 133 | 135 |
| 134 void NetworkSection::ItemChanged(views::Combobox* sender, | 136 void NetworkSection::ItemChanged(views::Combobox* sender, |
| 135 int prev_index, | 137 int prev_index, |
| 136 int new_index) { | 138 int new_index) { |
| 137 if (new_index == prev_index) | 139 if (new_index == prev_index) |
| 138 return; | 140 return; |
| 139 | 141 |
| 140 // Don't allow switching to the first item (which is empty). | 142 // Don't allow switching to the first item (which is empty). |
| 141 if (new_index == 0) { | 143 if (new_index == 0) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 154 wifi_ssid_combobox_->SetSelectedItem(last_selected_wifi_ssid_index_); | 156 wifi_ssid_combobox_->SetSelectedItem(last_selected_wifi_ssid_index_); |
| 155 if (activated_wifi_network_.encrypted) { | 157 if (activated_wifi_network_.encrypted) { |
| 156 NetworkConfigView* view = | 158 NetworkConfigView* view = |
| 157 new NetworkConfigView(activated_wifi_network_, true); | 159 new NetworkConfigView(activated_wifi_network_, true); |
| 158 views::Window* window = views::Window::CreateChromeWindow( | 160 views::Window* window = views::Window::CreateChromeWindow( |
| 159 NULL, gfx::Rect(), view); | 161 NULL, gfx::Rect(), view); |
| 160 window->SetIsAlwaysOnTop(true); | 162 window->SetIsAlwaysOnTop(true); |
| 161 window->Show(); | 163 window->Show(); |
| 162 view->SetLoginTextfieldFocus(); | 164 view->SetLoginTextfieldFocus(); |
| 163 } else { | 165 } else { |
| 164 NetworkLibrary::Get()->ConnectToWifiNetwork(activated_wifi_network_, | 166 CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork( |
| 165 string16()); | 167 activated_wifi_network_, |
| 168 string16()); |
| 166 } | 169 } |
| 167 } | 170 } |
| 168 | 171 |
| 169 void NetworkSection::ButtonPressed(views::Button* sender, | 172 void NetworkSection::ButtonPressed(views::Button* sender, |
| 170 const views::Event& event) { | 173 const views::Event& event) { |
| 171 if (sender == ethernet_options_button_) { | 174 if (sender == ethernet_options_button_) { |
| 172 NetworkConfigView* view = | 175 NetworkConfigView* view = |
| 173 new NetworkConfigView(NetworkLibrary::Get()->ethernet_network()); | 176 new NetworkConfigView( |
| 177 CrosLibrary::Get()->GetNetworkLibrary()->ethernet_network()); |
| 174 views::Window* window = views::Window::CreateChromeWindow( | 178 views::Window* window = views::Window::CreateChromeWindow( |
| 175 NULL, gfx::Rect(), view); | 179 NULL, gfx::Rect(), view); |
| 176 window->SetIsAlwaysOnTop(true); | 180 window->SetIsAlwaysOnTop(true); |
| 177 window->Show(); | 181 window->Show(); |
| 178 } else if (sender == wifi_options_button_) { | 182 } else if (sender == wifi_options_button_) { |
| 179 NetworkConfigView* view = | 183 NetworkConfigView* view = |
| 180 new NetworkConfigView(activated_wifi_network_, false); | 184 new NetworkConfigView(activated_wifi_network_, false); |
| 181 views::Window* window = views::Window::CreateChromeWindow( | 185 views::Window* window = views::Window::CreateChromeWindow( |
| 182 NULL, gfx::Rect(), view); | 186 NULL, gfx::Rect(), view); |
| 183 window->SetIsAlwaysOnTop(true); | 187 window->SetIsAlwaysOnTop(true); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 layout->StartRow(0, quad_column_view_set_id); | 346 layout->StartRow(0, quad_column_view_set_id); |
| 343 layout->SkipColumns(1); | 347 layout->SkipColumns(1); |
| 344 cellular_status_label_ = new views::Label(); | 348 cellular_status_label_ = new views::Label(); |
| 345 cellular_status_label_->SetFont(rb.GetFont(ResourceBundle::SmallFont)); | 349 cellular_status_label_->SetFont(rb.GetFont(ResourceBundle::SmallFont)); |
| 346 cellular_status_label_->SetColor(SK_ColorLTGRAY); | 350 cellular_status_label_->SetColor(SK_ColorLTGRAY); |
| 347 cellular_status_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 351 cellular_status_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 348 layout->AddView(cellular_status_label_); | 352 layout->AddView(cellular_status_label_); |
| 349 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 353 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 350 | 354 |
| 351 // Call NetworkChanged to set initial values. | 355 // Call NetworkChanged to set initial values. |
| 352 NetworkChanged(NetworkLibrary::Get()); | 356 NetworkChanged(CrosLibrary::Get()->GetNetworkLibrary()); |
| 353 } | 357 } |
| 354 | 358 |
| 355 void NetworkSection::SelectWifi(const std::string& wifi_ssid) { | 359 void NetworkSection::SelectWifi(const std::string& wifi_ssid) { |
| 356 if (wifi_ssid_model_.HasWifiNetworks() && wifi_ssid_combobox_) { | 360 if (wifi_ssid_model_.HasWifiNetworks() && wifi_ssid_combobox_) { |
| 357 // If we are not connected to any wifi network, wifi_ssid will be empty. | 361 // If we are not connected to any wifi network, wifi_ssid will be empty. |
| 358 // So we select the first item. | 362 // So we select the first item. |
| 359 if (wifi_ssid.empty()) { | 363 if (wifi_ssid.empty()) { |
| 360 wifi_ssid_combobox_->SetSelectedItem(0); | 364 wifi_ssid_combobox_->SetSelectedItem(0); |
| 361 } else { | 365 } else { |
| 362 // Loop through the list and select the ssid that matches. | 366 // Loop through the list and select the ssid that matches. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 385 ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); | 389 ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); |
| 386 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | 390 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
| 387 GridLayout::USE_PREF, 0, 0); | 391 GridLayout::USE_PREF, 0, 0); |
| 388 | 392 |
| 389 layout->StartRow(0, single_column_view_set_id); | 393 layout->StartRow(0, single_column_view_set_id); |
| 390 layout->AddView(new NetworkSection(profile())); | 394 layout->AddView(new NetworkSection(profile())); |
| 391 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 395 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 392 } | 396 } |
| 393 | 397 |
| 394 } // namespace chromeos | 398 } // namespace chromeos |
| OLD | NEW |