Merge lp:~charlesk/indicator-power/lp-811777 into lp:indicator-power/13.10
- lp-811777
- Merge into trunk.13.10
Status: | Merged |
---|---|
Approved by: | Charles Kerr |
Approved revision: | 193 |
Merged at revision: | 188 |
Proposed branch: | lp:~charlesk/indicator-power/lp-811777 |
Merge into: | lp:indicator-power/13.10 |
Diff against target: |
959 lines (+322/-214) 8 files modified
data/com.canonical.indicator.power.gschema.xml.in (+5/-0) src/device-provider.c (+1/-1) src/device.c (+120/-56) src/device.h (+16/-15) src/service.c (+76/-84) tests/test-dbus-listener.cc (+11/-11) tests/test-device.cc (+90/-44) tests/test-service.cc (+3/-3) |
To merge this branch: | bzr merge lp:~charlesk/indicator-power/lp-811777 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ted Gould (community) | Approve | ||
PS Jenkins bot (community) | continuous-integration | Approve | |
Review via email: mp+181707@code.launchpad.net |
Commit message
Description of the change
Updates the power indicator to match the spec changes at <https:/
This patch is based from hloeung's nice patch, fixes a few edge cases, adds unit tests for labels, headers, & accessible text for all combinations of show time & show percentage, and cleans up the bindings between GSettings and the checkbox actions.
PS Jenkins bot (ps-jenkins) wrote : | # |
- 192. By Charles Kerr
-
copyediting: more descriptive comments when building label/header/a11y text
- 193. By Charles Kerr
-
copyediting: some newly-dead code should have been removed instead of just commented out
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:193
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Ted Gould (ted) wrote : | # |
Only comment is that this should probably be deleted. Otherwise, cool!
610 + //g_signal_connect (p->settings, "changed::" SETTINGS_
611 + // G_CALLBACK(
Top approve when that gets dropped.
Charles Kerr (charlesk) wrote : | # |
heh, looks like we both saw that at the same time :)
> 193. By Charles Kerr 29 minutes ago
> copyediting: some newly-dead code should have been removed instead of just commented out
> Ted Gould (ted) wrote 13 minutes ago:
> Only comment is that this should probably be deleted. Otherwise, cool!
Preview Diff
1 | === modified file 'data/com.canonical.indicator.power.gschema.xml.in' | |||
2 | --- data/com.canonical.indicator.power.gschema.xml.in 2012-02-02 05:00:03 +0000 | |||
3 | +++ data/com.canonical.indicator.power.gschema.xml.in 2013-08-23 14:01:50 +0000 | |||
4 | @@ -10,6 +10,11 @@ | |||
5 | 10 | <_summary>Show time in Menu Bar</_summary> | 10 | <_summary>Show time in Menu Bar</_summary> |
6 | 11 | <_description>Whether or not to show the time in the menu bar.</_description> | 11 | <_description>Whether or not to show the time in the menu bar.</_description> |
7 | 12 | </key> | 12 | </key> |
8 | 13 | <key name="show-percentage" type="b"> | ||
9 | 14 | <default>false</default> | ||
10 | 15 | <_summary>Show percentage in Menu Bar</_summary> | ||
11 | 16 | <_description>Whether or not to show the percentage in the menu bar.</_description> | ||
12 | 17 | </key> | ||
13 | 13 | <key enum="icon-policy-enum" name="icon-policy"> | 18 | <key enum="icon-policy-enum" name="icon-policy"> |
14 | 14 | <default>"present"</default> | 19 | <default>"present"</default> |
15 | 15 | <_summary>When to show the battery status in the menu bar.</_summary> | 20 | <_summary>When to show the battery status in the menu bar.</_summary> |
16 | 16 | 21 | ||
17 | === modified file 'src/device-provider.c' | |||
18 | --- src/device-provider.c 2013-06-19 15:01:19 +0000 | |||
19 | +++ src/device-provider.c 2013-08-23 14:01:50 +0000 | |||
20 | @@ -54,7 +54,7 @@ | |||
21 | 54 | * An easy way to free the list properly in one step is as follows: | 54 | * An easy way to free the list properly in one step is as follows: |
22 | 55 | * | 55 | * |
23 | 56 | * g_slist_free_full (list, (GDestroyNotify)g_object_unref); | 56 | * g_slist_free_full (list, (GDestroyNotify)g_object_unref); |
25 | 57 | * | 57 | * |
26 | 58 | * Return value: (element-type IndicatorPowerDevice) | 58 | * Return value: (element-type IndicatorPowerDevice) |
27 | 59 | * (transfer full): | 59 | * (transfer full): |
28 | 60 | * list of devices | 60 | * list of devices |
29 | 61 | 61 | ||
30 | === modified file 'src/device.c' | |||
31 | --- src/device.c 2013-06-17 04:16:19 +0000 | |||
32 | +++ src/device.c 2013-08-23 14:01:50 +0000 | |||
33 | @@ -449,10 +449,11 @@ | |||
34 | 449 | **** | 449 | **** |
35 | 450 | ***/ | 450 | ***/ |
36 | 451 | 451 | ||
37 | 452 | /* Format time remaining for reading ("H:MM") and speech ("H hours, MM minutes") */ | ||
38 | 452 | static void | 453 | static void |
39 | 453 | get_timestring (guint64 time_secs, | 454 | get_timestring (guint64 time_secs, |
42 | 454 | gchar **short_timestring, | 455 | gchar **readable_timestring, |
43 | 455 | gchar **detailed_timestring) | 456 | gchar **accessible_timestring) |
44 | 456 | { | 457 | { |
45 | 457 | gint hours; | 458 | gint hours; |
46 | 458 | gint minutes; | 459 | gint minutes; |
47 | @@ -462,16 +463,16 @@ | |||
48 | 462 | 463 | ||
49 | 463 | if (minutes == 0) | 464 | if (minutes == 0) |
50 | 464 | { | 465 | { |
53 | 465 | *short_timestring = g_strdup (_("Unknown time")); | 466 | *readable_timestring = g_strdup (_("Unknown time")); |
54 | 466 | *detailed_timestring = g_strdup (_("Unknown time")); | 467 | *accessible_timestring = g_strdup (_("Unknown time")); |
55 | 467 | 468 | ||
56 | 468 | return; | 469 | return; |
57 | 469 | } | 470 | } |
58 | 470 | 471 | ||
59 | 471 | if (minutes < 60) | 472 | if (minutes < 60) |
60 | 472 | { | 473 | { |
63 | 473 | *short_timestring = g_strdup_printf ("0:%.2i", minutes); | 474 | *readable_timestring = g_strdup_printf ("0:%.2i", minutes); |
64 | 474 | *detailed_timestring = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "%i minute", | 475 | *accessible_timestring = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "%i minute", |
65 | 475 | "%i minutes", | 476 | "%i minutes", |
66 | 476 | minutes), minutes); | 477 | minutes), minutes); |
67 | 477 | return; | 478 | return; |
68 | @@ -480,11 +481,11 @@ | |||
69 | 480 | hours = minutes / 60; | 481 | hours = minutes / 60; |
70 | 481 | minutes = minutes % 60; | 482 | minutes = minutes % 60; |
71 | 482 | 483 | ||
73 | 483 | *short_timestring = g_strdup_printf ("%i:%.2i", hours, minutes); | 484 | *readable_timestring = g_strdup_printf ("%i:%.2i", hours, minutes); |
74 | 484 | 485 | ||
75 | 485 | if (minutes == 0) | 486 | if (minutes == 0) |
76 | 486 | { | 487 | { |
78 | 487 | *detailed_timestring = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, | 488 | *accessible_timestring = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, |
79 | 488 | "%i hour", | 489 | "%i hour", |
80 | 489 | "%i hours", | 490 | "%i hours", |
81 | 490 | hours), hours); | 491 | hours), hours); |
82 | @@ -493,7 +494,7 @@ | |||
83 | 493 | { | 494 | { |
84 | 494 | /* TRANSLATOR: "%i %s %i %s" are "%i hours %i minutes" | 495 | /* TRANSLATOR: "%i %s %i %s" are "%i hours %i minutes" |
85 | 495 | * Swap order with "%2$s %2$i %1$s %1$i if needed */ | 496 | * Swap order with "%2$s %2$i %1$s %1$i if needed */ |
87 | 496 | *detailed_timestring = g_strdup_printf (_("%i %s %i %s"), | 497 | *accessible_timestring = g_strdup_printf (_("%i %s %i %s"), |
88 | 497 | hours, g_dngettext (GETTEXT_PACKAGE, "hour", "hours", hours), | 498 | hours, g_dngettext (GETTEXT_PACKAGE, "hour", "hours", hours), |
89 | 498 | minutes, g_dngettext (GETTEXT_PACKAGE, "minute", "minutes", minutes)); | 499 | minutes, g_dngettext (GETTEXT_PACKAGE, "minute", "minutes", minutes)); |
90 | 499 | } | 500 | } |
91 | @@ -561,86 +562,149 @@ | |||
92 | 561 | return text; | 562 | return text; |
93 | 562 | } | 563 | } |
94 | 563 | 564 | ||
100 | 564 | void | 565 | static char * |
101 | 565 | indicator_power_device_get_time_details (const IndicatorPowerDevice * device, | 566 | join_strings (const char * name, const char * time, const char * percent) |
102 | 566 | gchar ** short_details, | 567 | { |
103 | 567 | gchar ** details, | 568 | char * str; |
104 | 568 | gchar ** accessible_name) | 569 | const gboolean have_name = name && *name; |
105 | 570 | const gboolean have_time = time && *time; | ||
106 | 571 | const gboolean have_percent = percent && *percent; | ||
107 | 572 | |||
108 | 573 | if (have_name && have_time && have_percent) | ||
109 | 574 | str = g_strdup_printf (_("%s (%s, %s)"), name, time, percent); | ||
110 | 575 | else if (have_name && have_time) | ||
111 | 576 | str = g_strdup_printf (_("%s (%s)"), name, time); | ||
112 | 577 | else if (have_name && have_percent) | ||
113 | 578 | str = g_strdup_printf (_("%s (%s)"), name, percent); | ||
114 | 579 | else if (have_name) | ||
115 | 580 | str = g_strdup (name); | ||
116 | 581 | else if (have_time && have_percent) | ||
117 | 582 | str = g_strdup_printf (_("(%s, %s)"), time, percent); | ||
118 | 583 | else if (have_time) | ||
119 | 584 | str = g_strdup_printf (_("(%s)"), time); | ||
120 | 585 | else if (have_percent) | ||
121 | 586 | str = g_strdup_printf (_("(%s)"), percent); | ||
122 | 587 | else | ||
123 | 588 | str = g_strdup (""); | ||
124 | 589 | |||
125 | 590 | return str; | ||
126 | 591 | } | ||
127 | 592 | |||
128 | 593 | static void | ||
129 | 594 | indicator_power_device_get_text (const IndicatorPowerDevice * device, | ||
130 | 595 | gboolean show_time_in_header, | ||
131 | 596 | gboolean show_percentage_in_header, | ||
132 | 597 | gchar ** header, | ||
133 | 598 | gchar ** label, | ||
134 | 599 | gchar ** a11y) | ||
135 | 569 | { | 600 | { |
136 | 570 | if (!INDICATOR_IS_POWER_DEVICE(device)) | 601 | if (!INDICATOR_IS_POWER_DEVICE(device)) |
137 | 571 | { | 602 | { |
141 | 572 | *short_details = NULL; | 603 | if (a11y != NULL) *a11y = NULL; |
142 | 573 | *details = NULL; | 604 | if (label != NULL) *label = NULL; |
143 | 574 | *accessible_name = NULL; | 605 | if (header != NULL) *header = NULL; |
144 | 575 | g_warning ("%s: %p is not an IndicatorPowerDevice", G_STRFUNC, device); | 606 | g_warning ("%s: %p is not an IndicatorPowerDevice", G_STRFUNC, device); |
145 | 576 | return; | 607 | return; |
146 | 577 | } | 608 | } |
147 | 578 | 609 | ||
148 | 579 | const time_t time = indicator_power_device_get_time (device); | 610 | const time_t time = indicator_power_device_get_time (device); |
149 | 580 | const UpDeviceState state = indicator_power_device_get_state (device); | 611 | const UpDeviceState state = indicator_power_device_get_state (device); |
150 | 612 | const UpDeviceKind kind = indicator_power_device_get_kind (device); | ||
151 | 613 | const gchar * device_name = device_kind_to_localised_string (kind); | ||
152 | 581 | const gdouble percentage = indicator_power_device_get_percentage (device); | 614 | const gdouble percentage = indicator_power_device_get_percentage (device); |
155 | 582 | const UpDeviceKind kind = indicator_power_device_get_kind (device); | 615 | char pctstr[32] = { '\0' }; |
156 | 583 | const gchar * device_name = device_kind_to_localised_string (kind); | 616 | g_snprintf (pctstr, sizeof(pctstr), "%.0lf%%", percentage); |
157 | 617 | |||
158 | 618 | GString * terse_time = g_string_new (NULL); | ||
159 | 619 | GString * verbose_time = g_string_new (NULL); | ||
160 | 620 | GString * accessible_time = g_string_new (NULL); | ||
161 | 584 | 621 | ||
162 | 585 | if (time > 0) | 622 | if (time > 0) |
163 | 586 | { | 623 | { |
170 | 587 | gchar *short_timestring = NULL; | 624 | char * readable_timestr = NULL; |
171 | 588 | gchar *detailed_timestring = NULL; | 625 | char * accessible_timestr = NULL; |
172 | 589 | 626 | get_timestring (time, &readable_timestr, &accessible_timestr); | |
167 | 590 | get_timestring (time, | ||
168 | 591 | &short_timestring, | ||
169 | 592 | &detailed_timestring); | ||
173 | 593 | 627 | ||
174 | 594 | if (state == UP_DEVICE_STATE_CHARGING) | 628 | if (state == UP_DEVICE_STATE_CHARGING) |
175 | 595 | { | 629 | { |
180 | 596 | /* TRANSLATORS: %2 is a time string, e.g. "1 hour 5 minutes" */ | 630 | g_string_assign (terse_time, readable_timestr); |
181 | 597 | *accessible_name = g_strdup_printf (_("%s (%s to charge (%.0lf%%))"), device_name, detailed_timestring, percentage); | 631 | g_string_printf (verbose_time, _("%s to charge"), readable_timestr); |
182 | 598 | *details = g_strdup_printf (_("%s (%s to charge)"), device_name, short_timestring); | 632 | g_string_printf (accessible_time, _("%s to charge"), accessible_timestr); |
179 | 599 | *short_details = g_strdup_printf ("(%s)", short_timestring); | ||
183 | 600 | } | 633 | } |
185 | 601 | else if ((state == UP_DEVICE_STATE_DISCHARGING) && (time > (60*60*12))) | 634 | else if ((state == UP_DEVICE_STATE_DISCHARGING) && (time <= (60*60*12))) |
186 | 602 | { | 635 | { |
190 | 603 | *accessible_name = g_strdup_printf (_("%s"), device_name); | 636 | g_string_assign (terse_time, readable_timestr); |
191 | 604 | *details = g_strdup_printf (_("%s"), device_name); | 637 | g_string_printf (verbose_time, _("%s left"), readable_timestr); |
192 | 605 | *short_details = g_strdup (short_timestring); | 638 | g_string_printf (accessible_time, _("%s left"), accessible_timestr); |
193 | 606 | } | 639 | } |
194 | 607 | else | 640 | else |
195 | 608 | { | 641 | { |
200 | 609 | /* TRANSLATORS: %2 is a time string, e.g. "1 hour 5 minutes" */ | 642 | /* if there's more than 12 hours remaining, we don't show it */ |
197 | 610 | *accessible_name = g_strdup_printf (_("%s (%s left (%.0lf%%))"), device_name, detailed_timestring, percentage); | ||
198 | 611 | *details = g_strdup_printf (_("%s (%s left)"), device_name, short_timestring); | ||
199 | 612 | *short_details = g_strdup (short_timestring); | ||
201 | 613 | } | 643 | } |
202 | 614 | 644 | ||
205 | 615 | g_free (short_timestring); | 645 | g_free (readable_timestr); |
206 | 616 | g_free (detailed_timestring); | 646 | g_free (accessible_timestr); |
207 | 617 | } | 647 | } |
208 | 618 | else if (state == UP_DEVICE_STATE_FULLY_CHARGED) | 648 | else if (state == UP_DEVICE_STATE_FULLY_CHARGED) |
209 | 619 | { | 649 | { |
213 | 620 | *details = g_strdup_printf (_("%s (charged)"), device_name); | 650 | g_string_assign (verbose_time, _("charged")); |
214 | 621 | *accessible_name = g_strdup (*details); | 651 | g_string_assign (accessible_time, _("charged")); |
212 | 622 | *short_details = g_strdup (""); | ||
215 | 623 | } | 652 | } |
216 | 624 | else if (percentage > 0) | 653 | else if (percentage > 0) |
217 | 625 | { | 654 | { |
229 | 626 | /* TRANSLATORS: %2 is a percentage value. Note: this string is only | 655 | g_string_assign (terse_time, _("estimating…")); |
230 | 627 | * used when we don't have a time value */ | 656 | g_string_assign (verbose_time, _("estimating…")); |
231 | 628 | *details = g_strdup_printf (_("%s (%.0lf%%)"), device_name, percentage); | 657 | g_string_assign (accessible_time, _("estimating…")); |
221 | 629 | *accessible_name = g_strdup (*details); | ||
222 | 630 | *short_details = g_strdup_printf (_("(%.0lf%%)"), percentage); | ||
223 | 631 | } | ||
224 | 632 | else if (kind == UP_DEVICE_KIND_LINE_POWER) | ||
225 | 633 | { | ||
226 | 634 | *details = g_strdup (device_name); | ||
227 | 635 | *accessible_name = g_strdup (device_name); | ||
228 | 636 | *short_details = g_strdup (""); | ||
232 | 637 | } | 658 | } |
233 | 638 | else | 659 | else |
234 | 639 | { | 660 | { |
238 | 640 | *details = g_strdup_printf (_("%s (not present)"), device_name); | 661 | *pctstr = '\0'; |
239 | 641 | *accessible_name = g_strdup (*details); | 662 | |
240 | 642 | *short_details = g_strdup (_("(not present)")); | 663 | if (kind != UP_DEVICE_KIND_LINE_POWER) |
241 | 664 | { | ||
242 | 665 | g_string_assign (verbose_time, _("not present")); | ||
243 | 666 | g_string_assign (accessible_time, _("not present")); | ||
244 | 667 | } | ||
245 | 643 | } | 668 | } |
246 | 669 | |||
247 | 670 | if (header != NULL) | ||
248 | 671 | *header = join_strings (NULL, | ||
249 | 672 | show_time_in_header ? terse_time->str : "", | ||
250 | 673 | show_percentage_in_header ? pctstr : ""); | ||
251 | 674 | |||
252 | 675 | if (label != NULL) | ||
253 | 676 | *label = join_strings (device_name, | ||
254 | 677 | verbose_time->str, | ||
255 | 678 | NULL); | ||
256 | 679 | |||
257 | 680 | if (a11y != NULL) | ||
258 | 681 | *a11y = join_strings (device_name, | ||
259 | 682 | accessible_time->str, | ||
260 | 683 | pctstr); | ||
261 | 684 | |||
262 | 685 | g_string_free (terse_time, TRUE); | ||
263 | 686 | g_string_free (verbose_time, TRUE); | ||
264 | 687 | g_string_free (accessible_time, TRUE); | ||
265 | 688 | } | ||
266 | 689 | |||
267 | 690 | gchar * | ||
268 | 691 | indicator_power_device_get_label (const IndicatorPowerDevice * device) | ||
269 | 692 | { | ||
270 | 693 | gchar * label = NULL; | ||
271 | 694 | indicator_power_device_get_text (device, FALSE, FALSE, | ||
272 | 695 | NULL, &label, NULL); | ||
273 | 696 | return label; | ||
274 | 697 | } | ||
275 | 698 | |||
276 | 699 | void | ||
277 | 700 | indicator_power_device_get_header (const IndicatorPowerDevice * device, | ||
278 | 701 | gboolean show_time, | ||
279 | 702 | gboolean show_percentage, | ||
280 | 703 | gchar ** header, | ||
281 | 704 | gchar ** a11y) | ||
282 | 705 | { | ||
283 | 706 | indicator_power_device_get_text (device, show_time, show_percentage, | ||
284 | 707 | header, NULL, a11y); | ||
285 | 644 | } | 708 | } |
286 | 645 | 709 | ||
287 | 646 | /*** | 710 | /*** |
288 | 647 | 711 | ||
289 | === modified file 'src/device.h' | |||
290 | --- src/device.h 2013-06-17 04:16:19 +0000 | |||
291 | +++ src/device.h 2013-08-23 14:01:50 +0000 | |||
292 | @@ -116,21 +116,22 @@ | |||
293 | 116 | IndicatorPowerDevice* indicator_power_device_new_from_variant (GVariant * variant); | 116 | IndicatorPowerDevice* indicator_power_device_new_from_variant (GVariant * variant); |
294 | 117 | 117 | ||
295 | 118 | 118 | ||
311 | 119 | UpDeviceKind indicator_power_device_get_kind (const IndicatorPowerDevice * device); | 119 | UpDeviceKind indicator_power_device_get_kind (const IndicatorPowerDevice * device); |
312 | 120 | UpDeviceState indicator_power_device_get_state (const IndicatorPowerDevice * device); | 120 | UpDeviceState indicator_power_device_get_state (const IndicatorPowerDevice * device); |
313 | 121 | const gchar * indicator_power_device_get_object_path (const IndicatorPowerDevice * device); | 121 | const gchar * indicator_power_device_get_object_path (const IndicatorPowerDevice * device); |
314 | 122 | gdouble indicator_power_device_get_percentage (const IndicatorPowerDevice * device); | 122 | gdouble indicator_power_device_get_percentage (const IndicatorPowerDevice * device); |
315 | 123 | time_t indicator_power_device_get_time (const IndicatorPowerDevice * device); | 123 | time_t indicator_power_device_get_time (const IndicatorPowerDevice * device); |
316 | 124 | 124 | ||
317 | 125 | GStrv indicator_power_device_get_icon_names (const IndicatorPowerDevice * device); | 125 | GStrv indicator_power_device_get_icon_names (const IndicatorPowerDevice * device); |
318 | 126 | GIcon * indicator_power_device_get_gicon (const IndicatorPowerDevice * device); | 126 | GIcon * indicator_power_device_get_gicon (const IndicatorPowerDevice * device); |
319 | 127 | 127 | ||
320 | 128 | void indicator_power_device_get_time_details (const IndicatorPowerDevice * device, | 128 | gchar * indicator_power_device_get_label (const IndicatorPowerDevice * device); |
321 | 129 | gchar ** short_details, | 129 | |
322 | 130 | gchar ** details, | 130 | void indicator_power_device_get_header (const IndicatorPowerDevice * device, |
323 | 131 | gchar ** accessible_name); | 131 | gboolean show_time, |
324 | 132 | 132 | gboolean show_percentage, | |
325 | 133 | 133 | gchar ** header, | |
326 | 134 | gchar ** a11y); | ||
327 | 134 | 135 | ||
328 | 135 | 136 | ||
329 | 136 | G_END_DECLS | 137 | G_END_DECLS |
330 | 137 | 138 | ||
331 | === modified file 'src/service.c' | |||
332 | --- src/service.c 2013-08-20 03:47:23 +0000 | |||
333 | +++ src/service.c 2013-08-23 14:01:50 +0000 | |||
334 | @@ -33,6 +33,7 @@ | |||
335 | 33 | 33 | ||
336 | 34 | #define SETTINGS_SHOW_TIME_S "show-time" | 34 | #define SETTINGS_SHOW_TIME_S "show-time" |
337 | 35 | #define SETTINGS_ICON_POLICY_S "icon-policy" | 35 | #define SETTINGS_ICON_POLICY_S "icon-policy" |
338 | 36 | #define SETTINGS_SHOW_PERCENTAGE_S "show-percentage" | ||
339 | 36 | 37 | ||
340 | 37 | G_DEFINE_TYPE (IndicatorPowerService, | 38 | G_DEFINE_TYPE (IndicatorPowerService, |
341 | 38 | indicator_power_service, | 39 | indicator_power_service, |
342 | @@ -112,6 +113,7 @@ | |||
343 | 112 | GSimpleActionGroup * actions; | 113 | GSimpleActionGroup * actions; |
344 | 113 | GSimpleAction * header_action; | 114 | GSimpleAction * header_action; |
345 | 114 | GSimpleAction * show_time_action; | 115 | GSimpleAction * show_time_action; |
346 | 116 | GSimpleAction * show_percentage_action; | ||
347 | 115 | GSimpleAction * battery_level_action; | 117 | GSimpleAction * battery_level_action; |
348 | 116 | GSimpleAction * brightness_action; | 118 | GSimpleAction * brightness_action; |
349 | 117 | 119 | ||
350 | @@ -318,16 +320,13 @@ | |||
351 | 318 | 320 | ||
352 | 319 | if (p->primary_device != NULL) | 321 | if (p->primary_device != NULL) |
353 | 320 | { | 322 | { |
360 | 321 | gchar * details; | 323 | indicator_power_device_get_header (p->primary_device, |
361 | 322 | 324 | g_settings_get_boolean (p->settings, SETTINGS_SHOW_TIME_S), | |
362 | 323 | indicator_power_device_get_time_details (p->primary_device, | 325 | g_settings_get_boolean (p->settings, SETTINGS_SHOW_PERCENTAGE_S), |
363 | 324 | &label, | 326 | &label, |
364 | 325 | &details, | 327 | &a11y); |
359 | 326 | &a11y); | ||
365 | 327 | 328 | ||
366 | 328 | icon = indicator_power_device_get_gicon (p->primary_device); | 329 | icon = indicator_power_device_get_gicon (p->primary_device); |
367 | 329 | |||
368 | 330 | g_free (details); | ||
369 | 331 | } | 330 | } |
370 | 332 | 331 | ||
371 | 333 | g_variant_builder_init (&b, G_VARIANT_TYPE("a{sv}")); | 332 | g_variant_builder_init (&b, G_VARIANT_TYPE("a{sv}")); |
372 | @@ -337,9 +336,7 @@ | |||
373 | 337 | 336 | ||
374 | 338 | if (label != NULL) | 337 | if (label != NULL) |
375 | 339 | { | 338 | { |
379 | 340 | if (g_settings_get_boolean (p->settings, SETTINGS_SHOW_TIME_S)) | 339 | g_variant_builder_add (&b, "{sv}", "label", g_variant_new_string (label)); |
377 | 341 | g_variant_builder_add (&b, "{sv}", "label", | ||
378 | 342 | g_variant_new_string (label)); | ||
380 | 343 | 340 | ||
381 | 344 | g_free (label); | 341 | g_free (label); |
382 | 345 | } | 342 | } |
383 | @@ -376,33 +373,24 @@ | |||
384 | 376 | 373 | ||
385 | 377 | if (kind != UP_DEVICE_KIND_LINE_POWER) | 374 | if (kind != UP_DEVICE_KIND_LINE_POWER) |
386 | 378 | { | 375 | { |
388 | 379 | char * brief; | 376 | GIcon * icon; |
389 | 380 | char * label; | 377 | char * label; |
390 | 381 | char * a11y; | ||
391 | 382 | GMenuItem * menu_item; | 378 | GMenuItem * menu_item; |
399 | 383 | GIcon * icon = indicator_power_device_get_gicon (device); | 379 | |
400 | 384 | 380 | icon = indicator_power_device_get_gicon (device); | |
401 | 385 | indicator_power_device_get_time_details (device, | 381 | label = indicator_power_device_get_label (device); |
395 | 386 | &brief, | ||
396 | 387 | &label, | ||
397 | 388 | &a11y); | ||
398 | 389 | |||
402 | 390 | menu_item = g_menu_item_new (label, "indicator.activate-statistics"); | 382 | menu_item = g_menu_item_new (label, "indicator.activate-statistics"); |
403 | 391 | 383 | ||
404 | 392 | if (icon != NULL) | 384 | if (icon != NULL) |
410 | 393 | { | 385 | g_menu_item_set_attribute_value (menu_item, |
411 | 394 | g_menu_item_set_attribute_value (menu_item, | 386 | G_MENU_ATTRIBUTE_ICON, |
412 | 395 | G_MENU_ATTRIBUTE_ICON, | 387 | g_icon_serialize (icon)); |
408 | 396 | g_icon_serialize (icon)); | ||
409 | 397 | } | ||
413 | 398 | 388 | ||
414 | 399 | g_menu_append_item (menu, menu_item); | 389 | g_menu_append_item (menu, menu_item); |
415 | 400 | g_object_unref (menu_item); | 390 | g_object_unref (menu_item); |
416 | 401 | 391 | ||
417 | 402 | g_clear_object (&icon); | 392 | g_clear_object (&icon); |
418 | 403 | g_free (brief); | ||
419 | 404 | g_free (label); | 393 | g_free (label); |
420 | 405 | g_free (a11y); | ||
421 | 406 | } | 394 | } |
422 | 407 | } | 395 | } |
423 | 408 | 396 | ||
424 | @@ -521,6 +509,10 @@ | |||
425 | 521 | "indicator.show-time"); | 509 | "indicator.show-time"); |
426 | 522 | 510 | ||
427 | 523 | g_menu_append (menu, | 511 | g_menu_append (menu, |
428 | 512 | _("Show Percentage in Menu Bar"), | ||
429 | 513 | "indicator.show-percentage"); | ||
430 | 514 | |||
431 | 515 | g_menu_append (menu, | ||
432 | 524 | _("Power Settings…"), | 516 | _("Power Settings…"), |
433 | 525 | "indicator.activate-settings"); | 517 | "indicator.activate-settings"); |
434 | 526 | 518 | ||
435 | @@ -706,49 +698,15 @@ | |||
436 | 706 | execute_command ("gnome-power-statistics"); | 698 | execute_command ("gnome-power-statistics"); |
437 | 707 | } | 699 | } |
438 | 708 | 700 | ||
476 | 709 | /* FIXME: use a GBinding to tie the gaction's state and the GSetting together? */ | 701 | /*** |
477 | 710 | 702 | **** | |
478 | 711 | static void | 703 | ***/ |
442 | 712 | set_show_time_flag (IndicatorPowerService * self, gboolean b) | ||
443 | 713 | { | ||
444 | 714 | GVariant * v; | ||
445 | 715 | priv_t * p = self->priv; | ||
446 | 716 | |||
447 | 717 | /* update the settings */ | ||
448 | 718 | if (b != g_settings_get_boolean (p->settings, SETTINGS_SHOW_TIME_S)) | ||
449 | 719 | g_settings_set_boolean (p->settings, SETTINGS_SHOW_TIME_S, b); | ||
450 | 720 | |||
451 | 721 | /* update the action state */ | ||
452 | 722 | v = g_action_get_state (G_ACTION(p->show_time_action)); | ||
453 | 723 | if (b != g_variant_get_boolean (v)) | ||
454 | 724 | g_simple_action_set_state (p->show_time_action, g_variant_new_boolean (b)); | ||
455 | 725 | g_variant_unref (v); | ||
456 | 726 | |||
457 | 727 | rebuild_header_now (self); | ||
458 | 728 | } | ||
459 | 729 | static void | ||
460 | 730 | on_show_time_setting_changed (GSettings * settings, gchar * key, gpointer gself) | ||
461 | 731 | { | ||
462 | 732 | set_show_time_flag (INDICATOR_POWER_SERVICE(gself), | ||
463 | 733 | g_settings_get_boolean (settings, key)); | ||
464 | 734 | } | ||
465 | 735 | |||
466 | 736 | static void | ||
467 | 737 | on_show_time_action_state_changed (GAction * action, | ||
468 | 738 | GParamSpec * pspec G_GNUC_UNUSED, | ||
469 | 739 | gpointer gself) | ||
470 | 740 | { | ||
471 | 741 | GVariant * v = g_action_get_state (action); | ||
472 | 742 | set_show_time_flag (INDICATOR_POWER_SERVICE(gself), | ||
473 | 743 | g_variant_get_boolean (v)); | ||
474 | 744 | g_variant_unref (v); | ||
475 | 745 | } | ||
479 | 746 | 704 | ||
480 | 747 | /* toggles the state */ | 705 | /* toggles the state */ |
481 | 748 | static void | 706 | static void |
485 | 749 | on_show_time_action_activated (GSimpleAction * simple, | 707 | on_toggle_action_activated (GSimpleAction * simple, |
486 | 750 | GVariant * parameter G_GNUC_UNUSED, | 708 | GVariant * parameter G_GNUC_UNUSED, |
487 | 751 | gpointer unused G_GNUC_UNUSED) | 709 | gpointer unused G_GNUC_UNUSED) |
488 | 752 | { | 710 | { |
489 | 753 | GVariant * v = g_action_get_state (G_ACTION (simple)); | 711 | GVariant * v = g_action_get_state (G_ACTION (simple)); |
490 | 754 | gboolean flag = g_variant_get_boolean (v); | 712 | gboolean flag = g_variant_get_boolean (v); |
491 | @@ -756,11 +714,27 @@ | |||
492 | 756 | g_variant_unref (v); | 714 | g_variant_unref (v); |
493 | 757 | } | 715 | } |
494 | 758 | 716 | ||
495 | 717 | static gboolean | ||
496 | 718 | settings_to_action_state (GValue * value, | ||
497 | 719 | GVariant * variant, | ||
498 | 720 | gpointer user_data G_GNUC_UNUSED) | ||
499 | 721 | { | ||
500 | 722 | g_value_set_variant (value, variant); | ||
501 | 723 | return TRUE; | ||
502 | 724 | } | ||
503 | 725 | |||
504 | 726 | static GVariant * | ||
505 | 727 | action_state_to_settings (const GValue * value, | ||
506 | 728 | const GVariantType * expected_type G_GNUC_UNUSED, | ||
507 | 729 | gpointer user_data G_GNUC_UNUSED) | ||
508 | 730 | { | ||
509 | 731 | return g_value_dup_variant (value); | ||
510 | 732 | } | ||
511 | 733 | |||
512 | 759 | static void | 734 | static void |
513 | 760 | init_gactions (IndicatorPowerService * self) | 735 | init_gactions (IndicatorPowerService * self) |
514 | 761 | { | 736 | { |
515 | 762 | GSimpleAction * a; | 737 | GSimpleAction * a; |
516 | 763 | gboolean show_time; | ||
517 | 764 | priv_t * p = self->priv; | 738 | priv_t * p = self->priv; |
518 | 765 | 739 | ||
519 | 766 | GActionEntry entries[] = { | 740 | GActionEntry entries[] = { |
520 | @@ -777,33 +751,47 @@ | |||
521 | 777 | 751 | ||
522 | 778 | /* add the header action */ | 752 | /* add the header action */ |
523 | 779 | a = g_simple_action_new_stateful ("_header", NULL, create_header_state (self)); | 753 | a = g_simple_action_new_stateful ("_header", NULL, create_header_state (self)); |
525 | 780 | g_simple_action_group_insert (p->actions, G_ACTION(a)); | 754 | g_action_map_add_action (G_ACTION_MAP(p->actions), G_ACTION(a)); |
526 | 781 | p->header_action = a; | 755 | p->header_action = a; |
527 | 782 | 756 | ||
528 | 783 | /* add the power-level action */ | 757 | /* add the power-level action */ |
529 | 784 | a = g_simple_action_new_stateful ("battery-level", NULL, g_variant_new_uint32(0)); | 758 | a = g_simple_action_new_stateful ("battery-level", NULL, g_variant_new_uint32(0)); |
530 | 785 | g_simple_action_set_enabled (a, FALSE); | 759 | g_simple_action_set_enabled (a, FALSE); |
532 | 786 | g_simple_action_group_insert (p->actions, G_ACTION(a)); | 760 | g_action_map_add_action (G_ACTION_MAP(p->actions), G_ACTION(a)); |
533 | 787 | p->battery_level_action = a; | 761 | p->battery_level_action = a; |
534 | 788 | 762 | ||
535 | 789 | /* add the brightness action */ | 763 | /* add the brightness action */ |
536 | 790 | a = g_simple_action_new_stateful ("brightness", NULL, action_state_for_brightness (self)); | 764 | a = g_simple_action_new_stateful ("brightness", NULL, action_state_for_brightness (self)); |
538 | 791 | g_simple_action_group_insert (p->actions, G_ACTION(a)); | 765 | g_action_map_add_action (G_ACTION_MAP(p->actions), G_ACTION(a)); |
539 | 792 | g_signal_connect (a, "change-state", G_CALLBACK(on_brightness_change_requested), self); | 766 | g_signal_connect (a, "change-state", G_CALLBACK(on_brightness_change_requested), self); |
540 | 793 | p->brightness_action = a; | 767 | p->brightness_action = a; |
541 | 794 | 768 | ||
542 | 795 | /* add the show-time action */ | 769 | /* add the show-time action */ |
552 | 796 | show_time = g_settings_get_boolean (p->settings, SETTINGS_SHOW_TIME_S); | 770 | a = g_simple_action_new ("show-time", NULL); |
553 | 797 | a = g_simple_action_new_stateful ("show-time", | 771 | g_settings_bind_with_mapping (p->settings, SETTINGS_SHOW_TIME_S, |
554 | 798 | NULL, | 772 | a, "state", |
555 | 799 | g_variant_new_boolean(show_time)); | 773 | G_SETTINGS_BIND_DEFAULT, |
556 | 800 | g_signal_connect (a, "activate", | 774 | settings_to_action_state, |
557 | 801 | G_CALLBACK(on_show_time_action_activated), self); | 775 | action_state_to_settings, |
558 | 802 | g_signal_connect (a, "notify", | 776 | NULL, NULL); |
559 | 803 | G_CALLBACK(on_show_time_action_state_changed), self); | 777 | g_signal_connect (a, "activate", G_CALLBACK(on_toggle_action_activated), self); |
560 | 804 | g_simple_action_group_insert (p->actions, G_ACTION(a)); | 778 | g_signal_connect_swapped (a, "notify", G_CALLBACK(rebuild_header_now), self); |
561 | 779 | g_action_map_add_action (G_ACTION_MAP(p->actions), G_ACTION(a)); | ||
562 | 805 | p->show_time_action = a; | 780 | p->show_time_action = a; |
563 | 806 | 781 | ||
564 | 782 | /* add the show-percentage action */ | ||
565 | 783 | a = g_simple_action_new ("show-percentage", NULL); | ||
566 | 784 | g_settings_bind_with_mapping (p->settings, SETTINGS_SHOW_PERCENTAGE_S, | ||
567 | 785 | a, "state", | ||
568 | 786 | G_SETTINGS_BIND_DEFAULT, | ||
569 | 787 | settings_to_action_state, | ||
570 | 788 | action_state_to_settings, | ||
571 | 789 | NULL, NULL); | ||
572 | 790 | g_signal_connect (a, "activate", G_CALLBACK(on_toggle_action_activated), self); | ||
573 | 791 | g_signal_connect_swapped (a, "notify", G_CALLBACK(rebuild_header_now), self); | ||
574 | 792 | g_action_map_add_action (G_ACTION_MAP(p->actions), G_ACTION(a)); | ||
575 | 793 | p->show_percentage_action = a; | ||
576 | 794 | |||
577 | 807 | rebuild_header_now (self); | 795 | rebuild_header_now (self); |
578 | 808 | } | 796 | } |
579 | 809 | 797 | ||
580 | @@ -949,7 +937,7 @@ | |||
581 | 949 | { | 937 | { |
582 | 950 | IndicatorPowerService * self = INDICATOR_POWER_SERVICE (o); | 938 | IndicatorPowerService * self = INDICATOR_POWER_SERVICE (o); |
583 | 951 | priv_t * p = self->priv; | 939 | priv_t * p = self->priv; |
585 | 952 | 940 | ||
586 | 953 | switch (property_id) | 941 | switch (property_id) |
587 | 954 | { | 942 | { |
588 | 955 | case PROP_DEVICE_PROVIDER: | 943 | case PROP_DEVICE_PROVIDER: |
589 | @@ -1014,10 +1002,16 @@ | |||
590 | 1014 | g_clear_object (&p->show_time_action); | 1002 | g_clear_object (&p->show_time_action); |
591 | 1015 | } | 1003 | } |
592 | 1016 | 1004 | ||
593 | 1005 | if (p->show_percentage_action != NULL) | ||
594 | 1006 | { | ||
595 | 1007 | g_signal_handlers_disconnect_by_data (p->show_percentage_action, self); | ||
596 | 1008 | |||
597 | 1009 | g_clear_object (&p->show_percentage_action); | ||
598 | 1010 | } | ||
599 | 1011 | |||
600 | 1017 | g_clear_object (&p->brightness_action); | 1012 | g_clear_object (&p->brightness_action); |
601 | 1018 | g_clear_object (&p->battery_level_action); | 1013 | g_clear_object (&p->battery_level_action); |
602 | 1019 | g_clear_object (&p->header_action); | 1014 | g_clear_object (&p->header_action); |
603 | 1020 | g_clear_object (&p->show_time_action); | ||
604 | 1021 | g_clear_object (&p->actions); | 1015 | g_clear_object (&p->actions); |
605 | 1022 | 1016 | ||
606 | 1023 | g_clear_object (&p->conn); | 1017 | g_clear_object (&p->conn); |
607 | @@ -1051,8 +1045,6 @@ | |||
608 | 1051 | 1045 | ||
609 | 1052 | g_signal_connect_swapped (p->settings, "changed::" SETTINGS_ICON_POLICY_S, | 1046 | g_signal_connect_swapped (p->settings, "changed::" SETTINGS_ICON_POLICY_S, |
610 | 1053 | G_CALLBACK(rebuild_header_now), self); | 1047 | G_CALLBACK(rebuild_header_now), self); |
611 | 1054 | g_signal_connect (p->settings, "changed::" SETTINGS_SHOW_TIME_S, | ||
612 | 1055 | G_CALLBACK(on_show_time_setting_changed), self); | ||
613 | 1056 | 1048 | ||
614 | 1057 | p->own_id = g_bus_own_name (G_BUS_TYPE_SESSION, | 1049 | p->own_id = g_bus_own_name (G_BUS_TYPE_SESSION, |
615 | 1058 | BUS_NAME, | 1050 | BUS_NAME, |
616 | 1059 | 1051 | ||
617 | === modified file 'tests/test-dbus-listener.cc' | |||
618 | --- tests/test-dbus-listener.cc 2013-01-17 21:07:08 +0000 | |||
619 | +++ tests/test-dbus-listener.cc 2013-08-23 14:01:50 +0000 | |||
620 | @@ -4,16 +4,16 @@ | |||
621 | 4 | Authors: | 4 | Authors: |
622 | 5 | Charles Kerr <charles.kerr@canonical.com> | 5 | Charles Kerr <charles.kerr@canonical.com> |
623 | 6 | 6 | ||
626 | 7 | This program is free software: you can redistribute it and/or modify it | 7 | This program is free software: you can redistribute it and/or modify it |
627 | 8 | under the terms of the GNU General Public License version 3, as published | 8 | under the terms of the GNU General Public License version 3, as published |
628 | 9 | by the Free Software Foundation. | 9 | by the Free Software Foundation. |
629 | 10 | 10 | ||
633 | 11 | This program is distributed in the hope that it will be useful, but | 11 | This program is distributed in the hope that it will be useful, but |
634 | 12 | WITHOUT ANY WARRANTY; without even the implied warranties of | 12 | WITHOUT ANY WARRANTY; without even the implied warranties of |
635 | 13 | MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | 13 | MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
636 | 14 | PURPOSE. See the GNU General Public License for more details. | 14 | PURPOSE. See the GNU General Public License for more details. |
637 | 15 | 15 | ||
639 | 16 | You should have received a copy of the GNU General Public License along | 16 | You should have received a copy of the GNU General Public License along |
640 | 17 | with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | with this program. If not, see <http://www.gnu.org/licenses/>. |
641 | 18 | */ | 18 | */ |
642 | 19 | 19 | ||
643 | @@ -40,7 +40,7 @@ | |||
644 | 40 | int gsd_name_ownership_id; | 40 | int gsd_name_ownership_id; |
645 | 41 | int gsd_power_registration_id; | 41 | int gsd_power_registration_id; |
646 | 42 | char * gsd_power_error_string; | 42 | char * gsd_power_error_string; |
648 | 43 | 43 | ||
649 | 44 | protected: | 44 | protected: |
650 | 45 | 45 | ||
651 | 46 | static void | 46 | static void |
652 | @@ -234,7 +234,7 @@ | |||
653 | 234 | 234 | ||
654 | 235 | // cleanup | 235 | // cleanup |
655 | 236 | g_object_run_dispose (o); // used to get coverage of both branches in the object's dispose func's g_clear_*() calls | 236 | g_object_run_dispose (o); // used to get coverage of both branches in the object's dispose func's g_clear_*() calls |
657 | 237 | g_object_unref (o); | 237 | g_object_unref (o); |
658 | 238 | } | 238 | } |
659 | 239 | 239 | ||
660 | 240 | TEST_F(DbusListenerTest, GSDHasNoDevices) | 240 | TEST_F(DbusListenerTest, GSDHasNoDevices) |
661 | @@ -261,7 +261,7 @@ | |||
662 | 261 | 261 | ||
663 | 262 | // cleanup | 262 | // cleanup |
664 | 263 | g_object_run_dispose (o); // used to get coverage of both branches in the object's dispose func's g_clear_*() calls | 263 | g_object_run_dispose (o); // used to get coverage of both branches in the object's dispose func's g_clear_*() calls |
666 | 264 | g_object_unref (o); | 264 | g_object_unref (o); |
667 | 265 | } | 265 | } |
668 | 266 | 266 | ||
669 | 267 | TEST_F(DbusListenerTest, GSDReturnsError) | 267 | TEST_F(DbusListenerTest, GSDReturnsError) |
670 | @@ -285,7 +285,7 @@ | |||
671 | 285 | 285 | ||
672 | 286 | // cleanup | 286 | // cleanup |
673 | 287 | g_object_run_dispose (o); // used to get coverage of both branches in the object's dispose func's g_clear_*() calls | 287 | g_object_run_dispose (o); // used to get coverage of both branches in the object's dispose func's g_clear_*() calls |
675 | 288 | g_object_unref (o); | 288 | g_object_unref (o); |
676 | 289 | } | 289 | } |
677 | 290 | 290 | ||
678 | 291 | /* This test emits a PropertiesChanged signal and confirms that | 291 | /* This test emits a PropertiesChanged signal and confirms that |
679 | @@ -347,5 +347,5 @@ | |||
680 | 347 | ASSERT_EQ (g_slist_length(devices), 2); | 347 | ASSERT_EQ (g_slist_length(devices), 2); |
681 | 348 | 348 | ||
682 | 349 | // cleanup | 349 | // cleanup |
684 | 350 | g_object_unref (o); | 350 | g_object_unref (o); |
685 | 351 | } | 351 | } |
686 | 352 | 352 | ||
687 | === modified file 'tests/test-device.cc' | |||
688 | --- tests/test-device.cc 2013-06-17 23:01:51 +0000 | |||
689 | +++ tests/test-device.cc 2013-08-23 14:01:50 +0000 | |||
690 | @@ -4,16 +4,16 @@ | |||
691 | 4 | Authors: | 4 | Authors: |
692 | 5 | Charles Kerr <charles.kerr@canonical.com> | 5 | Charles Kerr <charles.kerr@canonical.com> |
693 | 6 | 6 | ||
696 | 7 | This program is free software: you can redistribute it and/or modify it | 7 | This program is free software: you can redistribute it and/or modify it |
697 | 8 | under the terms of the GNU General Public License version 3, as published | 8 | under the terms of the GNU General Public License version 3, as published |
698 | 9 | by the Free Software Foundation. | 9 | by the Free Software Foundation. |
699 | 10 | 10 | ||
703 | 11 | This program is distributed in the hope that it will be useful, but | 11 | This program is distributed in the hope that it will be useful, but |
704 | 12 | WITHOUT ANY WARRANTY; without even the implied warranties of | 12 | WITHOUT ANY WARRANTY; without even the implied warranties of |
705 | 13 | MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | 13 | MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
706 | 14 | PURPOSE. See the GNU General Public License for more details. | 14 | PURPOSE. See the GNU General Public License for more details. |
707 | 15 | 15 | ||
709 | 16 | You should have received a copy of the GNU General Public License along | 16 | You should have received a copy of the GNU General Public License along |
710 | 17 | with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | with this program. If not, see <http://www.gnu.org/licenses/>. |
711 | 18 | */ | 18 | */ |
712 | 19 | 19 | ||
713 | @@ -69,27 +69,52 @@ | |||
714 | 69 | g_strfreev (names); | 69 | g_strfreev (names); |
715 | 70 | } | 70 | } |
716 | 71 | 71 | ||
734 | 72 | void check_strings (const IndicatorPowerDevice * device, | 72 | void check_label (const IndicatorPowerDevice * device, |
735 | 73 | const char * expected_timestring, | 73 | const char * expected_label) |
736 | 74 | const char * expected_details, | 74 | { |
737 | 75 | const char * expected_accessible) | 75 | char * label; |
738 | 76 | { | 76 | |
739 | 77 | char * timestring = NULL; | 77 | label = indicator_power_device_get_label (device); |
740 | 78 | char * details = NULL; | 78 | EXPECT_STREQ (expected_label, label); |
741 | 79 | char * accessible = NULL; | 79 | |
742 | 80 | 80 | g_free (label); | |
743 | 81 | indicator_power_device_get_time_details (device, ×tring, &details, &accessible); | 81 | } |
744 | 82 | EXPECT_STREQ (expected_timestring, timestring); | 82 | |
745 | 83 | EXPECT_STREQ (expected_details, details); | 83 | void check_header (const IndicatorPowerDevice * device, |
746 | 84 | EXPECT_STREQ (expected_accessible, accessible); | 84 | const char * expected_time_and_percent, |
747 | 85 | 85 | const char * expected_time, | |
748 | 86 | g_free (accessible); | 86 | const char * expected_percent, |
749 | 87 | g_free (details); | 87 | const char * expected_a11y) |
750 | 88 | g_free (timestring); | 88 | { |
751 | 89 | char * label; | ||
752 | 90 | char * a11y; | ||
753 | 91 | |||
754 | 92 | indicator_power_device_get_header (device, true, true, &label, &a11y); | ||
755 | 93 | EXPECT_STREQ (expected_time_and_percent, label); | ||
756 | 94 | EXPECT_STREQ (expected_a11y, a11y); | ||
757 | 95 | g_free (label); | ||
758 | 96 | g_free (a11y); | ||
759 | 97 | |||
760 | 98 | indicator_power_device_get_header (device, true, false, &label, &a11y); | ||
761 | 99 | EXPECT_STREQ (expected_time, label); | ||
762 | 100 | EXPECT_STREQ (expected_a11y, a11y); | ||
763 | 101 | g_free (label); | ||
764 | 102 | g_free (a11y); | ||
765 | 103 | |||
766 | 104 | indicator_power_device_get_header (device, false, true, &label, &a11y); | ||
767 | 105 | EXPECT_STREQ (expected_percent, label); | ||
768 | 106 | EXPECT_STREQ (expected_a11y, a11y); | ||
769 | 107 | g_free (label); | ||
770 | 108 | g_free (a11y); | ||
771 | 109 | |||
772 | 110 | indicator_power_device_get_header (device, false, false, &label, &a11y); | ||
773 | 111 | ASSERT_TRUE (!label || !*label); | ||
774 | 112 | EXPECT_STREQ (expected_a11y, a11y); | ||
775 | 113 | g_free (label); | ||
776 | 114 | g_free (a11y); | ||
777 | 89 | } | 115 | } |
778 | 90 | }; | 116 | }; |
779 | 91 | 117 | ||
780 | 92 | |||
781 | 93 | /*** | 118 | /*** |
782 | 94 | **** | 119 | **** |
783 | 95 | ***/ | 120 | ***/ |
784 | @@ -266,7 +291,7 @@ | |||
785 | 266 | g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind, | 291 | g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind, |
786 | 267 | INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_EMPTY, | 292 | INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_EMPTY, |
787 | 268 | NULL); | 293 | NULL); |
789 | 269 | 294 | ||
790 | 270 | g_string_append_printf (expected, "%s-empty-symbolic;", kind_str); | 295 | g_string_append_printf (expected, "%s-empty-symbolic;", kind_str); |
791 | 271 | g_string_append_printf (expected, "gpm-%s-empty;", kind_str); | 296 | g_string_append_printf (expected, "gpm-%s-empty;", kind_str); |
792 | 272 | g_string_append_printf (expected, "gpm-%s-000;", kind_str); | 297 | g_string_append_printf (expected, "gpm-%s-000;", kind_str); |
793 | @@ -434,7 +459,7 @@ | |||
794 | 434 | 459 | ||
795 | 435 | // state unknown | 460 | // state unknown |
796 | 436 | g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind, | 461 | g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind, |
798 | 437 | INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_UNKNOWN, | 462 | INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_UNKNOWN, |
799 | 438 | NULL); | 463 | NULL); |
800 | 439 | g_string_append_printf (expected, "%s-missing-symbolic;", kind_str); | 464 | g_string_append_printf (expected, "%s-missing-symbolic;", kind_str); |
801 | 440 | g_string_append_printf (expected, "gpm-%s-missing;", kind_str); | 465 | g_string_append_printf (expected, "gpm-%s-missing;", kind_str); |
802 | @@ -456,19 +481,21 @@ | |||
803 | 456 | g_setenv ("LANG", "en_US.UTF-8", TRUE); | 481 | g_setenv ("LANG", "en_US.UTF-8", TRUE); |
804 | 457 | 482 | ||
805 | 458 | // bad args: NULL device | 483 | // bad args: NULL device |
808 | 459 | log_count_ipower_expected++; | 484 | log_count_ipower_expected += 5; |
809 | 460 | check_strings (NULL, NULL, NULL, NULL); | 485 | check_label (NULL, NULL); |
810 | 486 | check_header (NULL, NULL, NULL, NULL, NULL); | ||
811 | 461 | 487 | ||
812 | 462 | // bad args: a GObject that isn't a device | 488 | // bad args: a GObject that isn't a device |
814 | 463 | log_count_ipower_expected++; | 489 | log_count_ipower_expected += 5; |
815 | 464 | GObject * o = G_OBJECT(g_cancellable_new()); | 490 | GObject * o = G_OBJECT(g_cancellable_new()); |
817 | 465 | check_strings ((IndicatorPowerDevice*)o, NULL, NULL, NULL); | 491 | check_label ((IndicatorPowerDevice*)o, NULL); |
818 | 492 | check_header (NULL, NULL, NULL, NULL, NULL); | ||
819 | 466 | g_object_unref (o); | 493 | g_object_unref (o); |
820 | 467 | 494 | ||
821 | 468 | /** | 495 | /** |
822 | 469 | *** | 496 | *** |
823 | 470 | **/ | 497 | **/ |
825 | 471 | 498 | ||
826 | 472 | IndicatorPowerDevice * device = INDICATOR_POWER_DEVICE (g_object_new (INDICATOR_POWER_DEVICE_TYPE, NULL)); | 499 | IndicatorPowerDevice * device = INDICATOR_POWER_DEVICE (g_object_new (INDICATOR_POWER_DEVICE_TYPE, NULL)); |
827 | 473 | o = G_OBJECT(device); | 500 | o = G_OBJECT(device); |
828 | 474 | 501 | ||
829 | @@ -478,9 +505,11 @@ | |||
830 | 478 | INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, | 505 | INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, |
831 | 479 | INDICATOR_POWER_DEVICE_TIME, guint64(60*61), | 506 | INDICATOR_POWER_DEVICE_TIME, guint64(60*61), |
832 | 480 | NULL); | 507 | NULL); |
836 | 481 | check_strings (device, "(1:01)", | 508 | check_label (device, "Battery (1:01 to charge)"); |
837 | 482 | "Battery (1:01 to charge)", | 509 | check_header (device, "(1:01, 50%)", |
838 | 483 | "Battery (1 hour 1 minute to charge (50%))"); | 510 | "(1:01)", |
839 | 511 | "(50%)", | ||
840 | 512 | "Battery (1 hour 1 minute to charge, 50%)"); | ||
841 | 484 | 513 | ||
842 | 485 | // discharging, < 12 hours left | 514 | // discharging, < 12 hours left |
843 | 486 | g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, | 515 | g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, |
844 | @@ -488,25 +517,36 @@ | |||
845 | 488 | INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, | 517 | INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, |
846 | 489 | INDICATOR_POWER_DEVICE_TIME, guint64(60*61), | 518 | INDICATOR_POWER_DEVICE_TIME, guint64(60*61), |
847 | 490 | NULL); | 519 | NULL); |
851 | 491 | check_strings (device, "1:01", | 520 | check_label (device, "Battery (1:01 left)"); |
852 | 492 | "Battery (1:01 left)", | 521 | check_header (device, "(1:01, 50%)", |
853 | 493 | "Battery (1 hour 1 minute left (50%))"); | 522 | "(1:01)", |
854 | 523 | "(50%)", | ||
855 | 524 | "Battery (1 hour 1 minute left, 50%)"); | ||
856 | 494 | 525 | ||
857 | 495 | // discharging, > 12 hours left | 526 | // discharging, > 12 hours left |
858 | 527 | // we don't show the clock time when > 12 hours dischargin | ||
859 | 496 | g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, | 528 | g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, |
860 | 497 | INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, | 529 | INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, |
861 | 498 | INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, | 530 | INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, |
862 | 499 | INDICATOR_POWER_DEVICE_TIME, guint64(60*60*13), | 531 | INDICATOR_POWER_DEVICE_TIME, guint64(60*60*13), |
863 | 500 | NULL); | 532 | NULL); |
865 | 501 | check_strings (device, "13:00", "Battery", "Battery"); | 533 | check_label (device, "Battery"); |
866 | 534 | check_header (device, "(50%)", | ||
867 | 535 | "", | ||
868 | 536 | "(50%)", | ||
869 | 537 | "Battery (50%)"); | ||
870 | 502 | 538 | ||
872 | 503 | // fully charged | 539 | // fully charged |
873 | 504 | g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, | 540 | g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, |
874 | 505 | INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_FULLY_CHARGED, | 541 | INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_FULLY_CHARGED, |
875 | 506 | INDICATOR_POWER_DEVICE_PERCENTAGE, 100.0, | 542 | INDICATOR_POWER_DEVICE_PERCENTAGE, 100.0, |
876 | 507 | INDICATOR_POWER_DEVICE_TIME, guint64(0), | 543 | INDICATOR_POWER_DEVICE_TIME, guint64(0), |
877 | 508 | NULL); | 544 | NULL); |
879 | 509 | check_strings (device, "", "Battery (charged)", "Battery (charged)"); | 545 | check_label (device, "Battery (charged)"); |
880 | 546 | check_header (device, "(100%)", | ||
881 | 547 | "", | ||
882 | 548 | "(100%)", | ||
883 | 549 | "Battery (charged, 100%)"); | ||
884 | 510 | 550 | ||
885 | 511 | // percentage but no time estimate | 551 | // percentage but no time estimate |
886 | 512 | g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, | 552 | g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, |
887 | @@ -514,7 +554,11 @@ | |||
888 | 514 | INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, | 554 | INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0, |
889 | 515 | INDICATOR_POWER_DEVICE_TIME, guint64(0), | 555 | INDICATOR_POWER_DEVICE_TIME, guint64(0), |
890 | 516 | NULL); | 556 | NULL); |
892 | 517 | check_strings (device, "(50%)", "Battery (50%)", "Battery (50%)"); | 557 | check_label (device, "Battery (estimating…)"); |
893 | 558 | check_header (device, "(estimating…, 50%)", | ||
894 | 559 | "(estimating…)", | ||
895 | 560 | "(50%)", | ||
896 | 561 | "Battery (estimating…, 50%)"); | ||
897 | 518 | 562 | ||
898 | 519 | // no percentage, no time estimate | 563 | // no percentage, no time estimate |
899 | 520 | g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, | 564 | g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY, |
900 | @@ -522,7 +566,8 @@ | |||
901 | 522 | INDICATOR_POWER_DEVICE_PERCENTAGE, 0.0, | 566 | INDICATOR_POWER_DEVICE_PERCENTAGE, 0.0, |
902 | 523 | INDICATOR_POWER_DEVICE_TIME, guint64(0), | 567 | INDICATOR_POWER_DEVICE_TIME, guint64(0), |
903 | 524 | NULL); | 568 | NULL); |
905 | 525 | check_strings (device, "(not present)", "Battery (not present)", "Battery (not present)"); | 569 | check_label (device, "Battery (not present)"); |
906 | 570 | check_header (device, "", "", "", "Battery (not present)"); | ||
907 | 526 | 571 | ||
908 | 527 | // power line | 572 | // power line |
909 | 528 | g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_LINE_POWER, | 573 | g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_LINE_POWER, |
910 | @@ -530,7 +575,8 @@ | |||
911 | 530 | INDICATOR_POWER_DEVICE_PERCENTAGE, 0.0, | 575 | INDICATOR_POWER_DEVICE_PERCENTAGE, 0.0, |
912 | 531 | INDICATOR_POWER_DEVICE_TIME, guint64(0), | 576 | INDICATOR_POWER_DEVICE_TIME, guint64(0), |
913 | 532 | NULL); | 577 | NULL); |
915 | 533 | check_strings (device, "", "AC Adapter", "AC Adapter"); | 578 | check_label (device, "AC Adapter"); |
916 | 579 | check_header (device, "", "", "", "AC Adapter"); | ||
917 | 534 | 580 | ||
918 | 535 | // cleanup | 581 | // cleanup |
919 | 536 | g_object_unref(o); | 582 | g_object_unref(o); |
920 | @@ -605,7 +651,7 @@ | |||
921 | 605 | ASSERT_EQ (a, indicator_power_service_choose_primary_device(device_list)); | 651 | ASSERT_EQ (a, indicator_power_service_choose_primary_device(device_list)); |
922 | 606 | } | 652 | } |
923 | 607 | } | 653 | } |
925 | 608 | 654 | ||
926 | 609 | // cleanup | 655 | // cleanup |
927 | 610 | g_list_free_full (device_list, g_object_unref); | 656 | g_list_free_full (device_list, g_object_unref); |
928 | 611 | } | 657 | } |
929 | 612 | 658 | ||
930 | === modified file 'tests/test-service.cc' | |||
931 | --- tests/test-service.cc 2013-06-17 23:01:51 +0000 | |||
932 | +++ tests/test-service.cc 2013-08-23 14:01:50 +0000 | |||
933 | @@ -65,7 +65,7 @@ | |||
934 | 65 | virtual void SetUp() | 65 | virtual void SetUp() |
935 | 66 | { | 66 | { |
936 | 67 | ensure_glib_initialized (); | 67 | ensure_glib_initialized (); |
938 | 68 | 68 | ||
939 | 69 | g_setenv( "GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, TRUE); | 69 | g_setenv( "GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, TRUE); |
940 | 70 | 70 | ||
941 | 71 | ac_device = indicator_power_device_new ( | 71 | ac_device = indicator_power_device_new ( |
942 | @@ -90,7 +90,7 @@ | |||
943 | 90 | const char* GetAccessibleDesc (IndicatorPower * power) const | 90 | const char* GetAccessibleDesc (IndicatorPower * power) const |
944 | 91 | { | 91 | { |
945 | 92 | GList * entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); | 92 | GList * entries = indicator_object_get_entries (INDICATOR_OBJECT(power)); |
947 | 93 | g_assert (g_list_length(entries) == 1); | 93 | g_assert (g_list_length(entries) == 1); |
948 | 94 | IndicatorObjectEntry * entry = static_cast<IndicatorObjectEntry*>(entries->data); | 94 | IndicatorObjectEntry * entry = static_cast<IndicatorObjectEntry*>(entries->data); |
949 | 95 | const char * ret = entry->accessible_desc; | 95 | const char * ret = entry->accessible_desc; |
950 | 96 | g_list_free (entries); | 96 | g_list_free (entries); |
951 | @@ -120,7 +120,7 @@ | |||
952 | 120 | devices = g_slist_append (devices, ac_device); | 120 | devices = g_slist_append (devices, ac_device); |
953 | 121 | devices = g_slist_append (devices, battery_device); | 121 | devices = g_slist_append (devices, battery_device); |
954 | 122 | indicator_power_set_devices (power, devices); | 122 | indicator_power_set_devices (power, devices); |
956 | 123 | g_slist_free (devices); | 123 | g_slist_free (devices); |
957 | 124 | 124 | ||
958 | 125 | g_object_unref (power); | 125 | g_object_unref (power); |
959 | 126 | } | 126 | } |
PASSED: Continuous integration, rev:191 jenkins. qa.ubuntu. com/job/ indicator- power-ci/ 51/ jenkins. qa.ubuntu. com/job/ indicator- power-saucy- amd64-ci/ 22 jenkins. qa.ubuntu. com/job/ indicator- power-saucy- armhf-ci/ 22 jenkins. qa.ubuntu. com/job/ indicator- power-saucy- armhf-ci/ 22/artifact/ work/output/ *zip*/output. zip
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild: s-jenkins: 8080/job/ indicator- power-ci/ 51/rebuild
http://