[network-manager-applet/NMA_0_8] mobile-wizard: filter APN entry characters



commit 7a3d1e052dd50b0c2070096ba41eef36913eaf30
Author: Dan Williams <dcbw redhat com>
Date:   Tue May 17 11:19:28 2011 -0500

    mobile-wizard: filter APN entry characters
    
    The ETSI specs state that valid characters are only ASCII alphanumeric
    characters, but then state that APNs should generally follow DNS
    naming rules.  Well, that means a lot more characters are allowed,
    but modems don't like many of them.  So let's slowly allow more
    characters as people find ones that actually are used.  The restriction
    was originally put in place to disallow spaces, because they
    certainly aren't allowed APN characters and modems and the
    network puke when they see spaces.

 src/utils/mobile-wizard.c |   37 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 36 insertions(+), 1 deletions(-)
---
diff --git a/src/utils/mobile-wizard.c b/src/utils/mobile-wizard.c
index 8e96f57..0a3ba9c 100644
--- a/src/utils/mobile-wizard.c
+++ b/src/utils/mobile-wizard.c
@@ -21,6 +21,7 @@
  */
 
 #include <stdlib.h>
+#include <ctype.h>
 
 #include <glib.h>
 #include <glib/gi18n.h>
@@ -425,6 +426,39 @@ plan_row_separator_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
 }
 
 static void
+apn_filter_cb (GtkEntry *   entry,
+               const gchar *text,
+               gint         length,
+               gint *       position,
+               gpointer     user_data)
+{
+	GtkEditable *editable = GTK_EDITABLE (entry);
+	int i, count = 0;
+	gchar *result = g_new0 (gchar, length);
+
+	for (i = 0; i < length; i++) {
+		if (   isalnum (text[i])
+		    || (text[i] == '.')
+		    || (text[i] == '_')
+		    || (text[i] == '-'))
+			result[count++] = text[i];
+	}
+
+	if (count > 0) {
+		g_signal_handlers_block_by_func (G_OBJECT (editable),
+		                                 G_CALLBACK (apn_filter_cb),
+		                                 user_data);
+		gtk_editable_insert_text (editable, result, count, position);
+		g_signal_handlers_unblock_by_func (G_OBJECT (editable),
+		                                   G_CALLBACK (apn_filter_cb),
+		                                   user_data);
+	}
+
+	g_signal_stop_emission_by_name (G_OBJECT (editable), "insert-text");
+	g_free (result);
+}
+
+static void
 plan_setup (MobileWizard *self)
 {
 	GtkWidget *vbox, *label, *alignment, *hbox, *image;
@@ -463,7 +497,8 @@ plan_setup (MobileWizard *self)
 
 	self->plan_unlisted_entry = gtk_entry_new ();
 	gtk_label_set_mnemonic_widget (GTK_LABEL (label), self->plan_unlisted_entry);
-	gtk_entry_set_max_length (GTK_ENTRY (self->plan_unlisted_entry), 40);
+	gtk_entry_set_max_length (GTK_ENTRY (self->plan_unlisted_entry), 64);
+	g_signal_connect (self->plan_unlisted_entry, "insert-text", G_CALLBACK (apn_filter_cb), self);
 	g_signal_connect_swapped (self->plan_unlisted_entry, "changed", G_CALLBACK (plan_update_complete), self);
 
 	alignment = gtk_alignment_new (0, 0.5, 0.5, 0);



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