/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
- * Copyright (C) 2008 Collabora Ltd.
+ * Copyright (C) 2008-2009 Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
#include <string.h>
#include <glib/gi18n.h>
-#include <webkit/webkitnetworkrequest.h>
+#include <webkit/webkit.h>
+#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/util.h>
+
#include <libempathy/empathy-time.h>
#include <libempathy/empathy-utils.h>
#include "empathy-smiley-manager.h"
#include "empathy-conf.h"
#include "empathy-ui-utils.h"
+#include "empathy-plist.h"
#define DEBUG_FLAG EMPATHY_DEBUG_CHAT
#include <libempathy/empathy-debug.h>
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyThemeAdium)
+/* "Join" consecutive messages with timestamps within five minutes */
+#define MESSAGE_JOIN_PERIOD 5*60
+
typedef struct {
+ EmpathyAdiumData *data;
EmpathySmileyManager *smiley_manager;
EmpathyContact *last_contact;
+ time_t last_timestamp;
+ gboolean last_is_backlog;
gboolean page_loaded;
GList *message_queue;
- gchar *path;
- gchar *default_avatar_filename;
- gchar *in_content_html;
- gsize in_content_len;
- gchar *in_nextcontent_html;
- gsize in_nextcontent_len;
- gchar *out_content_html;
- gsize out_content_len;
- gchar *out_nextcontent_html;
- gsize out_nextcontent_len;
+ gchar *hovered_uri;
+ guint notify_enable_webkit_developer_tools_id;
+ GtkWidget *inspector_window;
} EmpathyThemeAdiumPriv;
+struct _EmpathyAdiumData {
+ guint ref_count;
+ gchar *path;
+ gchar *basedir;
+ gchar *default_avatar_filename;
+ gchar *default_incoming_avatar_filename;
+ gchar *default_outgoing_avatar_filename;
+ gchar *template_html;
+ gchar *in_content_html;
+ gsize in_content_len;
+ gchar *in_context_html;
+ gsize in_context_len;
+ gchar *in_nextcontent_html;
+ gsize in_nextcontent_len;
+ gchar *in_nextcontext_html;
+ gsize in_nextcontext_len;
+ gchar *out_content_html;
+ gsize out_content_len;
+ gchar *out_context_html;
+ gsize out_context_len;
+ gchar *out_nextcontent_html;
+ gsize out_nextcontent_len;
+ gchar *out_nextcontext_html;
+ gsize out_nextcontext_len;
+ gchar *status_html;
+ gsize status_len;
+ GHashTable *info;
+};
+
static void theme_adium_iface_init (EmpathyChatViewIface *iface);
enum {
PROP_0,
- PROP_PATH,
+ PROP_ADIUM_DATA,
};
G_DEFINE_TYPE_WITH_CODE (EmpathyThemeAdium, empathy_theme_adium,
theme_adium_iface_init));
static void
-theme_adium_load (EmpathyThemeAdium *theme)
+theme_adium_update_enable_webkit_developer_tools (EmpathyThemeAdium *theme)
{
- EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
- gchar *basedir;
- gchar *file;
- gchar *template_html;
- gsize template_len;
- GString *string;
- gchar **strv;
- gchar *content;
- gchar *css_path;
+ WebKitWebView *web_view = WEBKIT_WEB_VIEW (theme);
+ gboolean enable_webkit_developer_tools;
- basedir = g_build_filename (priv->path, "Contents", "Resources", NULL);
+ if (!empathy_conf_get_bool (empathy_conf_get (),
+ EMPATHY_PREFS_CHAT_WEBKIT_DEVELOPER_TOOLS,
+ &enable_webkit_developer_tools)) {
+ return;
+ }
- /* Load html files */
- file = g_build_filename (basedir, "Template.html", NULL);
- g_file_get_contents (file, &template_html, &template_len, NULL);
- g_free (file);
+ g_object_set (G_OBJECT (webkit_web_view_get_settings (web_view)),
+ "enable-developer-extras",
+ enable_webkit_developer_tools,
+ NULL);
+}
- file = g_build_filename (basedir, "Incoming", "Content.html", NULL);
- g_file_get_contents (file, &priv->in_content_html, &priv->in_content_len, NULL);
- g_free (file);
+static void
+theme_adium_notify_enable_webkit_developer_tools_cb (EmpathyConf *conf,
+ const gchar *key,
+ gpointer user_data)
+{
+ EmpathyThemeAdium *theme = user_data;
- file = g_build_filename (basedir, "Incoming", "NextContent.html", NULL);
- g_file_get_contents (file, &priv->in_nextcontent_html, &priv->in_nextcontent_len, NULL);
- g_free (file);
+ theme_adium_update_enable_webkit_developer_tools (theme);
+}
- file = g_build_filename (basedir, "Outgoing", "Content.html", NULL);
- g_file_get_contents (file, &priv->out_content_html, &priv->out_content_len, NULL);
- g_free (file);
+static gboolean
+theme_adium_navigation_policy_decision_requested_cb (WebKitWebView *view,
+ WebKitWebFrame *web_frame,
+ WebKitNetworkRequest *request,
+ WebKitWebNavigationAction *action,
+ WebKitWebPolicyDecision *decision,
+ gpointer data)
+{
+ const gchar *uri;
- file = g_build_filename (basedir, "Outgoing", "NextContent.html", NULL);
- g_file_get_contents (file, &priv->out_nextcontent_html, &priv->out_nextcontent_len, NULL);
- g_free (file);
+ /* Only call url_show on clicks */
+ if (webkit_web_navigation_action_get_reason (action) !=
+ WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED) {
+ webkit_web_policy_decision_use (decision);
+ return TRUE;
+ }
- css_path = g_build_filename (basedir, "main.css", NULL);
+ uri = webkit_network_request_get_uri (request);
+ empathy_url_show (GTK_WIDGET (view), uri);
- /* Replace %@ with the needed information in the template html */
- strv = g_strsplit (template_html, "%@", 5);
- string = g_string_sized_new (template_len);
- g_string_append (string, strv[0]);
- g_string_append (string, basedir);
- g_string_append (string, strv[1]);
- g_string_append (string, css_path);
- g_string_append (string, strv[2]);
- g_string_append (string, ""); /* We don't want header */
- g_string_append (string, strv[3]);
- g_string_append (string, ""); /* We have no footer */
- g_string_append (string, strv[4]);
- content = g_string_free (string, FALSE);
+ webkit_web_policy_decision_ignore (decision);
+ return TRUE;
+}
- /* Load the template */
- webkit_web_view_load_html_string (WEBKIT_WEB_VIEW (theme),
- content, basedir);
+static void
+theme_adium_hovering_over_link_cb (EmpathyThemeAdium *theme,
+ gchar *title,
+ gchar *uri,
+ gpointer user_data)
+{
+ EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
- g_free (basedir);
- g_free (content);
- g_free (template_html);
- g_free (css_path);
- g_strfreev (strv);
+ if (tp_strdiff (uri, priv->hovered_uri)) {
+ g_free (priv->hovered_uri);
+ priv->hovered_uri = g_strdup (uri);
+ }
}
-static WebKitNavigationResponse
-theme_adium_navigation_requested_cb (WebKitWebView *view,
- WebKitWebFrame *frame,
- WebKitNetworkRequest *request,
- gpointer user_data)
+static void
+theme_adium_copy_address_cb (GtkMenuItem *menuitem,
+ gpointer user_data)
{
- const gchar *uri;
+ EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (user_data);
+ EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
+ GtkClipboard *clipboard;
- uri = webkit_network_request_get_uri (request);
- empathy_url_show (GTK_WIDGET (view), uri);
+ clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
+ gtk_clipboard_set_text (clipboard, priv->hovered_uri, -1);
- return WEBKIT_NAVIGATION_RESPONSE_IGNORE;
+ clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
+ gtk_clipboard_set_text (clipboard, priv->hovered_uri, -1);
}
-static gchar *
-theme_adium_escape_script (const gchar *text)
+static void
+theme_adium_open_address_cb (GtkMenuItem *menuitem,
+ gpointer user_data)
{
- const gchar *cur = text;
- GString *string;
+ EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (user_data);
+ EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
- string = g_string_sized_new (strlen (text));
- while (!G_STR_EMPTY (cur)) {
- switch (*cur) {
- case '\\':
- g_string_append (string, "\\\\");
- break;
- case '\"':
- g_string_append (string, "\\\"");
- break;
- case '\r':
- g_string_append (string, "<br/>");
- break;
- case '\n':
- break;
- default:
- g_string_append_c (string, *cur);
- }
- cur++;
+ empathy_url_show (GTK_WIDGET (menuitem), priv->hovered_uri);
+}
+
+static void
+theme_adium_populate_popup_cb (WebKitWebView *view,
+ GtkMenu *menu,
+ gpointer user_data)
+{
+ EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (view);
+ EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
+ GtkWidget *item;
+ GList *items;
+ GtkWidget *icon;
+ gchar *stock_id;
+ gboolean is_link = FALSE;
+ gboolean developer_tools_enabled;
+
+ /* FIXME: WebKitGTK+'s context menu API clearly needs an
+ * overhaul. There is currently no way to know what is being
+ * clicked, to decide what features to provide. You either
+ * take what it gives you as a menu, or use hacks to figure
+ * out what to display. */
+ items = gtk_container_get_children (GTK_CONTAINER (menu));
+ item = GTK_WIDGET (g_list_nth_data (items, 0));
+ g_list_free (items);
+
+ if (GTK_IS_IMAGE_MENU_ITEM (item)) {
+ icon = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (item));
+ gtk_image_get_stock (GTK_IMAGE (icon), &stock_id, NULL);
+
+ if ((!strcmp (stock_id, GTK_STOCK_OPEN)) && priv->hovered_uri)
+ is_link = TRUE;
+ }
+
+ /* Remove default menu items */
+ g_object_get (G_OBJECT (webkit_web_view_get_settings (view)),
+ "enable-developer-extras", &developer_tools_enabled, NULL);
+ if (!developer_tools_enabled)
+ gtk_container_foreach (GTK_CONTAINER (menu),
+ (GtkCallback) gtk_widget_destroy, NULL);
+
+ /* Select all item */
+ item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
+ gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+
+ g_signal_connect_swapped (item, "activate",
+ G_CALLBACK (webkit_web_view_select_all),
+ view);
+
+ /* Copy menu item */
+ if (webkit_web_view_can_copy_clipboard (view)) {
+ item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL);
+ gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+
+ g_signal_connect_swapped (item, "activate",
+ G_CALLBACK (webkit_web_view_copy_clipboard),
+ view);
}
- return g_string_free (string, FALSE);
+ /* Clear menu item */
+ item = gtk_separator_menu_item_new ();
+ gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+
+ item = gtk_image_menu_item_new_from_stock (GTK_STOCK_CLEAR, NULL);
+ gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+
+ g_signal_connect_swapped (item, "activate",
+ G_CALLBACK (empathy_chat_view_clear),
+ view);
+
+ /* We will only add the following menu items if we are
+ * right-clicking a link */
+ if (!is_link)
+ return;
+
+ /* Separator */
+ item = gtk_separator_menu_item_new ();
+ gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+
+ /* Copy Link Address menu item */
+ item = gtk_menu_item_new_with_mnemonic (_("_Copy Link Address"));
+ g_signal_connect (item, "activate",
+ G_CALLBACK (theme_adium_copy_address_cb),
+ view);
+ gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+
+ /* Open Link menu item */
+ item = gtk_menu_item_new_with_mnemonic (_("_Open Link"));
+ g_signal_connect (item, "activate",
+ G_CALLBACK (theme_adium_open_address_cb),
+ view);
+ gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
}
static gchar *
GMatchInfo *match_info;
gboolean match;
gchar *ret = NULL;
- gchar *iter;
- const gchar *cur = text;
+ gint prev;
empathy_conf_get_bool (empathy_conf_get (),
EMPATHY_PREFS_CHAT_SHOW_SMILEYS,
&use_smileys);
- if (use_smileys) {
- /* Replace smileys by a <img/> tag */
- string = g_string_sized_new (strlen (cur));
- smileys = empathy_smiley_manager_parse (priv->smiley_manager, cur);
- for (l = smileys; l; l = l->next) {
- EmpathySmiley *smiley;
-
- smiley = l->data;
- if (smiley->path) {
- g_string_append_printf (string,
- "<abbr title='%s'><img src=\"%s\"/ alt=\"%s\"/></abbr>",
- smiley->str, smiley->path, smiley->str);
- } else {
- g_string_append (string, smiley->str);
- }
- empathy_smiley_free (smiley);
- }
- g_slist_free (smileys);
-
- g_free (ret);
- cur = ret = g_string_free (string, FALSE);
- }
-
/* Add <a href></a> arround links */
uri_regex = empathy_uri_regex_dup_singleton ();
- match = g_regex_match (uri_regex, cur, 0, &match_info);
+ match = g_regex_match (uri_regex, text, 0, &match_info);
if (match) {
gint last = 0;
gint s = 0, e = 0;
- string = g_string_sized_new (strlen (cur));
+ string = g_string_sized_new (strlen (text));
do {
+ gchar *real_url;
+
g_match_info_fetch_pos (match_info, 0, &s, &e);
if (s > last) {
/* Append the text between last link (or the
* start of the message) and this link */
- g_string_append_len (string, cur + last, s - last);
+ g_string_append_len (string, text + last, s - last);
}
/* Append the link inside <a href=""></a> tag */
+ real_url = empathy_make_absolute_url_len (text + s, e - s);
+
g_string_append (string, "<a href=\"");
- g_string_append_len (string, cur + s, e - s);
+ g_string_append (string, real_url);
g_string_append (string, "\">");
- g_string_append_len (string, cur + s, e - s);
+ g_string_append_len (string, text + s, e - s);
g_string_append (string, "</a>");
+ g_free (real_url);
last = e;
} while (g_match_info_next (match_info, NULL));
- if (e < strlen (cur)) {
+ if (e < strlen (text)) {
/* Append the text after the last link */
- g_string_append_len (string, cur + e, strlen (cur) - e);
+ g_string_append_len (string, text + e, strlen (text) - e);
+ }
+
+ g_free (ret);
+ text = ret = g_string_free (string, FALSE);
+ } else if (use_smileys) {
+ /* Replace smileys by a <img/> tag */
+ string = g_string_sized_new (strlen (text));
+ smileys = empathy_smiley_manager_parse (priv->smiley_manager, text);
+ for (l = smileys; l; l = l->next) {
+ EmpathySmiley *smiley;
+
+ smiley = l->data;
+ if (smiley->path) {
+ g_string_append_printf (string,
+ "<abbr title='%s'><img src=\"%s\"/ alt=\"%s\"/></abbr>",
+ smiley->str, smiley->path, smiley->str);
+ } else {
+ gchar *str;
+
+ str = g_markup_escape_text (smiley->str, -1);
+ g_string_append (string, str);
+ g_free (str);
+ }
+ empathy_smiley_free (smiley);
}
+ g_slist_free (smileys);
g_free (ret);
- cur = ret = g_string_free (string, FALSE);
+ text = ret = g_string_free (string, FALSE);
}
+
g_match_info_free (match_info);
g_regex_unref (uri_regex);
- /* Replace \n by \r so it will be replaced by <br/> */
- iter = (gchar*) cur;
- for (i = 0; iter[i] != '\0'; i++) {
- if (iter[i] == '\n') {
- if (ret == NULL) {
- /* We have changes to make to the string but we
- * are still using the original one.
- * Dup it now */
- cur = iter = ret = g_strdup (cur);
+ /* Replace \n by <br/> */
+ string = NULL;
+ prev = 0;
+ for (i = 0; text[i] != '\0'; i++) {
+ if (text[i] == '\n') {
+ if (!string ) {
+ string = g_string_sized_new (strlen (text));
}
- iter[i] = '\r';
- }
+ g_string_append_len (string, text + prev, i - prev);
+ g_string_append (string, "<br/>");
+ prev = i + 1;
+ }
+ }
+ if (string) {
+ g_string_append (string, text + prev);
+ g_free (ret);
+ text = ret = g_string_free (string, FALSE);
}
- /* If we made changes to the text ret is now a newly allocated string,
- * otherwise it is NULL to indicate that the original text can be
- * used without modification */
return ret;
}
static void
-theme_adium_scroll_down (EmpathyChatView *view)
+escape_and_append_len (GString *string, const gchar *str, gint len)
{
- /* Not implemented */
+ while (*str != '\0' && len != 0) {
+ switch (*str) {
+ case '\\':
+ /* \ becomes \\ */
+ g_string_append (string, "\\\\");
+ break;
+ case '\"':
+ /* " becomes \" */
+ g_string_append (string, "\\\"");
+ break;
+ case '\n':
+ /* Remove end of lines */
+ break;
+ default:
+ g_string_append_c (string, *str);
+ }
+
+ str++;
+ len--;
+ }
+}
+
+static gboolean
+theme_adium_match (const gchar **str, const gchar *match)
+{
+ gint len;
+
+ len = strlen (match);
+ if (strncmp (*str, match, len) == 0) {
+ *str += len - 1;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void
+theme_adium_append_html (EmpathyThemeAdium *theme,
+ const gchar *func,
+ const gchar *html, gsize len,
+ const gchar *message,
+ const gchar *avatar_filename,
+ const gchar *name,
+ const gchar *contact_id,
+ const gchar *service_name,
+ const gchar *message_classes,
+ time_t timestamp)
+{
+ GString *string;
+ const gchar *cur = NULL;
+ gchar *script;
+
+ /* Make some search-and-replace in the html code */
+ string = g_string_sized_new (len + strlen (message));
+ g_string_append_printf (string, "%s(\"", func);
+ for (cur = html; *cur != '\0'; cur++) {
+ const gchar *replace = NULL;
+ gchar *dup_replace = NULL;
+
+ if (theme_adium_match (&cur, "%message%")) {
+ replace = message;
+ } else if (theme_adium_match (&cur, "%messageClasses%")) {
+ replace = message_classes;
+ } else if (theme_adium_match (&cur, "%userIconPath%")) {
+ replace = avatar_filename;
+ } else if (theme_adium_match (&cur, "%sender%")) {
+ replace = name;
+ } else if (theme_adium_match (&cur, "%senderScreenName%")) {
+ replace = contact_id;
+ } else if (theme_adium_match (&cur, "%senderDisplayName%")) {
+ /* %senderDisplayName% -
+ * "The serverside (remotely set) name of the sender,
+ * such as an MSN display name."
+ *
+ * We don't have access to that yet so we use local
+ * alias instead.*/
+ replace = name;
+ } else if (theme_adium_match (&cur, "%service%")) {
+ replace = service_name;
+ } else if (theme_adium_match (&cur, "%shortTime%")) {
+ dup_replace = empathy_time_to_string_local (timestamp,
+ EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
+ replace = dup_replace;
+ } else if (theme_adium_match (&cur, "%time")) {
+ gchar *format = NULL;
+ gchar *end;
+ /* Time can be in 2 formats:
+ * %time% or %time{strftime format}%
+ * Extract the time format if provided. */
+ if (cur[1] == '{') {
+ cur += 2;
+ end = strstr (cur, "}%");
+ if (!end) {
+ /* Invalid string */
+ continue;
+ }
+ format = g_strndup (cur, end - cur);
+ cur = end + 1;
+ } else {
+ cur++;
+ }
+
+ dup_replace = empathy_time_to_string_local (timestamp,
+ format ? format : EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
+ replace = dup_replace;
+ g_free (format);
+ } else {
+ escape_and_append_len (string, cur, 1);
+ continue;
+ }
+
+ /* Here we have a replacement to make */
+ escape_and_append_len (string, replace, -1);
+ g_free (dup_replace);
+ }
+ g_string_append (string, "\")");
+
+ script = g_string_free (string, FALSE);
+ webkit_web_view_execute_script (WEBKIT_WEB_VIEW (theme), script);
+ g_free (script);
}
-#define FOLLOW(cur, str) (!strncmp (cur, str, strlen (str)))
static void
theme_adium_append_message (EmpathyChatView *view,
EmpathyMessage *msg)
EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (view);
EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
EmpathyContact *sender;
+ EmpathyAccount *account;
gchar *dup_body = NULL;
const gchar *body;
const gchar *name;
+ const gchar *contact_id;
EmpathyAvatar *avatar;
const gchar *avatar_filename = NULL;
time_t timestamp;
- gsize len;
- GString *string;
- gchar *cur = NULL;
- gchar *prev;
- gchar *script;
- gchar *escape;
+ gchar *html = NULL;
+ gsize len = 0;
const gchar *func;
+ const gchar *service_name;
+ GString *message_classes = NULL;
+ gboolean is_backlog;
if (!priv->page_loaded) {
priv->message_queue = g_list_prepend (priv->message_queue,
/* Get information */
sender = empathy_message_get_sender (msg);
+ account = empathy_contact_get_account (sender);
+ service_name = empathy_protocol_name_to_display_name
+ (empathy_account_get_protocol (account));
+ if (service_name == NULL)
+ service_name = empathy_account_get_protocol (account);
timestamp = empathy_message_get_timestamp (msg);
body = empathy_message_get_body (msg);
dup_body = theme_adium_parse_body (theme, body);
body = dup_body;
}
name = empathy_contact_get_name (sender);
+ contact_id = empathy_contact_get_id (sender);
+
+ /* If this is a /me, append an event */
+ if (empathy_message_get_tptype (msg) == TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION) {
+ gchar *str;
+
+ str = g_strdup_printf ("%s %s", name, body);
+ empathy_chat_view_append_event (view, str);
+ g_free (str);
+ g_free (dup_body);
+ return;
+ }
+
+ /* Get the avatar filename, or a fallback */
avatar = empathy_contact_get_avatar (sender);
if (avatar) {
avatar_filename = avatar->filename;
}
if (!avatar_filename) {
- if (!priv->default_avatar_filename) {
- priv->default_avatar_filename =
- empathy_filename_from_icon_name ("stock_person",
- GTK_ICON_SIZE_DIALOG);
+ if (empathy_contact_is_user (sender)) {
+ avatar_filename = priv->data->default_outgoing_avatar_filename;
+ } else {
+ avatar_filename = priv->data->default_incoming_avatar_filename;
+ }
+ if (!avatar_filename) {
+ if (!priv->data->default_avatar_filename) {
+ priv->data->default_avatar_filename =
+ empathy_filename_from_icon_name ("stock_person",
+ GTK_ICON_SIZE_DIALOG);
+ }
+ avatar_filename = priv->data->default_avatar_filename;
}
- avatar_filename = priv->default_avatar_filename;
}
+ is_backlog = empathy_message_is_backlog (msg);
+
/* Get the right html/func to add the message */
- if (priv->last_contact &&
- empathy_contact_equal (priv->last_contact, sender)) {
- func = "appendNextMessage";
- if (empathy_contact_is_user (sender)) {
- cur = priv->out_nextcontent_html;
- len = priv->out_nextcontent_len;
- }
- if (!cur) {
- cur = priv->in_nextcontent_html;
- len = priv->in_nextcontent_len;
- }
+ func = "appendMessage";
+
+ message_classes = g_string_new ("message");
+
+ /* eventually append the "history" class */
+ if (is_backlog) {
+ g_string_append (message_classes, " history");
}
- if (!cur) {
- func = "appendMessage";
- if (empathy_contact_is_user (sender)) {
- cur = priv->out_content_html;
- len = priv->out_content_len;
- }
- if (!cur) {
- cur = priv->in_content_html;
- len = priv->in_content_len;
- }
+
+ /* check the sender of the message and append the appropriate class */
+ if (empathy_contact_is_user (sender)) {
+ g_string_append (message_classes, " outgoing");
+ }
+ else {
+ g_string_append (message_classes, " incoming");
}
- /* Make some search-and-replace in the html code */
- prev = cur;
- string = g_string_sized_new (len + strlen (body));
- while ((cur = strchr (cur, '%'))) {
- const gchar *replace = NULL;
- gchar *dup_replace = NULL;
- gchar *fin = NULL;
+ /*
+ * To mimick Adium's behavior, we only want to join messages
+ * sent by the same contact within a 5 minute time frame.
+ */
+ if (empathy_contact_equal (priv->last_contact, sender) &&
+ (timestamp - priv->last_timestamp < MESSAGE_JOIN_PERIOD) &&
+ (is_backlog == priv->last_is_backlog)) {
+ /* the messages can be appended */
+ func = "appendNextMessage";
+ g_string_append (message_classes, " consecutive");
- if (FOLLOW (cur, "%message%")) {
- replace = body;
- } else if (FOLLOW (cur, "%userIconPath%")) {
- replace = avatar_filename;
- } else if (FOLLOW (cur, "%sender%")) {
- replace = name;
- } else if (FOLLOW (cur, "%time")) {
- gchar *format = NULL;
- gchar *start;
- gchar *end;
+ /* check who is the sender of the message to use the correct html file */
+ if (empathy_contact_is_user (sender)) {
+ /* check if this is a backlog message and use NextContext.html */
+ if (is_backlog) {
+ html = priv->data->out_nextcontext_html;
+ len = priv->data->out_nextcontext_len;
+ }
- /* Extract the time format it provided. */
- if (*(start = cur + strlen("%time")) == '{') {
- start++;
- end = strstr (start, "}%");
- if (!end) /* Invalid string */
- continue;
- format = g_strndup (start, end - start);
- fin = end + 1;
- }
+ /*
+ * html is null if this is not a backlog message or
+ * if we have to fallback (NextContext.html missing).
+ * use NextContent.html
+ */
+ if (html == NULL) {
+ html = priv->data->out_nextcontent_html;
+ len = priv->data->out_nextcontent_len;
+ }
+ }
+ else {
+ if (is_backlog) {
+ html = priv->data->in_nextcontext_html;
+ len = priv->data->in_nextcontext_len;
+ }
- dup_replace = empathy_time_to_string_local (timestamp,
- format ? format : EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
- replace = dup_replace;
- g_free (format);
- } else {
- cur++;
- continue;
+ if (html == NULL) {
+ html = priv->data->in_nextcontent_html;
+ len = priv->data->in_nextcontent_len;
+ }
}
+ }
- /* Here we have a replacement to make */
- g_string_append_len (string, prev, cur - prev);
- g_string_append (string, replace);
- g_free (dup_replace);
+ /*
+ * we have html == NULL here if:
+ * 1. the message didn't have to be appended because
+ * the sender was different or the timestamp was too far
+ * 2. NextContent.html file does not exist, so we must
+ * not forget to fallback to the correct Content.html
+ */
+ if (html == NULL) {
+ if (empathy_contact_is_user (sender)) {
+ if (is_backlog) {
+ html = priv->data->out_context_html;
+ len = priv->data->out_context_len;
+ }
- /* And update the pointers */
- if (fin) {
- prev = cur = fin + 1;
- } else {
- prev = cur = strchr (cur + 1, '%') + 1;
+ if (html == NULL) {
+ html = priv->data->out_content_html;
+ len = priv->data->out_content_len;
+ }
+ }
+ else {
+ if (is_backlog) {
+ html = priv->data->in_context_html;
+ len = priv->data->in_context_len;
+ }
+
+ if (html == NULL) {
+ html = priv->data->in_content_html;
+ len = priv->data->in_content_len;
+ }
}
}
- g_string_append (string, prev);
- /* Execute a js to add the message */
- cur = g_string_free (string, FALSE);
- escape = theme_adium_escape_script (cur);
- script = g_strdup_printf("%s(\"%s\")", func, escape);
- webkit_web_view_execute_script (WEBKIT_WEB_VIEW (view), script);
+ theme_adium_append_html (theme, func, html, len, body, avatar_filename,
+ name, contact_id, service_name, message_classes->str,
+ timestamp);
/* Keep the sender of the last displayed message */
if (priv->last_contact) {
g_object_unref (priv->last_contact);
}
priv->last_contact = g_object_ref (sender);
+ priv->last_timestamp = timestamp;
+ priv->last_is_backlog = is_backlog;
g_free (dup_body);
- g_free (cur);
- g_free (script);
+ g_string_free (message_classes, TRUE);
}
-#undef FOLLOW
static void
theme_adium_append_event (EmpathyChatView *view,
const gchar *str)
{
- /* Not implemented */
+ EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (view);
+ EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
+
+ if (priv->data->status_html) {
+ theme_adium_append_html (theme, "appendMessage",
+ priv->data->status_html,
+ priv->data->status_len,
+ str, NULL, NULL, NULL, NULL, "event",
+ empathy_time_get_current ());
+ }
+
+ /* There is no last contact */
+ if (priv->last_contact) {
+ g_object_unref (priv->last_contact);
+ priv->last_contact = NULL;
+ }
}
static void
theme_adium_scroll (EmpathyChatView *view,
gboolean allow_scrolling)
{
- /* Not implemented */
+ /* FIXME: Is it possible? I guess we need a js function, but I don't
+ * see any... */
+}
+
+static void
+theme_adium_scroll_down (EmpathyChatView *view)
+{
+ webkit_web_view_execute_script (WEBKIT_WEB_VIEW (view), "scrollToBottom()");
}
static gboolean
theme_adium_get_has_selection (EmpathyChatView *view)
{
- /* Not implemented */
- return FALSE;
+ return webkit_web_view_has_selection (WEBKIT_WEB_VIEW (view));
}
static void
theme_adium_clear (EmpathyChatView *view)
{
- /* Not implemented */
+ EmpathyThemeAdiumPriv *priv = GET_PRIV (view);
+ gchar *basedir_uri;
+
+ priv->page_loaded = FALSE;
+ basedir_uri = g_strconcat ("file://", priv->data->basedir, NULL);
+ webkit_web_view_load_html_string (WEBKIT_WEB_VIEW (view),
+ priv->data->template_html,
+ basedir_uri);
+ g_free (basedir_uri);
+
+ /* Clear last contact to avoid trying to add a 'joined'
+ * message when we don't have an insertion point. */
+ if (priv->last_contact) {
+ g_object_unref (priv->last_contact);
+ priv->last_contact = NULL;
+ }
}
static gboolean
const gchar *search_criteria,
gboolean new_search)
{
- /* Not implemented */
- return FALSE;
+ return webkit_web_view_search_text (WEBKIT_WEB_VIEW (view),
+ search_criteria, FALSE,
+ FALSE, TRUE);
}
static gboolean
const gchar *search_criteria,
gboolean new_search)
{
- /* Not implemented */
- return FALSE;
+ return webkit_web_view_search_text (WEBKIT_WEB_VIEW (view),
+ search_criteria, FALSE,
+ TRUE, TRUE);
}
static void
gboolean *can_do_previous,
gboolean *can_do_next)
{
- /* Not implemented */
+ /* FIXME: Does webkit provide an API for that? We have wrap=true in
+ * find_next and find_previous to work around this problem. */
+ if (can_do_previous)
+ *can_do_previous = TRUE;
+ if (can_do_next)
+ *can_do_next = TRUE;
}
static void
theme_adium_highlight (EmpathyChatView *view,
const gchar *text)
{
- /* Not implemented */
+ webkit_web_view_unmark_text_matches (WEBKIT_WEB_VIEW (view));
+ webkit_web_view_mark_text_matches (WEBKIT_WEB_VIEW (view),
+ text, FALSE, 0);
+ webkit_web_view_set_highlight_text_matches (WEBKIT_WEB_VIEW (view),
+ TRUE);
}
static void
theme_adium_copy_clipboard (EmpathyChatView *view)
{
- /* Not implemented */
+ webkit_web_view_copy_clipboard (WEBKIT_WEB_VIEW (view));
}
static void
{
EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
- g_free (priv->in_content_html);
- g_free (priv->in_nextcontent_html);
- g_free (priv->out_content_html);
- g_free (priv->out_nextcontent_html);
- g_free (priv->default_avatar_filename);
- g_free (priv->path);
- g_object_unref (priv->smiley_manager);
+ empathy_adium_data_unref (priv->data);
+ g_free (priv->hovered_uri);
+
+ empathy_conf_notify_remove (empathy_conf_get (),
+ priv->notify_enable_webkit_developer_tools_id);
+
+ G_OBJECT_CLASS (empathy_theme_adium_parent_class)->finalize (object);
+}
+
+static void
+theme_adium_dispose (GObject *object)
+{
+ EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
+
+ if (priv->smiley_manager) {
+ g_object_unref (priv->smiley_manager);
+ priv->smiley_manager = NULL;
+ }
if (priv->last_contact) {
g_object_unref (priv->last_contact);
+ priv->last_contact = NULL;
}
- G_OBJECT_CLASS (empathy_theme_adium_parent_class)->finalize (object);
+ if (priv->inspector_window) {
+ gtk_widget_destroy (priv->inspector_window);
+ priv->inspector_window = NULL;
+ }
+
+ G_OBJECT_CLASS (empathy_theme_adium_parent_class)->dispose (object);
+}
+
+static gboolean
+theme_adium_inspector_show_window_cb (WebKitWebInspector *inspector,
+ EmpathyThemeAdium *theme)
+{
+ EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
+
+ if (priv->inspector_window) {
+ gtk_widget_show_all (priv->inspector_window);
+ }
+
+ return TRUE;
+}
+
+static gboolean
+theme_adium_inspector_close_window_cb (WebKitWebInspector *inspector,
+ EmpathyThemeAdium *theme)
+{
+ EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
+
+ if (priv->inspector_window) {
+ gtk_widget_hide (priv->inspector_window);
+ }
+
+ return TRUE;
+}
+
+static WebKitWebView *
+theme_adium_inspect_web_view_cb (WebKitWebInspector *inspector,
+ WebKitWebView *web_view,
+ EmpathyThemeAdium *theme)
+{
+ EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
+ GtkWidget *scrolled_window;
+ GtkWidget *inspector_web_view;
+
+ if (!priv->inspector_window) {
+ /* Create main window */
+ priv->inspector_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_default_size (GTK_WINDOW (priv->inspector_window),
+ 800, 600);
+ g_signal_connect (priv->inspector_window, "delete-event",
+ G_CALLBACK (gtk_widget_hide_on_delete), NULL);
+
+ /* Pack a scrolled window */
+ scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ gtk_container_add (GTK_CONTAINER (priv->inspector_window),
+ scrolled_window);
+ gtk_widget_show (scrolled_window);
+
+ /* Pack a webview in the scrolled window. That webview will be
+ * used to render the inspector tool. */
+ inspector_web_view = webkit_web_view_new ();
+ gtk_container_add (GTK_CONTAINER (scrolled_window),
+ inspector_web_view);
+ gtk_widget_show (scrolled_window);
+
+ return WEBKIT_WEB_VIEW (inspector_web_view);
+ }
+
+ return NULL;
}
static void
theme_adium_constructed (GObject *object)
{
- theme_adium_load (EMPATHY_THEME_ADIUM (object));
+ EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
+ gchar *basedir_uri;
+ const gchar *font_family = NULL;
+ gint font_size = 0;
+ WebKitWebView *webkit_view = WEBKIT_WEB_VIEW (object);
+ WebKitWebSettings *webkit_settings;
+ WebKitWebInspector *webkit_inspector;
+
+ /* Set default settings */
+ font_family = tp_asv_get_string (priv->data->info, "DefaultFontFamily");
+ font_size = tp_asv_get_int32 (priv->data->info, "DefaultFontSize", NULL);
+ webkit_settings = webkit_web_view_get_settings (webkit_view);
+ if (font_family) {
+ g_object_set (webkit_settings,
+ "default-font-family", font_family,
+ NULL);
+ }
+ if (font_size) {
+ g_object_set (webkit_settings,
+ "default-font-size", font_size,
+ NULL);
+ }
+
+ /* Setup webkit inspector */
+ webkit_inspector = webkit_web_view_get_inspector (webkit_view);
+ g_signal_connect (webkit_inspector, "inspect-web-view",
+ G_CALLBACK (theme_adium_inspect_web_view_cb),
+ object);
+ g_signal_connect (webkit_inspector, "show-window",
+ G_CALLBACK (theme_adium_inspector_show_window_cb),
+ object);
+ g_signal_connect (webkit_inspector, "close-window",
+ G_CALLBACK (theme_adium_inspector_close_window_cb),
+ object);
+
+ /* Load template */
+ basedir_uri = g_strconcat ("file://", priv->data->basedir, NULL);
+ webkit_web_view_load_html_string (WEBKIT_WEB_VIEW (object),
+ priv->data->template_html,
+ basedir_uri);
+ g_free (basedir_uri);
}
static void
EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
switch (param_id) {
- case PROP_PATH:
- g_value_set_string (value, priv->path);
+ case PROP_ADIUM_DATA:
+ g_value_set_boxed (value, priv->data);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
switch (param_id) {
- case PROP_PATH:
- g_free (priv->path);
- priv->path = g_value_dup_string (value);
+ case PROP_ADIUM_DATA:
+ g_assert (priv->data == NULL);
+ priv->data = g_value_dup_boxed (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
empathy_theme_adium_class_init (EmpathyThemeAdiumClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
+
object_class->finalize = theme_adium_finalize;
+ object_class->dispose = theme_adium_dispose;
object_class->constructed = theme_adium_constructed;
object_class->get_property = theme_adium_get_property;
object_class->set_property = theme_adium_set_property;
g_object_class_install_property (object_class,
- PROP_PATH,
- g_param_spec_string ("path",
- "The theme path",
- "Path to the adium theme",
- g_get_home_dir (),
+ PROP_ADIUM_DATA,
+ g_param_spec_boxed ("adium-data",
+ "The theme data",
+ "Data for the adium theme",
+ EMPATHY_TYPE_ADIUM_DATA,
G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_READWRITE));
-
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
g_type_class_add_private (object_class, sizeof (EmpathyThemeAdiumPriv));
}
EmpathyThemeAdiumPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (theme,
EMPATHY_TYPE_THEME_ADIUM, EmpathyThemeAdiumPriv);
- theme->priv = priv;
+ theme->priv = priv;
- priv->smiley_manager = empathy_smiley_manager_new ();
+ priv->smiley_manager = empathy_smiley_manager_dup_singleton ();
g_signal_connect (theme, "load-finished",
G_CALLBACK (theme_adium_load_finished_cb),
NULL);
- g_signal_connect (theme, "navigation-requested",
- G_CALLBACK (theme_adium_navigation_requested_cb),
+ g_signal_connect (theme, "navigation-policy-decision-requested",
+ G_CALLBACK (theme_adium_navigation_policy_decision_requested_cb),
+ NULL);
+ g_signal_connect (theme, "populate-popup",
+ G_CALLBACK (theme_adium_populate_popup_cb),
NULL);
+ g_signal_connect (theme, "hovering-over-link",
+ G_CALLBACK (theme_adium_hovering_over_link_cb),
+ NULL);
+
+ priv->notify_enable_webkit_developer_tools_id =
+ empathy_conf_notify_add (empathy_conf_get (),
+ EMPATHY_PREFS_CHAT_WEBKIT_DEVELOPER_TOOLS,
+ theme_adium_notify_enable_webkit_developer_tools_cb,
+ theme);
+
+ theme_adium_update_enable_webkit_developer_tools (theme);
}
EmpathyThemeAdium *
-empathy_theme_adium_new (const gchar *path)
+empathy_theme_adium_new (EmpathyAdiumData *data)
{
- g_return_val_if_fail (empathy_theme_adium_is_valid (path), NULL);
+ g_return_val_if_fail (data != NULL, NULL);
return g_object_new (EMPATHY_TYPE_THEME_ADIUM,
- "path", path,
+ "adium-data", data,
NULL);
}
gboolean
-empathy_theme_adium_is_valid (const gchar *path)
+empathy_adium_path_is_valid (const gchar *path)
{
gboolean ret;
gchar *file;
+ /* The theme is not valid if there is no Info.plist */
+ file = g_build_filename (path, "Contents", "Info.plist",
+ NULL);
+ ret = g_file_test (file, G_FILE_TEST_EXISTS);
+ g_free (file);
+
+ if (ret == FALSE)
+ return ret;
+
/* We ship a default Template.html as fallback if there is any problem
* with the one inside the theme. The only other required file is
* Content.html for incoming messages (outgoing fallback to use
return ret;
}
+GHashTable *
+empathy_adium_info_new (const gchar *path)
+{
+ gchar *file;
+ GValue *value;
+ GHashTable *info = NULL;
+
+ g_return_val_if_fail (empathy_adium_path_is_valid (path), NULL);
+
+ file = g_build_filename (path, "Contents", "Info.plist", NULL);
+ value = empathy_plist_parse_from_file (file);
+ g_free (file);
+
+ if (value == NULL)
+ return NULL;
+
+ info = g_value_dup_boxed (value);
+ tp_g_value_slice_free (value);
+
+ /* Insert the theme's path into the hash table,
+ * keys have to be dupped */
+ tp_asv_set_string (info, g_strdup ("path"), path);
+
+ return info;
+}
+
+GType
+empathy_adium_data_get_type (void)
+{
+ static GType type_id = 0;
+
+ if (!type_id)
+ {
+ type_id = g_boxed_type_register_static ("EmpathyAdiumData",
+ (GBoxedCopyFunc) empathy_adium_data_ref,
+ (GBoxedFreeFunc) empathy_adium_data_unref);
+ }
+
+ return type_id;
+}
+
+EmpathyAdiumData *
+empathy_adium_data_new_with_info (const gchar *path, GHashTable *info)
+{
+ EmpathyAdiumData *data;
+ gchar *file;
+ gchar *template_html = NULL;
+ gsize template_len;
+ gchar *footer_html = NULL;
+ gsize footer_len;
+ GString *string;
+ gchar **strv = NULL;
+ gchar *css_path;
+ guint len = 0;
+ guint i = 0;
+
+ g_return_val_if_fail (empathy_adium_path_is_valid (path), NULL);
+
+ data = g_slice_new0 (EmpathyAdiumData);
+ data->ref_count = 1;
+ data->path = g_strdup (path);
+ data->basedir = g_strconcat (path, G_DIR_SEPARATOR_S "Contents"
+ G_DIR_SEPARATOR_S "Resources" G_DIR_SEPARATOR_S, NULL);
+ data->info = g_hash_table_ref (info);
+
+ /* Load html files */
+ file = g_build_filename (data->basedir, "Incoming", "Content.html", NULL);
+ g_file_get_contents (file, &data->in_content_html, &data->in_content_len, NULL);
+ g_free (file);
+
+ file = g_build_filename (data->basedir, "Incoming", "NextContent.html", NULL);
+ g_file_get_contents (file, &data->in_nextcontent_html, &data->in_nextcontent_len, NULL);
+ g_free (file);
+
+ file = g_build_filename (data->basedir, "Incoming", "Context.html", NULL);
+ g_file_get_contents (file, &data->in_context_html, &data->in_context_len, NULL);
+ g_free (file);
+
+ file = g_build_filename (data->basedir, "Incoming", "NextContext.html", NULL);
+ g_file_get_contents (file, &data->in_nextcontext_html, &data->in_nextcontext_len, NULL);
+ g_free (file);
+
+ file = g_build_filename (data->basedir, "Outgoing", "Content.html", NULL);
+ g_file_get_contents (file, &data->out_content_html, &data->out_content_len, NULL);
+ g_free (file);
+
+ file = g_build_filename (data->basedir, "Outgoing", "NextContent.html", NULL);
+ g_file_get_contents (file, &data->out_nextcontent_html, &data->out_nextcontent_len, NULL);
+ g_free (file);
+
+ file = g_build_filename (data->basedir, "Outgoing", "Context.html", NULL);
+ g_file_get_contents (file, &data->out_context_html, &data->out_context_len, NULL);
+ g_free (file);
+
+ file = g_build_filename (data->basedir, "Outgoing", "NextContext.html", NULL);
+ g_file_get_contents (file, &data->out_nextcontext_html, &data->out_nextcontext_len, NULL);
+ g_free (file);
+
+ file = g_build_filename (data->basedir, "Status.html", NULL);
+ g_file_get_contents (file, &data->status_html, &data->status_len, NULL);
+ g_free (file);
+
+ file = g_build_filename (data->basedir, "Footer.html", NULL);
+ g_file_get_contents (file, &footer_html, &footer_len, NULL);
+ g_free (file);
+
+ file = g_build_filename (data->basedir, "Incoming", "buddy_icon.png", NULL);
+ if (g_file_test (file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
+ data->default_incoming_avatar_filename = file;
+ } else {
+ g_free (file);
+ }
+
+ file = g_build_filename (data->basedir, "Outgoing", "buddy_icon.png", NULL);
+ if (g_file_test (file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
+ data->default_outgoing_avatar_filename = file;
+ } else {
+ g_free (file);
+ }
+
+ css_path = g_build_filename (data->basedir, "main.css", NULL);
+
+ /* There is 2 formats for Template.html: The old one has 4 parameters,
+ * the new one has 5 parameters. */
+ file = g_build_filename (data->basedir, "Template.html", NULL);
+ if (g_file_get_contents (file, &template_html, &template_len, NULL)) {
+ strv = g_strsplit (template_html, "%@", -1);
+ len = g_strv_length (strv);
+ }
+ g_free (file);
+
+ if (len != 5 && len != 6) {
+ /* Either the theme has no template or it don't have the good
+ * number of parameters. Fallback to use our own template. */
+ g_free (template_html);
+ g_strfreev (strv);
+
+ file = empathy_file_lookup ("Template.html", "data");
+ g_file_get_contents (file, &template_html, &template_len, NULL);
+ g_free (file);
+ strv = g_strsplit (template_html, "%@", -1);
+ len = g_strv_length (strv);
+ }
+
+ /* Replace %@ with the needed information in the template html. */
+ string = g_string_sized_new (template_len);
+ g_string_append (string, strv[i++]);
+ g_string_append (string, data->basedir);
+ g_string_append (string, strv[i++]);
+ if (len == 6) {
+ const gchar *variant;
+
+ /* We include main.css by default */
+ g_string_append_printf (string, "@import url(\"%s\");", css_path);
+ g_string_append (string, strv[i++]);
+ variant = tp_asv_get_string (data->info, "DefaultVariant");
+ if (variant) {
+ g_string_append (string, "Variants/");
+ g_string_append (string, variant);
+ g_string_append (string, ".css");
+ }
+ } else {
+ /* FIXME: We should set main.css OR the variant css */
+ g_string_append (string, css_path);
+ }
+ g_string_append (string, strv[i++]);
+ g_string_append (string, ""); /* We don't want header */
+ g_string_append (string, strv[i++]);
+ /* FIXME: We should replace adium %macros% in footer */
+ if (footer_html) {
+ g_string_append (string, footer_html);
+ }
+ g_string_append (string, strv[i++]);
+ data->template_html = g_string_free (string, FALSE);
+
+ g_free (footer_html);
+ g_free (template_html);
+ g_free (css_path);
+ g_strfreev (strv);
+
+ return data;
+}
+
+EmpathyAdiumData *
+empathy_adium_data_new (const gchar *path)
+{
+ EmpathyAdiumData *data;
+ GHashTable *info;
+
+ info = empathy_adium_info_new (path);
+ data = empathy_adium_data_new_with_info (path, info);
+ g_hash_table_unref (info);
+
+ return data;
+}
+
+EmpathyAdiumData *
+empathy_adium_data_ref (EmpathyAdiumData *data)
+{
+ g_return_val_if_fail (data != NULL, NULL);
+
+ g_atomic_int_inc (&data->ref_count);
+
+ return data;
+}
+
+void
+empathy_adium_data_unref (EmpathyAdiumData *data)
+{
+ g_return_if_fail (data != NULL);
+
+ if (g_atomic_int_dec_and_test (&data->ref_count)) {
+ g_free (data->path);
+ g_free (data->basedir);
+ g_free (data->template_html);
+ g_free (data->in_content_html);
+ g_free (data->in_nextcontent_html);
+ g_free (data->in_context_html);
+ g_free (data->in_nextcontext_html);
+ g_free (data->out_content_html);
+ g_free (data->out_nextcontent_html);
+ g_free (data->out_context_html);
+ g_free (data->out_nextcontext_html);
+ g_free (data->default_avatar_filename);
+ g_free (data->default_incoming_avatar_filename);
+ g_free (data->default_outgoing_avatar_filename);
+ g_free (data->status_html);
+ g_hash_table_unref (data->info);
+ g_slice_free (EmpathyAdiumData, data);
+ }
+}
+
+GHashTable *
+empathy_adium_data_get_info (EmpathyAdiumData *data)
+{
+ g_return_val_if_fail (data != NULL, NULL);
+
+ return data->info;
+}
+
+const gchar *
+empathy_adium_data_get_path (EmpathyAdiumData *data)
+{
+ g_return_val_if_fail (data != NULL, NULL);
+
+ return data->path;
+}
+