diff --git a/data/io.elementary.monitor.gschema.xml b/data/io.elementary.monitor.gschema.xml
index 8a174d2e0..7a269bf32 100644
--- a/data/io.elementary.monitor.gschema.xml
+++ b/data/io.elementary.monitor.gschema.xml
@@ -60,6 +60,11 @@
To show network down bandwidth in Monitor Indicator or not
To show network down bandwidth in Monitor Indicator or not
+
+ false
+ To show network bandwidth in in bits instead of bytes per second
+ To show network bandwidth in in bits instead of bytes per second
+
false
To show GPU used percentage in Monitor Indicator or not
diff --git a/src/Indicator/Services/DBusClient.vala b/src/Indicator/Services/DBusClient.vala
index 5b20140f9..50ab4424c 100644
--- a/src/Indicator/Services/DBusClient.vala
+++ b/src/Indicator/Services/DBusClient.vala
@@ -15,6 +15,7 @@ public interface Monitor.DBusClientInterface : Object {
public signal void indicator_memory_state (bool state);
public signal void indicator_network_up_state (bool state);
public signal void indicator_network_down_state (bool state);
+ public signal void network_use_bits_state (bool state);
public signal void indicator_gpu_state (bool state);
public signal void indicator_gpu_memory_state (bool state);
public signal void indicator_gpu_temperature_state (bool state);
diff --git a/src/Indicator/Widgets/DisplayWidget.vala b/src/Indicator/Widgets/DisplayWidget.vala
index 01fca412c..c104a645e 100644
--- a/src/Indicator/Widgets/DisplayWidget.vala
+++ b/src/Indicator/Widgets/DisplayWidget.vala
@@ -29,6 +29,9 @@ public class Monitor.Widgets.DisplayWidget : Gtk.Box {
memory_widget.visible = Indicator.settings.get_boolean ("indicator-memory-state");
network_up_widget.visible = Indicator.settings.get_boolean ("indicator-network-upload-state");
network_down_widget.visible = Indicator.settings.get_boolean ("indicator-network-download-state");
+ bool use_bits = Indicator.settings.get_boolean ("network-use-bits-state");
+ network_up_widget.use_bits = use_bits;
+ network_down_widget.use_bits = use_bits;
gpu_widget.visible = Indicator.settings.get_boolean ("indicator-gpu-state");
gpu_memory_widget.visible = Indicator.settings.get_boolean ("indicator-gpu-memory-state");
gpu_temperature_widget.visible = Indicator.settings.get_boolean ("indicator-gpu-temperature-state");
@@ -40,6 +43,10 @@ public class Monitor.Widgets.DisplayWidget : Gtk.Box {
dbusclient.interface.indicator_memory_state.connect ((state) => memory_widget.visible = state);
dbusclient.interface.indicator_network_up_state.connect ((state) => network_up_widget.visible = state);
dbusclient.interface.indicator_network_down_state.connect ((state) => network_down_widget.visible = state);
+ dbusclient.interface.network_use_bits_state.connect ((state) => {
+ network_up_widget.use_bits = state;
+ network_down_widget.use_bits = state;
+ });
dbusclient.interface.indicator_gpu_state.connect ((state) => gpu_widget.visible = state);
dbusclient.interface.indicator_gpu_memory_state.connect ((state) => gpu_memory_widget.visible = state);
dbusclient.interface.indicator_gpu_temperature_state.connect ((state) => gpu_temperature_widget.visible = state);
diff --git a/src/Indicator/Widgets/IndicatorWidgetBandwidth.vala b/src/Indicator/Widgets/IndicatorWidgetBandwidth.vala
index e58b3a2fe..f0b3a64e9 100644
--- a/src/Indicator/Widgets/IndicatorWidgetBandwidth.vala
+++ b/src/Indicator/Widgets/IndicatorWidgetBandwidth.vala
@@ -4,6 +4,8 @@
*/
public class Monitor.IndicatorWidgetBandwidth : Monitor.IndicatorWidget {
+ public bool use_bits = false;
+
public IndicatorWidgetBandwidth (string icon_name) {
base (icon_name);
}
@@ -11,6 +13,6 @@ public class Monitor.IndicatorWidgetBandwidth : Monitor.IndicatorWidget {
public override void update_label (Value value) {
uint64 bandwidth = value.get_uint64 ();
- label.label = format_size (bandwidth);
+ label.label = Utils.Strings.format_network_speed (bandwidth, use_bits);
}
}
diff --git a/src/Services/DBusServer.vala b/src/Services/DBusServer.vala
index ddad83862..824133f43 100644
--- a/src/Services/DBusServer.vala
+++ b/src/Services/DBusServer.vala
@@ -22,6 +22,7 @@ public class Monitor.DBusServer : Object {
public signal void indicator_memory_state (bool state);
public signal void indicator_network_up_state (bool state);
public signal void indicator_network_down_state (bool state);
+ public signal void network_use_bits_state (bool state);
public signal void indicator_gpu_state (bool state);
public signal void indicator_gpu_memory_state (bool state);
public signal void indicator_gpu_temperature_state (bool state);
diff --git a/src/Utils.vala b/src/Utils.vala
index 6a8cfe1d0..a301467a2 100644
--- a/src/Utils.vala
+++ b/src/Utils.vala
@@ -49,6 +49,21 @@ public class Monitor.Utils.Strings {
return pretty;
}
+ public static string format_network_speed (uint64 bandwidth, bool use_bits = false) {
+ const int SCALE = 1000;
+ bandwidth = bandwidth * (use_bits ? 8 : 1);
+ string unit_suffix = use_bits ? "bps" : "Bps";
+ string[] units = { "", "K", "M", "G", "T" };
+
+ int unit_index = 0;
+
+ while (bandwidth >= SCALE && unit_index < units.length - 1) {
+ bandwidth /= SCALE;
+ unit_index++;
+ }
+
+ return "%llu %s%s".printf (bandwidth, units[unit_index], unit_suffix);
+ }
}
public class Monitor.Utils.Colors : Object {
diff --git a/src/Views/PreferencesView.vala b/src/Views/PreferencesView.vala
index fcb82da1f..23e2cc516 100644
--- a/src/Views/PreferencesView.vala
+++ b/src/Views/PreferencesView.vala
@@ -89,6 +89,11 @@ public class Monitor.PreferencesView : Granite.Bin {
dbusserver.indicator_network_down_state (network_download_check.active);
});
+ var network_use_bits_check = new Gtk.CheckButton.with_label (_("Network use bits"));
+ network_use_bits_check.toggled.connect (() => {
+ dbusserver.network_use_bits_state (network_use_bits_check.active);
+ });
+
var gpu_check = new Gtk.CheckButton.with_label (_("GPU percentage"));
gpu_check.toggled.connect (() => {
dbusserver.indicator_gpu_state (gpu_check.active);
@@ -124,6 +129,7 @@ public class Monitor.PreferencesView : Granite.Bin {
indicator_options_box.append (new Gtk.Separator (HORIZONTAL));
indicator_options_box.append (network_upload_check);
indicator_options_box.append (network_download_check);
+ indicator_options_box.append (network_use_bits_check);
var indicator_options_revealer = new Gtk.Revealer () {
child = indicator_options_box
@@ -158,5 +164,6 @@ public class Monitor.PreferencesView : Granite.Bin {
settings.bind ("indicator-gpu-state", gpu_check, "active", DEFAULT);
settings.bind ("indicator-network-download-state", network_download_check, "active", DEFAULT);
settings.bind ("indicator-network-upload-state", network_upload_check, "active", DEFAULT);
+ settings.bind ("network-use-bits-state", network_use_bits_check, "active", DEFAULT);
}
}
diff --git a/src/Views/SystemView/SystemNetworkView.vala b/src/Views/SystemView/SystemNetworkView.vala
index 1a4c5ef6e..7e405849f 100644
--- a/src/Views/SystemView/SystemNetworkView.vala
+++ b/src/Views/SystemView/SystemNetworkView.vala
@@ -11,6 +11,8 @@ public class Monitor.SystemNetworkView : Gtk.Grid {
private LabelRoundy network_upload_label;
private LabelRoundy network_download_label;
+ public bool use_bits = false;
+
construct {
margin_top = 12;
margin_bottom = 12;
@@ -60,8 +62,8 @@ 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 = ("%s/s").printf (format_size ((uint64) down_bytes, IEC_UNITS));
- network_upload_label.text = ("%s/s").printf (format_size ((uint64) up_bytes, IEC_UNITS));
+ network_download_label.text = Utils.Strings.format_network_speed ((uint64) down_bytes, use_bits);
+ network_upload_label.text = Utils.Strings.format_network_speed ((uint64) up_bytes, use_bits);
network_chart.update (0, up_bytes);
network_chart.update (1, down_bytes);
}
diff --git a/src/Views/SystemView/SystemView.vala b/src/Views/SystemView/SystemView.vala
index 43906b3c1..0cedb2811 100644
--- a/src/Views/SystemView/SystemView.vala
+++ b/src/Views/SystemView/SystemView.vala
@@ -50,6 +50,13 @@ public class Monitor.SystemView : Gtk.Box {
}
append (scrolled_window);
+
+ unowned var dbusclient = DBusClient.get_default ();
+ dbusclient.interface.network_use_bits_state.connect ((state) => {
+ network_view.use_bits = state;
+ });
+ Settings settings = new Settings ("io.elementary.monitor.settings");
+ network_view.use_bits = settings.get_boolean ("network-use-bits-state");
}
public void update () {
diff --git a/src/meson.build b/src/meson.build
index 036d04339..b3dcc7120 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -48,6 +48,7 @@ source_app_files = [
# Services
'Services/DBusServer.vala',
'Services/Appearance.vala',
+ 'Indicator/Services/DBusClient.vala',
# Resources
'Resources/Resources.vala',