[netspeed/unstable: 3/3] Move settings dialog into it's own class. Create a new class settings.



commit 72bb9a5d64814c004b48a1d3243f6a77ea7e0538
Author: Jörgen Scheibengruber <mfcn gmx de>
Date:   Fri Jun 11 00:29:25 2010 +0300

    Move settings dialog into it's own class. Create a new class settings.

 src/Makefile.am       |    2 +-
 src/netspeed.c        |  297 +++++++-----------------------------------
 src/settings-dialog.c |  347 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/settings-dialog.h |   58 ++++++++
 src/settings.c        |  128 ++++++++++++++++++
 src/settings.h        |   57 ++++++++
 6 files changed, 638 insertions(+), 251 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index c4a57ef..e2dadba 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,6 +7,6 @@ INCLUDES = -I$(top_srcdir) -I$(includedir) $(NETSPEED_CFLAGS) $(NETSPEED_LIBGTOP
 
 libexec_PROGRAMS = netspeed_applet2
 
-netspeed_applet2_SOURCES = backend.h backend.c netspeed.h netspeed.c dialogs.c
+netspeed_applet2_SOURCES = backend.h backend.c settings.h settings.c settings-dialog.h settings-dialog.c netspeed.h netspeed.c dialogs.c
 
 netspeed_applet2_LDADD = $(NETSPEED_LIBS) $(NETSPEED_LIBGTOP_LIBS) $(IWLIB) $(INTLLIBS)
diff --git a/src/netspeed.c b/src/netspeed.c
index 5928a3a..f9962ec 100644
--- a/src/netspeed.c
+++ b/src/netspeed.c
@@ -27,6 +27,8 @@
 #include <panel-applet-gconf.h>
 #include <gconf/gconf-client.h>
 #include "netspeed.h"
+#include "settings.h"
+#include "settings-dialog.h"
 #include "backend.h"
 
 /* Icons for the interfaces */
@@ -61,11 +63,32 @@ static const char LOGO_ICON[] = "netspeed-applet";
 #define GRAPH_VALUES 180
 #define GRAPH_LINES 4
 
+typedef struct _NetspeedApplet NetspeedApplet;
+
+struct _NetspeedPrivate
+{
+	NetspeedApplet *stuff;
+
+	Settings *settings;
+	guint timeout_id;
+};
+
+#define NETSPEED_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE ((o), NETSPEED_TYPE, NetspeedPrivate))
+
+static void netspeed_class_init (NetspeedClass *klass);
+static void netspeed_init       (Netspeed *self);
+static void netspeed_dispose    (GObject *object);
+static void netspeed_finalize   (GObject *object);
+
+G_DEFINE_TYPE (Netspeed, netspeed, PANEL_TYPE_APPLET);
+
+
 /* A struct containing all the "global" data of the 
  * applet
  * FIXME: This is old stuff and should be moved into NetspeedPrivate
  */
-typedef struct
+struct _NetspeedApplet
 {
 	PanelApplet *applet;
 	GtkWidget *box, *pix_box,
@@ -76,22 +99,21 @@ typedef struct
 	
 	GtkWidget *signalbar;
 	
-	gboolean labels_dont_shrink;
-	
-	DevInfo devinfo;
-	gboolean device_has_changed;
-		
 	int refresh_time;
 	char *up_cmd, *down_cmd;
 	gboolean show_sum, show_bits;
 	gboolean change_icon, auto_change_device;
 	GdkColor in_color, out_color;
+	gboolean labels_dont_shrink;
+	
+	DevInfo devinfo;
+	gboolean device_has_changed;
+		
 	int width;
 	
 	GtkWidget *inbytes_text, *outbytes_text;
-	GtkDialog *details, *settings;
+	GtkWidget *details, *settings_dialog;
 	GtkDrawingArea *drawingarea;
-	GtkWidget *network_device_combo;
 	
 	guint index_old;
 	guint64 in_old[OLD_VALUES], out_old[OLD_VALUES];
@@ -101,7 +123,7 @@ typedef struct
 	GtkWidget *connect_dialog;
 	
 	gboolean show_tooltip;
-} NetspeedApplet;
+};
 
 static const char 
 netspeed_applet_menu_xml [] =
@@ -844,89 +866,6 @@ about_cb(BonoboUIComponent *uic, gpointer data, const gchar *verbname)
 	
 }
 
