network-manager-applet r615 - in trunk: . src/connection-editor



Author: dcbw
Date: Wed Mar 26 22:15:53 2008
New Revision: 615
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=615&view=rev

Log:
2008-03-26  Dan Williams  <dcbw redhat com>

	Patch from Tambet Ingo <tambet gmail com>

	* src/connection-editor/ce-page.[ch]: Add a "changed" signal so that the pages
	can tell when they change and the connection editor to notice it.

	* src/connection-editor/nm-connection-editor.c: Listen to the CEPage::changed
	signals, validate them, and update the dialog's "OK" button's sensitivity
	accordingly.
	(nm_connection_editor_run_and_close): Update the connection by iterating over
	all pages and letting each update their own part.

	* src/connection-editor/page-*.c: Add a stub for required "update_connection"
	virtual function.

	* src/connection-editor/page-wireless-security.c (ce_page_wireless_security_new):
	Fix a bug where the default wireless combo box would always be the first item.
	Don't take the "ok_button" argument, it's handled by the framework now.
	(validate): Implement.



Modified:
   trunk/ChangeLog
   trunk/src/connection-editor/ce-page.c
   trunk/src/connection-editor/ce-page.h
   trunk/src/connection-editor/nm-connection-editor.c
   trunk/src/connection-editor/nm-connection-editor.h
   trunk/src/connection-editor/page-dsl.c
   trunk/src/connection-editor/page-ip4-address.c
   trunk/src/connection-editor/page-ip4.c
   trunk/src/connection-editor/page-wired.c
   trunk/src/connection-editor/page-wireless-security.c
   trunk/src/connection-editor/page-wireless-security.h
   trunk/src/connection-editor/page-wireless.c

Modified: trunk/src/connection-editor/ce-page.c
==============================================================================
--- trunk/src/connection-editor/ce-page.c	(original)
+++ trunk/src/connection-editor/ce-page.c	Wed Mar 26 22:15:53 2008
@@ -24,6 +24,14 @@
 
 G_DEFINE_ABSTRACT_TYPE (CEPage, ce_page, G_TYPE_OBJECT)
 
+enum {
+	CHANGED,
+
+	LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
 gboolean
 ce_page_validate (CEPage *self)
 {
@@ -91,6 +99,14 @@
 	return self->title;
 }
 
+void
+ce_page_changed (CEPage *self)
+{
+	g_return_if_fail (CE_IS_PAGE (self));
+
+	g_signal_emit (self, signals[CHANGED], 0);
+}
+
 static void
 ce_page_class_init (CEPageClass *page_class)
 {
@@ -99,5 +115,14 @@
 	/* virtual methods */
 	object_class->dispose     = dispose;
 	object_class->finalize    = finalize;
-}
 
+	/* Signals */
+	signals[CHANGED] = 
+		g_signal_new ("changed",
+					  G_OBJECT_CLASS_TYPE (object_class),
+					  G_SIGNAL_RUN_FIRST,
+					  G_STRUCT_OFFSET (CEPageClass, changed),
+					  NULL, NULL,
+					  g_cclosure_marshal_VOID__VOID,
+					  G_TYPE_NONE, 0);
+}

Modified: trunk/src/connection-editor/ce-page.h
==============================================================================
--- trunk/src/connection-editor/ce-page.h	(original)
+++ trunk/src/connection-editor/ce-page.h	Wed Mar 26 22:15:53 2008
@@ -53,8 +53,10 @@
 
 	/* Virtual functions */
 	gboolean    (*validate)            (CEPage *self);
-
 	void        (*update_connection)   (CEPage *self, NMConnection *connection);
+
+	/* Signals */
+	void        (*changed)             (CEPage *self);
 } CEPageClass;
 
 GType ce_page_get_type (void);
@@ -67,5 +69,7 @@
 
 void ce_page_update_connection (CEPage *self, NMConnection *connection);
 
+void ce_page_changed (CEPage *self);
+
 #endif  /* __CE_PAGE_H__ */
 

Modified: trunk/src/connection-editor/nm-connection-editor.c
==============================================================================
--- trunk/src/connection-editor/nm-connection-editor.c	(original)
+++ trunk/src/connection-editor/nm-connection-editor.c	Wed Mar 26 22:15:53 2008
@@ -159,6 +159,8 @@
 	editor->dialog = glade_xml_get_widget (editor->xml, "NMConnectionEditor");
 	g_signal_connect (G_OBJECT (editor->dialog), "response", G_CALLBACK (dialog_response_cb), editor);
 
