# HG changeset patch
# Node ID e78c08f95ba4
# Parent  46c68d8a7c56
diff --git a/libpurple/network.c b/libpurple/network.c
--- a/libpurple/network.c
+++ b/libpurple/network.c
@@ -29,6 +29,7 @@
 # include <nspapi.h>
 #endif
 
+#include "core.h"
 #include "debug.h"
 #include "network.h"
 #include "prefs.h"
@@ -39,17 +40,30 @@ static gboolean force_online = FALSE;
 void
 purple_network_set_public_ip(const char *ip)
 {
+	GSettings *settings = NULL;
+
 	g_return_if_fail(ip != NULL);
 
 	/* XXX - Ensure the IP address is valid */
 
-	purple_prefs_set_string("/purple/network/public_ip", ip);
+	settings = g_settings_new_with_backend("im.pidgin.Purple.Network.IP",
+	                                       purple_core_get_settings_backend());
+	g_settings_set_string(settings, "address", ip);
+	g_object_unref(settings);
 }
 
-const char *
+char *
 purple_network_get_public_ip(void)
 {
-	return purple_prefs_get_string("/purple/network/public_ip");
+	GSettings *settings = NULL;
+	char *ip = NULL;
+
+	settings = g_settings_new_with_backend("im.pidgin.Purple.Network.IP",
+	                                       purple_core_get_settings_backend());
+	ip = g_settings_get_string(settings, "address");
+	g_object_unref(settings);
+
+	return ip;
 }
 
 static gchar *
