comparison pidgin/gtkutils.c @ 25341:5b16203f76be

First round of GNOME URL handler support.
author Richard Laager <rlaager@wiktel.com>
date Fri, 28 Nov 2008 00:33:40 +0000
parents 6d4b56b81871
children 291b84bf4f8b
comparison
equal deleted inserted replaced
25340:97f1031d9bd0 25341:5b16203f76be
72 GtkWidget *menu; 72 GtkWidget *menu;
73 gint default_item; 73 gint default_item;
74 } AopMenu; 74 } AopMenu;
75 75
76 static guint accels_save_timer = 0; 76 static guint accels_save_timer = 0;
77 GList *gnome_url_handlers = NULL;
77 78
78 static gboolean 79 static gboolean
79 url_clicked_idle_cb(gpointer data) 80 url_clicked_idle_cb(gpointer data)
80 { 81 {
81 purple_notify_uri(NULL, data); 82 purple_notify_uri(NULL, data);
3566 dummy(GtkIMHtml *imhtml, GtkIMHtmlLink *link, GtkWidget *menu) 3567 dummy(GtkIMHtml *imhtml, GtkIMHtmlLink *link, GtkWidget *menu)
3567 { 3568 {
3568 return TRUE; 3569 return TRUE;
3569 } 3570 }
3570 3571
3572 gboolean
3573 register_gnome_url_handlers()
3574 {
3575 char *tmp;
3576 char *c;
3577 char *start;
3578
3579 tmp = g_find_program_in_path("gconftool-2");
3580 if (tmp == NULL)
3581 return FALSE;
3582
3583 tmp = NULL;
3584 if (!g_spawn_command_line_sync("gconftool-2 --all-dirs /desktop/gnome/url-handlers",
3585 &tmp, NULL, NULL, NULL))
3586 g_return_val_if_reached(FALSE);
3587
3588 for (c = start = tmp ; *c ; c++)
3589 {
3590 /* Skip leading spaces. */
3591 if (c == start && *c == ' ')
3592 start = c + 1;
3593 else if (*c == '\n')
3594 {
3595 *c = '\0';
3596 if (g_str_has_prefix(start, "/desktop/gnome/url-handlers/"))
3597 {
3598 char *protocol;
3599
3600 start += sizeof("/desktop/gnome/url-handlers/") - 1;
3601 protocol = g_strdup_printf("%s:", start);
3602 gnome_url_handlers = g_list_prepend(gnome_url_handlers, protocol);
3603
3604 if (!strcmp(protocol, "mailto:"))
3605 gtk_imhtml_class_register_protocol(protocol, url_clicked_cb, copy_email_address);
3606 else
3607 gtk_imhtml_class_register_protocol(protocol, url_clicked_cb, link_context_menu);
3608 }
3609 start = c + 1;
3610 }
3611 }
3612
3613 return (gnome_url_handlers != NULL);
3614 }
3615
3571 void pidgin_utils_init(void) 3616 void pidgin_utils_init(void)
3572 { 3617 {
3618 gtk_imhtml_class_register_protocol("open://", open_dialog, dummy);
3619
3620 /* If we're under GNOME, try registering the system URL handlers. */
3621 if (purple_running_gnome() && register_gnome_url_handlers())
3622 return;
3623
3573 gtk_imhtml_class_register_protocol("http://", url_clicked_cb, link_context_menu); 3624 gtk_imhtml_class_register_protocol("http://", url_clicked_cb, link_context_menu);
3574 gtk_imhtml_class_register_protocol("https://", url_clicked_cb, link_context_menu); 3625 gtk_imhtml_class_register_protocol("https://", url_clicked_cb, link_context_menu);
3575 gtk_imhtml_class_register_protocol("ftp://", url_clicked_cb, link_context_menu); 3626 gtk_imhtml_class_register_protocol("ftp://", url_clicked_cb, link_context_menu);
3576 gtk_imhtml_class_register_protocol("gopher://", url_clicked_cb, link_context_menu); 3627 gtk_imhtml_class_register_protocol("gopher://", url_clicked_cb, link_context_menu);
3577 gtk_imhtml_class_register_protocol("mailto:", url_clicked_cb, copy_email_address); 3628 gtk_imhtml_class_register_protocol("mailto:", url_clicked_cb, copy_email_address);
3578
3579 gtk_imhtml_class_register_protocol("open://", open_dialog, dummy);
3580 } 3629 }
3581 3630
3582 void pidgin_utils_uninit(void) 3631 void pidgin_utils_uninit(void)
3583 { 3632 {
3633 gtk_imhtml_class_register_protocol("open://", NULL, NULL);
3634
3635 /* If we have GNOME handlers registered, unregister them. */
3636 if (gnome_url_handlers)
3637 {
3638 GList *l;
3639 for (l = gnome_url_handlers ; l ; l = l->next)
3640 {
3641 gtk_imhtml_class_register_protocol((char *)l->data, NULL, NULL);
3642 g_free(l->data);
3643 }
3644 g_list_free(gnome_url_handlers);
3645 gnome_url_handlers = NULL;
3646 return;
3647 }
3648
3584 gtk_imhtml_class_register_protocol("http://", NULL, NULL); 3649 gtk_imhtml_class_register_protocol("http://", NULL, NULL);
3585 gtk_imhtml_class_register_protocol("https://", NULL, NULL); 3650 gtk_imhtml_class_register_protocol("https://", NULL, NULL);
3586 gtk_imhtml_class_register_protocol("ftp://", NULL, NULL); 3651 gtk_imhtml_class_register_protocol("ftp://", NULL, NULL);
3587 gtk_imhtml_class_register_protocol("mailto:", NULL, NULL); 3652 gtk_imhtml_class_register_protocol("mailto:", NULL, NULL);
3588 gtk_imhtml_class_register_protocol("gopher://", NULL, NULL); 3653 gtk_imhtml_class_register_protocol("gopher://", NULL, NULL);
3589 3654 }
3590 gtk_imhtml_class_register_protocol("open://", NULL, NULL); 3655
3591 }
3592