summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli Abdallah <ali.slackware@gmail.com>2009-05-16 17:38:01 +0000
committerAli Abdallah <ali.slackware@gmail.com>2009-05-16 17:38:01 +0000
commitb712e58860b9fc42cdb83658786f0906cfbe14d4 (patch)
tree0a2658a34760d53b6dfe47e41e3fc4600425bcb6
parent10e41dbad7b321d8fc2c92ceedb23bdb97e8c8ac (diff)
downloadixfce4-power-manager-b712e58860b9fc42cdb83658786f0906cfbe14d4.tar.gz
Handle wrong battery information data
(Old svn revision: 7350)
-rw-r--r--ChangeLog3
-rw-r--r--libxfpm/hal-battery.c13
-rw-r--r--libxfpm/xfpm-notify.c7
-rw-r--r--libxfpm/xfpm-notify.h3
-rw-r--r--settings/xfpm-settings.glade1
-rw-r--r--src/xfpm-battery.c21
6 files changed, 44 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 6870d518..88e6b45e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
+2009-05-16 19:37 Ali aliov@xfce.org
+ * : Handle wrong battery information data
+
2009-05-16 19:06 Ali aliov@xfce.org
* : Open settings dialog when tray icon is clicked
diff --git a/libxfpm/hal-battery.c b/libxfpm/hal-battery.c
index c6351125..2e293e4c 100644
--- a/libxfpm/hal-battery.c
+++ b/libxfpm/hal-battery.c
@@ -386,11 +386,20 @@ _get_battery_percentage (guint32 last_full, guint32 current)
guint val = 100;
float f;
- if ( last_full <= current ) return val;
-
+ if ( G_UNLIKELY (last_full <= current) ) return val;
+
+ /*
+ * Special case when we get 0 as last full
+ * this happens for me once i had the battery
+ * totally empty on my aspire one.
+ */
+ if ( G_UNLIKELY (last_full == 0 ) )
+ return 0;
+
f = (float)current/last_full *100;
val = (guint)f;
+
return val;
}
diff --git a/libxfpm/xfpm-notify.c b/libxfpm/xfpm-notify.c
index 5e28b8b9..6d5a1363 100644
--- a/libxfpm/xfpm-notify.c
+++ b/libxfpm/xfpm-notify.c
@@ -260,3 +260,10 @@ void xfpm_notify_close_critical (XfpmNotify *notify)
if ( n )
g_object_unref (n);
}
+
+void xfpm_notify_close_normal (XfpmNotify *notify)
+{
+ g_return_if_fail (XFPM_IS_NOTIFY (notify));
+
+ xfpm_notify_close_notification (notify);
+}
diff --git a/libxfpm/xfpm-notify.h b/libxfpm/xfpm-notify.h
index 84b21fed..5d519ffa 100644
--- a/libxfpm/xfpm-notify.h
+++ b/libxfpm/xfpm-notify.h
@@ -90,6 +90,9 @@ void xfpm_notify_critical (XfpmNotify
NotifyNotification *n);
void xfpm_notify_close_critical (XfpmNotify *notify);
+
+void xfpm_notify_close_normal (XfpmNotify *notify);
+
G_END_DECLS
#endif /* __XFPM_NOTIFY_H */
diff --git a/settings/xfpm-settings.glade b/settings/xfpm-settings.glade
index f2adba75..934d6eaa 100644
--- a/settings/xfpm-settings.glade
+++ b/settings/xfpm-settings.glade
@@ -360,6 +360,7 @@
</child>
</widget>
<packing>
+ <property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
diff --git a/src/xfpm-battery.c b/src/xfpm-battery.c
index 412be75b..3cfcbbe1 100644
--- a/src/xfpm-battery.c
+++ b/src/xfpm-battery.c
@@ -273,7 +273,13 @@ xfpm_battery_get_battery_state (XfpmBatteryState *state,
guint percentage,
guint8 critical_level)
{
- if ( !is_charging && !is_discharging && last_full == current_charge )
+ if ( G_UNLIKELY (current_charge == 0 || percentage == 0) )
+ {
+ *state = BATTERY_CHARGE_CRITICAL;
+ return _("is empty");
+ }
+
+ if ( !is_charging && !is_discharging && current_charge >= last_full )
{
*state = BATTERY_FULLY_CHARGED;
return _("is fully charged");
@@ -322,8 +328,11 @@ xfpm_battery_refresh_common (XfpmBattery *battery, guint percentage, XfpmBattery
battery->priv->state = state;
TRACE("Emitting signal battery state changed");
g_signal_emit (G_OBJECT(battery), signals[BATTERY_STATE_CHANGED], 0, state);
+
if ( battery->priv->state != BATTERY_NOT_FULLY_CHARGED )
xfpm_battery_notify (battery);
+ else
+ xfpm_notify_close_normal (battery->priv->notify);
}
}
@@ -451,7 +460,15 @@ xfpm_battery_refresh (XfpmBattery *battery)
"current-charge", &current_charge,
"time", &time_per,
NULL);
-
+
+ TRACE ("Battery status is_present %s is_charging %s is_discharging %s",
+ xfpm_bool_to_string (is_present),
+ xfpm_bool_to_string (is_charging),
+ xfpm_bool_to_string (is_discharging));
+
+ TRACE ("Battery info precentage %i last_full %i current_charge %i time_per %i",
+ percentage, last_full, current_charge, time_per);
+
battery->priv->type == HAL_DEVICE_TYPE_PRIMARY ?
xfpm_battery_refresh_primary (battery, is_present,
is_charging, is_discharging,