[gnome-system-monitor] Select memory format in preferences.
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-system-monitor] Select memory format in preferences.
- Date: Tue, 5 Jan 2021 11:44:48 +0000 (UTC)
commit 73417d0ef373d765fcc5ba715ecf4fdc964fdbfb
Author: Paweł Chałkowski <chauek gmail com>
Date: Tue Jan 5 11:44:47 2021 +0000
Select memory format in preferences.
data/preferences.ui | 38 +++++++++++++++++++++--
src/application.cpp | 30 ++++++++++++++++++
src/application.h | 4 +++
src/load-graph.cpp | 10 +++---
src/org.gnome.gnome-system-monitor.gschema.xml.in | 13 ++++++++
src/prefsdialog.cpp | 10 ++++++
src/settings-keys.h | 2 ++
src/util.cpp | 9 +++++-
src/util.h | 3 ++
9 files changed, 110 insertions(+), 9 deletions(-)
---
diff --git a/data/preferences.ui b/data/preferences.ui
index c1c4e12e..64f90e8b 100644
--- a/data/preferences.ui
+++ b/data/preferences.ui
@@ -168,6 +168,22 @@
<property name="height">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkCheckButton" id="proc_mem_in_iec_button">
+ <property name="label" translatable="yes">Show memory in IEC</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="halign">start</property>
+ <property name="hexpand">True</property>
+ <property name="use_underline">True</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">4</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="left_attach">0</property>
@@ -459,6 +475,22 @@
<property name="height">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkCheckButton" id="res_mem_in_iec_button">
+ <property name="label" translatable="yes">Show memory and swap in
IEC</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="halign">start</property>
+ <property name="hexpand">True</property>
+ <property name="use_underline">True</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">4</property>
+ </packing>
+ </child>
<child>
<object class="GtkCheckButton" id="bits_button">
<property name="label" translatable="yes">_Show network speed in
bits</property>
@@ -472,7 +504,7 @@
</object>
<packing>
<property name="left_attach">0</property>
- <property name="top_attach">4</property>
+ <property name="top_attach">5</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
@@ -491,7 +523,7 @@
</object>
<packing>
<property name="left_attach">0</property>
- <property name="top_attach">5</property>
+ <property name="top_attach">6</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
@@ -509,7 +541,7 @@
</object>
<packing>
<property name="left_attach">0</property>
- <property name="top_attach">6</property>
+ <property name="top_attach">7</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
diff --git a/src/application.cpp b/src/application.cpp
index fc5d7a62..247f7a64 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -31,6 +31,16 @@ cb_solaris_mode_changed (Gio::Settings& settings, Glib::ustring key, GsmApplicat
}
}
+static void
+cb_process_memory_in_iec_changed (Gio::Settings& settings, Glib::ustring key, GsmApplication* app)
+{
+ app->config.process_memory_in_iec = settings.get_boolean(key);
+ app->cpu_graph->clear_background();
+ if (app->timeout) {
+ proctable_update (app);
+ }
+}
+
static void
cb_draw_stacked_changed (Gio::Settings& settings, Glib::ustring key, GsmApplication* app)
{
@@ -51,6 +61,16 @@ cb_draw_smooth_changed (Gio::Settings& settings, Glib::ustring key, GsmApplicati
load_graph_reset(app->net_graph);
}
+static void
+cb_resources_memory_in_iec_changed (Gio::Settings& settings, Glib::ustring key, GsmApplication* app)
+{
+ app->config.resources_memory_in_iec = settings.get_boolean(key);
+ app->cpu_graph->clear_background();
+ if (app->timeout) {
+ proctable_update (app);
+ }
+}
+
static void
cb_network_in_bits_changed (Gio::Settings& settings, Glib::ustring key, GsmApplication* app)
{
@@ -199,6 +219,11 @@ GsmApplication::load_settings()
cb_solaris_mode_changed (*this->settings.operator->(), key, this);
});
+ config.process_memory_in_iec = this->settings->get_boolean (GSM_SETTING_PROCESS_MEMORY_IN_IEC);
+ this->settings->signal_changed (GSM_SETTING_PROCESS_MEMORY_IN_IEC).connect ([this](const Glib::ustring&
key) {
+ cb_process_memory_in_iec_changed (*this->settings.operator->(), key, this);
+ });
+
config.draw_stacked = this->settings->get_boolean (GSM_SETTING_DRAW_STACKED);
this->settings->signal_changed(GSM_SETTING_DRAW_STACKED).connect ([this](const Glib::ustring& key) {
cb_draw_stacked_changed (*this->settings.operator->(), key, this);
@@ -209,6 +234,11 @@ GsmApplication::load_settings()
cb_draw_smooth_changed (*this->settings.operator->(), key, this);
});
+ config.resources_memory_in_iec = this->settings->get_boolean (GSM_SETTING_RESOURCES_MEMORY_IN_IEC);
+ this->settings->signal_changed (GSM_SETTING_RESOURCES_MEMORY_IN_IEC).connect ([this](const
Glib::ustring& key) {
+ cb_resources_memory_in_iec_changed (*this->settings.operator->(), key, this);
+ });
+
config.network_in_bits = this->settings->get_boolean (GSM_SETTING_NETWORK_IN_BITS);
this->settings->signal_changed (GSM_SETTING_NETWORK_IN_BITS).connect ([this](const Glib::ustring& key) {
cb_network_in_bits_changed (*this->settings.operator->(), key, this);
diff --git a/src/application.h b/src/application.h
index d43cb9d9..9569a060 100644
--- a/src/application.h
+++ b/src/application.h
@@ -42,8 +42,10 @@ struct ProcConfig
frame_color(),
num_cpus(0),
solaris_mode(false),
+ process_memory_in_iec(true),
draw_stacked(false),
draw_smooth(true),
+ resources_memory_in_iec(true),
network_in_bits(false),
network_total_unit(false),
network_total_in_bits(false)
@@ -64,8 +66,10 @@ struct ProcConfig
GdkRGBA frame_color;
gint num_cpus;
bool solaris_mode;
+ bool process_memory_in_iec;
bool draw_stacked;
bool draw_smooth;
+ bool resources_memory_in_iec;
bool network_in_bits;
bool network_total_unit;
bool network_total_in_bits;
diff --git a/src/load-graph.cpp b/src/load-graph.cpp
index 3bf1c883..a1c6771d 100644
--- a/src/load-graph.cpp
+++ b/src/load-graph.cpp
@@ -477,17 +477,17 @@ namespace
char* total_text;
char* text;
- used_text = g_format_size_full(used, G_FORMAT_SIZE_IEC_UNITS);
- cached_text = g_format_size_full(cached, G_FORMAT_SIZE_IEC_UNITS);
- total_text = g_format_size_full(total, G_FORMAT_SIZE_IEC_UNITS);
+ used_text = format_byte_size(used, GsmApplication::get()->config.resources_memory_in_iec);
+ cached_text = format_byte_size(cached, GsmApplication::get()->config.resources_memory_in_iec);
+ total_text = format_byte_size(total, GsmApplication::get()->config.resources_memory_in_iec);
if (total == 0) {
text = g_strdup(_("not available"));
} else {
- // xgettext: 540MiB (53 %) of 1.0 GiB
+ // xgettext: "540MiB (53 %) of 1.0 GiB" or "540MB (53 %) of 1.0 GB"
text = g_strdup_printf(_("%s (%.1f%%) of %s"), used_text, 100.0 * percent, total_text);
if (cached != 0) {
- // xgettext: Used cache string, e.g.: "Cache 2.4GiB"
+ // xgettext: Used cache string, e.g.: "Cache 2.4GiB" or "Cache 2.4GB"
cached_label = g_strdup_printf(_("Cache %s"), cached_text);
text = g_strdup_printf("%s\n%s", text, cached_label);
g_free (cached_label);
diff --git a/src/org.gnome.gnome-system-monitor.gschema.xml.in
b/src/org.gnome.gnome-system-monitor.gschema.xml.in
index 83a45157..1630026a 100644
--- a/src/org.gnome.gnome-system-monitor.gschema.xml.in
+++ b/src/org.gnome.gnome-system-monitor.gschema.xml.in
@@ -28,6 +28,13 @@
</description>
</key>
+ <key name="process-memory-in-iec" type="b">
+ <default>false
+ </default>
+ <summary>Show memory in IEC
+ </summary>
+ </key>
+
<key name="smooth-refresh" type="b">
<default>true
</default>
@@ -188,6 +195,12 @@
</description>
</key>
+ <key name="resources-memory-in-iec" type="b">
+ <default>false
+ </default>
+ <summary>Show memory and swap in IEC
+ </summary>
+ </key>
<child name="proctree" schema="org.gnome.gnome-system-monitor.proctree" />
<child name="disktreenew" schema="org.gnome.gnome-system-monitor.disktreenew" />
diff --git a/src/prefsdialog.cpp b/src/prefsdialog.cpp
index 961e9c37..95cf86fb 100644
--- a/src/prefsdialog.cpp
+++ b/src/prefsdialog.cpp
@@ -274,6 +274,11 @@ create_preferences_dialog (GsmApplication *app)
solaris_button, "active",
G_SETTINGS_BIND_DEFAULT);
+ GtkCheckButton *proc_mem_in_iec_button = GTK_CHECK_BUTTON (gtk_builder_get_object (builder,
"proc_mem_in_iec_button"));
+ g_settings_bind(app->settings->gobj (), GSM_SETTING_PROCESS_MEMORY_IN_IEC,
+ proc_mem_in_iec_button, "active",
+ G_SETTINGS_BIND_DEFAULT);
+
GtkCheckButton *draw_stacked_button = GTK_CHECK_BUTTON (gtk_builder_get_object (builder,
"draw_stacked_button"));
g_settings_bind (app->settings->gobj (), GSM_SETTING_DRAW_STACKED,
draw_stacked_button, "active",
@@ -284,6 +289,11 @@ create_preferences_dialog (GsmApplication *app)
draw_smooth_button, "active",
G_SETTINGS_BIND_DEFAULT);
+ GtkCheckButton *res_mem_in_iec_button = GTK_CHECK_BUTTON (gtk_builder_get_object (builder,
"res_mem_in_iec_button"));
+ g_settings_bind(app->settings->gobj (), GSM_SETTING_RESOURCES_MEMORY_IN_IEC,
+ res_mem_in_iec_button, "active",
+ G_SETTINGS_BIND_DEFAULT);
+
create_field_page (builder, GTK_TREE_VIEW (app->tree), "proctree");
update = (gfloat) app->config.graph_update_interval;
diff --git a/src/settings-keys.h b/src/settings-keys.h
index 9eea4103..d6111c27 100644
--- a/src/settings-keys.h
+++ b/src/settings-keys.h
@@ -20,6 +20,7 @@
#define GSM_SETTING_SHOW_DEPENDENCIES "show-dependencies"
#define GSM_SETTING_SHOW_KILL_DIALOG "kill-dialog"
#define GSM_SETTING_SOLARIS_MODE "solaris-mode"
+#define GSM_SETTING_PROCESS_MEMORY_IN_IEC "process-memory-in-iec"
#define GSM_SETTING_GRAPH_UPDATE_INTERVAL "graph-update-interval"
#define GSM_SETTING_CPU_COLORS "cpu-colors"
#define GSM_SETTING_MEM_COLOR "mem-color"
@@ -28,6 +29,7 @@
#define GSM_SETTING_NET_OUT_COLOR "net-out-color"
#define GSM_SETTING_DRAW_STACKED "cpu-stacked-area-chart"
#define GSM_SETTING_DRAW_SMOOTH "cpu-smooth-graph"
+#define GSM_SETTING_RESOURCES_MEMORY_IN_IEC "resources-memory-in-iec"
#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"
diff --git a/src/util.cpp b/src/util.cpp
index f0b97f1d..59cb7b3e 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -192,6 +192,13 @@ procman::get_nice_level_with_priority (gint nice)
return _("Very Low Priority");
}
+gchar*
+format_byte_size(guint64 size, bool want_iec_format)
+{
+ const GFormatSizeFlags flags = (want_iec_format ? G_FORMAT_SIZE_IEC_UNITS : G_FORMAT_SIZE_DEFAULT);
+ return g_format_size_full(size, flags);
+}
+
gboolean
load_symbols(const char *module, ...)
{
@@ -466,7 +473,7 @@ namespace procman
NULL);
}
else {
- char *str = g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS);
+ char *str = format_byte_size(size, GsmApplication::get()->config.process_memory_in_iec);
g_object_set (renderer,
"text", str,
"style", PANGO_STYLE_NORMAL,
diff --git a/src/util.h b/src/util.h
index 3db739eb..750fa384 100644
--- a/src/util.h
+++ b/src/util.h
@@ -19,6 +19,9 @@ load_symbols(const char *module, ...) G_GNUC_NULL_TERMINATED;
const char*
format_process_state(guint state);
+gchar*
+format_byte_size(guint64 size, bool want_iec_format);
+
void
procman_debug_real(const char *file, int line, const char *func,
const char *format, ...) G_GNUC_PRINTF(4, 5);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]