diff --git a/src/Indicator/Widgets/IndicatorWidget.vala b/src/Indicator/Widgets/IndicatorWidget.vala index 80301e90c..9ae6aa590 100644 --- a/src/Indicator/Widgets/IndicatorWidget.vala +++ b/src/Indicator/Widgets/IndicatorWidget.vala @@ -8,6 +8,7 @@ public class Monitor.IndicatorWidget : Gtk.Box { public string icon_name { get; construct; } protected Gtk.Label label; + protected Gtk.Label secondary_label; public IndicatorWidget (string icon_name) { Object ( @@ -28,6 +29,15 @@ public class Monitor.IndicatorWidget : Gtk.Box { width_chars = 4, }; + secondary_label = new Gtk.Label (Utils.NOT_AVAILABLE) { + margin_start = 2, + margin_end = 2, + margin_top = 2, + margin_bottom = 2, + width_chars = 4, + visible = false, + }; + append (icon); append (label); } diff --git a/src/Indicator/Widgets/IndicatorWidgetBandwidth.vala b/src/Indicator/Widgets/IndicatorWidgetBandwidth.vala index 75bdad803..211d731a4 100644 --- a/src/Indicator/Widgets/IndicatorWidgetBandwidth.vala +++ b/src/Indicator/Widgets/IndicatorWidgetBandwidth.vala @@ -8,9 +8,24 @@ public class Monitor.IndicatorWidgetBandwidth : Monitor.IndicatorWidget { base (icon_name); } + construct { + label.xalign = 0.5f; + label.margin_end = 0; + label.width_chars = 3; + label.max_width_chars = 3; + secondary_label.xalign = 1; + secondary_label.visible = true; + append (secondary_label); + } + public override void update_label (Value value) { uint64 bandwidth = value.get_uint64 (); - label.label = Utils.Strings.format_network_speed (bandwidth); + string speed_value; + string speed_unit; + Utils.Strings.format_network_speed (bandwidth, out speed_value, out speed_unit); + + label.label = speed_value; + secondary_label.label = speed_unit; } } diff --git a/src/Indicator/Widgets/IndicatorWidgetFrequency.vala b/src/Indicator/Widgets/IndicatorWidgetFrequency.vala index 5aabb5def..efacf9ef4 100644 --- a/src/Indicator/Widgets/IndicatorWidgetFrequency.vala +++ b/src/Indicator/Widgets/IndicatorWidgetFrequency.vala @@ -8,9 +8,21 @@ public class Monitor.IndicatorWidgetFrequency : Monitor.IndicatorWidget { base (icon_name); } + construct { + secondary_label.width_chars = 3; + secondary_label.margin_start = 0; + secondary_label.visible = true; + append (secondary_label); + } + public override void update_label (Value value) { double frequency = value.get_double (); - label.label = Utils.Strings.format_frequency (frequency); + string frequency_value; + string frequency_unit; + Utils.Strings.format_frequency (frequency, out frequency_value, out frequency_unit); + + label.label = frequency_value; + secondary_label.label = frequency_unit; } } diff --git a/src/Utils.vala b/src/Utils.vala index e1bb59859..9dfc19ee7 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -6,6 +6,7 @@ namespace Monitor.Utils { const int BITS_IN_BYTES = 8; const int MHZ_IN_GHZ = 1000; + const int IEC_UNIT_BASE = 1024; const string NOT_AVAILABLE = (_("N/A")); const string NO_DATA = "\u2014"; @@ -52,27 +53,39 @@ public class Monitor.Utils.Strings { return pretty; } - public static string format_frequency (double mhz) { + public static void format_frequency (double mhz, out string frequency_value, out string frequency_unit) { var frequency = mhz; if (frequency >= MHZ_IN_GHZ) { frequency /= MHZ_IN_GHZ; ///TRANSLATORS: The first param is the cpu frequency speed value and ///the second param is the cpu frequency speed unit viz. "Ghz" for gigahertz. - return _("%.2f Ghz").printf (frequency); + frequency_value = _("%.2f").printf (frequency); + frequency_unit = _("Ghz"); + return; } ///TRANSLATORS: The first param is the cpu frequency speed value and ///the second param is the cpu frequency speed unit viz. "Mhz" for megahertz. - return _("%.0f Mhz").printf (frequency); + frequency_value = _("%.0f").printf (frequency); + frequency_unit = _("Mhz"); } - public static string format_network_speed (uint64 speed_in_bytes_per_second) { - ///TRANSLATORS: The first param is the numeric value (as string) of network speed. - ///The second param with the appended "/s" is the network speed unit such as "Mb/s" for megabits per second. - return _("%s %s/s").printf ( - format_size (speed_in_bytes_per_second * BITS_IN_BYTES, BITS | IEC_UNITS | ONLY_VALUE), - format_size (speed_in_bytes_per_second * BITS_IN_BYTES, BITS | ONLY_UNIT) - ); + public static void format_network_speed (uint64 speed_in_bytes_per_second, out string speed_value, out string speed_unit) { + ///TRANSLATORS: These are the network speed unit such as "Mbps" for "megabits per second". + string[] units = {_("bps"), _("Kbps"), _("Mbps"), _("Gbps"), _("Tbps")}; + + var speed_in_bits_per_second = speed_in_bytes_per_second * BITS_IN_BYTES; + + int unit_index = 0; + while ((speed_in_bits_per_second / IEC_UNIT_BASE) > 0 && (unit_index < units.length)) { + unit_index++; + speed_in_bits_per_second /= IEC_UNIT_BASE; + } + + ///TRANSLATORS: This is the numeric value of network speed. + speed_value = _("%llu").printf (speed_in_bits_per_second); + + speed_unit = units[unit_index]; } } diff --git a/src/Views/SystemView/SystemCPUView.vala b/src/Views/SystemView/SystemCPUView.vala index a17ff781d..403da5653 100644 --- a/src/Views/SystemView/SystemCPUView.vala +++ b/src/Views/SystemView/SystemCPUView.vala @@ -116,7 +116,12 @@ public class Monitor.SystemCPUView : Monitor.WidgetResource { } main_metric_value = ("%d%%").printf (cpu.percentage); - cpu_frequency_label.text = Utils.Strings.format_frequency (cpu.frequency); + string frequency_value; + string frequency_unit; + Utils.Strings.format_frequency (cpu.frequency, out frequency_value, out frequency_unit); + ///TRANSLATORS: The first param is the cpu frequency speed value (as a string) and + ///the second param is the cpu frequency speed unit such as "Ghz" for "gigahertz" or "Mhz" for "megahertz". + cpu_frequency_label.text = _("%s %s").printf (frequency_value, frequency_unit); } private Gtk.Grid grid_core_labels () { diff --git a/src/Views/SystemView/SystemNetworkView.vala b/src/Views/SystemView/SystemNetworkView.vala index dd5d1fb7d..0f6ceeee0 100644 --- a/src/Views/SystemView/SystemNetworkView.vala +++ b/src/Views/SystemView/SystemNetworkView.vala @@ -60,8 +60,16 @@ public class Monitor.SystemNetworkView : Gtk.Grid { double up_bytes = network.bytes_out; double down_bytes = network.bytes_in; if (up_bytes >= 0 && down_bytes >= 0) { - network_download_label.text = Utils.Strings.format_network_speed ((uint64) down_bytes); - network_upload_label.text = Utils.Strings.format_network_speed ((uint64) up_bytes); + string speed_value; + string speed_unit; + Utils.Strings.format_frequency ((uint64) down_bytes, out speed_value, out speed_unit); + ///TRANSLATORS: The first param is the numeric value (as string) of network speed. + ///The second param is the network speed unit such as "Mbps" for "megabits per second". + network_download_label.text = _("%s %s").printf (speed_value, speed_unit); + Utils.Strings.format_frequency ((uint64) up_bytes, out speed_value, out speed_unit); + ///TRANSLATORS: The first param is the numeric value (as string) of network speed. + ///The second param is the network speed unit such as "Mbps" for "megabits per second". + network_upload_label.text = _("%s %s").printf (speed_value, speed_unit); network_chart.update (0, up_bytes); network_chart.update (1, down_bytes); }