diff pidgin/plugins/adiumthemes/webkit.c @ 32107:5281f3b3ef4c

Instead of using references, use copy's. Sigh, I know this is a memory inefficient design, but it's the most robust.
author tdrhq@soc.pidgin.im
date Sun, 16 Aug 2009 07:01:11 +0000
parents 285db86fcf99
children 79f5a5e75152
line wrap: on
line diff
--- a/pidgin/plugins/adiumthemes/webkit.c	Fri Aug 14 04:47:16 2009 +0000
+++ b/pidgin/plugins/adiumthemes/webkit.c	Sun Aug 16 07:01:11 2009 +0000
@@ -94,7 +94,7 @@
 
 static char *
 replace_message_tokens(
-	char *text, 
+	const char *text, 
 	gsize len, 
 	PurpleConversation *conv, 
 	const char *name, 
@@ -104,8 +104,8 @@
 	time_t mtime)
 {
 	GString *str = g_string_new_len(NULL, len);
-	char *cur = text;
-	char *prev = cur;
+	const char *cur = text;
+	const char *prev = cur;
 
 	while ((cur = strchr(cur, '%'))) {
 		const char *replace = NULL;
@@ -119,7 +119,7 @@
 		} else if (!strncmp(cur, "%time", strlen("%time"))) {
 			char *format = NULL;
 			if (*(cur + strlen("%time")) == '{') {
-				char *start = cur + strlen("%time") + 1;
+				const char *start = cur + strlen("%time") + 1;
 				char *end = strstr(start, "}%");
 				if (!end) /* Invalid string */
 					continue;
@@ -333,11 +333,12 @@
 	PidginMessageStyle *style, *oldStyle;
 	oldStyle = g_object_get_data (G_OBJECT(webkit), MESSAGE_STYLE_KEY);
 	
-	if (oldStyle) return;
+	g_return_if_fail (!oldStyle);
 
 	purple_debug_info ("webkit", "loading %s\n", style_dir);
 	style = pidgin_message_style_load (style_dir);
 	g_assert (style);
+	g_assert (style->template_html); /* debugging test? */
 
 	basedir = g_build_filename (style->style_dir, "Contents", "Resources", "Template.html", NULL);
 	baseuri = g_strdup_printf ("file://%s", basedir);
@@ -353,10 +354,12 @@
 	set_theme_webkit_settings (WEBKIT_WEB_VIEW(webkit), style);
 	webkit_web_view_load_string(WEBKIT_WEB_VIEW(webkit), template, "text/html", "UTF-8", baseuri);
 
-	g_object_set_data (G_OBJECT(webkit), MESSAGE_STYLE_KEY, style);
+	PidginMessageStyle *copy = pidgin_message_style_copy (style);
+	g_object_set_data (G_OBJECT(webkit), MESSAGE_STYLE_KEY, copy);
 	
+	pidgin_message_style_unref (style);
 	/* I need to unref this style when the webkit object destroys */
-	g_signal_connect (G_OBJECT(webkit), "destroy", G_CALLBACK(webkit_on_webview_destroy), style);
+	g_signal_connect (G_OBJECT(webkit), "destroy", G_CALLBACK(webkit_on_webview_destroy), copy);
 
 	g_free (basedir);
 	g_free (baseuri);