Maximum network load in multiload applet



[Sorry if this is the wrong list; I can't find a list about
gnome-applets only]

Hi; I made a patch to set a maximum network load in the multiload
applet.

Rationale: I've a DSL Internet connection (512 kbps), and I use a very
old computer as gateway/NAT/router/etc. All the other computers in my
house are connected in a LAN, and all of them use the old one to access
the Internet.

I think that is a very common setup for a home LAN.

The problem with the multiload applet, specifically with the network
load, is that the current load is calculated against the maximum load
that has EVER been detected. So, if I transmit a file within my LAN, the
maximum load is set too high, and the load used by my Internet
connection gets lost, because it's too small in comparison. And is the
Internet load the one that matters to me. 

The patch adds two more gconf keys to the applet: bool fixed_netload_max
and int netload_max. If fixed_netload_max is false (by default it is),
the old behavior is used. If it's true, then netload_max is used as
maximum load.

I also modified the preferences dialog, but I'm aware that is very very
ugly. I only wanted to be able to set the keys via the preferences
dialog.

I think this is a cool idea. Maybe we could even set a preferences
dialog with preset options for maximum load (with already defined values
for connections of 128 kbps, 256, 512, etc.)

I hope you guys at least consider the idea.

Canek
--
All new:
	Parts not interchangeable with previous model.
diff -burN gnome-applets-2.6.2/multiload/linux-proc.c gnome-applets-2.6.2.reset/multiload/linux-proc.c
--- gnome-applets-2.6.2/multiload/linux-proc.c	2004-02-19 18:31:23.000000000 -0600
+++ gnome-applets-2.6.2.reset/multiload/linux-proc.c	2004-09-16 11:50:16.000000000 -0500
@@ -17,6 +17,8 @@
 #include <glibtop/loadavg.h>
 #include <glibtop/netload.h>
 
+#include <panel-applet-gconf.h>
+
 #include "linux-proc.h"
 
 static unsigned needed_cpu_flags =
@@ -378,7 +380,10 @@
 		    delta[i] = 0;
 	    total += delta[i];
 	}
-	if (total > max)
+
+	if (panel_applet_gconf_get_bool (g->applet, "fixed_netload_max", NULL))
+            max = panel_applet_gconf_get_int (g->applet, "netload_max", NULL);
+	else if (total > max)
 	    max = total;
 	for (i = 0; i < COUNT_TYPES; i++)
 	    data[i]   = rint (Maximum * (float)delta[i]  / max);
diff -burN gnome-applets-2.6.2/multiload/multiload.schemas.in gnome-applets-2.6.2.reset/multiload/multiload.schemas.in
--- gnome-applets-2.6.2/multiload/multiload.schemas.in	2003-08-08 09:50:57.000000000 -0500
+++ gnome-applets-2.6.2.reset/multiload/multiload.schemas.in	2004-09-16 00:00:05.000000000 -0500
@@ -234,5 +234,24 @@
 	</locale>
 </schema>
 
+<schema>
+	<key>/schemas/apps/multiload/prefs/netload_max</key>
+	<owner>multiload-applet-2</owner>
+	<type>int</type>
+	<default>500</default>
+	<locale name="C">
+		<short>Maximum network load</short>
+	</locale>
+</schema>
+<schema>
+	<key>/schemas/apps/multiload/prefs/fixed_netload_max</key>
+	<owner>multiload-applet-2</owner>
+	<type>bool</type>
+	<default>false</default>
+	<locale name="C">
+		<short>The maximum network load is fixed</short>
+	</locale>
+</schema>
+
 </schemalist>
 </gconfschemafile>
diff -burN gnome-applets-2.6.2/multiload/properties.c gnome-applets-2.6.2.reset/multiload/properties.c
--- gnome-applets-2.6.2/multiload/properties.c	2004-02-23 04:26:58.000000000 -0600
+++ gnome-applets-2.6.2.reset/multiload/properties.c	2004-09-16 13:38:13.000000000 -0500
@@ -101,6 +101,19 @@
 }
 
 void
