aboutsummaryrefslogtreecommitdiff
path: root/src/device.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/device.c')
-rw-r--r--src/device.c88
1 files changed, 50 insertions, 38 deletions
diff --git a/src/device.c b/src/device.c
index ed3c399..eff76d1 100644
--- a/src/device.c
+++ b/src/device.c
@@ -44,8 +44,6 @@ struct _IndicatorPowerDevicePrivate
GTimer * inestimable;
};
-#define INDICATOR_POWER_DEVICE_GET_PRIVATE(o) (INDICATOR_POWER_DEVICE(o)->priv)
-
/* Properties */
/* Enum for the properties so that they can be quickly found and looked up. */
enum {
@@ -69,7 +67,7 @@ static void set_property (GObject*, guint prop_id, const GValue*, GParamSpec* );
static void get_property (GObject*, guint prop_id, GValue*, GParamSpec* );
/* LCOV_EXCL_START */
-G_DEFINE_TYPE (IndicatorPowerDevice, indicator_power_device, G_TYPE_OBJECT);
+G_DEFINE_TYPE (IndicatorPowerDevice, indicator_power_device, G_TYPE_OBJECT)
/* LCOV_EXCL_STOP */
static void
@@ -189,7 +187,7 @@ get_property (GObject * o, guint prop_id, GValue * value, GParamSpec * pspec)
break;
case PROP_TIME:
- g_value_set_uint64 (value, priv->time);
+ g_value_set_uint64 (value, (guint64)priv->time);
break;
default:
@@ -207,11 +205,11 @@ set_property (GObject * o, guint prop_id, const GValue * value, GParamSpec * psp
switch (prop_id)
{
case PROP_KIND:
- p->kind = g_value_get_int (value);
+ p->kind = (UpDeviceKind) g_value_get_int (value);
break;
case PROP_STATE:
- p->state = g_value_get_int (value);
+ p->state = (UpDeviceState) g_value_get_int (value);
break;
case PROP_OBJECT_PATH:
@@ -224,7 +222,7 @@ set_property (GObject * o, guint prop_id, const GValue * value, GParamSpec * psp
break;
case PROP_TIME:
- p->time = g_value_get_uint64(value);
+ p->time = (time_t) g_value_get_uint64(value);
break;
default:
@@ -355,13 +353,6 @@ device_kind_to_string (UpDeviceKind kind)
indicator_power_device_get_icon_names:
@device: #IndicatorPowerDevice from which to generate the icon names
- This function's logic differs from GSD's power plugin in some ways:
-
- 1. For discharging batteries, we decide whether or not to use the 'caution'
- icon based on whether or not we have <= 30 minutes remaining, rather than
- looking at the battery's percentage left.
- <https://bugs.launchpad.net/indicator-power/+bug/743823>
-
See also indicator_power_device_get_gicon().
Return value: (array zero-terminated=1) (transfer full):
@@ -416,21 +407,15 @@ indicator_power_device_get_icon_names (const IndicatorPowerDevice * device)
case UP_DEVICE_STATE_CHARGING:
suffix_str = get_device_icon_suffix (percentage);
index_str = get_device_icon_index (percentage);
- g_ptr_array_add (names, g_strdup_printf ("%s-%s-charging-symbolic", kind_str, suffix_str));
+ g_ptr_array_add (names, g_strdup_printf ("%s-%s-charging", kind_str, index_str));
g_ptr_array_add (names, g_strdup_printf ("gpm-%s-%s-charging", kind_str, index_str));
+ g_ptr_array_add (names, g_strdup_printf ("%s-%s-charging-symbolic", kind_str, suffix_str));
g_ptr_array_add (names, g_strdup_printf ("%s-%s-charging", kind_str, suffix_str));
break;
case UP_DEVICE_STATE_PENDING_CHARGE:
case UP_DEVICE_STATE_DISCHARGING:
case UP_DEVICE_STATE_PENDING_DISCHARGE:
- /* Don't show the caution/red icons unless we have <=30 min left.
- <https://bugs.launchpad.net/indicator-power/+bug/743823>
- Themes use the caution color when the percentage is 0% or 20%,
- so if we have >30 min left, use 30% as the icon's percentage floor */
- if (indicator_power_device_get_time (device) > (30*60))
- percentage = MAX(percentage, 30);
-
suffix_str = get_device_icon_suffix (percentage);
index_str = get_device_icon_index (percentage);
g_ptr_array_add (names, g_strdup_printf ("%s-%s", kind_str, index_str));
@@ -595,10 +580,12 @@ get_expanded_time_remaining (const IndicatorPowerDevice * device)
if (p->state == UP_DEVICE_STATE_CHARGING)
{
+ /* TRANSLATORS: H:MM (hours, minutes) to charge the battery. Example: "1:30 to charge" */
str = g_strdup_printf (_("%0d:%02d to charge"), hours, minutes);
}
else // discharging
{
+ /* TRANSLATORS: H:MM (hours, minutes) to discharge the battery. Example: "1:30 left"*/
str = g_strdup_printf (_("%0d:%02d left"), hours, minutes);
}
}
@@ -624,29 +611,45 @@ get_accessible_time_remaining (const IndicatorPowerDevice * device)
if (p->time && ((p->state == UP_DEVICE_STATE_CHARGING) || (p->state == UP_DEVICE_STATE_DISCHARGING)))
{
- int minutes = p->time / 60;
- const int hours = minutes / 60;
+ guint minutes = (guint)p->time / 60u;
+ const guint hours = minutes / 60u;
minutes %= 60;
if (p->state == UP_DEVICE_STATE_CHARGING)
{
if (hours > 0)
- str = g_strdup_printf (_("%d %s %d %s to charge"),
- hours, g_dngettext (NULL, "hour", "hours", hours),
- minutes, g_dngettext (NULL, "minute", "minutes", minutes));
+ {
+ /* TRANSLATORS: "X (hour,hours) Y (minute,minutes) to charge" the battery.
+ Example: "1 hour 10 minutes to charge" */
+ str = g_strdup_printf (_("%d %s %d %s to charge"),
+ hours, g_dngettext (NULL, "hour", "hours", hours),
+ minutes, g_dngettext (NULL, "minute", "minutes", minutes));
+ }
else
- str = g_strdup_printf (_("%d %s to charge"),
- minutes, g_dngettext (NULL, "minute", "minutes", minutes));
+ {
+ /* TRANSLATORS: "Y (minute,minutes) to charge" the battery.
+ Example: "59 minutes to charge" */
+ str = g_strdup_printf (_("%d %s to charge"),
+ minutes, g_dngettext (NULL, "minute", "minutes", minutes));
+ }
}
else // discharging
{
if (hours > 0)
- str = g_strdup_printf (_("%d %s %d %s left"),
- hours, g_dngettext (NULL, "hour", "hours", hours),
- minutes, g_dngettext (NULL, "minute", "minutes", minutes));
- else
- str = g_strdup_printf (_("%d %s left"),
- minutes, g_dngettext (NULL, "minute", "minutes", minutes));
+ {
+ /* TRANSLATORS: "X (hour,hours) Y (minute,minutes) left" until the battery's empty.
+ Example: "1 hour 10 minutes left" */
+ str = g_strdup_printf (_("%d %s %d %s left"),
+ hours, g_dngettext (NULL, "hour", "hours", hours),
+ minutes, g_dngettext (NULL, "minute", "minutes", minutes));
+ }
+ else
+ {
+ /* TRANSLATORS: "Y (minute,minutes) left" until the battery's empty.
+ Example: "59 minutes left" */
+ str = g_strdup_printf (_("%d %s left"),
+ minutes, g_dngettext (NULL, "minute", "minutes", minutes));
+ }
}
}
else
@@ -700,6 +703,7 @@ get_menuitem_text (const IndicatorPowerDevice * device,
if (p->state == UP_DEVICE_STATE_FULLY_CHARGED)
{
+ /* TRANSLATORS: example: "battery (charged)" */
str = g_strdup_printf (_("%s (charged)"), kind_str);
}
else
@@ -715,9 +719,14 @@ get_menuitem_text (const IndicatorPowerDevice * device,
}
if (time_str && *time_str)
- str = g_strdup_printf (_("%s (%s)"), kind_str, time_str);
+ {
+ /* TRANSLATORS: example: "battery (time remaining)" */
+ str = g_strdup_printf (_("%s (%s)"), kind_str, time_str);
+ }
else
- str = g_strdup (kind_str);
+ {
+ str = g_strdup (kind_str);
+ }
g_free (time_str);
}
@@ -783,14 +792,17 @@ indicator_power_device_get_readable_title (const IndicatorPowerDevice * device,
if (want_time && want_percent)
{
+ /* TRANSLATORS: after the icon, a time-remaining string + battery %. Example: "(0:59, 33%)" */
str = g_strdup_printf (_("(%s, %.0lf%%)"), time_str, p->percentage);
}
else if (want_time)
{
+ /* TRANSLATORS: after the icon, a time-remaining string Example: "(0:59)" */
str = g_strdup_printf (_("(%s)"), time_str);
}
else if (want_percent)
{
+ /* TRANSLATORS: after the icon, a battery %. Example: "(33%)" */
str = g_strdup_printf (_("(%.0lf%%)"), p->percentage);
}
else
@@ -861,5 +873,5 @@ indicator_power_device_new_from_variant (GVariant * v)
kind,
percentage,
state,
- time);
+ (time_t)time);
}