]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-theme-adium.c
Merge branch 'master' into mc5
[empathy.git] / libempathy-gtk / empathy-theme-adium.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2008-2009 Collabora Ltd.
4  *
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.
9  *
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.
14  *
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
18  *
19  * Authors: Xavier Claessens <xclaesse@gmail.com>
20  */
21
22 #include "config.h"
23
24 #include <string.h>
25 #include <glib/gi18n.h>
26
27 #include <webkit/webkitnetworkrequest.h>
28 #include <telepathy-glib/dbus.h>
29 #include <telepathy-glib/util.h>
30
31
32 #include <libempathy/empathy-time.h>
33 #include <libempathy/empathy-utils.h>
34
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"
40
41 #define DEBUG_FLAG EMPATHY_DEBUG_CHAT
42 #include <libempathy/empathy-debug.h>
43
44 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyThemeAdium)
45
46 /* "Join" consecutive messages with timestamps within five minutes */
47 #define MESSAGE_JOIN_PERIOD 5*60
48
49 typedef struct {
50         EmpathyAdiumData     *data;
51         EmpathySmileyManager *smiley_manager;
52         EmpathyContact       *last_contact;
53         time_t                last_timestamp;
54         gboolean              last_is_backlog;
55         gboolean              page_loaded;
56         GList                *message_queue;
57         gchar                *hovered_uri;
58         guint                 notify_enable_webkit_developer_tools_id;
59         GtkWidget            *inspector_window;
60 } EmpathyThemeAdiumPriv;
61
62 struct _EmpathyAdiumData {
63         guint  ref_count;
64         gchar *path;
65         gchar *basedir;
66         gchar *default_avatar_filename;
67         gchar *default_incoming_avatar_filename;
68         gchar *default_outgoing_avatar_filename;
69         gchar *template_html;
70         gchar *in_content_html;
71         gsize  in_content_len;
72         gchar *in_context_html;
73         gsize  in_context_len;
74         gchar *in_nextcontent_html;
75         gsize  in_nextcontent_len;
76         gchar *in_nextcontext_html;
77         gsize  in_nextcontext_len;
78         gchar *out_content_html;
79         gsize  out_content_len;
80         gchar *out_context_html;
81         gsize  out_context_len;
82         gchar *out_nextcontent_html;
83         gsize  out_nextcontent_len;
84         gchar *out_nextcontext_html;
85         gsize  out_nextcontext_len;
86         gchar *status_html;
87         gsize  status_len;
88         GHashTable *info;
89 };
90
91 static void theme_adium_iface_init (EmpathyChatViewIface *iface);
92
93 enum {
94         PROP_0,
95         PROP_ADIUM_DATA,
96 };
97
98 G_DEFINE_TYPE_WITH_CODE (EmpathyThemeAdium, empathy_theme_adium,
99                          WEBKIT_TYPE_WEB_VIEW,
100                          G_IMPLEMENT_INTERFACE (EMPATHY_TYPE_CHAT_VIEW,
101                                                 theme_adium_iface_init));
102
103 static void
104 theme_adium_update_enable_webkit_developer_tools (EmpathyThemeAdium *theme)
105 {
106         WebKitWebView  *web_view = WEBKIT_WEB_VIEW (theme);
107         gboolean        enable_webkit_developer_tools;
108
109         if (!empathy_conf_get_bool (empathy_conf_get (),
110                                     EMPATHY_PREFS_CHAT_WEBKIT_DEVELOPER_TOOLS,
111                                     &enable_webkit_developer_tools)) {
112                 return;
113         }
114
115         g_object_set (G_OBJECT (webkit_web_view_get_settings (web_view)),
116                       "enable-developer-extras",
117                       enable_webkit_developer_tools,
118                       NULL);
119 }
120
121 static void
122 theme_adium_notify_enable_webkit_developer_tools_cb (EmpathyConf *conf,
123                                                      const gchar *key,
124                                                      gpointer     user_data)
125 {
126         EmpathyThemeAdium  *theme = user_data;
127
128         theme_adium_update_enable_webkit_developer_tools (theme);
129 }
130
131 static WebKitNavigationResponse
132 theme_adium_navigation_requested_cb (WebKitWebView        *view,
133                                      WebKitWebFrame       *frame,
134                                      WebKitNetworkRequest *request,
135                                      gpointer              user_data)
136 {
137         const gchar *uri;
138
139         uri = webkit_network_request_get_uri (request);
140         empathy_url_show (GTK_WIDGET (view), uri);
141
142         return WEBKIT_NAVIGATION_RESPONSE_IGNORE;
143 }
144
145 static void
146 theme_adium_hovering_over_link_cb (EmpathyThemeAdium *theme,
147                                    gchar             *title,
148                                    gchar             *uri,
149                                    gpointer           user_data)
150 {
151         EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
152
153         if (tp_strdiff (uri, priv->hovered_uri)) {
154                 g_free (priv->hovered_uri);
155                 priv->hovered_uri = g_strdup (uri);
156         }
157 }
158
159 static void
160 theme_adium_copy_address_cb (GtkMenuItem *menuitem,
161                              gpointer     user_data)
162 {
163         EmpathyThemeAdium     *theme = EMPATHY_THEME_ADIUM (user_data);
164         EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
165         GtkClipboard          *clipboard;
166
167         clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
168         gtk_clipboard_set_text (clipboard, priv->hovered_uri, -1);
169
170         clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
171         gtk_clipboard_set_text (clipboard, priv->hovered_uri, -1);
172 }
173
174 static void
175 theme_adium_open_address_cb (GtkMenuItem *menuitem,
176                              gpointer     user_data)
177 {
178         EmpathyThemeAdium     *theme = EMPATHY_THEME_ADIUM (user_data);
179         EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
180
181         empathy_url_show (GTK_WIDGET (menuitem), priv->hovered_uri);
182 }
183
184 static void
185 theme_adium_populate_popup_cb (WebKitWebView *view,
186                                GtkMenu       *menu,
187                                gpointer       user_data)
188 {
189         EmpathyThemeAdium     *theme = EMPATHY_THEME_ADIUM (view);
190         EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
191         GtkWidget             *item;
192         GList                 *items;
193         GtkWidget             *icon;
194         gchar                 *stock_id;
195         gboolean               is_link = FALSE;
196         gboolean               developer_tools_enabled;
197
198         /* FIXME: WebKitGTK+'s context menu API clearly needs an
199          * overhaul.  There is currently no way to know what is being
200          * clicked, to decide what features to provide. You either
201          * take what it gives you as a menu, or use hacks to figure
202          * out what to display. */
203         items = gtk_container_get_children (GTK_CONTAINER (menu));
204         item = GTK_WIDGET (g_list_nth_data (items, 0));
205         g_list_free (items);
206
207         if (GTK_IS_IMAGE_MENU_ITEM (item)) {
208                 icon = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (item));
209                 gtk_image_get_stock (GTK_IMAGE (icon), &stock_id, NULL);
210
211                 if ((!strcmp (stock_id, GTK_STOCK_OPEN)) && priv->hovered_uri)
212                         is_link = TRUE;
213         }
214
215         /* Remove default menu items */
216         g_object_get (G_OBJECT (webkit_web_view_get_settings (view)),
217                       "enable-developer-extras", &developer_tools_enabled, NULL);
218         if (!developer_tools_enabled)
219                 gtk_container_foreach (GTK_CONTAINER (menu),
220                                        (GtkCallback) gtk_widget_destroy, NULL);
221
222         /* Select all item */
223         item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
224         gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
225         gtk_widget_show (item);
226
227         g_signal_connect_swapped (item, "activate",
228                                   G_CALLBACK (webkit_web_view_select_all),
229                                   view);
230
231         /* Copy menu item */
232         if (webkit_web_view_can_copy_clipboard (view)) {
233                 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL);
234                 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
235                 gtk_widget_show (item);
236
237                 g_signal_connect_swapped (item, "activate",
238                                           G_CALLBACK (webkit_web_view_copy_clipboard),
239                                           view);
240         }
241
242         /* Clear menu item */
243         item = gtk_separator_menu_item_new ();
244         gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
245         gtk_widget_show (item);
246
247         item = gtk_image_menu_item_new_from_stock (GTK_STOCK_CLEAR, NULL);
248         gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
249         gtk_widget_show (item);
250
251         g_signal_connect_swapped (item, "activate",
252                                   G_CALLBACK (empathy_chat_view_clear),
253                                   view);
254
255         /* We will only add the following menu items if we are
256          * right-clicking a link */
257         if (!is_link)
258                 return;
259
260         /* Separator */
261         item = gtk_separator_menu_item_new ();
262         gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
263         gtk_widget_show (item);
264
265         /* Copy Link Address menu item */
266         item = gtk_menu_item_new_with_mnemonic (_("_Copy Link Address"));
267         g_signal_connect (item, "activate",
268                           G_CALLBACK (theme_adium_copy_address_cb),
269                           view);
270         gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
271         gtk_widget_show (item);
272
273         /* Open Link menu item */
274         item = gtk_menu_item_new_with_mnemonic (_("_Open Link"));
275         g_signal_connect (item, "activate",
276                           G_CALLBACK (theme_adium_open_address_cb),
277                           view);
278         gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
279         gtk_widget_show (item);
280 }
281
282 static gchar *
283 theme_adium_parse_body (EmpathyThemeAdium *theme,
284                         const gchar       *text)
285 {
286         EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
287         gboolean               use_smileys = FALSE;
288         GSList                *smileys, *l;
289         GString               *string;
290         gint                   i;
291         GRegex                *uri_regex;
292         GMatchInfo            *match_info;
293         gboolean               match;
294         gchar                 *ret = NULL;
295         gint                   prev;
296
297         empathy_conf_get_bool (empathy_conf_get (),
298                                EMPATHY_PREFS_CHAT_SHOW_SMILEYS,
299                                &use_smileys);
300
301         if (use_smileys) {
302                 /* Replace smileys by a <img/> tag */
303                 string = g_string_sized_new (strlen (text));
304                 smileys = empathy_smiley_manager_parse (priv->smiley_manager, text);
305                 for (l = smileys; l; l = l->next) {
306                         EmpathySmiley *smiley;
307
308                         smiley = l->data;
309                         if (smiley->path) {
310                                 g_string_append_printf (string,
311                                                         "<abbr title='%s'><img src=\"%s\"/ alt=\"%s\"/></abbr>",
312                                                         smiley->str, smiley->path, smiley->str);
313                         } else {
314                                 gchar *str;
315
316                                 str = g_markup_escape_text (smiley->str, -1);
317                                 g_string_append (string, str);
318                                 g_free (str);
319                         }
320                         empathy_smiley_free (smiley);
321                 }
322                 g_slist_free (smileys);
323
324                 g_free (ret);
325                 text = ret = g_string_free (string, FALSE);
326         }
327
328         /* Add <a href></a> arround links */
329         uri_regex = empathy_uri_regex_dup_singleton ();
330         match = g_regex_match (uri_regex, text, 0, &match_info);
331         if (match) {
332                 gint last = 0;
333                 gint s = 0, e = 0;
334
335                 string = g_string_sized_new (strlen (text));
336                 do {
337                         g_match_info_fetch_pos (match_info, 0, &s, &e);
338
339                         if (s > last) {
340                                 /* Append the text between last link (or the
341                                  * start of the message) and this link */
342                                 g_string_append_len (string, text + last, s - last);
343                         }
344
345                         /* Append the link inside <a href=""></a> tag */
346                         g_string_append (string, "<a href=\"");
347                         g_string_append_len (string, text + s, e - s);
348                         g_string_append (string, "\">");
349                         g_string_append_len (string, text + s, e - s);
350                         g_string_append (string, "</a>");
351
352                         last = e;
353                 } while (g_match_info_next (match_info, NULL));
354
355                 if (e < strlen (text)) {
356                         /* Append the text after the last link */
357                         g_string_append_len (string, text + e, strlen (text) - e);
358                 }
359
360                 g_free (ret);
361                 text = ret = g_string_free (string, FALSE);
362         }
363         g_match_info_free (match_info);
364         g_regex_unref (uri_regex);
365
366         /* Replace \n by <br/> */
367         string = NULL;
368         prev = 0;
369         for (i = 0; text[i] != '\0'; i++) {
370                 if (text[i] == '\n') {
371                         if (!string ) {
372                                 string = g_string_sized_new (strlen (text));
373                         }
374                         g_string_append_len (string, text + prev, i - prev);
375                         g_string_append (string, "<br/>");
376                         prev = i + 1;
377                 }
378         }
379         if (string) {
380                 g_string_append (string, text + prev);
381                 g_free (ret);
382                 text = ret = g_string_free (string, FALSE);
383         }
384
385         return ret;
386 }
387
388 static void
389 escape_and_append_len (GString *string, const gchar *str, gint len)
390 {
391         while (*str != '\0' && len != 0) {
392                 switch (*str) {
393                 case '\\':
394                         /* \ becomes \\ */
395                         g_string_append (string, "\\\\");
396                         break;
397                 case '\"':
398                         /* " becomes \" */
399                         g_string_append (string, "\\\"");
400                         break;
401                 case '\n':
402                         /* Remove end of lines */
403                         break;
404                 default:
405                         g_string_append_c (string, *str);
406                 }
407
408                 str++;
409                 len--;
410         }
411 }
412
413 static gboolean
414 theme_adium_match (const gchar **str, const gchar *match)
415 {
416         gint len;
417
418         len = strlen (match);
419         if (strncmp (*str, match, len) == 0) {
420                 *str += len - 1;
421                 return TRUE;
422         }
423
424         return FALSE;
425 }
426
427 static void
428 theme_adium_append_html (EmpathyThemeAdium *theme,
429                          const gchar       *func,
430                          const gchar       *html, gsize len,
431                          const gchar       *message,
432                          const gchar       *avatar_filename,
433                          const gchar       *name,
434                          const gchar       *contact_id,
435                          const gchar       *service_name,
436                          const gchar       *message_classes,
437                          time_t             timestamp)
438 {
439         GString     *string;
440         const gchar *cur = NULL;
441         gchar       *script;
442
443         /* Make some search-and-replace in the html code */
444         string = g_string_sized_new (len + strlen (message));
445         g_string_append_printf (string, "%s(\"", func);
446         for (cur = html; *cur != '\0'; cur++) {
447                 const gchar *replace = NULL;
448                 gchar       *dup_replace = NULL;
449
450                 if (theme_adium_match (&cur, "%message%")) {
451                         replace = message;
452                 } else if (theme_adium_match (&cur, "%messageClasses%")) {
453                         replace = message_classes;
454                 } else if (theme_adium_match (&cur, "%userIconPath%")) {
455                         replace = avatar_filename;
456                 } else if (theme_adium_match (&cur, "%sender%")) {
457                         replace = name;
458                 } else if (theme_adium_match (&cur, "%senderScreenName%")) {
459                         replace = contact_id;
460                 } else if (theme_adium_match (&cur, "%senderDisplayName%")) {
461                         /* %senderDisplayName% -
462                          * "The serverside (remotely set) name of the sender,
463                          *  such as an MSN display name."
464                          *
465                          * We don't have access to that yet so we use local
466                          * alias instead.*/
467                         replace = name;
468                 } else if (theme_adium_match (&cur, "%service%")) {
469                         replace = service_name;
470                 } else if (theme_adium_match (&cur, "%shortTime%")) {
471                         dup_replace = empathy_time_to_string_local (timestamp,
472                                 EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
473                         replace = dup_replace;
474                 } else if (theme_adium_match (&cur, "%time")) {
475                         gchar *format = NULL;
476                         gchar *end;
477                         /* Time can be in 2 formats:
478                          * %time% or %time{strftime format}%
479                          * Extract the time format if provided. */
480                         if (cur[1] == '{') {
481                                 cur += 2;
482                                 end = strstr (cur, "}%");
483                                 if (!end) {
484                                         /* Invalid string */
485                                         continue;
486                                 }
487                                 format = g_strndup (cur, end - cur);
488                                 cur = end + 1;
489                         } else {
490                                 cur++;
491                         }
492
493                         dup_replace = empathy_time_to_string_local (timestamp,
494                                 format ? format : EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
495                         replace = dup_replace;
496                         g_free (format);
497                 } else {
498                         escape_and_append_len (string, cur, 1);
499                         continue;
500                 }
501
502                 /* Here we have a replacement to make */
503                 escape_and_append_len (string, replace, -1);
504                 g_free (dup_replace);
505         }
506         g_string_append (string, "\")");
507
508         script = g_string_free (string, FALSE);
509         webkit_web_view_execute_script (WEBKIT_WEB_VIEW (theme), script);
510         g_free (script);
511 }
512
513 static void
514 theme_adium_append_message (EmpathyChatView *view,
515                             EmpathyMessage  *msg)
516 {
517         EmpathyThemeAdium     *theme = EMPATHY_THEME_ADIUM (view);
518         EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
519         EmpathyContact        *sender;
520         EmpathyAccount        *account;
521         gchar                 *dup_body = NULL;
522         const gchar           *body;
523         const gchar           *name;
524         const gchar           *contact_id;
525         EmpathyAvatar         *avatar;
526         const gchar           *avatar_filename = NULL;
527         time_t                 timestamp;
528         gchar                 *html = NULL;
529         gsize                  len = 0;
530         const gchar           *func;
531         const gchar           *service_name;
532         GString               *message_classes = NULL;
533         gboolean              is_backlog;
534
535         if (!priv->page_loaded) {
536                 priv->message_queue = g_list_prepend (priv->message_queue,
537                                                       g_object_ref (msg));
538                 return;
539         }
540
541         /* Get information */
542         sender = empathy_message_get_sender (msg);
543         account = empathy_contact_get_account (sender);
544         service_name = empathy_account_get_protocol (account);
545         timestamp = empathy_message_get_timestamp (msg);
546         body = empathy_message_get_body (msg);
547         dup_body = theme_adium_parse_body (theme, body);
548         if (dup_body) {
549                 body = dup_body;
550         }
551         name = empathy_contact_get_name (sender);
552         contact_id = empathy_contact_get_id (sender);
553
554         /* If this is a /me, append an event */
555         if (empathy_message_get_tptype (msg) == TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION) {
556                 gchar *str;
557
558                 str = g_strdup_printf ("%s %s", name, body);
559                 empathy_chat_view_append_event (view, str);
560                 g_free (str);
561                 g_free (dup_body);
562                 return;
563         }
564
565         /* Get the avatar filename, or a fallback */
566         avatar = empathy_contact_get_avatar (sender);
567         if (avatar) {
568                 avatar_filename = avatar->filename;
569         }
570         if (!avatar_filename) {
571                 if (empathy_contact_is_user (sender)) {
572                         avatar_filename = priv->data->default_outgoing_avatar_filename;
573                 } else {
574                         avatar_filename = priv->data->default_incoming_avatar_filename;
575                 }
576                 if (!avatar_filename) {
577                         if (!priv->data->default_avatar_filename) {
578                                 priv->data->default_avatar_filename =
579                                         empathy_filename_from_icon_name ("stock_person",
580                                                                          GTK_ICON_SIZE_DIALOG);
581                         }
582                         avatar_filename = priv->data->default_avatar_filename;
583                 }
584         }
585
586         is_backlog = empathy_message_is_backlog (msg);
587
588         /* Get the right html/func to add the message */
589         func = "appendMessage";
590
591         message_classes = g_string_new ("message");
592
593         /* eventually append the "history" class */
594         if (is_backlog) {
595                 g_string_append (message_classes, " history");
596         }
597
598         /* check the sender of the message and append the appropriate class */
599         if (empathy_contact_is_user (sender)) {
600                 g_string_append (message_classes, " outgoing");
601         }
602         else {
603                 g_string_append (message_classes, " incoming");
604         }
605
606         /*
607          * To mimick Adium's behavior, we only want to join messages
608          * sent by the same contact within a 5 minute time frame.
609          */
610         if (empathy_contact_equal (priv->last_contact, sender) &&
611             (timestamp - priv->last_timestamp < MESSAGE_JOIN_PERIOD) &&
612             (is_backlog == priv->last_is_backlog)) {
613                 /* the messages can be appended */
614                 func = "appendNextMessage";
615                 g_string_append (message_classes, " consecutive");
616
617                 /* check who is the sender of the message to use the correct html file */
618                 if (empathy_contact_is_user (sender)) {
619                         /* check if this is a backlog message and use NextContext.html */
620                         if (is_backlog) {
621                                 html = priv->data->out_nextcontext_html;
622                                 len = priv->data->out_nextcontext_len;
623                         }
624
625                         /*
626                          * html is null if this is not a backlog message or
627                          * if we have to fallback (NextContext.html missing).
628                          * use NextContent.html
629                          */
630                         if (html == NULL) {
631                                 html = priv->data->out_nextcontent_html;
632                                 len = priv->data->out_nextcontent_len;
633                         }
634                 }
635                 else {
636                         if (is_backlog) {
637                                 html = priv->data->in_nextcontext_html;
638                                 len = priv->data->in_nextcontext_len;
639                         }
640
641                         if (html == NULL) {
642                                 html = priv->data->in_nextcontent_html;
643                                 len = priv->data->in_nextcontent_len;
644                         }
645                 }
646         }
647
648         /*
649          * we have html == NULL here if:
650          * 1. the message didn't have to be appended because
651          *    the sender was different or the timestamp was too far
652          * 2. NextContent.html file does not exist, so we must
653          *    not forget to fallback to the correct Content.html
654          */
655         if (html == NULL) {
656                 if (empathy_contact_is_user (sender)) {
657                         if (is_backlog) {
658                                 html = priv->data->out_context_html;
659                                 len = priv->data->out_context_len;
660                         }
661
662                         if (html == NULL) {
663                                 html = priv->data->out_content_html;
664                                 len = priv->data->out_content_len;
665                         }
666                 }
667                 else {
668                         if (is_backlog) {
669                                 html = priv->data->in_context_html;
670                                 len = priv->data->in_context_len;
671                         }
672
673                         if (html == NULL) {
674                                 html = priv->data->in_content_html;
675                                 len = priv->data->in_content_len;
676                         }
677                 }
678         }
679
680         theme_adium_append_html (theme, func, html, len, body, avatar_filename,
681                                  name, contact_id, service_name, message_classes->str,
682                                  timestamp);
683
684         /* Keep the sender of the last displayed message */
685         if (priv->last_contact) {
686                 g_object_unref (priv->last_contact);
687         }
688         priv->last_contact = g_object_ref (sender);
689         priv->last_timestamp = timestamp;
690         priv->last_is_backlog = is_backlog;
691
692         g_free (dup_body);
693         g_string_free (message_classes, TRUE);
694 }
695
696 static void
697 theme_adium_append_event (EmpathyChatView *view,
698                           const gchar     *str)
699 {
700         EmpathyThemeAdium     *theme = EMPATHY_THEME_ADIUM (view);
701         EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
702
703         if (priv->data->status_html) {
704                 theme_adium_append_html (theme, "appendMessage",
705                                          priv->data->status_html,
706                                          priv->data->status_len,
707                                          str, NULL, NULL, NULL, NULL, "event",
708                                          empathy_time_get_current ());
709         }
710
711         /* There is no last contact */
712         if (priv->last_contact) {
713                 g_object_unref (priv->last_contact);
714                 priv->last_contact = NULL;
715         }
716 }
717
718 static void
719 theme_adium_scroll (EmpathyChatView *view,
720                     gboolean         allow_scrolling)
721 {
722         /* FIXME: Is it possible? I guess we need a js function, but I don't
723          * see any... */
724 }
725
726 static void
727 theme_adium_scroll_down (EmpathyChatView *view)
728 {
729         webkit_web_view_execute_script (WEBKIT_WEB_VIEW (view), "scrollToBottom()");
730 }
731
732 static gboolean
733 theme_adium_get_has_selection (EmpathyChatView *view)
734 {
735         return webkit_web_view_has_selection (WEBKIT_WEB_VIEW (view));
736 }
737
738 static void
739 theme_adium_clear (EmpathyChatView *view)
740 {
741         EmpathyThemeAdiumPriv *priv = GET_PRIV (view);
742         gchar *basedir_uri;
743
744         priv->page_loaded = FALSE;
745         basedir_uri = g_strconcat ("file://", priv->data->basedir, NULL);
746         webkit_web_view_load_html_string (WEBKIT_WEB_VIEW (view),
747                                           priv->data->template_html,
748                                           basedir_uri);
749         g_free (basedir_uri);
750
751         /* Clear last contact to avoid trying to add a 'joined'
752          * message when we don't have an insertion point. */
753         if (priv->last_contact) {
754                 g_object_unref (priv->last_contact);
755                 priv->last_contact = NULL;
756         }
757 }
758
759 static gboolean
760 theme_adium_find_previous (EmpathyChatView *view,
761                            const gchar     *search_criteria,
762                            gboolean         new_search)
763 {
764         return webkit_web_view_search_text (WEBKIT_WEB_VIEW (view),
765                                             search_criteria, FALSE,
766                                             FALSE, TRUE);
767 }
768
769 static gboolean
770 theme_adium_find_next (EmpathyChatView *view,
771                        const gchar     *search_criteria,
772                        gboolean         new_search)
773 {
774         return webkit_web_view_search_text (WEBKIT_WEB_VIEW (view),
775                                             search_criteria, FALSE,
776                                             TRUE, TRUE);
777 }
778
779 static void
780 theme_adium_find_abilities (EmpathyChatView *view,
781                             const gchar    *search_criteria,
782                             gboolean       *can_do_previous,
783                             gboolean       *can_do_next)
784 {
785         /* FIXME: Does webkit provide an API for that? We have wrap=true in
786          * find_next and find_previous to work around this problem. */
787         if (can_do_previous)
788                 *can_do_previous = TRUE;
789         if (can_do_next)
790                 *can_do_next = TRUE;
791 }
792
793 static void
794 theme_adium_highlight (EmpathyChatView *view,
795                        const gchar     *text)
796 {
797         webkit_web_view_unmark_text_matches (WEBKIT_WEB_VIEW (view));
798         webkit_web_view_mark_text_matches (WEBKIT_WEB_VIEW (view),
799                                            text, FALSE, 0);
800         webkit_web_view_set_highlight_text_matches (WEBKIT_WEB_VIEW (view),
801                                                     TRUE);
802 }
803
804 static void
805 theme_adium_copy_clipboard (EmpathyChatView *view)
806 {
807         webkit_web_view_copy_clipboard (WEBKIT_WEB_VIEW (view));
808 }
809
810 static void
811 theme_adium_iface_init (EmpathyChatViewIface *iface)
812 {
813         iface->append_message = theme_adium_append_message;
814         iface->append_event = theme_adium_append_event;
815         iface->scroll = theme_adium_scroll;
816         iface->scroll_down = theme_adium_scroll_down;
817         iface->get_has_selection = theme_adium_get_has_selection;
818         iface->clear = theme_adium_clear;
819         iface->find_previous = theme_adium_find_previous;
820         iface->find_next = theme_adium_find_next;
821         iface->find_abilities = theme_adium_find_abilities;
822         iface->highlight = theme_adium_highlight;
823         iface->copy_clipboard = theme_adium_copy_clipboard;
824 }
825
826 static void
827 theme_adium_load_finished_cb (WebKitWebView  *view,
828                               WebKitWebFrame *frame,
829                               gpointer        user_data)
830 {
831         EmpathyThemeAdiumPriv *priv = GET_PRIV (view);
832         EmpathyChatView       *chat_view = EMPATHY_CHAT_VIEW (view);
833
834         DEBUG ("Page loaded");
835         priv->page_loaded = TRUE;
836
837         /* Display queued messages */
838         priv->message_queue = g_list_reverse (priv->message_queue);
839         while (priv->message_queue) {
840                 EmpathyMessage *message = priv->message_queue->data;
841
842                 theme_adium_append_message (chat_view, message);
843                 priv->message_queue = g_list_remove (priv->message_queue, message);
844                 g_object_unref (message);
845         }
846 }
847
848 static void
849 theme_adium_finalize (GObject *object)
850 {
851         EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
852
853         empathy_adium_data_unref (priv->data);
854         g_free (priv->hovered_uri);
855
856         empathy_conf_notify_remove (empathy_conf_get (),
857                                     priv->notify_enable_webkit_developer_tools_id);
858
859         G_OBJECT_CLASS (empathy_theme_adium_parent_class)->finalize (object);
860 }
861
862 static void
863 theme_adium_dispose (GObject *object)
864 {
865         EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
866
867         if (priv->smiley_manager) {
868                 g_object_unref (priv->smiley_manager);
869                 priv->smiley_manager = NULL;
870         }
871
872         if (priv->last_contact) {
873                 g_object_unref (priv->last_contact);
874                 priv->last_contact = NULL;
875         }
876
877         if (priv->inspector_window) {
878                 gtk_widget_destroy (priv->inspector_window);
879                 priv->inspector_window = NULL;
880         }
881
882         G_OBJECT_CLASS (empathy_theme_adium_parent_class)->dispose (object);
883 }
884
885 static gboolean
886 theme_adium_inspector_show_window_cb (WebKitWebInspector *inspector,
887                                       EmpathyThemeAdium  *theme)
888 {
889         EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
890
891         if (priv->inspector_window) {
892                 gtk_widget_show_all (priv->inspector_window);
893         }
894
895         return TRUE;
896 }
897
898 static gboolean
899 theme_adium_inspector_close_window_cb (WebKitWebInspector *inspector,
900                                        EmpathyThemeAdium  *theme)
901 {
902         EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
903
904         if (priv->inspector_window) {
905                 gtk_widget_hide (priv->inspector_window);
906         }
907
908         return TRUE;
909 }
910
911 static WebKitWebView *
912 theme_adium_inspect_web_view_cb (WebKitWebInspector *inspector,
913                                  WebKitWebView      *web_view,
914                                  EmpathyThemeAdium  *theme)
915 {
916         EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
917         GtkWidget             *scrolled_window;
918         GtkWidget             *inspector_web_view;
919
920         if (!priv->inspector_window) {
921                 /* Create main window */
922                 priv->inspector_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
923                 gtk_window_set_default_size (GTK_WINDOW (priv->inspector_window),
924                                              800, 600);
925                 g_signal_connect (priv->inspector_window, "delete-event",
926                                   G_CALLBACK (gtk_widget_hide_on_delete), NULL);
927
928                 /* Pack a scrolled window */
929                 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
930                 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
931                                                 GTK_POLICY_AUTOMATIC,
932                                                 GTK_POLICY_AUTOMATIC);
933                 gtk_container_add (GTK_CONTAINER (priv->inspector_window),
934                                    scrolled_window);
935                 gtk_widget_show  (scrolled_window);
936
937                 /* Pack a webview in the scrolled window. That webview will be
938                  * used to render the inspector tool.  */
939                 inspector_web_view = webkit_web_view_new ();
940                 gtk_container_add (GTK_CONTAINER (scrolled_window),
941                                    inspector_web_view);
942                 gtk_widget_show (scrolled_window);
943
944                 return WEBKIT_WEB_VIEW (inspector_web_view);
945         }
946
947         return NULL;
948 }
949
950 static void
951 theme_adium_constructed (GObject *object)
952 {
953         EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
954         gchar                 *basedir_uri;
955         const gchar           *font_family = NULL;
956         gint                   font_size = 0;
957         WebKitWebView         *webkit_view = WEBKIT_WEB_VIEW (object);
958         WebKitWebSettings     *webkit_settings;
959         WebKitWebInspector    *webkit_inspector;
960
961         /* Set default settings */
962         font_family = tp_asv_get_string (priv->data->info, "DefaultFontFamily");
963         font_size = tp_asv_get_int32 (priv->data->info, "DefaultFontSize", NULL);
964         webkit_settings = webkit_web_view_get_settings (webkit_view);
965         if (font_family) {
966                 g_object_set (webkit_settings,
967                               "default-font-family", font_family,
968                               NULL);
969         }
970         if (font_size) {
971                 g_object_set (webkit_settings,
972                               "default-font-size", font_size,
973                               NULL);
974         }
975
976         /* Setup webkit inspector */
977         webkit_inspector = webkit_web_view_get_inspector (webkit_view);
978         g_signal_connect (webkit_inspector, "inspect-web-view",
979                           G_CALLBACK (theme_adium_inspect_web_view_cb),
980                           object);
981         g_signal_connect (webkit_inspector, "show-window",
982                           G_CALLBACK (theme_adium_inspector_show_window_cb),
983                           object);
984         g_signal_connect (webkit_inspector, "close-window",
985                           G_CALLBACK (theme_adium_inspector_close_window_cb),
986                           object);
987
988         /* Load template */
989         basedir_uri = g_strconcat ("file://", priv->data->basedir, NULL);
990         webkit_web_view_load_html_string (WEBKIT_WEB_VIEW (object),
991                                           priv->data->template_html,
992                                           basedir_uri);
993         g_free (basedir_uri);
994 }
995
996 static void
997 theme_adium_get_property (GObject    *object,
998                           guint       param_id,
999                           GValue     *value,
1000                           GParamSpec *pspec)
1001 {
1002         EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
1003
1004         switch (param_id) {
1005         case PROP_ADIUM_DATA:
1006                 g_value_set_boxed (value, priv->data);
1007                 break;
1008         default:
1009                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1010                 break;
1011         };
1012 }
1013
1014 static void
1015 theme_adium_set_property (GObject      *object,
1016                           guint         param_id,
1017                           const GValue *value,
1018                           GParamSpec   *pspec)
1019 {
1020         EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
1021
1022         switch (param_id) {
1023         case PROP_ADIUM_DATA:
1024                 g_assert (priv->data == NULL);
1025                 priv->data = g_value_dup_boxed (value);
1026                 break;
1027         default:
1028                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1029                 break;
1030         };
1031 }
1032
1033 static void
1034 empathy_theme_adium_class_init (EmpathyThemeAdiumClass *klass)
1035 {
1036         GObjectClass *object_class = G_OBJECT_CLASS (klass);
1037
1038         object_class->finalize = theme_adium_finalize;
1039         object_class->dispose = theme_adium_dispose;
1040         object_class->constructed = theme_adium_constructed;
1041         object_class->get_property = theme_adium_get_property;
1042         object_class->set_property = theme_adium_set_property;
1043
1044         g_object_class_install_property (object_class,
1045                                          PROP_ADIUM_DATA,
1046                                          g_param_spec_boxed ("adium-data",
1047                                                              "The theme data",
1048                                                              "Data for the adium theme",
1049                                                               EMPATHY_TYPE_ADIUM_DATA,
1050                                                               G_PARAM_CONSTRUCT_ONLY |
1051                                                               G_PARAM_READWRITE |
1052                                                               G_PARAM_STATIC_STRINGS));
1053
1054         g_type_class_add_private (object_class, sizeof (EmpathyThemeAdiumPriv));
1055 }
1056
1057 static void
1058 empathy_theme_adium_init (EmpathyThemeAdium *theme)
1059 {
1060         EmpathyThemeAdiumPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (theme,
1061                 EMPATHY_TYPE_THEME_ADIUM, EmpathyThemeAdiumPriv);
1062
1063         theme->priv = priv;
1064
1065         priv->smiley_manager = empathy_smiley_manager_dup_singleton ();
1066
1067         g_signal_connect (theme, "load-finished",
1068                           G_CALLBACK (theme_adium_load_finished_cb),
1069                           NULL);
1070         g_signal_connect (theme, "navigation-requested",
1071                           G_CALLBACK (theme_adium_navigation_requested_cb),
1072                           NULL);
1073         g_signal_connect (theme, "populate-popup",
1074                           G_CALLBACK (theme_adium_populate_popup_cb),
1075                           NULL);
1076         g_signal_connect (theme, "hovering-over-link",
1077                           G_CALLBACK (theme_adium_hovering_over_link_cb),
1078                           NULL);
1079
1080         priv->notify_enable_webkit_developer_tools_id =
1081                 empathy_conf_notify_add (empathy_conf_get (),
1082                                          EMPATHY_PREFS_CHAT_WEBKIT_DEVELOPER_TOOLS,
1083                                          theme_adium_notify_enable_webkit_developer_tools_cb,
1084                                          theme);
1085
1086         theme_adium_update_enable_webkit_developer_tools (theme);
1087 }
1088
1089 EmpathyThemeAdium *
1090 empathy_theme_adium_new (EmpathyAdiumData *data)
1091 {
1092         g_return_val_if_fail (data != NULL, NULL);
1093
1094         return g_object_new (EMPATHY_TYPE_THEME_ADIUM,
1095                              "adium-data", data,
1096                              NULL);
1097 }
1098
1099 gboolean
1100 empathy_adium_path_is_valid (const gchar *path)
1101 {
1102         gboolean ret;
1103         gchar   *file;
1104
1105         /* The theme is not valid if there is no Info.plist */
1106         file = g_build_filename (path, "Contents", "Info.plist",
1107                                  NULL);
1108         ret = g_file_test (file, G_FILE_TEST_EXISTS);
1109         g_free (file);
1110
1111         if (ret == FALSE)
1112                 return ret;
1113
1114         /* We ship a default Template.html as fallback if there is any problem
1115          * with the one inside the theme. The only other required file is
1116          * Content.html for incoming messages (outgoing fallback to use
1117          * incoming). */
1118         file = g_build_filename (path, "Contents", "Resources", "Incoming",
1119                                  "Content.html", NULL);
1120         ret = g_file_test (file, G_FILE_TEST_EXISTS);
1121         g_free (file);
1122
1123         return ret;
1124 }
1125
1126 GHashTable *
1127 empathy_adium_info_new (const gchar *path)
1128 {
1129         gchar *file;
1130         GValue *value;
1131         GHashTable *info = NULL;
1132
1133         g_return_val_if_fail (empathy_adium_path_is_valid (path), NULL);
1134
1135         file = g_build_filename (path, "Contents", "Info.plist", NULL);
1136         value = empathy_plist_parse_from_file (file);
1137         g_free (file);
1138
1139         if (value == NULL)
1140                 return NULL;
1141
1142         info = g_value_dup_boxed (value);
1143         tp_g_value_slice_free (value);
1144
1145         /* Insert the theme's path into the hash table,
1146          * keys have to be dupped */
1147         tp_asv_set_string (info, g_strdup ("path"), path);
1148
1149         return info;
1150 }
1151
1152 GType
1153 empathy_adium_data_get_type (void)
1154 {
1155   static GType type_id = 0;
1156
1157   if (!type_id)
1158     {
1159       type_id = g_boxed_type_register_static ("EmpathyAdiumData",
1160           (GBoxedCopyFunc) empathy_adium_data_ref,
1161           (GBoxedFreeFunc) empathy_adium_data_unref);
1162     }
1163
1164   return type_id;
1165 }
1166
1167 EmpathyAdiumData  *
1168 empathy_adium_data_new_with_info (const gchar *path, GHashTable *info)
1169 {
1170         EmpathyAdiumData *data;
1171         gchar            *file;
1172         gchar            *template_html = NULL;
1173         gsize             template_len;
1174         gchar            *footer_html = NULL;
1175         gsize             footer_len;
1176         GString          *string;
1177         gchar           **strv = NULL;
1178         gchar            *css_path;
1179         guint             len = 0;
1180         guint             i = 0;
1181
1182         g_return_val_if_fail (empathy_adium_path_is_valid (path), NULL);
1183
1184         data = g_slice_new0 (EmpathyAdiumData);
1185         data->ref_count = 1;
1186         data->path = g_strdup (path);
1187         data->basedir = g_strconcat (path, G_DIR_SEPARATOR_S "Contents"
1188                 G_DIR_SEPARATOR_S "Resources" G_DIR_SEPARATOR_S, NULL);
1189         data->info = g_hash_table_ref (info);
1190
1191         /* Load html files */
1192         file = g_build_filename (data->basedir, "Incoming", "Content.html", NULL);
1193         g_file_get_contents (file, &data->in_content_html, &data->in_content_len, NULL);
1194         g_free (file);
1195
1196         file = g_build_filename (data->basedir, "Incoming", "NextContent.html", NULL);
1197         g_file_get_contents (file, &data->in_nextcontent_html, &data->in_nextcontent_len, NULL);
1198         g_free (file);
1199
1200         file = g_build_filename (data->basedir, "Incoming", "Context.html", NULL);
1201         g_file_get_contents (file, &data->in_context_html, &data->in_context_len, NULL);
1202         g_free (file);
1203
1204         file = g_build_filename (data->basedir, "Incoming", "NextContext.html", NULL);
1205         g_file_get_contents (file, &data->in_nextcontext_html, &data->in_nextcontext_len, NULL);
1206         g_free (file);
1207
1208         file = g_build_filename (data->basedir, "Outgoing", "Content.html", NULL);
1209         g_file_get_contents (file, &data->out_content_html, &data->out_content_len, NULL);
1210         g_free (file);
1211
1212         file = g_build_filename (data->basedir, "Outgoing", "NextContent.html", NULL);
1213         g_file_get_contents (file, &data->out_nextcontent_html, &data->out_nextcontent_len, NULL);
1214         g_free (file);
1215
1216         file = g_build_filename (data->basedir, "Outgoing", "Context.html", NULL);
1217         g_file_get_contents (file, &data->out_context_html, &data->out_context_len, NULL);
1218         g_free (file);
1219
1220         file = g_build_filename (data->basedir, "Outgoing", "NextContext.html", NULL);
1221         g_file_get_contents (file, &data->out_nextcontext_html, &data->out_nextcontext_len, NULL);
1222         g_free (file);
1223
1224         file = g_build_filename (data->basedir, "Status.html", NULL);
1225         g_file_get_contents (file, &data->status_html, &data->status_len, NULL);
1226         g_free (file);
1227
1228         file = g_build_filename (data->basedir, "Footer.html", NULL);
1229         g_file_get_contents (file, &footer_html, &footer_len, NULL);
1230         g_free (file);
1231
1232         file = g_build_filename (data->basedir, "Incoming", "buddy_icon.png", NULL);
1233         if (g_file_test (file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
1234                 data->default_incoming_avatar_filename = file;
1235         } else {
1236                 g_free (file);
1237         }
1238
1239         file = g_build_filename (data->basedir, "Outgoing", "buddy_icon.png", NULL);
1240         if (g_file_test (file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
1241                 data->default_outgoing_avatar_filename = file;
1242         } else {
1243                 g_free (file);
1244         }
1245
1246         css_path = g_build_filename (data->basedir, "main.css", NULL);
1247
1248         /* There is 2 formats for Template.html: The old one has 4 parameters,
1249          * the new one has 5 parameters. */
1250         file = g_build_filename (data->basedir, "Template.html", NULL);
1251         if (g_file_get_contents (file, &template_html, &template_len, NULL)) {
1252                 strv = g_strsplit (template_html, "%@", -1);
1253                 len = g_strv_length (strv);
1254         }
1255         g_free (file);
1256
1257         if (len != 5 && len != 6) {
1258                 /* Either the theme has no template or it don't have the good
1259                  * number of parameters. Fallback to use our own template. */
1260                 g_free (template_html);
1261                 g_strfreev (strv);
1262
1263                 file = empathy_file_lookup ("Template.html", "data");
1264                 g_file_get_contents (file, &template_html, &template_len, NULL);
1265                 g_free (file);
1266                 strv = g_strsplit (template_html, "%@", -1);
1267                 len = g_strv_length (strv);
1268         }
1269
1270         /* Replace %@ with the needed information in the template html. */
1271         string = g_string_sized_new (template_len);
1272         g_string_append (string, strv[i++]);
1273         g_string_append (string, data->basedir);
1274         g_string_append (string, strv[i++]);
1275         if (len == 6) {
1276                 const gchar *variant;
1277
1278                 /* We include main.css by default */
1279                 g_string_append_printf (string, "@import url(\"%s\");", css_path);
1280                 g_string_append (string, strv[i++]);
1281                 variant = tp_asv_get_string (data->info, "DefaultVariant");
1282                 if (variant) {
1283                         g_string_append (string, "Variants/");
1284                         g_string_append (string, variant);
1285                         g_string_append (string, ".css");
1286                 }
1287         } else {
1288                 /* FIXME: We should set main.css OR the variant css */
1289                 g_string_append (string, css_path);
1290         }
1291         g_string_append (string, strv[i++]);
1292         g_string_append (string, ""); /* We don't want header */
1293         g_string_append (string, strv[i++]);
1294         /* FIXME: We should replace adium %macros% in footer */
1295         if (footer_html) {
1296                 g_string_append (string, footer_html);
1297         }
1298         g_string_append (string, strv[i++]);
1299         data->template_html = g_string_free (string, FALSE);
1300
1301         g_free (footer_html);
1302         g_free (template_html);
1303         g_free (css_path);
1304         g_strfreev (strv);
1305
1306         return data;
1307 }
1308
1309 EmpathyAdiumData  *
1310 empathy_adium_data_new (const gchar *path)
1311 {
1312         EmpathyAdiumData *data;
1313         GHashTable *info;
1314
1315         info = empathy_adium_info_new (path);
1316         data = empathy_adium_data_new_with_info (path, info);
1317         g_hash_table_unref (info);
1318
1319         return data;
1320 }
1321
1322 EmpathyAdiumData  *
1323 empathy_adium_data_ref (EmpathyAdiumData *data)
1324 {
1325         g_return_val_if_fail (data != NULL, NULL);
1326
1327         g_atomic_int_inc (&data->ref_count);
1328
1329         return data;
1330 }
1331
1332 void
1333 empathy_adium_data_unref (EmpathyAdiumData *data)
1334 {
1335         g_return_if_fail (data != NULL);
1336
1337         if (g_atomic_int_dec_and_test (&data->ref_count)) {
1338                 g_free (data->path);
1339                 g_free (data->basedir);
1340                 g_free (data->template_html);
1341                 g_free (data->in_content_html);
1342                 g_free (data->in_nextcontent_html);
1343                 g_free (data->in_context_html);
1344                 g_free (data->in_nextcontext_html);
1345                 g_free (data->out_content_html);
1346                 g_free (data->out_nextcontent_html);
1347                 g_free (data->out_context_html);
1348                 g_free (data->out_nextcontext_html);
1349                 g_free (data->default_avatar_filename);
1350                 g_free (data->default_incoming_avatar_filename);
1351                 g_free (data->default_outgoing_avatar_filename);
1352                 g_free (data->status_html);
1353                 g_hash_table_unref (data->info);
1354                 g_slice_free (EmpathyAdiumData, data);
1355         }
1356 }
1357
1358 GHashTable *
1359 empathy_adium_data_get_info (EmpathyAdiumData *data)
1360 {
1361         g_return_val_if_fail (data != NULL, NULL);
1362
1363         return data->info;
1364 }
1365
1366 const gchar *
1367 empathy_adium_data_get_path (EmpathyAdiumData *data)
1368 {
1369         g_return_val_if_fail (data != NULL, NULL);
1370
1371         return data->path;
1372 }
1373