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>
30 #include <libempathy/empathy-time.h>
31 #include <libempathy/empathy-utils.h>
32 #include <libmissioncontrol/mc-profile.h>
34 #include "empathy-theme-adium.h"
35 #include "empathy-smiley-manager.h"
36 #include "empathy-conf.h"
37 #include "empathy-ui-utils.h"
38 #include "empathy-plist.h"
40 #define DEBUG_FLAG EMPATHY_DEBUG_CHAT
41 #include <libempathy/empathy-debug.h>
43 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyThemeAdium)
45 /* "Join" consecutive messages with timestamps within five minutes */
46 #define MESSAGE_JOIN_PERIOD 5*60
49 EmpathySmileyManager *smiley_manager;
50 EmpathyContact *last_contact;
51 time_t last_timestamp;
55 gchar *default_avatar_filename;
56 gchar *default_incoming_avatar_filename;
57 gchar *default_outgoing_avatar_filename;
60 gchar *in_content_html;
62 gchar *in_nextcontent_html;
63 gsize in_nextcontent_len;
64 gchar *out_content_html;
65 gsize out_content_len;
66 gchar *out_nextcontent_html;
67 gsize out_nextcontent_len;
70 } EmpathyThemeAdiumPriv;
72 static void theme_adium_iface_init (EmpathyChatViewIface *iface);
79 G_DEFINE_TYPE_WITH_CODE (EmpathyThemeAdium, empathy_theme_adium,
81 G_IMPLEMENT_INTERFACE (EMPATHY_TYPE_CHAT_VIEW,
82 theme_adium_iface_init));
85 theme_adium_load (EmpathyThemeAdium *theme)
87 EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
89 gchar *template_html = NULL;
91 gchar *footer_html = NULL;
100 GHashTable *theme_info;
101 const gchar *variant = NULL;
102 const gchar *font_family = NULL;
104 WebKitWebSettings *webkit_settings;
106 priv->basedir = g_strconcat (priv->path, G_DIR_SEPARATOR_S "Contents" G_DIR_SEPARATOR_S "Resources" G_DIR_SEPARATOR_S, NULL);
107 basedir_uri = g_strconcat ("file://", priv->basedir, NULL);
109 /* Load html files */
110 file = g_build_filename (priv->basedir, "Incoming", "Content.html", NULL);
111 g_file_get_contents (file, &priv->in_content_html, &priv->in_content_len, NULL);
114 file = g_build_filename (priv->basedir, "Incoming", "NextContent.html", NULL);
115 g_file_get_contents (file, &priv->in_nextcontent_html, &priv->in_nextcontent_len, NULL);
118 file = g_build_filename (priv->basedir, "Outgoing", "Content.html", NULL);
119 g_file_get_contents (file, &priv->out_content_html, &priv->out_content_len, NULL);
122 file = g_build_filename (priv->basedir, "Outgoing", "NextContent.html", NULL);
123 g_file_get_contents (file, &priv->out_nextcontent_html, &priv->out_nextcontent_len, NULL);
126 file = g_build_filename (priv->basedir, "Status.html", NULL);
127 g_file_get_contents (file, &priv->status_html, &priv->status_len, NULL);
130 file = g_build_filename (priv->basedir, "Footer.html", NULL);
131 g_file_get_contents (file, &footer_html, &footer_len, NULL);
134 file = g_build_filename (priv->basedir, "Incoming", "buddy_icon.png", NULL);
135 if (g_file_test (file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
136 priv->default_incoming_avatar_filename = file;
141 file = g_build_filename (priv->basedir, "Outgoing", "buddy_icon.png", NULL);
142 if (g_file_test (file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
143 priv->default_outgoing_avatar_filename = file;
148 css_path = g_build_filename (priv->basedir, "main.css", NULL);
150 /* There is 2 formats for Template.html: The old one has 4 parameters,
151 * the new one has 5 parameters. */
152 file = g_build_filename (priv->basedir, "Template.html", NULL);
153 if (g_file_get_contents (file, &template_html, &template_len, NULL)) {
154 strv = g_strsplit (template_html, "%@", -1);
155 len = g_strv_length (strv);
159 if (len != 5 && len != 6) {
160 /* Either the theme has no template or it don't have the good
161 * number of parameters. Fallback to use our own template. */
162 g_free (template_html);
165 file = empathy_file_lookup ("Template.html", "data");
166 g_file_get_contents (file, &template_html, &template_len, NULL);
168 strv = g_strsplit (template_html, "%@", -1);
169 len = g_strv_length (strv);
172 file = g_build_filename (priv->path, "Contents", "Info.plist", NULL);
173 value = empathy_plist_parse_from_file (file);
177 theme_info = g_value_get_boxed (value);
178 variant = tp_asv_get_string (theme_info, "DefaultVariant");
179 font_family = tp_asv_get_string (theme_info, "DefaultFontFamily");
180 font_size = tp_asv_get_int32 (theme_info, "DefaultFontSize", NULL);
183 /* Replace %@ with the needed information in the template html. */
184 string = g_string_sized_new (template_len);
185 g_string_append (string, strv[i++]);
186 g_string_append (string, priv->basedir);
187 g_string_append (string, strv[i++]);
189 /* We include main.css by default */
190 g_string_append_printf (string, "@import url(\"%s\");", css_path);
191 g_string_append (string, strv[i++]);
193 g_string_append (string, "Variants/");
194 g_string_append (string, variant);
195 g_string_append (string, ".css");
198 /* FIXME: We should set main.css OR the variant css */
199 g_string_append (string, css_path);
201 g_string_append (string, strv[i++]);
202 g_string_append (string, ""); /* We don't want header */
203 g_string_append (string, strv[i++]);
204 /* FIXME: We should replace adium %macros% in footer */
205 g_string_append (string, footer_html);
206 g_string_append (string, strv[i++]);
207 priv->template_html = g_string_free (string, FALSE);
209 /* Load the template */
210 webkit_settings = webkit_web_settings_new ();
212 g_object_set (G_OBJECT (webkit_settings), "default-font-family", font_family, NULL);
215 g_object_set (G_OBJECT (webkit_settings), "default-font-size", font_size, NULL);
218 webkit_web_view_set_settings (WEBKIT_WEB_VIEW (theme), webkit_settings);
219 webkit_web_view_load_html_string (WEBKIT_WEB_VIEW (theme),
220 priv->template_html, basedir_uri);
222 g_object_unref (webkit_settings);
223 g_free (basedir_uri);
224 g_free (footer_html);
225 g_free (template_html);
230 static WebKitNavigationResponse
231 theme_adium_navigation_requested_cb (WebKitWebView *view,
232 WebKitWebFrame *frame,
233 WebKitNetworkRequest *request,
238 uri = webkit_network_request_get_uri (request);
239 empathy_url_show (GTK_WIDGET (view), uri);
241 return WEBKIT_NAVIGATION_RESPONSE_IGNORE;
245 theme_adium_populate_popup_cb (WebKitWebView *view,
251 /* Remove default menu items */
252 gtk_container_foreach (GTK_CONTAINER (menu),
253 (GtkCallback) gtk_widget_destroy, NULL);
255 /* Select all item */
256 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
257 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
258 gtk_widget_show (item);
260 g_signal_connect_swapped (item, "activate",
261 G_CALLBACK (webkit_web_view_select_all),
265 if (webkit_web_view_can_copy_clipboard (view)) {
266 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL);
267 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
268 gtk_widget_show (item);
270 g_signal_connect_swapped (item, "activate",
271 G_CALLBACK (webkit_web_view_copy_clipboard),
275 /* Clear menu item */
276 item = gtk_separator_menu_item_new ();
277 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
278 gtk_widget_show (item);
280 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_CLEAR, NULL);
281 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
282 gtk_widget_show (item);
284 g_signal_connect_swapped (item, "activate",
285 G_CALLBACK (empathy_chat_view_clear),
288 /* FIXME: Add open_link and copy_link when those bugs are fixed:
289 * https://bugs.webkit.org/show_bug.cgi?id=16092
290 * https://bugs.webkit.org/show_bug.cgi?id=16562
295 theme_adium_parse_body (EmpathyThemeAdium *theme,
298 EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
299 gboolean use_smileys = FALSE;
304 GMatchInfo *match_info;
309 empathy_conf_get_bool (empathy_conf_get (),
310 EMPATHY_PREFS_CHAT_SHOW_SMILEYS,
314 /* Replace smileys by a <img/> tag */
315 string = g_string_sized_new (strlen (text));
316 smileys = empathy_smiley_manager_parse (priv->smiley_manager, text);
317 for (l = smileys; l; l = l->next) {
318 EmpathySmiley *smiley;
322 g_string_append_printf (string,
323 "<abbr title='%s'><img src=\"%s\"/ alt=\"%s\"/></abbr>",
324 smiley->str, smiley->path, smiley->str);
328 str = g_markup_escape_text (smiley->str, -1);
329 g_string_append (string, str);
332 empathy_smiley_free (smiley);
334 g_slist_free (smileys);
337 text = ret = g_string_free (string, FALSE);
340 /* Add <a href></a> arround links */
341 uri_regex = empathy_uri_regex_dup_singleton ();
342 match = g_regex_match (uri_regex, text, 0, &match_info);
347 string = g_string_sized_new (strlen (text));
349 g_match_info_fetch_pos (match_info, 0, &s, &e);
352 /* Append the text between last link (or the
353 * start of the message) and this link */
354 g_string_append_len (string, text + last, s - last);
357 /* Append the link inside <a href=""></a> tag */
358 g_string_append (string, "<a href=\"");
359 g_string_append_len (string, text + s, e - s);
360 g_string_append (string, "\">");
361 g_string_append_len (string, text + s, e - s);
362 g_string_append (string, "</a>");
365 } while (g_match_info_next (match_info, NULL));
367 if (e < strlen (text)) {
368 /* Append the text after the last link */
369 g_string_append_len (string, text + e, strlen (text) - e);
373 text = ret = g_string_free (string, FALSE);
375 g_match_info_free (match_info);
376 g_regex_unref (uri_regex);
378 /* Replace \n by <br/> */
381 for (i = 0; text[i] != '\0'; i++) {
382 if (text[i] == '\n') {
384 string = g_string_sized_new (strlen (text));
386 g_string_append_len (string, text + prev, i - prev);
387 g_string_append (string, "<br/>");
392 g_string_append (string, text + prev);
394 text = ret = g_string_free (string, FALSE);
401 escape_and_append_len (GString *string, const gchar *str, gint len)
403 while (*str != '\0' && len != 0) {
407 g_string_append (string, "\\\\");
411 g_string_append (string, "\\\"");
414 /* Remove end of lines */
417 g_string_append_c (string, *str);
426 theme_adium_match (const gchar **str, const gchar *match)
430 len = strlen (match);
431 if (strncmp (*str, match, len) == 0) {
440 theme_adium_append_html (EmpathyThemeAdium *theme,
442 const gchar *html, gsize len,
443 const gchar *message,
444 const gchar *avatar_filename,
446 const gchar *contact_id,
447 const gchar *service_name,
448 const gchar *message_classes,
452 const gchar *cur = NULL;
455 /* Make some search-and-replace in the html code */
456 string = g_string_sized_new (len + strlen (message));
457 g_string_append_printf (string, "%s(\"", func);
458 for (cur = html; *cur != '\0'; cur++) {
459 const gchar *replace = NULL;
460 gchar *dup_replace = NULL;
462 if (theme_adium_match (&cur, "%message%")) {
464 } else if (theme_adium_match (&cur, "%messageClasses%")) {
465 replace = message_classes;
466 } else if (theme_adium_match (&cur, "%userIconPath%")) {
467 replace = avatar_filename;
468 } else if (theme_adium_match (&cur, "%sender%")) {
470 } else if (theme_adium_match (&cur, "%senderScreenName%")) {
471 replace = contact_id;
472 } else if (theme_adium_match (&cur, "%senderDisplayName%")) {
473 /* %senderDisplayName% -
474 * "The serverside (remotely set) name of the sender,
475 * such as an MSN display name."
477 * We don't have access to that yet so we use local
480 } else if (theme_adium_match (&cur, "%service%")) {
481 replace = service_name;
482 } else if (theme_adium_match (&cur, "%shortTime%")) {
483 dup_replace = empathy_time_to_string_local (timestamp,
484 EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
485 replace = dup_replace;
486 } else if (theme_adium_match (&cur, "%time")) {
487 gchar *format = NULL;
490 /* Time can be in 2 formats:
491 * %time% or %time{strftime format}%
492 * Extract the time format if provided. */
495 end = strstr (cur, "}%");
500 format = g_strndup (cur, end - cur);
506 dup_replace = empathy_time_to_string_local (timestamp,
507 format ? format : EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
508 replace = dup_replace;
511 escape_and_append_len (string, cur, 1);
515 /* Here we have a replacement to make */
516 escape_and_append_len (string, replace, -1);
517 g_free (dup_replace);
519 g_string_append (string, "\")");
521 script = g_string_free (string, FALSE);
522 webkit_web_view_execute_script (WEBKIT_WEB_VIEW (theme), script);
527 theme_adium_append_message (EmpathyChatView *view,
530 EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (view);
531 EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
532 EmpathyContact *sender;
534 McProfile *account_profile;
535 gchar *dup_body = NULL;
538 const gchar *contact_id;
539 EmpathyAvatar *avatar;
540 const gchar *avatar_filename = NULL;
545 const gchar *service_name;
546 const gchar *message_classes = NULL;
548 if (!priv->page_loaded) {
549 priv->message_queue = g_list_prepend (priv->message_queue,
554 /* Get information */
555 sender = empathy_message_get_sender (msg);
556 account = empathy_contact_get_account (sender);
557 account_profile = mc_account_get_profile (account);
558 service_name = mc_profile_get_display_name (account_profile);
559 timestamp = empathy_message_get_timestamp (msg);
560 body = empathy_message_get_body (msg);
561 dup_body = theme_adium_parse_body (theme, body);
565 name = empathy_contact_get_name (sender);
566 contact_id = empathy_contact_get_id (sender);
568 /* If this is a /me, append an event */
569 if (empathy_message_get_tptype (msg) == TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION) {
572 str = g_strdup_printf ("%s %s", name, body);
573 empathy_chat_view_append_event (view, str);
579 /* Get the avatar filename, or a fallback */
580 avatar = empathy_contact_get_avatar (sender);
582 avatar_filename = avatar->filename;
584 if (!avatar_filename) {
585 if (empathy_contact_is_user (sender)) {
586 avatar_filename = priv->default_outgoing_avatar_filename;
588 avatar_filename = priv->default_incoming_avatar_filename;
590 if (!avatar_filename) {
591 if (!priv->default_avatar_filename) {
592 priv->default_avatar_filename =
593 empathy_filename_from_icon_name ("stock_person",
594 GTK_ICON_SIZE_DIALOG);
596 avatar_filename = priv->default_avatar_filename;
600 /* Get the right html/func to add the message */
601 func = "appendMessage";
603 * To mimick Adium's behavior, we only want to join messages
604 * sent within a 5 minute time frame.
606 if (empathy_contact_equal (priv->last_contact, sender) &&
607 (timestamp - priv->last_timestamp < MESSAGE_JOIN_PERIOD)) {
608 func = "appendNextMessage";
609 if (empathy_contact_is_user (sender)) {
610 message_classes = "consecutive incoming message";
611 html = priv->out_nextcontent_html;
612 len = priv->out_nextcontent_len;
615 message_classes = "consecutive message outgoing";
616 html = priv->in_nextcontent_html;
617 len = priv->in_nextcontent_len;
621 if (empathy_contact_is_user (sender)) {
622 if (!message_classes) {
623 message_classes = "incoming message";
625 html = priv->out_content_html;
626 len = priv->out_content_len;
629 if (!message_classes) {
630 message_classes = "message outgoing";
632 html = priv->in_content_html;
633 len = priv->in_content_len;
637 theme_adium_append_html (theme, func, html, len, body, avatar_filename,
638 name, contact_id, service_name, message_classes,
641 /* Keep the sender of the last displayed message */
642 if (priv->last_contact) {
643 g_object_unref (priv->last_contact);
645 priv->last_contact = g_object_ref (sender);
646 priv->last_timestamp = timestamp;
652 theme_adium_append_event (EmpathyChatView *view,
655 EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (view);
656 EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
658 if (priv->status_html) {
659 theme_adium_append_html (theme, "appendMessage",
660 priv->status_html, priv->status_len,
661 str, NULL, NULL, NULL, NULL, "event",
662 empathy_time_get_current ());
665 /* There is no last contact */
666 if (priv->last_contact) {
667 g_object_unref (priv->last_contact);
668 priv->last_contact = NULL;
673 theme_adium_scroll (EmpathyChatView *view,
674 gboolean allow_scrolling)
676 /* FIXME: Is it possible? I guess we need a js function, but I don't
681 theme_adium_scroll_down (EmpathyChatView *view)
683 webkit_web_view_execute_script (WEBKIT_WEB_VIEW (view), "scrollToBottom()");
687 theme_adium_get_has_selection (EmpathyChatView *view)
689 return webkit_web_view_has_selection (WEBKIT_WEB_VIEW (view));
693 theme_adium_clear (EmpathyChatView *view)
695 EmpathyThemeAdiumPriv *priv = GET_PRIV (view);
698 priv->page_loaded = FALSE;
699 basedir_uri = g_strconcat ("file://", priv->basedir, NULL);
700 webkit_web_view_load_html_string (WEBKIT_WEB_VIEW (view),
701 priv->template_html, basedir_uri);
702 g_free (basedir_uri);
706 theme_adium_find_previous (EmpathyChatView *view,
707 const gchar *search_criteria,
710 return webkit_web_view_search_text (WEBKIT_WEB_VIEW (view),
711 search_criteria, FALSE,
716 theme_adium_find_next (EmpathyChatView *view,
717 const gchar *search_criteria,
720 return webkit_web_view_search_text (WEBKIT_WEB_VIEW (view),
721 search_criteria, FALSE,
726 theme_adium_find_abilities (EmpathyChatView *view,
727 const gchar *search_criteria,
728 gboolean *can_do_previous,
729 gboolean *can_do_next)
731 /* FIXME: Does webkit provide an API for that? We have wrap=true in
732 * find_next and find_previous to work around this problem. */
734 *can_do_previous = TRUE;
740 theme_adium_highlight (EmpathyChatView *view,
743 webkit_web_view_unmark_text_matches (WEBKIT_WEB_VIEW (view));
744 webkit_web_view_mark_text_matches (WEBKIT_WEB_VIEW (view),
746 webkit_web_view_set_highlight_text_matches (WEBKIT_WEB_VIEW (view),
751 theme_adium_copy_clipboard (EmpathyChatView *view)
753 webkit_web_view_copy_clipboard (WEBKIT_WEB_VIEW (view));
757 theme_adium_iface_init (EmpathyChatViewIface *iface)
759 iface->append_message = theme_adium_append_message;
760 iface->append_event = theme_adium_append_event;
761 iface->scroll = theme_adium_scroll;
762 iface->scroll_down = theme_adium_scroll_down;
763 iface->get_has_selection = theme_adium_get_has_selection;
764 iface->clear = theme_adium_clear;
765 iface->find_previous = theme_adium_find_previous;
766 iface->find_next = theme_adium_find_next;
767 iface->find_abilities = theme_adium_find_abilities;
768 iface->highlight = theme_adium_highlight;
769 iface->copy_clipboard = theme_adium_copy_clipboard;
773 theme_adium_load_finished_cb (WebKitWebView *view,
774 WebKitWebFrame *frame,
777 EmpathyThemeAdiumPriv *priv = GET_PRIV (view);
778 EmpathyChatView *chat_view = EMPATHY_CHAT_VIEW (view);
780 DEBUG ("Page loaded");
781 priv->page_loaded = TRUE;
783 /* Display queued messages */
784 priv->message_queue = g_list_reverse (priv->message_queue);
785 while (priv->message_queue) {
786 EmpathyMessage *message = priv->message_queue->data;
788 theme_adium_append_message (chat_view, message);
789 priv->message_queue = g_list_remove (priv->message_queue, message);
790 g_object_unref (message);
795 theme_adium_finalize (GObject *object)
797 EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
799 g_free (priv->basedir);
800 g_free (priv->template_html);
801 g_free (priv->in_content_html);
802 g_free (priv->in_nextcontent_html);
803 g_free (priv->out_content_html);
804 g_free (priv->out_nextcontent_html);
805 g_free (priv->default_avatar_filename);
806 g_free (priv->default_incoming_avatar_filename);
807 g_free (priv->default_outgoing_avatar_filename);
809 g_free (priv->status_html);
811 G_OBJECT_CLASS (empathy_theme_adium_parent_class)->finalize (object);
815 theme_adium_dispose (GObject *object)
817 EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
819 if (priv->smiley_manager) {
820 g_object_unref (priv->smiley_manager);
821 priv->smiley_manager = NULL;
824 if (priv->last_contact) {
825 g_object_unref (priv->last_contact);
826 priv->last_contact = NULL;
829 G_OBJECT_CLASS (empathy_theme_adium_parent_class)->dispose (object);
833 theme_adium_constructed (GObject *object)
835 theme_adium_load (EMPATHY_THEME_ADIUM (object));
839 theme_adium_get_property (GObject *object,
844 EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
848 g_value_set_string (value, priv->path);
851 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
857 theme_adium_set_property (GObject *object,
862 EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
867 priv->path = g_value_dup_string (value);
870 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
876 empathy_theme_adium_class_init (EmpathyThemeAdiumClass *klass)
878 GObjectClass *object_class = G_OBJECT_CLASS (klass);
880 object_class->finalize = theme_adium_finalize;
881 object_class->dispose = theme_adium_dispose;
882 object_class->constructed = theme_adium_constructed;
883 object_class->get_property = theme_adium_get_property;
884 object_class->set_property = theme_adium_set_property;
886 g_object_class_install_property (object_class,
888 g_param_spec_string ("path",
890 "Path to the adium theme",
892 G_PARAM_CONSTRUCT_ONLY |
896 g_type_class_add_private (object_class, sizeof (EmpathyThemeAdiumPriv));
900 empathy_theme_adium_init (EmpathyThemeAdium *theme)
902 EmpathyThemeAdiumPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (theme,
903 EMPATHY_TYPE_THEME_ADIUM, EmpathyThemeAdiumPriv);
907 priv->smiley_manager = empathy_smiley_manager_dup_singleton ();
909 g_signal_connect (theme, "load-finished",
910 G_CALLBACK (theme_adium_load_finished_cb),
912 g_signal_connect (theme, "navigation-requested",
913 G_CALLBACK (theme_adium_navigation_requested_cb),
915 g_signal_connect (theme, "populate-popup",
916 G_CALLBACK (theme_adium_populate_popup_cb),
921 empathy_theme_adium_new (const gchar *path)
923 g_return_val_if_fail (empathy_theme_adium_is_valid (path), NULL);
925 return g_object_new (EMPATHY_TYPE_THEME_ADIUM,
931 empathy_theme_adium_is_valid (const gchar *path)
936 /* We ship a default Template.html as fallback if there is any problem
937 * with the one inside the theme. The only other required file is
938 * Content.html for incoming messages (outgoing fallback to use
940 file = g_build_filename (path, "Contents", "Resources", "Incoming",
941 "Content.html", NULL);
942 ret = g_file_test (file, G_FILE_TEST_EXISTS);