OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "ash/system/power/tray_power.h" | 5 #include "ash/system/power/tray_power.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/system/date/date_view.h" | 8 #include "ash/system/date/date_view.h" |
9 #include "ash/system/power/power_supply_status.h" | 9 #include "ash/system/power/power_supply_status.h" |
10 #include "ash/system/tray/system_tray_delegate.h" | 10 #include "ash/system/tray/system_tray_delegate.h" |
11 #include "ash/system/tray/tray_constants.h" | 11 #include "ash/system/tray/tray_constants.h" |
| 12 #include "base/string_number_conversions.h" |
| 13 #include "base/stringprintf.h" |
12 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
13 #include "base/stringprintf.h" | 15 #include "grit/ash_strings.h" |
14 #include "grit/ui_resources.h" | 16 #include "grit/ui_resources.h" |
15 #include "third_party/skia/include/core/SkBitmap.h" | 17 #include "third_party/skia/include/core/SkBitmap.h" |
16 #include "third_party/skia/include/core/SkRect.h" | 18 #include "third_party/skia/include/core/SkRect.h" |
17 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
18 #include "ui/gfx/image/image.h" | 20 #include "ui/gfx/image/image.h" |
19 #include "ui/gfx/size.h" | 21 #include "ui/gfx/size.h" |
| 22 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/views/controls/button/button.h" | 23 #include "ui/views/controls/button/button.h" |
21 #include "ui/views/controls/button/text_button.h" | 24 #include "ui/views/controls/button/text_button.h" |
22 #include "ui/views/controls/image_view.h" | 25 #include "ui/views/controls/image_view.h" |
23 #include "ui/views/controls/label.h" | 26 #include "ui/views/controls/label.h" |
24 #include "ui/views/layout/box_layout.h" | 27 #include "ui/views/layout/box_layout.h" |
25 #include "ui/views/view.h" | 28 #include "ui/views/view.h" |
26 #include "ui/views/widget/widget.h" | 29 #include "ui/views/widget/widget.h" |
27 #include "unicode/fieldpos.h" | 30 #include "unicode/fieldpos.h" |
28 #include "unicode/fmtable.h" | 31 #include "unicode/fmtable.h" |
29 | 32 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 } | 116 } |
114 | 117 |
115 private: | 118 private: |
116 void UpdateText() { | 119 void UpdateText() { |
117 base::TimeDelta time = base::TimeDelta::FromSeconds( | 120 base::TimeDelta time = base::TimeDelta::FromSeconds( |
118 supply_status_.line_power_on ? | 121 supply_status_.line_power_on ? |
119 supply_status_.battery_seconds_to_full : | 122 supply_status_.battery_seconds_to_full : |
120 supply_status_.battery_seconds_to_empty); | 123 supply_status_.battery_seconds_to_empty); |
121 int hour = time.InHours(); | 124 int hour = time.InHours(); |
122 int min = (time - base::TimeDelta::FromHours(hour)).InMinutes(); | 125 int min = (time - base::TimeDelta::FromHours(hour)).InMinutes(); |
123 // TODO: Translation | 126 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
124 SetText(ASCIIToUTF16(base::StringPrintf("Battery: %.0lf%%\n%dh%02dm", | 127 if (hour && min) { |
125 supply_status_.battery_percentage, | 128 SetText(l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_BATTERY_STATUS, |
126 hour, min))); | 129 UTF8ToUTF16(base::DoubleToString(supply_status_.battery_percentage)), |
| 130 base::IntToString16(hour), |
| 131 base::IntToString16(min))); |
| 132 } else { |
| 133 if (supply_status_.line_power_on) { |
| 134 SetText(bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_FULL)); |
| 135 } else { |
| 136 // Completely discharged? ... ha? |
| 137 SetText(string16()); |
| 138 } |
| 139 } |
127 } | 140 } |
128 | 141 |
129 PowerSupplyStatus supply_status_; | 142 PowerSupplyStatus supply_status_; |
130 | 143 |
131 DISALLOW_COPY_AND_ASSIGN(PowerPopupView); | 144 DISALLOW_COPY_AND_ASSIGN(PowerPopupView); |
132 }; | 145 }; |
133 | 146 |
134 } // namespace tray | 147 } // namespace tray |
135 | 148 |
136 TrayPower::TrayPower() | 149 TrayPower::TrayPower() |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 208 |
196 void TrayPower::OnPowerStatusChanged(const PowerSupplyStatus& status) { | 209 void TrayPower::OnPowerStatusChanged(const PowerSupplyStatus& status) { |
197 if (power_tray_.get()) | 210 if (power_tray_.get()) |
198 power_tray_->UpdatePowerStatus(status); | 211 power_tray_->UpdatePowerStatus(status); |
199 if (power_.get()) | 212 if (power_.get()) |
200 power_->UpdatePowerStatus(status); | 213 power_->UpdatePowerStatus(status); |
201 } | 214 } |
202 | 215 |
203 } // namespace internal | 216 } // namespace internal |
204 } // namespace ash | 217 } // namespace ash |
OLD | NEW |