changeset 25869:7524f9a084ff

merge of 'abbc5b388482e59667d5f7950b41fc554d9332c5' and 'ae1747d0fffb12e2729f1ed66aff8083309ec96b'
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Tue, 02 Dec 2008 19:24:57 +0000
parents d5852f7208fa (current diff) ba083e5f633b (diff)
children d9da15c9e2a1
files
diffstat 2 files changed, 31 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkimhtml.c	Tue Dec 02 01:51:55 2008 +0000
+++ b/pidgin/gtkimhtml.c	Tue Dec 02 19:24:57 2008 +0000
@@ -1411,16 +1411,17 @@
 }
 
 static GtkIMHtmlProtocol *
-imhtml_find_protocol(const char *url)
+imhtml_find_protocol(const char *url, gboolean reverse)
 {
 	GtkIMHtmlClass *klass;
 	GList *iter;
 	GtkIMHtmlProtocol *proto = NULL;
+	int length = reverse ? strlen(url) : -1;
 
 	klass = g_type_class_ref(GTK_TYPE_IMHTML);
 	for (iter = klass->protocols; iter; iter = iter->next) {
 		proto = iter->data;
-		if (g_ascii_strncasecmp(url, proto->name, proto->length) == 0) {
+		if (g_ascii_strncasecmp(url, proto->name, reverse ? MIN(length, proto->length) : proto->length) == 0) {
 			return proto;
 		}
 	}
@@ -1430,7 +1431,7 @@
 static void
 imhtml_url_clicked(GtkIMHtml *imhtml, const char *url)
 {
-	GtkIMHtmlProtocol *proto = imhtml_find_protocol(url);
+	GtkIMHtmlProtocol *proto = imhtml_find_protocol(url, FALSE);
 	GtkIMHtmlLink *link;
 	if (!proto)
 		return;
@@ -1790,7 +1791,7 @@
 			g_object_set_data_full(G_OBJECT(menu), "x-imhtml-url-data", link,
 					(GDestroyNotify)gtk_imhtml_link_destroy);
 
-			proto = imhtml_find_protocol(link->url);
+			proto = imhtml_find_protocol(link->url, FALSE);
 
 			if (proto && proto->context_menu) {
 				proto->context_menu(GTK_IMHTML(link->imhtml), link, menu);
@@ -2386,7 +2387,7 @@
    the caller knows how long the protocol string is. */
 static int gtk_imhtml_is_protocol(const char *text)
 {
-	GtkIMHtmlProtocol *proto = imhtml_find_protocol(text);
+	GtkIMHtmlProtocol *proto = imhtml_find_protocol(text, FALSE);
 	return proto ? proto->length : 0;
 }
 
@@ -3302,7 +3303,8 @@
 			}
 			c++;
 			pos++;
-		} else if ((len_protocol = gtk_imhtml_is_protocol(c)) > 0){
+		} else if ((pos == 0 || wpos == 0 || isspace(*(c - 1))) &&
+		           (len_protocol = gtk_imhtml_is_protocol(c)) > 0) {
 			br = FALSE;
 			if (wpos > 0) {
 				gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
@@ -5755,14 +5757,16 @@
 	klass = g_type_class_ref(GTK_TYPE_IMHTML);
 	g_return_val_if_fail(klass, FALSE);
 
-	if ((proto = imhtml_find_protocol(name))) {
-		g_return_val_if_fail(!activate, FALSE);
+	if ((proto = imhtml_find_protocol(name, TRUE))) {
+		if (activate) {
+			return FALSE;
+		}
 		g_free(proto->name);
 		g_free(proto);
 		klass->protocols = g_list_remove(klass->protocols, proto);
 		return TRUE;
-	} else {
-		g_return_val_if_fail(activate, FALSE);
+	} else if (!activate) {
+		return FALSE;
 	}
 
 	proto = g_new0(GtkIMHtmlProtocol, 1);
--- a/pidgin/gtkutils.c	Tue Dec 02 01:51:55 2008 +0000
+++ b/pidgin/gtkutils.c	Tue Dec 02 19:24:57 2008 +0000
@@ -74,7 +74,7 @@
 } AopMenu;
 
 static guint accels_save_timer = 0;
-GList *gnome_url_handlers = NULL;
+static GList *gnome_url_handlers = NULL;
 
 static gboolean
 url_clicked_idle_cb(gpointer data)
@@ -3570,7 +3570,7 @@
 }
 
 static gboolean
-register_gnome_url_handlers()
+register_gnome_url_handlers(void)
 {
 	char *tmp;
 	char *err;
@@ -3585,6 +3585,7 @@
 	if (!g_spawn_command_line_sync("gconftool-2 --all-dirs /desktop/gnome/url-handlers",
 	                               &tmp, &err, NULL, NULL))
 	{
+		g_free(tmp);
 		g_free(err);
 		g_return_val_if_reached(FALSE);
 	}
@@ -3610,55 +3611,46 @@
 				if (g_spawn_command_line_sync(cmd, &tmp2, &err, NULL, NULL))
 				{
 					g_free(err);
+					err = NULL;
 					if (!strcmp(tmp2, "false\n"))
 					{
 						g_free(tmp2);
+						g_free(cmd);
 						start = c + 1;
 						continue;
 					}
-					else
-						g_free(tmp2);
 				}
+				g_free(cmd);
+				g_free(tmp2);
 
 				start += sizeof("/desktop/gnome/url-handlers/") - 1;
 
-				/* It would be nice if this was tracked in gconf. */
-				if (!strcmp(start, "ftp") ||
-				    !strcmp(start, "gopher") ||
-				    !strcmp(start, "http") ||
-				    !strcmp(start, "https"))
-					protocol = g_strdup_printf("%s://", start);
-				else
-					protocol = g_strdup_printf("%s:", start);
-
-				/* We need to free this later. */
+				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);
+				gtk_imhtml_class_register_protocol(protocol, url_clicked_cb, link_context_menu);
 			}
 			start = c + 1;
 		}
 	}
+	g_free(tmp);
 
 	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);
+
+	/* Example custom URL handler. */
+	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();
 }
 
 void pidgin_utils_uninit(void)