[Xfce4-commits] [xfce/xfce4-power-manager] 10/64: Fix a crash on upower version change
noreply at xfce.org
noreply at xfce.org
Mon May 26 06:00:05 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 d8deb1680f9184330d9413fcd2a41ccfb0d5c831
Author: Eric Koegel <eric.koegel at gmail.com>
Date: Fri May 2 05:17:16 2014 +0300
Fix a crash on upower version change
Also put more trace/dbg messages in place so it's easy to track
these issues when upower breaks itself again in the future.
---
common/xfpm-power-common.c | 15 +++---------
panel-plugins/battery/battery-button.c | 39 ++++++++++++++++++++++++--------
2 files changed, 32 insertions(+), 22 deletions(-)
diff --git a/common/xfpm-power-common.c b/common/xfpm-power-common.c
index 0d321b9..980f236 100644
--- a/common/xfpm-power-common.c
+++ b/common/xfpm-power-common.c
@@ -230,7 +230,7 @@ get_device_icon_name (UpClient *upower, UpDevice *device)
{
gchar *icon_name = NULL, *icon_prefix;
guint type = 0, state = 0;
- gboolean on_battery, battery_low = FALSE;
+ gboolean on_battery;
gboolean present;
gdouble percentage;
@@ -242,12 +242,7 @@ get_device_icon_name (UpClient *upower, UpDevice *device)
"percentage", &percentage,
NULL);
- g_object_get (upower,
- "on-battery", &on_battery,
-#if UP_CHECK_VERSION(0, 99, 0)
- "OnLowBattery", &battery_low,
-#endif
- NULL);
+ on_battery = up_client_get_on_battery (upower);
icon_prefix = xfpm_battery_get_icon_prefix_device_enum_type (type);
@@ -257,13 +252,9 @@ get_device_icon_name (UpClient *upower, UpDevice *device)
{
icon_name = g_strdup_printf ("%s", XFPM_AC_ADAPTER_ICON);
}
- else if ( battery_low )
- {
- icon_name = g_strdup_printf ("%s100", icon_prefix);
- }
else
{
- icon_name = g_strdup_printf ("%s100", icon_prefix);
+ icon_name = g_strdup_printf ("%s060", XFPM_PRIMARY_ICON_PREFIX);
}
}
else if ( type == UP_DEVICE_KIND_BATTERY || type == UP_DEVICE_KIND_UPS )
diff --git a/panel-plugins/battery/battery-button.c b/panel-plugins/battery/battery-button.c
index 4ef12e1..9d268dc 100644
--- a/panel-plugins/battery/battery-button.c
+++ b/panel-plugins/battery/battery-button.c
@@ -39,6 +39,8 @@
#include "battery-button.h"
static void battery_button_finalize (GObject *object);
+static gchar* get_device_description (UpClient *upower, UpDevice *device);
+static GtkTreeIter* find_device_in_tree (BatteryButton *button, const gchar *object_path);
#define BATTERY_BUTTON_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), BATTERY_TYPE_BUTTON, BatteryButtonPrivate))
@@ -78,9 +80,6 @@ enum
NCOLS
};
-static gchar* get_device_description (UpClient *upower, UpDevice *device);
-static GtkTreeIter* find_device_in_tree (BatteryButton *button, const gchar *object_path);
-
G_DEFINE_TYPE (BatteryButton, battery_button, GTK_TYPE_BUTTON)
static void
@@ -360,12 +359,11 @@ get_device_description (UpClient *upower, UpDevice *device)
"time-to-full", &time_to_full,
NULL);
- g_object_get (upower,
- "on-battery", &on_battery,
- NULL);
if (type == UP_DEVICE_KIND_LINE_POWER)
{
+ on_battery = up_client_get_on_battery (upower);
+
if (on_battery)
{
tip = g_strdup_printf(_("<b>On Battery</b>\t"));
@@ -401,7 +399,7 @@ get_device_description (UpClient *upower, UpDevice *device)
if ( time_to_full != 0 )
{
est_time_str = xfpm_battery_get_time_string (time_to_full);
- tip = g_strdup_printf (_("<b>%s %s</b>\t\nCharging (%0.0f%%).\t\n%s until is fully charged.\t"),
+ tip = g_strdup_printf (_("<b>%s %s</b>\t\nCharging (%0.0f%%).\t\n%s until fully charged.\t"),
vendor, model,
percentage,
est_time_str);
@@ -465,16 +463,27 @@ get_device_description (UpClient *upower, UpDevice *device)
static GtkTreeIter*
find_device_in_tree (BatteryButton *button, const gchar *object_path)
{
- GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(button->priv->treeview));
+ GtkTreeModel *model;
GtkTreeIter iter;
+ TRACE("entering");
+
+ g_return_val_if_fail ( BATTERY_IS_BUTTON(button), NULL );
+
+ if ( !button->priv->treeview )
+ return NULL;
+
+ model = gtk_tree_view_get_model(GTK_TREE_VIEW(button->priv->treeview));
+
+ if (!model)
+ return NULL;
+
if(gtk_tree_model_get_iter_first(model, &iter)) {
do {
gchar *path = NULL;
gtk_tree_model_get(model, &iter, COL_OBJ_PATH, &path, -1);
if(g_strcmp0(path, object_path) == 0) {
-
g_free(path);
return gtk_tree_iter_copy(&iter);
}
@@ -486,8 +495,13 @@ find_device_in_tree (BatteryButton *button, const gchar *object_path)
return NULL;
}
+
static void
+#if UP_CHECK_VERSION(0, 99, 0)
+device_changed_cb (UpDevice *device, GParamSpec *pspec, BatteryButton *button)
+#else
device_changed_cb (UpDevice *device, BatteryButton *button)
+#endif
{
GtkTreeIter *iter;
const gchar *object_path = up_device_get_object_path(device);
@@ -496,6 +510,8 @@ device_changed_cb (UpDevice *device, BatteryButton *button)
TRACE("entering for %s", object_path);
+ g_return_if_fail ( BATTERY_IS_BUTTON (button) );
+
iter = find_device_in_tree (button, object_path);
if (iter == NULL)
@@ -529,6 +545,10 @@ battery_button_add_device (UpDevice *device, BatteryButton *button)
const gchar *object_path = up_device_get_object_path(device);
gulong signal_id;
+ TRACE("entering for %s", object_path);
+
+ g_return_if_fail ( BATTERY_IS_BUTTON (button ) );
+
/* don't add the same device twice */
device_iter = find_device_in_tree (button, object_path);
if (device_iter)
@@ -649,7 +669,6 @@ battery_button_add_all_devices (BatteryButton *button)
for ( i = 0; i < array->len; i++)
{
UpDevice *device = g_ptr_array_index (array, i);
- const gchar *object_path = up_device_get_object_path(device);
battery_button_add_device (device, button);
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list