Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Indicator/Widgets/IndicatorWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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);
}
Expand Down
17 changes: 16 additions & 1 deletion src/Indicator/Widgets/IndicatorWidgetBandwidth.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
14 changes: 13 additions & 1 deletion src/Indicator/Widgets/IndicatorWidgetFrequency.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
33 changes: 23 additions & 10 deletions src/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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];
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/Views/SystemView/SystemCPUView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
12 changes: 10 additions & 2 deletions src/Views/SystemView/SystemNetworkView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading