aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk/empathy-theme-adium.c
diff options
context:
space:
mode:
authorNicolò Chieffo <84yelo3@gmail.com>2009-07-08 23:39:17 +0800
committerXavier Claessens <xclaesse@gmail.com>2009-07-08 23:39:17 +0800
commitee5227403193fe7b5dae7d5c15e33d8a9c385c3f (patch)
tree16aa2e8ba09c4f780a94307a486ae1b28a02ea33 /libempathy-gtk/empathy-theme-adium.c
parentaff75bcc97abac0173dfd4cc6f9a959fbd493ae6 (diff)
downloadgsoc2013-empathy-ee5227403193fe7b5dae7d5c15e33d8a9c385c3f.tar
gsoc2013-empathy-ee5227403193fe7b5dae7d5c15e33d8a9c385c3f.tar.gz
gsoc2013-empathy-ee5227403193fe7b5dae7d5c15e33d8a9c385c3f.tar.bz2
gsoc2013-empathy-ee5227403193fe7b5dae7d5c15e33d8a9c385c3f.tar.lz
gsoc2013-empathy-ee5227403193fe7b5dae7d5c15e33d8a9c385c3f.tar.xz
gsoc2013-empathy-ee5227403193fe7b5dae7d5c15e33d8a9c385c3f.tar.zst
gsoc2013-empathy-ee5227403193fe7b5dae7d5c15e33d8a9c385c3f.zip
Support for history message in Adium themes. Use context HTMLs.
Diffstat (limited to 'libempathy-gtk/empathy-theme-adium.c')
-rw-r--r--libempathy-gtk/empathy-theme-adium.c131
1 files changed, 110 insertions, 21 deletions
diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c
index f37c98841..d513c91ae 100644
--- a/libempathy-gtk/empathy-theme-adium.c
+++ b/libempathy-gtk/empathy-theme-adium.c
@@ -52,6 +52,7 @@ typedef struct {
EmpathySmileyManager *smiley_manager;
EmpathyContact *last_contact;
time_t last_timestamp;
+ gboolean last_is_backlog;
gboolean page_loaded;
GList *message_queue;
} EmpathyThemeAdiumPriv;
@@ -66,12 +67,20 @@ struct _EmpathyAdiumData {
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;
@@ -405,7 +414,8 @@ theme_adium_append_message (EmpathyChatView *view,
gsize len = 0;
const gchar *func;
const gchar *service_name;
- const gchar *message_classes = NULL;
+ GString *message_classes = NULL;
+ gboolean is_backlog;
if (!priv->page_loaded) {
priv->message_queue = g_list_prepend (priv->message_queue,
@@ -458,46 +468,103 @@ theme_adium_append_message (EmpathyChatView *view,
avatar_filename = priv->data->default_avatar_filename;
}
}
+
+ is_backlog = empathy_message_is_backlog (msg);
/* Get the right html/func to add the message */
func = "appendMessage";
+
+ message_classes = g_string_new ("message");
+
+ /* eventually append the "history" class */
+ if (is_backlog) {
+ g_string_append (message_classes, " history");
+ }
+
+ /* 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");
+ }
+
/*
* To mimick Adium's behavior, we only want to join messages
- * sent within a 5 minute time frame.
+ * 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)) {
+ (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");
+
+ /* check who is the sender of the message to use the correct html file */
if (empathy_contact_is_user (sender)) {
- message_classes = "consecutive incoming message";
- html = priv->data->out_nextcontent_html;
- len = priv->data->out_nextcontent_len;
+ /* 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;
+ }
+
+ /*
+ * 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;
+ }
}
- if (!html) {
- message_classes = "consecutive message outgoing";
- html = priv->data->in_nextcontent_html;
- len = priv->data->in_nextcontent_len;
+ else {
+ if (is_backlog) {
+ html = priv->data->in_nextcontext_html;
+ len = priv->data->in_nextcontext_len;
+ }
+
+ if (html == NULL) {
+ html = priv->data->in_nextcontent_html;
+ len = priv->data->in_nextcontent_len;
+ }
}
}
- if (!html) {
+
+ /*
+ * 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 (!message_classes) {
- message_classes = "incoming message";
+ if (is_backlog) {
+ html = priv->data->out_context_html;
+ len = priv->data->out_context_len;
+ }
+
+ if (html == NULL) {
+ html = priv->data->out_content_html;
+ len = priv->data->out_content_len;
}
- html = priv->data->out_content_html;
- len = priv->data->out_content_len;
}
- if (!html) {
- if (!message_classes) {
- message_classes = "message outgoing";
+ 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;
}
- html = priv->data->in_content_html;
- len = priv->data->in_content_len;
}
}
theme_adium_append_html (theme, func, html, len, body, avatar_filename,
- name, contact_id, service_name, message_classes,
+ name, contact_id, service_name, message_classes->str,
timestamp);
/* Keep the sender of the last displayed message */
@@ -506,8 +573,10 @@ theme_adium_append_message (EmpathyChatView *view,
}
priv->last_contact = g_object_ref (sender);
priv->last_timestamp = timestamp;
+ priv->last_is_backlog = is_backlog;
g_free (dup_body);
+ g_string_free (message_classes, TRUE);
}
static void
@@ -914,6 +983,14 @@ empathy_adium_data_new_with_info (const gchar *path, GHashTable *info)
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);
@@ -923,6 +1000,14 @@ empathy_adium_data_new_with_info (const gchar *path, GHashTable *info)
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);
@@ -1042,8 +1127,12 @@ empathy_adium_data_unref (EmpathyAdiumData *data)
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);