| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/status/network_menu_button.h" | 5 #include "chrome/browser/chromeos/status/network_menu_button.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 //////////////////////////////////////////////////////////////////////////////// | 114 //////////////////////////////////////////////////////////////////////////////// |
| 115 // NetworkMenuButton, private methods | 115 // NetworkMenuButton, private methods |
| 116 | 116 |
| 117 void NetworkMenuButton::SetNetworkIcon(NetworkLibrary* cros, | 117 void NetworkMenuButton::SetNetworkIcon(NetworkLibrary* cros, |
| 118 const Network* network) { | 118 const Network* network) { |
| 119 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 119 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 120 | 120 |
| 121 if (!cros || !CrosLibrary::Get()->EnsureLoaded()) { | 121 if (!cros || !CrosLibrary::Get()->EnsureLoaded()) { |
| 122 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0)); | 122 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0)); |
| 123 SetBadge(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_WARNING)); | 123 SetBadge(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_WARNING)); |
| 124 SetTooltipText(l10n_util::GetString( | 124 SetTooltipText(UTF16ToWide(l10n_util::GetStringUTF16( |
| 125 IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP)); | 125 IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP))); |
| 126 return; | 126 return; |
| 127 } | 127 } |
| 128 | 128 |
| 129 if (!cros->Connected() && !cros->Connecting()) { | 129 if (!cros->Connected() && !cros->Connecting()) { |
| 130 animation_connecting_.Stop(); | 130 animation_connecting_.Stop(); |
| 131 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0)); | 131 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0)); |
| 132 SetBadge(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_DISCONNECTED)); | 132 SetBadge(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_DISCONNECTED)); |
| 133 SetTooltipText(l10n_util::GetString( | 133 SetTooltipText(UTF16ToWide(l10n_util::GetStringUTF16( |
| 134 IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP)); | 134 IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP))); |
| 135 return; | 135 return; |
| 136 } | 136 } |
| 137 | 137 |
| 138 if (cros->wifi_connecting() || cros->cellular_connecting()) { | 138 if (cros->wifi_connecting() || cros->cellular_connecting()) { |
| 139 // Start the connecting animation if not running. | 139 // Start the connecting animation if not running. |
| 140 if (!animation_connecting_.is_animating()) { | 140 if (!animation_connecting_.is_animating()) { |
| 141 animation_connecting_.Reset(); | 141 animation_connecting_.Reset(); |
| 142 animation_connecting_.StartThrobbing(-1); | 142 animation_connecting_.StartThrobbing(-1); |
| 143 SetIcon(IconForNetworkConnecting(0, false)); | 143 SetIcon(IconForNetworkConnecting(0, false)); |
| 144 } | 144 } |
| 145 const WirelessNetwork* wireless = NULL; | 145 const WirelessNetwork* wireless = NULL; |
| 146 if (cros->wifi_connecting()) { | 146 if (cros->wifi_connecting()) { |
| 147 wireless = cros->wifi_network(); | 147 wireless = cros->wifi_network(); |
| 148 SetBadge(SkBitmap()); | 148 SetBadge(SkBitmap()); |
| 149 } else { // cellular_connecting | 149 } else { // cellular_connecting |
| 150 wireless = cros->cellular_network(); | 150 wireless = cros->cellular_network(); |
| 151 SetBadge(BadgeForNetworkTechnology(cros->cellular_network())); | 151 SetBadge(BadgeForNetworkTechnology(cros->cellular_network())); |
| 152 } | 152 } |
| 153 SetTooltipText( | 153 SetTooltipText(UTF16ToWide(l10n_util::GetStringFUTF16( |
| 154 l10n_util::GetStringF(wireless->configuring() ? | 154 wireless->configuring() ? IDS_STATUSBAR_NETWORK_CONFIGURING_TOOLTIP |
| 155 IDS_STATUSBAR_NETWORK_CONFIGURING_TOOLTIP : | 155 : IDS_STATUSBAR_NETWORK_CONNECTING_TOOLTIP, |
| 156 IDS_STATUSBAR_NETWORK_CONNECTING_TOOLTIP, | 156 UTF8ToUTF16(wireless->name())))); |
| 157 UTF8ToWide(wireless->name()))); | |
| 158 } else { | 157 } else { |
| 159 // Stop connecting animation since we are not connecting. | 158 // Stop connecting animation since we are not connecting. |
| 160 animation_connecting_.Stop(); | 159 animation_connecting_.Stop(); |
| 161 // Only set the icon, if it is an active network that changed. | 160 // Only set the icon, if it is an active network that changed. |
| 162 if (network && network->is_active()) { | 161 if (network && network->is_active()) { |
| 163 if (network->type() == TYPE_ETHERNET) { | 162 if (network->type() == TYPE_ETHERNET) { |
| 164 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_WIRED)); | 163 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_WIRED)); |
| 165 SetBadge(SkBitmap()); | 164 SetBadge(SkBitmap()); |
| 166 SetTooltipText( | 165 SetTooltipText( |
| 167 l10n_util::GetStringF( | 166 UTF16ToWide(l10n_util::GetStringFUTF16( |
| 168 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, | 167 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, |
| 169 l10n_util::GetString(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET))); | 168 l10n_util::GetStringUTF16( |
| 169 IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET)))); |
| 170 } else if (network->type() == TYPE_WIFI) { | 170 } else if (network->type() == TYPE_WIFI) { |
| 171 const WifiNetwork* wifi = static_cast<const WifiNetwork*>(network); | 171 const WifiNetwork* wifi = static_cast<const WifiNetwork*>(network); |
| 172 SetIcon(IconForNetworkStrength(wifi, false)); | 172 SetIcon(IconForNetworkStrength(wifi, false)); |
| 173 SetBadge(SkBitmap()); | 173 SetBadge(SkBitmap()); |
| 174 SetTooltipText(l10n_util::GetStringF( | 174 SetTooltipText(UTF16ToWide(l10n_util::GetStringFUTF16( |
| 175 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, | 175 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, |
| 176 UTF8ToWide(wifi->name()))); | 176 UTF8ToUTF16(wifi->name())))); |
| 177 } else if (network->type() == TYPE_CELLULAR) { | 177 } else if (network->type() == TYPE_CELLULAR) { |
| 178 const CellularNetwork* cellular = | 178 const CellularNetwork* cellular = |
| 179 static_cast<const CellularNetwork*>(network); | 179 static_cast<const CellularNetwork*>(network); |
| 180 SetIcon(IconForNetworkStrength(cellular, false)); | 180 SetIcon(IconForNetworkStrength(cellular, false)); |
| 181 SetBadge(BadgeForNetworkTechnology(cellular)); | 181 SetBadge(BadgeForNetworkTechnology(cellular)); |
| 182 SetTooltipText(l10n_util::GetStringF( | 182 SetTooltipText(UTF16ToWide(l10n_util::GetStringFUTF16( |
| 183 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, | 183 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, |
| 184 UTF8ToWide(cellular->name()))); | 184 UTF8ToUTF16(cellular->name())))); |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 | 189 |
| 190 void NetworkMenuButton::RefreshNetworkObserver(NetworkLibrary* cros) { | 190 void NetworkMenuButton::RefreshNetworkObserver(NetworkLibrary* cros) { |
| 191 const Network* network = cros->active_network(); | 191 const Network* network = cros->active_network(); |
| 192 std::string new_network = network ? network->service_path() : std::string(); | 192 std::string new_network = network ? network->service_path() : std::string(); |
| 193 if (active_network_ != new_network) { | 193 if (active_network_ != new_network) { |
| 194 if (!active_network_.empty()) { | 194 if (!active_network_.empty()) { |
| 195 cros->RemoveNetworkObserver(active_network_, this); | 195 cros->RemoveNetworkObserver(active_network_, this); |
| 196 } | 196 } |
| 197 if (!new_network.empty()) { | 197 if (!new_network.empty()) { |
| 198 cros->AddNetworkObserver(new_network, this); | 198 cros->AddNetworkObserver(new_network, this); |
| 199 } | 199 } |
| 200 active_network_ = new_network; | 200 active_network_ = new_network; |
| 201 } | 201 } |
| 202 } | 202 } |
| 203 | 203 |
| 204 } // namespace chromeos | 204 } // namespace chromeos |
| OLD | NEW |