-/* this basically just retrieves the new devicestring 
- * and then calls applet_device_change() and change_icons()
- */
-static void
-device_change_cb(GtkComboBox *combo, NetspeedApplet *applet)
-{
-	GList *devices;
-	int i, active;
-
-	g_assert(combo);
-	devices = g_object_get_data(G_OBJECT(combo), "devices");
-	active = gtk_combo_box_get_active(combo);
-	g_assert(active > -1);
-
-	if (0 == active) {
-		if (applet->auto_change_device)
-			return;
-		applet->auto_change_device = TRUE;
-	} else {
-		applet->auto_change_device = FALSE;
-		for (i = 1; i < active; i++) {
-			devices = g_list_next(devices);
-		}
-		if (g_str_equal(devices->data, applet->devinfo.name))
-			return;
-		free_device_info(&applet->devinfo);
-		get_device_info(devices->data, &applet->devinfo);
-	}
-
-	applet->device_has_changed = TRUE;
-	update_applet(applet);
-}
-
-
-/* Handle preference dialog response event
- */
-static void
-pref_response_cb (GtkDialog *dialog, gint id, gpointer data)
-{
-    NetspeedApplet *applet = data;
-  
-    if(id == GTK_RESPONSE_HELP){
-        display_help (GTK_WIDGET (dialog), "netspeed_applet-settings");
-	return;
-    }
-    panel_applet_gconf_set_string(PANEL_APPLET(applet->applet), "device", applet->devinfo.name, NULL);
-    panel_applet_gconf_set_bool(PANEL_APPLET(applet->applet), "show_sum", applet->show_sum, NULL);
-    panel_applet_gconf_set_bool(PANEL_APPLET(applet->applet), "show_bits", applet->show_bits, NULL);
-    panel_applet_gconf_set_bool(PANEL_APPLET(applet->applet), "change_icon", applet->change_icon, NULL);
-    panel_applet_gconf_set_bool(PANEL_APPLET(applet->applet), "auto_change_device", applet->auto_change_device, NULL);
-    panel_applet_gconf_set_bool(PANEL_APPLET(applet->applet), "have_settings", TRUE, NULL);
-
-    gtk_widget_destroy(GTK_WIDGET(applet->settings));
-    applet->settings = NULL;
-}
-
-/* Called when the showsum checkbutton is toggled...
- */
-static void
-showsum_change_cb(GtkToggleButton *togglebutton, NetspeedApplet *applet)
-{
-	applet->show_sum = gtk_toggle_button_get_active(togglebutton);
-	applet_change_size_or_orient(applet->applet, -1, (gpointer)applet);
-	change_icons(applet);
-}
-
-/* Called when the showbits checkbutton is toggled...
- */
-static void
-showbits_change_cb(GtkToggleButton *togglebutton, NetspeedApplet *applet)
-{
-	applet->show_bits = gtk_toggle_button_get_active(togglebutton);
-}
-
-/* Called when the changeicon checkbutton is toggled...
- */
-static void
-changeicon_change_cb(GtkToggleButton *togglebutton, NetspeedApplet *applet)
-{
-	applet->change_icon = gtk_toggle_button_get_active(togglebutton);
-	change_icons(applet);
-}
-
 /* Creates the settings dialog
  * After its been closed, take the new values and store
  * them in the gconf database
@@ -934,134 +873,17 @@ changeicon_change_cb(GtkToggleButton *togglebutton, NetspeedApplet *applet)
 static void
 settings_cb(BonoboUIComponent *uic, gpointer data, const gchar *verbname)
 {
-	NetspeedApplet *applet = (NetspeedApplet*)data;
-	GtkWidget *vbox;
-	GtkWidget *hbox;
-	GtkWidget *categories_vbox;
-	GtkWidget *category_vbox;
-	GtkWidget *controls_vbox;
-	GtkWidget *category_header_label;
-	GtkWidget *network_device_hbox;
-	GtkWidget *network_device_label;
-	GtkWidget *indent_label;
-	GtkWidget *show_sum_checkbutton;
-	GtkWidget *show_bits_checkbutton;
-	GtkWidget *change_icon_checkbutton;
-	GtkSizeGroup *category_label_size_group;
-	GtkSizeGroup *category_units_size_group;
-  	gchar *header_str;
-	GList *ptr, *devices;
-	int i, active = -1;
-	
-	g_assert(applet);
-	
-	if (applet->settings)
+	NetspeedApplet *applet = data;
+	NetspeedPrivate *priv = NETSPEED (applet->applet)->priv;
+
+	if (applet->settings_dialog)
 	{
-		gtk_window_present(GTK_WINDOW(applet->settings));
+		gtk_window_present(GTK_WINDOW(applet->settings_dialog));
 		return;
 	}
+	applet->settings_dialog = settings_dialog_new (priv->settings);
 
-	category_label_size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
-	category_units_size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
-  
-	applet->settings = GTK_DIALOG(gtk_dialog_new_with_buttons(_("Netspeed Preferences"), 
-								  NULL, 
-								  GTK_DIALOG_DESTROY_WITH_PARENT |
-								  GTK_DIALOG_NO_SEPARATOR,	
-								  GTK_STOCK_HELP, GTK_RESPONSE_HELP, 
-								  GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, 
-								  NULL));
-	
-	gtk_window_set_resizable(GTK_WINDOW(applet->settings), FALSE);
-	gtk_window_set_screen(GTK_WINDOW(applet->settings), 
-			      gtk_widget_get_screen(GTK_WIDGET(applet->settings)));
-			       
-	gtk_dialog_set_default_response(GTK_DIALOG(applet->settings), GTK_RESPONSE_CLOSE);
-
-	vbox = gtk_vbox_new(FALSE, 0);
-	gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
-
-	categories_vbox = gtk_vbox_new(FALSE, 18);
-	gtk_box_pack_start(GTK_BOX (vbox), categories_vbox, TRUE, TRUE, 0);
-
-	category_vbox = gtk_vbox_new(FALSE, 6);
-	gtk_box_pack_start(GTK_BOX (categories_vbox), category_vbox, TRUE, TRUE, 0);
-	
-	header_str = g_strconcat("<span weight=\"bold\">", _("General Settings"), "</span>", NULL);
-	category_header_label = gtk_label_new(header_str);
-	gtk_label_set_use_markup(GTK_LABEL(category_header_label), TRUE);
-	gtk_label_set_justify(GTK_LABEL(category_header_label), GTK_JUSTIFY_LEFT);
-	gtk_misc_set_alignment(GTK_MISC (category_header_label), 0, 0.5);
-	gtk_box_pack_start(GTK_BOX (category_vbox), category_header_label, FALSE, FALSE, 0);
-	g_free(header_str);
-	
-	hbox = gtk_hbox_new(FALSE, 0);
-	gtk_box_pack_start(GTK_BOX (category_vbox), hbox, TRUE, TRUE, 0);
-
-	indent_label = gtk_label_new("    ");
-	gtk_label_set_justify(GTK_LABEL (indent_label), GTK_JUSTIFY_LEFT);
-	gtk_box_pack_start(GTK_BOX (hbox), indent_label, FALSE, FALSE, 0);
-		
-	controls_vbox = gtk_vbox_new(FALSE, 10);
-	gtk_box_pack_start(GTK_BOX(hbox), controls_vbox, TRUE, TRUE, 0);
-
-	network_device_hbox = gtk_hbox_new(FALSE, 6);
-	gtk_box_pack_start(GTK_BOX(controls_vbox), network_device_hbox, TRUE, TRUE, 0);
-	
-	network_device_label = gtk_label_new_with_mnemonic(_("Network _device:"));
-	gtk_label_set_justify(GTK_LABEL(network_device_label), GTK_JUSTIFY_LEFT);
-	gtk_misc_set_alignment(GTK_MISC(network_device_label), 0.0f, 0.5f);
-	gtk_size_group_add_widget(category_label_size_group, network_device_label);
-	gtk_box_pack_start(GTK_BOX (network_device_hbox), network_device_label, FALSE, FALSE, 0);
-	
-	applet->network_device_combo = gtk_combo_box_new_text();
-	gtk_label_set_mnemonic_widget(GTK_LABEL(network_device_label), applet->network_device_combo);
-	gtk_box_pack_start (GTK_BOX (network_device_hbox), applet->network_device_combo, TRUE, TRUE, 0);
-
-	/* Default means device with default route set */
-	gtk_combo_box_append_text(GTK_COMBO_BOX(applet->network_device_combo), _("Default"));
-	ptr = devices = get_available_devices();
-	for (i = 1; ptr; ptr = g_list_next(ptr)) {
-		gtk_combo_box_append_text(GTK_COMBO_BOX(applet->network_device_combo), ptr->data);
-		if (g_str_equal(ptr->data, applet->devinfo.name)) active = i;
-		++i;
-	}
-	if (active < 0 || applet->auto_change_device) {
-		active = 0;
-	}
-	gtk_combo_box_set_active(GTK_COMBO_BOX(applet->network_device_combo), active);
-	g_object_set_data_full(G_OBJECT(applet->network_device_combo), "devices", devices, (GDestroyNotify)free_devices_list);
-
-	show_sum_checkbutton = gtk_check_button_new_with_mnemonic(_("Show _sum instead of in & out"));
-	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(show_sum_checkbutton), applet->show_sum);
-	gtk_box_pack_start(GTK_BOX(controls_vbox), show_sum_checkbutton, FALSE, FALSE, 0);
-	
-	show_bits_checkbutton = gtk_check_button_new_with_mnemonic(_("Show _bits instead of bytes"));
-	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(show_bits_checkbutton), applet->show_bits);
-	gtk_box_pack_start(GTK_BOX(controls_vbox), show_bits_checkbutton, FALSE, FALSE, 0);
-	
-	change_icon_checkbutton = gtk_check_button_new_with_mnemonic(_("Change _icon according to the selected device"));
-	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(change_icon_checkbutton), applet->change_icon);
-  	gtk_box_pack_start(GTK_BOX(controls_vbox), change_icon_checkbutton, FALSE, FALSE, 0);
-
-	g_signal_connect(G_OBJECT (applet->network_device_combo), "changed",
-			 G_CALLBACK(device_change_cb), (gpointer)applet);
-
-	g_signal_connect(G_OBJECT (show_sum_checkbutton), "toggled",
-			 G_CALLBACK(showsum_change_cb), (gpointer)applet);
-
-	g_signal_connect(G_OBJECT (show_bits_checkbutton), "toggled",
-			 G_CALLBACK(showbits_change_cb), (gpointer)applet);
-
-	g_signal_connect(G_OBJECT (change_icon_checkbutton), "toggled",
-			 G_CALLBACK(changeicon_change_cb), (gpointer)applet);
-
-	g_signal_connect(G_OBJECT (applet->settings), "response",
-			 G_CALLBACK(pref_response_cb), (gpointer)applet);
-
-	gtk_container_add(GTK_CONTAINER(applet->settings->vbox), vbox); 
-
-	gtk_widget_show_all(GTK_WIDGET(applet->settings));
+	gtk_widget_show_all (GTK_WIDGET(applet->settings_dialog));
 }
 
 static gboolean
