comparison src/browser.c @ 6465:fb64cc87bc96

[gaim-migrate @ 6974] open_url() is gone forever! WOOHOO! Now we have gaim_notify_uri(). Oh, and whitespace changes in some files, because they just really bugged me. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Thu, 14 Aug 2003 03:55:13 +0000
parents 8f94cce8faa5
children 338147ea6896
comparison
equal deleted inserted replaced
6464:059649ed25ed 6465:fb64cc87bc96
194 int format; 194 int format;
195 unsigned long nitems, bytesafter; 195 unsigned long nitems, bytesafter;
196 unsigned char *version = 0; 196 unsigned char *version = 0;
197 gchar *retval = NULL; 197 gchar *retval = NULL;
198 198
199 if (XGetWindowProperty(gdk_display, window, 199 if (XGetWindowProperty(gdk_display, window,
200 gdk_x11_atom_to_xatom(GDKA_MOZILLA_VERSION), 200 gdk_x11_atom_to_xatom(GDKA_MOZILLA_VERSION),
201 0, (65536 / sizeof(long)), 201 0, (65536 / sizeof(long)),
202 False, XA_STRING, 202 False, XA_STRING,
203 &type, &format, &nitems, &bytesafter, 203 &type, &format, &nitems, &bytesafter,
204 &version) != Success) { 204 &version) != Success) {
205 return NULL; 205 return NULL;
206 } 206 }
207 207
208 if (!version) { 208 if (!version) {
209 return NULL; 209 return NULL;
307 307
308 static const char *get_lock_data() { 308 static const char *get_lock_data() {
309 static char *lock_data = NULL; 309 static char *lock_data = NULL;
310 310
311 if (lock_data == NULL) { 311 if (lock_data == NULL) {
312 char hostname[HOST_NAME_MAX + 1] = {0}; 312 char hostname[HOST_NAME_MAX + 1] = {0};
313 313
314 if (gethostname(hostname, HOST_NAME_MAX + 1) == 0) { 314 if (gethostname(hostname, HOST_NAME_MAX + 1) == 0) {
315 lock_data = g_strdup_printf("pid%d@%s", getpid(), hostname); 315 lock_data = g_strdup_printf("pid%d@%s", getpid(), hostname);
316 } else { 316 } else {
317 lock_data = g_strdup_printf("pid%d", getpid()); 317 lock_data = g_strdup_printf("pid%d", getpid());
358 358
359 static void mozilla_remote_free_lock(GdkWindow * window) 359 static void mozilla_remote_free_lock(GdkWindow * window)
360 { 360 {
361 int result = 0; 361 int result = 0;
362 GdkAtom actual_type; 362 GdkAtom actual_type;
363 gint actual_format; 363 gint actual_format;
364 gint nitems; 364 gint nitems;
365 unsigned char *data = 0; 365 unsigned char *data = 0;
366 const char *lock_data = get_lock_data(); 366 const char *lock_data = get_lock_data();
367 367
368 gaim_debug(GAIM_DEBUG_MISC, "browser", 368 gaim_debug(GAIM_DEBUG_MISC, "browser",
369 "%s: deleting " MOZILLA_LOCK_PROP " \"%s\" from 0x%x\n", 369 "%s: deleting " MOZILLA_LOCK_PROP " \"%s\" from 0x%x\n",
370 progname, lock_data, (unsigned int)window); 370 progname, lock_data, (unsigned int)window);
371 371
372 result = gdk_property_get(window, GDKA_MOZILLA_LOCK, 372 result = gdk_property_get(window, GDKA_MOZILLA_LOCK,
373 gdk_x11_xatom_to_atom (XA_STRING), 373 gdk_x11_xatom_to_atom (XA_STRING),
374 0, (65536 / sizeof(long)), 374 0, (65536 / sizeof(long)),
375 1, &actual_type, &actual_format, &nitems, &data); 375 1, &actual_type, &actual_format, &nitems, &data);
376 376
377 if (result != TRUE) { 377 if (result != TRUE) {
422 return GDK_FILTER_CONTINUE; 422 return GDK_FILTER_CONTINUE;
423 } 423 }
424 424
425 if (XGetWindowProperty (gdk_display, xid, mozilla_response, 425 if (XGetWindowProperty (gdk_display, xid, mozilla_response,
426 0, (65536 / sizeof (long)), 426 0, (65536 / sizeof (long)),
427 True, 427 True,
428 XA_STRING, 428 XA_STRING,
429 &actual_type, &actual_format, 429 &actual_type, &actual_format,
430 &nitems, &bytes_after, 430 &nitems, &bytes_after,
431 &data) != Success 431 &data) != Success
432 || data == NULL || (data[0] != '1' && data[0] != '2')) { 432 || data == NULL || (data[0] != '1' && data[0] != '2')) {
433 433
434 gaim_notify_error(NULL, NULL, 434 gaim_notify_error(NULL, NULL,
435 _("Communication with the browser failed. " 435 _("Communication with the browser failed. "
436 "Please close all windows and try again."), NULL); 436 "Please close all windows and try again."), NULL);
437 } 437 }
438 438
439 if (data[0] == '1') { 439 if (data[0] == '1') {
440 /* Netscape isn't ready yet */ 440 /* Netscape isn't ready yet */
441 gaim_debug(GAIM_DEBUG_ERROR, "browser", 441 gaim_debug(GAIM_DEBUG_ERROR, "browser",
442 "Remote Netscape window isn't ready yet.\n"); 442 "Remote Netscape window isn't ready yet.\n");
443 return GDK_FILTER_REMOVE; 443 return GDK_FILTER_REMOVE;
444 } 444 }
445 445
446 if (data[0] == '2') { 446 if (data[0] == '2') {
447 /* Yay! It worked */ 447 /* Yay! It worked */
448 gaim_debug(GAIM_DEBUG_INFO, "browser", 448 gaim_debug(GAIM_DEBUG_INFO, "browser",
449 "Successfully sent command to remote Netscape window.\n"); 449 "Successfully sent command to remote Netscape window.\n");
450 } 450 }
451 451
452 gdk_window_remove_filter(window, (GdkFilterFunc) netscape_response_cb, window); 452 gdk_window_remove_filter(window, (GdkFilterFunc) netscape_response_cb, window);
453 mozilla_remote_free_lock(window); 453 mozilla_remote_free_lock(window);
454 netscape_lock = 0; 454 netscape_lock = 0;
455 return GDK_FILTER_REMOVE; 455 return GDK_FILTER_REMOVE;
456 } 456 }
457 457
476 476
477 gaim_debug(GAIM_DEBUG_MISC, "browser", 477 gaim_debug(GAIM_DEBUG_MISC, "browser",
478 "%s: Writing " MOZILLA_COMMAND_PROP " \"%s\" to 0x%x\n", 478 "%s: Writing " MOZILLA_COMMAND_PROP " \"%s\" to 0x%x\n",
479 progname, command, (unsigned int)window); 479 progname, command, (unsigned int)window);
480 480
481 gdk_property_change(window, GDKA_MOZILLA_COMMAND, 481 gdk_property_change(window, GDKA_MOZILLA_COMMAND,
482 gdk_x11_xatom_to_atom (XA_STRING), 482 gdk_x11_xatom_to_atom (XA_STRING),
483 8, GDK_PROP_MODE_REPLACE, (unsigned char *)command, strlen(command)); 483 8, GDK_PROP_MODE_REPLACE, (unsigned char *)command, strlen(command));
484 484
485 gdk_window_add_filter(window, (GdkFilterFunc) netscape_response_cb, window); 485 gdk_window_add_filter(window, (GdkFilterFunc) netscape_response_cb, window);
486 } 486 }
487 487
488 static gboolean netscape_command(const char *command) 488 static gboolean netscape_command(const char *command)
489 { 489 {
490 GdkWindow *window = NULL; 490 GdkWindow *window = NULL;
491 491
492 if (netscape_lock) { 492 if (netscape_lock) {
493 gaim_debug(GAIM_DEBUG_WARNING, "browser", 493 gaim_debug(GAIM_DEBUG_WARNING, "browser",
494 "netscape_command() is currently in use.\n"); 494 "netscape_command() is currently in use.\n");
495 return FALSE; 495 return FALSE;
496 } 496 }
510 mozilla_remote_command(window, command, False); 510 mozilla_remote_command(window, command, False);
511 511
512 netscape_lock = 0; 512 netscape_lock = 0;
513 return TRUE; 513 return TRUE;
514 } 514 }
515 515 #endif /* _WIN32 */
516 void open_url(GtkWidget *w, const char *url) 516
517 { 517 void *
518 gaim_gtk_notify_uri(const char *uri)
519 {
520 #ifndef _WIN32
518 char *command = NULL; 521 char *command = NULL;
519 GError *error = NULL; 522 GError *error = NULL;
520 const char *web_browser; 523 const char *web_browser;
521 524
522 web_browser = gaim_prefs_get_string("/gaim/gtk/browsers/browser"); 525 web_browser = gaim_prefs_get_string("/gaim/gtk/browsers/browser");
523 526
524 if (!strcmp(web_browser, "netscape")) { 527 if (!strcmp(web_browser, "netscape")) {
525 char *args = NULL; 528 char *args = NULL;
526 529
527 if (gaim_prefs_get_bool("/gaim/gtk/browsers/new_window")) 530 if (gaim_prefs_get_bool("/gaim/gtk/browsers/new_window"))
528 args = g_strdup_printf("OpenURL(%s, new-window)", url); 531 args = g_strdup_printf("OpenURL(%s, new-window)", uri);
529 else 532 else
530 args = g_strdup_printf("OpenURL(%s)", url); 533 args = g_strdup_printf("OpenURL(%s)", uri);
531 534
532 if (netscape_command(args)) { 535 if (netscape_command(args)) {
533 g_free(args); 536 g_free(args);
534 return; 537 return NULL;
535 } 538 }
536 539
537 /* if netscape is running ... 540 /* if netscape is running ...
538 command = g_strdup_printf("netscape -remote %s", args); */ 541 command = g_strdup_printf("netscape -remote %s", args); */
539 542
540 command = g_strdup_printf("netscape \"%s\"", url); 543 command = g_strdup_printf("netscape \"%s\"", uri);
541 g_free(args); 544 g_free(args);
542 } 545 }
543 else if (!strcmp(web_browser, "opera")) { 546 else if (!strcmp(web_browser, "opera")) {
544 if (gaim_prefs_get_bool("/gaim/gtk/browsers/new_window")) 547 if (gaim_prefs_get_bool("/gaim/gtk/browsers/new_window"))
545 command = g_strdup_printf("opera -newwindow \"%s\"", url); 548 command = g_strdup_printf("opera -newwindow \"%s\"", uri);
546 else 549 else
547 command = g_strdup_printf("opera \"%s\"", url); 550 command = g_strdup_printf("opera \"%s\"", uri);
548 } 551 }
549 else if (!strcmp(web_browser, "kfmclient")) { 552 else if (!strcmp(web_browser, "kfmclient")) {
550 command = g_strdup_printf("kfmclient openURL \"%s\"", url); 553 command = g_strdup_printf("kfmclient openURL \"%s\"", uri);
551 } 554 }
552 else if (!strcmp(web_browser, "galeon")) { 555 else if (!strcmp(web_browser, "galeon")) {
553 if (gaim_prefs_get_bool("/gaim/gtk/browsers/new_window")) 556 if (gaim_prefs_get_bool("/gaim/gtk/browsers/new_window"))
554 command = g_strdup_printf("galeon -w \"%s\"", url); 557 command = g_strdup_printf("galeon -w \"%s\"", uri);
555 else 558 else
556 command = g_strdup_printf("galeon \"%s\"", url); 559 command = g_strdup_printf("galeon \"%s\"", uri);
557 } 560 }
558 else if (!strcmp(web_browser, "mozilla")) { 561 else if (!strcmp(web_browser, "mozilla")) {
559 command = g_strdup_printf("mozilla \"%s\"", url); 562 command = g_strdup_printf("mozilla \"%s\"", uri);
560 } 563 }
561 else if (!strcmp(web_browser, "custom")) { 564 else if (!strcmp(web_browser, "custom")) {
562 const char *web_command; 565 const char *web_command;
563
564 566
565 web_command = gaim_prefs_get_string("/gaim/gtk/browsers/command"); 567 web_command = gaim_prefs_get_string("/gaim/gtk/browsers/command");
566 568
567 if (web_command == NULL || *web_command == '\0') { 569 if (web_command == NULL || *web_command == '\0') {
568 gaim_notify_error(NULL, NULL, 570 gaim_notify_error(NULL, NULL,
569 _("Unable to launch your browser because " 571 _("Unable to launch your browser because "
570 "the 'Manual' browser command has been " 572 "the 'Manual' browser command has been "
571 "chosen, but no command has been set."), 573 "chosen, but no command has been set."),
572 NULL); 574 NULL);
573 return; 575 return NULL;
574 } 576 }
575 577
576 if (strstr(web_command, "%s")) 578 if (strstr(web_command, "%s"))
577 command = gaim_strreplace(web_command, "%s", url); 579 command = gaim_strreplace(web_command, "%s", uri);
578 else { 580 else {
579 /* There is no "%s" in the browser command. Assume the user 581 /*
580 * wanted the URL tacked on to the end of the command. */ 582 * There is no "%s" in the browser command. Assume the user
581 command = g_strdup_printf("%s %s", web_command, url); 583 * wanted the URL tacked on to the end of the command.
582 } 584 */
583 } 585 command = g_strdup_printf("%s %s", web_command, uri);
584 586 }
585 if (g_spawn_command_line_async(command, &error) == FALSE) { 587 }
586 char *tmp = g_strdup_printf(_("There was an error launching your chosen browser: %s"), error->message); 588
589 if (!g_spawn_command_line_async(command, &error)) {
590 char *tmp = g_strdup_printf(
591 _("There was an error launching your chosen browser: %s"),
592 error->message);
593
587 gaim_notify_error(NULL, NULL, tmp, NULL); 594 gaim_notify_error(NULL, NULL, tmp, NULL);
595
588 g_free(tmp); 596 g_free(tmp);
589 g_error_free(error); 597 g_error_free(error);
590 } 598 }
591 599
592 g_free(command); 600 g_free(command);
593 } 601
594 602 #else
595 void add_bookmark(GtkWidget *w, char *url) 603 ShellExecute(NULL, NULL, uri, NULL, ".\\", 0);
596 { 604 #endif
597 const char *web_browser; 605
598 606 return NULL;
599 web_browser = gaim_prefs_get_string("/gaim/gtk/browsers/browser"); 607 }
600
601 if (!strcmp(web_browser, "netscape")) {
602 char *command = g_strdup_printf("AddBookmark(%s)", url);
603
604 netscape_command(command);
605 g_free(command);
606 }
607 }
608
609 #else /* _WIN32 */
610
611 /* Sooner or later, I shall support Windows clicking! */
612
613 void add_bookmark(GtkWidget *w, char *url)
614 {
615 }
616 void open_url(GtkWidget *w, char *url)
617 {
618 ShellExecute(NULL, NULL, url, NULL, ".\\", 0);
619 }
620
621 #endif /* _WIN32 */