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



Author: tambeti
Date: Thu Apr 10 08:52:17 2008
New Revision: 663
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=663&view=rev

Log:
2008-04-09  Tambet Ingo  <tambet gmail com>

	* src/connection-editor/page-dsl.c: Finish the implemention to load, validate,
	and save.

	* src/connection-editor/ce-page-dsl.glade: Add "Show Password" checkbox.
	Remove "invisible_char" properties.


Modified:
   trunk/ChangeLog
   trunk/src/connection-editor/ce-page-dsl.glade
   trunk/src/connection-editor/page-dsl.c

Modified: trunk/src/connection-editor/ce-page-dsl.glade
==============================================================================
--- trunk/src/connection-editor/ce-page-dsl.glade	(original)
+++ trunk/src/connection-editor/ce-page-dsl.glade	Thu Apr 10 08:52:17 2008
@@ -22,7 +22,7 @@
     <widget class="GtkTable" id="DslPage">
       <property name="border_width">12</property>
       <property name="visible">True</property>
-      <property name="n_rows">3</property>
+      <property name="n_rows">4</property>
       <property name="n_columns">2</property>
       <property name="homogeneous">False</property>
       <property name="row_spacing">6</property>
@@ -41,6 +41,7 @@
 	  <property name="yalign">0.5</property>
 	  <property name="xpad">0</property>
 	  <property name="ypad">0</property>
+	  <property name="mnemonic_widget">dsl_username</property>
 	  <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
 	  <property name="width_chars">-1</property>
 	  <property name="single_line_mode">False</property>
@@ -57,10 +58,50 @@
       </child>
 
       <child>
-	<widget class="GtkLabel" id="label25">
+	<widget class="GtkEntry" id="dsl_username">
 	  <property name="visible">True</property>
-	  <property name="label" translatable="yes">Password:</property>
-	  <property name="use_underline">True</property>
+	  <property name="can_focus">True</property>
+	  <property name="editable">True</property>
+	  <property name="visibility">True</property>
+	  <property name="max_length">0</property>
+	  <property name="text" translatable="yes"></property>
+	  <property name="has_frame">True</property>
+	  <property name="activates_default">False</property>
+	</widget>
+	<packing>
+	  <property name="left_attach">1</property>
+	  <property name="right_attach">2</property>
+	  <property name="top_attach">0</property>
+	  <property name="bottom_attach">1</property>
+	  <property name="y_options"></property>
+	</packing>
+      </child>
+
+      <child>
+	<widget class="GtkEntry" id="dsl_service">
+	  <property name="visible">True</property>
+	  <property name="can_focus">True</property>
+	  <property name="editable">True</property>
+	  <property name="visibility">True</property>
+	  <property name="max_length">0</property>
+	  <property name="text" translatable="yes"></property>
+	  <property name="has_frame">True</property>
+	  <property name="activates_default">False</property>
+	</widget>
+	<packing>
+	  <property name="left_attach">1</property>
+	  <property name="right_attach">2</property>
+	  <property name="top_attach">1</property>
+	  <property name="bottom_attach">2</property>
+	  <property name="y_options"></property>
+	</packing>
+      </child>
+
+      <child>
+	<widget class="GtkLabel" id="label26">
+	  <property name="visible">True</property>
+	  <property name="label" translatable="yes">Service:</property>
+	  <property name="use_underline">False</property>
 	  <property name="use_markup">False</property>
 	  <property name="justify">GTK_JUSTIFY_LEFT</property>
 	  <property name="wrap">False</property>
@@ -85,22 +126,23 @@
       </child>
 
       <child>
-	<widget class="GtkEntry" id="dsl_username">
+	<widget class="GtkCheckButton" id="dsl_show_password">
 	  <property name="visible">True</property>
 	  <property name="can_focus">True</property>
