power: Describe batteries properly when not called BAT0

When the main battery isn't called BAT0, as happens on a dual-battery,
convertible Toshiba laptop, we would tag both batteries as "Extra". Mark
the first one as being the main battery.

In the longer-term, we'll have UPower exporting the exact information
about which is in the "dock" and which is in the same package as the
processing unit, when the kernel exports it.
See https://bugzilla.kernel.org/show_bug.cgi?id=97841

https://bugzilla.gnome.org/show_bug.cgi?id=748592
This commit is contained in:
Bastien Nocera 2015-05-07 12:26:12 +02:00
parent ed1c8d668c
commit f31c3b16c7

View file

@ -397,7 +397,6 @@ add_battery (CcPowerPanel *panel, UpDevice *device)
GtkWidget *levelbar;
GtkWidget *widget;
gchar *s;
gchar *native_path;
gchar *icon_name;
const gchar *name;
@ -405,11 +404,10 @@ add_battery (CcPowerPanel *panel, UpDevice *device)
"kind", &kind,
"state", &state,
"percentage", &percentage,
"native-path", &native_path,
"icon-name", &icon_name,
NULL);
if (native_path && strstr (native_path, "BAT0"))
if (g_object_get_data (G_OBJECT (device), "is-main-battery") != NULL)
name = C_("Battery name", "Main");
else
name = C_("Battery name", "Extra");
@ -471,7 +469,6 @@ add_battery (CcPowerPanel *panel, UpDevice *device)
gtk_size_group_add_widget (priv->row_sizegroup, row);
gtk_widget_show_all (row);
g_free (native_path);
g_free (icon_name);
gtk_widget_set_visible (priv->battery_section, TRUE);
@ -726,13 +723,22 @@ up_client_changed (UpClient *client,
}
else
{
gboolean is_extra_battery = FALSE;
/* Count the batteries */
for (i = 0; priv->devices != NULL && i < priv->devices->len; i++)
{
UpDevice *device = (UpDevice*) g_ptr_array_index (priv->devices, i);
g_object_get (device, "kind", &kind, NULL);
if (kind == UP_DEVICE_KIND_BATTERY)
n_batteries++;
{
n_batteries++;
if (is_extra_battery == FALSE)
{
is_extra_battery = TRUE;
g_object_set_data (G_OBJECT (device), "is-main-battery", GINT_TO_POINTER(TRUE));
}
}
}
}