# HG changeset patch # User Elliott Sales de Andrade # Date 1246591808 0 # Node ID 5b20267a61d3a63c6db5ec378c19d92a36cc3f70 # Parent 13d0a8097a94361040c1b283848f664acf42bb15 Change the background of the IP address input in the Network preferences to green or red depending on if the address is valid or not. diff -r 13d0a8097a94 -r 5b20267a61d3 pidgin/gtkprefs.c --- a/pidgin/gtkprefs.c Fri Jul 03 02:21:42 2009 +0000 +++ b/pidgin/gtkprefs.c Fri Jul 03 03:30:08 2009 +0000 @@ -1636,15 +1636,82 @@ return ret; } +/* This isn't a very strict check, but should give the user a clue. */ +static gboolean +verify_ip_address(const gchar *text) +{ + char *tmp; + long octet; + + if (!text && !isdigit(*text)) + return FALSE; + + tmp = NULL; + octet = strtol(text, &tmp, 10); + if (octet < 0 || octet > 255) + return FALSE; + + if (!tmp || *tmp != '.') + return FALSE; + + text = tmp + 1; + if (!isdigit(*text)) + return FALSE; + + tmp = NULL; + octet = strtol(text, &tmp, 10); + if (octet < 0 || octet > 255) + return FALSE; + + if (!tmp || *tmp != '.') + return FALSE; + + text = tmp + 1; + if (!isdigit(*text)) + return FALSE; + + tmp = NULL; + octet = strtol(text, &tmp, 10); + if (octet < 0 || octet > 255) + return FALSE; + + text = tmp + 1; + if (!isdigit(*text)) + return FALSE; + + tmp = NULL; + octet = strtol(text, &tmp, 10); + if (octet < 0 || octet > 255) + return FALSE; + + if (!tmp || *tmp != '\0') + return FALSE; + + return TRUE; +} + static void network_ip_changed(GtkEntry *entry, gpointer data) { - /* - * TODO: It would be nice if we could validate this and show a - * red background in the box when the IP address is invalid - * and a green background when the IP address is valid. - */ - purple_network_set_public_ip(gtk_entry_get_text(entry)); + const gchar *text = gtk_entry_get_text(entry); + GdkColor color; + + if (verify_ip_address(text)) + { + color.red = 0xAFFF; + color.green = 0xFFFF; + color.blue = 0xAFFF; + + purple_network_set_public_ip(text); + } + else + { + color.red = 0xFFFF; + color.green = 0xAFFF; + color.blue = 0xAFFF; + } + + gtk_widget_modify_base(GTK_WIDGET(entry), GTK_STATE_NORMAL, &color); } static gboolean