Merge lp:~mdeslaur/indicator-power/indicator-power into lp:indicator-power/15.04

Proposed by Marc Deslauriers
Status: Merged
Approved by: Charles Kerr
Approved revision: 280
Merged at revision: 283
Proposed branch: lp:~mdeslaur/indicator-power/indicator-power
Merge into: lp:indicator-power/15.04
Diff against target: 60 lines (+23/-6)
1 file modified
src/service.c (+23/-6)
To merge this branch: bzr merge lp:~mdeslaur/indicator-power/indicator-power
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+252500@code.launchpad.net

Commit message

Change sort order to prefer items with known time remaining

Description of the change

    * Change sort order to prefer items with known time remaining
      (LP: #1315434)

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Marc, thanks for the patch! LGTM.

I'm a little disappointed in myself that this didn't break any tests. I need to expand coverage to test this case :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/service.c'
2--- src/service.c 2015-01-30 17:58:57 +0000
3+++ src/service.c 2015-03-10 19:43:48 +0000
4@@ -161,9 +161,9 @@
5
6 /* sort devices from most interesting to least interesting on this criteria:
7 1. discharging items from least time remaining until most time remaining
8- 2. discharging items with an unknown time remaining
9- 3. charging items from most time left to charge to least time left to charge
10- 4. charging items with an unknown time remaining
11+ 2. charging items from most time left to charge to least time left to charge
12+ 3. charging items with an unknown time remaining
13+ 4. discharging items with an unknown time remaining
14 5. batteries, then non-line power, then line-power */
15 static gint
16 device_compare_func (gconstpointer ga, gconstpointer gb)
17@@ -182,7 +182,8 @@
18 ret = 0;
19
20 state = UP_DEVICE_STATE_DISCHARGING;
21- if (!ret && ((a_state == state) || (b_state == state)))
22+ if (!ret && (((a_state == state) && a_time) ||
23+ ((b_state == state) && b_time)))
24 {
25 if (a_state != state) /* b is discharging */
26 {
27@@ -204,8 +205,7 @@
28 }
29
30 state = UP_DEVICE_STATE_CHARGING;
31- if (!ret && (((a_state == state) && a_time) ||
32- ((b_state == state) && b_time)))
33+ if (!ret && ((a_state == state) || (b_state == state)))
34 {
35 if (a_state != state) /* b is charging */
36 {
37@@ -226,6 +226,23 @@
38 }
39 }
40
41+ state = UP_DEVICE_STATE_DISCHARGING;
42+ if (!ret && ((a_state == state) || (b_state == state)))
43+ {
44+ if (a_state != state) /* b is discharging */
45+ {
46+ ret = 1;
47+ }
48+ else if (b_state != state) /* a is discharging */
49+ {
50+ ret = -1;
51+ }
52+ else /* both are discharging; use percentage */
53+ {
54+ ret = a_percentage < b_percentage ? -1 : 1;
55+ }
56+ }
57+
58 if (!ret) /* neither device is charging nor discharging... */
59 {
60 const int weight_a = get_device_kind_weight (a);

Subscribers

People subscribed via source and target branches