aboutsummaryrefslogtreecommitdiff
path: root/src/indicator-power.c
diff options
context:
space:
mode:
authorJavier Jardón <javier.jardon@codethink.co.uk>2011-07-04 15:45:01 +0100
committerJavier Jardón <javier.jardon@codethink.co.uk>2011-07-04 15:45:01 +0100
commitdd26fa313af6d2f18609b0afa958d62b0181853d (patch)
tree7c525eba596f1d2294081fabf1fcdaeb2b74de4d /src/indicator-power.c
parentf29bcda5aa5a4a93fe613ee214073c3ca4d525bc (diff)
downloadayatana-indicator-power-dd26fa313af6d2f18609b0afa958d62b0181853d.tar.gz
ayatana-indicator-power-dd26fa313af6d2f18609b0afa958d62b0181853d.tar.bz2
ayatana-indicator-power-dd26fa313af6d2f18609b0afa958d62b0181853d.zip
Construct the time details in a separate function
Diffstat (limited to 'src/indicator-power.c')
-rw-r--r--src/indicator-power.c80
1 files changed, 48 insertions, 32 deletions
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
@@ -223,6 +223,50 @@ device_kind_to_localised_string (UpDeviceKind kind)
}
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);