Mercurial > pidgin
comparison src/browser.c @ 4429:bf770f11132b
[gaim-migrate @ 4704]
(15:41:59) Robot101: the hunk that got left out in the cold.
its a good thing when things compile
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Sun, 26 Jan 2003 20:41:49 +0000 |
parents | b5669740e34c |
children | 801830dec409 |
comparison
equal
deleted
inserted
replaced
4428:b5669740e34c | 4429:bf770f11132b |
---|---|
485 | 485 |
486 gdk_property_change(window, GDKA_MOZILLA_COMMAND, | 486 gdk_property_change(window, GDKA_MOZILLA_COMMAND, |
487 gdk_x11_xatom_to_atom (XA_STRING), | 487 gdk_x11_xatom_to_atom (XA_STRING), |
488 8, GDK_PROP_MODE_REPLACE, (unsigned char *)command, strlen(command)); | 488 8, GDK_PROP_MODE_REPLACE, (unsigned char *)command, strlen(command)); |
489 | 489 |
490 while (!done) { | 490 gdk_window_add_filter(window, (GdkFilterFunc) netscape_response_cb, window); |
491 GdkEvent *event; | 491 } |
492 | 492 |
493 event = gdk_event_get(); | 493 static gboolean netscape_command(const char *command) |
494 | 494 { |
495 if (!event) | 495 GdkWindow *window = NULL; |
496 continue; | 496 |
497 | 497 if (netscape_lock) { |
498 if (event->any.window != window) { | 498 debug_printf("netscape_command() is currently in use.\n"); |
499 gtk_main_do_event(event); | 499 return FALSE; |
500 continue; | 500 } |
501 } | 501 |
502 | 502 netscape_lock = 1; |
503 if (event->type == GDK_DESTROY && event->any.window == window) { | |
504 | |
505 /* Print to warn user... */ | |
506 debug_printf("%s: window 0x%x was destroyed.\n", progname, (unsigned int)window); | |
507 result = 6; | |
508 done = True; | |
509 } else if (event->type == GDK_PROPERTY_NOTIFY && | |
510 event->property.state == GDK_PROPERTY_NEW_VALUE && | |
511 event->property.window == window && | |
512 event->property.atom == GDKA_MOZILLA_RESPONSE) { | |
513 GdkAtom actual_type; | |
514 gint actual_format, nitems; | |
515 unsigned char *data = 0; | |
516 | |
517 result = gdk_property_get(window, GDKA_MOZILLA_RESPONSE, | |
518 gdk_x11_xatom_to_atom (XA_STRING), 0, | |
519 (65536 / sizeof(long)), | |
520 1, &actual_type, &actual_format, &nitems, &data); | |
521 | |
522 | |
523 if (result == Success && data && *data) { | |
524 debug_printf("%s: (server sent " MOZILLA_RESPONSE_PROP | |
525 " \"%s\" to 0x%x.)\n", | |
526 progname, data, (unsigned int)window); | |
527 } | |
528 | |
529 if (result != Success) { | |
530 debug_printf("%s: failed reading " MOZILLA_RESPONSE_PROP | |
531 " from window 0x%0x.\n", progname, (unsigned int)window); | |
532 result = 6; | |
533 done = True; | |
534 } else if (!data || strlen((char *)data) < 5) { | |
535 debug_printf("%s: invalid data on " MOZILLA_RESPONSE_PROP | |
536 " property of window 0x%0x.\n", | |
537 progname, (unsigned int)window); | |
538 result = 6; | |
539 done = True; | |
540 } else if (*data == '1') { /* positive preliminary reply */ | |
541 debug_printf("%s: %s\n", progname, data + 4); | |
542 /* keep going */ | |
543 done = False; | |
544 } else if (!strncmp((char *)data, "200", 3)) { | |
545 result = 0; | |
546 done = True; | |
547 } else if (*data == '2') { | |
548 debug_printf("%s: %s\n", progname, data + 4); | |
549 result = 0; | |
550 done = True; | |
551 } else if (*data == '3') { | |
552 debug_printf("%s: internal error: " | |
553 "server wants more information? (%s)\n", progname, data); | |
554 result = 3; | |
555 done = True; | |
556 } else if (*data == '4' || *data == '5') { | |
557 debug_printf("%s: %s\n", progname, data + 4); | |
558 result = (*data - '0'); | |
559 done = True; | |
560 } else { | |
561 debug_printf("%s: unrecognised " MOZILLA_RESPONSE_PROP | |
562 " from window 0x%x: %s\n", | |
563 progname, (unsigned int)window, data); | |
564 result = 6; | |
565 done = True; | |
566 } | |
567 | |
568 if (data) | |
569 g_free(data); | |
570 } else if (event->type == GDK_PROPERTY_NOTIFY && | |
571 event->property.window == window && | |
572 event->property.state == GDK_PROPERTY_DELETE && | |
573 event->property.atom == GDKA_MOZILLA_COMMAND) { | |
574 debug_printf("%s: (server 0x%x has accepted " | |
575 MOZILLA_COMMAND_PROP ".)\n", progname, (unsigned int)window); | |
576 } | |
577 gdk_event_free(event); | |
578 } | |
579 | |
580 if (new_command) | |
581 g_free(new_command); | |
582 | |
583 return result; | |
584 } | |
585 | |
586 | |
587 gboolean check_netscape(gpointer data) | |
588 { | |
589 char *msg = data; | |
590 int status; | |
591 GdkWindow *window; | |
592 | 503 |
593 mozilla_remote_init_atoms(); | 504 mozilla_remote_init_atoms(); |
594 window = mozilla_remote_find_window(); | 505 window = mozilla_remote_find_window(); |
595 | 506 |
596 if (window && (GDK_WINDOW_OBJECT(window)->destroyed == FALSE)) { | 507 if (window == NULL || (GDK_WINDOW_OBJECT(window)->destroyed == TRUE)) { |
597 | 508 debug_printf("Remote window absent or unsuitable.\n"); |
598 XSelectInput(gdk_display, GDK_WINDOW_XWINDOW(window), | |
599 (PropertyChangeMask | StructureNotifyMask)); | |
600 | |
601 | |
602 mozilla_remote_obtain_lock(window); | |
603 | |
604 status = mozilla_remote_command(window, msg, False); | |
605 | |
606 if (status != 6) | |
607 mozilla_remote_free_lock(window); | |
608 | |
609 netscape_lock = 0; | 509 netscape_lock = 0; |
610 | |
611 g_free(msg); | |
612 return FALSE; | 510 return FALSE; |
613 } else | 511 } |
614 return TRUE; | 512 |
615 } | 513 mozilla_remote_command(window, command, False); |
616 | 514 |
617 | 515 netscape_lock = 0; |
618 static void netscape_command(char *command) | 516 return TRUE; |
619 { | |
620 int status; | |
621 pid_t pid; | |
622 GdkWindow *window; | |
623 | |
624 if (netscape_lock) | |
625 return; | |
626 | |
627 netscape_lock = 1; | |
628 | |
629 | |
630 | |
631 mozilla_remote_init_atoms(); | |
632 window = mozilla_remote_find_window(); | |
633 | |
634 if (window && (GDK_WINDOW_OBJECT(window)->destroyed == FALSE)) { | |
635 | |
636 XSelectInput(gdk_display, GDK_WINDOW_XWINDOW(window), | |
637 (PropertyChangeMask | StructureNotifyMask)); | |
638 | |
639 mozilla_remote_obtain_lock(window); | |
640 | |
641 status = mozilla_remote_command(window, command, False); | |
642 | |
643 if (status != 6) | |
644 mozilla_remote_free_lock(window); | |
645 | |
646 netscape_lock = 0; | |
647 | |
648 gdk_window_destroy(window); | |
649 } else { | |
650 pid = fork(); | |
651 if (pid == 0) { | |
652 char *args[2]; | |
653 int e; | |
654 | |
655 args[0] = g_strdup("netscape"); | |
656 args[1] = NULL; | |
657 e = execvp(args[0], args); | |
658 printf("Hello%d\n", getppid()); | |
659 | |
660 _exit(0); | |
661 } else { | |
662 char *tmp = g_strdup(command); | |
663 g_timeout_add(200, check_netscape, tmp); | |
664 } | |
665 } | |
666 | |
667 } | 517 } |
668 | 518 |
669 void open_url(GtkWidget *w, char *url) | 519 void open_url(GtkWidget *w, char *url) |
670 { | 520 { |
671 gchar *space_free_url; | 521 char *command = NULL; |
672 | 522 GError *error = NULL; |
523 | |
524 switch (web_browser) { | |
525 case BROWSER_NETSCAPE: { | |
526 char *args = NULL; | |
527 | |
528 if (misc_options & OPT_MISC_BROWSER_POPUP) | |
529 args = g_strdup_printf("OpenURL(%s, new-window)", url); | |
530 else | |
531 args = g_strdup_printf("OpenURL(%s)", url); | |
532 | |
533 if (netscape_command(args)) { | |
534 g_free(args); | |
535 return; | |
536 } | |
537 | |
538 /* if netscape is running ... | |
539 command = g_strdup_printf("netscape -remote %s", args); */ | |
540 | |
541 command = g_strdup_printf("netscape %s", url); | |
542 g_free(args); | |
543 } break; | |
544 | |
545 case BROWSER_OPERA: | |
546 command = g_strdup_printf("opera -newwindow %s", url); | |
547 break; | |
548 | |
549 case BROWSER_KONQ: | |
550 command = g_strdup_printf("kfmclient openURL %s", url); | |
551 break; | |
552 | |
553 case BROWSER_GALEON: | |
554 command = g_strdup_printf("galeon -w %s", url); | |
555 command = g_strdup_printf("galeon %s", url); | |
556 break; | |
557 | |
558 case BROWSER_MOZILLA: | |
559 command = g_strdup_printf("mozilla %s", url); | |
560 break; | |
561 | |
562 case BROWSER_MANUAL: { | |
563 char *space_free_url = NULL; | |
564 | |
565 if (!web_command[0]) { | |
566 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); | |
567 return; | |
568 } | |
569 | |
570 space_free_url = g_strdelimit(url, " ", '+'); | |
571 command = g_strdup_printf("%s %s", web_command, space_free_url); | |
572 g_free(space_free_url); | |
573 } break; | |
574 } | |
575 | |
576 if (g_spawn_command_line_async(command, &error) == FALSE) { | |
577 char *tmp = g_strdup_printf(_("There was an error launching your chosen browser: %s"), error->message); | |
578 do_error_dialog(tmp, NULL, GAIM_ERROR); | |
579 g_free(tmp); | |
580 g_error_free(error); | |
581 } | |
582 | |
583 g_free(command); | |
584 } | |
585 | |
586 void add_bookmark(GtkWidget *w, char *url) | |
587 { | |
673 if (web_browser == BROWSER_NETSCAPE) { | 588 if (web_browser == BROWSER_NETSCAPE) { |
674 char *command; | 589 char *command = g_strdup_printf("AddBookmark(%s)", url); |
675 | |
676 if (misc_options & OPT_MISC_BROWSER_POPUP) | |
677 command = g_strdup_printf("OpenURL(%s, new-window)", url); | |
678 else | |
679 command = g_strdup_printf("OpenURL(%s)", url); | |
680 | 590 |
681 netscape_command(command); | 591 netscape_command(command); |
682 g_free(command); | 592 g_free(command); |
683 /* fixme: GNOME helper * | 593 } |
684 * } else if (web_browser == BROWSER_GNOME) { * | 594 } |
685 * gnome_url_show(url); */ | 595 |
686 } else { | 596 #else |
687 pid_t pid; | 597 |
688 | 598 /* Sooner or later, I shall support Windows clicking! */ |
689 pid = fork(); | |
690 | |
691 if (pid == 0) { | |
692 /* args will be allocated below but we don't bother | |
693 * freeing it since we're just going to exec and | |
694 * exit */ | |
695 char **args=NULL; | |
696 char command[1024]; | |
697 | |
698 if (web_browser == BROWSER_OPERA) { | |
699 args = g_new(char *, 4); | |
700 args[0] = "opera"; | |
701 args[1] = "-newwindow"; | |
702 args[2] = url; | |
703 args[3] = NULL; | |
704 } else if (web_browser == BROWSER_KONQ) { | |
705 args = g_new(char *, 4); | |
706 args[0] = "kfmclient"; | |
707 args[1] = "openURL"; | |
708 args[2] = url; | |
709 args[3] = NULL; | |
710 } else if (web_browser == BROWSER_GALEON) { | |
711 args = g_new(char *, 4); | |
712 args[0] = "galeon"; | |
713 if (misc_options & OPT_MISC_BROWSER_POPUP) { | |
714 args[1] = "-w"; | |
715 args[2] = url; | |
716 args[3] = NULL; | |
717 } else { | |
718 args[1] = url; | |
719 args[2] = NULL; | |
720 } | |
721 } else if (web_browser == BROWSER_MOZILLA) { | |
722 args = g_new(char *, 4); | |
723 args[0] = "mozilla"; | |
724 args[1] = url; | |
725 args[2] = NULL; | |
726 } else if (web_browser == BROWSER_MANUAL) { | |
727 if(strcmp(web_command,"") == 0) | |
728 _exit(0); | |
729 space_free_url = g_strdelimit(url, " ", '+'); | |
730 g_snprintf(command, sizeof(command), web_command, space_free_url); | |
731 g_free(space_free_url); | |
732 args = g_strsplit(command, " ", 0); | |
733 } | |
734 | |
735 execvp(args[0], args); | |
736 _exit(0); | |
737 } | |
738 } | |
739 } | |
740 | 599 |
741 void add_bookmark(GtkWidget *w, char *url) | 600 void add_bookmark(GtkWidget *w, char *url) |
742 { | 601 { |
743 if (web_browser == BROWSER_NETSCAPE) { | |
744 char *command = g_malloc(1024); | |
745 | |
746 g_snprintf(command, 1024, "AddBookmark(%s)", url); | |
747 | |
748 netscape_command(command); | |
749 g_free(command); | |
750 } | |
751 } | |
752 | |
753 #else | |
754 | |
755 /* Sooner or later, I shall support Windows clicking! */ | |
756 | |
757 void add_bookmark(GtkWidget *w, char *url) | |
758 { | |
759 } | 602 } |
760 void open_url(GtkWidget *w, char *url) | 603 void open_url(GtkWidget *w, char *url) |
761 { | 604 { |
762 ShellExecute(NULL, NULL, url, NULL, ".\\", 0); | 605 ShellExecute(NULL, NULL, url, NULL, ".\\", 0); |
763 } | 606 } |