565
indicator_power_device_get_time_details (const IndicatorPowerDevice * device,
566
gchar ** short_details,
568
gchar ** accessible_name)
566
join_strings (const char * name, const char * time, const char * percent)
569
const gboolean have_name = name && *name;
570
const gboolean have_time = time && *time;
571
const gboolean have_percent = percent && *percent;
573
if (have_name && have_time && have_percent)
574
str = g_strdup_printf (_("%s (%s, %s)"), name, time, percent);
575
else if (have_name && have_time)
576
str = g_strdup_printf (_("%s (%s)"), name, time);
577
else if (have_name && have_percent)
578
str = g_strdup_printf (_("%s (%s)"), name, percent);
580
str = g_strdup (name);
581
else if (have_time && have_percent)
582
str = g_strdup_printf (_("(%s, %s)"), time, percent);
584
str = g_strdup_printf (_("(%s)"), time);
585
else if (have_percent)
586
str = g_strdup_printf (_("(%s)"), percent);
594
indicator_power_device_get_text (const IndicatorPowerDevice * device,
595
gboolean show_time_in_header,
596
gboolean show_percentage_in_header,
570
601
if (!INDICATOR_IS_POWER_DEVICE(device))
572
*short_details = NULL;
574
*accessible_name = NULL;
603
if (a11y != NULL) *a11y = NULL;
604
if (label != NULL) *label = NULL;
605
if (header != NULL) *header = NULL;
575
606
g_warning ("%s: %p is not an IndicatorPowerDevice", G_STRFUNC, device);
579
610
const time_t time = indicator_power_device_get_time (device);
580
611
const UpDeviceState state = indicator_power_device_get_state (device);
612
const UpDeviceKind kind = indicator_power_device_get_kind (device);
613
const gchar * device_name = device_kind_to_localised_string (kind);
581
614
const gdouble percentage = indicator_power_device_get_percentage (device);
582
const UpDeviceKind kind = indicator_power_device_get_kind (device);
583
const gchar * device_name = device_kind_to_localised_string (kind);
615
char pctstr[32] = { '\0' };
616
g_snprintf (pctstr, sizeof(pctstr), "%.0lf%%", percentage);
618
GString * terse_time = g_string_new (NULL);
619
GString * verbose_time = g_string_new (NULL);
620
GString * accessible_time = g_string_new (NULL);
587
gchar *short_timestring = NULL;
588
gchar *detailed_timestring = NULL;
590
get_timestring (time,
592
&detailed_timestring);
624
char * readable_timestr = NULL;
625
char * accessible_timestr = NULL;
626
get_timestring (time, &readable_timestr, &accessible_timestr);
594
628
if (state == UP_DEVICE_STATE_CHARGING)
596
/* TRANSLATORS: %2 is a time string, e.g. "1 hour 5 minutes" */
597
*accessible_name = g_strdup_printf (_("%s (%s to charge (%.0lf%%))"), device_name, detailed_timestring, percentage);
598
*details = g_strdup_printf (_("%s (%s to charge)"), device_name, short_timestring);
599
*short_details = g_strdup_printf ("(%s)", short_timestring);
630
g_string_assign (terse_time, readable_timestr);
631
g_string_printf (verbose_time, _("%s to charge"), readable_timestr);
632
g_string_printf (accessible_time, _("%s to charge"), accessible_timestr);
601
else if ((state == UP_DEVICE_STATE_DISCHARGING) && (time > (60*60*12)))
634
else if ((state == UP_DEVICE_STATE_DISCHARGING) && (time <= (60*60*12)))
603
*accessible_name = g_strdup_printf (_("%s"), device_name);
604
*details = g_strdup_printf (_("%s"), device_name);
605
*short_details = g_strdup (short_timestring);
636
g_string_assign (terse_time, readable_timestr);
637
g_string_printf (verbose_time, _("%s left"), readable_timestr);
638
g_string_printf (accessible_time, _("%s left"), accessible_timestr);
609
/* TRANSLATORS: %2 is a time string, e.g. "1 hour 5 minutes" */
610
*accessible_name = g_strdup_printf (_("%s (%s left (%.0lf%%))"), device_name, detailed_timestring, percentage);
611
*details = g_strdup_printf (_("%s (%s left)"), device_name, short_timestring);
612
*short_details = g_strdup (short_timestring);
642
/* if there's more than 12 hours remaining, we don't show it */
615
g_free (short_timestring);
616
g_free (detailed_timestring);
645
g_free (readable_timestr);
646
g_free (accessible_timestr);
618
648
else if (state == UP_DEVICE_STATE_FULLY_CHARGED)
620
*details = g_strdup_printf (_("%s (charged)"), device_name);
621
*accessible_name = g_strdup (*details);
622
*short_details = g_strdup ("");
650
g_string_assign (verbose_time, _("charged"));
651
g_string_assign (accessible_time, _("charged"));
624
653
else if (percentage > 0)
626
/* TRANSLATORS: %2 is a percentage value. Note: this string is only
627
* used when we don't have a time value */
628
*details = g_strdup_printf (_("%s (%.0lf%%)"), device_name, percentage);
629
*accessible_name = g_strdup (*details);
630
*short_details = g_strdup_printf (_("(%.0lf%%)"), percentage);
632
else if (kind == UP_DEVICE_KIND_LINE_POWER)
634
*details = g_strdup (device_name);
635
*accessible_name = g_strdup (device_name);
636
*short_details = g_strdup ("");
655
g_string_assign (terse_time, _("estimating…"));
656
g_string_assign (verbose_time, _("estimating…"));
657
g_string_assign (accessible_time, _("estimating…"));
640
*details = g_strdup_printf (_("%s (not present)"), device_name);
641
*accessible_name = g_strdup (*details);
642
*short_details = g_strdup (_("(not present)"));
663
if (kind != UP_DEVICE_KIND_LINE_POWER)
665
g_string_assign (verbose_time, _("not present"));
666
g_string_assign (accessible_time, _("not present"));
671
*header = join_strings (NULL,
672
show_time_in_header ? terse_time->str : "",
673
show_percentage_in_header ? pctstr : "");
676
*label = join_strings (device_name,
681
*a11y = join_strings (device_name,
682
accessible_time->str,
685
g_string_free (terse_time, TRUE);
686
g_string_free (verbose_time, TRUE);
687
g_string_free (accessible_time, TRUE);
691
indicator_power_device_get_label (const IndicatorPowerDevice * device)
693
gchar * label = NULL;
694
indicator_power_device_get_text (device, FALSE, FALSE,
700
indicator_power_device_get_header (const IndicatorPowerDevice * device,
702
gboolean show_percentage,
706
indicator_power_device_get_text (device, show_time, show_percentage,