~charlesk/indicator-power/lp-1100546-not-present-mouse

« back to all changes in this revision

Viewing changes to src/service.c

  • Committer: Charles Kerr
  • Author(s): Shih-Yuan Lee
  • Date: 2017-01-16 18:59:22 UTC
  • Revision ID: charles.kerr@canonical.com-20170116185922-4hze2f0bzacvpcfh
give sorting priority to devices with power supplies

Show diffs side-by-side

added added

removed removed

Lines of Context:
162
162
}
163
163
 
164
164
/* sort devices from most interesting to least interesting on this criteria:
165
 
   1. discharging items from least time remaining until most time remaining
166
 
   2. charging items from most time left to charge to least time left to charge
167
 
   3. charging items with an unknown time remaining
168
 
   4. discharging items with an unknown time remaining
169
 
   5. batteries, then non-line power, then line-power */
 
165
   1. device that supplied the power to the system
 
166
   2. discharging items from least time remaining until most time remaining
 
167
   3. charging items from most time left to charge to least time left to charge
 
168
   4. charging items with an unknown time remaining
 
169
   5. discharging items with an unknown time remaining
 
170
   6. batteries, then non-line power, then line-power */
170
171
static gint
171
172
device_compare_func (gconstpointer ga, gconstpointer gb)
172
173
{
174
175
  int state;
175
176
  const IndicatorPowerDevice * a = ga;
176
177
  const IndicatorPowerDevice * b = gb;
 
178
  const gboolean a_power_supply = indicator_power_device_get_power_supply (a);
 
179
  const gboolean b_power_supply = indicator_power_device_get_power_supply (b);
177
180
  const int a_state = indicator_power_device_get_state (a);
178
181
  const int b_state = indicator_power_device_get_state (b);
179
182
  const gdouble a_percentage = indicator_power_device_get_percentage (a);
183
186
 
184
187
  ret = 0;
185
188
 
 
189
  if (!ret && (a_power_supply != b_power_supply))
 
190
    {
 
191
      if (a_power_supply) /* a provides power to the system */
 
192
        {
 
193
          ret = -1;
 
194
        }
 
195
      else /* b provides power to the system */
 
196
        {
 
197
          ret = 1;
 
198
        }
 
199
    }
 
200
 
186
201
  state = UP_DEVICE_STATE_DISCHARGING;
187
202
  if (!ret && (((a_state == state) && a_time) ||
188
203
               ((b_state == state) && b_time)))
1436
1451
                                           UP_DEVICE_KIND_BATTERY,
1437
1452
                                           percent,
1438
1453
                                           state,
1439
 
                                           time_left);
 
1454
                                           time_left,
 
1455
                                           TRUE);
1440
1456
    }
1441
1457
 
1442
1458
  return device;