1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2008-2009 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Authors: Xavier Claessens <xclaesse@gmail.com>
25 #include <glib/gi18n.h>
27 #include <webkit/webkitnetworkrequest.h>
28 #include <telepathy-glib/dbus.h>
29 #include <telepathy-glib/util.h>
32 #include <libempathy/empathy-time.h>
33 #include <libempathy/empathy-utils.h>
35 #include "empathy-theme-adium.h"
36 #include "empathy-smiley-manager.h"
37 #include "empathy-conf.h"
38 #include "empathy-ui-utils.h"
39 #include "empathy-plist.h"
41 #define DEBUG_FLAG EMPATHY_DEBUG_CHAT
42 #include <libempathy/empathy-debug.h>
44 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyThemeAdium)
46 /* "Join" consecutive messages with timestamps within five minutes */
47 #define MESSAGE_JOIN_PERIOD 5*60
50 EmpathyAdiumData *data;
51 EmpathySmileyManager *smiley_manager;
52 EmpathyContact *last_contact;
53 time_t last_timestamp;
56 } EmpathyThemeAdiumPriv;
58 struct _EmpathyAdiumData {
62 gchar *default_avatar_filename;
63 gchar *default_incoming_avatar_filename;
64 gchar *default_outgoing_avatar_filename;
66 gchar *in_content_html;
68 gchar *in_nextcontent_html;
69 gsize in_nextcontent_len;
70 gchar *out_content_html;
71 gsize out_content_len;
72 gchar *out_nextcontent_html;
73 gsize out_nextcontent_len;
79 static void theme_adium_iface_init (EmpathyChatViewIface *iface);
86 G_DEFINE_TYPE_WITH_CODE (EmpathyThemeAdium, empathy_theme_adium,
88 G_IMPLEMENT_INTERFACE (EMPATHY_TYPE_CHAT_VIEW,
89 theme_adium_iface_init));
91 static WebKitNavigationResponse
92 theme_adium_navigation_requested_cb (WebKitWebView *view,
93 WebKitWebFrame *frame,
94 WebKitNetworkRequest *request,
99 uri = webkit_network_request_get_uri (request);
100 empathy_url_show (GTK_WIDGET (view), uri);
102 return WEBKIT_NAVIGATION_RESPONSE_IGNORE;
106 theme_adium_populate_popup_cb (WebKitWebView *view,
112 /* Remove default menu items */
113 gtk_container_foreach (GTK_CONTAINER (menu),
114 (GtkCallback) gtk_widget_destroy, NULL);
116 /* Select all item */
117 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
118 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
119 gtk_widget_show (item);
121 g_signal_connect_swapped (item, "activate",
122 G_CALLBACK (webkit_web_view_select_all),
126 if (webkit_web_view_can_copy_clipboard (view)) {
127 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL);
128 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
129 gtk_widget_show (item);
131 g_signal_connect_swapped (item, "activate",
132 G_CALLBACK (webkit_web_view_copy_clipboard),
136 /* Clear menu item */
137 item = gtk_separator_menu_item_new ();
138 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
139 gtk_widget_show (item);
141 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_CLEAR, NULL);
142 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
143 gtk_widget_show (item);
145 g_signal_connect_swapped (item, "activate",
146 G_CALLBACK (empathy_chat_view_clear),
149 /* FIXME: Add open_link and copy_link when those bugs are fixed:
150 * https://bugs.webkit.org/show_bug.cgi?id=16092
151 * https://bugs.webkit.org/show_bug.cgi?id=16562
156 theme_adium_parse_body (EmpathyThemeAdium *theme,
159 EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
160 gboolean use_smileys = FALSE;
165 GMatchInfo *match_info;
170 empathy_conf_get_bool (empathy_conf_get (),
171 EMPATHY_PREFS_CHAT_SHOW_SMILEYS,
175 /* Replace smileys by a <img/> tag */
176 string = g_string_sized_new (strlen (text));
177 smileys = empathy_smiley_manager_parse (priv->smiley_manager, text);
178 for (l = smileys; l; l = l->next) {
179 EmpathySmiley *smiley;
183 g_string_append_printf (string,
184 "<abbr title='%s'><img src=\"%s\"/ alt=\"%s\"/></abbr>",
185 smiley->str, smiley->path, smiley->str);
189 str = g_markup_escape_text (smiley->str, -1);
190 g_string_append (string, str);
193 empathy_smiley_free (smiley);
195 g_slist_free (smileys);
198 text = ret = g_string_free (string, FALSE);
201 /* Add <a href></a> arround links */
202 uri_regex = empathy_uri_regex_dup_singleton ();
203 match = g_regex_match (uri_regex, text, 0, &match_info);
208 string = g_string_sized_new (strlen (text));
210 g_match_info_fetch_pos (match_info, 0, &s, &e);
213 /* Append the text between last link (or the
214 * start of the message) and this link */
215 g_string_append_len (string, text + last, s - last);
218 /* Append the link inside <a href=""></a> tag */
219 g_string_append (string, "<a href=\"");
220 g_string_append_len (string, text + s, e - s);
221 g_string_append (string, "\">");
222 g_string_append_len (string, text + s, e - s);
223 g_string_append (string, "</a>");
226 } while (g_match_info_next (match_info, NULL));
228 if (e < strlen (text)) {
229 /* Append the text after the last link */
230 g_string_append_len (string, text + e, strlen (text) - e);
234 text = ret = g_string_free (string, FALSE);
236 g_match_info_free (match_info);
237 g_regex_unref (uri_regex);
239 /* Replace \n by <br/> */
242 for (i = 0; text[i] != '\0'; i++) {
243 if (text[i] == '\n') {
245 string = g_string_sized_new (strlen (text));
247 g_string_append_len (string, text + prev, i - prev);
248 g_string_append (string, "<br/>");
253 g_string_append (string, text + prev);
255 text = ret = g_string_free (string, FALSE);
262 escape_and_append_len (GString *string, const gchar *str, gint len)
264 while (*str != '\0' && len != 0) {
268 g_string_append (string, "\\\\");
272 g_string_append (string, "\\\"");
275 /* Remove end of lines */
278 g_string_append_c (string, *str);
287 theme_adium_match (const gchar **str, const gchar *match)
291 len = strlen (match);
292 if (strncmp (*str, match, len) == 0) {
301 theme_adium_append_html (EmpathyThemeAdium *theme,
303 const gchar *html, gsize len,
304 const gchar *message,
305 const gchar *avatar_filename,
307 const gchar *contact_id,
308 const gchar *service_name,
309 const gchar *message_classes,
313 const gchar *cur = NULL;
316 /* Make some search-and-replace in the html code */
317 string = g_string_sized_new (len + strlen (message));
318 g_string_append_printf (string, "%s(\"", func);
319 for (cur = html; *cur != '\0'; cur++) {
320 const gchar *replace = NULL;
321 gchar *dup_replace = NULL;
323 if (theme_adium_match (&cur, "%message%")) {
325 } else if (theme_adium_match (&cur, "%messageClasses%")) {
326 replace = message_classes;
327 } else if (theme_adium_match (&cur, "%userIconPath%")) {
328 replace = avatar_filename;
329 } else if (theme_adium_match (&cur, "%sender%")) {
331 } else if (theme_adium_match (&cur, "%senderScreenName%")) {
332 replace = contact_id;
333 } else if (theme_adium_match (&cur, "%senderDisplayName%")) {
334 /* %senderDisplayName% -
335 * "The serverside (remotely set) name of the sender,
336 * such as an MSN display name."
338 * We don't have access to that yet so we use local
341 } else if (theme_adium_match (&cur, "%service%")) {
342 replace = service_name;
343 } else if (theme_adium_match (&cur, "%shortTime%")) {
344 dup_replace = empathy_time_to_string_local (timestamp,
345 EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
346 replace = dup_replace;
347 } else if (theme_adium_match (&cur, "%time")) {
348 gchar *format = NULL;
350 /* Time can be in 2 formats:
351 * %time% or %time{strftime format}%
352 * Extract the time format if provided. */
355 end = strstr (cur, "}%");
360 format = g_strndup (cur, end - cur);
366 dup_replace = empathy_time_to_string_local (timestamp,
367 format ? format : EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
368 replace = dup_replace;
371 escape_and_append_len (string, cur, 1);
375 /* Here we have a replacement to make */
376 escape_and_append_len (string, replace, -1);
377 g_free (dup_replace);
379 g_string_append (string, "\")");
381 script = g_string_free (string, FALSE);
382 webkit_web_view_execute_script (WEBKIT_WEB_VIEW (theme), script);
387 theme_adium_append_message (EmpathyChatView *view,
390 EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (view);
391 EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
392 EmpathyContact *sender;
393 EmpathyAccount *account;
394 gchar *dup_body = NULL;
397 const gchar *contact_id;
398 EmpathyAvatar *avatar;
399 const gchar *avatar_filename = NULL;
404 const gchar *service_name;
405 const gchar *message_classes = NULL;
407 if (!priv->page_loaded) {
408 priv->message_queue = g_list_prepend (priv->message_queue,
413 /* Get information */
414 sender = empathy_message_get_sender (msg);
415 account = empathy_contact_get_account (sender);
416 service_name = empathy_account_get_protocol (account);
417 timestamp = empathy_message_get_timestamp (msg);
418 body = empathy_message_get_body (msg);
419 dup_body = theme_adium_parse_body (theme, body);
423 name = empathy_contact_get_name (sender);
424 contact_id = empathy_contact_get_id (sender);
426 /* If this is a /me, append an event */
427 if (empathy_message_get_tptype (msg) == TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION) {
430 str = g_strdup_printf ("%s %s", name, body);
431 empathy_chat_view_append_event (view, str);
437 /* Get the avatar filename, or a fallback */
438 avatar = empathy_contact_get_avatar (sender);
440 avatar_filename = avatar->filename;
442 if (!avatar_filename) {
443 if (empathy_contact_is_user (sender)) {
444 avatar_filename = priv->data->default_outgoing_avatar_filename;
446 avatar_filename = priv->data->default_incoming_avatar_filename;
448 if (!avatar_filename) {
449 if (!priv->data->default_avatar_filename) {
450 priv->data->default_avatar_filename =
451 empathy_filename_from_icon_name ("stock_person",
452 GTK_ICON_SIZE_DIALOG);
454 avatar_filename = priv->data->default_avatar_filename;
458 /* Get the right html/func to add the message */
459 func = "appendMessage";
461 * To mimick Adium's behavior, we only want to join messages
462 * sent within a 5 minute time frame.
464 if (empathy_contact_equal (priv->last_contact, sender) &&
465 (timestamp - priv->last_timestamp < MESSAGE_JOIN_PERIOD)) {
466 func = "appendNextMessage";
467 if (empathy_contact_is_user (sender)) {
468 message_classes = "consecutive incoming message";
469 html = priv->data->out_nextcontent_html;
470 len = priv->data->out_nextcontent_len;
473 message_classes = "consecutive message outgoing";
474 html = priv->data->in_nextcontent_html;
475 len = priv->data->in_nextcontent_len;
479 if (empathy_contact_is_user (sender)) {
480 if (!message_classes) {
481 message_classes = "incoming message";
483 html = priv->data->out_content_html;
484 len = priv->data->out_content_len;
487 if (!message_classes) {
488 message_classes = "message outgoing";
490 html = priv->data->in_content_html;
491 len = priv->data->in_content_len;
495 theme_adium_append_html (theme, func, html, len, body, avatar_filename,
496 name, contact_id, service_name, message_classes,
499 /* Keep the sender of the last displayed message */
500 if (priv->last_contact) {
501 g_object_unref (priv->last_contact);
503 priv->last_contact = g_object_ref (sender);
504 priv->last_timestamp = timestamp;
510 theme_adium_append_event (EmpathyChatView *view,
513 EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (view);
514 EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
516 if (priv->data->status_html) {
517 theme_adium_append_html (theme, "appendMessage",
518 priv->data->status_html,
519 priv->data->status_len,
520 str, NULL, NULL, NULL, NULL, "event",
521 empathy_time_get_current ());
524 /* There is no last contact */
525 if (priv->last_contact) {
526 g_object_unref (priv->last_contact);
527 priv->last_contact = NULL;
532 theme_adium_scroll (EmpathyChatView *view,
533 gboolean allow_scrolling)
535 /* FIXME: Is it possible? I guess we need a js function, but I don't
540 theme_adium_scroll_down (EmpathyChatView *view)
542 webkit_web_view_execute_script (WEBKIT_WEB_VIEW (view), "scrollToBottom()");
546 theme_adium_get_has_selection (EmpathyChatView *view)
548 return webkit_web_view_has_selection (WEBKIT_WEB_VIEW (view));
552 theme_adium_clear (EmpathyChatView *view)
554 EmpathyThemeAdiumPriv *priv = GET_PRIV (view);
557 priv->page_loaded = FALSE;
558 basedir_uri = g_strconcat ("file://", priv->data->basedir, NULL);
559 webkit_web_view_load_html_string (WEBKIT_WEB_VIEW (view),
560 priv->data->template_html,
562 g_free (basedir_uri);
566 theme_adium_find_previous (EmpathyChatView *view,
567 const gchar *search_criteria,
570 return webkit_web_view_search_text (WEBKIT_WEB_VIEW (view),
571 search_criteria, FALSE,
576 theme_adium_find_next (EmpathyChatView *view,
577 const gchar *search_criteria,
580 return webkit_web_view_search_text (WEBKIT_WEB_VIEW (view),
581 search_criteria, FALSE,
586 theme_adium_find_abilities (EmpathyChatView *view,
587 const gchar *search_criteria,
588 gboolean *can_do_previous,
589 gboolean *can_do_next)
591 /* FIXME: Does webkit provide an API for that? We have wrap=true in
592 * find_next and find_previous to work around this problem. */
594 *can_do_previous = TRUE;
600 theme_adium_highlight (EmpathyChatView *view,
603 webkit_web_view_unmark_text_matches (WEBKIT_WEB_VIEW (view));
604 webkit_web_view_mark_text_matches (WEBKIT_WEB_VIEW (view),
606 webkit_web_view_set_highlight_text_matches (WEBKIT_WEB_VIEW (view),
611 theme_adium_copy_clipboard (EmpathyChatView *view)
613 webkit_web_view_copy_clipboard (WEBKIT_WEB_VIEW (view));
617 theme_adium_iface_init (EmpathyChatViewIface *iface)
619 iface->append_message = theme_adium_append_message;
620 iface->append_event = theme_adium_append_event;
621 iface->scroll = theme_adium_scroll;
622 iface->scroll_down = theme_adium_scroll_down;
623 iface->get_has_selection = theme_adium_get_has_selection;
624 iface->clear = theme_adium_clear;
625 iface->find_previous = theme_adium_find_previous;
626 iface->find_next = theme_adium_find_next;
627 iface->find_abilities = theme_adium_find_abilities;
628 iface->highlight = theme_adium_highlight;
629 iface->copy_clipboard = theme_adium_copy_clipboard;
633 theme_adium_load_finished_cb (WebKitWebView *view,
634 WebKitWebFrame *frame,
637 EmpathyThemeAdiumPriv *priv = GET_PRIV (view);
638 EmpathyChatView *chat_view = EMPATHY_CHAT_VIEW (view);
640 DEBUG ("Page loaded");
641 priv->page_loaded = TRUE;
643 /* Display queued messages */
644 priv->message_queue = g_list_reverse (priv->message_queue);
645 while (priv->message_queue) {
646 EmpathyMessage *message = priv->message_queue->data;
648 theme_adium_append_message (chat_view, message);
649 priv->message_queue = g_list_remove (priv->message_queue, message);
650 g_object_unref (message);
655 theme_adium_finalize (GObject *object)
657 EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
659 empathy_adium_data_unref (priv->data);
661 G_OBJECT_CLASS (empathy_theme_adium_parent_class)->finalize (object);
665 theme_adium_dispose (GObject *object)
667 EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
669 if (priv->smiley_manager) {
670 g_object_unref (priv->smiley_manager);
671 priv->smiley_manager = NULL;
674 if (priv->last_contact) {
675 g_object_unref (priv->last_contact);
676 priv->last_contact = NULL;
679 G_OBJECT_CLASS (empathy_theme_adium_parent_class)->dispose (object);
683 theme_adium_constructed (GObject *object)
685 EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
687 const gchar *font_family = NULL;
689 WebKitWebSettings *webkit_settings;
691 /* Set default settings */
692 font_family = tp_asv_get_string (priv->data->info, "DefaultFontFamily");
693 font_size = tp_asv_get_int32 (priv->data->info, "DefaultFontSize", NULL);
694 webkit_settings = webkit_web_settings_new ();
696 g_object_set (G_OBJECT (webkit_settings), "default-font-family", font_family, NULL);
699 g_object_set (G_OBJECT (webkit_settings), "default-font-size", font_size, NULL);
701 webkit_web_view_set_settings (WEBKIT_WEB_VIEW (object), webkit_settings);
704 basedir_uri = g_strconcat ("file://", priv->data->basedir, NULL);
705 webkit_web_view_load_html_string (WEBKIT_WEB_VIEW (object),
706 priv->data->template_html,
709 g_object_unref (webkit_settings);
710 g_free (basedir_uri);
714 theme_adium_get_property (GObject *object,
719 EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
722 case PROP_ADIUM_DATA:
723 g_value_set_boxed (value, priv->data);
726 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
732 theme_adium_set_property (GObject *object,
737 EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
740 case PROP_ADIUM_DATA:
741 g_assert (priv->data == NULL);
742 priv->data = g_value_dup_boxed (value);
745 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
751 empathy_theme_adium_class_init (EmpathyThemeAdiumClass *klass)
753 GObjectClass *object_class = G_OBJECT_CLASS (klass);
755 object_class->finalize = theme_adium_finalize;
756 object_class->dispose = theme_adium_dispose;
757 object_class->constructed = theme_adium_constructed;
758 object_class->get_property = theme_adium_get_property;
759 object_class->set_property = theme_adium_set_property;
761 g_object_class_install_property (object_class,
763 g_param_spec_boxed ("adium-data",
765 "Data for the adium theme",
766 EMPATHY_TYPE_ADIUM_DATA,
767 G_PARAM_CONSTRUCT_ONLY |
769 G_PARAM_STATIC_STRINGS));
772 g_type_class_add_private (object_class, sizeof (EmpathyThemeAdiumPriv));
776 empathy_theme_adium_init (EmpathyThemeAdium *theme)
778 EmpathyThemeAdiumPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (theme,
779 EMPATHY_TYPE_THEME_ADIUM, EmpathyThemeAdiumPriv);
783 priv->smiley_manager = empathy_smiley_manager_dup_singleton ();
785 g_signal_connect (theme, "load-finished",
786 G_CALLBACK (theme_adium_load_finished_cb),
788 g_signal_connect (theme, "navigation-requested",
789 G_CALLBACK (theme_adium_navigation_requested_cb),
791 g_signal_connect (theme, "populate-popup",
792 G_CALLBACK (theme_adium_populate_popup_cb),
797 empathy_theme_adium_new (EmpathyAdiumData *data)
799 g_return_val_if_fail (data != NULL, NULL);
801 return g_object_new (EMPATHY_TYPE_THEME_ADIUM,
807 empathy_adium_path_is_valid (const gchar *path)
812 /* We ship a default Template.html as fallback if there is any problem
813 * with the one inside the theme. The only other required file is
814 * Content.html for incoming messages (outgoing fallback to use
816 file = g_build_filename (path, "Contents", "Resources", "Incoming",
817 "Content.html", NULL);
818 ret = g_file_test (file, G_FILE_TEST_EXISTS);
825 empathy_adium_info_new (const gchar *path)
829 GHashTable *info = NULL;
831 g_return_val_if_fail (empathy_adium_path_is_valid (path), NULL);
833 file = g_build_filename (path, "Contents", "Info.plist", NULL);
834 value = empathy_plist_parse_from_file (file);
838 info = g_value_dup_boxed (value);
839 tp_g_value_slice_free (value);
846 empathy_adium_data_get_type (void)
848 static GType type_id = 0;
852 type_id = g_boxed_type_register_static ("EmpathyAdiumData",
853 (GBoxedCopyFunc) empathy_adium_data_ref,
854 (GBoxedFreeFunc) empathy_adium_data_unref);
861 empathy_adium_data_new_with_info (const gchar *path, GHashTable *info)
863 EmpathyAdiumData *data;
865 gchar *template_html = NULL;
867 gchar *footer_html = NULL;
875 g_return_val_if_fail (empathy_adium_path_is_valid (path), NULL);
877 data = g_slice_new0 (EmpathyAdiumData);
879 data->path = g_strdup (path);
880 data->basedir = g_strconcat (path, G_DIR_SEPARATOR_S "Contents"
881 G_DIR_SEPARATOR_S "Resources" G_DIR_SEPARATOR_S, NULL);
882 data->info = g_hash_table_ref (info);
884 /* Load html files */
885 file = g_build_filename (data->basedir, "Incoming", "Content.html", NULL);
886 g_file_get_contents (file, &data->in_content_html, &data->in_content_len, NULL);
889 file = g_build_filename (data->basedir, "Incoming", "NextContent.html", NULL);
890 g_file_get_contents (file, &data->in_nextcontent_html, &data->in_nextcontent_len, NULL);
893 file = g_build_filename (data->basedir, "Outgoing", "Content.html", NULL);
894 g_file_get_contents (file, &data->out_content_html, &data->out_content_len, NULL);
897 file = g_build_filename (data->basedir, "Outgoing", "NextContent.html", NULL);
898 g_file_get_contents (file, &data->out_nextcontent_html, &data->out_nextcontent_len, NULL);
901 file = g_build_filename (data->basedir, "Status.html", NULL);
902 g_file_get_contents (file, &data->status_html, &data->status_len, NULL);
905 file = g_build_filename (data->basedir, "Footer.html", NULL);
906 g_file_get_contents (file, &footer_html, &footer_len, NULL);
909 file = g_build_filename (data->basedir, "Incoming", "buddy_icon.png", NULL);
910 if (g_file_test (file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
911 data->default_incoming_avatar_filename = file;
916 file = g_build_filename (data->basedir, "Outgoing", "buddy_icon.png", NULL);
917 if (g_file_test (file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
918 data->default_outgoing_avatar_filename = file;
923 css_path = g_build_filename (data->basedir, "main.css", NULL);
925 /* There is 2 formats for Template.html: The old one has 4 parameters,
926 * the new one has 5 parameters. */
927 file = g_build_filename (data->basedir, "Template.html", NULL);
928 if (g_file_get_contents (file, &template_html, &template_len, NULL)) {
929 strv = g_strsplit (template_html, "%@", -1);
930 len = g_strv_length (strv);
934 if (len != 5 && len != 6) {
935 /* Either the theme has no template or it don't have the good
936 * number of parameters. Fallback to use our own template. */
937 g_free (template_html);
940 file = empathy_file_lookup ("Template.html", "data");
941 g_file_get_contents (file, &template_html, &template_len, NULL);
943 strv = g_strsplit (template_html, "%@", -1);
944 len = g_strv_length (strv);
947 /* Replace %@ with the needed information in the template html. */
948 string = g_string_sized_new (template_len);
949 g_string_append (string, strv[i++]);
950 g_string_append (string, data->basedir);
951 g_string_append (string, strv[i++]);
953 const gchar *variant;
955 /* We include main.css by default */
956 g_string_append_printf (string, "@import url(\"%s\");", css_path);
957 g_string_append (string, strv[i++]);
958 variant = tp_asv_get_string (data->info, "DefaultVariant");
960 g_string_append (string, "Variants/");
961 g_string_append (string, variant);
962 g_string_append (string, ".css");
965 /* FIXME: We should set main.css OR the variant css */
966 g_string_append (string, css_path);
968 g_string_append (string, strv[i++]);
969 g_string_append (string, ""); /* We don't want header */
970 g_string_append (string, strv[i++]);
971 /* FIXME: We should replace adium %macros% in footer */
973 g_string_append (string, footer_html);
975 g_string_append (string, strv[i++]);
976 data->template_html = g_string_free (string, FALSE);
978 g_free (footer_html);
979 g_free (template_html);
987 empathy_adium_data_new (const gchar *path)
989 EmpathyAdiumData *data;
992 info = empathy_adium_info_new (path);
993 data = empathy_adium_data_new_with_info (path, info);
994 g_hash_table_unref (info);
1000 empathy_adium_data_ref (EmpathyAdiumData *data)
1002 g_return_val_if_fail (data != NULL, NULL);
1010 empathy_adium_data_unref (EmpathyAdiumData *data)
1012 g_return_if_fail (data != NULL);
1015 if (data->ref_count == 0) {
1016 g_free (data->path);
1017 g_free (data->basedir);
1018 g_free (data->template_html);
1019 g_free (data->in_content_html);
1020 g_free (data->in_nextcontent_html);
1021 g_free (data->out_content_html);
1022 g_free (data->out_nextcontent_html);
1023 g_free (data->default_avatar_filename);
1024 g_free (data->default_incoming_avatar_filename);
1025 g_free (data->default_outgoing_avatar_filename);
1026 g_free (data->status_html);
1027 g_hash_table_unref (data->info);
1028 g_slice_free (EmpathyAdiumData, data);
1033 empathy_adium_data_get_info (EmpathyAdiumData *data)
1035 g_return_val_if_fail (data != NULL, NULL);
1041 empathy_adium_data_get_path (EmpathyAdiumData *data)
1043 g_return_val_if_fail (data != NULL, NULL);