-	  <property name="editable">True</property>
-	  <property name="visibility">True</property>
-	  <property name="max_length">0</property>
-	  <property name="text" translatable="yes"></property>
-	  <property name="has_frame">True</property>
-	  <property name="invisible_char">â</property>
-	  <property name="activates_default">False</property>
+	  <property name="label" translatable="yes">Show password</property>
+	  <property name="use_underline">True</property>
+	  <property name="relief">GTK_RELIEF_NORMAL</property>
+	  <property name="focus_on_click">True</property>
+	  <property name="active">False</property>
+	  <property name="inconsistent">False</property>
+	  <property name="draw_indicator">True</property>
 	</widget>
 	<packing>
 	  <property name="left_attach">1</property>
 	  <property name="right_attach">2</property>
-	  <property name="top_attach">0</property>
-	  <property name="bottom_attach">1</property>
+	  <property name="top_attach">3</property>
+	  <property name="bottom_attach">4</property>
+	  <property name="x_options">fill</property>
 	  <property name="y_options"></property>
 	</packing>
       </child>
@@ -114,23 +156,22 @@
 	  <property name="max_length">0</property>
 	  <property name="text" translatable="yes"></property>
 	  <property name="has_frame">True</property>
-	  <property name="invisible_char">â</property>
 	  <property name="activates_default">False</property>
 	</widget>
 	<packing>
 	  <property name="left_attach">1</property>
 	  <property name="right_attach">2</property>
-	  <property name="top_attach">1</property>
-	  <property name="bottom_attach">2</property>
+	  <property name="top_attach">2</property>
+	  <property name="bottom_attach">3</property>
 	  <property name="y_options"></property>
 	</packing>
       </child>
 
       <child>
-	<widget class="GtkLabel" id="label26">
+	<widget class="GtkLabel" id="label25">
 	  <property name="visible">True</property>
-	  <property name="label" translatable="yes">Service:</property>
-	  <property name="use_underline">False</property>
+	  <property name="label" translatable="yes">Password:</property>
+	  <property name="use_underline">True</property>
 	  <property name="use_markup">False</property>
 	  <property name="justify">GTK_JUSTIFY_LEFT</property>
 	  <property name="wrap">False</property>
@@ -139,6 +180,7 @@
 	  <property name="yalign">0.5</property>
 	  <property name="xpad">0</property>
 	  <property name="ypad">0</property>
+	  <property name="mnemonic_widget">dsl_service</property>
 	  <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
 	  <property name="width_chars">-1</property>
 	  <property name="single_line_mode">False</property>
@@ -155,22 +197,29 @@
       </child>
 
       <child>
-	<widget class="GtkEntry" id="dsl_service">
+	<widget class="GtkLabel" id="label27">
 	  <property name="visible">True</property>
-	  <property name="can_focus">True</property>
-	  <property name="editable">True</property>
-	  <property name="visibility">True</property>
-	  <property name="max_length">0</property>
-	  <property name="text" translatable="yes"></property>
-	  <property name="has_frame">True</property>
-	  <property name="invisible_char">â</property>
-	  <property name="activates_default">False</property>
+	  <property name="label" translatable="yes"></property>
+	  <property name="use_underline">False</property>
+	  <property name="use_markup">False</property>
+	  <property name="justify">GTK_JUSTIFY_LEFT</property>
+	  <property name="wrap">False</property>
+	  <property name="selectable">False</property>
+	  <property name="xalign">0</property>
+	  <property name="yalign">0.5</property>
+	  <property name="xpad">0</property>
+	  <property name="ypad">0</property>
+	  <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+	  <property name="width_chars">-1</property>
+	  <property name="single_line_mode">False</property>
+	  <property name="angle">0</property>
 	</widget>
 	<packing>
-	  <property name="left_attach">1</property>
-	  <property name="right_attach">2</property>
-	  <property name="top_attach">2</property>
-	  <property name="bottom_attach">3</property>
+	  <property name="left_attach">0</property>
+	  <property name="right_attach">1</property>
+	  <property name="top_attach">3</property>
+	  <property name="bottom_attach">4</property>
+	  <property name="x_options">fill</property>
 	  <property name="y_options"></property>
 	</packing>
       </child>

