From 88e553e3b557b5a4f92199aeddf8b0e5bb7868a8 Mon Sep 17 00:00:00 2001 From: rbuj Date: Tue, 21 Jul 2020 13:33:09 +0200 Subject: multiload: set and check the ranges for all network thresholds --- multiload/global.h | 6 ++++++ multiload/main.c | 6 +++--- multiload/org.mate.panel.applet.multiload.gschema.xml.in | 3 +++ multiload/properties.c | 6 +++--- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/multiload/global.h b/multiload/global.h index ea8b6330..9074e2fc 100644 --- a/multiload/global.h +++ b/multiload/global.h @@ -12,6 +12,12 @@ G_BEGIN_DECLS #define NCPUSTATES 5 #define NGRAPHS 6 +#define MIN_NET_THRESHOLD1 10 +#define MIN_NET_THRESHOLD2 11 +#define MIN_NET_THRESHOLD3 12 +#define MAX_NET_THRESHOLD1 999999998 +#define MAX_NET_THRESHOLD2 999999999 +#define MAX_NET_THRESHOLD3 1000000000 typedef struct _MultiloadApplet MultiloadApplet; typedef struct _LoadGraph LoadGraph; diff --git a/multiload/main.c b/multiload/main.c index db7ef3cc..45756891 100644 --- a/multiload/main.c +++ b/multiload/main.c @@ -378,9 +378,9 @@ multiload_create_graphs(MultiloadApplet *ma) speed = g_settings_get_int (ma->settings, "speed"); size = g_settings_get_int (ma->settings, "size"); - net_threshold1 = g_settings_get_uint (ma->settings, "netthreshold1"); - net_threshold2 = g_settings_get_uint (ma->settings, "netthreshold2"); - net_threshold3 = g_settings_get_uint (ma->settings, "netthreshold3"); + net_threshold1 = CLAMP (g_settings_get_uint (ma->settings, "netthreshold1"), MIN_NET_THRESHOLD1, MAX_NET_THRESHOLD1); + net_threshold2 = CLAMP (g_settings_get_uint (ma->settings, "netthreshold2"), MIN_NET_THRESHOLD2, MAX_NET_THRESHOLD2); + net_threshold3 = CLAMP (g_settings_get_uint (ma->settings, "netthreshold3"), MIN_NET_THRESHOLD3, MAX_NET_THRESHOLD3); if (net_threshold1 >= net_threshold2) { net_threshold1 = net_threshold2 - 1; diff --git a/multiload/org.mate.panel.applet.multiload.gschema.xml.in b/multiload/org.mate.panel.applet.multiload.gschema.xml.in index 53bf8c76..9f199bc3 100644 --- a/multiload/org.mate.panel.applet.multiload.gschema.xml.in +++ b/multiload/org.mate.panel.applet.multiload.gschema.xml.in @@ -98,14 +98,17 @@ Indicator color + 1000000 Network threshold 1 in bytes + 10000000 Network threshold 2 in bytes + 100000000 Network threshold 3 in bytes diff --git a/multiload/properties.c b/multiload/properties.c index 8849943c..d8299cde 100644 --- a/multiload/properties.c +++ b/multiload/properties.c @@ -723,7 +723,7 @@ fill_properties(GtkWidget *dialog, MultiloadApplet *ma) spin_size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); - spin_button = gtk_spin_button_new_with_range(10, 1000000000, 5); + spin_button = gtk_spin_button_new_with_range (MIN_NET_THRESHOLD1, MAX_NET_THRESHOLD1, 5); gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button); g_object_set_data(G_OBJECT(spin_button), "MultiloadApplet", ma); g_object_set_data(G_OBJECT(spin_button), "prop_type", @@ -759,7 +759,7 @@ fill_properties(GtkWidget *dialog, MultiloadApplet *ma) gtk_box_pack_start (GTK_BOX (control_hbox), hbox, TRUE, TRUE, 0); gtk_widget_show (hbox); - spin_button = gtk_spin_button_new_with_range(10, 1000000000, 5); + spin_button = gtk_spin_button_new_with_range (MIN_NET_THRESHOLD2, MAX_NET_THRESHOLD2, 5); gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button); g_object_set_data(G_OBJECT(spin_button), "MultiloadApplet", ma); g_object_set_data(G_OBJECT(spin_button), "prop_type", @@ -794,7 +794,7 @@ fill_properties(GtkWidget *dialog, MultiloadApplet *ma) gtk_box_pack_start (GTK_BOX (control_hbox), hbox, TRUE, TRUE, 0); gtk_widget_show (hbox); - spin_button = gtk_spin_button_new_with_range(10, 1000000000, 5); + spin_button = gtk_spin_button_new_with_range (MIN_NET_THRESHOLD3, MAX_NET_THRESHOLD3, 5); gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button); g_object_set_data(G_OBJECT(spin_button), "MultiloadApplet", ma); g_object_set_data(G_OBJECT(spin_button), "prop_type", -- cgit v1.2.1