changeset 8272:9af78e73f0b2

[gaim-migrate @ 8996] A pizatch from Nizathan Frizedricksizon to mizake our brizowser prizeferences bizetter. There izis an izopshizun for "izopen in nizew tizab" nizow, and "mozilla -remote" comizzands wizill bize trizied if the brizowser is alrizedy rizunning. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Tue, 17 Feb 2004 01:33:20 +0000
parents 5c9cd9c97727
children f24172f53650
files ChangeLog src/gaimrc.c src/gtknotify.c src/gtkprefs.c src/gtkutils.h
diffstat 5 files changed, 115 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Feb 16 23:22:45 2004 +0000
+++ b/ChangeLog	Tue Feb 17 01:33:20 2004 +0000
@@ -6,6 +6,7 @@
 	* Ability to be invisible on AIM
 	* Chatroom list support (Tim Ringenbach)
 	* Non-ascii character support in AIM chats (Uli Luckas and Marco Ziech)
+	* Vastly improved browser opening, with tab support! (Nathan Fredrickson)
 	* Support for Mozilla Firefox (Chris Friesen and Nathan Fredrickson)
 	* Local IP address information can be changed in Preferences
 	  (Tim Ringenbach)
--- a/src/gaimrc.c	Mon Feb 16 23:22:45 2004 +0000
+++ b/src/gaimrc.c	Tue Feb 17 01:33:20 2004 +0000
@@ -883,8 +883,9 @@
 					general_options & OPT_GEN_SEND_LINKS);
 			gaim_prefs_set_bool("/gaim/gtk/debug/enabled",
 					general_options & OPT_GEN_DEBUG);
