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

Side by Side Diff: chrome/browser/chromeos/status/power_menu_button.cc

Issue 3056029: Move the number conversions from string_util to a new file.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 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) 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/power_menu_button.h" 5 #include "chrome/browser/chromeos/status/power_menu_button.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/string_number_conversions.h"
9 #include "base/time.h" 10 #include "base/time.h"
10 #include "chrome/browser/chromeos/cros/cros_library.h" 11 #include "chrome/browser/chromeos/cros/cros_library.h"
11 #include "gfx/canvas.h" 12 #include "gfx/canvas.h"
12 #include "grit/generated_resources.h" 13 #include "grit/generated_resources.h"
13 #include "grit/theme_resources.h" 14 #include "grit/theme_resources.h"
14 15
15 namespace chromeos { 16 namespace chromeos {
16 17
17 //////////////////////////////////////////////////////////////////////////////// 18 ////////////////////////////////////////////////////////////////////////////////
18 // PowerMenuButton 19 // PowerMenuButton
(...skipping 25 matching lines...) Expand all
44 } 45 }
45 46
46 string16 PowerMenuButton::GetLabelAt(int index) const { 47 string16 PowerMenuButton::GetLabelAt(int index) const {
47 PowerLibrary* cros = CrosLibrary::Get()->GetPowerLibrary(); 48 PowerLibrary* cros = CrosLibrary::Get()->GetPowerLibrary();
48 // The first item shows the percentage of battery left. 49 // The first item shows the percentage of battery left.
49 if (index == 0) { 50 if (index == 0) {
50 // If fully charged, always show 100% even if internal number is a bit less. 51 // If fully charged, always show 100% even if internal number is a bit less.
51 double percent = cros->battery_fully_charged() ? 100 : 52 double percent = cros->battery_fully_charged() ? 100 :
52 cros->battery_percentage(); 53 cros->battery_percentage();
53 return l10n_util::GetStringFUTF16(IDS_STATUSBAR_BATTERY_PERCENTAGE, 54 return l10n_util::GetStringFUTF16(IDS_STATUSBAR_BATTERY_PERCENTAGE,
54 IntToString16(static_cast<int>(percent))); 55 base::IntToString16(static_cast<int>(percent)));
55 } 56 }
56 57
57 // The second item shows the battery is charged if it is. 58 // The second item shows the battery is charged if it is.
58 if (cros->battery_fully_charged()) 59 if (cros->battery_fully_charged())
59 return l10n_util::GetStringUTF16(IDS_STATUSBAR_BATTERY_IS_CHARGED); 60 return l10n_util::GetStringUTF16(IDS_STATUSBAR_BATTERY_IS_CHARGED);
60 61
61 // If battery is in an intermediate charge state, we show how much time left. 62 // If battery is in an intermediate charge state, we show how much time left.
62 base::TimeDelta time = cros->line_power_on() ? cros->battery_time_to_full() : 63 base::TimeDelta time = cros->line_power_on() ? cros->battery_time_to_full() :
63 cros->battery_time_to_empty(); 64 cros->battery_time_to_empty();
64 if (time.InSeconds() == 0) { 65 if (time.InSeconds() == 0) {
65 // If time is 0, then that means we are still calculating how much time. 66 // If time is 0, then that means we are still calculating how much time.
66 // Depending if line power is on, we either show a message saying that we 67 // Depending if line power is on, we either show a message saying that we
67 // are calculating time until full or calculating remaining time. 68 // are calculating time until full or calculating remaining time.
68 int msg = cros->line_power_on() ? 69 int msg = cros->line_power_on() ?
69 IDS_STATUSBAR_BATTERY_CALCULATING_TIME_UNTIL_FULL : 70 IDS_STATUSBAR_BATTERY_CALCULATING_TIME_UNTIL_FULL :
70 IDS_STATUSBAR_BATTERY_CALCULATING_TIME_UNTIL_EMPTY; 71 IDS_STATUSBAR_BATTERY_CALCULATING_TIME_UNTIL_EMPTY;
71 return l10n_util::GetStringUTF16(msg); 72 return l10n_util::GetStringUTF16(msg);
72 } else { 73 } else {
73 // Depending if line power is on, we either show a message saying XX:YY 74 // Depending if line power is on, we either show a message saying XX:YY
74 // until full or XX:YY remaining where XX is number of hours and YY is 75 // until full or XX:YY remaining where XX is number of hours and YY is
75 // number of minutes. 76 // number of minutes.
76 int msg = cros->line_power_on() ? IDS_STATUSBAR_BATTERY_TIME_UNTIL_FULL : 77 int msg = cros->line_power_on() ? IDS_STATUSBAR_BATTERY_TIME_UNTIL_FULL :
77 IDS_STATUSBAR_BATTERY_TIME_UNTIL_EMPTY; 78 IDS_STATUSBAR_BATTERY_TIME_UNTIL_EMPTY;
78 int hour = time.InHours(); 79 int hour = time.InHours();
79 int min = (time - base::TimeDelta::FromHours(hour)).InMinutes(); 80 int min = (time - base::TimeDelta::FromHours(hour)).InMinutes();
80 string16 hour_str = IntToString16(hour); 81 string16 hour_str = base::IntToString16(hour);
81 string16 min_str = IntToString16(min); 82 string16 min_str = base::IntToString16(min);
82 // Append a "0" before the minute if it's only a single digit. 83 // Append a "0" before the minute if it's only a single digit.
83 if (min < 10) 84 if (min < 10)
84 min_str = ASCIIToUTF16("0") + min_str; 85 min_str = ASCIIToUTF16("0") + min_str;
85 return l10n_util::GetStringFUTF16(msg, hour_str, min_str); 86 return l10n_util::GetStringFUTF16(msg, hour_str, min_str);
86 } 87 }
87 } 88 }
88 89
89 //////////////////////////////////////////////////////////////////////////////// 90 ////////////////////////////////////////////////////////////////////////////////
90 // PowerMenuButton, views::ViewMenuDelegate implementation: 91 // PowerMenuButton, views::ViewMenuDelegate implementation:
91 92
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 index = std::max(std::min(index, kNumPowerImages - 1), 0); 171 index = std::max(std::min(index, kNumPowerImages - 1), 0);
171 icon_id_ = cros->line_power_on() ? 172 icon_id_ = cros->line_power_on() ?
172 kChargingImages[index] : kDischargingImages[index]; 173 kChargingImages[index] : kDischargingImages[index];
173 } 174 }
174 } 175 }
175 SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed(icon_id_)); 176 SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed(icon_id_));
176 SchedulePaint(); 177 SchedulePaint();
177 } 178 }
178 179
179 } // namespace chromeos 180 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/network_library.cc ('k') | chrome/browser/chromeos/update_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698