@@ -1152,13 +974,13 @@ showinfo_cb(BonoboUIComponent *uic, gpointer data, const gchar *verbname)
 	}
 	
 	title = g_strdup_printf(_("Device Details for %s"), applet->devinfo.name);
-	applet->details = GTK_DIALOG(gtk_dialog_new_with_buttons(title, 
+	applet->details = gtk_dialog_new_with_buttons(title, 
 		NULL, 
 		GTK_DIALOG_DESTROY_WITH_PARENT |
 	 	GTK_DIALOG_NO_SEPARATOR,
 		GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, 
 		GTK_STOCK_HELP, GTK_RESPONSE_HELP,
-		NULL));
+		NULL);
 	g_free(title);
 
 	gtk_dialog_set_default_response(GTK_DIALOG(applet->details), GTK_RESPONSE_CLOSE);
@@ -1310,7 +1132,7 @@ showinfo_cb(BonoboUIComponent *uic, gpointer data, const gchar *verbname)
 	gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
 	gtk_box_pack_start(GTK_BOX(box), table, FALSE, FALSE, 0);
 
-	gtk_container_add(GTK_CONTAINER(applet->details->vbox), box); 
+	gtk_container_add(GTK_CONTAINER(GTK_DIALOG(applet->details)->vbox), box); 
 	gtk_widget_show_all(GTK_WIDGET(applet->details));
 }	
 
