soc.2009.webkitmessageview: e4e58d4b: Instead of using references, use copy's....
tdrhq at soc.pidgin.im
tdrhq at soc.pidgin.im
Tue Aug 25 12:06:28 EDT 2009
-----------------------------------------------------------------
Revision: e4e58d4b4143636dd7f7d688dca9378608e41afa
Ancestor: f01effe93dd666800ad333c537ceb1163f525d0a
Author: tdrhq at soc.pidgin.im
Date: 2009-08-16T07:01:11
Branch: im.pidgin.soc.2009.webkitmessageview
URL: http://d.pidgin.im/viewmtn/revision/info/e4e58d4b4143636dd7f7d688dca9378608e41afa
Modified files:
pidgin/plugins/adiumthemes/message-style.c
pidgin/plugins/adiumthemes/message-style.h
pidgin/plugins/adiumthemes/webkit.c
ChangeLog:
Instead of using references, use copy's. Sigh, I know this is a memory inefficient
design, but it's the most robust.
-------------- next part --------------
============================================================
--- pidgin/plugins/adiumthemes/message-style.c ad834e1d70c741ac42d629de3328d4a1d5962375
+++ pidgin/plugins/adiumthemes/message-style.c 1962727925f8c2959aa2a476bf1f974843e54c9f
@@ -27,8 +27,6 @@
#include <debug.h>
#include <util.h>
-static GList *style_list; /**< List of PidginMessageStyles */
-
static void
glist_free_all_string (GList *list)
{
@@ -42,16 +40,10 @@ PidginMessageStyle* pidgin_message_style
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 @@ void pidgin_message_style_unref (PidginM
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 @@ pidgin_message_style_load (const char* s
*/
/* 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 @@ pidgin_message_style_load (const char* s
}
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 @@ pidgin_message_style_load (const char* s
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)
{
============================================================
--- pidgin/plugins/adiumthemes/message-style.h d6c25ba662e6ac5d4e9c5b782b031384d0289b85
+++ pidgin/plugins/adiumthemes/message-style.h 2cfd168626c813dd9c8ccf010f3a3db589f5da75
@@ -12,10 +12,10 @@ typedef struct _PidginMessageStyle {
/* 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* pidgin_message_style
} 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);
============================================================
--- pidgin/plugins/adiumthemes/webkit.c 9f45f14be6e286d1020c86f6fbf54cb83471e547
+++ pidgin/plugins/adiumthemes/webkit.c 562f58b02a6e31cf60a67668b4734eae11eb0271
@@ -94,7 +94,7 @@ replace_message_tokens(
static char *
replace_message_tokens(
- char *text,
+ const char *text,
gsize len,
PurpleConversation *conv,
const char *name,
@@ -104,8 +104,8 @@ replace_message_tokens(
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 @@ replace_message_tokens(
} 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 @@ init_theme_for_webkit (PurpleConversatio
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 @@ init_theme_for_webkit (PurpleConversatio
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);
More information about the Commits
mailing list