+	editor->ok_button = glade_xml_get_widget (editor->xml, "ok_button");
+
 	widget = glade_xml_get_widget (editor->xml, "connection_name");
 	g_signal_connect (G_OBJECT (widget), "changed",
 	                  G_CALLBACK (connection_name_changed), editor);
@@ -255,6 +257,14 @@
 }
 
 static void
+page_changed (CEPage *page, gpointer user_data)
+{
+	NMConnectionEditor *editor = NM_CONNECTION_EDITOR (user_data);
+
+	gtk_widget_set_sensitive (editor->ok_button, ce_page_validate (page));
+}
+
+static void
 add_page (NMConnectionEditor *editor, CEPage *page)
 {
 	GtkWidget *widget;
@@ -266,6 +276,10 @@
 	widget = ce_page_get_page (page);
 	gtk_notebook_append_page (GTK_NOTEBOOK (notebook), widget, label);
 
+	g_signal_connect (page, "changed",
+				   G_CALLBACK (page_changed),
+				   editor);
+
 	editor->pages = g_slist_append (editor->pages, page);
 }
 
@@ -296,13 +310,11 @@
 	} else if (!strcmp (s_con->type, NM_SETTING_WIRELESS_SETTING_NAME)) {
 		CEPageWireless *wireless_page;
 		CEPageWirelessSecurity *wireless_security_page;
-		GtkWidget *ok_button;
 
 		wireless_page = ce_page_wireless_new (editor->connection);
 		add_page (editor, CE_PAGE (wireless_page));
 
-		ok_button = glade_xml_get_widget (editor->xml, "ok_button");
-		wireless_security_page = ce_page_wireless_security_new (editor->connection, ok_button, wireless_page);
+		wireless_security_page = ce_page_wireless_security_new (editor->connection, wireless_page);
 		add_page (editor, CE_PAGE (wireless_security_page));
 
 		add_page (editor, CE_PAGE (ce_page_ip4_address_new (editor->connection)));
@@ -328,6 +340,12 @@
 	gtk_widget_show (editor->dialog);
 }
 
+static void
+update_one_page (gpointer data, gpointer user_data)
+{
+	ce_page_update_connection (CE_PAGE (data), NM_CONNECTION (user_data));
+}
+
 gint
 nm_connection_editor_run_and_close (NMConnectionEditor *editor)
 {
@@ -338,5 +356,13 @@
 	result = gtk_dialog_run (GTK_DIALOG (editor->dialog));
 	gtk_widget_hide (editor->dialog);
 
+	switch (result) {
+	case GTK_RESPONSE_OK:
+		g_slist_foreach (editor->pages, update_one_page, editor->connection);
+		break;
+	default:
+		break;
+	}
+
 	return result;
 }

Modified: trunk/src/connection-editor/nm-connection-editor.h
==============================================================================
--- trunk/src/connection-editor/nm-connection-editor.h	(original)
+++ trunk/src/connection-editor/nm-connection-editor.h	Wed Mar 26 22:15:53 2008
@@ -39,8 +39,9 @@
 	/* private data */
 	NMConnection *connection;
 	GSList *pages;
-	GtkWidget *dialog;
 	GladeXML *xml;
+	GtkWidget *dialog;
+	GtkWidget *ok_button;
 } NMConnectionEditor;
 
 typedef struct {

Modified: trunk/src/connection-editor/page-dsl.c
==============================================================================
--- trunk/src/connection-editor/page-dsl.c	(original)
+++ trunk/src/connection-editor/page-dsl.c	Wed Mar 26 22:15:53 2008
@@ -87,6 +87,12 @@
 }
 
 static void
+update_connection (CEPage *page, NMConnection *connection)
+{
+	g_print ("FIXME: update DSL page\n");
+}
+
+static void
 ce_page_dsl_init (CEPageDsl *self)
 {
 }
@@ -94,5 +100,8 @@
 static void
 ce_page_dsl_class_init (CEPageDslClass *dsl_class)
 {
-}
+	CEPageClass *parent_class = CE_PAGE_CLASS (dsl_class);
 
+	/* virtual methods */
+	parent_class->update_connection = update_connection;
+}

Modified: trunk/src/connection-editor/page-ip4-address.c
==============================================================================
--- trunk/src/connection-editor/page-ip4-address.c	(original)
+++ trunk/src/connection-editor/page-ip4-address.c	Wed Mar 26 22:15:53 2008
@@ -69,6 +69,11 @@
 	return self;
 }
 
+static void
+update_connection (CEPage *page, NMConnection *connection)
+{
+	g_print ("FIXME: update IP4 address page\n");
+}
 
 static void
 ce_page_ip4_address_init (CEPageIP4Address *self)
