pidgin.next.minor: cc734dce: Pass only the URL scheme to gtkimhtml an...

rlaager at pidgin.im rlaager at pidgin.im
Mon Dec 1 14:25:27 EST 2008


-----------------------------------------------------------------
Revision: cc734dce829ffdefc3efcf3e9d9778914406a819
Ancestor: 90550c01cd5732c944f11ea0a9a37c5ef3b8faf1
Author: rlaager at pidgin.im
Date: 2008-12-01T19:23:23
Branch: im.pidgin.pidgin.next.minor
URL: http://d.pidgin.im/viewmtn/revision/info/cc734dce829ffdefc3efcf3e9d9778914406a819

Modified files:
        pidgin/gtkimhtml.c pidgin/gtkimhtml.h pidgin/gtkutils.c

ChangeLog: 

Pass only the URL scheme to gtkimhtml and let it add the colon automatically.

-------------- next part --------------
============================================================
--- pidgin/gtkimhtml.c	3be59dd9d129a7167163a916d4b73574d7c2e7ee
+++ pidgin/gtkimhtml.c	ce9df3ada7661779ecffb588968bba05c21ba385
@@ -2641,7 +2641,7 @@ void gtk_imhtml_insert_html_at_iter(GtkI
 	c = text;
 	len = strlen(text);
 	ws = g_malloc(len + 1);
-	ws[0] = 0;
+	ws[0] = '\0';
 
 	gtk_text_buffer_begin_user_action(imhtml->text_buffer);
 	while (pos < len) {
@@ -3287,8 +3287,7 @@ void gtk_imhtml_insert_html_at_iter(GtkI
 				ws[wpos] = '\n';
 				wpos++;
 				gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
-				ws[0] = '\0';
-				wpos = 0;
+				ws[0] = '\0'; wpos = 0;
 				/* NEW_BIT (NEW_TEXT_BIT); */
 			} else if (!br) {  /* Don't insert a space immediately after an HTML break */
 				/* A newline is defined by HTML as whitespace, which means we have to replace it with a word boundary.
@@ -3299,8 +3298,7 @@ void gtk_imhtml_insert_html_at_iter(GtkI
 				ws[wpos] = ' ';
 				wpos++;
 				gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
-				ws[0] = '\0';
-				wpos = 0;
+				ws[0] = '\0'; wpos = 0;
 			}
 			c++;
 			pos++;
@@ -3308,15 +3306,14 @@ void gtk_imhtml_insert_html_at_iter(GtkI
 			br = FALSE;
 			if (wpos > 0) {
 				gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
-				ws[0] = '\0';
-				wpos = 0;
+				ws[0] = '\0'; wpos = 0;
 			}
-			while(len_protocol--){
-				/* Skip the next len_protocol characters, but make sure they're
-				   copied into the ws array.
-				*/
-				 ws [wpos++] = *c++;
-				 pos++;
+			while (len_protocol--) {
+				/* Skip the next len_protocol characters, but
+				 * make sure they're copied into the ws array.
+				 */
+				ws [wpos++] = *c++;
+				pos++;
 			}
 			if (!imhtml->edit.link) {
 				while (*c && *c != ' ') {
@@ -3364,8 +3361,7 @@ void gtk_imhtml_insert_html_at_iter(GtkI
 		ws[wpos]  = '\0';
 		gtk_text_buffer_insert(imhtml->text_buffer, &line_iter, ws, wpos);
 		gtk_text_buffer_get_end_iter(gtk_text_iter_get_buffer(&line_iter), iter);
-		ws[0] = '\0';
-		wpos = 0;
+		ws[0] = '\0'; wpos = 0;
 	}
 
 	while (fonts) {
@@ -5753,13 +5749,16 @@ gboolean gtk_imhtml_class_register_proto
 {
 	GtkIMHtmlClass *klass;
 	GtkIMHtmlProtocol *proto;
+	char *protocol;
 
 	g_return_val_if_fail(name, FALSE);
 
 	klass = g_type_class_ref(GTK_TYPE_IMHTML);
 	g_return_val_if_fail(klass, FALSE);
 
-	if ((proto = imhtml_find_protocol(name))) {
+	protocol = g_strdup_printf("%s:", name);
+	if ((proto = imhtml_find_protocol(protocol))) {
+		g_free(protocol);
 		g_return_val_if_fail(!activate, FALSE);
 		g_free(proto->name);
 		g_free(proto);
@@ -5770,8 +5769,8 @@ gboolean gtk_imhtml_class_register_proto
 	}
 
 	proto = g_new0(GtkIMHtmlProtocol, 1);
-	proto->name = g_strdup(name);
-	proto->length = strlen(name);
+	proto->name = protocol;
+	proto->length = strlen(protocol);
 	proto->activate = activate;
 	proto->context_menu = context_menu;
 	klass->protocols = g_list_prepend(klass->protocols, proto);
============================================================
--- pidgin/gtkimhtml.h	d684251b6a734966c1304959aec53134cab55408
+++ pidgin/gtkimhtml.h	691a4172b8a0441f807b7b0ea35ec75a16e5e3d6
@@ -892,7 +892,7 @@ void gtk_imhtml_smiley_destroy(GtkIMHtml
  * Register a protocol with the GtkIMHtml widget. Registering a protocol would
  * allow certain text to be clickable.
  *
- * @param name      The name of the protocol (e.g. http://)
+ * @param name      The name of the protocol (e.g. http)
  * @param activate  The callback to trigger when the protocol text is clicked.
  *                  Removes any current protocol definition if @c NULL. The
  *                  callback should return @c TRUE if the link was activated
============================================================
--- pidgin/gtkutils.c	0e691068dc109c650bcf23d24bca246fc459e581
+++ pidgin/gtkutils.c	43546c1f1475f314af1477820c9938dd38c07d9c
@@ -3569,7 +3569,7 @@ dummy(GtkIMHtml *imhtml, GtkIMHtmlLink *
 	return TRUE;
 }
 
-gboolean
+static gboolean
 register_gnome_url_handlers()
 {
 	char *tmp;
@@ -3621,10 +3621,12 @@ register_gnome_url_handlers()
 				}
 
 				start += sizeof("/desktop/gnome/url-handlers/") - 1;
-				protocol = g_strdup_printf("%s:", start);
+				protocol = g_strdup(start);
 				gnome_url_handlers = g_list_prepend(gnome_url_handlers, protocol);
 
-				if (!strcmp(protocol, "mailto:"))
+				purple_debug_info("url-handlers", "Registering handler for %s.\n", 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);
@@ -3638,22 +3640,22 @@ void pidgin_utils_init(void)
 
 void pidgin_utils_init(void)
 {
-	gtk_imhtml_class_register_protocol("open://", open_dialog, dummy);
+	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("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);
 }
 
 void pidgin_utils_uninit(void)
 {
-	gtk_imhtml_class_register_protocol("open://", NULL, NULL);
+	gtk_imhtml_class_register_protocol("open", NULL, NULL);
 
 	/* If we have GNOME handlers registered, unregister them. */
 	if (gnome_url_handlers)
@@ -3669,10 +3671,10 @@ void pidgin_utils_uninit(void)
 		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("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);
 }
 


More information about the Commits mailing list