[Xfce4-commits] [xfce/xfce4-power-manager] 01/01: Fix uninitialized pointer read
noreply at xfce.org
noreply at xfce.org
Tue Apr 29 07:06:23 CEST 2014
This is an automated email from the git hooks/post-receive script.
eric pushed a commit to branch master
in repository xfce/xfce4-power-manager.
commit 6189440308723dd72fa9a97a0f19db34083c95a9
Author: Eric Koegel <eric.koegel at gmail.com>
Date: Tue Apr 29 08:00:17 2014 +0300
Fix uninitialized pointer read
The tip pointer could be used uninitialized when the device state
is unknown. Also tooltips are now shown for all device types rather
than just UPS and battery (i.e. for the mouse/keyboard icons). This
should prevent some confustion over what the other icons represent.
---
src/xfpm-battery.c | 33 ++++++++++++++++++++++-----------
1 file changed, 22 insertions(+), 11 deletions(-)
diff --git a/src/xfpm-battery.c b/src/xfpm-battery.c
index 603c8de..3a246ad 100644
--- a/src/xfpm-battery.c
+++ b/src/xfpm-battery.c
@@ -405,16 +405,25 @@ xfpm_battery_notify_state (XfpmBattery *battery)
}
/*
- * Refresh tooltip function for UPS and battery device only.
+ * Refresh tooltip function for devices with a battery.
*/
static void
xfpm_battery_set_tooltip_primary (XfpmBattery *battery, GtkTooltip *tooltip)
{
- gchar *tip;
+ gchar *tip = NULL;
gchar *est_time_str = NULL;
gchar *power_status = NULL;
- power_status = g_strdup_printf (battery->priv->ac_online ? _("Adaptor is online") : _("System is running on battery power"));
+ if ( battery->priv->type == UP_DEVICE_KIND_BATTERY ||
+ battery->priv->type == UP_DEVICE_KIND_UPS )
+ {
+ power_status = g_strdup_printf (battery->priv->ac_online ? _("Adaptor is online") : _("System is running on battery power"));
+ }
+ else
+ {
+ /* Let the user know it's not a system battery being monitored */
+ power_status = g_strdup(_("Peripheral Device"));
+ }
if ( battery->priv->state == UP_DEVICE_STATE_FULLY_CHARGED )
{
@@ -489,6 +498,14 @@ xfpm_battery_set_tooltip_primary (XfpmBattery *battery, GtkTooltip *tooltip)
{
tip = g_strdup_printf (_("%s\nYour %s is empty"), power_status, battery->priv->battery_name);
}
+ else
+ {
+ /* unknown device state, just display the percentage */
+ tip = g_strdup_printf (_("%s\nYour %s is at (%i%%)."),
+ power_status,
+ battery->priv->battery_name,
+ battery->priv->percentage);
+ }
gtk_tooltip_set_text (tooltip, tip);
g_free (power_status);
@@ -592,14 +609,8 @@ xfpm_battery_query_tooltip (GtkStatusIcon *icon,
battery = XFPM_BATTERY (icon);
- if ( battery->priv->type == UP_DEVICE_KIND_BATTERY ||
- battery->priv->type == UP_DEVICE_KIND_UPS )
- {
- xfpm_battery_set_tooltip_primary (battery, tooltip);
- return TRUE;
- }
-
- return FALSE;
+ xfpm_battery_set_tooltip_primary (battery, tooltip);
+ return TRUE;
}
static void
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list