-			gaim_prefs_set_bool("/gaim/gtk/browsers/new_window",
-					general_options & OPT_GEN_BROWSER_POPUP);
+			gaim_prefs_set_int("/gaim/gtk/browsers/place",
+					(general_options & OPT_GEN_BROWSER_POPUP) ? 
+					GAIM_BROWSER_NEW_WINDOW : GAIM_BROWSER_DEFAULT );
 			gaim_prefs_set_bool("/gaim/gtk/conversations/spellecheck",
 					general_options & OPT_GEN_CHECK_SPELLING);
 			gaim_prefs_set_bool("/gaim/gtk/conversations/chat/raise_on_events",
@@ -955,8 +956,6 @@
 			misc_options = atoi(p->value[0]);
 			gaim_prefs_set_bool("/gaim/gtk/debug/enabled",
 					misc_options & OPT_MISC_DEBUG);
-			gaim_prefs_set_bool("/gaim/gtk/browsers/new_window",
-					misc_options & OPT_MISC_BROWSER_POPUP);
 			gaim_prefs_set_bool("/gaim/gtk/conversations/im/send_typing",
 					!(misc_options & OPT_MISC_STEALTH_TYPING));
 			gaim_prefs_set_bool("/gaim/gtk/buddies/use_server_alias",
--- a/src/gtknotify.c	Mon Feb 16 23:22:45 2004 +0000
+++ b/src/gtknotify.c	Tue Feb 17 01:33:20 2004 +0000
@@ -288,7 +288,7 @@
 	GSList *images = NULL;
 	int options = 0;
 	char label_text[2048];
-    char *linked_text;
+	char *linked_text;
 
 	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 	gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG);
@@ -361,12 +361,12 @@
 	options ^= GTK_IMHTML_NO_SCROLL;
 
 	gaim_gtk_find_images(text, &images);
-    if(gaim_prefs_get_bool("/gaim/gtk/conversations/show_urls_as_links")){
-        linked_text = gaim_markup_linkify(text);
-        gtk_imhtml_append_text_with_images(GTK_IMHTML(imhtml), linked_text,
+	if(gaim_prefs_get_bool("/gaim/gtk/conversations/show_urls_as_links")){
+		linked_text = gaim_markup_linkify(text);
+		gtk_imhtml_append_text_with_images(GTK_IMHTML(imhtml), linked_text,
 										   options, images);
-        g_free(linked_text);
-    } else
+		g_free(linked_text);
+	} else
 		gtk_imhtml_append_text_with_images(GTK_IMHTML(imhtml), text, options, images);
 
 	if (images) {
@@ -402,36 +402,106 @@
 		gtk_widget_destroy(GTK_WIDGET(ui_handle));
 }
 
+#ifndef _WIN32
+static gint
+uri_command(const char *command, const gboolean sync)
+{
+	GError *error = NULL;
+	gint ret = 0;
+
+	if (!gaim_program_is_valid(command)) {
+		gchar *tmp = g_strdup_printf(_("The browser \"%s\" is invalid."), 
+						command);
+		gaim_notify_error(NULL, NULL, _("Unable to open URL"), tmp);
+		g_free(tmp);
+
+	} else if (sync) {
+		gint status;
+ 
+		if (!g_spawn_command_line_sync(command, NULL, NULL, &status, &error)) {
+			char *tmp = g_strdup_printf(
+				_("Error launching \"command\": %s"),
+				error->message);
+
+			gaim_notify_error(NULL, NULL, _("Unable to open URL"), tmp);
+
+			g_free(tmp);
+			g_error_free(error);
+		} else {
+			ret = status;
+		}
+
+	} else {
+		if (!g_spawn_command_line_async(command, &error)) {
+			char *tmp = g_strdup_printf(
+				_("Error launching \"command\": %s"),
+				error->message);
+
+			gaim_notify_error(NULL, NULL, _("Unable to open URL"), tmp);
+
+			g_free(tmp);
+			g_error_free(error);
+		}
+	}
+
+	printf("command: %d = %s\n", ret, command);
+	return ret;
+}
+#endif
+
 static void *
 gaim_gtk_notify_uri(const char *uri)
 {
 #ifndef _WIN32
 	char *command = NULL;
-	GError *error = NULL;
+	char *remote_command = NULL;
 	const char *web_browser;
+	int place;
 
 	web_browser = gaim_prefs_get_string("/gaim/gtk/browsers/browser");
+	place = gaim_prefs_get_int("/gaim/gtk/browsers/place");
 
 	if (!strcmp(web_browser, "netscape")) {
 		command = g_strdup_printf("netscape \"%s\"", uri);
+		if (place == GAIM_BROWSER_NEW_WINDOW)
+			remote_command = g_strdup_printf("netscape -remote \"openURL(\"%s\",new-window)\"", uri);
+		else if (place == GAIM_BROWSER_CURRENT)
+			remote_command = g_strdup_printf("netscape -remote \"openURL(\"%s\")\"", uri);
+
 	} else if (!strcmp(web_browser, "opera")) {
-		if (gaim_prefs_get_bool("/gaim/gtk/browsers/new_window"))
+		if (place == GAIM_BROWSER_NEW_WINDOW)
 			command = g_strdup_printf("opera -newwindow \"%s\"", uri);
-		else
+		else if (place == GAIM_BROWSER_NEW_TAB)
+			command = g_strdup_printf("opera -newpage \"%s\"", uri);
+		else if (place == GAIM_BROWSER_CURRENT) {
+			remote_command = g_strdup_printf("opera -remote \"openURL(\"%s\")\"", uri);
 			command = g_strdup_printf("opera \"%s\"", uri);
+		} else
+			command = g_strdup_printf("opera \"%s\"", uri);
+
 	} else if (!strcmp(web_browser, "kfmclient")) {
 		command = g_strdup_printf("kfmclient openURL \"%s\"", uri);
+		/* does Konqueror have options to open in new tab and/or current window? */
+
 	} else if (!strcmp(web_browser, "galeon")) {
-		if (gaim_prefs_get_bool("/gaim/gtk/browsers/new_window"))
+		if (place == GAIM_BROWSER_NEW_WINDOW)
 			command = g_strdup_printf("galeon -w \"%s\"", uri);
+		else if (place == GAIM_BROWSER_NEW_TAB)
+			command = g_strdup_printf("galeon -n \"%s\"", uri);
 		else
 			command = g_strdup_printf("galeon \"%s\"", uri);
-	} else if (!strcmp(web_browser, "mozilla")) {
-		command = g_strdup_printf("mozilla \"%s\"", uri);
-	} else if (!strcmp(web_browser, "mozilla-firebird")) {
-		command = g_strdup_printf("mozilla-firebird \"%s\"", uri);
-	} else if (!strcmp(web_browser, "firefox")) {
-		command = g_strdup_printf("firefox \"%s\"", uri);
+
+	} else if (!strcmp(web_browser, "mozilla") || 
+			   !strcmp(web_browser, "mozilla-firebird") ||
+			   !strcmp(web_browser, "firefox")) {
+		command = g_strdup_printf("%s \"%s\"", web_browser, uri);
+		if (place == GAIM_BROWSER_NEW_WINDOW)
+			remote_command = g_strdup_printf("%s -remote \"openURL(\"%s\",new-window)\"", web_browser, uri);
+		else if (place == GAIM_BROWSER_NEW_TAB)
+			remote_command = g_strdup_printf("%s -remote \"openURL(\"%s\",new-tab)\"", web_browser, uri);
+		else if (place == GAIM_BROWSER_CURRENT)
+			remote_command = g_strdup_printf("%s -remote \"openURL(\"%s\")\"", web_browser, uri);
+
 	} else if (!strcmp(web_browser, "custom")) {
 		const char *web_command;
 
@@ -455,21 +525,13 @@
 		}
 	}
 
-	if (!gaim_program_is_valid(command)) {
-		gchar *tmp = g_strdup_printf(_("The browser \"%s\" is invalid."), 
-						command);
-		gaim_notify_error(NULL, NULL, _("Unable to open URL"), tmp);
-		g_free(tmp);
-
-	} else if (!g_spawn_command_line_async(command, &error)) {
-		char *tmp = g_strdup_printf(
-				_("Error launching \"command\": %s"),
-				error->message);
-
-		gaim_notify_error(NULL, NULL, _("Unable to open URL"), tmp);
-
-		g_free(tmp);
-		g_error_free(error);
+	if (remote_command != NULL) {
+		/* try the remote command first */
+		if (uri_command(remote_command, TRUE) != 0)
+			uri_command(command, FALSE);
+		g_free(remote_command);
+	} else {
+		uri_command(command, FALSE);
 	}
 
 	g_free(command);
--- a/src/gtkprefs.c	Mon Feb 16 23:22:45 2004 +0000
+++ b/src/gtkprefs.c	Tue Feb 17 01:33:20 2004 +0000
@@ -1333,7 +1333,6 @@
 	GtkWidget *vbox;
 	GtkWidget *hbox;
 	GtkWidget *label;
-	GtkWidget *checkbox;
 	GtkWidget *entry;
 	GtkSizeGroup *sg;
 	GList *browsers = NULL;
@@ -1379,9 +1378,13 @@
 
 	if (browsers != NULL) {
 		vbox = gaim_gtk_make_frame (ret, _("Browser Options"));
-		checkbox = gaim_gtk_prefs_checkbox(_("Open new _window by default"),
-										   "/gaim/gtk/browsers/new_window",
-										   vbox);
+		gaim_gtk_prefs_dropdown(vbox, _("_Open link in:"), GAIM_PREF_INT,
+			"/gaim/gtk/browsers/place",
+			_("Browser default"), GAIM_BROWSER_DEFAULT,
+			_("Existing window"), GAIM_BROWSER_CURRENT,
+			_("New window"), GAIM_BROWSER_NEW_WINDOW,
+			_("New tab"), GAIM_BROWSER_NEW_TAB,
+			NULL);
 	}
 
 	gtk_widget_show_all(ret);
@@ -2910,7 +2913,7 @@
 
 	/* Browsers */
 	gaim_prefs_add_none("/gaim/gtk/browsers");
-	gaim_prefs_add_bool("/gaim/gtk/browsers/new_window", FALSE);
+	gaim_prefs_add_int("/gaim/gtk/browsers/place", GAIM_BROWSER_DEFAULT);
 	gaim_prefs_add_string("/gaim/gtk/browsers/command", "");
 	gaim_prefs_add_string("/gaim/gtk/browsers/browser", "mozilla");
 
--- a/src/gtkutils.h	Mon Feb 16 23:22:45 2004 +0000
+++ b/src/gtkutils.h	Tue Feb 17 01:33:20 2004 +0000
@@ -45,6 +45,16 @@
 
 } GaimButtonStyle;
 
+#ifndef _WIN32
+typedef enum
+{
+	GAIM_BROWSER_DEFAULT = 0,
+	GAIM_BROWSER_CURRENT,
+	GAIM_BROWSER_NEW_WINDOW,
+	GAIM_BROWSER_NEW_TAB
+} GaimBrowserPlace;
+#endif /* _WIN32 */
+
 typedef gboolean (*GaimCheckAccountFunc)(GaimAccount *account);
 
 extern guint accels_save_timer;