pidgin/plugins/adiumthemes/message-style.c

Fri, 16 Sep 2011 06:10:04 +0000

author
Elliott Sales de Andrade <qulogic@pidgin.im>
date
Fri, 16 Sep 2011 06:10:04 +0000
changeset 32534
0fb9ddb72e3e
parent 32515
43b517b313a2
permissions
-rw-r--r--

Add a WebKit Development plugin, that allows opening the builtin
inspector on a view. To use, activate the plugin, right-click a view,
and select 'Inspect Element'.

32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
1 /* pidgin
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
2 *
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
3 * Pidgin is the legal property of its developers, whose names are too numerous
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
4 * to list here. Please refer to the COPYRIGHT file distributed with this
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
5 * source distribution.
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
6 *
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
7 * This program is free software; you can redistribute it and/or modify
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
8 * it under the terms of the GNU General Public License as published by
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
10 * (at your option) any later version.
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
11 *
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
12 * This program is distributed in the hope that it will be useful,
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
15 * GNU General Public License for more details.
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
16 *
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
20 *
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
21 */
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
22
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
23 #include "message-style.h"
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
24
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
25 #include <string.h>
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
26
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
27 #include <glib.h>
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
28
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
29 #include <debug.h>
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
30 #include <util.h>
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
31
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
32 static void
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
33 glist_free_all_string(GList *list)
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
34 {
32515
43b517b313a2 Simplify, don't loop through list twice.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32514
diff changeset
35 for (; list; list = g_list_delete_link(list, list))
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
36 g_free(list->data);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
37 }
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
38
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
39 static PidginMessageStyle *
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
40 pidgin_message_style_new(const char *styledir)
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
41 {
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
42 PidginMessageStyle *ret = g_new0(PidginMessageStyle, 1);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
43
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
44 ret->ref_counter = 1;
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
45 ret->style_dir = g_strdup(styledir);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
46
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
47 return ret;
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
48 }
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
49
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
50 void
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
51 pidgin_message_style_unref(PidginMessageStyle *style)
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
52 {
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
53 if (!style)
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
54 return;
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
55 g_assert (style->ref_counter > 0);
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
56
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
57 style->ref_counter--;
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
58 if (style->ref_counter)
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
59 return;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
60
32514
2477c1e93890 Remove unnecessary function. It's also a use-after-free.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32513
diff changeset
61 g_free(style->cf_bundle_name);
2477c1e93890 Remove unnecessary function. It's also a use-after-free.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32513
diff changeset
62 g_free(style->cf_bundle_identifier);
2477c1e93890 Remove unnecessary function. It's also a use-after-free.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32513
diff changeset
63 g_free(style->cf_bundle_get_info_string);
2477c1e93890 Remove unnecessary function. It's also a use-after-free.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32513
diff changeset
64 g_free(style->default_font_family);
2477c1e93890 Remove unnecessary function. It's also a use-after-free.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32513
diff changeset
65 g_free(style->default_background_color);
2477c1e93890 Remove unnecessary function. It's also a use-after-free.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32513
diff changeset
66 g_free(style->image_mask);
2477c1e93890 Remove unnecessary function. It's also a use-after-free.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32513
diff changeset
67 g_free(style->default_variant);
2477c1e93890 Remove unnecessary function. It's also a use-after-free.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32513
diff changeset
68
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
69 g_free(style->style_dir);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
70 g_free(style->template_path);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
71
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
72 g_free(style->template_html);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
73 g_free(style->incoming_content_html);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
74 g_free(style->outgoing_content_html);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
75 g_free(style->outgoing_next_content_html);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
76 g_free(style->status_html);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
77 g_free(style->basestyle_css);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
78
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
79 g_free(style);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
80 }
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
81
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
82 void
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
83 pidgin_message_style_save_state(const PidginMessageStyle *style)
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
84 {
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
85 char *prefname = g_strdup_printf("/plugins/gtk/adiumthemes/%s", style->cf_bundle_identifier);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
86 char *variant = g_strdup_printf("%s/variant", prefname);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
87
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
88 purple_debug_info("webkit", "saving state with variant %s\n", style->variant);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
89 purple_prefs_add_none(prefname);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
90 purple_prefs_add_string(variant, "");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
91 purple_prefs_set_string(variant, style->variant);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
92
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
93 g_free(prefname);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
94 g_free(variant);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
95 }
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
96
32491
c917d2ba4a38 Read AllowTextColors key properly.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32488
diff changeset
97 static void
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
98 pidgin_message_style_load_state(PidginMessageStyle *style)
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
99 {
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
100 char *prefname = g_strdup_printf("/plugins/gtk/adiumthemes/%s", style->cf_bundle_identifier);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
101 char *variant = g_strdup_printf("%s/variant", prefname);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
102
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
103 const char* value = purple_prefs_get_string(variant);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
104 gboolean changed = !style->variant || !g_str_equal(style->variant, value);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
105
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
106 g_free(style->variant);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
107 style->variant = g_strdup(value);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
108
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
109 if (changed)
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
110 pidgin_message_style_read_info_plist(style, style->variant);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
111
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
112 g_free(prefname);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
113 g_free(variant);
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
114 }
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
115
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
116
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
117 static gboolean
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
118 parse_info_plist_key_value(xmlnode* key, gpointer destination, const char* expected)
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
119 {
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
120 xmlnode *val = key->next;
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
121
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
122 for (; val && val->type != XMLNODE_TYPE_TAG; val = val->next)
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
123 ;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
124 if (!val)
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
125 return FALSE;
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
126
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
127 if (expected == NULL || g_str_equal(expected, "string")) {
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
128 char **dest = (char **)destination;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
129 if (!g_str_equal(val->name, "string"))
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
130 return FALSE;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
131 if (*dest)
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
132 g_free(*dest);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
133 *dest = xmlnode_get_data_unescaped(val);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
134 } else if (g_str_equal(expected, "integer")) {
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
135 int *dest = (int *)destination;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
136 char *value = xmlnode_get_data_unescaped(val);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
137
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
138 if (!g_str_equal(val->name, "integer"))
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
139 return FALSE;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
140 *dest = atoi(value);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
141 g_free(value);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
142 } else if (g_str_equal(expected, "boolean")) {
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
143 gboolean *dest = (gboolean *)destination;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
144 if (g_str_equal(val->name, "true"))
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
145 *dest = TRUE;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
146 else if (g_str_equal(val->name, "false"))
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
147 *dest = FALSE;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
148 else
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
149 return FALSE;
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
150 } else return FALSE;
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
151
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
152 return TRUE;
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
153 }
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
154
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
155 static gboolean
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
156 str_for_key(const char *key, const char *found, const char *variant)
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
157 {
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
158 if (g_str_equal(key, found))
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
159 return TRUE;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
160 if (!variant)
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
161 return FALSE;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
162 return (g_str_has_prefix(found, key)
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
163 && g_str_has_suffix(found, variant)
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
164 && strlen(found) == strlen(key) + strlen(variant) + 1);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
165 }
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
166
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
167 /**
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
168 * Info.plist should be re-read every time the variant changes, this is because
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
169 * the keys that take precedence depend on the value of the current variant.
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
170 */
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
171 void
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
172 pidgin_message_style_read_info_plist(PidginMessageStyle *style, const char *variant)
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
173 {
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
174 /* note that if a variant is used the option:VARIANTNAME takes precedence */
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
175 char *contents = g_build_filename(style->style_dir, "Contents", NULL);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
176 xmlnode *plist = xmlnode_from_file(contents, "Info.plist", "Info.plist", "webkit"), *iter;
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
177 xmlnode *dict = xmlnode_get_child(plist, "dict");
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
178
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
179 g_assert (dict);
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
180 for (iter = xmlnode_get_child(dict, "key"); iter; iter = xmlnode_get_next_twin(iter)) {
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
181 char* key = xmlnode_get_data_unescaped(iter);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
182 gboolean pr = TRUE;
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
183
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
184 if (g_str_equal("MessageViewVersion", key))
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
185 pr = parse_info_plist_key_value(iter, &style->message_view_version, "integer");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
186 else if (g_str_equal("CFBundleName", key))
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
187 pr = parse_info_plist_key_value(iter, &style->cf_bundle_name, "string");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
188 else if (g_str_equal("CFBundleIdentifier", key))
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
189 pr = parse_info_plist_key_value(iter, &style->cf_bundle_identifier, "string");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
190 else if (g_str_equal("CFBundleGetInfoString", key))
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
191 pr = parse_info_plist_key_value(iter, &style->cf_bundle_get_info_string, "string");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
192 else if (str_for_key("DefaultFontFamily", key, variant))
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
193 pr = parse_info_plist_key_value(iter, &style->default_font_family, "string");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
194 else if (str_for_key("DefaultFontSize", key, variant))
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
195 pr = parse_info_plist_key_value(iter, &style->default_font_size, "integer");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
196 else if (str_for_key("ShowsUserIcons", key, variant))
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
197 pr = parse_info_plist_key_value(iter, &style->shows_user_icons, "boolean");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
198 else if (str_for_key("DisableCombineConsecutive", key, variant))
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
199 pr = parse_info_plist_key_value(iter, &style->disable_combine_consecutive, "boolean");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
200 else if (str_for_key("DefaultBackgroundIsTransparent", key, variant))
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
201 pr = parse_info_plist_key_value(iter, &style->default_background_is_transparent, "boolean");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
202 else if (str_for_key("DisableCustomBackground", key, variant))
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
203 pr = parse_info_plist_key_value(iter, &style->disable_custom_background, "boolean");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
204 else if (str_for_key("DefaultBackgroundColor", key, variant))
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
205 pr = parse_info_plist_key_value(iter, &style->default_background_color, "string");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
206 else if (str_for_key("AllowTextColors", key, variant))
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
207 pr = parse_info_plist_key_value(iter, &style->allow_text_colors, "integer");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
208 else if (str_for_key("ImageMask", key, variant))
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
209 pr = parse_info_plist_key_value(iter, &style->image_mask, "string");
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
210
32491
c917d2ba4a38 Read AllowTextColors key properly.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32488
diff changeset
211 if (!pr)
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
212 purple_debug_warning("webkit", "Failed to parse key %s\n", key);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
213 g_free(key);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
214 }
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
215
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
216 xmlnode_free(plist);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
217 }
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
218
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
219 PidginMessageStyle *
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
220 pidgin_message_style_load(const char *styledir)
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
221 {
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
222 /*
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
223 * the loading process described:
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
224 *
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
225 * First we load all the style .html files, etc.
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
226 * The we load any config options that have been stored for
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
227 * this variant.
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
228 * Then we load the Info.plist, for the currently decided variant.
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
229 * At this point, if we find that variants exist, yet
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
230 * we don't have a variant selected, we choose DefaultVariant
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
231 * and if that does not exist, we choose the first one in the
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
232 * directory.
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
233 */
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
234 char *file;
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
235 PidginMessageStyle *style = NULL;
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
236
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
237 style = pidgin_message_style_new(styledir);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
238
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
239 /* load all other files */
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
240
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
241 /* The template path can either come from the theme, or can
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
242 * be stock Template.html that comes with the plugin */
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
243 style->template_path = g_build_filename(styledir, "Contents", "Resources", "Template.html", NULL);
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
244
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
245 if (!g_file_test(style->template_path, G_FILE_TEST_EXISTS)) {
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
246 g_free(style->template_path);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
247 style->template_path = g_build_filename(DATADIR, "pidgin", "webkit", "Template.html", NULL);
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
248 }
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
249
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
250 if (!g_file_get_contents(style->template_path, &style->template_html, NULL, NULL)) {
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
251 purple_debug_error("webkit", "Could not locate a Template.html (%s)\n", style->template_path);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
252 pidgin_message_style_unref(style);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
253 return NULL;
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
254 }
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
255
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
256 file = g_build_filename(styledir, "Contents", "Resources", "Status.html", NULL);
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
257 if (!g_file_get_contents(file, &style->status_html, NULL, NULL)) {
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
258 purple_debug_info("webkit", "%s could not find Resources/Status.html", styledir);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
259 pidgin_message_style_unref(style);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
260 g_free(file);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
261 return NULL;
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
262 }
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
263 g_free(file);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
264
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
265 file = g_build_filename(styledir, "Contents", "Resources", "main.css", NULL);
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
266 if (!g_file_get_contents(file, &style->basestyle_css, NULL, NULL))
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
267 style->basestyle_css = g_strdup("");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
268 g_free(file);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
269
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
270 file = g_build_filename(styledir, "Contents", "Resources", "Header.html", NULL);
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
271 if (!g_file_get_contents(file, &style->header_html, NULL, NULL))
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
272 style->header_html = g_strdup("");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
273 g_free(file);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
274
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
275 file = g_build_filename(styledir, "Contents", "Resources", "Footer.html", NULL);
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
276 if (!g_file_get_contents(file, &style->footer_html, NULL, NULL))
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
277 style->footer_html = g_strdup("");
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
278 g_free(file);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
279
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
280 file = g_build_filename(styledir, "Contents", "Resources", "Incoming", "Content.html", NULL);
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
281 if (!g_file_get_contents(file, &style->incoming_content_html, NULL, NULL)) {
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
282 purple_debug_info("webkit", "%s did not have a Incoming/Content.html\n", styledir);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
283 pidgin_message_style_unref(style);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
284 g_free(file);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
285 return NULL;
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
286 }
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
287 g_free(file);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
288
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
289
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
290 /* according to the spec, the following are optional files */
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
291 file = g_build_filename(styledir, "Contents", "Resources", "Incoming", "NextContent.html", NULL);
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
292 if (!g_file_get_contents(file, &style->incoming_next_content_html, NULL, NULL)) {
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
293 style->incoming_next_content_html = g_strdup(style->incoming_content_html);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
294 }
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
295 g_free(file);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
296
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
297 file = g_build_filename(styledir, "Contents", "Resources", "Outgoing", "Content.html", NULL);
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
298 if (!g_file_get_contents(file, &style->outgoing_content_html, NULL, NULL)) {
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
299 style->outgoing_content_html = g_strdup(style->incoming_content_html);
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
300 }
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
301 g_free(file);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
302
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
303 file = g_build_filename(styledir, "Contents", "Resources", "Outgoing", "NextContent.html", NULL);
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
304 if (!g_file_get_contents(file, &style->outgoing_next_content_html, NULL, NULL)) {
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
305 style->outgoing_next_content_html = g_strdup(style->outgoing_content_html);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
306 }
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
307
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
308 pidgin_message_style_read_info_plist(style, NULL);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
309 pidgin_message_style_load_state(style);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
310
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
311 /* non variant dependent Info.plist checks */
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
312 if (style->message_view_version < 3) {
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
313 purple_debug_info("webkit", "%s is a legacy style (version %d) and will not be loaded\n", style->cf_bundle_name, style->message_view_version);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
314 pidgin_message_style_unref(style);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
315 return NULL;
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
316 }
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
317
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
318 if (!style->variant)
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
319 {
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
320 GList *variants = pidgin_message_style_get_variants(style);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
321
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
322 if (variants)
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
323 pidgin_message_style_set_variant(style, variants->data);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
324
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
325 glist_free_all_string(variants);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
326 }
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
327
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
328 return style;
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
329 }
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
330
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
331 PidginMessageStyle *
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
332 pidgin_message_style_copy(const PidginMessageStyle *style)
32487
13f307997f1a Instead of using references, use copy's. Sigh, I know this is a memory inefficient
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32486
diff changeset
333 {
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
334 PidginMessageStyle *ret = pidgin_message_style_new(style->style_dir);
32487
13f307997f1a Instead of using references, use copy's. Sigh, I know this is a memory inefficient
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32486
diff changeset
335
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
336 ret->variant = g_strdup(style->variant);
32487
13f307997f1a Instead of using references, use copy's. Sigh, I know this is a memory inefficient
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32486
diff changeset
337 ret->message_view_version = style->message_view_version;
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
338 ret->cf_bundle_name = g_strdup(style->cf_bundle_name);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
339 ret->cf_bundle_identifier = g_strdup(style->cf_bundle_identifier);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
340 ret->cf_bundle_get_info_string = g_strdup(style->cf_bundle_get_info_string);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
341 ret->default_font_family = g_strdup(style->default_font_family);
32487
13f307997f1a Instead of using references, use copy's. Sigh, I know this is a memory inefficient
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32486
diff changeset
342 ret->default_font_size = style->default_font_size;
13f307997f1a Instead of using references, use copy's. Sigh, I know this is a memory inefficient
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32486
diff changeset
343 ret->shows_user_icons = style->shows_user_icons;
13f307997f1a Instead of using references, use copy's. Sigh, I know this is a memory inefficient
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32486
diff changeset
344 ret->disable_combine_consecutive = style->disable_combine_consecutive;
13f307997f1a Instead of using references, use copy's. Sigh, I know this is a memory inefficient
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32486
diff changeset
345 ret->default_background_is_transparent = style->default_background_is_transparent;
13f307997f1a Instead of using references, use copy's. Sigh, I know this is a memory inefficient
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32486
diff changeset
346 ret->disable_custom_background = style->disable_custom_background;
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
347 ret->default_background_color = g_strdup(style->default_background_color);
32487
13f307997f1a Instead of using references, use copy's. Sigh, I know this is a memory inefficient
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32486
diff changeset
348 ret->allow_text_colors = style->allow_text_colors;
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
349 ret->image_mask = g_strdup(style->image_mask);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
350 ret->default_variant = g_strdup(style->default_variant);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
351
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
352 ret->template_path = g_strdup(style->template_path);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
353 ret->template_html = g_strdup(style->template_html);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
354 ret->header_html = g_strdup(style->header_html);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
355 ret->footer_html = g_strdup(style->footer_html);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
356 ret->incoming_content_html = g_strdup(style->incoming_content_html);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
357 ret->outgoing_content_html = g_strdup(style->outgoing_content_html);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
358 ret->incoming_next_content_html = g_strdup(style->incoming_next_content_html);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
359 ret->outgoing_next_content_html = g_strdup(style->outgoing_next_content_html);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
360 ret->status_html = g_strdup(style->status_html);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
361 ret->basestyle_css = g_strdup(style->basestyle_css);
32487
13f307997f1a Instead of using references, use copy's. Sigh, I know this is a memory inefficient
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32486
diff changeset
362 return ret;
13f307997f1a Instead of using references, use copy's. Sigh, I know this is a memory inefficient
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32486
diff changeset
363 }
13f307997f1a Instead of using references, use copy's. Sigh, I know this is a memory inefficient
Arnold Noronha <tdrhq@soc.pidgin.im>
parents: 32486
diff changeset
364
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
365 void
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
366 pidgin_message_style_set_variant(PidginMessageStyle *style, const char *variant)
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
367 {
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
368 /* I'm not going to test whether this variant is valid! */
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
369 g_free(style->variant);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
370 style->variant = g_strdup(variant);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
371
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
372 pidgin_message_style_read_info_plist(style, variant);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
373
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
374 /* todo, the style has "changed". Ideally, I would like to use signals at this point. */
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
375 }
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
376
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
377 char *
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
378 pidgin_message_style_get_variant(PidginMessageStyle *style)
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
379 {
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
380 return g_strdup(style->variant);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
381 }
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
382
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
383 /**
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
384 * Get a list of variants supported by the style.
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
385 */
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
386 GList*
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
387 pidgin_message_style_get_variants(PidginMessageStyle *style)
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
388 {
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
389 GList *ret = NULL;
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
390 GDir *variants;
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
391 const char *css_file;
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
392 char *css;
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
393 char *variant_dir;
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
394
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
395 g_assert(style->style_dir);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
396 variant_dir = g_build_filename(style->style_dir, "Contents", "Resources", "Variants", NULL);
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
397
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
398 variants = g_dir_open(variant_dir, 0, NULL);
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
399 if (!variants)
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
400 return NULL;
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
401
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
402 while ((css_file = g_dir_read_name(variants)) != NULL) {
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
403 if (!g_str_has_suffix(css_file, ".css"))
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
404 continue;
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
405
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
406 css = g_strndup(css_file, strlen(css_file) - 4);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
407 ret = g_list_append(ret, css);
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
408 }
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
409
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
410 g_dir_close(variants);
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
411 g_free(variant_dir);
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
412
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
413 ret = g_list_sort(ret, (GCompareFunc)g_strcmp0);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
414 return ret;
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
415 }
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
416
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
417 char *
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
418 pidgin_message_style_get_css(PidginMessageStyle *style)
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
419 {
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
420 if (!style->variant) {
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
421 return g_build_filename(style->style_dir, "Contents", "Resources", "main.css", NULL);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
422 } else {
32513
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
423 char *file = g_strdup_printf("%s.css", style->variant);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
424 char *ret = g_build_filename(style->style_dir, "Contents", "Resources", "Variants", file, NULL);
9352b4c92d13 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32491
diff changeset
425 g_free(file);
32485
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
426 return ret;
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
427 }
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
428 }
b932922007bc Separated the MessageStyle loading code from the actual rendering code.
Arnold Noronha <tdrhq@soc.pidgin.im>
parents:
diff changeset
429

mercurial