comparison src/gtknotify.c @ 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 62af52b1614a
children e6ed38d28636
comparison
equal deleted inserted replaced
8271:5c9cd9c97727 8272:9af78e73f0b2
286 GtkWidget *imhtml; 286 GtkWidget *imhtml;
287 GtkWidget *sw; 287 GtkWidget *sw;
288 GSList *images = NULL; 288 GSList *images = NULL;
289 int options = 0; 289 int options = 0;
290 char label_text[2048]; 290 char label_text[2048];
291 char *linked_text; 291 char *linked_text;
292 292
293 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 293 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
294 gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG); 294 gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG);
295 gtk_container_set_border_width(GTK_CONTAINER(window), 12); 295 gtk_container_set_border_width(GTK_CONTAINER(window), 12);
296 296
359 options ^= GTK_IMHTML_NO_TITLE; 359 options ^= GTK_IMHTML_NO_TITLE;
360 options ^= GTK_IMHTML_NO_NEWLINE; 360 options ^= GTK_IMHTML_NO_NEWLINE;
361 options ^= GTK_IMHTML_NO_SCROLL; 361 options ^= GTK_IMHTML_NO_SCROLL;
362 362
363 gaim_gtk_find_images(text, &images); 363 gaim_gtk_find_images(text, &images);
364 if(gaim_prefs_get_bool("/gaim/gtk/conversations/show_urls_as_links")){ 364 if(gaim_prefs_get_bool("/gaim/gtk/conversations/show_urls_as_links")){
365 linked_text = gaim_markup_linkify(text); 365 linked_text = gaim_markup_linkify(text);
366 gtk_imhtml_append_text_with_images(GTK_IMHTML(imhtml), linked_text, 366 gtk_imhtml_append_text_with_images(GTK_IMHTML(imhtml), linked_text,
367 options, images); 367 options, images);
368 g_free(linked_text); 368 g_free(linked_text);
369 } else 369 } else
370 gtk_imhtml_append_text_with_images(GTK_IMHTML(imhtml), text, options, images); 370 gtk_imhtml_append_text_with_images(GTK_IMHTML(imhtml), text, options, images);
371 371
372 if (images) { 372 if (images) {
373 GSList *tmp; 373 GSList *tmp;
374 374
400 } 400 }
401 else 401 else
402 gtk_widget_destroy(GTK_WIDGET(ui_handle)); 402 gtk_widget_destroy(GTK_WIDGET(ui_handle));
403 } 403 }
404 404
405 #ifndef _WIN32
406 static gint
407 uri_command(const char *command, const gboolean sync)
408 {
409 GError *error = NULL;
410 gint ret = 0;
411
412 if (!gaim_program_is_valid(command)) {
413 gchar *tmp = g_strdup_printf(_("The browser \"%s\" is invalid."),
414 command);
415 gaim_notify_error(NULL, NULL, _("Unable to open URL"), tmp);
416 g_free(tmp);
417
418 } else if (sync) {
419 gint status;
420
421 if (!g_spawn_command_line_sync(command, NULL, NULL, &status, &error)) {
422 char *tmp = g_strdup_printf(
423 _("Error launching \"command\": %s"),
424 error->message);
425
426 gaim_notify_error(NULL, NULL, _("Unable to open URL"), tmp);
427
428 g_free(tmp);
429 g_error_free(error);
430 } else {
431 ret = status;
432 }
433
434 } else {
435 if (!g_spawn_command_line_async(command, &error)) {
436 char *tmp = g_strdup_printf(
437 _("Error launching \"command\": %s"),
438 error->message);
439
440 gaim_notify_error(NULL, NULL, _("Unable to open URL"), tmp);
441
442 g_free(tmp);
443 g_error_free(error);
444 }
445 }
446
447 printf("command: %d = %s\n", ret, command);
448 return ret;
449 }
450 #endif
451
405 static void * 452 static void *
406 gaim_gtk_notify_uri(const char *uri) 453 gaim_gtk_notify_uri(const char *uri)
407 { 454 {
408 #ifndef _WIN32 455 #ifndef _WIN32
409 char *command = NULL; 456 char *command = NULL;
410 GError *error = NULL; 457 char *remote_command = NULL;
411 const char *web_browser; 458 const char *web_browser;
459 int place;
412 460
413 web_browser = gaim_prefs_get_string("/gaim/gtk/browsers/browser"); 461 web_browser = gaim_prefs_get_string("/gaim/gtk/browsers/browser");
462 place = gaim_prefs_get_int("/gaim/gtk/browsers/place");
414 463
415 if (!strcmp(web_browser, "netscape")) { 464 if (!strcmp(web_browser, "netscape")) {
416 command = g_strdup_printf("netscape \"%s\"", uri); 465 command = g_strdup_printf("netscape \"%s\"", uri);
466 if (place == GAIM_BROWSER_NEW_WINDOW)
467 remote_command = g_strdup_printf("netscape -remote \"openURL(\"%s\",new-window)\"", uri);
468 else if (place == GAIM_BROWSER_CURRENT)
469 remote_command = g_strdup_printf("netscape -remote \"openURL(\"%s\")\"", uri);
470
417 } else if (!strcmp(web_browser, "opera")) { 471 } else if (!strcmp(web_browser, "opera")) {
418 if (gaim_prefs_get_bool("/gaim/gtk/browsers/new_window")) 472 if (place == GAIM_BROWSER_NEW_WINDOW)
419 command = g_strdup_printf("opera -newwindow \"%s\"", uri); 473 command = g_strdup_printf("opera -newwindow \"%s\"", uri);
420 else 474 else if (place == GAIM_BROWSER_NEW_TAB)
475 command = g_strdup_printf("opera -newpage \"%s\"", uri);
476 else if (place == GAIM_BROWSER_CURRENT) {
477 remote_command = g_strdup_printf("opera -remote \"openURL(\"%s\")\"", uri);
421 command = g_strdup_printf("opera \"%s\"", uri); 478 command = g_strdup_printf("opera \"%s\"", uri);
479 } else
480 command = g_strdup_printf("opera \"%s\"", uri);
481
422 } else if (!strcmp(web_browser, "kfmclient")) { 482 } else if (!strcmp(web_browser, "kfmclient")) {
423 command = g_strdup_printf("kfmclient openURL \"%s\"", uri); 483 command = g_strdup_printf("kfmclient openURL \"%s\"", uri);
484 /* does Konqueror have options to open in new tab and/or current window? */
485
424 } else if (!strcmp(web_browser, "galeon")) { 486 } else if (!strcmp(web_browser, "galeon")) {
425 if (gaim_prefs_get_bool("/gaim/gtk/browsers/new_window")) 487 if (place == GAIM_BROWSER_NEW_WINDOW)
426 command = g_strdup_printf("galeon -w \"%s\"", uri); 488 command = g_strdup_printf("galeon -w \"%s\"", uri);
489 else if (place == GAIM_BROWSER_NEW_TAB)
490 command = g_strdup_printf("galeon -n \"%s\"", uri);
427 else 491 else
428 command = g_strdup_printf("galeon \"%s\"", uri); 492 command = g_strdup_printf("galeon \"%s\"", uri);
429 } else if (!strcmp(web_browser, "mozilla")) { 493
430 command = g_strdup_printf("mozilla \"%s\"", uri); 494 } else if (!strcmp(web_browser, "mozilla") ||
431 } else if (!strcmp(web_browser, "mozilla-firebird")) { 495 !strcmp(web_browser, "mozilla-firebird") ||
432 command = g_strdup_printf("mozilla-firebird \"%s\"", uri); 496 !strcmp(web_browser, "firefox")) {
433 } else if (!strcmp(web_browser, "firefox")) { 497 command = g_strdup_printf("%s \"%s\"", web_browser, uri);
434 command = g_strdup_printf("firefox \"%s\"", uri); 498 if (place == GAIM_BROWSER_NEW_WINDOW)
499 remote_command = g_strdup_printf("%s -remote \"openURL(\"%s\",new-window)\"", web_browser, uri);
500 else if (place == GAIM_BROWSER_NEW_TAB)
501 remote_command = g_strdup_printf("%s -remote \"openURL(\"%s\",new-tab)\"", web_browser, uri);
502 else if (place == GAIM_BROWSER_CURRENT)
503 remote_command = g_strdup_printf("%s -remote \"openURL(\"%s\")\"", web_browser, uri);
504
435 } else if (!strcmp(web_browser, "custom")) { 505 } else if (!strcmp(web_browser, "custom")) {
436 const char *web_command; 506 const char *web_command;
437 507
438 web_command = gaim_prefs_get_string("/gaim/gtk/browsers/command"); 508 web_command = gaim_prefs_get_string("/gaim/gtk/browsers/command");
439 509
453 */ 523 */
454 command = g_strdup_printf("%s %s", web_command, uri); 524 command = g_strdup_printf("%s %s", web_command, uri);
455 } 525 }
456 } 526 }
457 527
458 if (!gaim_program_is_valid(command)) { 528 if (remote_command != NULL) {
459 gchar *tmp = g_strdup_printf(_("The browser \"%s\" is invalid."), 529 /* try the remote command first */
460 command); 530 if (uri_command(remote_command, TRUE) != 0)
461 gaim_notify_error(NULL, NULL, _("Unable to open URL"), tmp); 531 uri_command(command, FALSE);
462 g_free(tmp); 532 g_free(remote_command);
463 533 } else {
464 } else if (!g_spawn_command_line_async(command, &error)) { 534 uri_command(command, FALSE);
465 char *tmp = g_strdup_printf(
466 _("Error launching \"command\": %s"),
467 error->message);
468
469 gaim_notify_error(NULL, NULL, _("Unable to open URL"), tmp);
470
471 g_free(tmp);
472 g_error_free(error);
473 } 535 }
474 536
475 g_free(command); 537 g_free(command);
476 538
477 #else 539 #else