pidgin.next.minor: 2762868b: First round of GNOME URL handler support...

rlaager at pidgin.im rlaager at pidgin.im
Mon Dec 1 12:25:44 EST 2008


-----------------------------------------------------------------
Revision: 2762868b2443ad2402678378a59277332eb684f0
Ancestor: b9b075560137e0b053dd6bc930905c3a52e26973
Author: rlaager at pidgin.im
Date: 2008-11-28T00:33:40
Branch: im.pidgin.pidgin.next.minor
URL: http://d.pidgin.im/viewmtn/revision/info/2762868b2443ad2402678378a59277332eb684f0

Modified files:
        pidgin/gtkutils.c

ChangeLog: 

First round of GNOME URL handler support.

-------------- next part --------------
============================================================
--- pidgin/gtkutils.c	75858d799f47f9f20d1d701ffa18657de04f63ff
+++ pidgin/gtkutils.c	081c0bfe7a0ef4a4ab6eb375cf2ff60a5e505d54
@@ -74,6 +74,7 @@ static guint accels_save_timer = 0;
 } AopMenu;
 
 static guint accels_save_timer = 0;
+GList *gnome_url_handlers = NULL;
 
 static gboolean
 url_clicked_idle_cb(gpointer data)
@@ -3568,25 +3569,87 @@ dummy(GtkIMHtml *imhtml, GtkIMHtmlLink *
 	return TRUE;
 }
 
+gboolean
+register_gnome_url_handlers()
+{
+	char *tmp;
+	char *c;
+	char *start;
+
+	tmp = g_find_program_in_path("gconftool-2");
+	if (tmp == NULL)
+		return FALSE;
+
+	tmp = NULL;
+	if (!g_spawn_command_line_sync("gconftool-2 --all-dirs /desktop/gnome/url-handlers",
+	                               &tmp, NULL, NULL, NULL))
+		g_return_val_if_reached(FALSE);
+
+	for (c = start = tmp ; *c ; c++)
+	{
+		/* Skip leading spaces. */
+		if (c == start && *c == ' ')
+			start = c + 1;
+		else if (*c == '\n')
+		{
+			*c = '\0';
+			if (g_str_has_prefix(start, "/desktop/gnome/url-handlers/"))
+			{
+				char *protocol;
+
+				start += sizeof("/desktop/gnome/url-handlers/") - 1;
+				protocol = g_strdup_printf("%s:", start);
+				gnome_url_handlers = g_list_prepend(gnome_url_handlers, protocol);
+
+				if (!strcmp(protocol, "mailto:"))
+					gtk_imhtml_class_register_protocol(protocol, url_clicked_cb, copy_email_address);
+				else
+					gtk_imhtml_class_register_protocol(protocol, url_clicked_cb, link_context_menu);
+			}
+			start = c + 1;
+		}
+	}
+
+	return (gnome_url_handlers != NULL);
+}
+
 void pidgin_utils_init(void)
 {
+	gtk_imhtml_class_register_protocol("open://", open_dialog, dummy);
+
+	/* If we're under GNOME, try registering the system URL handlers. */
+	if (purple_running_gnome() && register_gnome_url_handlers())
+		return;
+
 	gtk_imhtml_class_register_protocol("http://", url_clicked_cb, link_context_menu);
 	gtk_imhtml_class_register_protocol("https://", url_clicked_cb, link_context_menu);
 	gtk_imhtml_class_register_protocol("ftp://", url_clicked_cb, link_context_menu);
 	gtk_imhtml_class_register_protocol("gopher://", url_clicked_cb, link_context_menu);
 	gtk_imhtml_class_register_protocol("mailto:", url_clicked_cb, copy_email_address);
-
-	gtk_imhtml_class_register_protocol("open://", open_dialog, dummy);
 }
 
 void pidgin_utils_uninit(void)
 {
+	gtk_imhtml_class_register_protocol("open://", NULL, NULL);
+
+	/* If we have GNOME handlers registered, unregister them. */
+	if (gnome_url_handlers)
+	{
+		GList *l;
+		for (l = gnome_url_handlers ; l ; l = l->next)
+		{
+			gtk_imhtml_class_register_protocol((char *)l->data, NULL, NULL);
+			g_free(l->data);
+		}
+		g_list_free(gnome_url_handlers);
+		gnome_url_handlers = NULL;
+		return;
+	}
+
 	gtk_imhtml_class_register_protocol("http://", NULL, NULL);
 	gtk_imhtml_class_register_protocol("https://", NULL, NULL);
 	gtk_imhtml_class_register_protocol("ftp://", NULL, NULL);
 	gtk_imhtml_class_register_protocol("mailto:", NULL, NULL);
 	gtk_imhtml_class_register_protocol("gopher://", NULL, NULL);
-
-	gtk_imhtml_class_register_protocol("open://", NULL, NULL);
 }
 


More information about the Commits mailing list