Disable Login button until valid data is enetered [PATCH]



as in panel-applet/NMWirelessAppletOtherNetworkDialog.c, this patch
disables the Login button in
info-daemon/NetworkManagerInfoPassphraseDialog.c
until a possible passphrase/key is entered.

j
Index: info-daemon/NetworkManagerInfoPassphraseDialog.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/info-daemon/NetworkManagerInfoPassphraseDialog.c,v
retrieving revision 1.9
diff -u -r1.9 NetworkManagerInfoPassphraseDialog.c
--- info-daemon/NetworkManagerInfoPassphraseDialog.c	3 Nov 2004 17:06:31 -0000	1.9
+++ info-daemon/NetworkManagerInfoPassphraseDialog.c	10 Nov 2004 03:00:32 -0000
@@ -46,6 +46,39 @@
 	KEY_TYPE_HEX_KEY = 2
 };
 
+static void update_button_cb (GtkWidget *widget, GladeXML *xml)
+{
+	gboolean		 enable = TRUE;
+
+	g_return_if_fail (xml != NULL);
+
+	GtkButton	*button = GTK_BUTTON (glade_xml_get_widget (xml, "login_button"));
+	GtkComboBox	*combo = GTK_COMBO_BOX (glade_xml_get_widget (xml, "key_type_combo"));
+	GtkEntry	*passphrase_entry = GTK_ENTRY (glade_xml_get_widget (xml, "passphrase_entry"));
+	const char	*passphrase_text = gtk_entry_get_text (passphrase_entry);
+
+	if (passphrase_text[0] == '\000')
+		enable = FALSE;
+	else
+	{
+		int combo_choice = gtk_combo_box_get_active (combo);
+		switch (combo_choice)
+		{
+			case KEY_TYPE_ASCII_KEY:
+				if ((strlen (passphrase_text) != 5) && (strlen (passphrase_text) != 13))
+					enable = FALSE;
+				break;
+			case KEY_TYPE_HEX_KEY:
+				if ((strlen (passphrase_text) != 10) && (strlen (passphrase_text) != 26))
+					enable = FALSE;
+				break;
+			default:
+				break;
+		}
+	}		
+
+	gtk_widget_set_sensitive (GTK_WIDGET (button), enable);
+}
 
 /*
  * nmi_passphrase_dialog_clear
@@ -296,6 +329,8 @@
 
 	entry = GTK_ENTRY (glade_xml_get_widget (info->passphrase_dialog, "passphrase_entry"));
 	nmi_passphrase_dialog_clear (dialog, GTK_WIDGET (entry));
+	gtk_widget_set_sensitive (GTK_WIDGET (ok_button), FALSE);
+	g_signal_connect (entry, "changed", G_CALLBACK (update_button_cb), info->passphrase_dialog);
 
 	key_type_combo = GTK_COMBO_BOX (glade_xml_get_widget (info->passphrase_dialog, "key_type_combo"));
 	gtk_combo_box_set_active (key_type_combo, 0);


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