From 04891491daee1cfe70aa7652deb09595f379153d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 17 Mar 2012 14:42:05 -0500 Subject: fix variant leaks in menu_add_devices() --- src/indicator-power.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/indicator-power.c') diff --git a/src/indicator-power.c b/src/indicator-power.c index 6140c54..ff56fda 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -615,7 +615,6 @@ static gsize menu_add_devices (GtkMenu *menu, GVariant *devices) { - GVariant *device; gsize n_devices; guint i; @@ -627,8 +626,9 @@ menu_add_devices (GtkMenu *menu, for (i = 0; i < n_devices; i++) { - device = g_variant_get_child_value (devices, i); + GVariant * device = g_variant_get_child_value (devices, i); menu_add_device (menu, device); + g_variant_unref (device); } return n_devices; -- cgit v1.2.3 From a9ab1c3e64481d4ea4cd6d540b0dc75b055193d1 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 17 Mar 2012 14:45:06 -0500 Subject: Fix variant leak in count_batteries() -- the returned value of g_variant_get_child_value() needs to be freed with g_variant_unref() when we're done with it. --- src/indicator-power.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/indicator-power.c') diff --git a/src/indicator-power.c b/src/indicator-power.c index ff56fda..d97ecdd 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -1040,6 +1040,8 @@ count_batteries(GVariant *devices, int *total, int *inuse) if ((state == UP_DEVICE_STATE_CHARGING) || (state == UP_DEVICE_STATE_DISCHARGING)) ++*inuse; } + + g_variant_unref (device); } g_debug("count_batteries found %d batteries (%d are charging/discharging)", *total, *inuse); -- cgit v1.2.3 From 22a82f675f9552756ecac17b0a53a09bb20d1b46 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 17 Mar 2012 14:48:58 -0500 Subject: Fix memory leaks in get_primary_device(). 1. All the calls to g_variant_get_child_value() were leaked. Fixed by changing the use to g_variant_get_child() and keeping index values of the interesting children instead of pointers to them. 2. There were several paths where the local string "object_path" and "device_icon" were leaked. (For example, any non-battery entry given to us by upower). Fixed by making these const strings and peeking them from the variant with "&s" instead of "s". --- src/indicator-power.c | 60 ++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 32 deletions(-) (limited to 'src/indicator-power.c') diff --git a/src/indicator-power.c b/src/indicator-power.c index d97ecdd..701415d 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -688,38 +688,34 @@ build_menu (IndicatorPower *self) static GVariant * get_primary_device (GVariant *devices) { - UpDeviceKind kind; - UpDeviceState state; - GVariant *device; - GVariant *primary_device_charging = NULL; - GVariant *primary_device_discharging = NULL; - GVariant *primary_device = NULL; + gint primary_device_charging_index = -1; + gint primary_device_discharging_index = -1; + gint primary_device_index = -1; gboolean charging = FALSE; gboolean discharging = FALSE; - gchar *object_path; - gchar *device_icon; - gdouble percentage; - guint64 time; guint64 min_discharging_time = G_MAXUINT64; guint64 max_charging_time = 0; - gsize n_devices; guint i; - n_devices = devices ? g_variant_n_children (devices) : 0; + const gsize n_devices = devices ? g_variant_n_children (devices) : 0; g_debug ("Num devices: '%" G_GSIZE_FORMAT "'\n", n_devices); for (i = 0; i < n_devices; i++) { - time = 0; - device = g_variant_get_child_value (devices, i); - g_variant_get (device, - "(susdut)", - &object_path, - &kind, - &device_icon, - &percentage, - &state, - &time); + const gchar *object_path; + UpDeviceKind kind; + const gchar *device_icon; + gdouble percentage; + UpDeviceState state; + guint64 time = 0; + + g_variant_get_child (devices, i, "(&su&sdut)", + &object_path, + &kind, + &device_icon, + &percentage, + &state, + &time); g_debug ("%s: got data from object %s", G_STRFUNC, object_path); @@ -738,7 +734,7 @@ get_primary_device (GVariant *devices) if (time < min_discharging_time) { min_discharging_time = time; - primary_device_discharging = device; + primary_device_discharging_index = i; } } else if (state == UP_DEVICE_STATE_CHARGING) @@ -746,33 +742,33 @@ get_primary_device (GVariant *devices) charging = TRUE; if (time == 0) /* Battery broken */ { - primary_device_charging = device; + primary_device_charging_index = i; } if (time > max_charging_time) { max_charging_time = time; - primary_device_charging = device; + primary_device_charging_index = i; } } else { - primary_device = device; + primary_device_index = i; } - - g_free (device_icon); - g_free (object_path); } if (discharging) { - primary_device = primary_device_discharging; + primary_device_index = primary_device_discharging_index; } else if (charging) { - primary_device = primary_device_charging; + primary_device_index = primary_device_charging_index; } - return primary_device; + if (primary_device_index >= 0) + return g_variant_get_child_value (devices, primary_device_index); + + return NULL; } static void -- cgit v1.2.3 From fd5fac8de3af29f2d7a3ccd985092f9e14361026 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 15 Apr 2012 09:17:21 -0500 Subject: fix leaked strings in menu_add_device when (kind == UP_DEVICE_KIND_LINE_POWER) --- src/indicator-power.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/indicator-power.c') diff --git a/src/indicator-power.c b/src/indicator-power.c index 701415d..ea831e5 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -510,7 +510,7 @@ static GIcon* get_device_icon (UpDeviceKind kind, UpDeviceState state, guint64 time_sec, - gchar *device_icon) + const gchar *device_icon) { GIcon *gicon; @@ -553,8 +553,8 @@ menu_add_device (GtkMenu *menu, GtkWidget *details_label; GtkWidget *grid; GIcon *device_gicons; - gchar *device_icon = NULL; - gchar *object_path = NULL; + const gchar *device_icon = NULL; + const gchar *object_path = NULL; gdouble percentage; guint64 time; const gchar *device_name; @@ -566,7 +566,7 @@ menu_add_device (GtkMenu *menu, return; g_variant_get (device, - "(susdut)", + "(&su&sdut)", &object_path, &kind, &device_icon, @@ -607,8 +607,6 @@ menu_add_device (GtkMenu *menu, g_free (short_details); g_free (details); g_free (accessible_name); - g_free (device_icon); - g_free (object_path); } static gsize -- cgit v1.2.3 From 820cc22b429e6b89f107b9d7baf4414e4c49a338 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 15 Apr 2012 09:23:24 -0500 Subject: tweak: in put_primary_device(), peek at the variant's strings instead of dup'ing them --- src/indicator-power.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/indicator-power.c') diff --git a/src/indicator-power.c b/src/indicator-power.c index cf16fbf..1b3794e 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -785,15 +785,15 @@ put_primary_device (IndicatorPower *self, gchar *short_details = NULL; gchar *details = NULL; gchar *accessible_name = NULL; - gchar *device_icon = NULL; - gchar *object_path = NULL; + const gchar *device_icon = NULL; + const gchar *object_path = NULL; gdouble percentage; guint64 time; const gchar *device_name; /* set the icon and text */ g_variant_get (device, - "(susdut)", + "(&su&sdut)", &object_path, &kind, &device_icon, @@ -825,8 +825,6 @@ put_primary_device (IndicatorPower *self, g_free (short_details); g_free (details); g_free (accessible_name); - g_free (device_icon); - g_free (object_path); } static void -- cgit v1.2.3 From 71a3e5394346f529ae74e7174dd4156c0229d190 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 23 May 2012 22:11:51 -0500 Subject: =?UTF-8?q?replace=20'Power=20Settings...'=20with=20'Power=20Setti?= =?UTF-8?q?ngs=E2=80=A6'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/indicator-power.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/indicator-power.c') diff --git a/src/indicator-power.c b/src/indicator-power.c index 1b3794e..7cdaeb2 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -677,7 +677,7 @@ build_menu (IndicatorPower *self) gtk_menu_shell_append (GTK_MENU_SHELL (self->menu), item); /* preferences */ - item = gtk_image_menu_item_new_with_label (_("Power Settings...")); + item = gtk_image_menu_item_new_with_label (_("Power Settings…")); image = gtk_image_new_from_icon_name (GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_MENU); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); g_signal_connect (G_OBJECT (item), "activate", -- cgit v1.2.3 From f434dc2f9579aeea0c7afe6fa8b78d56c560707f Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 24 May 2012 10:00:15 -0500 Subject: add a 'hello world' test for instantiating IndicatorPower --- src/indicator-power.c | 41 +---------------------------------------- 1 file changed, 1 insertion(+), 40 deletions(-) (limited to 'src/indicator-power.c') diff --git a/src/indicator-power.c b/src/indicator-power.c index 7cdaeb2..ea1caa5 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -31,9 +31,7 @@ with this program. If not, see . /* upower */ #include -/* Indicator Stuff */ -#include -#include +#include "indicator-power.h" #define ICON_POLICY_KEY "icon-policy" @@ -50,43 +48,6 @@ enum { POWER_INDICATOR_ICON_POLICY_NEVER }; -#define INDICATOR_POWER_TYPE (indicator_power_get_type ()) -#define INDICATOR_POWER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_POWER_TYPE, IndicatorPower)) -#define INDICATOR_POWER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INDICATOR_POWER_TYPE, IndicatorPowerClass)) -#define IS_INDICATOR_POWER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_POWER_TYPE)) -#define IS_INDICATOR_POWER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_POWER_TYPE)) -#define INDICATOR_POWER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_POWER_TYPE, IndicatorPowerClass)) - -typedef struct _IndicatorPowerClass IndicatorPowerClass; -typedef struct _IndicatorPower IndicatorPower; - -struct _IndicatorPowerClass -{ - IndicatorObjectClass parent_class; -}; - -struct _IndicatorPower -{ - IndicatorObject parent_instance; - - GtkMenu *menu; - - GtkLabel *label; - GtkImage *status_image; - gchar *accessible_desc; - - GCancellable *proxy_cancel; - GDBusProxy *proxy; - guint watcher_id; - - GVariant *devices; - GVariant *device; - - GSettings *settings; -}; - -GType indicator_power_get_type (void) G_GNUC_CONST; - INDICATOR_SET_VERSION INDICATOR_SET_TYPE (INDICATOR_POWER_TYPE) -- cgit v1.2.3 From 33f4e3d7024984b8b4f3b4fe0b1dfa4ec8ab5700 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 25 May 2012 09:26:06 -0500 Subject: put IndicatorPower's fields back inside a priv struct --- src/indicator-power.c | 154 +++++++++++++++++++++++++++++++------------------- 1 file changed, 96 insertions(+), 58 deletions(-) (limited to 'src/indicator-power.c') diff --git a/src/indicator-power.c b/src/indicator-power.c index ea1caa5..dc1c512 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -48,6 +48,25 @@ enum { POWER_INDICATOR_ICON_POLICY_NEVER }; +struct _IndicatorPowerPrivate +{ + GtkMenu *menu; + + GtkLabel *label; + GtkImage *status_image; + gchar *accessible_desc; + + GCancellable *proxy_cancel; + GDBusProxy *proxy; + guint watcher_id; + + GVariant *devices; + GVariant *device; + + GSettings *settings; +}; + + INDICATOR_SET_VERSION INDICATOR_SET_TYPE (INDICATOR_POWER_TYPE) @@ -76,6 +95,8 @@ indicator_power_class_init (IndicatorPowerClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); IndicatorObjectClass *io_class = INDICATOR_OBJECT_CLASS (klass); + g_type_class_add_private (klass, sizeof (IndicatorPowerPrivate)); + object_class->dispose = indicator_power_dispose; object_class->finalize = indicator_power_finalize; @@ -89,11 +110,15 @@ indicator_power_class_init (IndicatorPowerClass *klass) static void indicator_power_init (IndicatorPower *self) { - self->menu = GTK_MENU(gtk_menu_new()); + IndicatorPowerPrivate * priv; + + priv = G_TYPE_INSTANCE_GET_PRIVATE (self, INDICATOR_POWER_TYPE, IndicatorPowerPrivate); + + priv->menu = GTK_MENU(gtk_menu_new()); - self->accessible_desc = NULL; + priv->accessible_desc = NULL; - self->watcher_id = g_bus_watch_name (G_BUS_TYPE_SESSION, + priv->watcher_id = g_bus_watch_name (G_BUS_TYPE_SESSION, DBUS_SERVICE, G_BUS_NAME_WATCHER_FLAGS_NONE, gsd_appeared_callback, @@ -101,8 +126,8 @@ indicator_power_init (IndicatorPower *self) self, NULL); - self->settings = g_settings_new ("com.canonical.indicator.power"); - g_signal_connect_swapped (self->settings, "changed::" ICON_POLICY_KEY, + priv->settings = g_settings_new ("com.canonical.indicator.power"); + g_signal_connect_swapped (priv->settings, "changed::" ICON_POLICY_KEY, G_CALLBACK(update_visibility), self); g_object_set (G_OBJECT(self), INDICATOR_OBJECT_DEFAULT_VISIBILITY, FALSE, @@ -110,27 +135,30 @@ indicator_power_init (IndicatorPower *self) g_signal_connect (INDICATOR_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED, G_CALLBACK(on_entry_added), NULL); + + self->priv = priv; } static void indicator_power_dispose (GObject *object) { IndicatorPower *self = INDICATOR_POWER(object); + IndicatorPowerPrivate * priv = self->priv; - if (self->devices != NULL) { - g_variant_unref (self->devices); - self->devices = NULL; + if (priv->devices != NULL) { + g_variant_unref (priv->devices); + priv->devices = NULL; } - if (self->device != NULL) { - g_variant_unref (self->device); - self->device = NULL; + if (priv->device != NULL) { + g_variant_unref (priv->device); + priv->device = NULL; } - g_clear_object (&self->proxy); - g_clear_object (&self->proxy_cancel); + g_clear_object (&priv->proxy); + g_clear_object (&priv->proxy_cancel); - g_clear_object (&self->settings); + g_clear_object (&priv->settings); G_OBJECT_CLASS (indicator_power_parent_class)->dispose (object); } @@ -139,8 +167,9 @@ static void indicator_power_finalize (GObject *object) { IndicatorPower *self = INDICATOR_POWER(object); + IndicatorPowerPrivate * priv = self->priv; - g_free (self->accessible_desc); + g_free (priv->accessible_desc); G_OBJECT_CLASS (indicator_power_parent_class)->finalize (object); } @@ -169,7 +198,7 @@ show_info_cb (GtkMenuItem *item, static void option_toggled_cb (GtkCheckMenuItem *item, IndicatorPower * self) { - gtk_widget_set_visible (GTK_WIDGET (self->label), + gtk_widget_set_visible (GTK_WIDGET (self->priv->label), gtk_check_menu_item_get_active(item)); } @@ -368,7 +397,7 @@ build_device_time_details (const gchar *device_name, static void refresh_entry_accessible_desc (IndicatorPower * self, IndicatorObjectEntry * entry) { - const char * newval = self->accessible_desc; + const char * newval = self->priv->accessible_desc; if (entry->accessible_desc != newval) { @@ -394,8 +423,8 @@ set_accessible_desc (IndicatorPower *self, const gchar *desc) if (desc && *desc) { /* update our copy of the string */ - char * oldval = self->accessible_desc; - self->accessible_desc = g_strdup (desc); + char * oldval = self->priv->accessible_desc; + self->priv->accessible_desc = g_strdup (desc); /* ensure that the entries are using self's accessible description */ GList * l; @@ -614,28 +643,29 @@ build_menu (IndicatorPower *self) GtkWidget *image; GList *children; gsize n_devices = 0; + IndicatorPowerPrivate * priv = self->priv; /* remove the existing menuitems */ - children = gtk_container_get_children (GTK_CONTAINER (self->menu)); + children = gtk_container_get_children (GTK_CONTAINER (priv->menu)); g_list_foreach (children, (GFunc) gtk_widget_destroy, NULL); g_list_free (children); /* devices */ - n_devices = menu_add_devices (self->menu, self->devices); + n_devices = menu_add_devices (priv->menu, priv->devices); if (!get_greeter_mode ()) { /* only do the separator if we have at least one device */ if (n_devices != 0) { item = gtk_separator_menu_item_new (); - gtk_menu_shell_append (GTK_MENU_SHELL (self->menu), item); + gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), item); } /* options */ item = gtk_check_menu_item_new_with_label (_("Show Time in Menu Bar")); g_signal_connect (item, "toggled", G_CALLBACK(option_toggled_cb), self); - g_settings_bind (self->settings, "show-time", item, "active", G_SETTINGS_BIND_DEFAULT); - gtk_menu_shell_append (GTK_MENU_SHELL (self->menu), item); + g_settings_bind (priv->settings, "show-time", item, "active", G_SETTINGS_BIND_DEFAULT); + gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), item); /* preferences */ item = gtk_image_menu_item_new_with_label (_("Power Settings…")); @@ -643,11 +673,11 @@ build_menu (IndicatorPower *self) gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (show_preferences_cb), NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (self->menu), item); + gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), item); } /* show the menu */ - gtk_widget_show_all (GTK_WIDGET (self->menu)); + gtk_widget_show_all (GTK_WIDGET (priv->menu)); } static GVariant * @@ -751,6 +781,7 @@ put_primary_device (IndicatorPower *self, gdouble percentage; guint64 time; const gchar *device_name; + IndicatorPowerPrivate * priv = self->priv; /* set the icon and text */ g_variant_get (device, @@ -766,11 +797,11 @@ put_primary_device (IndicatorPower *self, /* set icon */ device_gicons = get_device_icon (kind, state, time, device_icon); - gtk_image_set_from_gicon (self->status_image, + gtk_image_set_from_gicon (priv->status_image, device_gicons, GTK_ICON_SIZE_LARGE_TOOLBAR); g_clear_object (&device_gicons); - gtk_widget_show (GTK_WIDGET (self->status_image)); + gtk_widget_show (GTK_WIDGET (priv->status_image)); /* get the device name */ @@ -779,7 +810,7 @@ put_primary_device (IndicatorPower *self, /* get the description */ build_device_time_details (device_name, time, state, percentage, &short_details, &details, &accessible_name); - gtk_label_set_label (GTK_LABEL (self->label), + gtk_label_set_label (GTK_LABEL (priv->label), short_details); set_accessible_desc (self, accessible_name); @@ -794,6 +825,7 @@ get_devices_cb (GObject *source_object, gpointer user_data) { IndicatorPower *self = INDICATOR_POWER (user_data); + IndicatorPowerPrivate * priv = self->priv; GVariant *devices_container; GError *error = NULL; @@ -805,23 +837,23 @@ get_devices_cb (GObject *source_object, } else /* update 'devices' */ { - if (self->devices != NULL) - g_variant_unref (self->devices); - self->devices = g_variant_get_child_value (devices_container, 0); + if (priv->devices != NULL) + g_variant_unref (priv->devices); + priv->devices = g_variant_get_child_value (devices_container, 0); g_variant_unref (devices_container); - if (self->device != NULL) - g_variant_unref (self->device); - self->device = get_primary_device (self->devices); + if (priv->device != NULL) + g_variant_unref (priv->device); + priv->device = get_primary_device (priv->devices); - if (self->device == NULL) + if (priv->device == NULL) { g_message ("Couldn't find primary device"); } else { - put_primary_device (self, self->device); + put_primary_device (self, priv->device); } } @@ -844,14 +876,15 @@ receive_properties_changed (GDBusProxy *proxy G_GNUC_UNUSED, gpointer user_data) { IndicatorPower *self = INDICATOR_POWER (user_data); + IndicatorPowerPrivate * priv = self->priv; /* it's time to refresh our device list */ - g_dbus_proxy_call (self->proxy, + g_dbus_proxy_call (priv->proxy, "GetDevices", NULL, G_DBUS_CALL_FLAGS_NONE, -1, - self->proxy_cancel, + priv->proxy_cancel, get_devices_cb, user_data); } @@ -862,11 +895,12 @@ service_proxy_cb (GObject *object, gpointer user_data) { IndicatorPower *self = INDICATOR_POWER (user_data); + IndicatorPowerPrivate * priv = self->priv; GError *error = NULL; - self->proxy = g_dbus_proxy_new_for_bus_finish (res, &error); + priv->proxy = g_dbus_proxy_new_for_bus_finish (res, &error); - g_clear_object (&self->proxy_cancel); + g_clear_object (&priv->proxy_cancel); if (error != NULL) { @@ -877,18 +911,18 @@ service_proxy_cb (GObject *object, } /* we want to change the primary device changes */ - g_signal_connect (self->proxy, + g_signal_connect (priv->proxy, "g-properties-changed", G_CALLBACK (receive_properties_changed), user_data); /* get the initial state */ - g_dbus_proxy_call (self->proxy, + g_dbus_proxy_call (priv->proxy, "GetDevices", NULL, G_DBUS_CALL_FLAGS_NONE, -1, - self->proxy_cancel, + priv->proxy_cancel, get_devices_cb, user_data); } @@ -900,8 +934,9 @@ gsd_appeared_callback (GDBusConnection *connection, gpointer user_data) { IndicatorPower *self = INDICATOR_POWER (user_data); + IndicatorPowerPrivate * priv = self->priv; - self->proxy_cancel = g_cancellable_new (); + priv->proxy_cancel = g_cancellable_new (); g_dbus_proxy_new (connection, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, @@ -909,7 +944,7 @@ gsd_appeared_callback (GDBusConnection *connection, name, POWER_DBUS_PATH, POWER_DBUS_INTERFACE, - self->proxy_cancel, + priv->proxy_cancel, service_proxy_cb, self); } @@ -923,32 +958,34 @@ static GtkLabel * get_label (IndicatorObject *io) { IndicatorPower *self = INDICATOR_POWER (io); + IndicatorPowerPrivate * priv = self->priv; - if (self->label == NULL) + if (priv->label == NULL) { /* Create the label if it doesn't exist already */ - self->label = GTK_LABEL (gtk_label_new ("")); - gtk_widget_set_visible (GTK_WIDGET (self->label), FALSE); + priv->label = GTK_LABEL (gtk_label_new ("")); + gtk_widget_set_visible (GTK_WIDGET (priv->label), FALSE); } - return self->label; + return priv->label; } static GtkImage * get_image (IndicatorObject *io) { - IndicatorPower *self = INDICATOR_POWER (io); GIcon *gicon; + IndicatorPower *self = INDICATOR_POWER (io); + IndicatorPowerPrivate * priv = self->priv; - if (self->status_image == NULL) + if (priv->status_image == NULL) { /* Will create the status icon if it doesn't exist already */ gicon = g_themed_icon_new (DEFAULT_ICON); - self->status_image = GTK_IMAGE (gtk_image_new_from_gicon (gicon, + priv->status_image = GTK_IMAGE (gtk_image_new_from_gicon (gicon, GTK_ICON_SIZE_LARGE_TOOLBAR)); } - return self->status_image; + return priv->status_image; } static GtkMenu * @@ -958,7 +995,7 @@ get_menu (IndicatorObject *io) build_menu (self); - return GTK_MENU (self->menu); + return GTK_MENU (self->priv->menu); } static const gchar * @@ -966,7 +1003,7 @@ get_accessible_desc (IndicatorObject *io) { IndicatorPower *self = INDICATOR_POWER (io); - return self->accessible_desc; + return self->priv->accessible_desc; } static const gchar * @@ -1011,8 +1048,9 @@ static gboolean should_be_visible (IndicatorPower * self) { gboolean visible = TRUE; + IndicatorPowerPrivate * priv = self->priv; - const int icon_policy = g_settings_get_enum (self->settings, ICON_POLICY_KEY); + const int icon_policy = g_settings_get_enum (priv->settings, ICON_POLICY_KEY); g_debug ("icon_policy is: %d (present==0, charge==1, never==2)", icon_policy); @@ -1023,7 +1061,7 @@ should_be_visible (IndicatorPower * self) else { int batteries=0, inuse=0; - count_batteries (self->devices, &batteries, &inuse); + count_batteries (priv->devices, &batteries, &inuse); if (icon_policy == POWER_INDICATOR_ICON_POLICY_PRESENT) { -- cgit v1.2.3 From 34c756aa7a894ee9c12f3dce0b4ae6e4ac6a30a8 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 25 May 2012 14:58:56 -0500 Subject: modify IndicatorPower to use IndicatorPowerDevices internally --- src/indicator-power.c | 344 +++++++++++++++++++++++--------------------------- 1 file changed, 159 insertions(+), 185 deletions(-) (limited to 'src/indicator-power.c') diff --git a/src/indicator-power.c b/src/indicator-power.c index dc1c512..c2ace80 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -31,6 +31,7 @@ with this program. If not, see . /* upower */ #include +#include "device.h" #include "indicator-power.h" #define ICON_POLICY_KEY "icon-policy" @@ -60,8 +61,8 @@ struct _IndicatorPowerPrivate GDBusProxy *proxy; guint watcher_id; - GVariant *devices; - GVariant *device; + GSList * devices; + IndicatorPowerDevice * device; GSettings *settings; }; @@ -139,21 +140,22 @@ indicator_power_init (IndicatorPower *self) self->priv = priv; } +static void +dispose_devices (IndicatorPower * self) +{ + IndicatorPowerPrivate * priv = self->priv; + + g_slist_free_full (priv->devices, g_object_unref); + priv->devices = NULL; + g_clear_object (&priv->device); +} static void indicator_power_dispose (GObject *object) { IndicatorPower *self = INDICATOR_POWER(object); IndicatorPowerPrivate * priv = self->priv; - if (priv->devices != NULL) { - g_variant_unref (priv->devices); - priv->devices = NULL; - } - - if (priv->device != NULL) { - g_variant_unref (priv->device); - priv->device = NULL; - } + dispose_devices (self); g_clear_object (&priv->proxy); g_clear_object (&priv->proxy_cancel); @@ -533,99 +535,78 @@ get_device_icon (UpDeviceKind kind, } -static void -menu_add_device (GtkMenu *menu, - GVariant *device) +static gboolean +menu_add_device (GtkMenu * menu, const IndicatorPowerDevice * device) { - UpDeviceKind kind; - UpDeviceState state; - GtkWidget *icon; - GtkWidget *item; - GtkWidget *details_label; - GtkWidget *grid; - GIcon *device_gicons; - const gchar *device_icon = NULL; - const gchar *object_path = NULL; - gdouble percentage; - guint64 time; - const gchar *device_name; - gchar *short_details = NULL; - gchar *details = NULL; - gchar *accessible_name = NULL; - AtkObject *atk_object; - - if (device == NULL) - return; - - g_variant_get (device, - "(&su&sdut)", - &object_path, - &kind, - &device_icon, - &percentage, - &state, - &time); - - g_debug ("%s: got data from object %s", G_STRFUNC, object_path); + gboolean added = FALSE; + const UpDeviceKind kind = indicator_power_device_get_kind (device); if (kind == UP_DEVICE_KIND_LINE_POWER) - return; - - /* Process the data */ - device_gicons = get_device_icon (kind, state, time, device_icon); - icon = gtk_image_new_from_gicon (device_gicons, - GTK_ICON_SIZE_SMALL_TOOLBAR); - g_clear_object (&device_gicons); - - device_name = device_kind_to_localised_string (kind); - - build_device_time_details (device_name, time, state, percentage, &short_details, &details, &accessible_name); - - /* Create menu item */ - item = gtk_image_menu_item_new (); - atk_object = gtk_widget_get_accessible(item); - if (atk_object != NULL) - atk_object_set_name (atk_object, accessible_name); - - grid = gtk_grid_new (); - gtk_grid_set_column_spacing (GTK_GRID (grid), 6); - gtk_grid_attach (GTK_GRID (grid), icon, 0, 0, 1, 1); - details_label = gtk_label_new (details); - gtk_grid_attach_next_to (GTK_GRID (grid), details_label, icon, GTK_POS_RIGHT, 1, 1); - gtk_container_add (GTK_CONTAINER (item), grid); - gtk_widget_show (grid); + { + GtkWidget *icon; + GtkWidget *item; + GtkWidget *details_label; + GtkWidget *grid; + GIcon *device_gicons; + const gchar *device_name; + gchar *short_details = NULL; + gchar *details = NULL; + gchar *accessible_name = NULL; + AtkObject *atk_object; + const time_t time = indicator_power_device_get_time (device); + const UpDeviceState state = indicator_power_device_get_state (device); + const gchar * device_icon = indicator_power_device_get_icon (device); + const gdouble percentage = indicator_power_device_get_percentage (device); + + /* Process the data */ + device_gicons = get_device_icon (kind, state, time, device_icon); + icon = gtk_image_new_from_gicon (device_gicons, + GTK_ICON_SIZE_SMALL_TOOLBAR); + g_clear_object (&device_gicons); + + device_name = device_kind_to_localised_string (kind); + + build_device_time_details (device_name, time, state, percentage, &short_details, &details, &accessible_name); + + /* Create menu item */ + item = gtk_image_menu_item_new (); + atk_object = gtk_widget_get_accessible(item); + if (atk_object != NULL) + atk_object_set_name (atk_object, accessible_name); + + grid = gtk_grid_new (); + gtk_grid_set_column_spacing (GTK_GRID (grid), 6); + gtk_grid_attach (GTK_GRID (grid), icon, 0, 0, 1, 1); + details_label = gtk_label_new (details); + gtk_grid_attach_next_to (GTK_GRID (grid), details_label, icon, GTK_POS_RIGHT, 1, 1); + gtk_container_add (GTK_CONTAINER (item), grid); + gtk_widget_show (grid); + + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + added = TRUE; - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + g_signal_connect (G_OBJECT (item), "activate", + G_CALLBACK (show_info_cb), NULL); - g_signal_connect (G_OBJECT (item), "activate", - G_CALLBACK (show_info_cb), NULL); + g_free (short_details); + g_free (details); + g_free (accessible_name); + } - g_free (short_details); - g_free (details); - g_free (accessible_name); + return added; } static gsize -menu_add_devices (GtkMenu *menu, - GVariant *devices) +menu_add_devices (GtkMenu * menu, GSList * devices) { - gsize n_devices; - guint i; - - if (devices == NULL) - return 0; + GSList * l; + gsize n_added = 0; - n_devices = g_variant_n_children (devices); - g_debug ("Num devices: '%" G_GSIZE_FORMAT "'\n", n_devices); + for (l=devices; l!=NULL; l=l->next) + if (menu_add_device (menu, l->data)) + ++n_added; - for (i = 0; i < n_devices; i++) - { - GVariant * device = g_variant_get_child_value (devices, i); - menu_add_device (menu, device); - g_variant_unref (device); - } - - return n_devices; + return n_added; } static gboolean @@ -680,39 +661,25 @@ build_menu (IndicatorPower *self) gtk_widget_show_all (GTK_WIDGET (priv->menu)); } -static GVariant * -get_primary_device (GVariant *devices) +static IndicatorPowerDevice* +get_primary_device (GSList * devices) { - gint primary_device_charging_index = -1; - gint primary_device_discharging_index = -1; - gint primary_device_index = -1; + IndicatorPowerDevice * primary_device = NULL; + IndicatorPowerDevice * primary_device_charging = NULL; + IndicatorPowerDevice * primary_device_discharging = NULL; gboolean charging = FALSE; gboolean discharging = FALSE; guint64 min_discharging_time = G_MAXUINT64; guint64 max_charging_time = 0; - guint i; + GSList * l; - const gsize n_devices = devices ? g_variant_n_children (devices) : 0; - g_debug ("Num devices: '%" G_GSIZE_FORMAT "'\n", n_devices); - - for (i = 0; i < n_devices; i++) + for (l=devices; l!=NULL; l=l->next) { - const gchar *object_path; - UpDeviceKind kind; - const gchar *device_icon; - gdouble percentage; - UpDeviceState state; - guint64 time = 0; - - g_variant_get_child (devices, i, "(&su&sdut)", - &object_path, - &kind, - &device_icon, - &percentage, - &state, - &time); - - g_debug ("%s: got data from object %s", G_STRFUNC, object_path); + IndicatorPowerDevice * device = INDICATOR_POWER_DEVICE(l->data); + const UpDeviceKind kind = indicator_power_device_get_kind (device); + const UpDeviceState state = indicator_power_device_get_state (device); + const gdouble percentage = indicator_power_device_get_percentage (device); + const time_t time = indicator_power_device_get_time (device); /* Try to fix the case when we get a empty battery bay as a real battery */ if (state == UP_DEVICE_STATE_UNKNOWN && @@ -729,7 +696,7 @@ get_primary_device (GVariant *devices) if (time < min_discharging_time) { min_discharging_time = time; - primary_device_discharging_index = i; + primary_device_discharging = device; } } else if (state == UP_DEVICE_STATE_CHARGING) @@ -737,64 +704,49 @@ get_primary_device (GVariant *devices) charging = TRUE; if (time == 0) /* Battery broken */ { - primary_device_charging_index = i; + primary_device_charging = device; } if (time > max_charging_time) { max_charging_time = time; - primary_device_charging_index = i; + primary_device_charging = device; } } else { - primary_device_index = i; + primary_device = device; } } if (discharging) { - primary_device_index = primary_device_discharging_index; + primary_device = primary_device_discharging; } else if (charging) { - primary_device_index = primary_device_charging_index; + primary_device = primary_device_charging; } - if (primary_device_index >= 0) - return g_variant_get_child_value (devices, primary_device_index); + if (primary_device != NULL) + g_object_ref (primary_device); - return NULL; + return primary_device; } static void -put_primary_device (IndicatorPower *self, - GVariant *device) +put_primary_device (IndicatorPower *self, IndicatorPowerDevice *device) { - UpDeviceKind kind; - UpDeviceState state; GIcon *device_gicons; gchar *short_details = NULL; gchar *details = NULL; gchar *accessible_name = NULL; - const gchar *device_icon = NULL; - const gchar *object_path = NULL; - gdouble percentage; - guint64 time; const gchar *device_name; IndicatorPowerPrivate * priv = self->priv; - - /* set the icon and text */ - g_variant_get (device, - "(&su&sdut)", - &object_path, - &kind, - &device_icon, - &percentage, - &state, - &time); - - g_debug ("%s: got data from object %s", G_STRFUNC, object_path); - + const time_t time = indicator_power_device_get_time (device); + const UpDeviceKind kind = indicator_power_device_get_kind (device); + const UpDeviceState state = indicator_power_device_get_state (device); + const gchar * device_icon = indicator_power_device_get_icon (device); + const gdouble percentage = indicator_power_device_get_percentage (device); /* set icon */ device_gicons = get_device_icon (kind, state, time, device_icon); gtk_image_set_from_gicon (priv->status_image, @@ -819,47 +771,75 @@ put_primary_device (IndicatorPower *self, g_free (accessible_name); } +void +indicator_power_set_devices (IndicatorPower * self, + IndicatorPowerDevice ** devices, + gsize device_count) +{ + gsize i; + IndicatorPowerPrivate * priv; + + g_return_if_fail (IS_INDICATOR_POWER(self)); + priv = self->priv; + + /* clear out the previous values */ + dispose_devices (self); + + /* get the new devices */ + for (i=0; idevices = g_slist_prepend (priv->devices, g_object_ref(devices[i])); + priv->devices = g_slist_reverse (priv->devices); + + /* get the new primary device */ + priv->device = get_primary_device (priv->devices); + if (priv->device) + put_primary_device (self, priv->device); + else + g_message ("Couldn't find primary device"); + + build_menu (self); + update_visibility (self); +} + static void -get_devices_cb (GObject *source_object, - GAsyncResult *res, - gpointer user_data) +get_devices_cb (GObject * source_object, + GAsyncResult * res, + gpointer user_data) { + GError *error; + int device_count; + IndicatorPowerDevice ** devices; + GVariant * devices_container; IndicatorPower *self = INDICATOR_POWER (user_data); - IndicatorPowerPrivate * priv = self->priv; - GVariant *devices_container; - GError *error = NULL; + /* build an array of IndicatorPowerDevices from the DBus response */ + error = NULL; devices_container = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error); if (devices_container == NULL) { g_message ("Couldn't get devices: %s\n", error->message); g_error_free (error); } - else /* update 'devices' */ + else { - if (priv->devices != NULL) - g_variant_unref (priv->devices); - priv->devices = g_variant_get_child_value (devices_container, 0); + gsize i; + GVariant * devices_variant = g_variant_get_child_value (devices_container, 0); + device_count = devices_variant ? g_variant_n_children (devices_variant) : 0; + devices = g_new0 (IndicatorPowerDevice*, device_count); - g_variant_unref (devices_container); - - if (priv->device != NULL) - g_variant_unref (priv->device); - priv->device = get_primary_device (priv->devices); - - if (priv->device == NULL) + for (i=0; idevice); - } - } - build_menu (self); + g_variant_unref (devices_variant); + g_variant_unref (devices_container); + } - update_visibility (self); + indicator_power_set_devices (self, devices, device_count); + g_free (devices); } static void @@ -1017,28 +997,22 @@ get_name_hint (IndicatorObject *io) ***/ static void -count_batteries(GVariant *devices, int *total, int *inuse) +count_batteries (GSList * devices, int *total, int *inuse) { - const int n_devices = devices ? g_variant_n_children (devices) : 0; + GSList * l; - int i; - for (i=0; inext) { - GVariant * device = g_variant_get_child_value (devices, i); + const IndicatorPowerDevice * device = INDICATOR_POWER_DEVICE(l->data); - UpDeviceKind kind; - g_variant_get_child (device, 1, "u", &kind); - if (kind == UP_DEVICE_KIND_BATTERY) + if (indicator_power_device_get_kind(device) == UP_DEVICE_KIND_BATTERY) { ++*total; - UpDeviceState state; - g_variant_get_child (device, 4, "u", &state); + const UpDeviceState state = indicator_power_device_get_state (device); if ((state == UP_DEVICE_STATE_CHARGING) || (state == UP_DEVICE_STATE_DISCHARGING)) ++*inuse; } - - g_variant_unref (device); } g_debug("count_batteries found %d batteries (%d are charging/discharging)", *total, *inuse); -- cgit v1.2.3 From ce8268447f48ba8d8bff99d8ac402be7bb9c01d5 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 25 May 2012 15:31:16 -0500 Subject: indicator_power_set_devices() should fail gracefully when no devices are available --- src/indicator-power.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/indicator-power.c') diff --git a/src/indicator-power.c b/src/indicator-power.c index c2ace80..59f884a 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -747,6 +747,9 @@ put_primary_device (IndicatorPower *self, IndicatorPowerDevice *device) const UpDeviceState state = indicator_power_device_get_state (device); const gchar * device_icon = indicator_power_device_get_icon (device); const gdouble percentage = indicator_power_device_get_percentage (device); + +g_message ("new primary device: %s", indicator_power_device_get_object_path(device)); + /* set icon */ device_gicons = get_device_icon (kind, state, time, device_icon); gtk_image_set_from_gicon (priv->status_image, @@ -807,9 +810,9 @@ get_devices_cb (GObject * source_object, gpointer user_data) { GError *error; - int device_count; - IndicatorPowerDevice ** devices; + int device_count = 0; GVariant * devices_container; + IndicatorPowerDevice ** devices = NULL; IndicatorPower *self = INDICATOR_POWER (user_data); /* build an array of IndicatorPowerDevices from the DBus response */ -- cgit v1.2.3 From 73d31da1baed181dee9cead8a710444f4a4363a6 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 25 May 2012 16:00:56 -0500 Subject: fix negated logic in menu_add_device() introduced in r160 --- src/indicator-power.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/indicator-power.c') diff --git a/src/indicator-power.c b/src/indicator-power.c index 59f884a..768504d 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -541,7 +541,7 @@ menu_add_device (GtkMenu * menu, const IndicatorPowerDevice * device) gboolean added = FALSE; const UpDeviceKind kind = indicator_power_device_get_kind (device); - if (kind == UP_DEVICE_KIND_LINE_POWER) + if (kind != UP_DEVICE_KIND_LINE_POWER) { GtkWidget *icon; GtkWidget *item; -- cgit v1.2.3 From 7ac2b78246e26f354453935301ed322eb6870c3a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 25 May 2012 17:10:52 -0500 Subject: make indicator_power_set_devices() safe for passing in the same devices more than once --- src/indicator-power.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src/indicator-power.c') diff --git a/src/indicator-power.c b/src/indicator-power.c index 768504d..6eb6904 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -145,9 +145,9 @@ dispose_devices (IndicatorPower * self) { IndicatorPowerPrivate * priv = self->priv; + g_clear_object (&priv->device); g_slist_free_full (priv->devices, g_object_unref); priv->devices = NULL; - g_clear_object (&priv->device); } static void indicator_power_dispose (GObject *object) @@ -748,8 +748,6 @@ put_primary_device (IndicatorPower *self, IndicatorPowerDevice *device) const gchar * device_icon = indicator_power_device_get_icon (device); const gdouble percentage = indicator_power_device_get_percentage (device); -g_message ("new primary device: %s", indicator_power_device_get_object_path(device)); - /* set icon */ device_gicons = get_device_icon (kind, state, time, device_icon); gtk_image_set_from_gicon (priv->status_image, @@ -780,26 +778,30 @@ indicator_power_set_devices (IndicatorPower * self, gsize device_count) { gsize i; + GSList * new_devices; IndicatorPowerPrivate * priv; g_return_if_fail (IS_INDICATOR_POWER(self)); priv = self->priv; - /* clear out the previous values */ - dispose_devices (self); - - /* get the new devices */ + /* make a reff'ed list of the new devices */ + new_devices = NULL; for (i=0; idevices = g_slist_prepend (priv->devices, g_object_ref(devices[i])); - priv->devices = g_slist_reverse (priv->devices); + new_devices = g_slist_prepend (new_devices, g_object_ref(devices[i])); + new_devices = g_slist_reverse (new_devices); - /* get the new primary device */ + /* clear out the old devices */ + dispose_devices (self); + + /* add the new ones */ + priv->devices = new_devices; priv->device = get_primary_device (priv->devices); - if (priv->device) + + /* and update ourselves based on this new data */ + if (priv->device != NULL) put_primary_device (self, priv->device); else g_message ("Couldn't find primary device"); - build_menu (self); update_visibility (self); } -- cgit v1.2.3 From 9ee74a367606a4dd6779b0448bef237dd9e2797e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 26 May 2012 15:19:38 -0500 Subject: separate the dbus org.gnome.SettingsDaemon.Power logic into a separate class --- src/indicator-power.c | 155 +++----------------------------------------------- 1 file changed, 9 insertions(+), 146 deletions(-) (limited to 'src/indicator-power.c') diff --git a/src/indicator-power.c b/src/indicator-power.c index 6eb6904..dc95aae 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -20,7 +20,7 @@ with this program. If not, see . */ #ifdef HAVE_CONFIG_H -#include "config.h" + #include "config.h" #endif /* GStuff */ @@ -28,9 +28,7 @@ with this program. If not, see . #include #include -/* upower */ -#include - +#include "dbus-listener.h" #include "device.h" #include "indicator-power.h" @@ -38,11 +36,6 @@ with this program. If not, see . #define DEFAULT_ICON "gpm-battery-missing" -#define DBUS_SERVICE "org.gnome.SettingsDaemon" -#define DBUS_PATH "/org/gnome/SettingsDaemon" -#define POWER_DBUS_PATH DBUS_PATH "/Power" -#define POWER_DBUS_INTERFACE "org.gnome.SettingsDaemon.Power" - enum { POWER_INDICATOR_ICON_POLICY_PRESENT, POWER_INDICATOR_ICON_POLICY_CHARGE, @@ -57,9 +50,7 @@ struct _IndicatorPowerPrivate GtkImage *status_image; gchar *accessible_desc; - GCancellable *proxy_cancel; - GDBusProxy *proxy; - guint watcher_id; + IndicatorPowerDbusListener * dbus_listener; GSList * devices; IndicatorPowerDevice * device; @@ -86,7 +77,9 @@ static gboolean should_be_visible (IndicatorPower * self); static void on_entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data); +/* static void gsd_appeared_callback (GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data); +*/ G_DEFINE_TYPE (IndicatorPower, indicator_power, INDICATOR_OBJECT_TYPE); @@ -119,14 +112,9 @@ indicator_power_init (IndicatorPower *self) priv->accessible_desc = NULL; - priv->watcher_id = g_bus_watch_name (G_BUS_TYPE_SESSION, - DBUS_SERVICE, - G_BUS_NAME_WATCHER_FLAGS_NONE, - gsd_appeared_callback, - NULL, - self, - NULL); - + priv->dbus_listener = g_object_new (INDICATOR_POWER_DBUS_LISTENER_TYPE, + INDICATOR_POWER_DBUS_LISTENER_INDICATOR, self, + NULL); priv->settings = g_settings_new ("com.canonical.indicator.power"); g_signal_connect_swapped (priv->settings, "changed::" ICON_POLICY_KEY, G_CALLBACK(update_visibility), self); @@ -157,9 +145,7 @@ indicator_power_dispose (GObject *object) dispose_devices (self); - g_clear_object (&priv->proxy); - g_clear_object (&priv->proxy_cancel); - + g_clear_object (&priv->dbus_listener); g_clear_object (&priv->settings); G_OBJECT_CLASS (indicator_power_parent_class)->dispose (object); @@ -806,47 +792,6 @@ indicator_power_set_devices (IndicatorPower * self, update_visibility (self); } -static void -get_devices_cb (GObject * source_object, - GAsyncResult * res, - gpointer user_data) -{ - GError *error; - int device_count = 0; - GVariant * devices_container; - IndicatorPowerDevice ** devices = NULL; - IndicatorPower *self = INDICATOR_POWER (user_data); - - /* build an array of IndicatorPowerDevices from the DBus response */ - error = NULL; - devices_container = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error); - if (devices_container == NULL) - { - g_message ("Couldn't get devices: %s\n", error->message); - g_error_free (error); - } - else - { - gsize i; - GVariant * devices_variant = g_variant_get_child_value (devices_container, 0); - device_count = devices_variant ? g_variant_n_children (devices_variant) : 0; - devices = g_new0 (IndicatorPowerDevice*, device_count); - - for (i=0; ipriv; - - /* it's time to refresh our device list */ - g_dbus_proxy_call (priv->proxy, - "GetDevices", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - priv->proxy_cancel, - get_devices_cb, - user_data); -} - -static void -service_proxy_cb (GObject *object, - GAsyncResult *res, - gpointer user_data) -{ - IndicatorPower *self = INDICATOR_POWER (user_data); - IndicatorPowerPrivate * priv = self->priv; - GError *error = NULL; - - priv->proxy = g_dbus_proxy_new_for_bus_finish (res, &error); - - g_clear_object (&priv->proxy_cancel); - - if (error != NULL) - { - g_error ("Error creating proxy: %s", error->message); - g_error_free (error); - - return; - } - - /* we want to change the primary device changes */ - g_signal_connect (priv->proxy, - "g-properties-changed", - G_CALLBACK (receive_properties_changed), - user_data); - - /* get the initial state */ - g_dbus_proxy_call (priv->proxy, - "GetDevices", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - priv->proxy_cancel, - get_devices_cb, - user_data); -} - -static void -gsd_appeared_callback (GDBusConnection *connection, - const gchar *name, - const gchar *name_owner, - gpointer user_data) -{ - IndicatorPower *self = INDICATOR_POWER (user_data); - IndicatorPowerPrivate * priv = self->priv; - - priv->proxy_cancel = g_cancellable_new (); - - g_dbus_proxy_new (connection, - G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, - NULL, - name, - POWER_DBUS_PATH, - POWER_DBUS_INTERFACE, - priv->proxy_cancel, - service_proxy_cb, - self); -} - - - /* Grabs the label. Creates it if it doesn't exist already */ -- cgit v1.2.3 From 194cfbc5c7be5b7b298a6e7079452af2f8331142 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 26 May 2012 16:57:13 -0500 Subject: try adding LCOV_EXCL_{START,STOP} for unreachable conditions (glib looking for subclasses of IndicatorPowerDevice; unreachables in G_DEFINE_TYPE) --- src/indicator-power.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/indicator-power.c') diff --git a/src/indicator-power.c b/src/indicator-power.c index dc95aae..cf96619 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -59,8 +59,10 @@ struct _IndicatorPowerPrivate }; +/* LCOV_EXCL_START */ INDICATOR_SET_VERSION INDICATOR_SET_TYPE (INDICATOR_POWER_TYPE) +/* LCOV_EXCL_STOP */ /* Prototypes */ static void indicator_power_dispose (GObject *object); @@ -81,7 +83,9 @@ static void on_entry_added (IndicatorObject * io, I static void gsd_appeared_callback (GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data); */ +/* LCOV_EXCL_START */ G_DEFINE_TYPE (IndicatorPower, indicator_power, INDICATOR_OBJECT_TYPE); +/* LCOV_EXCL_STOP */ static void indicator_power_class_init (IndicatorPowerClass *klass) @@ -767,7 +771,9 @@ indicator_power_set_devices (IndicatorPower * self, GSList * new_devices; IndicatorPowerPrivate * priv; +/* LCOV_EXCL_START */ g_return_if_fail (IS_INDICATOR_POWER(self)); +/* LCOV_EXCL_STOP */ priv = self->priv; /* make a reff'ed list of the new devices */ -- cgit v1.2.3 From 23a2672a1a763cdef67ccc5cb9f8fec7daf021be Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 27 May 2012 09:22:28 -0500 Subject: use signals to decouple i-power and dbus-listener --- src/indicator-power.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) (limited to 'src/indicator-power.c') diff --git a/src/indicator-power.c b/src/indicator-power.c index cf96619..6690f9b 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -116,9 +116,10 @@ indicator_power_init (IndicatorPower *self) priv->accessible_desc = NULL; - priv->dbus_listener = g_object_new (INDICATOR_POWER_DBUS_LISTENER_TYPE, - INDICATOR_POWER_DBUS_LISTENER_INDICATOR, self, - NULL); + priv->dbus_listener = g_object_new (INDICATOR_POWER_DBUS_LISTENER_TYPE, NULL); + g_signal_connect_swapped (priv->dbus_listener, INDICATOR_POWER_DBUS_LISTENER_DEVICES_ENUMERATED, + G_CALLBACK(indicator_power_set_devices), self); + priv->settings = g_settings_new ("com.canonical.indicator.power"); g_signal_connect_swapped (priv->settings, "changed::" ICON_POLICY_KEY, G_CALLBACK(update_visibility), self); @@ -763,33 +764,22 @@ put_primary_device (IndicatorPower *self, IndicatorPowerDevice *device) } void -indicator_power_set_devices (IndicatorPower * self, - IndicatorPowerDevice ** devices, - gsize device_count) +indicator_power_set_devices (IndicatorPower * self, GSList * devices) { - gsize i; - GSList * new_devices; IndicatorPowerPrivate * priv; -/* LCOV_EXCL_START */ + /* LCOV_EXCL_START */ g_return_if_fail (IS_INDICATOR_POWER(self)); -/* LCOV_EXCL_STOP */ + /* LCOV_EXCL_STOP */ priv = self->priv; - /* make a reff'ed list of the new devices */ - new_devices = NULL; - for (i=0; idevices = new_devices; + priv->devices = g_slist_copy (devices); priv->device = get_primary_device (priv->devices); - /* and update ourselves based on this new data */ + /* and our menus/visibility from the new device list */ if (priv->device != NULL) put_primary_device (self, priv->device); else -- cgit v1.2.3 From 5786ecae0d9ecae7aaf2b19094474db54e53a691 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 29 May 2012 14:41:27 -0500 Subject: t^Cak to indicator_set_power_differences() --- src/indicator-power.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/indicator-power.c') diff --git a/src/indicator-power.c b/src/indicator-power.c index 6690f9b..7029739 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -766,12 +766,11 @@ put_primary_device (IndicatorPower *self, IndicatorPowerDevice *device) void indicator_power_set_devices (IndicatorPower * self, GSList * devices) { - IndicatorPowerPrivate * priv; - /* LCOV_EXCL_START */ g_return_if_fail (IS_INDICATOR_POWER(self)); /* LCOV_EXCL_STOP */ - priv = self->priv; + + IndicatorPowerPrivate * priv = self->priv; /* update our devices & primary device */ g_slist_foreach (devices, (GFunc)g_object_ref, NULL); -- cgit v1.2.3 From b18b5862fb4e69773bf89328f4c65fdd344d8f1a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 31 May 2012 13:00:31 -0500 Subject: Add indicator_power_device_get_icon_names(). The main goal of this change is to make it possible to test the device's icon. A secondary goal is to clarify in the code how indicator-power's icons differ from the ones recommended by GSD. --- src/indicator-power.c | 116 ++++---------------------------------------------- 1 file changed, 8 insertions(+), 108 deletions(-) (limited to 'src/indicator-power.c') diff --git a/src/indicator-power.c b/src/indicator-power.c index 7029739..96c0f1d 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -431,101 +431,6 @@ set_accessible_desc (IndicatorPower *self, const gchar *desc) } } -static const gchar * -get_icon_percentage_for_status (const gchar *status) -{ - - if (g_strcmp0 (status, "caution") == 0) - return "000"; - else if (g_strcmp0 (status, "low") == 0) - return "040"; - else if (g_strcmp0 (status, "good") == 0) - return "080"; - else - return "100"; -} - -static GIcon* -build_battery_icon (UpDeviceState state, - gchar *suffix_str) -{ - GIcon *gicon; - - GString *filename; - gchar **iconnames; - - filename = g_string_new (NULL); - - if (state == UP_DEVICE_STATE_FULLY_CHARGED) - { - g_string_append (filename, "battery-charged;"); - g_string_append (filename, "battery-full-charged-symbolic;"); - g_string_append (filename, "battery-full-charged;"); - g_string_append (filename, "gpm-battery-charged;"); - g_string_append (filename, "gpm-battery-100-charging;"); - } - else if (state == UP_DEVICE_STATE_CHARGING) - { - g_string_append (filename, "battery-000-charging;"); - g_string_append (filename, "battery-caution-charging-symbolic;"); - g_string_append (filename, "battery-caution-charging;"); - g_string_append (filename, "gpm-battery-000-charging;"); - } - else if (state == UP_DEVICE_STATE_DISCHARGING) - { - const gchar *percentage = get_icon_percentage_for_status (suffix_str); - g_string_append_printf (filename, "battery-%s;", suffix_str); - g_string_append_printf (filename, "battery-%s-symbolic;", suffix_str); - g_string_append_printf (filename, "battery-%s;", percentage); - g_string_append_printf (filename, "gpm-battery-%s;", percentage); - } - - iconnames = g_strsplit (filename->str, ";", -1); - gicon = g_themed_icon_new_from_names (iconnames, -1); - - g_strfreev (iconnames); - g_string_free (filename, TRUE); - - return gicon; -} - -static GIcon* -get_device_icon (UpDeviceKind kind, - UpDeviceState state, - guint64 time_sec, - const gchar *device_icon) -{ - GIcon *gicon = NULL; - - if (kind == UP_DEVICE_KIND_BATTERY && - (state == UP_DEVICE_STATE_FULLY_CHARGED || - state == UP_DEVICE_STATE_CHARGING || - state == UP_DEVICE_STATE_DISCHARGING)) - { - if (state == UP_DEVICE_STATE_FULLY_CHARGED || - state == UP_DEVICE_STATE_CHARGING) - { - gicon = build_battery_icon (state, NULL); - } - else if (state == UP_DEVICE_STATE_DISCHARGING) - { - if ((time_sec > 60 * 30) && /* more than 30 minutes left */ - (g_strrstr (device_icon, "000") || - g_strrstr (device_icon, "020") || - g_strrstr (device_icon, "caution"))) /* the icon is red */ - { - gicon = build_battery_icon (state, "low"); - } - } - } - - if (gicon == NULL) - gicon = g_icon_new_for_string (device_icon, NULL); - - return gicon; -} - - static gboolean menu_add_device (GtkMenu * menu, const IndicatorPowerDevice * device) { @@ -538,7 +443,7 @@ menu_add_device (GtkMenu * menu, const IndicatorPowerDevice * device) GtkWidget *item; GtkWidget *details_label; GtkWidget *grid; - GIcon *device_gicons; + GIcon *device_gicon; const gchar *device_name; gchar *short_details = NULL; gchar *details = NULL; @@ -546,14 +451,12 @@ menu_add_device (GtkMenu * menu, const IndicatorPowerDevice * device) AtkObject *atk_object; const time_t time = indicator_power_device_get_time (device); const UpDeviceState state = indicator_power_device_get_state (device); - const gchar * device_icon = indicator_power_device_get_icon (device); const gdouble percentage = indicator_power_device_get_percentage (device); /* Process the data */ - device_gicons = get_device_icon (kind, state, time, device_icon); - icon = gtk_image_new_from_gicon (device_gicons, - GTK_ICON_SIZE_SMALL_TOOLBAR); - g_clear_object (&device_gicons); + device_gicon = indicator_power_device_get_gicon (device); + icon = gtk_image_new_from_gicon (device_gicon, GTK_ICON_SIZE_SMALL_TOOLBAR); + g_clear_object (&device_gicon); device_name = device_kind_to_localised_string (kind); @@ -727,7 +630,7 @@ get_primary_device (GSList * devices) static void put_primary_device (IndicatorPower *self, IndicatorPowerDevice *device) { - GIcon *device_gicons; + GIcon *device_gicon; gchar *short_details = NULL; gchar *details = NULL; gchar *accessible_name = NULL; @@ -736,15 +639,12 @@ put_primary_device (IndicatorPower *self, IndicatorPowerDevice *device) const time_t time = indicator_power_device_get_time (device); const UpDeviceKind kind = indicator_power_device_get_kind (device); const UpDeviceState state = indicator_power_device_get_state (device); - const gchar * device_icon = indicator_power_device_get_icon (device); const gdouble percentage = indicator_power_device_get_percentage (device); /* set icon */ - device_gicons = get_device_icon (kind, state, time, device_icon); - gtk_image_set_from_gicon (priv->status_image, - device_gicons, - GTK_ICON_SIZE_LARGE_TOOLBAR); - g_clear_object (&device_gicons); + device_gicon = indicator_power_device_get_gicon (device); + gtk_image_set_from_gicon (priv->status_image, device_gicon, GTK_ICON_SIZE_LARGE_TOOLBAR); + g_clear_object (&device_gicon); gtk_widget_show (GTK_WIDGET (priv->status_image)); -- cgit v1.2.3 From 8476e802d84ee91e50dd6556d8293ece77033201 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 31 May 2012 14:00:12 -0500 Subject: Move private indicator-power function build_device_time_details() to device.c to public function indicator_power_device_get_time_details() so that we can unit test the user-visible strings. --- src/indicator-power.c | 201 +------------------------------------------------- 1 file changed, 3 insertions(+), 198 deletions(-) (limited to 'src/indicator-power.c') diff --git a/src/indicator-power.c b/src/indicator-power.c index 96c0f1d..d5735ee 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -202,190 +202,6 @@ show_preferences_cb (GtkMenuItem *item, spawn_command_line_async ("gnome-control-center power"); } -static void -get_timestring (guint64 time_secs, - gchar **short_timestring, - gchar **detailed_timestring) -{ - gint hours; - gint minutes; - - /* Add 0.5 to do rounding */ - minutes = (int) ( ( time_secs / 60.0 ) + 0.5 ); - - if (minutes == 0) - { - *short_timestring = g_strdup (_("Unknown time")); - *detailed_timestring = g_strdup (_("Unknown time")); - - return; - } - - if (minutes < 60) - { - *short_timestring = g_strdup_printf ("0:%.2i", minutes); - *detailed_timestring = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "%i minute", - "%i minutes", - minutes), minutes); - return; - } - - hours = minutes / 60; - minutes = minutes % 60; - - *short_timestring = g_strdup_printf ("%i:%.2i", hours, minutes); - - if (minutes == 0) - { - *detailed_timestring = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, - "%i hour", - "%i hours", - hours), hours); - } - else - { - /* TRANSLATOR: "%i %s %i %s" are "%i hours %i minutes" - * Swap order with "%2$s %2$i %1$s %1$i if needed */ - *detailed_timestring = g_strdup_printf (_("%i %s %i %s"), - hours, g_dngettext (GETTEXT_PACKAGE, "hour", "hours", hours), - minutes, g_dngettext (GETTEXT_PACKAGE, "minute", "minutes", minutes)); - } -} - -static const gchar * -device_kind_to_localised_string (UpDeviceKind kind) -{ - const gchar *text = NULL; - - switch (kind) { - case UP_DEVICE_KIND_LINE_POWER: - /* TRANSLATORS: system power cord */ - text = _("AC adapter"); - break; - case UP_DEVICE_KIND_BATTERY: - /* TRANSLATORS: laptop primary battery */ - text = _("Battery"); - break; - case UP_DEVICE_KIND_UPS: - /* TRANSLATORS: battery-backed AC power source */ - text = _("UPS"); - break; - case UP_DEVICE_KIND_MONITOR: - /* TRANSLATORS: a monitor is a device to measure voltage and current */ - text = _("Monitor"); - break; - case UP_DEVICE_KIND_MOUSE: - /* TRANSLATORS: wireless mice with internal batteries */ - text = _("Mouse"); - break; - case UP_DEVICE_KIND_KEYBOARD: - /* TRANSLATORS: wireless keyboard with internal battery */ - text = _("Keyboard"); - break; - case UP_DEVICE_KIND_PDA: - /* TRANSLATORS: portable device */ - text = _("PDA"); - break; - case UP_DEVICE_KIND_PHONE: - /* TRANSLATORS: cell phone (mobile...) */ - text = _("Cell phone"); - break; - case UP_DEVICE_KIND_MEDIA_PLAYER: - /* TRANSLATORS: media player, mp3 etc */ - text = _("Media player"); - break; - case UP_DEVICE_KIND_TABLET: - /* TRANSLATORS: tablet device */ - text = _("Tablet"); - break; - case UP_DEVICE_KIND_COMPUTER: - /* TRANSLATORS: tablet device */ - text = _("Computer"); - break; - default: - g_warning ("enum unrecognised: %i", kind); - text = up_device_kind_to_string (kind); - } - - return text; -} - -static void -build_device_time_details (const gchar *device_name, - guint64 time, - UpDeviceState state, - gdouble percentage, - gchar **short_details, - gchar **details, - gchar **accessible_name) -{ - gchar *short_timestring = NULL; - gchar *detailed_timestring = NULL; - - if (time > 0) - { - get_timestring (time, - &short_timestring, - &detailed_timestring); - - if (state == UP_DEVICE_STATE_CHARGING) - { - /* TRANSLATORS: %2 is a time string, e.g. "1 hour 5 minutes" */ - *accessible_name = g_strdup_printf (_("%s (%s to charge (%.0lf%%))"), - device_name, detailed_timestring, percentage); - *details = g_strdup_printf (_("%s (%s to charge)"), - device_name, short_timestring); - *short_details = g_strdup_printf ("(%s)", short_timestring); - } - else if (state == UP_DEVICE_STATE_DISCHARGING) - { - *short_details = g_strdup_printf ("%s", short_timestring); - - if (time > 43200) /* 12 hours */ - { - *accessible_name = g_strdup_printf (_("%s"), device_name); - *details = g_strdup_printf (_("%s"), device_name); - } - else - { - /* TRANSLATORS: %2 is a time string, e.g. "1 hour 5 minutes" */ - *accessible_name = g_strdup_printf (_("%s (%s left (%.0lf%%))"), - device_name, detailed_timestring, percentage); - *details = g_strdup_printf (_("%s (%s left)"), - device_name, short_timestring); - } - } - - g_free (short_timestring); - g_free (detailed_timestring); - } - else - { - if (state == UP_DEVICE_STATE_FULLY_CHARGED) - { - *details = g_strdup_printf (_("%s (charged)"), device_name); - *accessible_name = g_strdup (*details); - *short_details = g_strdup (""); - } - else if (percentage > 0) - { - /* TRANSLATORS: %2 is a percentage value. Note: this string is only - * used when we don't have a time value */ - *details = g_strdup_printf (_("%s (%.0lf%%)"), - device_name, percentage); - *accessible_name = g_strdup (*details); - *short_details = g_strdup_printf (_("(%.0lf%%)"), - percentage); - } - else - { - *details = g_strdup_printf (_("%s (not present)"), device_name); - *accessible_name = g_strdup (*details); - *short_details = g_strdup (_("(not present)")); - } - } -} - /* ensure that the entry is using self's accessible description */ static void refresh_entry_accessible_desc (IndicatorPower * self, IndicatorObjectEntry * entry) @@ -444,23 +260,17 @@ menu_add_device (GtkMenu * menu, const IndicatorPowerDevice * device) GtkWidget *details_label; GtkWidget *grid; GIcon *device_gicon; - const gchar *device_name; gchar *short_details = NULL; gchar *details = NULL; gchar *accessible_name = NULL; AtkObject *atk_object; - const time_t time = indicator_power_device_get_time (device); - const UpDeviceState state = indicator_power_device_get_state (device); - const gdouble percentage = indicator_power_device_get_percentage (device); /* Process the data */ device_gicon = indicator_power_device_get_gicon (device); icon = gtk_image_new_from_gicon (device_gicon, GTK_ICON_SIZE_SMALL_TOOLBAR); g_clear_object (&device_gicon); - device_name = device_kind_to_localised_string (kind); - - build_device_time_details (device_name, time, state, percentage, &short_details, &details, &accessible_name); + indicator_power_device_get_time_details (device, &short_details, &details, &accessible_name); /* Create menu item */ item = gtk_image_menu_item_new (); @@ -634,12 +444,7 @@ put_primary_device (IndicatorPower *self, IndicatorPowerDevice *device) gchar *short_details = NULL; gchar *details = NULL; gchar *accessible_name = NULL; - const gchar *device_name; IndicatorPowerPrivate * priv = self->priv; - const time_t time = indicator_power_device_get_time (device); - const UpDeviceKind kind = indicator_power_device_get_kind (device); - const UpDeviceState state = indicator_power_device_get_state (device); - const gdouble percentage = indicator_power_device_get_percentage (device); /* set icon */ device_gicon = indicator_power_device_get_gicon (device); @@ -649,10 +454,10 @@ put_primary_device (IndicatorPower *self, IndicatorPowerDevice *device) /* get the device name */ - device_name = device_kind_to_localised_string (kind); + //device_name = device_kind_to_localised_string (kind); /* get the description */ - build_device_time_details (device_name, time, state, percentage, &short_details, &details, &accessible_name); + indicator_power_device_get_time_details (device, &short_details, &details, &accessible_name); gtk_label_set_label (GTK_LABEL (priv->label), short_details); -- cgit v1.2.3 From 66ba8edb03428310abe360f443849cb8e57c3480 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 1 Jun 2012 14:48:05 -0500 Subject: In indicator-power.c's put_primary_device(), remove dead code. --- src/indicator-power.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'src/indicator-power.c') diff --git a/src/indicator-power.c b/src/indicator-power.c index d5735ee..33f49e7 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -440,32 +440,24 @@ get_primary_device (GSList * devices) static void put_primary_device (IndicatorPower *self, IndicatorPowerDevice *device) { - GIcon *device_gicon; - gchar *short_details = NULL; - gchar *details = NULL; - gchar *accessible_name = NULL; IndicatorPowerPrivate * priv = self->priv; /* set icon */ - device_gicon = indicator_power_device_get_gicon (device); + GIcon * device_gicon = indicator_power_device_get_gicon (device); gtk_image_set_from_gicon (priv->status_image, device_gicon, GTK_ICON_SIZE_LARGE_TOOLBAR); g_clear_object (&device_gicon); gtk_widget_show (GTK_WIDGET (priv->status_image)); - - /* get the device name */ - //device_name = device_kind_to_localised_string (kind); - /* get the description */ + gchar * short_details; + gchar * details; + gchar * accessible_name; indicator_power_device_get_time_details (device, &short_details, &details, &accessible_name); - - gtk_label_set_label (GTK_LABEL (priv->label), - short_details); + gtk_label_set_label (GTK_LABEL (priv->label), short_details); set_accessible_desc (self, accessible_name); - - g_free (short_details); - g_free (details); g_free (accessible_name); + g_free (details); + g_free (short_details); } void -- cgit v1.2.3 From 867f9fe6955aed2b63bf671f85ae403a6152db74 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 7 Jun 2012 10:36:13 -0500 Subject: remove some dead code. --- src/indicator-power.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) (limited to 'src/indicator-power.c') diff --git a/src/indicator-power.c b/src/indicator-power.c index 33f49e7..f3a7235 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -180,14 +180,6 @@ spawn_command_line_async (const char * command) g_clear_error (&err); } -static void -show_info_cb (GtkMenuItem *item, - gpointer data) -{ - /*TODO: show the statistics of the specific device*/ - spawn_command_line_async ("gnome-power-statistics"); -} - static void option_toggled_cb (GtkCheckMenuItem *item, IndicatorPower * self) { @@ -195,13 +187,6 @@ option_toggled_cb (GtkCheckMenuItem *item, IndicatorPower * self) gtk_check_menu_item_get_active(item)); } -static void -show_preferences_cb (GtkMenuItem *item, - gpointer data) -{ - spawn_command_line_async ("gnome-control-center power"); -} - /* ensure that the entry is using self's accessible description */ static void refresh_entry_accessible_desc (IndicatorPower * self, IndicatorObjectEntry * entry) @@ -289,8 +274,8 @@ menu_add_device (GtkMenu * menu, const IndicatorPowerDevice * device) gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); added = TRUE; - g_signal_connect (G_OBJECT (item), "activate", - G_CALLBACK (show_info_cb), NULL); + g_signal_connect_swapped (G_OBJECT (item), "activate", + G_CALLBACK (spawn_command_line_async), "gnome-power-statistics"); g_free (short_details); g_free (details); @@ -356,8 +341,8 @@ build_menu (IndicatorPower *self) item = gtk_image_menu_item_new_with_label (_("Power Settings…")); image = gtk_image_new_from_icon_name (GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_MENU); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); - g_signal_connect (G_OBJECT (item), "activate", - G_CALLBACK (show_preferences_cb), NULL); + g_signal_connect_swapped (G_OBJECT (item), "activate", + G_CALLBACK (spawn_command_line_async), "gnome-control-center power"); gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), item); } -- cgit v1.2.3