pidgin: aed601f2: In the Network prefs page, always show t...

qulogic at pidgin.im qulogic at pidgin.im
Sat Jul 4 00:31:21 EDT 2009


-----------------------------------------------------------------
Revision: aed601f22fca91705bab1c3dd963575547419e64
Ancestor: 3a68abca93e8d2c768fac191dfe7ce49e63e7cbc
Author: qulogic at pidgin.im
Date: 2009-07-04T04:27:48
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/aed601f22fca91705bab1c3dd963575547419e64

Modified files:
        pidgin/gtkprefs.c

ChangeLog: 

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.

-------------- next part --------------
============================================================
--- pidgin/gtkprefs.c	0623f40ef64143d6f5566827c5247bf3cc47323f
+++ pidgin/gtkprefs.c	434fffb7e20211f3d8fe3e9edcc498c46e6c4f60
@@ -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 @@ network_page(void)
 	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,9 +1783,31 @@ network_page(void)
 	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);
 	gtk_table_set_col_spacings(GTK_TABLE(table), 5);
@@ -1797,17 +1825,10 @@ network_page(void)
 	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));
+	gtk_entry_set_text(GTK_ENTRY(entry), purple_network_get_public_ip());
 
-	pidgin_set_accessible_label (entry, label);
+	pidgin_set_accessible_label(entry, label);
 
-
 	if (purple_prefs_get_bool("/purple/network/auto_ip")) {
 		gtk_widget_set_sensitive(GTK_WIDGET(table), FALSE);
 	}


More information about the Commits mailing list