# HG changeset patch # User tdrhq@soc.pidgin.im # Date 1250406071 0 # Node ID 5281f3b3ef4c38ab5153f150d503cd1ee36f703c # Parent 285db86fcf9971120646e865a16cec92d65bc478 Instead of using references, use copy's. Sigh, I know this is a memory inefficient design, but it's the most robust. diff -r 285db86fcf99 -r 5281f3b3ef4c pidgin/plugins/adiumthemes/message-style.c --- a/pidgin/plugins/adiumthemes/message-style.c Fri Aug 14 04:47:16 2009 +0000 +++ b/pidgin/plugins/adiumthemes/message-style.c Sun Aug 16 07:01:11 2009 +0000 @@ -27,8 +27,6 @@ #include #include -static GList *style_list; /**< List of PidginMessageStyles */ - static void glist_free_all_string (GList *list) { @@ -42,16 +40,10 @@ PidginMessageStyle* pidgin_message_style_new (const char* styledir) { PidginMessageStyle* ret = g_new0 (PidginMessageStyle, 1); - GList *iter; - - /* sanity check */ - for (iter = style_list; iter; iter = g_list_next (iter)) - g_assert (!g_str_equal (((PidginMessageStyle*)iter->data)->style_dir, styledir)); ret->ref_counter = 1; ret->style_dir = g_strdup (styledir); - style_list = g_list_append (style_list, ret); return ret; } @@ -110,7 +102,6 @@ g_free (style->status_html); g_free (style->basestyle_css); - style_list = g_list_remove (style_list, style); g_free (style); pidgin_message_style_unset_info_plist (style); @@ -256,19 +247,9 @@ */ /* is this style already loaded? */ - GList *cur = style_list; char *file; /* temporary variable */ PidginMessageStyle *style = NULL; - g_assert (styledir); - for (cur = style_list; cur; cur = g_list_next (cur)) { - style = (PidginMessageStyle*) cur->data; - if (g_str_equal (styledir, style->style_dir)) { - style->ref_counter++; - return style; - } - } - /* else we need to load it */ style = pidgin_message_style_new (styledir); @@ -284,8 +265,8 @@ } if (!g_file_get_contents(style->template_path, &style->template_html, NULL, NULL)) { + purple_debug_error ("webkit", "Could not locate a Template.html (%s)\n", style->template_path); pidgin_message_style_unref (style); - purple_debug_error ("webkit", "Could not locate a Template.html\n"); return NULL; } @@ -364,6 +345,41 @@ return style; } +PidginMessageStyle* +pidgin_message_style_copy (const PidginMessageStyle *style) +{ + /* it's at times like this that I miss C++ */ + PidginMessageStyle *ret = pidgin_message_style_new (style->style_dir); + + ret->variant = g_strdup (style->variant); + ret->message_view_version = style->message_view_version; + ret->cf_bundle_name = g_strdup (style->cf_bundle_name); + ret->cf_bundle_identifier = g_strdup (style->cf_bundle_identifier); + ret->cf_bundle_get_info_string = g_strdup (style->cf_bundle_get_info_string); + ret->default_font_family = g_strdup (style->default_font_family); + ret->default_font_size = style->default_font_size; + ret->shows_user_icons = style->shows_user_icons; + ret->disable_combine_consecutive = style->disable_combine_consecutive; + ret->default_background_is_transparent = style->default_background_is_transparent; + ret->disable_custom_background = style->disable_custom_background; + ret->default_background_color = g_strdup (style->default_background_color); + ret->allow_text_colors = style->allow_text_colors; + ret->image_mask = g_strdup (style->image_mask); + ret->default_variant = g_strdup (style->default_variant); + + ret->template_path = g_strdup (style->template_path); + ret->template_html = g_strdup (style->template_html); + ret->header_html = g_strdup (style->header_html); + ret->footer_html = g_strdup (style->footer_html); + ret->incoming_content_html = g_strdup (style->incoming_content_html); + ret->outgoing_content_html = g_strdup (style->outgoing_content_html); + ret->incoming_next_content_html = g_strdup (style->incoming_next_content_html); + ret->outgoing_next_content_html = g_strdup (style->outgoing_next_content_html); + ret->status_html = g_strdup (style->status_html); + ret->basestyle_css = g_strdup (style->basestyle_css); + return ret; +} + void pidgin_message_style_set_variant (PidginMessageStyle *style, const char *variant) { diff -r 285db86fcf99 -r 5281f3b3ef4c pidgin/plugins/adiumthemes/message-style.h --- a/pidgin/plugins/adiumthemes/message-style.h Fri Aug 14 04:47:16 2009 +0000 +++ b/pidgin/plugins/adiumthemes/message-style.h Sun Aug 16 07:01:11 2009 +0000 @@ -12,10 +12,10 @@ /* current config options */ char *variant; /* allowed to be NULL if there are no variants */ - gboolean show_user_icons; + /* Info.plist keys that change with Variant */ - /* Info.plist keys */ + /* Static Info.plist keys */ int message_view_version; char *cf_bundle_name; char *cf_bundle_identifier; @@ -48,6 +48,7 @@ } PidginMessageStyle; PidginMessageStyle* pidgin_message_style_load (const char* styledir); +PidginMessageStyle* pidgin_message_style_copy (const PidginMessageStyle *style); void pidgin_message_style_unref (PidginMessageStyle *style); void pidgin_message_style_read_info_plist (PidginMessageStyle *style, const char* variant); char* pidgin_message_style_get_variant (PidginMessageStyle *style); diff -r 285db86fcf99 -r 5281f3b3ef4c pidgin/plugins/adiumthemes/webkit.c --- 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);