@@ -1408,16 +1230,6 @@ applet_button_press(GtkWidget *widget, GdkEventButton *event, NetspeedApplet *ap
 }	
 
 static void
-applet_destroy(PanelApplet *applet_widget, NetspeedApplet *applet)
-{
-	g_assert(applet);
-	
-	return;
-}
-
-
-
-static void
 update_tooltip(NetspeedApplet* applet)
 {
   GString* tooltip;
@@ -1484,23 +1296,6 @@ netspeed_leave_cb(GtkWidget *widget, GdkEventCrossing *event, gpointer data)
 	return TRUE;
 }
 
-struct _NetspeedPrivate
-{
-	NetspeedApplet *stuff;
-
-	guint timeout_id;
-};
-
-#define NETSPEED_GET_PRIVATE(o) \
-(G_TYPE_INSTANCE_GET_PRIVATE ((o), NETSPEED_TYPE, NetspeedPrivate))
-
-static void netspeed_class_init (NetspeedClass *klass);
-static void netspeed_init       (Netspeed *self);
-static void netspeed_dispose    (GObject *object);
-static void netspeed_finalize   (GObject *object);
-
-G_DEFINE_TYPE (Netspeed, netspeed, PANEL_TYPE_APPLET);
-
 static void
 netspeed_class_init (NetspeedClass *klass)
 {
@@ -1530,6 +1325,7 @@ netspeed_init (Netspeed *self)
 
 	gtk_widget_set_name (GTK_WIDGET(self), "PanelApplet");
 	
+	priv->settings = settings_new();
 	/* Alloc the applet. The "NULL-setting" is really redudant
  	 * but aren't we paranoid?
 	 */
@@ -1606,10 +1402,6 @@ netspeed_init (Netspeed *self)
                            G_CALLBACK(label_size_request_cb),
                            (gpointer)applet);
 
-	g_signal_connect(G_OBJECT(self), "destroy",
-                           G_CALLBACK(applet_destroy),
-                           (gpointer)applet);
-
 	g_signal_connect(G_OBJECT(self), "button-press-event",
                            G_CALLBACK(applet_button_press),
                            (gpointer)applet);
@@ -1629,6 +1421,11 @@ netspeed_dispose (GObject *object)
 	NetspeedPrivate *priv;
 	priv = NETSPEED (object)->priv;
 
+	if (priv->settings) {
+		g_object_unref (priv->settings);
+		priv->settings = NULL;
+	}
+
 	G_OBJECT_CLASS (netspeed_parent_class)->dispose (object);
 }
 
