aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@gmail.com>2008-07-17 02:05:08 +0800
committerXavier Claessens <xclaesse@gmail.com>2009-06-12 00:06:28 +0800
commitc9b74c0e4891a12133aab46312b6038c3a2d0047 (patch)
tree8c258e236a86d34eff9746beec398f9ae29ce3b4
parent250c6aaadcfd00470f670bc6bf4b1098c1640179 (diff)
downloadgsoc2013-empathy-c9b74c0e4891a12133aab46312b6038c3a2d0047.tar
gsoc2013-empathy-c9b74c0e4891a12133aab46312b6038c3a2d0047.tar.gz
gsoc2013-empathy-c9b74c0e4891a12133aab46312b6038c3a2d0047.tar.bz2
gsoc2013-empathy-c9b74c0e4891a12133aab46312b6038c3a2d0047.tar.lz
gsoc2013-empathy-c9b74c0e4891a12133aab46312b6038c3a2d0047.tar.xz
gsoc2013-empathy-c9b74c0e4891a12133aab46312b6038c3a2d0047.tar.zst
gsoc2013-empathy-c9b74c0e4891a12133aab46312b6038c3a2d0047.zip
Add the filename in EmpathyAvatar and fallback to stock_person
-rw-r--r--libempathy-gtk/empathy-avatar-chooser.c4
-rw-r--r--libempathy-gtk/empathy-theme-adium.c88
-rw-r--r--libempathy/empathy-contact.c27
-rw-r--r--libempathy/empathy-contact.h5
4 files changed, 81 insertions, 43 deletions
diff --git a/libempathy-gtk/empathy-avatar-chooser.c b/libempathy-gtk/empathy-avatar-chooser.c
index 0f4311e07..8c005a029 100644
--- a/libempathy-gtk/empathy-avatar-chooser.c
+++ b/libempathy-gtk/empathy-avatar-chooser.c
@@ -555,7 +555,7 @@ avatar_chooser_maybe_convert_and_scale (EmpathyAvatarChooser *chooser,
/* Takes ownership of new_mime_type and converted_image_data */
avatar = empathy_avatar_new (converted_image_data,
- converted_image_size, new_mime_type, NULL);
+ converted_image_size, new_mime_type, NULL, NULL);
return avatar;
}
@@ -598,7 +598,7 @@ avatar_chooser_set_image_from_data (EmpathyAvatarChooser *chooser,
}
/* avatar takes ownership of data and mime_type */
- avatar = empathy_avatar_new (data, size, mime_type, NULL);
+ avatar = empathy_avatar_new (data, size, mime_type, NULL, NULL);
avatar_chooser_set_image (chooser, avatar, pixbuf, set_locally);
}
diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c
index 3da260714..e1cdc39a2 100644
--- a/libempathy-gtk/empathy-theme-adium.c
+++ b/libempathy-gtk/empathy-theme-adium.c
@@ -44,6 +44,7 @@ typedef struct {
EmpathyContact *last_contact;
gboolean ready;
GList *message_queue;
+ gchar *default_avatar_filename;
} EmpathyThemeAdiumPriv;
static void theme_adium_iface_init (EmpathyChatViewIface *iface);
@@ -118,8 +119,7 @@ theme_adium_load (EmpathyThemeAdium *theme)
}
static gchar *
-theme_adium_escape (EmpathyThemeAdium *theme,
- const gchar *text)
+theme_adium_escape_script (const gchar *text)
{
const gchar *cur = text;
GString *string;
@@ -147,22 +147,67 @@ theme_adium_escape (EmpathyThemeAdium *theme,
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;
@@ -180,16 +225,20 @@ theme_adium_append_message (EmpathyChatView *view,
/* 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)) {
@@ -222,6 +271,10 @@ theme_adium_append_message (EmpathyChatView *view,
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;
@@ -241,10 +294,6 @@ theme_adium_append_message (EmpathyChatView *view,
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;
@@ -266,7 +315,7 @@ theme_adium_append_message (EmpathyChatView *view,
/* 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);
@@ -276,7 +325,7 @@ theme_adium_append_message (EmpathyChatView *view,
}
priv->last_contact = g_object_ref (sender);
- g_free (avatar);
+ g_free (body);
g_free (cur);
g_free (script);
}
@@ -396,6 +445,7 @@ theme_adium_finalize (GObject *object)
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);
diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c
index 6800c8e30..a99e66b13 100644
--- a/libempathy/empathy-contact.c
+++ b/libempathy/empathy-contact.c
@@ -863,7 +863,7 @@ contact_get_avatar_filename (EmpathyContact *contact,
void
empathy_contact_load_avatar_data (EmpathyContact *contact,
- const guchar *data,
+ const guchar *data,
const gsize len,
const gchar *format,
const gchar *token)
@@ -879,13 +879,13 @@ empathy_contact_load_avatar_data (EmpathyContact *contact,
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))
@@ -897,7 +897,6 @@ empathy_contact_load_avatar_data (EmpathyContact *contact,
else
DEBUG ("Avatar saved to %s", filename);
}
- g_free (filename);
}
gboolean
@@ -928,28 +927,14 @@ empathy_contact_load_avatar_cache (EmpathyContact *contact,
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)
{
@@ -969,7 +954,8 @@ EmpathyAvatar *
empathy_avatar_new (guchar *data,
gsize len,
gchar *format,
- gchar *token)
+ gchar *token,
+ gchar *filename)
{
EmpathyAvatar *avatar;
@@ -978,6 +964,7 @@ empathy_avatar_new (guchar *data,
avatar->len = len;
avatar->format = format;
avatar->token = token;
+ avatar->filename = filename;
avatar->refcount = 1;
return avatar;
diff --git a/libempathy/empathy-contact.h b/libempathy/empathy-contact.h
index 0d02dabc2..f4418768e 100644
--- a/libempathy/empathy-contact.h
+++ b/libempathy/empathy-contact.h
@@ -55,6 +55,7 @@ typedef struct {
gsize len;
gchar *format;
gchar *token;
+ gchar *filename;
guint refcount;
} EmpathyAvatar;
@@ -107,7 +108,6 @@ void empathy_contact_load_avatar_data (EmpathyContact *contact,
const gchar *token);
gboolean empathy_contact_load_avatar_cache (EmpathyContact *contact,
const gchar *token);
-gchar * empathy_contact_get_avatar_filename (EmpathyContact *contact);
#define EMPATHY_TYPE_AVATAR (empathy_avatar_get_type ())
@@ -115,7 +115,8 @@ GType empathy_avatar_get_type (void) G_GNUC_CONST;
EmpathyAvatar * empathy_avatar_new (guchar *data,
gsize len,
gchar *format,
- gchar *token);
+ gchar *token,
+ gchar *filename);
EmpathyAvatar * empathy_avatar_ref (EmpathyAvatar *avatar);
void empathy_avatar_unref (EmpathyAvatar *avatar);