EmpathyContact *last_contact;
gboolean ready;
GList *message_queue;
+ gchar *default_avatar_filename;
} EmpathyThemeAdiumPriv;
static void theme_adium_iface_init (EmpathyChatViewIface *iface);
}
static gchar *
-theme_adium_escape (EmpathyThemeAdium *theme,
- const gchar *text)
+theme_adium_escape_script (const gchar *text)
{
const gchar *cur = text;
GString *string;
return g_string_free (string, FALSE);
}
+static gchar *
+theme_adium_escape_body (const gchar *body)
+{
+ gchar *ret, *iter;
+
+ /* Replace \n by \r so it will be replaced by <br/> */
+ ret = g_strdup (body);
+ for (iter = ret; *iter != '\0'; iter++) {
+ if (*iter == '\n') {
+ *iter = '\r';
+ }
+ }
+
+ return ret;
+}
+
+static const gchar *
+theme_adium_get_default_avatar_filename (EmpathyThemeAdium *theme)
+{
+ EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
+ GtkIconTheme *icon_theme;
+ GtkIconInfo *icon_info;
+ gint w, h;
+ gint size = 48;
+
+ /* Lazy initialization */
+ if (priv->default_avatar_filename) {
+ return priv->default_avatar_filename;
+ }
+
+ icon_theme = gtk_icon_theme_get_default ();
+
+ if (gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, &w, &h)) {
+ size = (w + h) / 2;
+ }
+
+ icon_info = gtk_icon_theme_lookup_icon (icon_theme, "stock_person", size, 0);
+ priv->default_avatar_filename = g_strdup (gtk_icon_info_get_filename (icon_info));
+ gtk_icon_info_free (icon_info);
+
+ return priv->default_avatar_filename;
+}
+
static void
theme_adium_scroll_down (EmpathyChatView *view)
{
/* Not implemented */
}
-#define FOLLOW(str) (!strncmp (cur, str, strlen (str)))
+#define FOLLOW(cur, str) (!strncmp (cur, str, strlen (str)))
static void
theme_adium_append_message (EmpathyChatView *view,
EmpathyMessage *msg)
{
- EmpathyThemeAdiumPriv *priv = GET_PRIV (view);
+ EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (view);
+ EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
EmpathyContact *sender;
- const gchar *body;
+ gchar *body;
const gchar *name;
- gchar *avatar;
+ EmpathyAvatar *avatar;
+ const gchar *avatar_filename = NULL;
time_t timestamp;
gsize len;
GString *string;
/* Get information */
sender = empathy_message_get_sender (msg);
- body = empathy_message_get_body (msg);
- name = empathy_contact_get_name (sender);
- avatar = empathy_contact_get_avatar_filename (sender);
timestamp = empathy_message_get_timestamp (msg);
-
- if (!avatar) {
- /* FIXME: We should give a default icon of a buddy */
- avatar = g_strdup ("FIXME");
+ body = theme_adium_escape_body (empathy_message_get_body (msg));
+ name = empathy_contact_get_name (sender);
+ avatar = empathy_contact_get_avatar (sender);
+ if (avatar) {
+ avatar_filename = avatar->filename;
+ }
+ if (!avatar_filename) {
+ avatar_filename = theme_adium_get_default_avatar_filename (theme);
}
+g_print ("%s\n", priv->default_avatar_filename);
+
+
/* Get the right html/func to add the message */
if (priv->last_contact &&
empathy_contact_equal (priv->last_contact, sender)) {
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;
format ? format : EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
replace = dup_replace;
g_free (format);
- } else if (FOLLOW (cur, "%userIconPath%")) {
- replace = avatar;
- } else if (FOLLOW (cur, "%sender%")) {
- replace = name;
} else {
cur++;
continue;
/* Execute a js to add the message */
cur = g_string_free (string, FALSE);
- escape = theme_adium_escape (EMPATHY_THEME_ADIUM (view), cur);
+ escape = theme_adium_escape_script (cur);
script = g_strdup_printf("%s(\"%s\")", func, escape);
webkit_web_view_execute_script (WEBKIT_WEB_VIEW (view), script);
}
priv->last_contact = g_object_ref (sender);
- g_free (avatar);
+ g_free (body);
g_free (cur);
g_free (script);
}
g_free (priv->in_nextcontent_html);
g_free (priv->out_content_html);
g_free (priv->out_nextcontent_html);
+ g_free (priv->default_avatar_filename);
if (priv->last_contact) {
g_object_unref (priv->last_contact);
void
empathy_contact_load_avatar_data (EmpathyContact *contact,
- const guchar *data,
+ const guchar *data,
const gsize len,
const gchar *format,
const gchar *token)
g_return_if_fail (!EMP_STR_EMPTY (token));
/* Load and set the avatar */
+ filename = contact_get_avatar_filename (contact, token);
avatar = empathy_avatar_new (g_memdup (data, len), len, g_strdup (format),
- g_strdup (token));
+ g_strdup (token), filename);
empathy_contact_set_avatar (contact, avatar);
empathy_avatar_unref (avatar);
/* Save to cache if not yet in it */
- filename = contact_get_avatar_filename (contact, token);
if (filename && !g_file_test (filename, G_FILE_TEST_EXISTS))
{
if (!empathy_avatar_save_to_file (avatar, filename, &error))
else
DEBUG ("Avatar saved to %s", filename);
}
- g_free (filename);
}
gboolean
if (data)
{
DEBUG ("Avatar loaded from %s", filename);
- avatar = empathy_avatar_new (data, len, NULL, g_strdup (token));
+ avatar = empathy_avatar_new (data, len, NULL, g_strdup (token), filename);
empathy_contact_set_avatar (contact, avatar);
empathy_avatar_unref (avatar);
}
- g_free (filename);
-
return data != NULL;
}
-gchar *
-empathy_contact_get_avatar_filename (EmpathyContact *contact)
-{
- EmpathyContactPriv *priv = GET_PRIV (contact);
-
- if (priv->avatar)
- return contact_get_avatar_filename (contact, priv->avatar->token);
-
- return NULL;
-}
-
-
GType
empathy_avatar_get_type (void)
{
empathy_avatar_new (guchar *data,
gsize len,
gchar *format,
- gchar *token)
+ gchar *token,
+ gchar *filename)
{
EmpathyAvatar *avatar;
avatar->len = len;
avatar->format = format;
avatar->token = token;
+ avatar->filename = filename;
avatar->refcount = 1;
return avatar;