Mercurial > pidgin.yaz
comparison pidgin/plugins/adiumthemes/webkit.c @ 32536:fc2c2f20370f
Another temporary commit that will not compile.
Separated the code to load the message style.
author | tdrhq@soc.pidgin.im |
---|---|
date | Mon, 10 Aug 2009 02:38:12 +0000 |
parents | 41cb5245b253 |
children | 9ad4257f5e8f |
comparison
equal
deleted
inserted
replaced
32535:41cb5245b253 | 32536:fc2c2f20370f |
---|---|
72 char *status_html; | 72 char *status_html; |
73 char *basestyle_css; | 73 char *basestyle_css; |
74 } PidginMessageStyle; | 74 } PidginMessageStyle; |
75 | 75 |
76 static GList *style_list; | 76 static GList *style_list; |
77 static PidginMessageStyle *cur_style = NULL; | |
77 static void *handle = NULL; | 78 static void *handle = NULL; |
78 | 79 |
79 static PidginMessageStyle* pidgin_message_style_new () | 80 static PidginMessageStyle* pidgin_message_style_new () |
80 { | 81 { |
81 PidginMessageStyle* ret = g_new0 (PidginMessageStyle, 1); | 82 PidginMessageStyle* ret = g_new0 (PidginMessageStyle, 1); |
103 | 104 |
104 g_list_remove (style_list, style); | 105 g_list_remove (style_list, style); |
105 g_free (style); | 106 g_free (style); |
106 } | 107 } |
107 | 108 |
109 static void variant_set_default (PidginMessageStyle* style); | |
108 static PidginMessageStyle* | 110 static PidginMessageStyle* |
109 pidgin_message_style_load (const char* styledir) | 111 pidgin_message_style_load (const char* styledir) |
110 { | 112 { |
111 /* is this style already loaded? */ | 113 /* is this style already loaded? */ |
112 GList* cur = style_list; | 114 GList *cur = style_list; |
115 char *file; /* temporary variable */ | |
113 PidginMessageStyle *ret = NULL; | 116 PidginMessageStyle *ret = NULL; |
117 | |
114 for (; cur; cur = g_list_next (cur)) { | 118 for (; cur; cur = g_list_next (cur)) { |
115 if (g_str_equal (styldir, ((PidginMessageStyle*) cur->data)->styledir)) | 119 if (g_str_equal (styldir, ((PidginMessageStyle*) cur->data)->styledir)) |
116 return (PidginMessageStyle*) cur->data; | 120 return (PidginMessageStyle*) cur->data; |
117 } | 121 } |
118 | 122 |
119 /* else we need to load it */ | 123 /* else we need to load it */ |
120 ret = pidgin_message_style_new (); | 124 ret = pidgin_message_style_new (); |
121 | 125 ret->style_dir = g_strdup (style); |
126 | |
127 /* find some variant file (or load from user's settings) */ | |
128 variant_set_default (style); | |
129 | |
130 /* load all other files */ | |
131 | |
132 /* The template path can either come from the theme, or can | |
133 * be stock Template.html that comes with the plugin */ | |
134 style->template_path = g_build_filename(styledir, "Contents", "Resources", "Template.html", NULL); | |
135 | |
136 if (!g_file_test(style->template_path, G_FILE_TEST_EXISTS)) { | |
137 g_free (style->template_path); | |
138 style->template_path = g_build_filename(DATADIR, "pidgin", "webkit", "Template.html", NULL); | |
139 } | |
140 | |
141 if (!g_file_get_contents(style->template_path, &style->template_html, NULL, NULL)) { | |
142 pidgin_message_style_free (style); | |
143 return NULL; | |
144 } | |
145 | |
146 file = g_build_filename(style_dir, "Contents", "Resources", "Status.html", NULL); | |
147 if (!g_file_get_contents(file, &style->status_html, NULL, NULL)) { | |
148 pidgin_message_style_free (style); | |
149 g_free (file); | |
150 return NULL; | |
151 } | |
152 g_free (file); | |
153 | |
154 file = g_build_filename(style_dir, "Contents", "Resources", "main.css", NULL); | |
155 if (!g_file_get_contents(file, &basestyle_css, NULL, NULL)) { | |
156 pidgin_message_style_free (style); | |
157 g_free (file); | |
158 return NULL; | |
159 } | |
160 g_free (file); | |
161 | |
162 file = g_build_filename(style_dir, "Contents", "Resources", "Header.html", NULL); | |
163 g_file_get_contents(file, &style->header_html, NULL, NULL); | |
164 g_free (file); | |
165 | |
166 file = g_build_filename(style_dir, "Contents", "Resources", "Footer.html", NULL); | |
167 g_file_get_contents(file, &style->footer_html, NULL, NULL); | |
168 g_free (file); | |
169 | |
170 | |
171 | |
172 file = g_build_filename(style_dir, "Contents", "Resources", "Incoming", "Content.html", NULL); | |
173 if (!g_file_get_contents(file, &style->incoming_content_html, &NULL, NULL)) { | |
174 pidgin_message_style_free (style); | |
175 g_free (file); | |
176 return NULL; | |
177 } | |
178 g_free (file); | |
179 | |
180 | |
181 /* according to the spec, the following are not necessary files */ | |
182 file = g_build_filename(styledir, "Contents", "Resources", "Incoming", "NextContent.html", NULL); | |
183 if (!g_file_get_contents(file, &style->incoming_next_content_html, NULL, NULL)) { | |
184 style->incoming_next_content_html = g_strdup (style->incoming_content_html); | |
185 } | |
186 g_free (file); | |
187 | |
188 file = g_build_filename(styledir, "Contents", "Resources", "Outgoing", "Content.html", NULL); | |
189 if (!g_file_get_contents(file, &style->outgoing_content_html, NULL, NULL)) { | |
190 style->outgoing_content_html = g_strdup(style->incoming_content_html); | |
191 } | |
192 g_free (file); | |
193 | |
194 file = g_build_filename(styledir, "Contents", "Resources", "Outgoing", "NextContent.html", NULL); | |
195 if (!g_file_get_contents(file, &style->outgoing_next_content_html, NULL, NULL)) { | |
196 outgoing_next_content_html = g_strdup (outgoing_content_html); | |
197 } | |
198 | |
122 } | 199 } |
123 | 200 |
124 | 201 |
125 static void* webkit_plugin_get_handle () | 202 static void* webkit_plugin_get_handle () |
126 { | 203 { |
539 | 616 |
540 for (iter = all; iter; iter = g_list_next (iter)) | 617 for (iter = all; iter; iter = g_list_next (iter)) |
541 g_free (iter->data); | 618 g_free (iter->data); |
542 | 619 |
543 g_list_free (all); | 620 g_list_free (all); |
544 | |
545 g_free (style->css_path); | |
546 style->css_path = css_path; | |
547 } | 621 } |
548 | 622 |
549 static gboolean | 623 static gboolean |
550 plugin_load(PurplePlugin *plugin) | 624 plugin_load(PurplePlugin *plugin) |
551 { | 625 { |
552 char *file; | 626 char *cur_style; |
553 | 627 |
554 if (g_path_is_absolute (purple_user_dir())) | 628 if (g_path_is_absolute (purple_user_dir())) |
555 style_dir = g_build_filename(purple_user_dir(), "style", NULL); | 629 style_dir = g_build_filename(purple_user_dir(), "style", NULL); |
556 else { | 630 else { |
557 char* cur = g_get_current_dir (); | 631 char* cur = g_get_current_dir (); |
558 style_dir = g_build_filename (cur, purple_user_dir(), "style", NULL); | 632 style_dir = g_build_filename (cur, purple_user_dir(), "style", NULL); |
559 g_free (cur); | 633 g_free (cur); |
560 } | 634 } |
561 | 635 |
562 variant_set_default (); | 636 cur_style = pidgin_message_style_load (style_dir); |
563 if (!css_path) | 637 |
564 return FALSE; | 638 if (!cur_style) return; |
565 | |
566 | |
567 template_path = g_build_filename(style_dir, "Contents", "Resources", "Template.html", NULL); | |
568 if (!g_file_test(template_path, G_FILE_TEST_EXISTS)) { | |
569 g_free(template_path); | |
570 template_path = g_build_filename(DATADIR, "pidgin", "webkit", "Template.html", NULL); | |
571 } | |
572 if (!g_file_get_contents(template_path, &template_html, &template_html_len, NULL)) | |
573 return FALSE; | |
574 | |
575 file = g_build_filename(style_dir, "Contents", "Resources", "Header.html", NULL); | |
576 g_file_get_contents(file, &header_html, &header_html_len, NULL); | |
577 | |
578 file = g_build_filename(style_dir, "Contents", "Resources", "Footer.html", NULL); | |
579 g_file_get_contents(file, &footer_html, &footer_html_len, NULL); | |
580 | |
581 file = g_build_filename(style_dir, "Contents", "Resources", "Incoming", "Content.html", NULL); | |
582 if (!g_file_get_contents(file, &incoming_content_html, &incoming_content_html_len, NULL)) | |
583 return FALSE; | |
584 | |
585 file = g_build_filename(style_dir, "Contents", "Resources", "Incoming", "NextContent.html", NULL); | |
586 if (!g_file_get_contents(file, &incoming_next_content_html, &incoming_next_content_html_len, NULL)) { | |
587 incoming_next_content_html = incoming_content_html; | |
588 incoming_next_content_html_len = incoming_content_html_len; | |
589 } | |
590 | |
591 file = g_build_filename(style_dir, "Contents", "Resources", "Outgoing", "Content.html", NULL); | |
592 if (!g_file_get_contents(file, &outgoing_content_html, &outgoing_content_html_len, NULL)) { | |
593 outgoing_content_html = incoming_content_html; | |
594 outgoing_content_html_len = incoming_content_html_len; | |
595 } | |
596 | |
597 file = g_build_filename(style_dir, "Contents", "Resources", "Outgoing", "NextContent.html", NULL); | |
598 if (!g_file_get_contents(file, &outgoing_next_content_html, &outgoing_next_content_html_len, NULL)) { | |
599 outgoing_next_content_html = outgoing_content_html; | |
600 outgoing_next_content_html_len = outgoing_content_html_len; | |
601 } | |
602 | |
603 | |
604 file = g_build_filename(style_dir, "Contents", "Resources", "Status.html", NULL); | |
605 if (!g_file_get_contents(file, &status_html, &status_html_len, NULL)) | |
606 return FALSE; | |
607 | |
608 file = g_build_filename(style_dir, "Contents", "Resources", "main.css", NULL); | |
609 g_file_get_contents(file, &basestyle_css, &basestyle_css_len, NULL); | |
610 | 639 |
611 uiops = pidgin_conversations_get_conv_ui_ops(); | 640 uiops = pidgin_conversations_get_conv_ui_ops(); |
612 | 641 |
613 if (uiops == NULL) | 642 if (uiops == NULL) |
614 return FALSE; | 643 return FALSE; |