changeset 32432:79fdae8fa875

merge of '3100be309efb98a39bb8ef745c0302722534234a' and 'f7aa873b9699de75db73441a0ca52795d63cfae1'
author Paul Aurich <paul@darkrain42.org>
date Tue, 03 Jan 2012 19:29:43 +0000
parents 36fc641ca013 (current diff) 9e72389456f6 (diff)
children 98520ee78f12
files
diffstat 1 files changed, 96 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkconv.c	Tue Jan 03 19:29:20 2012 +0000
+++ b/pidgin/gtkconv.c	Tue Jan 03 19:29:43 2012 +0000
@@ -187,6 +187,7 @@
 static void generate_send_to_items(PidginWindow *win);
 
 /* Prototypes. <-- because Paco-Paco hates this comment. */
+static void load_conv_theme(PidginConversation *gtkconv);
 static gboolean infopane_entry_activate(PidginConversation *gtkconv);
 static void got_typing_keypress(PidginConversation *gtkconv, gboolean first);
 static void gray_stuff_out(PidginConversation *gtkconv);
@@ -440,12 +441,12 @@
 static void clear_conversation_scrollback_cb(PurpleConversation *conv,
                                              void *data)
 {
-	PidginConversation *gtkconv = NULL;
-
-	gtkconv = PIDGIN_CONVERSATION(conv);
-
-	if (PIDGIN_CONVERSATION(conv))
-		webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(gtkconv->webview), "", "");
+	PidginConversation *gtkconv = PIDGIN_CONVERSATION(conv);
+
+	if (PIDGIN_CONVERSATION(conv)) {
+		load_conv_theme(gtkconv);
+		gtkconv->last_flags = 0;
+	}
 }
 
 static PurpleCmdRet
@@ -5044,6 +5045,8 @@
 	GString *str;
 	const char *cur = text;
 	const char *prev = cur;
+	time_t mtime;
+	struct tm *tm = NULL;
 
 	if (text == NULL || *text == '\0')
 		return NULL;
@@ -5080,6 +5083,7 @@
 		} else if (g_str_has_prefix(cur, "%timeOpened")) {
 			const char *tmp = cur + strlen("%timeOpened");
 			char *format = NULL;
+
 			if (*tmp == '{') {
 				const char *end;
 				tmp++;
@@ -5089,11 +5093,22 @@
 				format = g_strndup(tmp, end - tmp);
 				fin = end + 1;
 			}
-			replace = purple_utf8_strftime(format ? format : "%X", NULL);
+
+			if (!tm) {
+				mtime = time(NULL);
+				tm = localtime(&mtime);
+			}
+
+			replace = purple_utf8_strftime(format ? format : "%X", tm);
 			g_free(format);
 
 		} else if (g_str_has_prefix(cur, "%dateOpened%")) {
-			replace = purple_date_format_short(NULL);
+			if (!tm) {
+				mtime = time(NULL);
+				tm = localtime(&mtime);
+			}
+
+			replace = purple_date_format_short(tm);
 
 		} else {
 			cur++;
@@ -5204,6 +5219,43 @@
 	g_free(js);
 }
 
