diff pidgin/gtkconv.c @ 15519:b15cc37605c4

In Pidgin, display a full date on the timestamp of the first message to cross the boundary into a new day. Sean and various users want this. I think I'm finally going to admit it's a decent idea. I've also refactored plenty of code related to the conversation-timestamp and log-timestamp signals. This breaks API compatibility, but I'm pretty sure the only plugin that uses those signals is the Message Timestamps plugin that we ship. The changes eliminate duplicated code between the core/UI and the plugin.
author Richard Laager <rlaager@wiktel.com>
date Sat, 03 Feb 2007 20:28:41 +0000
parents 75ffc646647f
children 9c32176ac555
line wrap: on
line diff
--- a/pidgin/gtkconv.c	Sat Feb 03 18:46:49 2007 +0000
+++ b/pidgin/gtkconv.c	Sat Feb 03 20:28:41 2007 +0000
@@ -4810,6 +4810,16 @@
 	return buddytag;
 }
 
+static void pidgin_conv_calculate_newday(PidginConversation *gtkconv, time_t mtime)
+{
+	struct tm *tm = localtime(&mtime);
+
+	tm->tm_hour = tm->tm_min = tm->tm_sec = 0;
+	tm->tm_mday++;
+
+	gtkconv->newday = mktime(tm);
+}
+
 static void
 pidgin_conv_write_conv(GaimConversation *conv, const char *name, const char *alias,
 						const char *message, GaimMessageFlags flags,
@@ -4825,6 +4835,7 @@
 	int max_scrollback_lines;
 	int line_count;
 	char buf2[BUF_LONG];
+	gboolean show_date;
 	char *mdate;
 	char color[10];
 	char *str;
@@ -4932,18 +4943,30 @@
 	if (gtk_text_buffer_get_char_count(gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->imhtml))))
 		gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<BR>", gtk_font_options_all);
 
+	/* First message in a conversation. */
+	if (gtkconv->newday == 0)
+		pidgin_conv_calculate_newday(gtkconv, mtime);
+
+	/* Show the date on the first message in a new day, or if the message is
+	 * older than 20 minutes. */
+	show_date = (mtime >= gtkconv->newday) || (time(NULL) > mtime + 20*60);
+
 	mdate = gaim_signal_emit_return_1(pidgin_conversations_get_handle(),
 	                                  "conversation-timestamp",
-	                                  conv, mtime);
+	                                  conv, mtime, show_date);
+
 	if (mdate == NULL)
 	{
 		struct tm *tm = localtime(&mtime);
-		if (time(NULL) > mtime + 20*60) /* show date if older than 20 minutes */
+		if (show_date)
 			mdate = g_strdup(gaim_date_format_long(tm));
 		else
 			mdate = g_strdup(gaim_time_format(tm));
 	}
 
+	if (mtime >= gtkconv->newday)
+		pidgin_conv_calculate_newday(gtkconv, mtime);
+
 	sml_attrib = g_strdup_printf("sml=\"%s\"", gaim_account_get_protocol_name(account));
 
 	gtk_font_options |= GTK_IMHTML_NO_COMMENTS;
@@ -6778,22 +6801,23 @@
 
 	gaim_signal_register(handle, "conversation-timestamp",
 #if SIZEOF_TIME_T == 4
-	                     gaim_marshal_POINTER__POINTER_INT,
+	                     gaim_marshal_POINTER__POINTER_INT_BOOLEAN,
 #elif SIZEOF_TIME_T == 8
-			     gaim_marshal_POINTER__POINTER_INT64,
+			     gaim_marshal_POINTER__POINTER_INT64_BOOLEAN,
 #else
 #error Unkown size of time_t
 #endif
-	                     gaim_value_new(GAIM_TYPE_POINTER), 2,
+	                     gaim_value_new(GAIM_TYPE_POINTER), 3,
 	                     gaim_value_new(GAIM_TYPE_SUBTYPE,
 	                                    GAIM_SUBTYPE_CONVERSATION),
 #if SIZEOF_TIME_T == 4
-	                     gaim_value_new(GAIM_TYPE_INT));
+	                     gaim_value_new(GAIM_TYPE_INT),
 #elif SIZEOF_TIME_T == 8
-	                     gaim_value_new(GAIM_TYPE_INT64));
+	                     gaim_value_new(GAIM_TYPE_INT64),
 #else
 # error Unknown size of time_t
 #endif
+	                     gaim_value_new(GAIM_TYPE_BOOLEAN));
 
 	gaim_signal_register(handle, "displaying-im-msg",
 						 gaim_marshal_BOOLEAN__POINTER_POINTER_POINTER_POINTER_POINTER,