Merge lp:~charlesk/indicator-power/lp-1388235-use-new-battery-icons-rtm-14.09 into lp:indicator-power/rtm-14.09

Proposed by Charles Kerr
Status: Merged
Approved by: Charles Kerr
Approved revision: 274
Merged at revision: 274
Proposed branch: lp:~charlesk/indicator-power/lp-1388235-use-new-battery-icons-rtm-14.09
Merge into: lp:indicator-power/rtm-14.09
Diff against target: 207 lines (+60/-6)
3 files modified
src/device.c (+32/-3)
tests/manual (+8/-1)
tests/test-device.cc (+20/-2)
To merge this branch: bzr merge lp:~charlesk/indicator-power/lp-1388235-use-new-battery-icons-rtm-14.09
Reviewer Review Type Date Requested Status
dobey (community) Approve
Review via email: mp+249684@code.launchpad.net

Commit message

Use the new power level icons for a more accurate display of the battery level.

Description of the change

rtm-14.09 backport of <https://code.launchpad.net/~charlesk/indicator-power/lp-1388235-use-new-battery-icons/+merge/246232>. The description and checklist there also applies to this MP.

To post a comment you must log in.
Revision history for this message
dobey (dobey) wrote :

Looks ok to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/device.c'
2--- src/device.c 2014-07-29 14:49:19 +0000
3+++ src/device.c 2015-02-13 16:46:19 +0000
4@@ -319,7 +319,23 @@
5 }
6
7 static const gchar *
8-get_device_icon_index (gdouble percentage)
9+get_closest_10_percent_percentage (gdouble percentage)
10+{
11+ if (percentage >= 95) return "100";
12+ if (percentage >= 85) return "090";
13+ if (percentage >= 75) return "080";
14+ if (percentage >= 65) return "070";
15+ if (percentage >= 55) return "060";
16+ if (percentage >= 45) return "050";
17+ if (percentage >= 35) return "040";
18+ if (percentage >= 21) return "030"; /* don't round down to 20: see bug #1388235 */
19+ if (percentage >= 15) return "020";
20+ if (percentage >= 5) return "010";
21+ return "000";
22+}
23+
24+static const gchar *
25+get_fallback_device_icon_index (gdouble percentage)
26 {
27 if (percentage >= 90) return "100";
28 if (percentage >= 70) return "080";
29@@ -364,6 +380,7 @@
30 {
31 const gchar *suffix_str;
32 const gchar *index_str;
33+ const gchar *index_str_2;
34
35 /* LCOV_EXCL_START */
36 g_return_val_if_fail (INDICATOR_IS_POWER_DEVICE(device), NULL);
37@@ -406,9 +423,15 @@
38
39 case UP_DEVICE_STATE_CHARGING:
40 suffix_str = get_device_icon_suffix (percentage);
41- index_str = get_device_icon_index (percentage);
42+ index_str = get_closest_10_percent_percentage (percentage);
43 g_ptr_array_add (names, g_strdup_printf ("%s-%s-charging", kind_str, index_str));
44 g_ptr_array_add (names, g_strdup_printf ("gpm-%s-%s-charging", kind_str, index_str));
45+ index_str_2 = get_fallback_device_icon_index (percentage);
46+ if (g_strcmp0 (index_str, index_str_2))
47+ {
48+ g_ptr_array_add (names, g_strdup_printf ("%s-%s-charging", kind_str, index_str_2));
49+ g_ptr_array_add (names, g_strdup_printf ("gpm-%s-%s-charging", kind_str, index_str_2));
50+ }
51 g_ptr_array_add (names, g_strdup_printf ("%s-%s-charging-symbolic", kind_str, suffix_str));
52 g_ptr_array_add (names, g_strdup_printf ("%s-%s-charging", kind_str, suffix_str));
53 break;
54@@ -417,9 +440,15 @@
55 case UP_DEVICE_STATE_DISCHARGING:
56 case UP_DEVICE_STATE_PENDING_DISCHARGE:
57 suffix_str = get_device_icon_suffix (percentage);
58- index_str = get_device_icon_index (percentage);
59+ index_str = get_closest_10_percent_percentage (percentage);
60 g_ptr_array_add (names, g_strdup_printf ("%s-%s", kind_str, index_str));
61 g_ptr_array_add (names, g_strdup_printf ("gpm-%s-%s", kind_str, index_str));
62+ index_str_2 = get_fallback_device_icon_index (percentage);
63+ if (g_strcmp0 (index_str, index_str_2))
64+ {
65+ g_ptr_array_add (names, g_strdup_printf ("%s-%s", kind_str, index_str_2));
66+ g_ptr_array_add (names, g_strdup_printf ("gpm-%s-%s", kind_str, index_str_2));
67+ }
68 g_ptr_array_add (names, g_strdup_printf ("%s-%s-symbolic", kind_str, suffix_str));
69 g_ptr_array_add (names, g_strdup_printf ("%s-%s", kind_str, suffix_str));
70 break;
71
72=== modified file 'tests/manual'
73--- tests/manual 2014-10-14 19:09:32 +0000
74+++ tests/manual 2015-02-13 16:46:19 +0000
75@@ -13,7 +13,6 @@
76 --object-path /com/canonical/indicator/power/Testing \
77 --method org.freedesktop.DBus.Properties.GetAll \
78 com.canonical.indicator.power.Testing
79-({'MockBatteryEnabled': <false>, 'MockBatteryLevel': <uint32 50>, 'MockBatteryState': <'discharging'>, 'MockBatteryMinutesLeft': <uint32 30>},)
80
81 Enable the mock battery:
82
83@@ -88,6 +87,14 @@
84 <dd>ubuntu-system-settings should be launched to the Battery page </dd>
85 </dl>
86
87+Test-case indicator-power/low-power-icon
88+<dl>
89+ <dt>Wait for the system's battery level to drop to 21% (or fake it, see 'Notes on Battery Testing' above)</dt>
90+ <dd>The indicator's icon should use the non-critical coloring (eg, grey)</dd>
91+ <dt>Wait for the system's battery level to drop to 20% (or fake it, see 'Notes on Battery Testing' above)</dt>
92+ <dd>The indicator's icon should use the critical coloring (eg, red)</dd>
93+</dl>
94+
95 Test-case indicator-power/device-brightness-slider
96 <dl>
97 <dt>On a device, pull down the power indicator's menu</dt>
98
99=== modified file 'tests/test-device.cc'
100--- tests/test-device.cc 2014-09-08 16:16:29 +0000
101+++ tests/test-device.cc 2015-02-13 16:46:19 +0000
102@@ -297,7 +297,6 @@
103 g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind,
104 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_EMPTY,
105 NULL);
106-
107 g_string_append_printf (expected, "%s-empty-symbolic;", kind_str);
108 g_string_append_printf (expected, "gpm-%s-empty;", kind_str);
109 g_string_append_printf (expected, "gpm-%s-000;", kind_str);
110@@ -323,7 +322,6 @@
111 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING,
112 INDICATOR_POWER_DEVICE_PERCENTAGE, 95.0,
113 NULL);
114-
115 g_string_append_printf (expected, "%s-100-charging;", kind_str);
116 g_string_append_printf (expected, "gpm-%s-100-charging;", kind_str);
117 g_string_append_printf (expected, "%s-full-charging-symbolic;", kind_str);
118@@ -336,6 +334,8 @@
119 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING,
120 INDICATOR_POWER_DEVICE_PERCENTAGE, 85.0,
121 NULL);
122+ g_string_append_printf (expected, "%s-090-charging;", kind_str);
123+ g_string_append_printf (expected, "gpm-%s-090-charging;", kind_str);
124 g_string_append_printf (expected, "%s-080-charging;", kind_str);
125 g_string_append_printf (expected, "gpm-%s-080-charging;", kind_str);
126 g_string_append_printf (expected, "%s-full-charging-symbolic;", kind_str);
127@@ -348,6 +348,8 @@
128 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING,
129 INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0,
130 NULL);
131+ g_string_append_printf (expected, "%s-050-charging;", kind_str);
132+ g_string_append_printf (expected, "gpm-%s-050-charging;", kind_str);
133 g_string_append_printf (expected, "%s-060-charging;", kind_str);
134 g_string_append_printf (expected, "gpm-%s-060-charging;", kind_str);
135 g_string_append_printf (expected, "%s-good-charging-symbolic;", kind_str);
136@@ -360,6 +362,8 @@
137 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING,
138 INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0,
139 NULL);
140+ g_string_append_printf (expected, "%s-030-charging;", kind_str);
141+ g_string_append_printf (expected, "gpm-%s-030-charging;", kind_str);
142 g_string_append_printf (expected, "%s-020-charging;", kind_str);
143 g_string_append_printf (expected, "gpm-%s-020-charging;", kind_str);
144 g_string_append_printf (expected, "%s-low-charging-symbolic;", kind_str);
145@@ -372,6 +376,8 @@
146 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING,
147 INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0,
148 NULL);
149+ g_string_append_printf (expected, "%s-010-charging;", kind_str);
150+ g_string_append_printf (expected, "gpm-%s-010-charging;", kind_str);
151 g_string_append_printf (expected, "%s-000-charging;", kind_str);
152 g_string_append_printf (expected, "gpm-%s-000-charging;", kind_str);
153 g_string_append_printf (expected, "%s-caution-charging-symbolic;", kind_str);
154@@ -396,6 +402,8 @@
155 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING,
156 INDICATOR_POWER_DEVICE_PERCENTAGE, 85.0,
157 NULL);
158+ g_string_append_printf (expected, "%s-090;", kind_str);
159+ g_string_append_printf (expected, "gpm-%s-090;", kind_str);
160 g_string_append_printf (expected, "%s-080;", kind_str);
161 g_string_append_printf (expected, "gpm-%s-080;", kind_str);
162 g_string_append_printf (expected, "%s-full-symbolic;", kind_str);
163@@ -409,6 +417,8 @@
164 INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0,
165 INDICATOR_POWER_DEVICE_TIME, guint64(60*60),
166 NULL);
167+ g_string_append_printf (expected, "%s-050;", kind_str);
168+ g_string_append_printf (expected, "gpm-%s-050;", kind_str);
169 g_string_append_printf (expected, "%s-060;", kind_str);
170 g_string_append_printf (expected, "gpm-%s-060;", kind_str);
171 g_string_append_printf (expected, "%s-good-symbolic;", kind_str);
172@@ -422,6 +432,8 @@
173 INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0,
174 INDICATOR_POWER_DEVICE_TIME, guint64(60*60),
175 NULL);
176+ g_string_append_printf (expected, "%s-030;", kind_str);
177+ g_string_append_printf (expected, "gpm-%s-030;", kind_str);
178 g_string_append_printf (expected, "%s-020;", kind_str);
179 g_string_append_printf (expected, "gpm-%s-020;", kind_str);
180 g_string_append_printf (expected, "%s-low-symbolic;", kind_str);
181@@ -435,6 +447,8 @@
182 INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0,
183 INDICATOR_POWER_DEVICE_TIME, guint64(60*15),
184 NULL);
185+ g_string_append_printf (expected, "%s-030;", kind_str);
186+ g_string_append_printf (expected, "gpm-%s-030;", kind_str);
187 g_string_append_printf (expected, "%s-020;", kind_str);
188 g_string_append_printf (expected, "gpm-%s-020;", kind_str);
189 g_string_append_printf (expected, "%s-low-symbolic;", kind_str);
190@@ -448,6 +462,8 @@
191 INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0,
192 INDICATOR_POWER_DEVICE_TIME, guint64(60*60),
193 NULL);
194+ g_string_append_printf (expected, "%s-010;", kind_str);
195+ g_string_append_printf (expected, "gpm-%s-010;", kind_str);
196 g_string_append_printf (expected, "%s-000;", kind_str);
197 g_string_append_printf (expected, "gpm-%s-000;", kind_str);
198 g_string_append_printf (expected, "%s-caution-symbolic;", kind_str);
199@@ -461,6 +477,8 @@
200 INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0,
201 INDICATOR_POWER_DEVICE_TIME, guint64(60*15),
202 NULL);
203+ g_string_append_printf (expected, "%s-010;", kind_str);
204+ g_string_append_printf (expected, "gpm-%s-010;", kind_str);
205 g_string_append_printf (expected, "%s-000;", kind_str);
206 g_string_append_printf (expected, "gpm-%s-000;", kind_str);
207 g_string_append_printf (expected, "%s-caution-symbolic;", kind_str);

Subscribers

People subscribed via source and target branches