Modified: trunk/src/connection-editor/page-dsl.c
==============================================================================
--- trunk/src/connection-editor/page-dsl.c	(original)
+++ trunk/src/connection-editor/page-dsl.c	Thu Apr 10 08:52:17 2008
@@ -33,24 +33,72 @@
 
 G_DEFINE_TYPE (CEPageDsl, ce_page_dsl, CE_TYPE_PAGE)
 
+#define CE_PAGE_DSL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CE_TYPE_PAGE_DSL, CEPageDslPrivate))
+
+typedef struct {
+	NMSettingPPPOE *setting;
+
+	GtkEntry *username;
+	GtkEntry *password;
+	GtkEntry *service;
+
+	gboolean disposed;
+} CEPageDslPrivate;
+
+static void
+dsl_private_init (CEPageDsl *self)
+{
+	CEPageDslPrivate *priv = CE_PAGE_DSL_GET_PRIVATE (self);
+	GladeXML *xml;
+
+	xml = CE_PAGE (self)->xml;
+
+	priv->username = GTK_ENTRY (glade_xml_get_widget (xml, "dsl_username"));
+	priv->password = GTK_ENTRY (glade_xml_get_widget (xml, "dsl_password"));
+	priv->service = GTK_ENTRY (glade_xml_get_widget (xml, "dsl_service"));
+}
+
+static void
+populate_ui (CEPageDsl *self)
+{
+	CEPageDslPrivate *priv = CE_PAGE_DSL_GET_PRIVATE (self);
+	NMSettingPPPOE *setting = priv->setting;
+
+	if (setting->username)
+		gtk_entry_set_text (priv->username, setting->username);
+
+	if (setting->password)
+		gtk_entry_set_text (priv->password, setting->password);
+
+	if (setting->service)
+		gtk_entry_set_text (priv->service, setting->service);
+}
+
+static void
+stuff_changed (GtkEditable *editable, gpointer user_data)
+{
+	ce_page_changed (CE_PAGE (user_data));
+}
+
+static void
+show_password (GtkToggleButton *button, gpointer user_data)
+{
+	CEPageDslPrivate *priv = CE_PAGE_DSL_GET_PRIVATE (user_data);
+
+	gtk_entry_set_visibility (priv->password, gtk_toggle_button_get_active (button));
+}
+
 CEPageDsl *
 ce_page_dsl_new (NMConnection *connection)
 {
 	CEPageDsl *self;
+	CEPageDslPrivate *priv;
 	CEPage *parent;
 	NMSettingPPPOE *s_pppoe;
-	GtkWidget *w;
 
 	self = CE_PAGE_DSL (g_object_new (CE_TYPE_PAGE_DSL, NULL));
 	parent = CE_PAGE (self);
 
-	s_pppoe = NM_SETTING_PPPOE (nm_connection_get_setting (connection, NM_TYPE_SETTING_PPPOE));
-	if (!s_pppoe) {
-		g_warning ("%s: Connection didn't have a PPPOE setting!", __func__);
-		g_object_unref (self);
-		return NULL;
-	}
-
 	parent->xml = glade_xml_new (GLADEDIR "/ce-page-dsl.glade", "DslPage", NULL);
 	if (!parent->xml) {
 		g_warning ("%s: Couldn't load dsl page glade file.", __func__);
@@ -68,28 +116,79 @@
 
 	parent->title = g_strdup (_("DSL"));
 
-	if (s_pppoe->username) {
-		w = glade_xml_get_widget (parent->xml, "dsl_username");
-		gtk_entry_set_text (GTK_ENTRY (w), s_pppoe->username);
-	}
+	dsl_private_init (self);
+	priv = CE_PAGE_DSL_GET_PRIVATE (self);
 
-	if (s_pppoe->password) {
-		w = glade_xml_get_widget (parent->xml, "dsl_password");
-		gtk_entry_set_text (GTK_ENTRY (w), s_pppoe->password);
-	}
+	s_pppoe = (NMSettingPPPOE *) nm_connection_get_setting (connection, NM_TYPE_SETTING_PPPOE);
+	if (s_pppoe) {
+		/* Duplicate it */
+		/* FIXME: Implement nm_setting_dup () in nm-setting.[ch] maybe? */
+		GHashTable *hash;
+
+		hash = nm_setting_to_hash (NM_SETTING (s_pppoe));
+		priv->setting = NM_SETTING_PPPOE (nm_setting_from_hash (NM_TYPE_SETTING_PPPOE, hash));
+		g_hash_table_destroy (hash);
+	} else
+		priv->setting = NM_SETTING_PPPOE (nm_setting_pppoe_new ());
+
+	populate_ui (self);
+
+	g_signal_connect (priv->username, "changed", G_CALLBACK (stuff_changed), self);
+	g_signal_connect (priv->password, "changed", G_CALLBACK (stuff_changed), self);
+	g_signal_connect (priv->service, "changed", G_CALLBACK (stuff_changed), self);
 
-	if (s_pppoe->service) {
-		w = glade_xml_get_widget (parent->xml, "dsl_service");
-		gtk_entry_set_text (GTK_ENTRY (w), s_pppoe->service);
-	}
+	g_signal_connect (glade_xml_get_widget (parent->xml, "dsl_show_password"), "toggled",
+					  G_CALLBACK (show_password), self);
 
 	return self;
 }
 
 static void
+ui_to_setting (CEPageDsl *self)
+{
+	CEPageDslPrivate *priv = CE_PAGE_DSL_GET_PRIVATE (self);
+	const char *username;
+	const char *password;
+	const char *service;
+
+	username = gtk_entry_get_text (priv->username);
+	if (username && strlen (username) < 1)
+		username = NULL;
+
+	password = gtk_entry_get_text (priv->password);
+	if (password && strlen (password) < 1)
+		password = NULL;
+
+	service = gtk_entry_get_text (priv->service);
+	if (service && strlen (service) < 1)
+		service = NULL;
+
+	g_object_set (priv->setting,
+				  NM_SETTING_PPPOE_USERNAME, username,
+				  NM_SETTING_PPPOE_PASSWORD, password,
+				  NM_SETTING_PPPOE_SERVICE, service,
+				  NULL);
+}
+
+static gboolean
+validate (CEPage *page)
+{
+	CEPageDsl *self = CE_PAGE_DSL (page);
+	CEPageDslPrivate *priv = CE_PAGE_DSL_GET_PRIVATE (self);
+
+	ui_to_setting (self);
+	return nm_setting_verify (NM_SETTING (priv->setting), NULL);
+}
+
+static void
 update_connection (CEPage *page, NMConnection *connection)
 {
-	g_print ("FIXME: update DSL page\n");
+	CEPageDsl *self = CE_PAGE_DSL (page);
+	CEPageDslPrivate *priv = CE_PAGE_DSL_GET_PRIVATE (self);
+
+	ui_to_setting (self);
+	g_object_ref (priv->setting); /* Add setting steals the reference. */
+	nm_connection_add_setting (connection, NM_SETTING (priv->setting));
 }
 
 static void
@@ -98,10 +197,30 @@
 }
 
 static void
+dispose (GObject *object)
+{
+	CEPageDslPrivate *priv = CE_PAGE_DSL_GET_PRIVATE (object);
+
+	if (priv->disposed)
+		return;
+
+	priv->disposed = TRUE;
+	g_object_unref (priv->setting);
+
+	G_OBJECT_CLASS (ce_page_dsl_parent_class)->dispose (object);
+}
+
+static void
 ce_page_dsl_class_init (CEPageDslClass *dsl_class)
 {
+	GObjectClass *object_class = G_OBJECT_CLASS (dsl_class);
 	CEPageClass *parent_class = CE_PAGE_CLASS (dsl_class);
 
+	g_type_class_add_private (object_class, sizeof (CEPageDslPrivate));
+
 	/* virtual methods */
+	object_class->dispose = dispose;
+
+	parent_class->validate = validate;
 	parent_class->update_connection = update_connection;
 }



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