summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrbuj <[email protected]>2020-12-10 15:42:44 +0100
committerVictor Kareh <[email protected]>2020-12-17 07:29:54 -0500
commit858a664996894c3e74586db06afa8f8d1ba0121a (patch)
tree872d62da411f4b4b46abe1f4d1eb585dd870c55b
parentb3ef7cce4a6390eec5058d2308070fbe072ad8f4 (diff)
downloadmate-applets-858a664996894c3e74586db06afa8f8d1ba0121a.tar.bz2
mate-applets-858a664996894c3e74586db06afa8f8d1ba0121a.tar.xz
multiload: Use one callback for each of the spin buttons
-rw-r--r--multiload/data/org.mate.panel.applet.multiload.gschema.xml.in3
-rw-r--r--multiload/src/global.h7
-rw-r--r--multiload/src/load-graph.c7
-rw-r--r--multiload/src/main.c10
-rw-r--r--multiload/src/properties.c216
5 files changed, 114 insertions, 129 deletions
diff --git a/multiload/data/org.mate.panel.applet.multiload.gschema.xml.in b/multiload/data/org.mate.panel.applet.multiload.gschema.xml.in
index 01e6658d..0fed6921 100644
--- a/multiload/data/org.mate.panel.applet.multiload.gschema.xml.in
+++ b/multiload/data/org.mate.panel.applet.multiload.gschema.xml.in
@@ -29,7 +29,8 @@
<default>500</default>
<summary>Applet refresh rate in milliseconds</summary>
</key>
- <key name="size" type="i">
+ <key name="size" type="u">
+ <range min="10" max="1000"/>
<default>40</default>
<summary>Graph size</summary>
<description>For horizontal panels, the width of the graphs in pixels. For vertical panels, this is the height of the graphs.</description>
diff --git a/multiload/src/global.h b/multiload/src/global.h
index 558bcf67..29771369 100644
--- a/multiload/src/global.h
+++ b/multiload/src/global.h
@@ -10,6 +10,9 @@
G_BEGIN_DECLS
+#define KEY_NET_THRESHOLD1 "netthreshold1"
+#define KEY_NET_THRESHOLD2 "netthreshold2"
+#define KEY_NET_THRESHOLD3 "netthreshold3"
#define MIN_NET_THRESHOLD1 10
#define MIN_NET_THRESHOLD2 11
#define MIN_NET_THRESHOLD3 12
@@ -28,6 +31,10 @@ G_BEGIN_DECLS
#define REFRESH_RATE_MIN 50
#define REFRESH_RATE_MAX 60000
+#define GRAPH_SIZE_KEY "size"
+#define GRAPH_SIZE_MIN 10
+#define GRAPH_SIZE_MAX 1000
+
typedef struct _MultiloadApplet MultiloadApplet;
typedef struct _LoadGraph LoadGraph;
typedef void (*LoadGraphDataFunc) (int, int [], LoadGraph *);
diff --git a/multiload/src/load-graph.c b/multiload/src/load-graph.c
index 3d00eba1..d613ed59 100644
--- a/multiload/src/load-graph.c
+++ b/multiload/src/load-graph.c
@@ -265,8 +265,9 @@ load_graph_unalloc (LoadGraph *g)
g->pos = NULL;
g->data = NULL;
- g->size = g_settings_get_int(g->multiload->settings, "size");
- g->size = MAX (g->size, 10);
+ g->size = CLAMP (g_settings_get_uint (g->multiload->settings, GRAPH_SIZE_KEY),
+ GRAPH_SIZE_MIN,
+ GRAPH_SIZE_MAX);
if (g->surface) {
cairo_surface_destroy (g->surface);
@@ -412,7 +413,7 @@ load_graph_new (MultiloadApplet *ma, guint n, const gchar *label,
g->n = n;
g->id = id;
g->speed = speed;
- g->size = MAX (size, 10);
+ g->size = size;
g->pixel_size = mate_panel_applet_get_size (ma->applet);
g->tooltip_update = FALSE;
g->multiload = ma;
diff --git a/multiload/src/main.c b/multiload/src/main.c
index 12363fe8..e1b0481e 100644
--- a/multiload/src/main.c
+++ b/multiload/src/main.c
@@ -361,7 +361,7 @@ multiload_create_graphs(MultiloadApplet *ma)
[graph_diskload] = { _("Disk Load"), VIEW_DISKLOAD_KEY, "diskload", diskload_n, GetDiskLoad }
};
- gint size;
+ guint size;
guint speed;
guint net_threshold1;
guint net_threshold2;
@@ -369,10 +369,10 @@ multiload_create_graphs(MultiloadApplet *ma)
gint i;
speed = CLAMP (g_settings_get_uint (ma->settings, REFRESH_RATE_KEY), REFRESH_RATE_MIN, REFRESH_RATE_MAX);
- size = CLAMP (g_settings_get_int (ma->settings, "size"), 10, 400);
- 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);
+ size = CLAMP (g_settings_get_uint (ma->settings, GRAPH_SIZE_KEY), GRAPH_SIZE_MIN, GRAPH_SIZE_MAX);
+ net_threshold1 = CLAMP (g_settings_get_uint (ma->settings, KEY_NET_THRESHOLD1), MIN_NET_THRESHOLD1, MAX_NET_THRESHOLD1);
+ net_threshold2 = CLAMP (g_settings_get_uint (ma->settings, KEY_NET_THRESHOLD2), MIN_NET_THRESHOLD2, MAX_NET_THRESHOLD2);
+ net_threshold3 = CLAMP (g_settings_get_uint (ma->settings, KEY_NET_THRESHOLD3), MIN_NET_THRESHOLD3, MAX_NET_THRESHOLD3);
if (net_threshold1 >= net_threshold2)
{
net_threshold1 = net_threshold2 - 1;
diff --git a/multiload/src/properties.c b/multiload/src/properties.c
index 9da7b271..9e1ec66c 100644
--- a/multiload/src/properties.c
+++ b/multiload/src/properties.c
@@ -28,10 +28,6 @@
#define PROP_AVG 4
#define PROP_DISK 5
-#define PROP_SIZE 7
-#define PROP_NET_THRESHOLD1 8
-#define PROP_NET_THRESHOLD2 9
-#define PROP_NET_THRESHOLD3 10
#define HIG_IDENTATION " "
#define NEVER_SENSITIVE "never_sensitive"
@@ -157,92 +153,80 @@ on_speed_spin_button_value_changed (GtkSpinButton *spin_button,
}
static void
-spin_button_changed_cb (GtkWidget *widget,
- gpointer name)
+on_graph_size_spin_button_value_changed (GtkSpinButton *spin_button,
+ gpointer user_data)
{
- MultiloadApplet *ma;
+ MultiloadApplet *ma = user_data;
gint value;
- gint prop_type, i;
+ gint i;
- ma = g_object_get_data (G_OBJECT (widget), "MultiloadApplet");
- prop_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "prop_type"));
- value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
+ value = gtk_spin_button_get_value_as_int (spin_button);
+ g_settings_set_uint (ma->settings, GRAPH_SIZE_KEY, (guint) value);
+ for (i = 0; i < graph_n; i++) {
+ ma->graphs[i]->size = (guint) value;
+ if (ma->graphs[i]->orient) {
+ gtk_widget_set_size_request (ma->graphs[i]->main_widget,
+ ma->graphs[i]->pixel_size,
+ ma->graphs[i]->size);
+ } else {
+ gtk_widget_set_size_request (ma->graphs[i]->main_widget,
+ ma->graphs[i]->size,
+ ma->graphs[i]->pixel_size);
+ }
+ }
+}
- switch(prop_type)
- {
- case PROP_SIZE:
- for (i = 0; i < graph_n; i++)
- {
- g_settings_set_int (ma->settings, (gchar *)name, value);
- ma->graphs[i]->size = value ;
-
- if (ma->graphs[i]->orient)
- gtk_widget_set_size_request (
- ma->graphs[i]->main_widget,
- ma->graphs[i]->pixel_size,
- ma->graphs[i]->size);
- else
- gtk_widget_set_size_request (
- ma->graphs[i]->main_widget,
- ma->graphs[i]->size,
- ma->graphs[i]->pixel_size);
- }
- break;
+static void
+on_net_threshold1_spin_button_value_changed (GtkSpinButton *spin_button,
+ gpointer user_data)
+{
+ MultiloadApplet *ma = user_data;
+ gint value;
- case PROP_NET_THRESHOLD1:
- g_settings_set_uint (ma->settings, (gchar *)name, value);
- if (value >= ma->net_threshold2)
- {
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget),
- (gdouble)g_settings_get_uint (ma->settings,
- "netthreshold2") - 1);
- ma->net_threshold1 = g_settings_get_uint (ma->settings,
- "netthreshold2") - 1;
- }
- else
- ma->net_threshold1 = value;
- break;
+ value = gtk_spin_button_get_value_as_int (spin_button);
+ if (value >= (gint) ma->net_threshold2) {
+ value = (gint) ma->net_threshold2 - 1;
+ gtk_spin_button_set_value (spin_button, (gdouble) value);
+ }
+ ma->net_threshold1 = (guint) value;
+ g_settings_set_uint (ma->settings, KEY_NET_THRESHOLD1, ma->net_threshold1);
+}
- case PROP_NET_THRESHOLD2:
- g_settings_set_uint (ma->settings, (gchar *)name, value);
- if (value >= ma->net_threshold3)
- {
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget),
- (gdouble)g_settings_get_uint (ma->settings,
- "netthreshold3") - 1);
- ma->net_threshold2 = g_settings_get_uint (ma->settings,
- "netthreshold3") - 1;
- }
- else if (value <= ma->net_threshold1)
- {
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget),
- (gdouble)g_settings_get_uint (ma->settings,
- "netthreshold1") + 1);
- ma->net_threshold2 = g_settings_get_uint (ma->settings,
- "netthreshold1") + 1;
- }
- else
- ma->net_threshold2 = value;
- break;
- case PROP_NET_THRESHOLD3:
- g_settings_set_uint (ma->settings, (gchar *)name, value);
- if (value <= ma->net_threshold2)
- {
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget),
- (gdouble)g_settings_get_uint (ma->settings,
- "netthreshold2") + 1);
- ma->net_threshold3 = g_settings_get_uint (ma->settings,
- "netthreshold2") + 1;
- }
- else
- ma->net_threshold3 = value;
- break;
- default:
- g_assert_not_reached();
+static void
+on_net_threshold2_spin_button_value_changed (GtkSpinButton *spin_button,
+ gpointer user_data)
+{
+ MultiloadApplet *ma = user_data;
+ gint value;
+
+ value = gtk_spin_button_get_value_as_int (spin_button);
+ if (value >= (gint) ma->net_threshold3) {
+ value = (gint) ma->net_threshold3 - 1;
+ gtk_spin_button_set_value (spin_button, (gdouble) value);
+ } else if (value <= (gint) ma->net_threshold1) {
+ value = (gint) ma->net_threshold1 + 1;
+ gtk_spin_button_set_value (spin_button, (gdouble) value);
}
+ ma->net_threshold2 = (guint) value;
+ g_settings_set_uint (ma->settings, KEY_NET_THRESHOLD2, ma->net_threshold2);
+}
- return;
+
+static void
+on_net_threshold3_spin_button_value_changed (GtkSpinButton *spin_button,
+ gpointer user_data)
+{
+ MultiloadApplet *ma = user_data;
+ gint value;
+
+ value = gtk_spin_button_get_value_as_int (spin_button);
+ if (value <= (gint) ma->net_threshold2) {
+ value = (gint) ma->net_threshold2 + 1;
+ gtk_spin_button_set_value (spin_button, (gdouble) value);
+ }
+ ma->net_threshold3 = (guint) value;
+ g_settings_set_uint (ma->settings, KEY_NET_THRESHOLD3, ma->net_threshold3);
}
/* create a new page in the notebook widget, add it, and return a pointer to it */
@@ -370,6 +354,7 @@ fill_properties(GtkWidget *dialog, MultiloadApplet *ma)
GtkSizeGroup *spin_size;
gchar *label_text;
gchar *title;
+ guint spin_value_uint;
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
@@ -540,17 +525,16 @@ 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, 1000, 5);
+ spin_button = gtk_spin_button_new_with_range (GRAPH_SIZE_MIN, GRAPH_SIZE_MAX, 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",
- GINT_TO_POINTER(PROP_SIZE));
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_button),
- (gdouble)g_settings_get_int(ma->settings, "size"));
- g_signal_connect(G_OBJECT(spin_button), "value_changed",
- G_CALLBACK(spin_button_changed_cb), "size");
-
- if ( ! g_settings_is_writable (ma->settings, "size")) {
+ spin_value_uint = CLAMP (g_settings_get_uint (ma->settings, GRAPH_SIZE_KEY),
+ GRAPH_SIZE_MIN,
+ GRAPH_SIZE_MAX);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin_button), (gdouble) spin_value_uint);
+ g_signal_connect (GTK_SPIN_BUTTON (spin_button), "value-changed",
+ G_CALLBACK (on_graph_size_spin_button_value_changed), ma);
+
+ if ( ! g_settings_is_writable (ma->settings, GRAPH_SIZE_KEY)) {
hard_set_sensitive (label, FALSE);
hard_set_sensitive (hbox, FALSE);
}
@@ -579,11 +563,12 @@ fill_properties(GtkWidget *dialog, MultiloadApplet *ma)
REFRESH_RATE_MAX,
50);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button);
+ spin_value_uint = CLAMP (g_settings_get_uint (ma->settings, REFRESH_RATE_KEY),
+ REFRESH_RATE_MIN,
+ REFRESH_RATE_MAX);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin_button),
- (gdouble) CLAMP (g_settings_get_uint (ma->settings, REFRESH_RATE_KEY),
- REFRESH_RATE_MIN,
- REFRESH_RATE_MAX));
- g_signal_connect (GTK_SPIN_BUTTON (spin_button), "value_changed",
+ (gdouble) spin_value_uint);
+ g_signal_connect (GTK_SPIN_BUTTON (spin_button), "value-changed",
G_CALLBACK (on_speed_spin_button_value_changed), ma);
gtk_size_group_add_widget (spin_size, spin_button);
gtk_box_pack_start (GTK_BOX (hbox), spin_button, FALSE, FALSE, 0);
@@ -722,15 +707,12 @@ fill_properties(GtkWidget *dialog, MultiloadApplet *ma)
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",
- GUINT_TO_POINTER(PROP_NET_THRESHOLD1));
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_button),
- (gdouble)g_settings_get_uint(ma->settings, "netthreshold1"));
- g_signal_connect(G_OBJECT(spin_button), "value_changed",
- G_CALLBACK(spin_button_changed_cb), "netthreshold1");
-
- if ( ! g_settings_is_writable (ma->settings, "netthreshold1"))
+ spin_value_uint = g_settings_get_uint (ma->settings, KEY_NET_THRESHOLD1);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin_button), (gdouble) spin_value_uint);
+ g_signal_connect (GTK_SPIN_BUTTON (spin_button), "value-changed",
+ G_CALLBACK (on_net_threshold1_spin_button_value_changed), ma);
+
+ if ( ! g_settings_is_writable (ma->settings, KEY_NET_THRESHOLD1))
{
hard_set_sensitive (label, FALSE);
hard_set_sensitive (hbox, FALSE);
@@ -758,17 +740,14 @@ fill_properties(GtkWidget *dialog, MultiloadApplet *ma)
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",
- GINT_TO_POINTER(PROP_NET_THRESHOLD2));
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_button),
- (gdouble)g_settings_get_uint (ma->settings, "netthreshold2"));
- g_signal_connect(G_OBJECT(spin_button), "value_changed",
- G_CALLBACK(spin_button_changed_cb), "netthreshold2");
+ spin_value_uint = g_settings_get_uint (ma->settings, KEY_NET_THRESHOLD2);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin_button), (gdouble) spin_value_uint);
+ g_signal_connect (GTK_SPIN_BUTTON (spin_button), "value-changed",
+ G_CALLBACK (on_net_threshold2_spin_button_value_changed), ma);
gtk_size_group_add_widget (spin_size, spin_button);
gtk_box_pack_start (GTK_BOX (hbox), spin_button, FALSE, FALSE, 0);
- if ( ! g_settings_is_writable (ma->settings, "netthreshold2"))
+ if ( ! g_settings_is_writable (ma->settings, KEY_NET_THRESHOLD2))
{
hard_set_sensitive (label, FALSE);
hard_set_sensitive (hbox, FALSE);
@@ -793,17 +772,14 @@ fill_properties(GtkWidget *dialog, MultiloadApplet *ma)
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",
- GINT_TO_POINTER(PROP_NET_THRESHOLD3));
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_button),
- (gdouble)g_settings_get_uint (ma->settings, "netthreshold3"));
- g_signal_connect(G_OBJECT(spin_button), "value_changed",
- G_CALLBACK(spin_button_changed_cb), "netthreshold3");
+ spin_value_uint = g_settings_get_uint (ma->settings, KEY_NET_THRESHOLD3);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin_button), (gdouble) spin_value_uint);
+ g_signal_connect (GTK_SPIN_BUTTON (spin_button), "value-changed",
+ G_CALLBACK (on_net_threshold3_spin_button_value_changed), ma);
gtk_size_group_add_widget (spin_size, spin_button);
gtk_box_pack_start (GTK_BOX (hbox), spin_button, FALSE, FALSE, 0);
- if ( ! g_settings_is_writable (ma->settings, "netthreshold3"))
+ if ( ! g_settings_is_writable (ma->settings, KEY_NET_THRESHOLD3))
{
hard_set_sensitive (label, FALSE);
hard_set_sensitive (hbox, FALSE);