Mercurial > pidgin.yaz
changeset 27359:c65ad9007e42
In the Network prefs page, always show the auto-detected IP address by
placing it in the text of the auto-IP checkbox instead of the "Public IP"
entry box.
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sat, 04 Jul 2009 04:27:48 +0000 |
parents | df8d6f75535a |
children | c3b1711991fc |
files | pidgin/gtkprefs.c |
diffstat | 1 files changed, 33 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/pidgin/gtkprefs.c Sat Jul 04 04:22:25 2009 +0000 +++ b/pidgin/gtkprefs.c Sat Jul 04 04:27:48 2009 +0000 @@ -28,6 +28,7 @@ #include "pidgin.h" #include "debug.h" +#include "nat-pmp.h" #include "notify.h" #include "prefs.h" #include "proxy.h" @@ -36,7 +37,9 @@ #include "savedstatuses.h" #include "sound.h" #include "sound-theme.h" +#include "stun.h" #include "theme-manager.h" +#include "upnp.h" #include "util.h" #include "network.h" @@ -1747,6 +1750,9 @@ GtkWidget *proxy_button = NULL, *browser_button = NULL; GtkSizeGroup *sg; PurpleProxyInfo *proxy_info = NULL; + const char *ip; + PurpleStunNatDiscovery *stun; + char *auto_ip_text; ret = gtk_vbox_new(FALSE, PIDGIN_HIG_CAT_SPACE); gtk_container_set_border_width (GTK_CONTAINER (ret), PIDGIN_HIG_BORDER); @@ -1777,8 +1783,30 @@ gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); gtk_container_add(GTK_CONTAINER(hbox), label); - auto_ip_checkbox = pidgin_prefs_checkbox(_("_Autodetect IP address"), - "/purple/network/auto_ip", vbox); + /* purple_network_get_my_ip will return the IP that was set by the user with + purple_network_set_public_ip, so make a lookup for the auto-detected IP + ourselves. */ + + /* Check if STUN discovery was already done */ + stun = purple_stun_discover(NULL); + if ((stun != NULL) && (stun->status == PURPLE_STUN_STATUS_DISCOVERED)) { + ip = stun->publicip; + } else { + /* Attempt to get the IP from a NAT device using UPnP */ + ip = purple_upnp_get_public_ip(); + if (ip == NULL) { + /* Attempt to get the IP from a NAT device using NAT-PMP */ + ip = purple_pmp_get_public_ip(); + if (ip == NULL) { + /* Just fetch the IP of the local system */ + ip = purple_network_get_local_system_ip(-1); + } + } + } + + auto_ip_text = g_strdup_printf(_("Use _automatically detected IP address: %s"), ip); + auto_ip_checkbox = pidgin_prefs_checkbox(auto_ip_text, "/purple/network/auto_ip", vbox); + g_free(auto_ip_text); table = gtk_table_new(2, 2, FALSE); gtk_container_set_border_width(GTK_CONTAINER(table), 0); @@ -1797,16 +1825,9 @@ g_signal_connect(G_OBJECT(entry), "changed", G_CALLBACK(network_ip_changed), NULL); - /* - * TODO: This could be better by showing the autodeteced - * IP separately from the user-specified IP. - */ - if (purple_network_get_my_ip(-1) != NULL) - gtk_entry_set_text(GTK_ENTRY(entry), - purple_network_get_my_ip(-1)); - - pidgin_set_accessible_label (entry, label); - + gtk_entry_set_text(GTK_ENTRY(entry), purple_network_get_public_ip()); + + pidgin_set_accessible_label(entry, label); if (purple_prefs_get_bool("/purple/network/auto_ip")) { gtk_widget_set_sensitive(GTK_WIDGET(table), FALSE);