diff pidgin/gtkutils.c @ 25142:38a2f78f80a7

Allow plugins to specify custom link types to the GtkIMHtml widget. Currently, the custom link types are added for all GtkIMHtml widgets. If we wanted, it should be possible to add custom links to particular widgets only too. If everything looks OK, I might merge this in before 2.6.0
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sun, 16 Nov 2008 09:58:48 +0000
parents fae699fece1f
children 284fd17c6020
line wrap: on
line diff
--- a/pidgin/gtkutils.c	Sun Nov 16 00:10:02 2008 +0000
+++ b/pidgin/gtkutils.c	Sun Nov 16 09:58:48 2008 +0000
@@ -56,6 +56,9 @@
 #include "signals.h"
 #include "util.h"
 
+#include "gtkaccount.h"
+#include "gtkprefs.h"
+
 #include "gtkconv.h"
 #include "gtkdialogs.h"
 #include "gtkimhtml.h"
@@ -80,10 +83,11 @@
 	return FALSE;
 }
 
-static void
-url_clicked_cb(GtkWidget *w, const char *uri)
+static gboolean
+url_clicked_cb(GtkIMHtml *imhtml, const char *uri)
 {
 	g_idle_add(url_clicked_idle_cb, g_strdup(uri));
+	return TRUE;
 }
 
 static GtkIMHtmlFuncs gtkimhtml_cbs = {
@@ -102,9 +106,6 @@
 	g_return_if_fail(imhtml != NULL);
 	g_return_if_fail(GTK_IS_IMHTML(imhtml));
 
-	g_signal_connect(G_OBJECT(imhtml), "url_clicked",
-					 G_CALLBACK(url_clicked_cb), NULL);
-
 	pidgin_themes_smiley_themeize(imhtml);
 
 	gtk_imhtml_set_funcs(GTK_IMHTML(imhtml), &gtkimhtml_cbs);
@@ -3480,3 +3481,47 @@
 	return pixbuf;
 }
 
+/* XXX: The following two functions are for demonstration purposes only! */
+static gboolean
+open_dialog(GtkIMHtml *imhtml, const char *url)
+{
+	const char *str;
+
+	if (strlen(url) < sizeof("open://"))
+		return FALSE;
+
+	str = url + sizeof("open://") - 1;
+
+	if (strcmp(str, "accounts") == 0)
+		pidgin_accounts_window_show();
+	else if (strcmp(str, "prefs") == 0)
+		pidgin_prefs_show();
+	else
+		return FALSE;
+	return TRUE;
+}
+
+static gboolean
+dummy(GtkIMHtml *imhtml, const char *text, GtkWidget *menu)
+{
+	return TRUE;
+}
+
+void pidgin_utils_init(void)
+{
+	gtk_imhtml_class_register_protocol("http://", url_clicked_cb, NULL);
+	gtk_imhtml_class_register_protocol("https://", url_clicked_cb, NULL);
+	gtk_imhtml_class_register_protocol("ftp://", url_clicked_cb, NULL);
+
+	gtk_imhtml_class_register_protocol("open://", open_dialog, dummy);
+}
+
+void pidgin_utils_uninit(void)
+{
+	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("open://", NULL, NULL);
+}
+