changeset 11878:f672349cfc1c

[gaim-migrate @ 14169] Use GNOME proxy preferences. Works For Me. People are going to go crazy. We'll try it out in beta. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Fri, 28 Oct 2005 23:12:04 +0000
parents f1f7c83d7b6c
children 20479a2cf911
files src/gtkprefs.c src/gtkutils.c src/proxy.c src/util.c src/util.h
diffstat 5 files changed, 164 insertions(+), 91 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkprefs.c	Fri Oct 28 21:41:20 2005 +0000
+++ b/src/gtkprefs.c	Fri Oct 28 23:12:04 2005 +0000
@@ -996,99 +996,101 @@
 	g_signal_connect(G_OBJECT(ports_checkbox), "clicked",
 					 G_CALLBACK(gaim_gtk_toggle_sensitive), spin_button);
 
-	vbox = gaim_gtk_make_frame(ret, _("Proxy Server"));
-	prefs_proxy_frame = gtk_vbox_new(FALSE, 0);
-	gaim_gtk_prefs_dropdown(vbox, _("Proxy _type:"), GAIM_PREF_STRING,
-				"/core/proxy/type",
-				_("No proxy"), "none",
-				"SOCKS 4", "socks4",
-				"SOCKS 5", "socks5",
-				"HTTP", "http",
-				_("Use Environmental Settings"), "envvar",
-				NULL);
-	gtk_box_pack_start(GTK_BOX(vbox), prefs_proxy_frame, 0, 0, 0);
-	proxy_info = gaim_global_proxy_get_info();
+	if (!gaim_running_gnome()) {
+		vbox = gaim_gtk_make_frame(ret, _("Proxy Server"));
+		prefs_proxy_frame = gtk_vbox_new(FALSE, 0);
+		gaim_gtk_prefs_dropdown(vbox, _("Proxy _type:"), GAIM_PREF_STRING,
+					"/core/proxy/type",
+					_("No proxy"), "none",
+					"SOCKS 4", "socks4",
+					"SOCKS 5", "socks5",
+					"HTTP", "http",
+					_("Use Environmental Settings"), "envvar",
+					NULL);
+		gtk_box_pack_start(GTK_BOX(vbox), prefs_proxy_frame, 0, 0, 0);
+		proxy_info = gaim_global_proxy_get_info();
 
-	gaim_prefs_connect_callback(prefs, "/core/proxy/type",
-				    proxy_changed_cb, prefs_proxy_frame);
-
-	table = gtk_table_new(4, 2, FALSE);
-	gtk_container_set_border_width(GTK_CONTAINER(table), 0);
-	gtk_table_set_col_spacings(GTK_TABLE(table), 5);
-	gtk_table_set_row_spacings(GTK_TABLE(table), 10);
-	gtk_container_add(GTK_CONTAINER(prefs_proxy_frame), table);
+		gaim_prefs_connect_callback(prefs, "/core/proxy/type",
+					    proxy_changed_cb, prefs_proxy_frame);
+	
+		table = gtk_table_new(4, 2, FALSE);
+		gtk_container_set_border_width(GTK_CONTAINER(table), 0);
+		gtk_table_set_col_spacings(GTK_TABLE(table), 5);
+		gtk_table_set_row_spacings(GTK_TABLE(table), 10);
+		gtk_container_add(GTK_CONTAINER(prefs_proxy_frame), table);
 
 
-	label = gtk_label_new_with_mnemonic(_("_Host:"));
-	gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
-	gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL, 0, 0, 0);
+		label = gtk_label_new_with_mnemonic(_("_Host:"));
+		gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
+		gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL, 0, 0, 0);
 
-	entry = gtk_entry_new();
-	gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry);
-	gtk_table_attach(GTK_TABLE(table), entry, 1, 2, 0, 1, GTK_FILL, 0, 0, 0);
-	g_signal_connect(G_OBJECT(entry), "changed",
-					 G_CALLBACK(proxy_print_option), (void *)PROXYHOST);
+		entry = gtk_entry_new();
+		gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry);
+		gtk_table_attach(GTK_TABLE(table), entry, 1, 2, 0, 1, GTK_FILL, 0, 0, 0);
+		g_signal_connect(G_OBJECT(entry), "changed",
+				 G_CALLBACK(proxy_print_option), (void *)PROXYHOST);
 
-	if (proxy_info != NULL && gaim_proxy_info_get_host(proxy_info))
-		gtk_entry_set_text(GTK_ENTRY(entry),
-						   gaim_proxy_info_get_host(proxy_info));
+		if (proxy_info != NULL && gaim_proxy_info_get_host(proxy_info))
+			gtk_entry_set_text(GTK_ENTRY(entry),
+					   gaim_proxy_info_get_host(proxy_info));
 
-	hbox = gtk_hbox_new(TRUE, 5);
-	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
-	gaim_set_accessible_label (entry, label);
+		hbox = gtk_hbox_new(TRUE, 5);
+		gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+		gaim_set_accessible_label (entry, label);
 
