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
=== modified file 'src/device.c'
--- src/device.c 2014-07-29 14:49:19 +0000
+++ src/device.c 2015-02-13 16:46:19 +0000
@@ -319,7 +319,23 @@
319}319}
320320
321static const gchar *321static const gchar *
322get_device_icon_index (gdouble percentage)322get_closest_10_percent_percentage (gdouble percentage)
323{
324 if (percentage >= 95) return "100";
325 if (percentage >= 85) return "090";
326 if (percentage >= 75) return "080";
327 if (percentage >= 65) return "070";
328 if (percentage >= 55) return "060";
329 if (percentage >= 45) return "050";
330 if (percentage >= 35) return "040";
331 if (percentage >= 21) return "030"; /* don't round down to 20: see bug #1388235 */
332 if (percentage >= 15) return "020";
333 if (percentage >= 5) return "010";
334 return "000";
335}
336
337static const gchar *
338get_fallback_device_icon_index (gdouble percentage)
323{339{
324 if (percentage >= 90) return "100";340 if (percentage >= 90) return "100";
325 if (percentage >= 70) return "080";341 if (percentage >= 70) return "080";
@@ -364,6 +380,7 @@
364{380{
365 const gchar *suffix_str;381 const gchar *suffix_str;
366 const gchar *index_str;382 const gchar *index_str;
383 const gchar *index_str_2;
367384
368 /* LCOV_EXCL_START */385 /* LCOV_EXCL_START */
369 g_return_val_if_fail (INDICATOR_IS_POWER_DEVICE(device), NULL);386 g_return_val_if_fail (INDICATOR_IS_POWER_DEVICE(device), NULL);
@@ -406,9 +423,15 @@
406423
407 case UP_DEVICE_STATE_CHARGING:424 case UP_DEVICE_STATE_CHARGING:
408 suffix_str = get_device_icon_suffix (percentage);425 suffix_str = get_device_icon_suffix (percentage);
409 index_str = get_device_icon_index (percentage);426 index_str = get_closest_10_percent_percentage (percentage);
410 g_ptr_array_add (names, g_strdup_printf ("%s-%s-charging", kind_str, index_str));427 g_ptr_array_add (names, g_strdup_printf ("%s-%s-charging", kind_str, index_str));
411 g_ptr_array_add (names, g_strdup_printf ("gpm-%s-%s-charging", kind_str, index_str));428 g_ptr_array_add (names, g_strdup_printf ("gpm-%s-%s-charging", kind_str, index_str));
429 index_str_2 = get_fallback_device_icon_index (percentage);
430 if (g_strcmp0 (index_str, index_str_2))
431 {
432 g_ptr_array_add (names, g_strdup_printf ("%s-%s-charging", kind_str, index_str_2));
433 g_ptr_array_add (names, g_strdup_printf ("gpm-%s-%s-charging", kind_str, index_str_2));
434 }
412 g_ptr_array_add (names, g_strdup_printf ("%s-%s-charging-symbolic", kind_str, suffix_str));435 g_ptr_array_add (names, g_strdup_printf ("%s-%s-charging-symbolic", kind_str, suffix_str));
413 g_ptr_array_add (names, g_strdup_printf ("%s-%s-charging", kind_str, suffix_str));436 g_ptr_array_add (names, g_strdup_printf ("%s-%s-charging", kind_str, suffix_str));
414 break;437 break;
@@ -417,9 +440,15 @@
417 case UP_DEVICE_STATE_DISCHARGING:440 case UP_DEVICE_STATE_DISCHARGING:
418 case UP_DEVICE_STATE_PENDING_DISCHARGE:441 case UP_DEVICE_STATE_PENDING_DISCHARGE:
419 suffix_str = get_device_icon_suffix (percentage);442 suffix_str = get_device_icon_suffix (percentage);
420 index_str = get_device_icon_index (percentage);443 index_str = get_closest_10_percent_percentage (percentage);
421 g_ptr_array_add (names, g_strdup_printf ("%s-%s", kind_str, index_str));444 g_ptr_array_add (names, g_strdup_printf ("%s-%s", kind_str, index_str));
422 g_ptr_array_add (names, g_strdup_printf ("gpm-%s-%s", kind_str, index_str));445 g_ptr_array_add (names, g_strdup_printf ("gpm-%s-%s", kind_str, index_str));
446 index_str_2 = get_fallback_device_icon_index (percentage);
447 if (g_strcmp0 (index_str, index_str_2))
448 {
449 g_ptr_array_add (names, g_strdup_printf ("%s-%s", kind_str, index_str_2));
450 g_ptr_array_add (names, g_strdup_printf ("gpm-%s-%s", kind_str, index_str_2));
451 }
423 g_ptr_array_add (names, g_strdup_printf ("%s-%s-symbolic", kind_str, suffix_str));452 g_ptr_array_add (names, g_strdup_printf ("%s-%s-symbolic", kind_str, suffix_str));
424 g_ptr_array_add (names, g_strdup_printf ("%s-%s", kind_str, suffix_str));453 g_ptr_array_add (names, g_strdup_printf ("%s-%s", kind_str, suffix_str));
425 break;454 break;
426455
=== modified file 'tests/manual'
--- tests/manual 2014-10-14 19:09:32 +0000
+++ tests/manual 2015-02-13 16:46:19 +0000
@@ -13,7 +13,6 @@
13 --object-path /com/canonical/indicator/power/Testing \13 --object-path /com/canonical/indicator/power/Testing \
14 --method org.freedesktop.DBus.Properties.GetAll \14 --method org.freedesktop.DBus.Properties.GetAll \
15 com.canonical.indicator.power.Testing15 com.canonical.indicator.power.Testing
16({'MockBatteryEnabled': <false>, 'MockBatteryLevel': <uint32 50>, 'MockBatteryState': <'discharging'>, 'MockBatteryMinutesLeft': <uint32 30>},)
1716
18Enable the mock battery:17Enable the mock battery:
1918
@@ -88,6 +87,14 @@
88 <dd>ubuntu-system-settings should be launched to the Battery page </dd>87 <dd>ubuntu-system-settings should be launched to the Battery page </dd>
89</dl>88</dl>
9089
90Test-case indicator-power/low-power-icon
91<dl>
92 <dt>Wait for the system's battery level to drop to 21% (or fake it, see 'Notes on Battery Testing' above)</dt>
93 <dd>The indicator's icon should use the non-critical coloring (eg, grey)</dd>
94 <dt>Wait for the system's battery level to drop to 20% (or fake it, see 'Notes on Battery Testing' above)</dt>
95 <dd>The indicator's icon should use the critical coloring (eg, red)</dd>
96</dl>
97
91Test-case indicator-power/device-brightness-slider98Test-case indicator-power/device-brightness-slider
92<dl>99<dl>
93 <dt>On a device, pull down the power indicator's menu</dt>100 <dt>On a device, pull down the power indicator's menu</dt>
94101
=== modified file 'tests/test-device.cc'
--- tests/test-device.cc 2014-09-08 16:16:29 +0000
+++ tests/test-device.cc 2015-02-13 16:46:19 +0000
@@ -297,7 +297,6 @@
297 g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind,297 g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind,
298 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_EMPTY,298 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_EMPTY,
299 NULL);299 NULL);
300
301 g_string_append_printf (expected, "%s-empty-symbolic;", kind_str);300 g_string_append_printf (expected, "%s-empty-symbolic;", kind_str);
302 g_string_append_printf (expected, "gpm-%s-empty;", kind_str);301 g_string_append_printf (expected, "gpm-%s-empty;", kind_str);
303 g_string_append_printf (expected, "gpm-%s-000;", kind_str);302 g_string_append_printf (expected, "gpm-%s-000;", kind_str);
@@ -323,7 +322,6 @@
323 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING,322 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING,
324 INDICATOR_POWER_DEVICE_PERCENTAGE, 95.0,323 INDICATOR_POWER_DEVICE_PERCENTAGE, 95.0,
325 NULL);324 NULL);
326
327 g_string_append_printf (expected, "%s-100-charging;", kind_str);325 g_string_append_printf (expected, "%s-100-charging;", kind_str);
328 g_string_append_printf (expected, "gpm-%s-100-charging;", kind_str);326 g_string_append_printf (expected, "gpm-%s-100-charging;", kind_str);
329 g_string_append_printf (expected, "%s-full-charging-symbolic;", kind_str);327 g_string_append_printf (expected, "%s-full-charging-symbolic;", kind_str);
@@ -336,6 +334,8 @@
336 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING,334 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING,
337 INDICATOR_POWER_DEVICE_PERCENTAGE, 85.0,335 INDICATOR_POWER_DEVICE_PERCENTAGE, 85.0,
338 NULL);336 NULL);
337 g_string_append_printf (expected, "%s-090-charging;", kind_str);
338 g_string_append_printf (expected, "gpm-%s-090-charging;", kind_str);
339 g_string_append_printf (expected, "%s-080-charging;", kind_str);339 g_string_append_printf (expected, "%s-080-charging;", kind_str);
340 g_string_append_printf (expected, "gpm-%s-080-charging;", kind_str);340 g_string_append_printf (expected, "gpm-%s-080-charging;", kind_str);
341 g_string_append_printf (expected, "%s-full-charging-symbolic;", kind_str);341 g_string_append_printf (expected, "%s-full-charging-symbolic;", kind_str);
@@ -348,6 +348,8 @@
348 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING,348 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING,
349 INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0,349 INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0,
350 NULL);350 NULL);
351 g_string_append_printf (expected, "%s-050-charging;", kind_str);
352 g_string_append_printf (expected, "gpm-%s-050-charging;", kind_str);
351 g_string_append_printf (expected, "%s-060-charging;", kind_str);353 g_string_append_printf (expected, "%s-060-charging;", kind_str);
352 g_string_append_printf (expected, "gpm-%s-060-charging;", kind_str);354 g_string_append_printf (expected, "gpm-%s-060-charging;", kind_str);
353 g_string_append_printf (expected, "%s-good-charging-symbolic;", kind_str);355 g_string_append_printf (expected, "%s-good-charging-symbolic;", kind_str);
@@ -360,6 +362,8 @@
360 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING,362 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING,
361 INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0,363 INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0,
362 NULL);364 NULL);
365 g_string_append_printf (expected, "%s-030-charging;", kind_str);
366 g_string_append_printf (expected, "gpm-%s-030-charging;", kind_str);
363 g_string_append_printf (expected, "%s-020-charging;", kind_str);367 g_string_append_printf (expected, "%s-020-charging;", kind_str);
364 g_string_append_printf (expected, "gpm-%s-020-charging;", kind_str);368 g_string_append_printf (expected, "gpm-%s-020-charging;", kind_str);
365 g_string_append_printf (expected, "%s-low-charging-symbolic;", kind_str);369 g_string_append_printf (expected, "%s-low-charging-symbolic;", kind_str);
@@ -372,6 +376,8 @@
372 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING,376 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING,
373 INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0,377 INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0,
374 NULL);378 NULL);
379 g_string_append_printf (expected, "%s-010-charging;", kind_str);
380 g_string_append_printf (expected, "gpm-%s-010-charging;", kind_str);
375 g_string_append_printf (expected, "%s-000-charging;", kind_str);381 g_string_append_printf (expected, "%s-000-charging;", kind_str);
376 g_string_append_printf (expected, "gpm-%s-000-charging;", kind_str);382 g_string_append_printf (expected, "gpm-%s-000-charging;", kind_str);
377 g_string_append_printf (expected, "%s-caution-charging-symbolic;", kind_str);383 g_string_append_printf (expected, "%s-caution-charging-symbolic;", kind_str);
@@ -396,6 +402,8 @@
396 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING,402 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING,
397 INDICATOR_POWER_DEVICE_PERCENTAGE, 85.0,403 INDICATOR_POWER_DEVICE_PERCENTAGE, 85.0,
398 NULL);404 NULL);
405 g_string_append_printf (expected, "%s-090;", kind_str);
406 g_string_append_printf (expected, "gpm-%s-090;", kind_str);
399 g_string_append_printf (expected, "%s-080;", kind_str);407 g_string_append_printf (expected, "%s-080;", kind_str);
400 g_string_append_printf (expected, "gpm-%s-080;", kind_str);408 g_string_append_printf (expected, "gpm-%s-080;", kind_str);
401 g_string_append_printf (expected, "%s-full-symbolic;", kind_str);409 g_string_append_printf (expected, "%s-full-symbolic;", kind_str);
@@ -409,6 +417,8 @@
409 INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0,417 INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0,
410 INDICATOR_POWER_DEVICE_TIME, guint64(60*60),418 INDICATOR_POWER_DEVICE_TIME, guint64(60*60),
411 NULL);419 NULL);
420 g_string_append_printf (expected, "%s-050;", kind_str);
421 g_string_append_printf (expected, "gpm-%s-050;", kind_str);
412 g_string_append_printf (expected, "%s-060;", kind_str);422 g_string_append_printf (expected, "%s-060;", kind_str);
413 g_string_append_printf (expected, "gpm-%s-060;", kind_str);423 g_string_append_printf (expected, "gpm-%s-060;", kind_str);
414 g_string_append_printf (expected, "%s-good-symbolic;", kind_str);424 g_string_append_printf (expected, "%s-good-symbolic;", kind_str);
@@ -422,6 +432,8 @@
422 INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0,432 INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0,
423 INDICATOR_POWER_DEVICE_TIME, guint64(60*60),433 INDICATOR_POWER_DEVICE_TIME, guint64(60*60),
424 NULL);434 NULL);
435 g_string_append_printf (expected, "%s-030;", kind_str);
436 g_string_append_printf (expected, "gpm-%s-030;", kind_str);
425 g_string_append_printf (expected, "%s-020;", kind_str);437 g_string_append_printf (expected, "%s-020;", kind_str);
426 g_string_append_printf (expected, "gpm-%s-020;", kind_str);438 g_string_append_printf (expected, "gpm-%s-020;", kind_str);
427 g_string_append_printf (expected, "%s-low-symbolic;", kind_str);439 g_string_append_printf (expected, "%s-low-symbolic;", kind_str);
@@ -435,6 +447,8 @@
435 INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0,447 INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0,
436 INDICATOR_POWER_DEVICE_TIME, guint64(60*15),448 INDICATOR_POWER_DEVICE_TIME, guint64(60*15),
437 NULL);449 NULL);
450 g_string_append_printf (expected, "%s-030;", kind_str);
451 g_string_append_printf (expected, "gpm-%s-030;", kind_str);
438 g_string_append_printf (expected, "%s-020;", kind_str);452 g_string_append_printf (expected, "%s-020;", kind_str);
439 g_string_append_printf (expected, "gpm-%s-020;", kind_str);453 g_string_append_printf (expected, "gpm-%s-020;", kind_str);
440 g_string_append_printf (expected, "%s-low-symbolic;", kind_str);454 g_string_append_printf (expected, "%s-low-symbolic;", kind_str);
@@ -448,6 +462,8 @@
448 INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0,462 INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0,
449 INDICATOR_POWER_DEVICE_TIME, guint64(60*60),463 INDICATOR_POWER_DEVICE_TIME, guint64(60*60),
450 NULL);464 NULL);
465 g_string_append_printf (expected, "%s-010;", kind_str);
466 g_string_append_printf (expected, "gpm-%s-010;", kind_str);
451 g_string_append_printf (expected, "%s-000;", kind_str);467 g_string_append_printf (expected, "%s-000;", kind_str);
452 g_string_append_printf (expected, "gpm-%s-000;", kind_str);468 g_string_append_printf (expected, "gpm-%s-000;", kind_str);
453 g_string_append_printf (expected, "%s-caution-symbolic;", kind_str);469 g_string_append_printf (expected, "%s-caution-symbolic;", kind_str);
@@ -461,6 +477,8 @@
461 INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0,477 INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0,
462 INDICATOR_POWER_DEVICE_TIME, guint64(60*15),478 INDICATOR_POWER_DEVICE_TIME, guint64(60*15),
463 NULL);479 NULL);
480 g_string_append_printf (expected, "%s-010;", kind_str);
481 g_string_append_printf (expected, "gpm-%s-010;", kind_str);
464 g_string_append_printf (expected, "%s-000;", kind_str);482 g_string_append_printf (expected, "%s-000;", kind_str);
465 g_string_append_printf (expected, "gpm-%s-000;", kind_str);483 g_string_append_printf (expected, "gpm-%s-000;", kind_str);
466 g_string_append_printf (expected, "%s-caution-symbolic;", kind_str);484 g_string_append_printf (expected, "%s-caution-symbolic;", kind_str);

Subscribers

People subscribed via source and target branches