]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-theme-adium.c
Merge back from master
[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         /* Add <a href></a> arround links */
302         uri_regex = empathy_uri_regex_dup_singleton ();
303         match = g_regex_match (uri_regex, text, 0, &match_info);
304         if (match) {
305                 gint last = 0;
306                 gint s = 0, e = 0;
307
308                 string = g_string_sized_new (strlen (text));
309                 do {
310                         gchar *real_url;
311
312                         g_match_info_fetch_pos (match_info, 0, &s, &e);
313
314                         if (s > last) {
315                                 /* Append the text between last link (or the
316                                  * start of the message) and this link */
317                                 g_string_append_len (string, text + last, s - last);
318                         }
319
320                         /* Append the link inside <a href=""></a> tag */
321                         real_url = empathy_make_absolute_url (text + s);
322
323                         g_string_append (string, "<a href=\"");
324                         g_string_append (string, real_url);
325                         g_string_append (string, "\">");
326                         g_string_append_len (string, text + s, e - s);
327                         g_string_append (string, "</a>");
328
329                         g_free (real_url);
330                         last = e;
331                 } while (g_match_info_next (match_info, NULL));
332
333                 if (e < strlen (text)) {
334                         /* Append the text after the last link */
335                         g_string_append_len (string, text + e, strlen (text) - e);
336                 }
337
338                 g_free (ret);
339                 text = ret = g_string_free (string, FALSE);
340         } else if (use_smileys) {
341                 /* Replace smileys by a <img/> tag */
342                 string = g_string_sized_new (strlen (text));
343                 smileys = empathy_smiley_manager_parse (priv->smiley_manager, text);
344                 for (l = smileys; l; l = l->next) {
345                         EmpathySmiley *smiley;
346
347                         smiley = l->data;
348                         if (smiley->path) {
349                                 g_string_append_printf (string,
350                                                         "<abbr title='%s'><img src=\"%s\"/ alt=\"%s\"/></abbr>",
351                                                         smiley->str, smiley->path, smiley->str);
352                         } else {
353                                 gchar *str;
354
355                                 str = g_markup_escape_text (smiley->str, -1);
356                                 g_string_append (string, str);
357                                 g_free (str);
358                         }
359                         empathy_smiley_free (smiley);
360                 }
361                 g_slist_free (smileys);
362
363                 g_free (ret);
364                 text = ret = g_string_free (string, FALSE);
365         }
366
367         g_match_info_free (match_info);
368         g_regex_unref (uri_regex);
369
370         /* Replace \n by <br/> */
371         string = NULL;
372         prev = 0;
373         for (i = 0; text[i] != '\0'; i++) {
374                 if (text[i] == '\n') {
375                         if (!string ) {
376                                 string = g_string_sized_new (strlen (text));
377                         }
378                         g_string_append_len (string, text + prev, i - prev);
379                         g_string_append (string, "<br/>");
380                         prev = i + 1;
381                 }
382         }
383         if (string) {
384                 g_string_append (string, text + prev);
385                 g_free (ret);
386                 text = ret = g_string_free (string, FALSE);
387         }
388
389         return ret;
390 }
391
392 static void
393 escape_and_append_len (GString *string, const gchar *str, gint len)
394 {
395         while (*str != '\0' && len != 0) {
396                 switch (*str) {
397                 case '\\':
398                         /* \ becomes \\ */
399                         g_string_append (string, "\\\\");
400                         break;
401                 case '\"':
402                         /* " becomes \" */
403                         g_string_append (string, "\\\"");
404                         break;
405                 case '\n':
406                         /* Remove end of lines */
407                         break;
408                 default:
409                         g_string_append_c (string, *str);
410                 }
411
412                 str++;
413                 len--;
414         }
415 }
416
417 static gboolean
418 theme_adium_match (const gchar **str, const gchar *match)
419 {
420         gint len;
421
422         len = strlen (match);
423         if (strncmp (*str, match, len) == 0) {
424                 *str += len - 1;
425                 return TRUE;
426         }
427
428         return FALSE;
429 }
430
431 static void
432 theme_adium_append_html (EmpathyThemeAdium *theme,
433                          const gchar       *func,
434                          const gchar       *html, gsize len,
435                          const gchar       *message,
436                          const gchar       *avatar_filename,
437                          const gchar       *name,
438                          const gchar       *contact_id,
439                          const gchar       *service_name,
440                          const gchar       *message_classes,
441                          time_t             timestamp)
442 {
443         GString     *string;
444         const gchar *cur = NULL;
445         gchar       *script;
446
447         /* Make some search-and-replace in the html code */
448         string = g_string_sized_new (len + strlen (message));
449         g_string_append_printf (string, "%s(\"", func);
450         for (cur = html; *cur != '\0'; cur++) {
451                 const gchar *replace = NULL;
452                 gchar       *dup_replace = NULL;
453
454                 if (theme_adium_match (&cur, "%message%")) {
455                         replace = message;
456                 } else if (theme_adium_match (&cur, "%messageClasses%")) {
457                         replace = message_classes;
458                 } else if (theme_adium_match (&cur, "%userIconPath%")) {
459                         replace = avatar_filename;
460                 } else if (theme_adium_match (&cur, "%sender%")) {
461                         replace = name;
462                 } else if (theme_adium_match (&cur, "%senderScreenName%")) {
463                         replace = contact_id;
464                 } else if (theme_adium_match (&cur, "%senderDisplayName%")) {
465                         /* %senderDisplayName% -
466                          * "The serverside (remotely set) name of the sender,
467                          *  such as an MSN display name."
468                          *
469                          * We don't have access to that yet so we use local
470                          * alias instead.*/
471                         replace = name;
472                 } else if (theme_adium_match (&cur, "%service%")) {
473                         replace = service_name;
474                 } else if (theme_adium_match (&cur, "%shortTime%")) {
475                         dup_replace = empathy_time_to_string_local (timestamp,
476                                 EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
477                         replace = dup_replace;
478                 } else if (theme_adium_match (&cur, "%time")) {
479                         gchar *format = NULL;
480                         gchar *end;
481                         /* Time can be in 2 formats:
482                          * %time% or %time{strftime format}%
483                          * Extract the time format if provided. */
484                         if (cur[1] == '{') {
485                                 cur += 2;
486                                 end = strstr (cur, "}%");
487                                 if (!end) {
488                                         /* Invalid string */
489                                         continue;
490                                 }
491                                 format = g_strndup (cur, end - cur);
492                                 cur = end + 1;
493                         } else {
494                                 cur++;
495                         }
496
497                         dup_replace = empathy_time_to_string_local (timestamp,
498                                 format ? format : EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
499                         replace = dup_replace;
500                         g_free (format);
501                 } else {
502                         escape_and_append_len (string, cur, 1);
503                         continue;
504                 }
505
506                 /* Here we have a replacement to make */
507                 escape_and_append_len (string, replace, -1);
508                 g_free (dup_replace);
509         }
510         g_string_append (string, "\")");
511
512         script = g_string_free (string, FALSE);
513         webkit_web_view_execute_script (WEBKIT_WEB_VIEW (theme), script);
514         g_free (script);
515 }
516
517 static void
518 theme_adium_append_message (EmpathyChatView *view,
519                             EmpathyMessage  *msg)
520 {
521         EmpathyThemeAdium     *theme = EMPATHY_THEME_ADIUM (view);
522         EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
523         EmpathyContact        *sender;
524         EmpathyAccount        *account;
525         gchar                 *dup_body = NULL;
526         const gchar           *body;
527         const gchar           *name;
528         const gchar           *contact_id;
529         EmpathyAvatar         *avatar;
530         const gchar           *avatar_filename = NULL;
531         time_t                 timestamp;
532         gchar                 *html = NULL;
533         gsize                  len = 0;
534         const gchar           *func;
535         const gchar           *service_name;
536         GString               *message_classes = NULL;
537         gboolean              is_backlog;
538
539         if (!priv->page_loaded) {
540                 priv->message_queue = g_list_prepend (priv->message_queue,
541                                                       g_object_ref (msg));
542                 return;
543         }
544
545         /* Get information */
546         sender = empathy_message_get_sender (msg);
547         account = empathy_contact_get_account (sender);
548         service_name = empathy_account_get_protocol (account);
549         timestamp = empathy_message_get_timestamp (msg);
550         body = empathy_message_get_body (msg);
551         dup_body = theme_adium_parse_body (theme, body);
552         if (dup_body) {
553                 body = dup_body;
554         }
555         name = empathy_contact_get_name (sender);
556         contact_id = empathy_contact_get_id (sender);
557
558         /* If this is a /me, append an event */
559         if (empathy_message_get_tptype (msg) == TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION) {
560                 gchar *str;
561
562                 str = g_strdup_printf ("%s %s", name, body);
563                 empathy_chat_view_append_event (view, str);
564                 g_free (str);
565                 g_free (dup_body);
566                 return;
567         }
568
569         /* Get the avatar filename, or a fallback */
570         avatar = empathy_contact_get_avatar (sender);
571         if (avatar) {
572                 avatar_filename = avatar->filename;
573         }
574         if (!avatar_filename) {
575                 if (empathy_contact_is_user (sender)) {
576                         avatar_filename = priv->data->default_outgoing_avatar_filename;
577                 } else {
578                         avatar_filename = priv->data->default_incoming_avatar_filename;
579                 }
580                 if (!avatar_filename) {
581                         if (!priv->data->default_avatar_filename) {
582                                 priv->data->default_avatar_filename =
583                                         empathy_filename_from_icon_name ("stock_person",
584                                                                          GTK_ICON_SIZE_DIALOG);
585                         }
586                         avatar_filename = priv->data->default_avatar_filename;
587                 }
588         }
589
590         is_backlog = empathy_message_is_backlog (msg);
591
592         /* Get the right html/func to add the message */
593         func = "appendMessage";
594
595         message_classes = g_string_new ("message");
596
597         /* eventually append the "history" class */
598         if (is_backlog) {
599                 g_string_append (message_classes, " history");
600         }
601
602         /* check the sender of the message and append the appropriate class */
603         if (empathy_contact_is_user (sender)) {
604                 g_string_append (message_classes, " outgoing");
605         }
606         else {
607                 g_string_append (message_classes, " incoming");
608         }
609
610         /*
611          * To mimick Adium's behavior, we only want to join messages
612          * sent by the same contact within a 5 minute time frame.
613          */
614         if (empathy_contact_equal (priv->last_contact, sender) &&
615             (timestamp - priv->last_timestamp < MESSAGE_JOIN_PERIOD) &&
616             (is_backlog == priv->last_is_backlog)) {
617                 /* the messages can be appended */
618                 func = "appendNextMessage";
619                 g_string_append (message_classes, " consecutive");
620
621                 /* check who is the sender of the message to use the correct html file */
622                 if (empathy_contact_is_user (sender)) {
623                         /* check if this is a backlog message and use NextContext.html */
624                         if (is_backlog) {
625                                 html = priv->data->out_nextcontext_html;
626                                 len = priv->data->out_nextcontext_len;
627                         }
628
629                         /*
630                          * html is null if this is not a backlog message or
631                          * if we have to fallback (NextContext.html missing).
632                          * use NextContent.html
633                          */
634                         if (html == NULL) {
635                                 html = priv->data->out_nextcontent_html;
636                                 len = priv->data->out_nextcontent_len;
637                         }
638                 }
639                 else {
640                         if (is_backlog) {
641                                 html = priv->data->in_nextcontext_html;
642                                 len = priv->data->in_nextcontext_len;
643                         }
644
645                         if (html == NULL) {
646                                 html = priv->data->in_nextcontent_html;
647                                 len = priv->data->in_nextcontent_len;
648                         }
649                 }
650         }
651
652         /*
653          * we have html == NULL here if:
654          * 1. the message didn't have to be appended because
655          *    the sender was different or the timestamp was too far
656          * 2. NextContent.html file does not exist, so we must
657          *    not forget to fallback to the correct Content.html
658          */
659         if (html == NULL) {
660                 if (empathy_contact_is_user (sender)) {
661                         if (is_backlog) {
662                                 html = priv->data->out_context_html;
663                                 len = priv->data->out_context_len;
664                         }
665
666                         if (html == NULL) {
667                                 html = priv->data->out_content_html;
668                                 len = priv->data->out_content_len;
669                         }
670                 }
671                 else {
672                         if (is_backlog) {
673                                 html = priv->data->in_context_html;
674                                 len = priv->data->in_context_len;
675                         }
676
677                         if (html == NULL) {
678                                 html = priv->data->in_content_html;
679                                 len = priv->data->in_content_len;
680                         }
681                 }
682         }
683
684         theme_adium_append_html (theme, func, html, len, body, avatar_filename,
685                                  name, contact_id, service_name, message_classes->str,
686                                  timestamp);
687
688         /* Keep the sender of the last displayed message */
689         if (priv->last_contact) {
690                 g_object_unref (priv->last_contact);
691         }
692         priv->last_contact = g_object_ref (sender);
693         priv->last_timestamp = timestamp;
694         priv->last_is_backlog = is_backlog;
695
696         g_free (dup_body);
697         g_string_free (message_classes, TRUE);
698 }
699
700 static void
701 theme_adium_append_event (EmpathyChatView *view,
702                           const gchar     *str)
703 {
704         EmpathyThemeAdium     *theme = EMPATHY_THEME_ADIUM (view);
705         EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
706
707         if (priv->data->status_html) {
708                 theme_adium_append_html (theme, "appendMessage",
709                                          priv->data->status_html,
710                                          priv->data->status_len,
711                                          str, NULL, NULL, NULL, NULL, "event",
712                                          empathy_time_get_current ());
713         }
714
715         /* There is no last contact */
716         if (priv->last_contact) {
717                 g_object_unref (priv->last_contact);
718                 priv->last_contact = NULL;
719         }
720 }
721
722 static void
723 theme_adium_scroll (EmpathyChatView *view,
724                     gboolean         allow_scrolling)
725 {
726         /* FIXME: Is it possible? I guess we need a js function, but I don't
727          * see any... */
728 }
729
730 static void
731 theme_adium_scroll_down (EmpathyChatView *view)
732 {
733         webkit_web_view_execute_script (WEBKIT_WEB_VIEW (view), "scrollToBottom()");
734 }
735
736 static gboolean
737 theme_adium_get_has_selection (EmpathyChatView *view)
738 {
739         return webkit_web_view_has_selection (WEBKIT_WEB_VIEW (view));
740 }
741
742 static void
743 theme_adium_clear (EmpathyChatView *view)
744 {
745         EmpathyThemeAdiumPriv *priv = GET_PRIV (view);
746         gchar *basedir_uri;
747
748         priv->page_loaded = FALSE;
749         basedir_uri = g_strconcat ("file://", priv->data->basedir, NULL);
750         webkit_web_view_load_html_string (WEBKIT_WEB_VIEW (view),
751                                           priv->data->template_html,
752                                           basedir_uri);
753         g_free (basedir_uri);
754
755         /* Clear last contact to avoid trying to add a 'joined'
756          * message when we don't have an insertion point. */
757         if (priv->last_contact) {
758                 g_object_unref (priv->last_contact);
759                 priv->last_contact = NULL;
760         }
761 }
762
763 static gboolean
764 theme_adium_find_previous (EmpathyChatView *view,
765                            const gchar     *search_criteria,
766                            gboolean         new_search)
767 {
768         return webkit_web_view_search_text (WEBKIT_WEB_VIEW (view),
769                                             search_criteria, FALSE,
770                                             FALSE, TRUE);
771 }
772
773 static gboolean
774 theme_adium_find_next (EmpathyChatView *view,
775                        const gchar     *search_criteria,
776                        gboolean         new_search)
777 {
778         return webkit_web_view_search_text (WEBKIT_WEB_VIEW (view),
779                                             search_criteria, FALSE,
780                                             TRUE, TRUE);
781 }
782
783 static void
784 theme_adium_find_abilities (EmpathyChatView *view,
785                             const gchar    *search_criteria,
786                             gboolean       *can_do_previous,
787                             gboolean       *can_do_next)
788 {
789         /* FIXME: Does webkit provide an API for that? We have wrap=true in
790          * find_next and find_previous to work around this problem. */
791         if (can_do_previous)
792                 *can_do_previous = TRUE;
793         if (can_do_next)
794                 *can_do_next = TRUE;
795 }
796
797 static void
798 theme_adium_highlight (EmpathyChatView *view,
799                        const gchar     *text)
800 {
801         webkit_web_view_unmark_text_matches (WEBKIT_WEB_VIEW (view));
802         webkit_web_view_mark_text_matches (WEBKIT_WEB_VIEW (view),
803                                            text, FALSE, 0);
804         webkit_web_view_set_highlight_text_matches (WEBKIT_WEB_VIEW (view),
805                                                     TRUE);
806 }
807
808 static void
809 theme_adium_copy_clipboard (EmpathyChatView *view)
810 {
811         webkit_web_view_copy_clipboard (WEBKIT_WEB_VIEW (view));
812 }
813
814 static void
815 theme_adium_iface_init (EmpathyChatViewIface *iface)
816 {
817         iface->append_message = theme_adium_append_message;
818         iface->append_event = theme_adium_append_event;
819         iface->scroll = theme_adium_scroll;
820         iface->scroll_down = theme_adium_scroll_down;
821         iface->get_has_selection = theme_adium_get_has_selection;
822         iface->clear = theme_adium_clear;
823         iface->find_previous = theme_adium_find_previous;
824         iface->find_next = theme_adium_find_next;
825         iface->find_abilities = theme_adium_find_abilities;
826         iface->highlight = theme_adium_highlight;
827         iface->copy_clipboard = theme_adium_copy_clipboard;
828 }
829
830 static void
831 theme_adium_load_finished_cb (WebKitWebView  *view,
832                               WebKitWebFrame *frame,
833                               gpointer        user_data)
834 {
835         EmpathyThemeAdiumPriv *priv = GET_PRIV (view);
836         EmpathyChatView       *chat_view = EMPATHY_CHAT_VIEW (view);
837
838         DEBUG ("Page loaded");
839         priv->page_loaded = TRUE;
840
841         /* Display queued messages */
842         priv->message_queue = g_list_reverse (priv->message_queue);
843         while (priv->message_queue) {
844                 EmpathyMessage *message = priv->message_queue->data;
845
846                 theme_adium_append_message (chat_view, message);
847                 priv->message_queue = g_list_remove (priv->message_queue, message);
848                 g_object_unref (message);
849         }
850 }
851
852 static void
853 theme_adium_finalize (GObject *object)
854 {
855         EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
856
857         empathy_adium_data_unref (priv->data);
858         g_free (priv->hovered_uri);
859
860         empathy_conf_notify_remove (empathy_conf_get (),
861                                     priv->notify_enable_webkit_developer_tools_id);
862
863         G_OBJECT_CLASS (empathy_theme_adium_parent_class)->finalize (object);
864 }
865
866 static void
867 theme_adium_dispose (GObject *object)
868 {
869         EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
870
871         if (priv->smiley_manager) {
872                 g_object_unref (priv->smiley_manager);
873                 priv->smiley_manager = NULL;
874         }
875
876         if (priv->last_contact) {
877                 g_object_unref (priv->last_contact);
878                 priv->last_contact = NULL;
879         }
880
881         if (priv->inspector_window) {
882                 gtk_widget_destroy (priv->inspector_window);
883                 priv->inspector_window = NULL;
884         }
885
886         G_OBJECT_CLASS (empathy_theme_adium_parent_class)->dispose (object);
887 }
888
889 static gboolean
890 theme_adium_inspector_show_window_cb (WebKitWebInspector *inspector,
891                                       EmpathyThemeAdium  *theme)
892 {
893         EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
894
895         if (priv->inspector_window) {
896                 gtk_widget_show_all (priv->inspector_window);
897         }
898
899         return TRUE;
900 }
901
902 static gboolean
903 theme_adium_inspector_close_window_cb (WebKitWebInspector *inspector,
904                                        EmpathyThemeAdium  *theme)
905 {
906         EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
907
908         if (priv->inspector_window) {
909                 gtk_widget_hide (priv->inspector_window);
910         }
911
912         return TRUE;
913 }
914
915 static WebKitWebView *
916 theme_adium_inspect_web_view_cb (WebKitWebInspector *inspector,
917                                  WebKitWebView      *web_view,
918                                  EmpathyThemeAdium  *theme)
919 {
920         EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
921         GtkWidget             *scrolled_window;
922         GtkWidget             *inspector_web_view;
923
924         if (!priv->inspector_window) {
925                 /* Create main window */
926                 priv->inspector_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
927                 gtk_window_set_default_size (GTK_WINDOW (priv->inspector_window),
928                                              800, 600);
929                 g_signal_connect (priv->inspector_window, "delete-event",
930                                   G_CALLBACK (gtk_widget_hide_on_delete), NULL);
931
932                 /* Pack a scrolled window */
933                 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
934                 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
935                                                 GTK_POLICY_AUTOMATIC,
936                                                 GTK_POLICY_AUTOMATIC);
937                 gtk_container_add (GTK_CONTAINER (priv->inspector_window),
938                                    scrolled_window);
939                 gtk_widget_show  (scrolled_window);
940
941                 /* Pack a webview in the scrolled window. That webview will be
942                  * used to render the inspector tool.  */
943                 inspector_web_view = webkit_web_view_new ();
944                 gtk_container_add (GTK_CONTAINER (scrolled_window),
945                                    inspector_web_view);
946                 gtk_widget_show (scrolled_window);
947
948                 return WEBKIT_WEB_VIEW (inspector_web_view);
949         }
950
951         return NULL;
952 }
953
954 static void
955 theme_adium_constructed (GObject *object)
956 {
957         EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
958         gchar                 *basedir_uri;
959         const gchar           *font_family = NULL;
960         gint                   font_size = 0;
961         WebKitWebView         *webkit_view = WEBKIT_WEB_VIEW (object);
962         WebKitWebSettings     *webkit_settings;
963         WebKitWebInspector    *webkit_inspector;
964
965         /* Set default settings */
966         font_family = tp_asv_get_string (priv->data->info, "DefaultFontFamily");
967         font_size = tp_asv_get_int32 (priv->data->info, "DefaultFontSize", NULL);
968         webkit_settings = webkit_web_view_get_settings (webkit_view);
969         if (font_family) {
970                 g_object_set (webkit_settings,
971                               "default-font-family", font_family,
972                               NULL);
973         }
974         if (font_size) {
975                 g_object_set (webkit_settings,
976                               "default-font-size", font_size,
977                               NULL);
978         }
979
980         /* Setup webkit inspector */
981         webkit_inspector = webkit_web_view_get_inspector (webkit_view);
982         g_signal_connect (webkit_inspector, "inspect-web-view",
983                           G_CALLBACK (theme_adium_inspect_web_view_cb),
984                           object);
985         g_signal_connect (webkit_inspector, "show-window",
986                           G_CALLBACK (theme_adium_inspector_show_window_cb),
987                           object);
988         g_signal_connect (webkit_inspector, "close-window",
989                           G_CALLBACK (theme_adium_inspector_close_window_cb),
990                           object);
991
992         /* Load template */
993         basedir_uri = g_strconcat ("file://", priv->data->basedir, NULL);
994         webkit_web_view_load_html_string (WEBKIT_WEB_VIEW (object),
995                                           priv->data->template_html,
996                                           basedir_uri);
997         g_free (basedir_uri);
998 }
999
1000 static void
1001 theme_adium_get_property (GObject    *object,
1002                           guint       param_id,
1003                           GValue     *value,
1004                           GParamSpec *pspec)
1005 {
1006         EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
1007
1008         switch (param_id) {
1009         case PROP_ADIUM_DATA:
1010                 g_value_set_boxed (value, priv->data);
1011                 break;
1012         default:
1013                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1014                 break;
1015         };
1016 }
1017
1018 static void
1019 theme_adium_set_property (GObject      *object,
1020                           guint         param_id,
1021                           const GValue *value,
1022                           GParamSpec   *pspec)
1023 {
1024         EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
1025
1026         switch (param_id) {
1027         case PROP_ADIUM_DATA:
1028                 g_assert (priv->data == NULL);
1029                 priv->data = g_value_dup_boxed (value);
1030                 break;
1031         default:
1032                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1033                 break;
1034         };
1035 }
1036
1037 static void
1038 empathy_theme_adium_class_init (EmpathyThemeAdiumClass *klass)
1039 {
1040         GObjectClass *object_class = G_OBJECT_CLASS (klass);
1041
1042         object_class->finalize = theme_adium_finalize;
1043         object_class->dispose = theme_adium_dispose;
1044         object_class->constructed = theme_adium_constructed;
1045         object_class->get_property = theme_adium_get_property;
1046         object_class->set_property = theme_adium_set_property;
1047
1048         g_object_class_install_property (object_class,
1049                                          PROP_ADIUM_DATA,
1050                                          g_param_spec_boxed ("adium-data",
1051                                                              "The theme data",
1052                                                              "Data for the adium theme",
1053                                                               EMPATHY_TYPE_ADIUM_DATA,
1054                                                               G_PARAM_CONSTRUCT_ONLY |
1055                                                               G_PARAM_READWRITE |
1056                                                               G_PARAM_STATIC_STRINGS));
1057
1058         g_type_class_add_private (object_class, sizeof (EmpathyThemeAdiumPriv));
1059 }
1060
1061 static void
1062 empathy_theme_adium_init (EmpathyThemeAdium *theme)
1063 {
1064         EmpathyThemeAdiumPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (theme,
1065                 EMPATHY_TYPE_THEME_ADIUM, EmpathyThemeAdiumPriv);
1066
1067         theme->priv = priv;
1068
1069         priv->smiley_manager = empathy_smiley_manager_dup_singleton ();
1070
1071         g_signal_connect (theme, "load-finished",
1072                           G_CALLBACK (theme_adium_load_finished_cb),
1073                           NULL);
1074         g_signal_connect (theme, "navigation-requested",
1075                           G_CALLBACK (theme_adium_navigation_requested_cb),
1076                           NULL);
1077         g_signal_connect (theme, "populate-popup",
1078                           G_CALLBACK (theme_adium_populate_popup_cb),
1079                           NULL);
1080         g_signal_connect (theme, "hovering-over-link",
1081                           G_CALLBACK (theme_adium_hovering_over_link_cb),
1082                           NULL);
1083
1084         priv->notify_enable_webkit_developer_tools_id =
1085                 empathy_conf_notify_add (empathy_conf_get (),
1086                                          EMPATHY_PREFS_CHAT_WEBKIT_DEVELOPER_TOOLS,
1087                                          theme_adium_notify_enable_webkit_developer_tools_cb,
1088                                          theme);
1089
1090         theme_adium_update_enable_webkit_developer_tools (theme);
1091 }
1092
1093 EmpathyThemeAdium *
1094 empathy_theme_adium_new (EmpathyAdiumData *data)
1095 {
1096         g_return_val_if_fail (data != NULL, NULL);
1097
1098         return g_object_new (EMPATHY_TYPE_THEME_ADIUM,
1099                              "adium-data", data,
1100                              NULL);
1101 }
1102
1103 gboolean
1104 empathy_adium_path_is_valid (const gchar *path)
1105 {
1106         gboolean ret;
1107         gchar   *file;
1108
1109         /* The theme is not valid if there is no Info.plist */
1110         file = g_build_filename (path, "Contents", "Info.plist",
1111                                  NULL);
1112         ret = g_file_test (file, G_FILE_TEST_EXISTS);
1113         g_free (file);
1114
1115         if (ret == FALSE)
1116                 return ret;
1117
1118         /* We ship a default Template.html as fallback if there is any problem
1119          * with the one inside the theme. The only other required file is
1120          * Content.html for incoming messages (outgoing fallback to use
1121          * incoming). */
1122         file = g_build_filename (path, "Contents", "Resources", "Incoming",
1123                                  "Content.html", NULL);
1124         ret = g_file_test (file, G_FILE_TEST_EXISTS);
1125         g_free (file);
1126
1127         return ret;
1128 }
1129
1130 GHashTable *
1131 empathy_adium_info_new (const gchar *path)
1132 {
1133         gchar *file;
1134         GValue *value;
1135         GHashTable *info = NULL;
1136
1137         g_return_val_if_fail (empathy_adium_path_is_valid (path), NULL);
1138
1139         file = g_build_filename (path, "Contents", "Info.plist", NULL);
1140         value = empathy_plist_parse_from_file (file);
1141         g_free (file);
1142
1143         if (value == NULL)
1144                 return NULL;
1145
1146         info = g_value_dup_boxed (value);
1147         tp_g_value_slice_free (value);
1148
1149         /* Insert the theme's path into the hash table,
1150          * keys have to be dupped */
1151         tp_asv_set_string (info, g_strdup ("path"), path);
1152
1153         return info;
1154 }
1155
1156 GType
1157 empathy_adium_data_get_type (void)
1158 {
1159   static GType type_id = 0;
1160
1161   if (!type_id)
1162     {
1163       type_id = g_boxed_type_register_static ("EmpathyAdiumData",
1164           (GBoxedCopyFunc) empathy_adium_data_ref,
1165           (GBoxedFreeFunc) empathy_adium_data_unref);
1166     }
1167
1168   return type_id;
1169 }
1170
1171 EmpathyAdiumData  *
1172 empathy_adium_data_new_with_info (const gchar *path, GHashTable *info)
1173 {
1174         EmpathyAdiumData *data;
1175         gchar            *file;
1176         gchar            *template_html = NULL;
1177         gsize             template_len;
1178         gchar            *footer_html = NULL;
1179         gsize             footer_len;
1180         GString          *string;
1181         gchar           **strv = NULL;
1182         gchar            *css_path;
1183         guint             len = 0;
1184         guint             i = 0;
1185
1186         g_return_val_if_fail (empathy_adium_path_is_valid (path), NULL);
1187
1188         data = g_slice_new0 (EmpathyAdiumData);
1189         data->ref_count = 1;
1190         data->path = g_strdup (path);
1191         data->basedir = g_strconcat (path, G_DIR_SEPARATOR_S "Contents"
1192                 G_DIR_SEPARATOR_S "Resources" G_DIR_SEPARATOR_S, NULL);
1193         data->info = g_hash_table_ref (info);
1194
1195         /* Load html files */
1196         file = g_build_filename (data->basedir, "Incoming", "Content.html", NULL);
1197         g_file_get_contents (file, &data->in_content_html, &data->in_content_len, NULL);
1198         g_free (file);
1199
1200         file = g_build_filename (data->basedir, "Incoming", "NextContent.html", NULL);
1201         g_file_get_contents (file, &data->in_nextcontent_html, &data->in_nextcontent_len, NULL);
1202         g_free (file);
1203
1204         file = g_build_filename (data->basedir, "Incoming", "Context.html", NULL);
1205         g_file_get_contents (file, &data->in_context_html, &data->in_context_len, NULL);
1206         g_free (file);
1207
1208         file = g_build_filename (data->basedir, "Incoming", "NextContext.html", NULL);
1209         g_file_get_contents (file, &data->in_nextcontext_html, &data->in_nextcontext_len, NULL);
1210         g_free (file);
1211
1212         file = g_build_filename (data->basedir, "Outgoing", "Content.html", NULL);
1213         g_file_get_contents (file, &data->out_content_html, &data->out_content_len, NULL);
1214         g_free (file);
1215
1216         file = g_build_filename (data->basedir, "Outgoing", "NextContent.html", NULL);
1217         g_file_get_contents (file, &data->out_nextcontent_html, &data->out_nextcontent_len, NULL);
1218         g_free (file);
1219
1220         file = g_build_filename (data->basedir, "Outgoing", "Context.html", NULL);
1221         g_file_get_contents (file, &data->out_context_html, &data->out_context_len, NULL);
1222         g_free (file);
1223
1224         file = g_build_filename (data->basedir, "Outgoing", "NextContext.html", NULL);
1225         g_file_get_contents (file, &data->out_nextcontext_html, &data->out_nextcontext_len, NULL);
1226         g_free (file);
1227
1228         file = g_build_filename (data->basedir, "Status.html", NULL);
1229         g_file_get_contents (file, &data->status_html, &data->status_len, NULL);
1230         g_free (file);
1231
1232         file = g_build_filename (data->basedir, "Footer.html", NULL);
1233         g_file_get_contents (file, &footer_html, &footer_len, NULL);
1234         g_free (file);
1235
1236         file = g_build_filename (data->basedir, "Incoming", "buddy_icon.png", NULL);
1237         if (g_file_test (file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
1238                 data->default_incoming_avatar_filename = file;
1239         } else {
1240                 g_free (file);
1241         }
1242
1243         file = g_build_filename (data->basedir, "Outgoing", "buddy_icon.png", NULL);
1244         if (g_file_test (file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
1245                 data->default_outgoing_avatar_filename = file;
1246         } else {
1247                 g_free (file);
1248         }
1249
1250         css_path = g_build_filename (data->basedir, "main.css", NULL);
1251
1252         /* There is 2 formats for Template.html: The old one has 4 parameters,
1253          * the new one has 5 parameters. */
1254         file = g_build_filename (data->basedir, "Template.html", NULL);
1255         if (g_file_get_contents (file, &template_html, &template_len, NULL)) {
1256                 strv = g_strsplit (template_html, "%@", -1);
1257                 len = g_strv_length (strv);
1258         }
1259         g_free (file);
1260
1261         if (len != 5 && len != 6) {
1262                 /* Either the theme has no template or it don't have the good
1263                  * number of parameters. Fallback to use our own template. */
1264                 g_free (template_html);
1265                 g_strfreev (strv);
1266
1267                 file = empathy_file_lookup ("Template.html", "data");
1268                 g_file_get_contents (file, &template_html, &template_len, NULL);
1269                 g_free (file);
1270                 strv = g_strsplit (template_html, "%@", -1);
1271                 len = g_strv_length (strv);
1272         }
1273
1274         /* Replace %@ with the needed information in the template html. */
1275         string = g_string_sized_new (template_len);
1276         g_string_append (string, strv[i++]);
1277         g_string_append (string, data->basedir);
1278         g_string_append (string, strv[i++]);
1279         if (len == 6) {
1280                 const gchar *variant;
1281
1282                 /* We include main.css by default */
1283                 g_string_append_printf (string, "@import url(\"%s\");", css_path);
1284                 g_string_append (string, strv[i++]);
1285                 variant = tp_asv_get_string (data->info, "DefaultVariant");
1286                 if (variant) {
1287                         g_string_append (string, "Variants/");
1288                         g_string_append (string, variant);
1289                         g_string_append (string, ".css");
1290                 }
1291         } else {
1292                 /* FIXME: We should set main.css OR the variant css */
1293                 g_string_append (string, css_path);
1294         }
1295         g_string_append (string, strv[i++]);
1296         g_string_append (string, ""); /* We don't want header */
1297         g_string_append (string, strv[i++]);
1298         /* FIXME: We should replace adium %macros% in footer */
1299         if (footer_html) {
1300                 g_string_append (string, footer_html);
1301         }
1302         g_string_append (string, strv[i++]);
1303         data->template_html = g_string_free (string, FALSE);
1304
1305         g_free (footer_html);
1306         g_free (template_html);
1307         g_free (css_path);
1308         g_strfreev (strv);
1309
1310         return data;
1311 }
1312
1313 EmpathyAdiumData  *
1314 empathy_adium_data_new (const gchar *path)
1315 {
1316         EmpathyAdiumData *data;
1317         GHashTable *info;
1318
1319         info = empathy_adium_info_new (path);
1320         data = empathy_adium_data_new_with_info (path, info);
1321         g_hash_table_unref (info);
1322
1323         return data;
1324 }
1325
1326 EmpathyAdiumData  *
1327 empathy_adium_data_ref (EmpathyAdiumData *data)
1328 {
1329         g_return_val_if_fail (data != NULL, NULL);
1330
1331         g_atomic_int_inc (&data->ref_count);
1332
1333         return data;
1334 }
1335
1336 void
1337 empathy_adium_data_unref (EmpathyAdiumData *data)
1338 {
1339         g_return_if_fail (data != NULL);
1340
1341         if (g_atomic_int_dec_and_test (&data->ref_count)) {
1342                 g_free (data->path);
1343                 g_free (data->basedir);
1344                 g_free (data->template_html);
1345                 g_free (data->in_content_html);
1346                 g_free (data->in_nextcontent_html);
1347                 g_free (data->in_context_html);
1348                 g_free (data->in_nextcontext_html);
1349                 g_free (data->out_content_html);
1350                 g_free (data->out_nextcontent_html);
1351                 g_free (data->out_context_html);
1352                 g_free (data->out_nextcontext_html);
1353                 g_free (data->default_avatar_filename);
1354                 g_free (data->default_incoming_avatar_filename);
1355                 g_free (data->default_outgoing_avatar_filename);
1356                 g_free (data->status_html);
1357                 g_hash_table_unref (data->info);
1358                 g_slice_free (EmpathyAdiumData, data);
1359         }
1360 }
1361
1362 GHashTable *
1363 empathy_adium_data_get_info (EmpathyAdiumData *data)
1364 {
1365         g_return_val_if_fail (data != NULL, NULL);
1366
1367         return data->info;
1368 }
1369
1370 const gchar *
1371 empathy_adium_data_get_path (EmpathyAdiumData *data)
1372 {
1373         g_return_val_if_fail (data != NULL, NULL);
1374
1375         return data->path;
1376 }
1377