@@ -78,5 +83,8 @@
 static void
 ce_page_ip4_address_class_init (CEPageIP4AddressClass *ip4_address_class)
 {
-}
+	CEPageClass *parent_class = CE_PAGE_CLASS (ip4_address_class);
 
+	/* virtual methods */
+	parent_class->update_connection = update_connection;
+}

Modified: trunk/src/connection-editor/page-ip4.c
==============================================================================
--- trunk/src/connection-editor/page-ip4.c	(original)
+++ trunk/src/connection-editor/page-ip4.c	Wed Mar 26 22:15:53 2008
@@ -69,6 +69,11 @@
 	return self;
 }
 
+static void
+update_connection (CEPage *page, NMConnection *connection)
+{
+	g_print ("FIXME: update IP4 page\n");
+}
 
 static void
 ce_page_ip4_init (CEPageIP4 *self)
@@ -78,5 +83,8 @@
 static void
 ce_page_ip4_class_init (CEPageIP4Class *ip4_class)
 {
-}
+	CEPageClass *parent_class = CE_PAGE_CLASS (ip4_class);
 
+	/* virtual methods */
+	parent_class->update_connection = update_connection;
+}

Modified: trunk/src/connection-editor/page-wired.c
==============================================================================
--- trunk/src/connection-editor/page-wired.c	(original)
+++ trunk/src/connection-editor/page-wired.c	Wed Mar 26 22:15:53 2008
@@ -131,6 +131,12 @@
 }
 
 static void
+update_connection (CEPage *page, NMConnection *connection)
+{
+	g_print ("FIXME: update wired page\n");
+}
+
+static void
 ce_page_wired_init (CEPageWired *self)
 {
 }
@@ -138,5 +144,8 @@
 static void
 ce_page_wired_class_init (CEPageWiredClass *wired_class)
 {
-}
+	CEPageClass *parent_class = CE_PAGE_CLASS (wired_class);
 
+	/* virtual methods */
+	parent_class->update_connection = update_connection;
+}

Modified: trunk/src/connection-editor/page-wireless-security.c
==============================================================================
--- trunk/src/connection-editor/page-wireless-security.c	(original)
+++ trunk/src/connection-editor/page-wireless-security.c	Wed Mar 26 22:15:53 2008
@@ -95,17 +95,7 @@
 static void
 stuff_changed_cb (WirelessSecurity *sec, gpointer user_data)
 {
-	CEPageWirelessSecurity *self = CE_PAGE_WIRELESS_SECURITY (user_data);
-	GByteArray *ssid = NULL;
-	gboolean valid = FALSE;
-
-	ssid = ce_page_wireless_get_ssid (self->wireless_page);
-	if (ssid) {
-		valid = wireless_security_validate (sec, ssid);
-		g_byte_array_free (ssid, TRUE);
-	}
-
-	gtk_widget_set_sensitive (self->ok_button, valid);
+	ce_page_changed (CE_PAGE (user_data));
 }
 
 static void
@@ -121,16 +111,28 @@
 		gtk_size_group_remove_widget (group, GTK_WIDGET (iter->data));
 }
 
+static WirelessSecurity *
+wireless_security_combo_get_active (CEPageWirelessSecurity *self)
+{
+	GtkTreeIter iter;
+	GtkTreeModel *model;
+	WirelessSecurity *sec = NULL;
+
+	model = gtk_combo_box_get_model (self->security_combo);
+	gtk_combo_box_get_active_iter (self->security_combo, &iter);
+	gtk_tree_model_get (model, &iter, S_SEC_COLUMN, &sec, -1);
+
+	return sec;
+}
+
 static void
-wireless_security_combo_changed (GtkWidget *combo,
+wireless_security_combo_changed (GtkComboBox *combo,
                                  gpointer user_data)
 {
 	CEPageWirelessSecurity *self = CE_PAGE_WIRELESS_SECURITY (user_data);
 	GtkWidget *vbox;
 	GList *elt, *children;
-	GtkTreeIter iter;
-	GtkTreeModel *model;
-	WirelessSecurity *sec = NULL;
+	WirelessSecurity *sec;
 
 	vbox = glade_xml_get_widget (CE_PAGE (self)->xml, "wireless_security_vbox");
 	g_assert (vbox);
@@ -142,9 +144,7 @@
 	for (elt = children; elt; elt = g_list_next (elt))
 		gtk_container_remove (GTK_CONTAINER (vbox), GTK_WIDGET (elt->data));
 
-	model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
-	gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter);
-	gtk_tree_model_get (model, &iter, S_SEC_COLUMN, &sec, -1);
+	sec = wireless_security_combo_get_active (self);
 	if (sec) {
 		GtkWidget *sec_widget;
 		GtkWidget *widget;
@@ -159,6 +159,8 @@
 		gtk_container_add (GTK_CONTAINER (vbox), sec_widget);
 		wireless_security_unref (sec);
 	}
+
+	ce_page_changed (CE_PAGE (self));
 }
 
 static void
