From dd26fa313af6d2f18609b0afa958d62b0181853d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jard=C3=B3n?= Date: Mon, 4 Jul 2011 15:45:01 +0100 Subject: Construct the time details in a separate function --- src/indicator-power.c | 80 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 32 deletions(-) (limited to 'src/indicator-power.c') diff --git a/src/indicator-power.c b/src/indicator-power.c index f9bd9af..723d7f4 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -222,6 +222,50 @@ device_kind_to_localised_string (UpDeviceKind 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 *short_timestring = NULL; + gchar *detailed_timestring = NULL; + + if (time > 0) + { + get_timestring (time, + &short_timestring, + &detailed_timestring); + + *short_details = g_strdup_printf ("(%s)", + short_timestring); + + if (state == UP_DEVICE_STATE_CHARGING) + { + /* TRANSLATORS: %2 is a time string, e.g. "1 hour 5 minutes" */ + *details = g_strdup_printf (_("%s (%s until charged (%.0lf%%))"), + device_name, detailed_timestring, percentage); + } + else if (state == UP_DEVICE_STATE_DISCHARGING) + { + /* TRANSLATORS: %2 is a time string, e.g. "1 hour 5 minutes" */ + *details = g_strdup_printf (_("%s (%s until empty (%.0lf%%))"), + device_name, detailed_timestring, percentage); + } + } + else + { + /* 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); + *short_details = g_strdup_printf (_("(%.0lf%%)"), + percentage); + } +} + static void set_accessible_desc (IndicatorPower *self, const gchar *desc) @@ -247,6 +291,7 @@ get_primary_device_cb (GObject *source_object, UpDeviceState state; GVariant *result; GError *error = NULL; + gchar *short_details = NULL; gchar *details = NULL; gchar **device_icons; gchar *device_icon = NULL; @@ -256,7 +301,6 @@ get_primary_device_cb (GObject *source_object, const gchar *device_name; gchar *short_timestring = NULL; gchar *detailed_timestring = NULL; - gchar *label_text = NULL; result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error); if (result == NULL) @@ -290,41 +334,13 @@ get_primary_device_cb (GObject *source_object, device_name = device_kind_to_localised_string (kind); /* get the description */ - if (time > 0) - { - get_timestring (time, - &short_timestring, - &detailed_timestring); + build_device_time_details (device_name, time, state, percentage, &short_details, &details); - label_text = g_strdup_printf(_("(%s)"), - short_timestring); - - if (state == UP_DEVICE_STATE_CHARGING) - { - /* TRANSLATORS: %2 is a time string, e.g. "1 hour 5 minutes" */ - details = g_strdup_printf(_("%s (%s until charged (%.0lf%%))"), - device_name, detailed_timestring, percentage); - } - else if (state == UP_DEVICE_STATE_DISCHARGING) - { - /* TRANSLATORS: %2 is a time string, e.g. "1 hour 5 minutes" */ - details = g_strdup_printf(_("%s (%s until empty (%.0lf%%))"), - device_name, detailed_timestring, percentage); - } - } - else - { - /* 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); - label_text = g_strdup (details); - } gtk_label_set_label (GTK_LABEL (priv->label), - label_text); + short_details); set_accessible_desc (self, details); - g_free (label_text); + g_free (short_details); g_free (details); g_free (device_icon); g_free (short_timestring); -- cgit v1.2.3