aboutsummaryrefslogtreecommitdiff
path: root/src/device.c
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2012-06-01 13:20:02 -0500
committerCharles Kerr <charles.kerr@canonical.com>2012-06-01 13:20:02 -0500
commit53d9c7e23ebe4a031af88a71a694643b02598b6e (patch)
tree49e14dff903ee41e7b1633bc20f086e1787bc4aa /src/device.c
parent624a1f305ba4b9914ac489e86a649d117cc33995 (diff)
downloadayatana-indicator-power-53d9c7e23ebe4a031af88a71a694643b02598b6e.tar.gz
ayatana-indicator-power-53d9c7e23ebe4a031af88a71a694643b02598b6e.tar.bz2
ayatana-indicator-power-53d9c7e23ebe4a031af88a71a694643b02598b6e.zip
In indicator_power_device_get_time_details(), remove an unlikely branch that could result in time/detail strings not being set.
Diffstat (limited to 'src/device.c')
-rw-r--r--src/device.c72
1 files changed, 30 insertions, 42 deletions
diff --git a/src/device.c b/src/device.c
index 8f040b2..75a4139 100644
--- a/src/device.c
+++ b/src/device.c
@@ -516,7 +516,7 @@ indicator_power_device_get_time_details (const IndicatorPowerDevice * device,
gchar ** accessible_name)
{
const time_t time = indicator_power_device_get_time (device);
- const UpDeviceState state = indicator_power_device_get_state (device);
+ const UpDeviceState state = indicator_power_device_get_state (device);
const gdouble percentage = indicator_power_device_get_percentage (device);
const gchar * device_name = device_kind_to_localised_string (indicator_power_device_get_kind(device));
@@ -532,58 +532,46 @@ indicator_power_device_get_time_details (const IndicatorPowerDevice * device,
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);
+ *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)
+ else if ((state == UP_DEVICE_STATE_DISCHARGING) && (time > (60*60*12)))
{
+ *accessible_name = g_strdup_printf (_("%s"), device_name);
+ *details = g_strdup_printf (_("%s"), device_name);
+ *short_details = g_strdup_printf ("%s", short_timestring);
+ }
+ 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);
*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
{
- 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)"));
- }
+ *details = g_strdup_printf (_("%s (not present)"), device_name);
+ *accessible_name = g_strdup (*details);
+ *short_details = g_strdup (_("(not present)"));
}
}