@@ -176,7 +178,6 @@
 
 CEPageWirelessSecurity *
 ce_page_wireless_security_new (NMConnection *connection,
-                               GtkWidget *ok_button,
                                CEPageWireless *wireless_page)
 {
 	CEPageWirelessSecurity *self;
@@ -191,7 +192,7 @@
 	int active = -1;
 	int item = 0;
 	const char *glade_file = GLADEDIR "/applet.glade";
-	GtkWidget *combo;
+	GtkComboBox *combo;
 
 	self = CE_PAGE_WIRELESS_SECURITY (g_object_new (CE_TYPE_PAGE_WIRELESS_SECURITY, NULL));
 	parent = CE_PAGE (self);
@@ -223,9 +224,8 @@
 	self->group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
 
 	self->wireless_page = g_object_ref (wireless_page);
-	self->ok_button = g_object_ref (ok_button);
 
-	combo = glade_xml_get_widget (parent->xml, "wireless_security_combo");
+	combo = GTK_COMBO_BOX (glade_xml_get_widget (parent->xml, "wireless_security_combo"));
 
 	dev_caps =   NM_802_11_DEVICE_CAP_CIPHER_WEP40
 	           | NM_802_11_DEVICE_CAP_CIPHER_WEP104
@@ -261,24 +261,27 @@
 		if (ws_wep_passphrase) {
 			add_security_item (self, WIRELESS_SECURITY (ws_wep_passphrase), sec_model,
 			                   &iter, _("WEP 128-bit Passphrase"));
+			item++;
 			if ((active < 0) && (default_type == NMU_SEC_STATIC_WEP))
-				active = item++;
+				active = item;
 		}
 
 		ws_wep_hex = ws_wep_key_new (glade_file, connection, WEP_KEY_TYPE_HEX);
 		if (ws_wep_hex) {
 			add_security_item (self, WIRELESS_SECURITY (ws_wep_hex), sec_model,
 			                   &iter, _("WEP 40/128-bit Hexadecimal"));
+			item++;
 			if ((active < 0) && (default_type == NMU_SEC_STATIC_WEP))
-				active = item++;
+				active = item;
 		}
 
 		ws_wep_ascii = ws_wep_key_new (glade_file, connection, WEP_KEY_TYPE_ASCII);
 		if (ws_wep_ascii) {
 			add_security_item (self, WIRELESS_SECURITY (ws_wep_ascii), sec_model,
 			                   &iter, _("WEP 40/128-bit ASCII"));
+			item++;
 			if ((active < 0) && (default_type == NMU_SEC_STATIC_WEP))
-				active = item++;
+				active = item;
 		}
 	}
 
@@ -289,8 +292,9 @@
 		if (ws_leap) {
 			add_security_item (self, WIRELESS_SECURITY (ws_leap), sec_model,
 			                   &iter, _("LEAP"));
+			item++;
 			if ((active < 0) && (default_type == NMU_SEC_LEAP))
-				active = item++;
+				active = item;
 		}
 	}
 
@@ -301,8 +305,9 @@
 		if (ws_dynamic_wep) {
 			add_security_item (self, WIRELESS_SECURITY (ws_dynamic_wep), sec_model,
 			                   &iter, _("Dynamic WEP (802.1x)"));
+			item++;
 			if ((active < 0) && (default_type == NMU_SEC_DYNAMIC_WEP))
-				active = item++;
+				active = item;
 		}
 	}
 
@@ -314,8 +319,9 @@
 		if (ws_wpa_psk) {
 			add_security_item (self, WIRELESS_SECURITY (ws_wpa_psk), sec_model,
 			                   &iter, _("WPA & WPA2 Personal"));
+			item++;
 			if ((active < 0) && ((default_type == NMU_SEC_WPA_PSK) || (default_type == NMU_SEC_WPA2_PSK)))
-				active = item++;
+				active = item;
 		}
 	}
 
@@ -327,18 +333,20 @@
 		if (ws_wpa_eap) {
 			add_security_item (self, WIRELESS_SECURITY (ws_wpa_eap), sec_model,
 			                   &iter, _("WPA & WPA2 Enterprise"));
+			item++;
 			if ((active < 0) && ((default_type == NMU_SEC_WPA_ENTERPRISE) || (default_type == NMU_SEC_WPA2_ENTERPRISE)))
-				active = item++;
+				active = item;
 		}
 	}
 
