[gnome-settings-daemon] power: Simplify {icon, state}_changed functions
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon] power: Simplify {icon, state}_changed functions
- Date: Fri, 9 Nov 2012 15:07:27 +0000 (UTC)
commit 4bfff3e3bc7bbea8c7a2ff4dad3bd90e36ecb5fd
Author: Bastien Nocera <hadess hadess net>
Date: Fri Nov 9 13:10:30 2012 +0100
power: Simplify {icon,state}_changed functions
plugins/power/gsd-power-manager.c | 60 +++++++++++-------------------------
1 files changed, 19 insertions(+), 41 deletions(-)
---
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index d43f60c..2bc36f2 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -703,58 +703,37 @@ engine_recalculate_state_icon (GsdPowerManager *manager)
/* show a different icon if we are disconnected */
icon = engine_get_icon (manager);
- if (icon == NULL) {
- /* none before, now none */
- if (manager->priv->previous_icon == NULL)
- return FALSE;
-
- g_object_unref (manager->priv->previous_icon);
- manager->priv->previous_icon = NULL;
- return TRUE;
- }
-
- /* no icon before, now icon */
- if (manager->priv->previous_icon == NULL) {
-
- /* set fallback icon */
- manager->priv->previous_icon = icon;
- return TRUE;
+ if (g_icon_equal (icon, manager->priv->previous_icon)) {
+ g_object_unref (icon);
+ return FALSE;
}
- /* icon before, now different */
- if (!g_icon_equal (manager->priv->previous_icon, icon)) {
+ g_clear_object (&manager->priv->previous_icon);
+ manager->priv->previous_icon = icon;
- g_object_unref (manager->priv->previous_icon);
- manager->priv->previous_icon = icon;
- return TRUE;
- }
+ g_debug ("Icon changed");
- g_debug ("no change");
- /* nothing to do */
- g_object_unref (icon);
- return FALSE;
+ return TRUE;
}
static gboolean
engine_recalculate_state_summary (GsdPowerManager *manager)
{
- gchar *summary;
+ char *summary;
summary = engine_get_summary (manager);
- if (manager->priv->previous_summary == NULL) {
- manager->priv->previous_summary = summary;
- return TRUE;
- }
- if (strcmp (manager->priv->previous_summary, summary) != 0) {
- g_free (manager->priv->previous_summary);
- manager->priv->previous_summary = summary;
- return TRUE;
+ if (g_strcmp0 (manager->priv->previous_summary, summary) == 0) {
+ g_free (summary);
+ return FALSE;
}
- g_debug ("no change");
- /* nothing to do */
- g_free (summary);
- return FALSE;
+
+ g_free (manager->priv->previous_summary);
+ manager->priv->previous_summary = summary;
+
+ g_debug ("Summary changed");
+
+ return TRUE;
}
static void
@@ -4126,8 +4105,7 @@ gsd_power_manager_stop (GsdPowerManager *manager)
g_clear_object (&manager->priv->device_composite);
g_clear_object (&manager->priv->previous_icon);
- g_free (manager->priv->previous_summary);
- manager->priv->previous_summary = NULL;
+ g_clear_pointer (&manager->priv->previous_summary, g_free);
g_clear_object (&manager->priv->upower_proxy);
g_clear_object (&manager->priv->session_proxy);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]