Index: branches/hal_based/panel-plugin/battery-monitor.c =================================================================== --- branches/hal_based/panel-plugin/battery-monitor.c (revision 6991) +++ branches/hal_based/panel-plugin/battery-monitor.c (working copy) @@ -274,7 +274,7 @@ info->charge_last_full = info->charge_low = info->charge_warning = 0; info->charge_current = 0; info->percentage = info->remaining_time = 0; - info->is_discharging = info->is_present = FALSE; + info->state = STATE_MISSING; return info; } @@ -340,8 +340,7 @@ global->charge_low = 0; global->charge_warning = 0; global->charge_current = 0; - global->is_discharging = TRUE; - global->is_present = FALSE; + global->state = STATE_MISSING; /* get all devices */ devices = g_hash_table_get_values (monitor->devices); @@ -358,12 +357,12 @@ global->charge_current += info->charge_current; /* global is charging, when atleast one battery is charging */ - if (!info->is_discharging) - global->is_discharging = FALSE; + if (info->state == STATE_CHARGING) + global->state = STATE_CHARGING; /* global is present, when one battery is pressent */ - if (info->is_present) - global->is_present = TRUE; + if (info->state != STATE_MISSING) + global->state = STATE_IDLE; } /* cleanup */ @@ -429,16 +428,21 @@ } } + /* whether the battery is present */ + if (libhal_device_property_exists (monitor->context, udi, "battery.present", &error)) + info->state = libhal_device_get_property_bool (monitor->context, udi, "battery.present", &error) ? + STATE_IDLE : STATE_MISSING; + /* whether the battery is discharging */ if (libhal_device_property_exists (monitor->context, udi, "battery.rechargeable.is_discharging", &error)) - info->is_discharging = libhal_device_get_property_bool (monitor->context, udi, "battery.rechargeable.is_discharging", &error); + info->state = libhal_device_get_property_bool (monitor->context, udi, "battery.rechargeable.is_discharging", &error) ? + STATE_DISCHARGING : info->state; - /* whether the battery is present */ - if (libhal_device_property_exists (monitor->context, udi, "battery.present", &error)) - info->is_present = libhal_device_get_property_bool (monitor->context, udi, "battery.present", &error); - else - info->is_present = FALSE; - + /* whether the battery is discharging */ + if (libhal_device_property_exists (monitor->context, udi, "battery.rechargeable.is_charging", &error)) + info->state = libhal_device_get_property_bool (monitor->context, udi, "battery.rechargeable.is_charging", &error) ? + STATE_CHARGING : info->state; + /* current remaining time */ if (libhal_device_property_exists (monitor->context, udi, "battery.remaining_time", &error)) { @@ -462,7 +466,7 @@ if (info->charge_current == 0) { info->remaining_time = 0; - info->is_present = FALSE; + info->state = STATE_MISSING; } } @@ -473,12 +477,12 @@ monitor->global->charge_current += info->charge_current; /* when atleast one battery is pressent, global is present */ - if (info->is_present) - monitor->global->is_present = TRUE; + if (info->state != STATE_MISSING) + monitor->global->state = STATE_IDLE; /* when one battery is charging, global is charging */ - if (!info->is_discharging && info->is_present) - monitor->global->is_discharging = FALSE; + if (info->state == STATE_CHARGING) + monitor->global->state = STATE_CHARGING; } /* recalculate the battery status */ @@ -669,8 +673,7 @@ if (G_UNLIKELY (monitor->global)) { monitor->global->charge_current = 0; - monitor->global->is_discharging = TRUE; - monitor->global->is_present = FALSE; + monitor->global->state = STATE_MISSING; } /* update all devices */ Index: branches/hal_based/panel-plugin/battery-monitor.h =================================================================== --- branches/hal_based/panel-plugin/battery-monitor.h (revision 6991) +++ branches/hal_based/panel-plugin/battery-monitor.h (working copy) @@ -37,8 +37,15 @@ #define BATTERY_IS_MONITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BATTERY_TYPE_MONITOR)) #define BATTERY_MONITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BATTERY_TYPE_MONITOR, BatteryMonitorClass)) -#define BATTERY_FULLY_CHARGED(info) ((info)->is_discharging == FALSE && (info)->charge_current == (info)->charge_last_full) +#define BATTERY_FULLY_CHARGED(info) ((info)->state == STATE_IDLE) +enum +{ + STATE_MISSING, + STATE_IDLE, + STATE_CHARGING, + STATE_DISCHARGING +}; struct _BatteryInfo @@ -56,8 +63,7 @@ gint charge_current; /* status */ - guint is_discharging : 1; - guint is_present : 1; + guint state; gint percentage; gint remaining_time; }; Index: branches/hal_based/panel-plugin/battery-plugin.c =================================================================== --- branches/hal_based/panel-plugin/battery-plugin.c (revision 6991) +++ branches/hal_based/panel-plugin/battery-plugin.c (working copy) @@ -44,7 +44,7 @@ gchar *icon_name; const gchar *icon_number; - if (info->is_present == FALSE) + if (info == NULL || info->state == STATE_MISSING) { /* no icon present */ icon_name = g_strdup ("ac-adapter"); @@ -71,7 +71,7 @@ icon_number = "100"; /* set name */ - if (info->is_discharging) + if (info->state == STATE_DISCHARGING) icon_name = g_strdup_printf ("battery-discharging-%s", icon_number); else icon_name = g_strdup_printf ("battery-charging-%s", icon_number); @@ -163,21 +163,29 @@ string = g_string_append (string, "medium\">"); /* create the label */ - if (info->is_present == FALSE) + if (info->state == STATE_MISSING) { /* battery not present */ string = g_string_append (string, _("Not Present")); } else if (BATTERY_FULLY_CHARGED (info)) { - /* append "Changed" */ - string = g_string_append (string, _("Charged")); + /* Idle, neither charging nor discharging */ + g_string_append_printf (string, "%s (%d%)", _("Idle"), info->percentage); } else if (info->remaining_time > 0) { /* get panel orientation */ orientation = xfce_panel_plugin_get_orientation (plugin->panel_plugin); - + + if (info->state == STATE_CHARGING) + g_string_append_printf (string, "%s%s", + _("Charging"), + orientation == GTK_ORIENTATION_HORIZONTAL ? " " : "\n "); + else + g_string_append_printf (string, "%s%s", + _("Discharging"), + orientation == GTK_ORIENTATION_HORIZONTAL ? " " : "\n "); /* append both time and percentage */ g_string_append_printf (string, "%d:%02d%s(%d%%)", info->remaining_time / 3600, @@ -209,15 +217,15 @@ { gchar *time_string; - if (info->is_present == FALSE) + if (info == NULL || info->state == STATE_MISSING) { /* Not Present */ string = g_string_append (string, _("Not Present")); } else if (BATTERY_FULLY_CHARGED (info)) { - /* Fully Charged (100%) */ - g_string_append_printf (string, "%s (100%%)", _("Fully Charged")); + /* Idle, neither charging nor discharging */ + g_string_append_printf (string, "%s (%d%)", _("Idle"), info->percentage); } else { @@ -241,7 +249,7 @@ time_string = NULL; } - if (info->is_discharging) + if (info->state == STATE_DISCHARGING) { if (time_string) { @@ -255,7 +263,7 @@ g_string_append_printf (string, "%d%% %s", info->percentage, _("remaining")); } } - else /* charging */ + else if (info->state == STATE_CHARGING) { /* Charging (50% */ g_string_append_printf (string, "%s (%d%%", _("Charging"), info->percentage); @@ -273,6 +281,10 @@ } } + else + { + g_string_append_printf(string, "%s", _("Idle")); + } /* cleanup */ g_free (time_string); } @@ -402,7 +414,7 @@ { info = li->data; - if (info->is_present) + if (info->state != STATE_MISSING) { /* append the battery status */ battery_plugin_update_tooltip_append (string, info); @@ -458,7 +470,7 @@ if (G_LIKELY (info)) { /* hide some widgets when the battery is not present */ - if (!info->is_present) + if (info->state == STATE_MISSING) { /* hide the label when the icon is visible */ if (plugin->show_status_icon)