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
5 changes: 5 additions & 0 deletions data/io.elementary.monitor.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
<summary>To show network down bandwidth in Monitor Indicator or not</summary>
<description>To show network down bandwidth in Monitor Indicator or not</description>
</key>
<key type='b' name="network-use-bits-state">
<default>false</default>
<summary>To show network bandwidth in in bits instead of bytes per second</summary>
<description>To show network bandwidth in in bits instead of bytes per second</description>
</key>
<key type='b' name="indicator-gpu-state">
<default>false</default>
<summary>To show GPU used percentage in Monitor Indicator or not</summary>
Expand Down
1 change: 1 addition & 0 deletions src/Indicator/Services/DBusClient.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions src/Indicator/Widgets/DisplayWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/Indicator/Widgets/IndicatorWidgetBandwidth.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
*/

public class Monitor.IndicatorWidgetBandwidth : Monitor.IndicatorWidget {
public bool use_bits = false;

public IndicatorWidgetBandwidth (string icon_name) {
base (icon_name);
}

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);
}
}
1 change: 1 addition & 0 deletions src/Services/DBusServer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions src/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions src/Views/PreferencesView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
6 changes: 4 additions & 2 deletions src/Views/SystemView/SystemNetworkView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
7 changes: 7 additions & 0 deletions src/Views/SystemView/SystemView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ source_app_files = [
# Services
'Services/DBusServer.vala',
'Services/Appearance.vala',
'Indicator/Services/DBusClient.vala',

# Resources
'Resources/Resources.vala',
Expand Down
Loading