# HG changeset patch # User Luke Schierer # Date 1043613873 0 # Node ID 50ef0203fdbfc4a20eac19462159940ec024072d # Parent 801830dec40994f13be0e4414e6ccf3a3a13df1f [gaim-migrate @ 4706] (15:44:23) Robot101: http://people.debian.org/~robot101/honestly-really-fixed-browser-patch.diff (15:44:33) Robot101: that *is* just the hunk that got left out in the cold. =) we'll see ;-) committer: Tailor Script diff -r 801830dec409 -r 50ef0203fdbf src/browser.c --- a/src/browser.c Sun Jan 26 20:43:25 2003 +0000 +++ b/src/browser.c Sun Jan 26 20:44:33 2003 +0000 @@ -487,263 +487,106 @@ gdk_x11_xatom_to_atom (XA_STRING), 8, GDK_PROP_MODE_REPLACE, (unsigned char *)command, strlen(command)); - while (!done) { - GdkEvent *event; - - event = gdk_event_get(); - - if (!event) - continue; - - if (event->any.window != window) { - gtk_main_do_event(event); - continue; - } - - if (event->type == GDK_DESTROY && event->any.window == window) { - - /* Print to warn user... */ - debug_printf("%s: window 0x%x was destroyed.\n", progname, (unsigned int)window); - result = 6; - done = True; - } else if (event->type == GDK_PROPERTY_NOTIFY && - event->property.state == GDK_PROPERTY_NEW_VALUE && - event->property.window == window && - event->property.atom == GDKA_MOZILLA_RESPONSE) { - GdkAtom actual_type; - gint actual_format, nitems; - unsigned char *data = 0; - - result = gdk_property_get(window, GDKA_MOZILLA_RESPONSE, - gdk_x11_xatom_to_atom (XA_STRING), 0, - (65536 / sizeof(long)), - 1, &actual_type, &actual_format, &nitems, &data); - - - if (result == Success && data && *data) { - debug_printf("%s: (server sent " MOZILLA_RESPONSE_PROP - " \"%s\" to 0x%x.)\n", - progname, data, (unsigned int)window); - } + gdk_window_add_filter(window, (GdkFilterFunc) netscape_response_cb, window); +} - if (result != Success) { - debug_printf("%s: failed reading " MOZILLA_RESPONSE_PROP - " from window 0x%0x.\n", progname, (unsigned int)window); - result = 6; - done = True; - } else if (!data || strlen((char *)data) < 5) { - debug_printf("%s: invalid data on " MOZILLA_RESPONSE_PROP - " property of window 0x%0x.\n", - progname, (unsigned int)window); - result = 6; - done = True; - } else if (*data == '1') { /* positive preliminary reply */ - debug_printf("%s: %s\n", progname, data + 4); - /* keep going */ - done = False; - } else if (!strncmp((char *)data, "200", 3)) { - result = 0; - done = True; - } else if (*data == '2') { - debug_printf("%s: %s\n", progname, data + 4); - result = 0; - done = True; - } else if (*data == '3') { - debug_printf("%s: internal error: " - "server wants more information? (%s)\n", progname, data); - result = 3; - done = True; - } else if (*data == '4' || *data == '5') { - debug_printf("%s: %s\n", progname, data + 4); - result = (*data - '0'); - done = True; - } else { - debug_printf("%s: unrecognised " MOZILLA_RESPONSE_PROP - " from window 0x%x: %s\n", - progname, (unsigned int)window, data); - result = 6; - done = True; - } - - if (data) - g_free(data); - } else if (event->type == GDK_PROPERTY_NOTIFY && - event->property.window == window && - event->property.state == GDK_PROPERTY_DELETE && - event->property.atom == GDKA_MOZILLA_COMMAND) { - debug_printf("%s: (server 0x%x has accepted " - MOZILLA_COMMAND_PROP ".)\n", progname, (unsigned int)window); - } - gdk_event_free(event); +static gboolean netscape_command(const char *command) +{ + GdkWindow *window = NULL; + + if (netscape_lock) { + debug_printf("netscape_command() is currently in use.\n"); + return FALSE; } - if (new_command) - g_free(new_command); - - return result; -} - - -gboolean check_netscape(gpointer data) -{ - char *msg = data; - int status; - GdkWindow *window; + netscape_lock = 1; mozilla_remote_init_atoms(); window = mozilla_remote_find_window(); - if (window && (GDK_WINDOW_OBJECT(window)->destroyed == FALSE)) { - - XSelectInput(gdk_display, GDK_WINDOW_XWINDOW(window), - (PropertyChangeMask | StructureNotifyMask)); - - - mozilla_remote_obtain_lock(window); - - status = mozilla_remote_command(window, msg, False); - - if (status != 6) - mozilla_remote_free_lock(window); - + if (window == NULL || (GDK_WINDOW_OBJECT(window)->destroyed == TRUE)) { + debug_printf("Remote window absent or unsuitable.\n"); netscape_lock = 0; - - g_free(msg); return FALSE; - } else - return TRUE; -} - - -static void netscape_command(char *command) -{ - int status; - pid_t pid; - GdkWindow *window; - - if (netscape_lock) - return; - - netscape_lock = 1; - - - - mozilla_remote_init_atoms(); - window = mozilla_remote_find_window(); - - if (window && (GDK_WINDOW_OBJECT(window)->destroyed == FALSE)) { - - XSelectInput(gdk_display, GDK_WINDOW_XWINDOW(window), - (PropertyChangeMask | StructureNotifyMask)); - - mozilla_remote_obtain_lock(window); - - status = mozilla_remote_command(window, command, False); - - if (status != 6) - mozilla_remote_free_lock(window); - - netscape_lock = 0; - - gdk_window_destroy(window); - } else { - pid = fork(); - if (pid == 0) { - char *args[2]; - int e; - - args[0] = g_strdup("netscape"); - args[1] = NULL; - e = execvp(args[0], args); - printf("Hello%d\n", getppid()); - - _exit(0); - } else { - char *tmp = g_strdup(command); - g_timeout_add(200, check_netscape, tmp); - } } + mozilla_remote_command(window, command, False); + + netscape_lock = 0; + return TRUE; } void open_url(GtkWidget *w, char *url) { - gchar *space_free_url; - - if (web_browser == BROWSER_NETSCAPE) { - char *command; - - if (misc_options & OPT_MISC_BROWSER_POPUP) - command = g_strdup_printf("OpenURL(%s, new-window)", url); - else - command = g_strdup_printf("OpenURL(%s)", url); - - netscape_command(command); - g_free(command); -/* fixme: GNOME helper * - * } else if (web_browser == BROWSER_GNOME) { * - * gnome_url_show(url); */ - } else { - pid_t pid; - - pid = fork(); - - if (pid == 0) { - /* args will be allocated below but we don't bother - * freeing it since we're just going to exec and - * exit */ - char **args=NULL; - char command[1024]; - - if (web_browser == BROWSER_OPERA) { - args = g_new(char *, 4); - args[0] = "opera"; - args[1] = "-newwindow"; - args[2] = url; - args[3] = NULL; - } else if (web_browser == BROWSER_KONQ) { - args = g_new(char *, 4); - args[0] = "kfmclient"; - args[1] = "openURL"; - args[2] = url; - args[3] = NULL; - } else if (web_browser == BROWSER_GALEON) { - args = g_new(char *, 4); - args[0] = "galeon"; - if (misc_options & OPT_MISC_BROWSER_POPUP) { - args[1] = "-w"; - args[2] = url; - args[3] = NULL; - } else { - args[1] = url; - args[2] = NULL; - } - } else if (web_browser == BROWSER_MOZILLA) { - args = g_new(char *, 4); - args[0] = "mozilla"; - args[1] = url; - args[2] = NULL; - } else if (web_browser == BROWSER_MANUAL) { - if(strcmp(web_command,"") == 0) - _exit(0); - space_free_url = g_strdelimit(url, " ", '+'); - g_snprintf(command, sizeof(command), web_command, space_free_url); - g_free(space_free_url); - args = g_strsplit(command, " ", 0); + char *command = NULL; + GError *error = NULL; + + switch (web_browser) { + case BROWSER_NETSCAPE: { + char *args = NULL; + + if (misc_options & OPT_MISC_BROWSER_POPUP) + args = g_strdup_printf("OpenURL(%s, new-window)", url); + else + args = g_strdup_printf("OpenURL(%s)", url); + + if (netscape_command(args)) { + g_free(args); + return; } - execvp(args[0], args); - _exit(0); - } + /* if netscape is running ... + command = g_strdup_printf("netscape -remote %s", args); */ + + command = g_strdup_printf("netscape %s", url); + g_free(args); + } break; + + case BROWSER_OPERA: + command = g_strdup_printf("opera -newwindow %s", url); + break; + + case BROWSER_KONQ: + command = g_strdup_printf("kfmclient openURL %s", url); + break; + + case BROWSER_GALEON: + command = g_strdup_printf("galeon -w %s", url); + command = g_strdup_printf("galeon %s", url); + break; + + case BROWSER_MOZILLA: + command = g_strdup_printf("mozilla %s", url); + break; + + case BROWSER_MANUAL: { + char *space_free_url = NULL; + + if (!web_command[0]) { + do_error_dialog(_("Unable to launch your browser because the 'Manual' browser command has been chosen, but no command has been set."), NULL, GAIM_ERROR); + return; + } + + space_free_url = g_strdelimit(url, " ", '+'); + command = g_strdup_printf("%s %s", web_command, space_free_url); + g_free(space_free_url); + } break; } + + if (g_spawn_command_line_async(command, &error) == FALSE) { + char *tmp = g_strdup_printf(_("There was an error launching your chosen browser: %s"), error->message); + do_error_dialog(tmp, NULL, GAIM_ERROR); + g_free(tmp); + g_error_free(error); + } + + g_free(command); } void add_bookmark(GtkWidget *w, char *url) { if (web_browser == BROWSER_NETSCAPE) { - char *command = g_malloc(1024); - - g_snprintf(command, 1024, "AddBookmark(%s)", url); + char *command = g_strdup_printf("AddBookmark(%s)", url); netscape_command(command); g_free(command);