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