[gnome-system-monitor] Added option to select network totals unit separately
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-system-monitor] Added option to select network totals unit separately
- Date: Sun, 8 Nov 2020 00:17:14 +0000 (UTC)
commit 51dd01565958dbcce7912eeb67f09962a04f32f5
Author: Robert Roth <robert roth off gmail com>
Date: Sun Nov 8 02:17:07 2020 +0200
Added option to select network totals unit separately
data/preferences.ui | 38 ++++++++++++++++++++++
src/application.cpp | 39 +++++++++++++++++++++++
src/application.h | 6 +++-
src/org.gnome.gnome-system-monitor.gschema.xml.in | 15 +++++++++
src/prefsdialog.cpp | 19 +++++++++++
src/prefsdialog.h | 1 +
src/settings-keys.h | 2 ++
src/util.cpp | 2 +-
8 files changed, 120 insertions(+), 2 deletions(-)
---
diff --git a/data/preferences.ui b/data/preferences.ui
index 1c242811..2d2fe220 100644
--- a/data/preferences.ui
+++ b/data/preferences.ui
@@ -477,6 +477,43 @@
<property name="height">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkCheckButton" id="bits_unit_button">
+ <property name="label" translatable="yes">Set network totals _unit
separately</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="hexpand">True</property>
+ <property name="use_underline">True</property>
+ <property name="halign">start</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="on_bits_unit_button_toggled"
object="bits_total_button" swapped="no"/>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">4</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="bits_total_button">
+ <property name="label" translatable="yes">Show network _totals in
bits</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="hexpand">True</property>
+ <property name="use_underline">True</property>
+ <property name="halign">start</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">5</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="left_attach">0</property>
@@ -759,3 +796,4 @@
</child>
</object>
</interface>
+
diff --git a/src/application.cpp b/src/application.cpp
index 9af91110..fc5d7a62 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -55,6 +55,30 @@ static void
cb_network_in_bits_changed (Gio::Settings& settings, Glib::ustring key, GsmApplication* app)
{
app->config.network_in_bits = settings.get_boolean(key);
+ if (app->config.network_total_unit == FALSE) {
+ app->config.network_total_in_bits = app->config.network_in_bits;
+ }
+ // force scale to be redrawn
+ app->net_graph->clear_background();
+}
+
+static void
+cb_network_total_in_unit_changed (Gio::Settings& settings, Glib::ustring key, GsmApplication* app)
+{
+ app->config.network_total_unit = settings.get_boolean(key);
+ if (app->config.network_total_unit == FALSE) {
+ app->config.network_total_in_bits = app->config.network_in_bits;
+ } else {
+ app->config.network_total_in_bits = app->settings->get_boolean (GSM_SETTING_NETWORK_TOTAL_IN_BITS);
+ }
+ // force scale to be redrawn
+ app->net_graph->clear_background();
+}
+
+static void
+cb_network_total_in_bits_changed (Gio::Settings& settings, Glib::ustring key, GsmApplication* app)
+{
+ app->config.network_total_in_bits = settings.get_boolean(key);
// force scale to be redrawn
app->net_graph->clear_background();
}
@@ -190,6 +214,21 @@ GsmApplication::load_settings()
cb_network_in_bits_changed (*this->settings.operator->(), key, this);
});
+ config.network_total_unit = this->settings->get_boolean (GSM_SETTING_NETWORK_TOTAL_UNIT);
+ this->settings->signal_changed (GSM_SETTING_NETWORK_TOTAL_UNIT).connect ([this](const Glib::ustring&
key) {
+ cb_network_total_in_unit_changed (*this->settings.operator->(), key, this);
+ });
+
+ if (config.network_total_unit == FALSE) {
+ config.network_total_in_bits = config.network_in_bits;
+ this->settings->set_boolean (GSM_SETTING_NETWORK_TOTAL_IN_BITS, config.network_in_bits);
+ } else {
+ config.network_total_in_bits = this->settings->get_boolean (GSM_SETTING_NETWORK_TOTAL_IN_BITS);
+ }
+ this->settings->signal_changed (GSM_SETTING_NETWORK_TOTAL_IN_BITS).connect ([this](const Glib::ustring&
key) {
+ cb_network_total_in_bits_changed (*this->settings.operator->(), key, this);
+ });
+
auto cbtc = [this](const Glib::ustring& key) { cb_timeouts_changed(*this->settings.operator->(), key,
this); };
config.update_interval = this->settings->get_int (GSM_SETTING_PROCESS_UPDATE_INTERVAL);
this->settings->signal_changed (GSM_SETTING_PROCESS_UPDATE_INTERVAL).connect (cbtc);
diff --git a/src/application.h b/src/application.h
index dbaf8d29..d43cb9d9 100644
--- a/src/application.h
+++ b/src/application.h
@@ -44,7 +44,9 @@ struct ProcConfig
solaris_mode(false),
draw_stacked(false),
draw_smooth(true),
- network_in_bits(false)
+ network_in_bits(false),
+ network_total_unit(false),
+ network_total_in_bits(false)
{
std::fill(&this->cpu_color[0], &this->cpu_color[GLIBTOP_NCPU], GdkRGBA());
}
@@ -65,6 +67,8 @@ struct ProcConfig
bool draw_stacked;
bool draw_smooth;
bool network_in_bits;
+ bool network_total_unit;
+ bool network_total_in_bits;
};
diff --git a/src/org.gnome.gnome-system-monitor.gschema.xml.in
b/src/org.gnome.gnome-system-monitor.gschema.xml.in
index e66a91f7..83a45157 100644
--- a/src/org.gnome.gnome-system-monitor.gschema.xml.in
+++ b/src/org.gnome.gnome-system-monitor.gschema.xml.in
@@ -156,6 +156,20 @@
</summary>
</key>
+ <key name="network-total-unit" type="b">
+ <default>false
+ </default>
+ <summary>Set network totals unit separately
+ </summary>
+ </key>
+
+ <key name="network-total-in-bits" type="b">
+ <default>false
+ </default>
+ <summary>Show network totals in bits
+ </summary>
+ </key>
+
<key name="cpu-stacked-area-chart" type="b">
<default>false
</default>
@@ -737,3 +751,4 @@
</key>
</schema>
</schemalist>
+
diff --git a/src/prefsdialog.cpp b/src/prefsdialog.cpp
index d433265b..961e9c37 100644
--- a/src/prefsdialog.cpp
+++ b/src/prefsdialog.cpp
@@ -309,6 +309,20 @@ create_preferences_dialog (GsmApplication *app)
bits_button, "active",
G_SETTINGS_BIND_DEFAULT);
+ GtkCheckButton *bits_unit_button = GTK_CHECK_BUTTON (gtk_builder_get_object (builder,
"bits_unit_button"));
+ g_settings_bind(app->settings->gobj (), GSM_SETTING_NETWORK_TOTAL_UNIT,
+ bits_unit_button, "active",
+ G_SETTINGS_BIND_DEFAULT);
+ gtk_builder_add_callback_symbol (builder, "on_bits_unit_button_toggled",
+ G_CALLBACK (on_bits_unit_button_toggled));
+
+ GtkCheckButton *bits_total_button = GTK_CHECK_BUTTON (gtk_builder_get_object (builder,
"bits_total_button"));
+ g_settings_bind(app->settings->gobj (), GSM_SETTING_NETWORK_TOTAL_IN_BITS,
+ bits_total_button, "active",
+ G_SETTINGS_BIND_DEFAULT);
+
+ gtk_widget_set_sensitive((GtkWidget *)bits_total_button, gtk_toggle_button_get_active ((GtkToggleButton
*)bits_unit_button));
+
update = (gfloat) app->config.disks_update_interval;
spin_button = GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "devices_interval_spinner"));
adjustment = gtk_spin_button_get_adjustment (spin_button);
@@ -344,3 +358,8 @@ create_preferences_dialog (GsmApplication *app)
g_object_unref (G_OBJECT (builder));
}
+void
+on_bits_unit_button_toggled (GtkToggleButton *togglebutton, gpointer bits_total_button)
+{
+ gtk_widget_set_sensitive((GtkWidget *)bits_total_button, gtk_toggle_button_get_active ((GtkToggleButton
*)togglebutton));
+}
diff --git a/src/prefsdialog.h b/src/prefsdialog.h
index 5e3f8336..63c966ce 100644
--- a/src/prefsdialog.h
+++ b/src/prefsdialog.h
@@ -5,5 +5,6 @@
#include "application.h"
void create_preferences_dialog (GsmApplication *app);
+void on_bits_unit_button_toggled (GtkToggleButton *togglebutton, gpointer bits_total_button);
#endif /* _GSM_PREFS_DIALOG_H_ */
diff --git a/src/settings-keys.h b/src/settings-keys.h
index e5cbd8c7..9eea4103 100644
--- a/src/settings-keys.h
+++ b/src/settings-keys.h
@@ -30,6 +30,8 @@
#define GSM_SETTING_DRAW_SMOOTH "cpu-smooth-graph"
#define GSM_SETTING_NETWORK_IN_BITS "network-in-bits"
#define GSM_SETTING_GRAPH_DATA_POINTS "graph-data-points"
+#define GSM_SETTING_NETWORK_TOTAL_UNIT "network-total-unit"
+#define GSM_SETTING_NETWORK_TOTAL_IN_BITS "network-total-in-bits"
#define GSM_SETTING_SHOW_CPU "show-cpu"
#define GSM_SETTING_SHOW_MEM "show-mem"
#define GSM_SETTING_SHOW_NETWORK "show-network"
diff --git a/src/util.cpp b/src/util.cpp
index f0c89cff..f0b97f1d 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -711,7 +711,7 @@ namespace procman
std::string format_network(guint64 rate)
{
- char* bytes = procman::format_size(rate, GsmApplication::get()->config.network_in_bits);
+ char* bytes = procman::format_size(rate, GsmApplication::get()->config.network_total_in_bits);
std::string formatted(bytes);
g_free(bytes);
return formatted;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]