diff options
author | Anshul Fadnavis <afadnavis@nvidia.com> | 2017-06-28 21:46:04 -0700 |
---|---|---|
committer | Aaron Plattner <aplattner@nvidia.com> | 2017-07-24 10:19:12 -0700 |
commit | 05df8bb3b28fe2d8e73d0d56ba57299fcd41a427 (patch) | |
tree | dbb8979320699781fff00ece94f3e29a6d79dc86 | |
parent | 1ea1f57b1eb23b972efaa1a313c60e7c4c461e1c (diff) |
Adding text control checks for the GTK widgets on the Manage License page in nvidia-settings
Through this change:
1. Server Address fields will not allow entry of whitespace characters.
2. Port Number fields will only allow entry of digits.
-rw-r--r-- | src/gtk+-2.x/ctkgridlicense.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/gtk+-2.x/ctkgridlicense.c b/src/gtk+-2.x/ctkgridlicense.c index 9bda9ff..6124f80 100644 --- a/src/gtk+-2.x/ctkgridlicense.c +++ b/src/gtk+-2.x/ctkgridlicense.c @@ -100,6 +100,8 @@ static void ctk_manage_grid_license_finalize(GObject *object); static void ctk_manage_grid_license_class_init(CtkManageGridLicenseClass *); static void dbusClose(DbusData *dbusData); static gboolean checkConfigfile(gboolean *writable); +static gboolean disallow_whitespace(GtkWidget *widget, GdkEvent *event, gpointer user_data); +static gboolean allow_digits(GtkWidget *widget, GdkEvent *event, gpointer user_data); GType ctk_manage_grid_license_get_type(void) { @@ -888,6 +890,35 @@ static void license_edition_toggled(GtkWidget *widget, gpointer user_data) "%s", licenseState); } +static gboolean disallow_whitespace(GtkWidget *widget, GdkEvent *event, gpointer user_data) +{ + GdkEventKey *key_event; + + if (event->type == GDK_KEY_PRESS) { + key_event = (GdkEventKey *) event; + + if (isspace(key_event->keyval)) { + return TRUE; + } + } + + return FALSE; +} + +static gboolean allow_digits(GtkWidget *widget, GdkEvent *event, gpointer user_data) +{ + GdkEventKey *key_event; + + if (event->type == GDK_KEY_PRESS) { + key_event = (GdkEventKey *) event; + + if (isdigit(key_event->keyval)) { + return FALSE; + } + } + + return TRUE; +} static gboolean checkConfigfile(gboolean *writable) { @@ -1189,6 +1220,9 @@ GtkWidget* ctk_manage_grid_license_new(CtrlTarget *target, gtk_box_pack_start(GTK_BOX(hbox), eventbox, FALSE, TRUE, 0); gtk_table_attach(GTK_TABLE(table), hbox, 0, 1, 1, 2, GTK_FILL, GTK_FILL | GTK_EXPAND, 0, 0); + g_signal_connect(GTK_ENTRY(ctk_manage_grid_license->txt_server_address), "key-press-event", + G_CALLBACK(disallow_whitespace), + (gpointer) ctk_manage_grid_license); /* value */ hbox = gtk_hbox_new(FALSE, 0); @@ -1219,6 +1253,9 @@ GtkWidget* ctk_manage_grid_license_new(CtrlTarget *target, FALSE, FALSE, 0); gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 2, 3, GTK_FILL, GTK_FILL | GTK_EXPAND, 5, 0); + g_signal_connect(GTK_ENTRY(ctk_manage_grid_license->txt_server_port), "key-press-event", + G_CALLBACK(allow_digits), + (gpointer) ctk_manage_grid_license); /* Backup Server Address */ label = gtk_label_new("Secondary Server:"); @@ -1233,6 +1270,9 @@ GtkWidget* ctk_manage_grid_license_new(CtrlTarget *target, gtk_box_pack_start(GTK_BOX(hbox), eventbox, FALSE, TRUE, 0); gtk_table_attach(GTK_TABLE(table), hbox, 0, 1, 5, 6, GTK_FILL, GTK_FILL | GTK_EXPAND, 0, 0); + g_signal_connect(GTK_ENTRY(ctk_manage_grid_license->txt_secondary_server_address), "key-press-event", + G_CALLBACK(disallow_whitespace), + (gpointer) ctk_manage_grid_license); /* value */ hbox = gtk_hbox_new(FALSE, 0); @@ -1263,6 +1303,9 @@ GtkWidget* ctk_manage_grid_license_new(CtrlTarget *target, FALSE, FALSE, 0); gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 6, 7, GTK_FILL, GTK_FILL | GTK_EXPAND, 5, 0); + g_signal_connect(GTK_ENTRY(ctk_manage_grid_license->txt_secondary_server_port), "key-press-event", + G_CALLBACK(allow_digits), + (gpointer) ctk_manage_grid_license); ctk_manage_grid_license->box_server_info = vbox2; /* Apply button */ |