@@ -98,32 +112,49 @@ purple_network_is_ipv4(const gchar *host
 void
 purple_network_discover_my_ip(void)
 {
-	const char *ip = NULL;
+	GSettings *settings = NULL;
+
+	settings = g_settings_new_with_backend("im.pidgin.Purple.Network.IP",
+	                                       purple_core_get_settings_backend());
 
 	/* Check if the user specified an IP manually */
-	if (!purple_prefs_get_bool("/purple/network/auto_ip")) {
-		ip = purple_network_get_public_ip();
+	if(!g_settings_get_boolean(settings, "autodetect")) {
+		char *ip = purple_network_get_public_ip();
 		/* Make sure the IP address entered by the user is valid */
 		if (ip != NULL && purple_network_is_ipv4(ip)) {
+			g_free(ip);
+			g_clear_object(&settings);
 			return;
 		}
+		g_free(ip);
 	}
+
+	/* TODO: Actually discover the IP address. */
+
+	g_clear_object(&settings);
 }
 
 gchar *
 purple_network_get_my_ip_from_gio(GSocketConnection *sockconn)
 {
+	GSettings *settings = NULL;
+
+	settings = g_settings_new_with_backend("im.pidgin.Purple.Network.IP",
+	                                       purple_core_get_settings_backend());
+
 	/* Check if the user specified an IP manually */
-	if (!purple_prefs_get_bool("/purple/network/auto_ip")) {
-		const gchar *ip = NULL;
-
-		ip = purple_network_get_public_ip();
+	if(!g_settings_get_boolean(settings, "autodetect")) {
+		char *ip = purple_network_get_public_ip();
 
 		/* Make sure the IP address entered by the user is valid */
-		if ((ip != NULL) && (purple_network_is_ipv4(ip))) {
-			return g_strdup(ip);
+		if(ip != NULL && purple_network_is_ipv4(ip)) {
+			g_clear_object(&settings);
+			return ip;
 		}
+
+		g_free(ip);
 	}
+	g_clear_object(&settings);
 
 	/* Just fetch the IP of the local system */
 	return purple_network_get_local_system_ip_from_gio(sockconn);
@@ -175,13 +206,6 @@ gboolean
 void
 purple_network_init(void)
 {
-	purple_prefs_add_none  ("/purple/network");
-	purple_prefs_add_bool  ("/purple/network/auto_ip", TRUE);
-	purple_prefs_add_string("/purple/network/public_ip", "");
-	purple_prefs_add_bool  ("/purple/network/map_ports", TRUE);
-	purple_prefs_add_bool  ("/purple/network/ports_range_use", FALSE);
-	purple_prefs_add_int   ("/purple/network/ports_range_start", 1024);
-	purple_prefs_add_int   ("/purple/network/ports_range_end", 2048);
 }
 
 void
diff --git a/libpurple/network.h b/libpurple/network.h
--- a/libpurple/network.h
+++ b/libpurple/network.h
@@ -64,7 +64,7 @@ void purple_network_set_public_ip(const 
  * Since: 2.0
  */
 PURPLE_AVAILABLE_IN_ALL
-const char *purple_network_get_public_ip(void);
+char *purple_network_get_public_ip(void);
 
 /**
  * purple_network_discover_my_ip:
diff --git a/libpurple/purplegio.c b/libpurple/purplegio.c
--- a/libpurple/purplegio.c
+++ b/libpurple/purplegio.c
@@ -22,7 +22,9 @@
 
 #include "purplegio.h"
 
+#include "core.h"
 #include "debug.h"
+#include "network.h"
 #include "prefs.h"
 #include "proxy.h"
 
@@ -140,16 +142,24 @@ purple_socket_listener_add_any_inet_port
                                          GObject *source_object,
                                          GError **error)
 {
+	GSettings *settings = NULL;
 	GError *internal_error = NULL;
 	guint16 port, start, end;
 
-	if(!purple_prefs_get_bool("/purple/network/ports_range_use")) {
+	settings = g_settings_new_with_backend("im.pidgin.Purple.Network.Ports.Manual",
+	                                       purple_core_get_settings_backend());
+
+	if(!g_settings_get_boolean(settings, "enabled")) {
+		g_object_unref(settings);
+
 		return g_socket_listener_add_any_inet_port(listener, source_object,
 		                                           error);
 	}
 
-	start = purple_prefs_get_int("/purple/network/ports_range_start");
-	end = purple_prefs_get_int("/purple/network/ports_range_end");
+	start = g_settings_get_int(settings, "start");
+	end = g_settings_get_int(settings, "end");
+	g_clear_object(&settings);
+
 	for(port = start; port <= end; port++) {
 		if (g_socket_listener_add_inet_port(listener, port, source_object,
 		                                    &internal_error))
diff --git a/pidgin/prefs/pidginnetworkprefs.c b/pidgin/prefs/pidginnetworkprefs.c
--- a/pidgin/prefs/pidginnetworkprefs.c
+++ b/pidgin/prefs/pidginnetworkprefs.c
@@ -72,26 +72,19 @@ network_ip_changed(GtkEditable *editable
 }
 
 static void
-network_stun_server_changed_cb(G_GNUC_UNUSED GtkEventControllerFocus *focus,
-                               gpointer data)
-{
-	GtkEditable *editable = data;
-
-	purple_prefs_set_string("/purple/network/stun_server",
-	                        gtk_editable_get_text(editable));
-}
-
-static void
 auto_ip_button_clicked_cb(G_GNUC_UNUSED GObject *obj,
                           G_GNUC_UNUSED GParamSpec *pspec, gpointer data)
 {
 	PidginNetworkPrefs *prefs = PIDGIN_NETWORK_PREFS(data);
+	GSettings *settings = NULL;
 	const char *ip;
 	char *auto_ip_text;
 	GList *list = NULL;
 
 	/* Make a lookup for the auto-detected IP ourselves. */
-	if (purple_prefs_get_bool("/purple/network/auto_ip")) {
+	settings = g_settings_new_with_backend("im.pidgin.Purple.Network.IP",
+	                                       purple_core_get_settings_backend());
+	if(g_settings_get_boolean(settings, "autodetect")) {
 		ip = "0.0.0.0";
 	} else {
 		ip = _("Disabled");
@@ -102,6 +95,7 @@ auto_ip_button_clicked_cb(G_GNUC_UNUSED 
 	                              auto_ip_text);
 	g_free(auto_ip_text);
 	g_list_free_full(list, g_free);
+	g_object_unref(settings);
 }
 
 /******************************************************************************
@@ -134,8 +128,6 @@ pidgin_network_prefs_class_init(PidginNe
 	gtk_widget_class_bind_template_child(widget_class, PidginNetworkPrefs,
 	                                     ports_range_end);
 	gtk_widget_class_bind_template_callback(widget_class,
-	                                        network_stun_server_changed_cb);
-	gtk_widget_class_bind_template_callback(widget_class,
 	                                        auto_ip_button_clicked_cb);
 	gtk_widget_class_bind_template_callback(widget_class, network_ip_changed);
 }
@@ -143,31 +135,46 @@ pidgin_network_prefs_class_init(PidginNe
 static void
 pidgin_network_prefs_init(PidginNetworkPrefs *prefs)
 {
-	const char *stun_server = NULL;
+	GSettings *settings = NULL;
+	char *ip = NULL;
 
 	gtk_widget_init_template(GTK_WIDGET(prefs));
 
-	stun_server = purple_prefs_get_string("/purple/network/stun_server");
-	if (stun_server != NULL) {
-		gtk_editable_set_text(GTK_EDITABLE(prefs->stun_server),
-		                      stun_server);
-	}
+	settings = g_settings_new_with_backend("im.pidgin.Purple.Network.Stun",
+	                                       purple_core_get_settings_backend());
+	g_settings_bind(settings, "server", prefs->stun_server, "text",
+	                G_SETTINGS_BIND_DEFAULT);
+	g_clear_object(&settings);
 
-	pidgin_prefs_bind_switch("/purple/network/auto_ip", prefs->auto_ip);
-	auto_ip_button_clicked_cb(NULL, NULL, prefs); /* Update label */
+	settings = g_settings_new_with_backend("im.pidgin.Purple.Network.IP",
+	                                       purple_core_get_settings_backend());
+	g_settings_bind(settings, "autodetect", prefs->auto_ip, "active",
+	                G_SETTINGS_BIND_DEFAULT);
+	g_clear_object(&settings);
+
+	ip = purple_network_get_public_ip();
+	gtk_editable_set_text(GTK_EDITABLE(prefs->public_ip), ip);
+	g_free(ip);
 
-	gtk_editable_set_text(GTK_EDITABLE(prefs->public_ip),
-	                      purple_network_get_public_ip());
+	settings = g_settings_new_with_backend("im.pidgin.Purple.Network.Ports",
+	                                       purple_core_get_settings_backend());
+	g_settings_bind(settings, "use-discovery", prefs->map_ports, "active",
+	                G_SETTINGS_BIND_DEFAULT);
+	g_clear_object(&settings);
 
-	pidgin_prefs_bind_switch("/purple/network/map_ports", prefs->map_ports);
+	settings = g_settings_new_with_backend("im.pidgin.Purple.Network.Ports.Manual",
+	                                       purple_core_get_settings_backend());
 
-	pidgin_prefs_bind_expander_row("/purple/network/ports_range_use",
-	                               prefs->ports_range_use);
+	g_settings_bind(settings, "enabled",
+	                prefs->ports_range_use, "enable-expansion",
+	                G_SETTINGS_BIND_DEFAULT);
 
-	pidgin_prefs_bind_spin_button("/purple/network/ports_range_start",
-			prefs->ports_range_start);
-	pidgin_prefs_bind_spin_button("/purple/network/ports_range_end",
-			prefs->ports_range_end);
+	g_settings_bind(settings, "start", prefs->ports_range_start, "value",
+	                G_SETTINGS_BIND_DEFAULT);
+	g_settings_bind(settings, "end", prefs->ports_range_end, "value",
+	                G_SETTINGS_BIND_DEFAULT);
+
+	g_clear_object(&settings);
 }
 
 /******************************************************************************
diff --git a/pidgin/resources/Prefs/network.ui b/pidgin/resources/Prefs/network.ui
--- a/pidgin/resources/Prefs/network.ui
+++ b/pidgin/resources/Prefs/network.ui
@@ -42,11 +42,6 @@ along with this program; if not, see <ht
             <property name="title" translatable="1">ST_UN server</property>
             <property name="use-underline">1</property>
             <property name="input-purpose">url</property>
-            <child>
-              <object class="GtkEventControllerFocus">
-                <signal name="leave" handler="network_stun_server_changed_cb" object="stun_server" swapped="no"/>
-              </object>
-            </child>
           </object>
         </child>
         <child>