-	label = gtk_label_new_with_mnemonic(_("_Port:"));
-	gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
-	gtk_table_attach(GTK_TABLE(table), label, 2, 3, 0, 1, GTK_FILL, 0, 0, 0);
+		label = gtk_label_new_with_mnemonic(_("_Port:"));
+		gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
+		gtk_table_attach(GTK_TABLE(table), label, 2, 3, 0, 1, GTK_FILL, 0, 0, 0);
 
-	entry = gtk_entry_new();
-	gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry);
-	gtk_table_attach(GTK_TABLE(table), entry, 3, 4, 0, 1, GTK_FILL, 0, 0, 0);
-	g_signal_connect(G_OBJECT(entry), "changed",
-					 G_CALLBACK(proxy_print_option), (void *)PROXYPORT);
+		entry = gtk_entry_new();
+		gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry);
+		gtk_table_attach(GTK_TABLE(table), entry, 3, 4, 0, 1, GTK_FILL, 0, 0, 0);
+		g_signal_connect(G_OBJECT(entry), "changed",
+				 G_CALLBACK(proxy_print_option), (void *)PROXYPORT);
 
-	if (proxy_info != NULL && gaim_proxy_info_get_port(proxy_info) != 0) {
-		char buf[128];
-		g_snprintf(buf, sizeof(buf), "%d",
+		if (proxy_info != NULL && gaim_proxy_info_get_port(proxy_info) != 0) {
+			char buf[128];
+			g_snprintf(buf, sizeof(buf), "%d",
 				   gaim_proxy_info_get_port(proxy_info));
 
-		gtk_entry_set_text(GTK_ENTRY(entry), buf);
-	}
-	gaim_set_accessible_label (entry, label);
+			gtk_entry_set_text(GTK_ENTRY(entry), buf);
+		}
+		gaim_set_accessible_label (entry, label);
 
-	label = gtk_label_new_with_mnemonic(_("_User:"));
-	gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
-	gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, GTK_FILL, 0, 0, 0);
+		label = gtk_label_new_with_mnemonic(_("_User:"));
+		gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
+		gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, GTK_FILL, 0, 0, 0);
 
-	entry = gtk_entry_new();
-	gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry);
-	gtk_table_attach(GTK_TABLE(table), entry, 1, 2, 1, 2, GTK_FILL, 0, 0, 0);
-	g_signal_connect(G_OBJECT(entry), "changed",
-					 G_CALLBACK(proxy_print_option), (void *)PROXYUSER);
+		entry = gtk_entry_new();
+		gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry);
+		gtk_table_attach(GTK_TABLE(table), entry, 1, 2, 1, 2, GTK_FILL, 0, 0, 0);
+		g_signal_connect(G_OBJECT(entry), "changed",
+				 G_CALLBACK(proxy_print_option), (void *)PROXYUSER);
 
-	if (proxy_info != NULL && gaim_proxy_info_get_username(proxy_info) != NULL)
-		gtk_entry_set_text(GTK_ENTRY(entry),
+		if (proxy_info != NULL && gaim_proxy_info_get_username(proxy_info) != NULL)
+			gtk_entry_set_text(GTK_ENTRY(entry),
 						   gaim_proxy_info_get_username(proxy_info));
 
-	hbox = gtk_hbox_new(TRUE, 5);
-	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
-	gaim_set_accessible_label (entry, label);
+		hbox = gtk_hbox_new(TRUE, 5);
+		gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+		gaim_set_accessible_label (entry, label);
 
-	label = gtk_label_new_with_mnemonic(_("Pa_ssword:"));
-	gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
-	gtk_table_attach(GTK_TABLE(table), label, 2, 3, 1, 2, GTK_FILL, 0, 0, 0);
+		label = gtk_label_new_with_mnemonic(_("Pa_ssword:"));
+		gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
+		gtk_table_attach(GTK_TABLE(table), label, 2, 3, 1, 2, GTK_FILL, 0, 0, 0);
 
-	entry = gtk_entry_new();
-	gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry);
-	gtk_table_attach(GTK_TABLE(table), entry, 3, 4, 1, 2, GTK_FILL , 0, 0, 0);
-	gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
-	g_signal_connect(G_OBJECT(entry), "changed",
-					 G_CALLBACK(proxy_print_option), (void *)PROXYPASS);
+		entry = gtk_entry_new();
+		gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry);
+		gtk_table_attach(GTK_TABLE(table), entry, 3, 4, 1, 2, GTK_FILL , 0, 0, 0);
+		gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
+		g_signal_connect(G_OBJECT(entry), "changed",
+				 G_CALLBACK(proxy_print_option), (void *)PROXYPASS);
 