diff --git a/src/settings-dialog.c b/src/settings-dialog.c
new file mode 100644
index 0000000..d24e5bd
--- /dev/null
+++ b/src/settings-dialog.c
@@ -0,0 +1,347 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <glib/gi18n.h>
+#include "backend.h"
+#include "settings-dialog.h"
+
+enum
+{
+	PROP_0,
+	PROP_SETTINGS
+};
+
+struct _SettingsDialogPrivate
+{
+	GtkWidget *network_device_combo;
+	GtkWidget *show_sum_checkbutton;
+	GtkWidget *show_bits_checkbutton;
+	GtkWidget *change_icon_checkbutton;
+
+	Settings *settings;
+};
+
+#define SETTINGS_DIALOG_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE ((o), SETTINGS_DIALOG_TYPE, SettingsDialogPrivate))
+
+static void settings_dialog_class_init (SettingsDialogClass *klass);
+static void settings_dialog_init       (SettingsDialog *self);
+static void settings_dialog_constructed(GObject *object);
+static void settings_dialog_dispose    (GObject *object);
+static void settings_dialog_finalize   (GObject *object);
+static void settings_dialog_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+static void settings_dialog_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+
+G_DEFINE_TYPE (SettingsDialog, settings_dialog, GTK_TYPE_DIALOG);
+
+static void
+settings_dialog_class_init (SettingsDialogClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+	g_type_class_add_private (klass, sizeof (SettingsDialogPrivate));
+
+	object_class->constructed = settings_dialog_constructed;
+	object_class->dispose = settings_dialog_dispose;
+	object_class->finalize = settings_dialog_finalize;
+	object_class->set_property = settings_dialog_set_property;
+	object_class->get_property = settings_dialog_get_property;
+
+	g_object_class_install_property (object_class, PROP_SETTINGS,
+		g_param_spec_object ("settings",
+							 "Settings",
+							 "The netspeed settings.",
+							 SETTINGS_TYPE,
+							 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
+}
+
+/* Handle preference dialog response event
+ */
+static void
+pref_response_cb (GtkDialog *dialog, gint id, gpointer data)
+{
+#if 0
+    NetspeedApplet *applet = data;
+  
+    if(id == GTK_RESPONSE_HELP){
+        display_help (GTK_WIDGET (dialog), "netspeed_applet-settings");
+	return;
+    }
+    panel_applet_gconf_set_string(PANEL_APPLET(applet->applet), "device", applet->devinfo.name, NULL);
+    panel_applet_gconf_set_bool(PANEL_APPLET(applet->applet), "show_sum", applet->show_sum, NULL);
+    panel_applet_gconf_set_bool(PANEL_APPLET(applet->applet), "show_bits", applet->show_bits, NULL);
+    panel_applet_gconf_set_bool(PANEL_APPLET(applet->applet), "change_icon", applet->change_icon, NULL);
+    panel_applet_gconf_set_bool(PANEL_APPLET(applet->applet), "auto_change_device", applet->auto_change_device, NULL);
+    panel_applet_gconf_set_bool(PANEL_APPLET(applet->applet), "have_settings", TRUE, NULL);
+
+    gtk_widget_destroy(GTK_WIDGET(applet->settings));
+    applet->settings = NULL;
+#endif
+}
+
+#if 0
+/* this basically just retrieves the new devicestring 
+ * and then calls applet_device_change() and change_icons()
+ */
+static void
+device_change_cb(GtkComboBox *combo, NetspeedApplet *applet)
+{
+	GList *devices;
+	int i, active;
+
+	g_assert(combo);
+	devices = g_object_get_data(G_OBJECT(combo), "devices");
+	active = gtk_combo_box_get_active(combo);
+	g_assert(active > -1);
+
+	if (0 == active) {
+		if (applet->auto_change_device)
+			return;
+		applet->auto_change_device = TRUE;
+	} else {
+		applet->auto_change_device = FALSE;
+		for (i = 1; i < active; i++) {
+			devices = g_list_next(devices);
+		}
+		if (g_str_equal(devices->data, applet->devinfo.name))
+			return;
+		free_device_info(&applet->devinfo);
+		get_device_info(devices->data, &applet->devinfo);
+	}
+
+	applet->device_has_changed = TRUE;
+	update_applet(applet);
+}
+
+
+/* Called when the showsum checkbutton is toggled...
+ */
+static void
+showsum_change_cb(GtkToggleButton *togglebutton, NetspeedApplet *applet)
+{
+	applet->show_sum = gtk_toggle_button_get_active(togglebutton);
+	applet_change_size_or_orient(applet->applet, -1, (gpointer)applet);
+	change_icons(applet);
+}
+
+/* Called when the showbits checkbutton is toggled...
+ */
+static void
+showbits_change_cb(GtkToggleButton *togglebutton, NetspeedApplet *applet)
+{
+	applet->show_bits = gtk_toggle_button_get_active(togglebutton);
+}
+
+/* Called when the changeicon checkbutton is toggled...
+ */
+static void
+changeicon_change_cb(GtkToggleButton *togglebutton, NetspeedApplet *applet)
+{
+	applet->change_icon = gtk_toggle_button_get_active(togglebutton);
+	change_icons(applet);
+}
+#endif
+
+static void
+settings_dialog_init (SettingsDialog *self)
+{
+	SettingsDialogPrivate *priv;
+	GtkWidget *vbox;
+	GtkWidget *hbox;
+	GtkWidget *categories_vbox;
+	GtkWidget *category_vbox;
+	GtkWidget *controls_vbox;
+	GtkWidget *category_header_label;
+	GtkWidget *network_device_hbox;
+	GtkWidget *network_device_label;
+	GtkWidget *indent_label;
+	GtkSizeGroup *category_label_size_group;
+	GtkSizeGroup *category_units_size_group;
+	gchar *header_str;
+
+	priv = SETTINGS_DIALOG_GET_PRIVATE (self);
+	self->priv = priv;
+
+	category_label_size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+	category_units_size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+
+	gtk_dialog_add_buttons (GTK_DIALOG (self),
+							GTK_STOCK_HELP, GTK_RESPONSE_HELP,
+							GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT,
+							NULL);
+	gtk_dialog_set_default_response(GTK_DIALOG(self),
+									GTK_RESPONSE_CLOSE);
+	gtk_window_set_destroy_with_parent (GTK_WINDOW (self), TRUE);
+	gtk_window_set_title (GTK_WINDOW (self), _("Netspeed Preferences"));
+	
+	gtk_window_set_resizable(GTK_WINDOW(self), FALSE);
+	gtk_window_set_screen(GTK_WINDOW(self), 
+						gtk_widget_get_screen(GTK_WIDGET(self)));
+
+	vbox = gtk_vbox_new(FALSE, 0);
+	gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
+
+	categories_vbox = gtk_vbox_new(FALSE, 18);
+	gtk_box_pack_start(GTK_BOX (vbox), categories_vbox, TRUE, TRUE, 0);
+
+	category_vbox = gtk_vbox_new(FALSE, 6);
+	gtk_box_pack_start(GTK_BOX (categories_vbox), category_vbox, TRUE, TRUE, 0);
+	
+	header_str = g_strconcat("<span weight=\"bold\">", _("General Settings"), "</span>", NULL);
+	category_header_label = gtk_label_new(header_str);
+	gtk_label_set_use_markup(GTK_LABEL(category_header_label), TRUE);
+	gtk_label_set_justify(GTK_LABEL(category_header_label), GTK_JUSTIFY_LEFT);
+	gtk_misc_set_alignment(GTK_MISC (category_header_label), 0, 0.5);
+	gtk_box_pack_start(GTK_BOX (category_vbox), category_header_label, FALSE, FALSE, 0);
+	g_free(header_str);
+	
+	hbox = gtk_hbox_new(FALSE, 0);
+	gtk_box_pack_start(GTK_BOX (category_vbox), hbox, TRUE, TRUE, 0);
+
+	indent_label = gtk_label_new("    ");
+	gtk_label_set_justify(GTK_LABEL (indent_label), GTK_JUSTIFY_LEFT);
+	gtk_box_pack_start(GTK_BOX (hbox), indent_label, FALSE, FALSE, 0);
+		
+	controls_vbox = gtk_vbox_new(FALSE, 10);
+	gtk_box_pack_start(GTK_BOX(hbox), controls_vbox, TRUE, TRUE, 0);
+
+	network_device_hbox = gtk_hbox_new(FALSE, 6);
+	gtk_box_pack_start(GTK_BOX(controls_vbox), network_device_hbox, TRUE, TRUE, 0);
+	
+	network_device_label = gtk_label_new_with_mnemonic(_("Network _device:"));
+	gtk_label_set_justify(GTK_LABEL(network_device_label), GTK_JUSTIFY_LEFT);
+	gtk_misc_set_alignment(GTK_MISC(network_device_label), 0.0f, 0.5f);
+	gtk_size_group_add_widget(category_label_size_group, network_device_label);
+	gtk_box_pack_start(GTK_BOX (network_device_hbox), network_device_label, FALSE, FALSE, 0);
+	
+	priv->network_device_combo = gtk_combo_box_new_text();
+	gtk_label_set_mnemonic_widget(GTK_LABEL(network_device_label), priv->network_device_combo);
+	gtk_box_pack_start (GTK_BOX (network_device_hbox), priv->network_device_combo, TRUE, TRUE, 0);
+
+	priv->show_sum_checkbutton = gtk_check_button_new_with_mnemonic(_("Show _sum instead of in & out"));
+	gtk_box_pack_start(GTK_BOX(controls_vbox), priv->show_sum_checkbutton, FALSE, FALSE, 0);
+	
+	priv->show_bits_checkbutton = gtk_check_button_new_with_mnemonic(_("Show _bits instead of bytes"));
+	gtk_box_pack_start(GTK_BOX(controls_vbox), priv->show_bits_checkbutton, FALSE, FALSE, 0);
+	
+	priv->change_icon_checkbutton = gtk_check_button_new_with_mnemonic(_("Change _icon according to the selected device"));
+	gtk_box_pack_start(GTK_BOX(controls_vbox), priv->change_icon_checkbutton, FALSE, FALSE, 0);
+
+#if 0
+	g_signal_connect(G_OBJECT (priv->network_device_combo), "changed",
+			 G_CALLBACK(device_change_cb), (gpointer)applet);
+
+	g_signal_connect(G_OBJECT (show_sum_checkbutton), "toggled",
+			 G_CALLBACK(showsum_change_cb), (gpointer)applet);
+
+	g_signal_connect(G_OBJECT (show_bits_checkbutton), "toggled",
+			 G_CALLBACK(showbits_change_cb), (gpointer)applet);
+
+	g_signal_connect(G_OBJECT (change_icon_checkbutton), "toggled",
+			 G_CALLBACK(changeicon_change_cb), (gpointer)applet);
+
+	g_signal_connect(G_OBJECT (priv->settings), "response",
+			 G_CALLBACK(pref_response_cb), (gpointer)applet);
+#endif
+
+	gtk_container_add(GTK_CONTAINER (GTK_DIALOG (self)->vbox), vbox);
+}
+
+static void
+settings_dialog_constructed (GObject *object)
+{
+	SettingsDialogPrivate *priv = SETTINGS_DIALOG (object)->priv;
+	gboolean show_sum, show_bits, change_icon, auto_change_device;
+	char *device;
+	GList *ptr, *devices;
+	int i, active = -1;
+
+	g_object_get (priv->settings,
+				"device", &device,
+				"show-sum", &show_sum,
+				"show-bits", &show_bits,
+				"change-icon", &change_icon,
+				"auto-change-device", &auto_change_device,
+				NULL);
+
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->show_sum_checkbutton), show_sum);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->show_bits_checkbutton), show_bits);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->change_icon_checkbutton), change_icon);
+
+	/* Default means device with default route set */
+	gtk_combo_box_append_text(GTK_COMBO_BOX(priv->network_device_combo), _("Default"));
+	ptr = devices = get_available_devices();
+	for (i = 1; ptr; ptr = g_list_next(ptr)) {
+		gtk_combo_box_append_text(GTK_COMBO_BOX(priv->network_device_combo), ptr->data);
+		if (g_str_equal(ptr->data, device)) active = i;
+		++i;
+	}
+	g_object_set_data_full(G_OBJECT(priv->network_device_combo), "devices", devices, (GDestroyNotify)free_devices_list);
+	if (active < 0 || auto_change_device) {
+		active = 0;
+	}
+	gtk_combo_box_set_active(GTK_COMBO_BOX(priv->network_device_combo), active);
+
+	if (G_OBJECT_CLASS (settings_dialog_parent_class)->constructed) {
+		G_OBJECT_CLASS (settings_dialog_parent_class)->constructed (object);
+	}
+}
+
+
+static void
+settings_dialog_set_property (GObject    *object,
+							guint         property_id,
+							const GValue *value,
+							GParamSpec   *pspec)
+{
+	SettingsDialogPrivate *priv = SETTINGS_DIALOG (object)->priv;
+
+	switch (property_id) {
+		case PROP_SETTINGS:
+			priv->settings = g_value_get_object (value);
+			break;
+	}
+}
+
+static void
+settings_dialog_get_property (GObject    *object,
+							guint         property_id,
+							GValue       *value,
+							GParamSpec   *pspec)
+{
+	SettingsDialogPrivate *priv = SETTINGS_DIALOG (object)->priv;
+
+	switch (property_id) {
+		case PROP_SETTINGS:
+			g_value_set_object (value, priv->settings);
+			break;
+	}
+}
+
+static void
+settings_dialog_dispose (GObject *object)
+{
+	SettingsDialogPrivate *priv = SETTINGS_DIALOG (object)->priv;
+
+	if (priv->settings) {
+		g_object_unref (priv->settings);
+		priv->settings = NULL;
+	}
+
+	G_OBJECT_CLASS (settings_dialog_parent_class)->dispose (object);
+}
+
+static void
+settings_dialog_finalize (GObject *object)
+{
+	G_OBJECT_CLASS (settings_dialog_parent_class)->finalize (object);
+}
+
+GtkWidget* settings_dialog_new (Settings *settings)
+{
+	return g_object_new (SETTINGS_DIALOG_TYPE,
+						"settings", settings,
+						"has-separator", FALSE,
+						NULL);
+}
diff --git a/src/settings-dialog.h b/src/settings-dialog.h
new file mode 100644
index 0000000..9214f7f
--- /dev/null
+++ b/src/settings-dialog.h
@@ -0,0 +1,58 @@
+/*  settings-dialog.h
+ *  vim:ts=4:sw=4:noexpandtab:cindent
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *  Netspeed Applet was writen by Jörgen Scheibengruber <mfcn gmx de>
+ */
+
+#ifndef _SETTINGS_DIALOG_H
+#define _SETTINGS_DIALOG_H
+
+#include <gtk/gtk.h>
+#include "settings.h"
+
+G_BEGIN_DECLS
+
+#define SETTINGS_DIALOG_TYPE            (settings_dialog_get_type ())
+#define SETTINGS_DIALOG(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), SETTINGS_DIALOG_TYPE, SettingsDialog))
+#define SETTINGS_DIALOG_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), SETTINGS_DIALOG_TYPE, SettingsDialogClass))
+#define IS_SETTINGS_DIALOG(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SETTINGS_DIALOG_TYPE))
+#define IS_SETTINGS_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SETTINGS_DIALOG_TYPE))
+#define SETTINGS_DIALOG_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), SETTINGS_DIALOG_TYPE, SettingsDialogClass))
+
+typedef struct _SettingsDialog        SettingsDialog;
+typedef struct _SettingsDialogClass   SettingsDialogClass;
+typedef struct _SettingsDialogPrivate SettingsDialogPrivate;
+
+struct _SettingsDialogClass
+{
+	GtkDialogClass parent_class;
+};
+
+struct _SettingsDialog
+{
+	GtkDialog parent;
+	SettingsDialogPrivate *priv;
+	
+};
+
+GType      settings_dialog_get_type (void);
+
+GtkWidget* settings_dialog_new (Settings*);
+
+G_END_DECLS
+
+#endif
diff --git a/src/settings.c b/src/settings.c
new file mode 100644
index 0000000..1664319
--- /dev/null
+++ b/src/settings.c
@@ -0,0 +1,128 @@
+/*  settings.c
+ *  vim:ts=4:sw=4:noexpandtab:cindent
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *  Netspeed Applet was writen by Jörgen Scheibengruber <mfcn gmx de>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include "settings.h"
+
+enum
+{
+	PROP_0,
+	PROP_DEVICE,
+	PROP_SHOW_SUM,
+	PROP_SHOW_BITS,
+	PROP_CHANGE_ICON,
+	PROP_AUTO_CHANGE_DEVICE,
+	PROP_IN_COLOR,
+	PROP_OUT_COLOR,
+	PROP_UP_CMD,
+	PROP_DOWN_CMD
+};
+
+struct _SettingsPrivate
+{
+	char *device;
+};
+
+#define SETTINGS_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE ((o), SETTINGS_TYPE, SettingsPrivate))
+
+static void settings_class_init (SettingsClass *klass);
+static void settings_init       (Settings *self);
+static void settings_finalize   (GObject *object);
+static void settings_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+static void settings_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+
+G_DEFINE_TYPE (Settings, settings, G_TYPE_OBJECT);
+
+static void
+settings_class_init (SettingsClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+	g_type_class_add_private (klass, sizeof (SettingsPrivate));
+
+	object_class->finalize = settings_finalize;
+	object_class->set_property = settings_set_property;
+	object_class->get_property = settings_get_property;
+
+	g_object_class_install_property (object_class, PROP_DEVICE,
+		g_param_spec_string ("device",
+							 "Device",
+							 "The device that is monitored.",
+							 "lo",
+							 G_PARAM_READWRITE));
+}
+
+static void
+settings_init (Settings *self)
+{
+	SettingsPrivate *priv = SETTINGS_GET_PRIVATE (self);
+	self->priv = priv;
+
+	priv->device = g_strdup ("lo");
+}
+
+static void
+settings_set_property (GObject       *object,
+						guint         property_id,
+						const GValue *value,
+						GParamSpec   *pspec)
+{
+	SettingsPrivate *priv = SETTINGS (object)->priv;
+
+	switch (property_id) {
+		case PROP_DEVICE:
+			g_free (priv->device);
+			priv->device = g_value_dup_string (value);
+			break;
+	}
+}
+
+static void
+settings_get_property (GObject       *object,
+						guint         property_id,
+						GValue       *value,
+						GParamSpec   *pspec)
+{
+	SettingsPrivate *priv = SETTINGS (object)->priv;
+
+	switch (property_id) {
+		case PROP_DEVICE:
+			g_value_set_string (value, priv->device);
+			break;
+	}
+}
+
+static void
+settings_finalize (GObject *object)
+{
+	SettingsPrivate *priv = SETTINGS (object)->priv;
+
+	g_free (priv->device);
+
+	G_OBJECT_CLASS (settings_parent_class)->finalize (object);
+}
+
+Settings* settings_new (void)
+{
+	return g_object_new (SETTINGS_TYPE, NULL);
+}
diff --git a/src/settings.h b/src/settings.h
new file mode 100644
index 0000000..5649a15
--- /dev/null
+++ b/src/settings.h
@@ -0,0 +1,57 @@
+/*  settings.h
+ *  vim:ts=4:sw=4:noexpandtab:cindent
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *  Netspeed Applet was writen by Jörgen Scheibengruber <mfcn gmx de>
+ */
+
+#ifndef _SETTINGS_H
+#define _SETTINGS_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define SETTINGS_TYPE            (settings_get_type ())
+#define SETTINGS(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), SETTINGS_TYPE, Settings))
+#define SETTINGS_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), SETTINGS_TYPE, SettingsClass))
+#define IS_SETTINGS(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SETTINGS_TYPE))
+#define IS_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SETTINGS_TYPE))
+#define SETTINGS_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), SETTINGS_TYPE, SettingsClass))
+
+typedef struct _Settings        Settings;
+typedef struct _SettingsClass   SettingsClass;
+typedef struct _SettingsPrivate SettingsPrivate;
+
+struct _SettingsClass
+{
+	GObjectClass parent_class;
+};
+
+struct _Settings
+{
+	GObject parent;
+	SettingsPrivate *priv;
+};
+
+GType     settings_get_type (void);
+
+Settings* settings_new (void);
+
+G_END_DECLS
+
+#endif



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