+netload_max_toggled_cb(GtkWidget *widget, gpointer name)
+{
+	MultiloadApplet *ma;
+	GtkWidget *spin_button;
+	gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
+	spin_button = g_object_get_data(G_OBJECT(widget), "spin_button");
+	ma = g_object_get_data(G_OBJECT(widget), "MultiloadApplet");
+	panel_applet_gconf_set_bool(ma->applet, (gchar *)name, active, NULL);
+	panel_applet_gconf_set_bool(ma->applet, (gchar *)name, active, NULL);
+	gtk_widget_set_sensitive (spin_button, active);
+}
+
+void
 property_toggled_cb(GtkWidget *widget, gpointer name)
 {
 	MultiloadApplet *ma;
@@ -137,6 +150,18 @@
 }
 
 void
+netload_max_spined_cb(GtkWidget *widget, gpointer name)
+{
+	MultiloadApplet *ma;
+	gint value;
+
+	ma = g_object_get_data(G_OBJECT(widget), "MultiloadApplet");
+	value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
+	panel_applet_gconf_set_int(ma->applet, (gchar *)name, value, NULL);
+	panel_applet_gconf_set_int(ma->applet, (gchar *)name, value, NULL);
+}
+
+void
 spin_button_changed_cb(GtkWidget *widget, gpointer name)
 {
 	MultiloadApplet *ma;
@@ -305,9 +330,11 @@
 	GtkWidget *control_vbox;
 	GtkWidget *control_hbox;
 	GtkWidget *check_box;
+	GtkWidget *netload_max_check_box;
 	GtkWidget *indent;
 	GtkWidget *spin_button;
 	GtkWidget *label;
+	GtkWidget *separator;
 	PanelAppletOrient orient;
 	GtkSizeGroup *label_size;
 	GtkSizeGroup *spin_size;
@@ -526,6 +553,52 @@
 	
 	g_free(label_text);
 	
+	separator = gtk_hseparator_new();
+	gtk_box_pack_start (GTK_BOX (control_vbox), separator, TRUE, TRUE, 0);
+	gtk_widget_show (separator);
+
+	control_hbox = gtk_hbox_new (FALSE, 12);
+	gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0);
+	gtk_widget_show (control_hbox);
+
+	check_box = gtk_check_button_new_with_mnemonic(_("_Set maximum network load"));
+	netload_max_check_box = check_box;
+	g_object_set_data(G_OBJECT(check_box), "MultiloadApplet", ma);
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box),
+				panel_applet_gconf_get_bool(ma->applet, "fixed_netload_max", NULL));
+	g_signal_connect(G_OBJECT(check_box), "toggled",
+				G_CALLBACK(netload_max_toggled_cb), "fixed_netload_max");
+	gtk_box_pack_start(GTK_BOX(control_hbox), check_box, FALSE, FALSE, 0);
+
+	control_hbox = gtk_hbox_new (FALSE, 12);
+	gtk_box_pack_start (GTK_BOX (control_vbox), control_hbox, TRUE, TRUE, 0);
+	gtk_widget_show (control_hbox);
+
+	label = gtk_label_new_with_mnemonic(_("Ma_ximum network load: "));
+	gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f);
+	gtk_size_group_add_widget (label_size, label);
+	gtk_box_pack_start (GTK_BOX (control_hbox), label, FALSE, FALSE, 0);
+	
+	hbox = gtk_hbox_new (FALSE, 6);
+	gtk_box_pack_start (GTK_BOX (control_hbox), hbox, TRUE, TRUE, 0);
+	gtk_widget_show (hbox);
+
+	spin_button = gtk_spin_button_new_with_range(500, 5000000, 500);
+	gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button);
+	g_object_set_data(G_OBJECT(netload_max_check_box), "spin_button", spin_button);
+	g_object_set_data(G_OBJECT(spin_button), "MultiloadApplet", ma);
+	gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_button),
+				(gdouble)panel_applet_gconf_get_int(ma->applet, "netload_max", NULL));
+	g_signal_connect(G_OBJECT(spin_button), "value_changed",
+				G_CALLBACK(netload_max_spined_cb), "netload_max");
+	gtk_size_group_add_widget (spin_size, spin_button);
+	gtk_box_pack_start (GTK_BOX (hbox), spin_button, FALSE, FALSE, 0);
+	gtk_widget_set_sensitive (spin_button,
+				  panel_applet_gconf_get_bool(ma->applet, "fixed_netload_max", NULL));
+
+	label = gtk_label_new(_("bps"));
+	gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f);
+	gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
 	
 	category_vbox = gtk_vbox_new (FALSE, 6);
 	gtk_box_pack_start (GTK_BOX (categories_vbox), category_vbox, TRUE, TRUE, 0);

Attachment: Multiload-preferences.png
Description: PNG image

Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]