-	if (proxy_info != NULL && gaim_proxy_info_get_password(proxy_info) != NULL)
-		gtk_entry_set_text(GTK_ENTRY(entry),
-						   gaim_proxy_info_get_password(proxy_info));
-	gaim_set_accessible_label (entry, label);
+		if (proxy_info != NULL && gaim_proxy_info_get_password(proxy_info) != NULL)
+			gtk_entry_set_text(GTK_ENTRY(entry),
+					   gaim_proxy_info_get_password(proxy_info));
+		gaim_set_accessible_label (entry, label);
+	}
 
 	gtk_widget_show_all(ret);
 	if (proxy_info == NULL ||
--- a/src/gtkutils.c	Fri Oct 28 21:41:20 2005 +0000
+++ b/src/gtkutils.c	Fri Oct 28 23:12:04 2005 +0000
@@ -1349,20 +1349,6 @@
 #endif
 }
 
-gboolean
-gaim_running_gnome(void)
-{
-	gchar *tmp = g_find_program_in_path("gnome-open");
-	if ((g_getenv("GNOME_DESKTOP_SESSION_ID") != NULL) &&
-		(tmp != NULL))
-	{
-		g_free(tmp);
-		return TRUE;
-	}
-	g_free(tmp);
-	return FALSE;
-}
-
 enum {
 	DND_FILE_TRANSFER,
 	DND_IM_IMAGE,
--- a/src/proxy.c	Fri Oct 28 21:41:20 2005 +0000
+++ b/src/proxy.c	Fri Oct 28 23:12:04 2005 +0000
@@ -183,6 +183,67 @@
 	return global_proxy_info;
 }
 
+GaimProxyInfo *
+gaim_gnome_proxy_get_info(void)
+{
+	static GaimProxyInfo info = {0, NULL, 0, NULL, NULL};
+	gchar *path;
+	if ((path = g_find_program_in_path("gconftool-2"))) {
+		gchar *tmp;
+		
+		/* See whether to use a proxy. */
+		if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/use_http_proxy", &tmp,
+					       NULL, NULL, NULL))
+			return gaim_global_proxy_get_info();
+		if (strcmp(tmp, "true\n")) {
+			info.type = GAIM_PROXY_NONE;
+			g_free(tmp);
+			return gaim_global_proxy_get_info();
+		}
+			
+		g_free(tmp);
+		info.type = GAIM_PROXY_HTTP;
+		
+		/* Free the old fields */
+		if (info.host) {
+			g_free(info.host);
+			info.host = NULL;
+		}
+		if (info.username) {
+			g_free(info.username);
+			info.username = NULL;
+		}
+		if (info.password) {
+			g_free(info.password);
+			info.password = NULL;
+		}
+		
+		/* Get the new ones */
+		if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/host", &info.host,
+					       NULL, NULL, NULL))
+			return gaim_global_proxy_get_info();
+		g_strchomp(info.host);
+		
+		if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_user", &info.username,
+					       NULL, NULL, NULL))
+			return gaim_global_proxy_get_info();
+		g_strchomp(info.username);
+
+		if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_password", &info.password,
+					       NULL, NULL, NULL))
+			return gaim_global_proxy_get_info();
+		g_strchomp(info.password);
+
+		if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/port", &tmp,
+					       NULL, NULL, NULL))
+			return gaim_global_proxy_get_info();
+		info.port = atoi(tmp);
+
+		g_free(path);
+		return &info;
+	}
+	return gaim_global_proxy_get_info();
+}
 /**************************************************************************
  * Proxy API
  **************************************************************************/
@@ -1806,10 +1867,12 @@
 
 	phb = g_new0(struct PHB, 1);
 
-	if (account == NULL || gaim_account_get_proxy_info(account) == NULL)
+	if (account && gaim_account_get_proxy_info(account) != NULL)
+		phb->gpi = gaim_account_get_proxy_info(account);
+	else if (gaim_running_gnome())
+		phb->gpi = gaim_gnome_proxy_get_info();
+	else
 		phb->gpi = gaim_global_proxy_get_info();
-	else
-		phb->gpi = gaim_account_get_proxy_info(account);
 
 	phb->func = func;
 	phb->data = data;
--- a/src/util.c	Fri Oct 28 21:41:20 2005 +0000
+++ b/src/util.c	Fri Oct 28 23:12:04 2005 +0000
@@ -2227,6 +2227,21 @@
 	return is_valid;
 }
 
+
+gboolean
+gaim_running_gnome(void)
+{
+	gchar *tmp = g_find_program_in_path("gnome-open");
+	if ((g_getenv("GNOME_DESKTOP_SESSION_ID") != NULL) &&
+		(tmp != NULL))
+	{
+		g_free(tmp);
+		return TRUE;
+	}
+	g_free(tmp);
+	return FALSE;
+}
+
 char *
 gaim_fd_get_ip(int fd)
 {
--- a/src/util.h	Fri Oct 28 21:41:20 2005 +0000
+++ b/src/util.h	Fri Oct 28 23:12:04 2005 +0000
@@ -464,6 +464,13 @@
 gboolean gaim_program_is_valid(const char *program);
 
 /**
+ * Check if running Gnome.
+ *
+ * @return TRUE if running Gnome, FALSE otherwise.
+ */
+gboolean gaim_running_gnome(void);
+
+/**
  * Returns the IP address from a socket file descriptor.
  *
  * @param fd The socket file descriptor.