aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2012-11-13 14:40:47 -0600
committerCharles Kerr <charles.kerr@canonical.com>2012-11-13 14:40:47 -0600
commitf6075f09a107998beb6fb8d4bbc111f11a3f9dae (patch)
tree3ed2ff86dba38a43390f8c3a84fe96343bac5d4f
parent014fbc261c19e75f24d46f3f06d3abf63840529e (diff)
parent727b8cab56a9ecd920c5656d09de0c5e6470017b (diff)
downloadayatana-indicator-power-f6075f09a107998beb6fb8d4bbc111f11a3f9dae.tar.gz
ayatana-indicator-power-f6075f09a107998beb6fb8d4bbc111f11a3f9dae.tar.bz2
ayatana-indicator-power-f6075f09a107998beb6fb8d4bbc111f11a3f9dae.zip
backport the 'AC Adapter shown in panel' bugfix from trunk/13.04
-rw-r--r--src/device.c2
-rw-r--r--src/indicator-power.c43
-rw-r--r--tests/test-device.cc29
3 files changed, 60 insertions, 14 deletions
diff --git a/src/device.c b/src/device.c
index 490ff1a..d028ab7 100644
--- a/src/device.c
+++ b/src/device.c
@@ -612,7 +612,7 @@ indicator_power_device_get_time_details (const IndicatorPowerDevice * device,
{
*details = g_strdup (device_name);
*accessible_name = g_strdup (device_name);
- *short_details = g_strdup (device_name);
+ *short_details = g_strdup ("");
}
else
{
diff --git a/src/indicator-power.c b/src/indicator-power.c
index 4118dcc..06f1c2e 100644
--- a/src/indicator-power.c
+++ b/src/indicator-power.c
@@ -352,12 +352,38 @@ build_menu (IndicatorPower *self)
gtk_widget_show_all (GTK_WIDGET (priv->menu));
}
+/* the higher the weight, the more interesting the device */
+static int
+get_device_kind_weight (const IndicatorPowerDevice * device)
+{
+ UpDeviceKind kind;
+ static gboolean initialized = FALSE;
+ static int weights[UP_DEVICE_KIND_LAST];
+
+ kind = indicator_power_device_get_kind (device);
+ g_return_val_if_fail (0<=kind && kind<UP_DEVICE_KIND_LAST, 0);
+
+ if (G_UNLIKELY(!initialized))
+ {
+ int i;
+
+ initialized = TRUE;
+
+ for (i=0; i<UP_DEVICE_KIND_LAST; i++)
+ weights[i] = 1;
+ weights[UP_DEVICE_KIND_BATTERY] = 2;
+ weights[UP_DEVICE_KIND_LINE_POWER] = 0;
+ }
+
+ return weights[kind];
+}
+
/* sort devices from most interesting to least interesting on this criteria:
1. discharging items from least time remaining until most time remaining
2. discharging items with an unknown time remaining
3. charging items from most time left to charge to least time left to charge
4. charging items with an unknown time remaining
- 5. everything else */
+ 5. batteries, then non-line power, then line-power */
static gint
device_compare_func (gconstpointer ga, gconstpointer gb)
{
@@ -418,6 +444,21 @@ device_compare_func (gconstpointer ga, gconstpointer gb)
}
}
+ if (!ret) /* neither device is charging nor discharging... */
+ {
+ const int weight_a = get_device_kind_weight (a);
+ const int weight_b = get_device_kind_weight (b);
+
+ if (weight_a > weight_b)
+ {
+ ret = -1;
+ }
+ else if (weight_a < weight_b)
+ {
+ ret = 1;
+ }
+ }
+
if (!ret)
ret = a_state - b_state;
diff --git a/tests/test-device.cc b/tests/test-device.cc
index 18bdc08..021404f 100644
--- a/tests/test-device.cc
+++ b/tests/test-device.cc
@@ -555,7 +555,7 @@ TEST_F(DeviceTest, Labels)
INDICATOR_POWER_DEVICE_PERCENTAGE, 0.0,
INDICATOR_POWER_DEVICE_TIME, guint64(0),
NULL);
- check_strings (device, "AC Adapter", "AC Adapter", "AC Adapter");
+ check_strings (device, "", "AC Adapter", "AC Adapter");
// cleanup
g_object_unref(o);
@@ -587,19 +587,22 @@ TEST_F(DeviceTest, ChoosePrimary)
sorted in order of preference wrt the spec's criteria.
So tests[i] should be picked over any test with an index greater than i */
struct {
+ int kind;
int state;
guint64 time;
double percentage;
} tests[] = {
- { UP_DEVICE_STATE_DISCHARGING, 49, 50.0 },
- { UP_DEVICE_STATE_DISCHARGING, 50, 50.0 },
- { UP_DEVICE_STATE_DISCHARGING, 50, 100.0 },
- { UP_DEVICE_STATE_DISCHARGING, 51, 50.0 },
- { UP_DEVICE_STATE_CHARGING, 50, 50.0 },
- { UP_DEVICE_STATE_CHARGING, 49, 50.0 },
- { UP_DEVICE_STATE_CHARGING, 49, 100.0 },
- { UP_DEVICE_STATE_CHARGING, 48, 50.0 },
- { UP_DEVICE_STATE_FULLY_CHARGED, 0, 50.0 }
+ { UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 49, 50.0 },
+ { UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 50, 50.0 },
+ { UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 50, 100.0 },
+ { UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 51, 50.0 },
+ { UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 50, 50.0 },
+ { UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 49, 50.0 },
+ { UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 49, 100.0 },
+ { UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 48, 50.0 },
+ { UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_FULLY_CHARGED, 0, 50.0 },
+ { UP_DEVICE_KIND_KEYBOARD, UP_DEVICE_STATE_FULLY_CHARGED, 0, 50.0 },
+ { UP_DEVICE_KIND_LINE_POWER, UP_DEVICE_STATE_UNKNOWN, 0, 0.0 }
};
device_list = NULL;
@@ -610,11 +613,13 @@ TEST_F(DeviceTest, ChoosePrimary)
{
for (int j=i+1; j<n; j++)
{
- g_object_set (a, INDICATOR_POWER_DEVICE_STATE, tests[i].state,
+ g_object_set (a, INDICATOR_POWER_DEVICE_KIND, tests[i].kind,
+ INDICATOR_POWER_DEVICE_STATE, tests[i].state,
INDICATOR_POWER_DEVICE_TIME, guint64(tests[i].time),
INDICATOR_POWER_DEVICE_PERCENTAGE, tests[i].percentage,
NULL);
- g_object_set (b, INDICATOR_POWER_DEVICE_STATE, tests[j].state,
+ g_object_set (b, INDICATOR_POWER_DEVICE_KIND, tests[j].kind,
+ INDICATOR_POWER_DEVICE_STATE, tests[j].state,
INDICATOR_POWER_DEVICE_TIME, guint64(tests[j].time),
INDICATOR_POWER_DEVICE_PERCENTAGE, tests[j].percentage,
NULL);