-	gtk_combo_box_set_model (GTK_COMBO_BOX (combo), GTK_TREE_MODEL (sec_model));
-	gtk_combo_box_set_active (GTK_COMBO_BOX (combo), active < 0 ? 0 : (guint32) active);
+	gtk_combo_box_set_model (combo, GTK_TREE_MODEL (sec_model));
+	gtk_combo_box_set_active (combo, active < 0 ? 0 : (guint32) active);
 	g_object_unref (G_OBJECT (sec_model));
 
+	self->security_combo = combo;
+
 	wireless_security_combo_changed (combo, self);
-	g_signal_connect (G_OBJECT (combo),
-	                  "changed",
+	g_signal_connect (combo, "changed",
 	                  GTK_SIGNAL_FUNC (wireless_security_combo_changed),
 	                  self);
 
@@ -364,21 +372,49 @@
 	if (self->group)
 		g_object_unref (self->group);
 
-	if (self->ok_button)
-		g_object_unref (self->ok_button);
-
 	if (self->wireless_page)
 		g_object_unref (self->wireless_page);
 
 	G_OBJECT_CLASS (ce_page_wireless_security_parent_class)->dispose (object);
 }
 
+static gboolean
+validate (CEPage *page)
+{
+	CEPageWirelessSecurity *self = CE_PAGE_WIRELESS_SECURITY (page);
+	GByteArray *ssid;
+	WirelessSecurity *sec;
+	gboolean valid = FALSE;
+
+	sec = wireless_security_combo_get_active (self);
+	if (!sec)
+		return FALSE;
+
+	ssid = ce_page_wireless_get_ssid (self->wireless_page);
+	if (ssid) {
+		valid = wireless_security_validate (sec, ssid);
+		g_byte_array_free (ssid, TRUE);
+	}
+
+	return valid;
+}
+
+static void
+update_connection (CEPage *page, NMConnection *connection)
+{
+	g_print ("FIXME: update wireless security page\n");
+}
+
 static void
 ce_page_wireless_security_class_init (CEPageWirelessSecurityClass *wireless_security_class)
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (wireless_security_class);
+	CEPageClass *parent_class = CE_PAGE_CLASS (wireless_security_class);
 
 	/* virtual methods */
 	object_class->dispose = dispose;
+
+	parent_class->validate = validate;
+	parent_class->update_connection = update_connection;
 }
 

Modified: trunk/src/connection-editor/page-wireless-security.h
==============================================================================
--- trunk/src/connection-editor/page-wireless-security.h	(original)
+++ trunk/src/connection-editor/page-wireless-security.h	Wed Mar 26 22:15:53 2008
@@ -29,6 +29,7 @@
 
 #include <glib/gtypes.h>
 #include <glib-object.h>
+#include <gtk/gtk.h>
 
 #include "ce-page.h"
 
@@ -44,7 +45,7 @@
 
 	gboolean disposed;
 	GtkSizeGroup *group;
-	GtkWidget *ok_button;
+	GtkComboBox *security_combo;
 	CEPageWireless *wireless_page;
 } CEPageWirelessSecurity;
 
@@ -55,7 +56,6 @@
 GType ce_page_wireless_security_get_type (void);
 
 CEPageWirelessSecurity *ce_page_wireless_security_new (NMConnection *connection,
-                                                       GtkWidget *ok_button,
                                                        CEPageWireless *wireless_page);
 
 #endif  /* __PAGE_WIRELESS_SECURITY_H__ */

Modified: trunk/src/connection-editor/page-wireless.c
==============================================================================
--- trunk/src/connection-editor/page-wireless.c	(original)
+++ trunk/src/connection-editor/page-wireless.c	Wed Mar 26 22:15:53 2008
@@ -286,12 +286,21 @@
 }
 
 static void
-ce_page_wireless_init (CEPageWireless *self)
+update_connection (CEPage *page, NMConnection *connection)
 {
+	g_print ("FIXME: update wireless page\n");
 }
 
 static void
-ce_page_wireless_class_init (CEPageWirelessClass *wired_class)
+ce_page_wireless_init (CEPageWireless *self)
 {
 }
 
+static void
+ce_page_wireless_class_init (CEPageWirelessClass *wireless_class)
+{
+	CEPageClass *parent_class = CE_PAGE_CLASS (wireless_class);
+
+	/* virtual methods */
+	parent_class->update_connection = update_connection;
+}



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