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>
34 #include <libmissioncontrol/mc-profile.h>
36 #include "empathy-theme-adium.h"
37 #include "empathy-smiley-manager.h"
38 #include "empathy-conf.h"
39 #include "empathy-ui-utils.h"
40 #include "empathy-plist.h"
42 #define DEBUG_FLAG EMPATHY_DEBUG_CHAT
43 #include <libempathy/empathy-debug.h>
45 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyThemeAdium)
47 /* "Join" consecutive messages with timestamps within five minutes */
48 #define MESSAGE_JOIN_PERIOD 5*60
51 EmpathyAdiumData *data;
52 EmpathySmileyManager *smiley_manager;
53 EmpathyContact *last_contact;
54 time_t last_timestamp;
57 } EmpathyThemeAdiumPriv;
59 struct _EmpathyAdiumData {
63 gchar *default_avatar_filename;
64 gchar *default_incoming_avatar_filename;
65 gchar *default_outgoing_avatar_filename;
67 gchar *in_content_html;
69 gchar *in_nextcontent_html;
70 gsize in_nextcontent_len;
71 gchar *out_content_html;
72 gsize out_content_len;
73 gchar *out_nextcontent_html;
74 gsize out_nextcontent_len;
80 static void theme_adium_iface_init (EmpathyChatViewIface *iface);
87 G_DEFINE_TYPE_WITH_CODE (EmpathyThemeAdium, empathy_theme_adium,
89 G_IMPLEMENT_INTERFACE (EMPATHY_TYPE_CHAT_VIEW,
90 theme_adium_iface_init));
92 static WebKitNavigationResponse
93 theme_adium_navigation_requested_cb (WebKitWebView *view,
94 WebKitWebFrame *frame,
95 WebKitNetworkRequest *request,
100 uri = webkit_network_request_get_uri (request);
101 empathy_url_show (GTK_WIDGET (view), uri);
103 return WEBKIT_NAVIGATION_RESPONSE_IGNORE;
107 theme_adium_populate_popup_cb (WebKitWebView *view,
113 /* Remove default menu items */
114 gtk_container_foreach (GTK_CONTAINER (menu),
115 (GtkCallback) gtk_widget_destroy, NULL);
117 /* Select all item */
118 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
119 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
120 gtk_widget_show (item);
122 g_signal_connect_swapped (item, "activate",
123 G_CALLBACK (webkit_web_view_select_all),
127 if (webkit_web_view_can_copy_clipboard (view)) {
128 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL);
129 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
130 gtk_widget_show (item);
132 g_signal_connect_swapped (item, "activate",
133 G_CALLBACK (webkit_web_view_copy_clipboard),
137 /* Clear menu item */
138 item = gtk_separator_menu_item_new ();
139 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
140 gtk_widget_show (item);
142 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_CLEAR, NULL);
143 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
144 gtk_widget_show (item);
146 g_signal_connect_swapped (item, "activate",
147 G_CALLBACK (empathy_chat_view_clear),
150 /* FIXME: Add open_link and copy_link when those bugs are fixed:
151 * https://bugs.webkit.org/show_bug.cgi?id=16092
152 * https://bugs.webkit.org/show_bug.cgi?id=16562
157 theme_adium_parse_body (EmpathyThemeAdium *theme,
160 EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
161 gboolean use_smileys = FALSE;
166 GMatchInfo *match_info;
171 empathy_conf_get_bool (empathy_conf_get (),
172 EMPATHY_PREFS_CHAT_SHOW_SMILEYS,
176 /* Replace smileys by a <img/> tag */
177 string = g_string_sized_new (strlen (text));
178 smileys = empathy_smiley_manager_parse (priv->smiley_manager, text);
179 for (l = smileys; l; l = l->next) {
180 EmpathySmiley *smiley;
184 g_string_append_printf (string,
185 "<abbr title='%s'><img src=\"%s\"/ alt=\"%s\"/></abbr>",
186 smiley->str, smiley->path, smiley->str);
190 str = g_markup_escape_text (smiley->str, -1);
191 g_string_append (string, str);
194 empathy_smiley_free (smiley);
196 g_slist_free (smileys);
199 text = ret = g_string_free (string, FALSE);
202 /* Add <a href></a> arround links */
203 uri_regex = empathy_uri_regex_dup_singleton ();
204 match = g_regex_match (uri_regex, text, 0, &match_info);
209 string = g_string_sized_new (strlen (text));
211 g_match_info_fetch_pos (match_info, 0, &s, &e);
214 /* Append the text between last link (or the
215 * start of the message) and this link */
216 g_string_append_len (string, text + last, s - last);
219 /* Append the link inside <a href=""></a> tag */
220 g_string_append (string, "<a href=\"");
221 g_string_append_len (string, text + s, e - s);
222 g_string_append (string, "\">");
223 g_string_append_len (string, text + s, e - s);
224 g_string_append (string, "</a>");
227 } while (g_match_info_next (match_info, NULL));
229 if (e < strlen (text)) {
230 /* Append the text after the last link */
231 g_string_append_len (string, text + e, strlen (text) - e);
235 text = ret = g_string_free (string, FALSE);
237 g_match_info_free (match_info);
238 g_regex_unref (uri_regex);
240 /* Replace \n by <br/> */
243 for (i = 0; text[i] != '\0'; i++) {
244 if (text[i] == '\n') {
246 string = g_string_sized_new (strlen (text));
248 g_string_append_len (string, text + prev, i - prev);
249 g_string_append (string, "<br/>");
254 g_string_append (string, text + prev);
256 text = ret = g_string_free (string, FALSE);
263 escape_and_append_len (GString *string, const gchar *str, gint len)
265 while (*str != '\0' && len != 0) {
269 g_string_append (string, "\\\\");
273 g_string_append (string, "\\\"");
276 /* Remove end of lines */
279 g_string_append_c (string, *str);
288 theme_adium_match (const gchar **str, const gchar *match)
292 len = strlen (match);
293 if (strncmp (*str, match, len) == 0) {
302 theme_adium_append_html (EmpathyThemeAdium *theme,
304 const gchar *html, gsize len,
305 const gchar *message,
306 const gchar *avatar_filename,
308 const gchar *contact_id,
309 const gchar *service_name,
310 const gchar *message_classes,
314 const gchar *cur = NULL;
317 /* Make some search-and-replace in the html code */
318 string = g_string_sized_new (len + strlen (message));
319 g_string_append_printf (string, "%s(\"", func);
320 for (cur = html; *cur != '\0'; cur++) {
321 const gchar *replace = NULL;
322 gchar *dup_replace = NULL;
324 if (theme_adium_match (&cur, "%message%")) {
326 } else if (theme_adium_match (&cur, "%messageClasses%")) {
327 replace = message_classes;
328 } else if (theme_adium_match (&cur, "%userIconPath%")) {
329 replace = avatar_filename;
330 } else if (theme_adium_match (&cur, "%sender%")) {
332 } else if (theme_adium_match (&cur, "%senderScreenName%")) {
333 replace = contact_id;
334 } else if (theme_adium_match (&cur, "%senderDisplayName%")) {
335 /* %senderDisplayName% -
336 * "The serverside (remotely set) name of the sender,
337 * such as an MSN display name."
339 * We don't have access to that yet so we use local
342 } else if (theme_adium_match (&cur, "%service%")) {
343 replace = service_name;
344 } else if (theme_adium_match (&cur, "%shortTime%")) {
345 dup_replace = empathy_time_to_string_local (timestamp,
346 EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
347 replace = dup_replace;
348 } else if (theme_adium_match (&cur, "%time")) {
349 gchar *format = NULL;
352 /* Time can be in 2 formats:
353 * %time% or %time{strftime format}%
354 * Extract the time format if provided. */
357 end = strstr (cur, "}%");
362 format = g_strndup (cur, end - cur);
368 dup_replace = empathy_time_to_string_local (timestamp,
369 format ? format : EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
370 replace = dup_replace;
373 escape_and_append_len (string, cur, 1);
377 /* Here we have a replacement to make */
378 escape_and_append_len (string, replace, -1);
379 g_free (dup_replace);
381 g_string_append (string, "\")");
383 script = g_string_free (string, FALSE);
384 webkit_web_view_execute_script (WEBKIT_WEB_VIEW (theme), script);
389 theme_adium_append_message (EmpathyChatView *view,
392 EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (view);
393 EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
394 EmpathyContact *sender;
395 EmpathyAccount *account;
396 McProfile *account_profile;
397 gchar *dup_body = NULL;
400 const gchar *contact_id;
401 EmpathyAvatar *avatar;
402 const gchar *avatar_filename = NULL;
407 const gchar *service_name;
408 const gchar *message_classes = NULL;
410 if (!priv->page_loaded) {
411 priv->message_queue = g_list_prepend (priv->message_queue,
416 /* Get information */
417 sender = empathy_message_get_sender (msg);
418 account = empathy_contact_get_account (sender);
419 account_profile = empathy_account_get_profile (account);
420 service_name = mc_profile_get_display_name (account_profile);
421 timestamp = empathy_message_get_timestamp (msg);
422 body = empathy_message_get_body (msg);
423 dup_body = theme_adium_parse_body (theme, body);
427 name = empathy_contact_get_name (sender);
428 contact_id = empathy_contact_get_id (sender);
430 /* If this is a /me, append an event */
431 if (empathy_message_get_tptype (msg) == TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION) {
434 str = g_strdup_printf ("%s %s", name, body);
435 empathy_chat_view_append_event (view, str);
441 /* Get the avatar filename, or a fallback */
442 avatar = empathy_contact_get_avatar (sender);
444 avatar_filename = avatar->filename;
446 if (!avatar_filename) {
447 if (empathy_contact_is_user (sender)) {
448 avatar_filename = priv->data->default_outgoing_avatar_filename;
450 avatar_filename = priv->data->default_incoming_avatar_filename;
452 if (!avatar_filename) {
453 if (!priv->data->default_avatar_filename) {
454 priv->data->default_avatar_filename =
455 empathy_filename_from_icon_name ("stock_person",
456 GTK_ICON_SIZE_DIALOG);
458 avatar_filename = priv->data->default_avatar_filename;
462 /* Get the right html/func to add the message */
463 func = "appendMessage";
465 * To mimick Adium's behavior, we only want to join messages
466 * sent within a 5 minute time frame.
468 if (empathy_contact_equal (priv->last_contact, sender) &&
469 (timestamp - priv->last_timestamp < MESSAGE_JOIN_PERIOD)) {
470 func = "appendNextMessage";
471 if (empathy_contact_is_user (sender)) {
472 message_classes = "consecutive incoming message";
473 html = priv->data->out_nextcontent_html;
474 len = priv->data->out_nextcontent_len;
477 message_classes = "consecutive message outgoing";
478 html = priv->data->in_nextcontent_html;
479 len = priv->data->in_nextcontent_len;
483 if (empathy_contact_is_user (sender)) {
484 if (!message_classes) {
485 message_classes = "incoming message";
487 html = priv->data->out_content_html;
488 len = priv->data->out_content_len;
491 if (!message_classes) {
492 message_classes = "message outgoing";
494 html = priv->data->in_content_html;
495 len = priv->data->in_content_len;
499 theme_adium_append_html (theme, func, html, len, body, avatar_filename,
500 name, contact_id, service_name, message_classes,
503 /* Keep the sender of the last displayed message */
504 if (priv->last_contact) {
505 g_object_unref (priv->last_contact);
507 priv->last_contact = g_object_ref (sender);
508 priv->last_timestamp = timestamp;
514 theme_adium_append_event (EmpathyChatView *view,
517 EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (view);
518 EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
520 if (priv->data->status_html) {
521 theme_adium_append_html (theme, "appendMessage",
522 priv->data->status_html,
523 priv->data->status_len,
524 str, NULL, NULL, NULL, NULL, "event",
525 empathy_time_get_current ());
528 /* There is no last contact */
529 if (priv->last_contact) {
530 g_object_unref (priv->last_contact);
531 priv->last_contact = NULL;
536 theme_adium_scroll (EmpathyChatView *view,
537 gboolean allow_scrolling)
539 /* FIXME: Is it possible? I guess we need a js function, but I don't
544 theme_adium_scroll_down (EmpathyChatView *view)
546 webkit_web_view_execute_script (WEBKIT_WEB_VIEW (view), "scrollToBottom()");
550 theme_adium_get_has_selection (EmpathyChatView *view)
552 return webkit_web_view_has_selection (WEBKIT_WEB_VIEW (view));
556 theme_adium_clear (EmpathyChatView *view)
558 EmpathyThemeAdiumPriv *priv = GET_PRIV (view);
561 priv->page_loaded = FALSE;
562 basedir_uri = g_strconcat ("file://", priv->data->basedir, NULL);
563 webkit_web_view_load_html_string (WEBKIT_WEB_VIEW (view),
564 priv->data->template_html,
566 g_free (basedir_uri);
568 /* Clear last contact to avoid trying to add a 'joined'
569 * message when we don't have an insertion point. */
570 if (priv->last_contact) {
571 g_object_unref (priv->last_contact);
572 priv->last_contact = NULL;
577 theme_adium_find_previous (EmpathyChatView *view,
578 const gchar *search_criteria,
581 return webkit_web_view_search_text (WEBKIT_WEB_VIEW (view),
582 search_criteria, FALSE,
587 theme_adium_find_next (EmpathyChatView *view,
588 const gchar *search_criteria,
591 return webkit_web_view_search_text (WEBKIT_WEB_VIEW (view),
592 search_criteria, FALSE,
597 theme_adium_find_abilities (EmpathyChatView *view,
598 const gchar *search_criteria,
599 gboolean *can_do_previous,
600 gboolean *can_do_next)
602 /* FIXME: Does webkit provide an API for that? We have wrap=true in
603 * find_next and find_previous to work around this problem. */
605 *can_do_previous = TRUE;
611 theme_adium_highlight (EmpathyChatView *view,
614 webkit_web_view_unmark_text_matches (WEBKIT_WEB_VIEW (view));
615 webkit_web_view_mark_text_matches (WEBKIT_WEB_VIEW (view),
617 webkit_web_view_set_highlight_text_matches (WEBKIT_WEB_VIEW (view),
622 theme_adium_copy_clipboard (EmpathyChatView *view)
624 webkit_web_view_copy_clipboard (WEBKIT_WEB_VIEW (view));
628 theme_adium_iface_init (EmpathyChatViewIface *iface)
630 iface->append_message = theme_adium_append_message;
631 iface->append_event = theme_adium_append_event;
632 iface->scroll = theme_adium_scroll;
633 iface->scroll_down = theme_adium_scroll_down;
634 iface->get_has_selection = theme_adium_get_has_selection;
635 iface->clear = theme_adium_clear;
636 iface->find_previous = theme_adium_find_previous;
637 iface->find_next = theme_adium_find_next;
638 iface->find_abilities = theme_adium_find_abilities;
639 iface->highlight = theme_adium_highlight;
640 iface->copy_clipboard = theme_adium_copy_clipboard;
644 theme_adium_load_finished_cb (WebKitWebView *view,
645 WebKitWebFrame *frame,
648 EmpathyThemeAdiumPriv *priv = GET_PRIV (view);
649 EmpathyChatView *chat_view = EMPATHY_CHAT_VIEW (view);
651 DEBUG ("Page loaded");
652 priv->page_loaded = TRUE;
654 /* Display queued messages */
655 priv->message_queue = g_list_reverse (priv->message_queue);
656 while (priv->message_queue) {
657 EmpathyMessage *message = priv->message_queue->data;
659 theme_adium_append_message (chat_view, message);
660 priv->message_queue = g_list_remove (priv->message_queue, message);
661 g_object_unref (message);
666 theme_adium_finalize (GObject *object)
668 EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
670 empathy_adium_data_unref (priv->data);
672 G_OBJECT_CLASS (empathy_theme_adium_parent_class)->finalize (object);
676 theme_adium_dispose (GObject *object)
678 EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
680 if (priv->smiley_manager) {
681 g_object_unref (priv->smiley_manager);
682 priv->smiley_manager = NULL;
685 if (priv->last_contact) {
686 g_object_unref (priv->last_contact);
687 priv->last_contact = NULL;
690 G_OBJECT_CLASS (empathy_theme_adium_parent_class)->dispose (object);
694 theme_adium_constructed (GObject *object)
696 EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
698 const gchar *font_family = NULL;
700 WebKitWebSettings *webkit_settings;
702 /* Set default settings */
703 font_family = tp_asv_get_string (priv->data->info, "DefaultFontFamily");
704 font_size = tp_asv_get_int32 (priv->data->info, "DefaultFontSize", NULL);
705 webkit_settings = webkit_web_settings_new ();
707 g_object_set (G_OBJECT (webkit_settings), "default-font-family", font_family, NULL);
710 g_object_set (G_OBJECT (webkit_settings), "default-font-size", font_size, NULL);
712 webkit_web_view_set_settings (WEBKIT_WEB_VIEW (object), webkit_settings);
715 basedir_uri = g_strconcat ("file://", priv->data->basedir, NULL);
716 webkit_web_view_load_html_string (WEBKIT_WEB_VIEW (object),
717 priv->data->template_html,
720 g_object_unref (webkit_settings);
721 g_free (basedir_uri);
725 theme_adium_get_property (GObject *object,
730 EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
733 case PROP_ADIUM_DATA:
734 g_value_set_boxed (value, priv->data);
737 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
743 theme_adium_set_property (GObject *object,
748 EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
751 case PROP_ADIUM_DATA:
752 g_assert (priv->data == NULL);
753 priv->data = g_value_dup_boxed (value);
756 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
762 empathy_theme_adium_class_init (EmpathyThemeAdiumClass *klass)
764 GObjectClass *object_class = G_OBJECT_CLASS (klass);
766 object_class->finalize = theme_adium_finalize;
767 object_class->dispose = theme_adium_dispose;
768 object_class->constructed = theme_adium_constructed;
769 object_class->get_property = theme_adium_get_property;
770 object_class->set_property = theme_adium_set_property;
772 g_object_class_install_property (object_class,
774 g_param_spec_boxed ("adium-data",
776 "Data for the adium theme",
777 EMPATHY_TYPE_ADIUM_DATA,
778 G_PARAM_CONSTRUCT_ONLY |
780 G_PARAM_STATIC_STRINGS));
783 g_type_class_add_private (object_class, sizeof (EmpathyThemeAdiumPriv));
787 empathy_theme_adium_init (EmpathyThemeAdium *theme)
789 EmpathyThemeAdiumPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (theme,
790 EMPATHY_TYPE_THEME_ADIUM, EmpathyThemeAdiumPriv);
794 priv->smiley_manager = empathy_smiley_manager_dup_singleton ();
796 g_signal_connect (theme, "load-finished",
797 G_CALLBACK (theme_adium_load_finished_cb),
799 g_signal_connect (theme, "navigation-requested",
800 G_CALLBACK (theme_adium_navigation_requested_cb),
802 g_signal_connect (theme, "populate-popup",
803 G_CALLBACK (theme_adium_populate_popup_cb),
808 empathy_theme_adium_new (EmpathyAdiumData *data)
810 g_return_val_if_fail (data != NULL, NULL);
812 return g_object_new (EMPATHY_TYPE_THEME_ADIUM,
818 empathy_adium_path_is_valid (const gchar *path)
823 /* We ship a default Template.html as fallback if there is any problem
824 * with the one inside the theme. The only other required file is
825 * Content.html for incoming messages (outgoing fallback to use
827 file = g_build_filename (path, "Contents", "Resources", "Incoming",
828 "Content.html", NULL);
829 ret = g_file_test (file, G_FILE_TEST_EXISTS);
836 empathy_adium_info_new (const gchar *path)
840 GHashTable *info = NULL;
842 g_return_val_if_fail (empathy_adium_path_is_valid (path), NULL);
844 file = g_build_filename (path, "Contents", "Info.plist", NULL);
845 value = empathy_plist_parse_from_file (file);
849 info = g_value_dup_boxed (value);
850 tp_g_value_slice_free (value);
857 empathy_adium_data_get_type (void)
859 static GType type_id = 0;
863 type_id = g_boxed_type_register_static ("EmpathyAdiumData",
864 (GBoxedCopyFunc) empathy_adium_data_ref,
865 (GBoxedFreeFunc) empathy_adium_data_unref);
872 empathy_adium_data_new_with_info (const gchar *path, GHashTable *info)
874 EmpathyAdiumData *data;
876 gchar *template_html = NULL;
878 gchar *footer_html = NULL;
886 g_return_val_if_fail (empathy_adium_path_is_valid (path), NULL);
888 data = g_slice_new0 (EmpathyAdiumData);
890 data->path = g_strdup (path);
891 data->basedir = g_strconcat (path, G_DIR_SEPARATOR_S "Contents"
892 G_DIR_SEPARATOR_S "Resources" G_DIR_SEPARATOR_S, NULL);
893 data->info = g_hash_table_ref (info);
895 /* Load html files */
896 file = g_build_filename (data->basedir, "Incoming", "Content.html", NULL);
897 g_file_get_contents (file, &data->in_content_html, &data->in_content_len, NULL);
900 file = g_build_filename (data->basedir, "Incoming", "NextContent.html", NULL);
901 g_file_get_contents (file, &data->in_nextcontent_html, &data->in_nextcontent_len, NULL);
904 file = g_build_filename (data->basedir, "Outgoing", "Content.html", NULL);
905 g_file_get_contents (file, &data->out_content_html, &data->out_content_len, NULL);
908 file = g_build_filename (data->basedir, "Outgoing", "NextContent.html", NULL);
909 g_file_get_contents (file, &data->out_nextcontent_html, &data->out_nextcontent_len, NULL);
912 file = g_build_filename (data->basedir, "Status.html", NULL);
913 g_file_get_contents (file, &data->status_html, &data->status_len, NULL);
916 file = g_build_filename (data->basedir, "Footer.html", NULL);
917 g_file_get_contents (file, &footer_html, &footer_len, NULL);
920 file = g_build_filename (data->basedir, "Incoming", "buddy_icon.png", NULL);
921 if (g_file_test (file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
922 data->default_incoming_avatar_filename = file;
927 file = g_build_filename (data->basedir, "Outgoing", "buddy_icon.png", NULL);
928 if (g_file_test (file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
929 data->default_outgoing_avatar_filename = file;
934 css_path = g_build_filename (data->basedir, "main.css", NULL);
936 /* There is 2 formats for Template.html: The old one has 4 parameters,
937 * the new one has 5 parameters. */
938 file = g_build_filename (data->basedir, "Template.html", NULL);
939 if (g_file_get_contents (file, &template_html, &template_len, NULL)) {
940 strv = g_strsplit (template_html, "%@", -1);
941 len = g_strv_length (strv);
945 if (len != 5 && len != 6) {
946 /* Either the theme has no template or it don't have the good
947 * number of parameters. Fallback to use our own template. */
948 g_free (template_html);
951 file = empathy_file_lookup ("Template.html", "data");
952 g_file_get_contents (file, &template_html, &template_len, NULL);
954 strv = g_strsplit (template_html, "%@", -1);
955 len = g_strv_length (strv);
958 /* Replace %@ with the needed information in the template html. */
959 string = g_string_sized_new (template_len);
960 g_string_append (string, strv[i++]);
961 g_string_append (string, data->basedir);
962 g_string_append (string, strv[i++]);
964 const gchar *variant;
966 /* We include main.css by default */
967 g_string_append_printf (string, "@import url(\"%s\");", css_path);
968 g_string_append (string, strv[i++]);
969 variant = tp_asv_get_string (data->info, "DefaultVariant");
971 g_string_append (string, "Variants/");
972 g_string_append (string, variant);
973 g_string_append (string, ".css");
976 /* FIXME: We should set main.css OR the variant css */
977 g_string_append (string, css_path);
979 g_string_append (string, strv[i++]);
980 g_string_append (string, ""); /* We don't want header */
981 g_string_append (string, strv[i++]);
982 /* FIXME: We should replace adium %macros% in footer */
984 g_string_append (string, footer_html);
986 g_string_append (string, strv[i++]);
987 data->template_html = g_string_free (string, FALSE);
989 g_free (footer_html);
990 g_free (template_html);
998 empathy_adium_data_new (const gchar *path)
1000 EmpathyAdiumData *data;
1003 info = empathy_adium_info_new (path);
1004 data = empathy_adium_data_new_with_info (path, info);
1005 g_hash_table_unref (info);
1011 empathy_adium_data_ref (EmpathyAdiumData *data)
1013 g_return_val_if_fail (data != NULL, NULL);
1021 empathy_adium_data_unref (EmpathyAdiumData *data)
1023 g_return_if_fail (data != NULL);
1026 if (data->ref_count == 0) {
1027 g_free (data->path);
1028 g_free (data->basedir);
1029 g_free (data->template_html);
1030 g_free (data->in_content_html);
1031 g_free (data->in_nextcontent_html);
1032 g_free (data->out_content_html);
1033 g_free (data->out_nextcontent_html);
1034 g_free (data->default_avatar_filename);
1035 g_free (data->default_incoming_avatar_filename);
1036 g_free (data->default_outgoing_avatar_filename);
1037 g_free (data->status_html);
1038 g_hash_table_unref (data->info);
1039 g_slice_free (EmpathyAdiumData, data);
1044 empathy_adium_data_get_info (EmpathyAdiumData *data)
1046 g_return_val_if_fail (data != NULL, NULL);
1052 empathy_adium_data_get_path (EmpathyAdiumData *data)
1054 g_return_val_if_fail (data != NULL, NULL);