+static void
+load_conv_theme(PidginConversation *gtkconv)
+{
+	char *header, *footer;
+	char *template;
+	char *basedir, *baseuri;
+
+	header = replace_header_tokens(gtkconv->active_conv,
+		pidgin_conversation_theme_get_template(gtkconv->theme, PIDGIN_CONVERSATION_THEME_TEMPLATE_HEADER));
+	footer = replace_header_tokens(gtkconv->active_conv,
+		pidgin_conversation_theme_get_template(gtkconv->theme, PIDGIN_CONVERSATION_THEME_TEMPLATE_FOOTER));
+	template = replace_template_tokens(gtkconv->theme, header, footer);
+	g_free(header);
+	g_free(footer);
+
+	if (template == NULL)
+		return;
+
+	set_theme_webkit_settings(WEBKIT_WEB_VIEW(gtkconv->webview), gtkconv->theme);
+
+	basedir = pidgin_conversation_theme_get_template_path(gtkconv->theme);
+	baseuri = g_strdup_printf("file://%s", basedir);
+	webkit_web_view_load_string(WEBKIT_WEB_VIEW(gtkconv->webview), template,
+	                            "text/html", "UTF-8", baseuri);
+
+	if (purple_conversation_get_type(gtkconv->active_conv) == PURPLE_CONV_TYPE_CHAT)
+		gtk_webview_safe_execute_script(GTK_WEBVIEW(gtkconv->webview),
+			"document.getElementById('Chat').className = 'groupchat'");
+
+	g_signal_connect(G_OBJECT(gtkconv->theme), "notify::variant",
+	                 G_CALLBACK(conv_variant_changed_cb), gtkconv);
+
+	g_free(basedir);
+	g_free(baseuri);
+	g_free(template);
+}
+
 static GtkWidget *
 setup_common_pane(PidginConversation *gtkconv)
 {
@@ -5214,8 +5266,6 @@
 	PurpleBuddy *buddy;
 	gboolean chat = (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT);
 	int buddyicon_size = 0;
-	char *header, *footer;
-	char *template;
 
 	/* Setup the top part of the pane */
 	vbox = gtk_vbox_new(FALSE, PIDGIN_HIG_BOX_SPACE);
@@ -5309,36 +5359,7 @@
 	frame = pidgin_create_webview(FALSE, &gtkconv->webview, NULL, &webview_sw);
 	gtk_widget_set_size_request(gtkconv->webview, -1, 0);
 
-	header = replace_header_tokens(conv,
-		pidgin_conversation_theme_get_template(gtkconv->theme, PIDGIN_CONVERSATION_THEME_TEMPLATE_HEADER));
-	footer = replace_header_tokens(conv,
-		pidgin_conversation_theme_get_template(gtkconv->theme, PIDGIN_CONVERSATION_THEME_TEMPLATE_FOOTER));
-	template = replace_template_tokens(gtkconv->theme, header, footer);
-	g_free(header);
-	g_free(footer);
-
-	if (template != NULL) {
-		char *basedir;
-		char *baseuri;
-
-		purple_debug_info("webkit", "template: %s\n", template);
-
-		set_theme_webkit_settings(WEBKIT_WEB_VIEW(gtkconv->webview), gtkconv->theme);
-
-		basedir = pidgin_conversation_theme_get_template_path(gtkconv->theme);
-		baseuri = g_strdup_printf("file://%s", basedir);
-		webkit_web_view_load_string(WEBKIT_WEB_VIEW(gtkconv->webview), template, "text/html", "UTF-8", baseuri);
-
-		if (chat)
-			gtk_webview_safe_execute_script(GTK_WEBVIEW(gtkconv->webview), "document.getElementById('Chat').className = 'groupchat'");
-
-		g_signal_connect(G_OBJECT(gtkconv->theme), "notify::variant",
-		                 G_CALLBACK(conv_variant_changed_cb), gtkconv);
-
-		g_free(basedir);
-		g_free(baseuri);
-		g_free(template);
-	}
+	load_conv_theme(gtkconv);
 
 	if (chat) {
 		GtkWidget *hpaned;
@@ -6096,6 +6117,7 @@
 	GString *str;
 	const char *cur = text;
 	const char *prev = cur;
+	struct tm *tm = NULL;
 
 	if (text == NULL || *text == '\0')
 		return NULL;
@@ -6116,6 +6138,7 @@
 		} else if (g_str_has_prefix(cur, "%time")) {
 			const char *tmp = cur + strlen("%time");
 			char *format = NULL;
+
 			if (*tmp == '{') {
 				char *end;
 				tmp++;
@@ -6125,11 +6148,18 @@
 				format = g_strndup(tmp, end - tmp);
 				fin = end + 1;
 			}
-			replace = purple_utf8_strftime(format ? format : "%X", NULL);
+
+			if (!tm)
+				tm = localtime(&mtime);
+
+			replace = purple_utf8_strftime(format ? format : "%X", tm);
 			g_free(format);
 
 		} else if (g_str_has_prefix(cur, "%shortTime%")) {
-			replace = purple_utf8_strftime("%H:%M", NULL);
+			if (!tm)
+				tm = localtime(&mtime);
+
+			replace = purple_utf8_strftime("%H:%M", tm);
 
 		} else if (g_str_has_prefix(cur, "%userIconPath%")) {
 			if (flags & PURPLE_MESSAGE_SEND) {
@@ -6173,7 +6203,7 @@
 		if (replace)
 			g_string_append(str, replace);
 		g_free(freeval);
-		freeval = replace = NULL;
+		replace = freeval = NULL;
 
 		/* And update the pointers */
 		if (fin) {
@@ -6281,17 +6311,34 @@
 
 	old_flags = gtkconv->last_flags;
 	if ((flags & PURPLE_MESSAGE_SEND) && (old_flags & PURPLE_MESSAGE_SEND)) {
-		message_html = pidgin_conversation_theme_get_template(gtkconv->theme, PIDGIN_CONVERSATION_THEME_TEMPLATE_OUTGOING_NEXT_CONTENT);
+		message_html = pidgin_conversation_theme_get_template(gtkconv->theme,
+			PIDGIN_CONVERSATION_THEME_TEMPLATE_OUTGOING_NEXT_CONTENT);
 		func = "appendNextMessage";
+
 	} else if (flags & PURPLE_MESSAGE_SEND) {
-		message_html = pidgin_conversation_theme_get_template(gtkconv->theme, PIDGIN_CONVERSATION_THEME_TEMPLATE_OUTGOING_CONTENT);
+		message_html = pidgin_conversation_theme_get_template(gtkconv->theme,
+			PIDGIN_CONVERSATION_THEME_TEMPLATE_OUTGOING_CONTENT);
+
 	} else if ((flags & PURPLE_MESSAGE_RECV) && (old_flags & PURPLE_MESSAGE_RECV)) {
-		message_html = pidgin_conversation_theme_get_template(gtkconv->theme, PIDGIN_CONVERSATION_THEME_TEMPLATE_INCOMING_NEXT_CONTENT);
-		func = "appendNextMessage";
+		GList *history = purple_conversation_get_message_history(conv);
+		PurpleConvMessage *last_msg = (PurpleConvMessage *)history->data;
+
+		/* If the senders are the same, use appendNextMessage */
+		if (purple_strequal(purple_conversation_message_get_sender(last_msg), name)) {
+			message_html = pidgin_conversation_theme_get_template(gtkconv->theme,
+				PIDGIN_CONVERSATION_THEME_TEMPLATE_INCOMING_NEXT_CONTENT);
+			func = "appendNextMessage";
+		} else {
+			message_html = pidgin_conversation_theme_get_template(gtkconv->theme,
+				PIDGIN_CONVERSATION_THEME_TEMPLATE_INCOMING_CONTENT);
+		}
 	} else if (flags & PURPLE_MESSAGE_RECV) {
-		message_html = pidgin_conversation_theme_get_template(gtkconv->theme, PIDGIN_CONVERSATION_THEME_TEMPLATE_INCOMING_CONTENT);
+		message_html = pidgin_conversation_theme_get_template(gtkconv->theme,
+			PIDGIN_CONVERSATION_THEME_TEMPLATE_INCOMING_CONTENT);
+
 	} else {
-		message_html = pidgin_conversation_theme_get_template(gtkconv->theme, PIDGIN_CONVERSATION_THEME_TEMPLATE_STATUS);
+		message_html = pidgin_conversation_theme_get_template(gtkconv->theme,
+			PIDGIN_CONVERSATION_THEME_TEMPLATE_STATUS);
 	}
 	gtkconv->last_flags = flags;