diff src/conversation.c @ 11672:04e0189bb519

[gaim-migrate @ 13958] (contact-aware conversation)-aware logging: When the active buddy changes, a new log is opened. This way, the logs (on-disk, assuming a file-based logger) always correspond to the buddy that send/received the messages. Given that we already have contactized logging, the logs will all be shown in the same log viewer. Also, if you use Options -> Enable Logging to change the default logging mode for a perticular conversation or part of a conversation, that setting will be preserved even if the active buddy changes. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Sun, 16 Oct 2005 18:15:47 +0000
parents 4ebd27e664c4
children 0c54f9b0e67c
line wrap: on
line diff
--- a/src/conversation.c	Sat Oct 15 19:25:18 2005 +0000
+++ b/src/conversation.c	Sun Oct 16 18:15:47 2005 +0000
@@ -229,6 +229,15 @@
 	g_free(sent);
 }
 
+static void
+open_log(GaimConversation *conv)
+{
+	conv->logs = g_list_append(NULL, gaim_log_new(conv->type == GAIM_CONV_TYPE_CHAT ? GAIM_LOG_CHAT :
+							   GAIM_LOG_IM, conv->name, conv->account,
+							   conv, time(NULL)));
+}
+
+
 /**************************************************************************
  * Conversation API
  **************************************************************************/
@@ -241,10 +250,8 @@
 
 	account = gaim_conversation_get_account(conv);
 
-	g_list_foreach(conv->logs, (GFunc)gaim_log_free, NULL);
-	g_list_free(conv->logs);
-	conv->logs = g_list_append(NULL, gaim_log_new(GAIM_LOG_CHAT, gaim_conversation_get_name(conv),
-							 account, conv, time(NULL)));
+	gaim_conversation_close_logs(conv);
+	open_log(conv);
 
 	gc = gaim_account_get_connection(account);
 
@@ -301,9 +308,6 @@
 	conv->send_history = g_list_append(NULL, NULL);
 	conv->data         = g_hash_table_new_full(g_str_hash, g_str_equal,
 											   g_free, NULL);
-	conv->logs         = g_list_append(NULL, gaim_log_new(type == GAIM_CONV_TYPE_CHAT ? GAIM_LOG_CHAT :
-									  GAIM_LOG_IM, conv->name, account,
-									  conv, time(NULL)));
 	/* copy features from the connection. */
 	conv->features = gc->flags;
 
@@ -318,8 +322,11 @@
 		if ((icon = gaim_buddy_icons_find(account, name)))
 			gaim_conv_im_set_icon(conv->u.im, icon);
 
-		gaim_conversation_set_logging(conv,
-				gaim_prefs_get_bool("/core/logging/log_ims"));
+		if (gaim_prefs_get_bool("/core/logging/log_ims"))
+		{
+			gaim_conversation_set_logging(conv, TRUE);
+			open_log(conv);
+		}
 	}
 	else if (type == GAIM_CONV_TYPE_CHAT)
 	{
@@ -337,8 +344,11 @@
 			gaim_conv_chat_set_nick(conv->u.chat,
 									gaim_account_get_username(account));
 
-		gaim_conversation_set_logging(conv,
-				gaim_prefs_get_bool("/core/logging/log_chats"));
+		if (gaim_prefs_get_bool("/core/logging/log_chats"))
+		{
+			gaim_conversation_set_logging(conv, TRUE);
+			open_log(conv);
+		}
 	}
 
 	conversations = g_list_append(conversations, conv);
@@ -514,8 +524,7 @@
 	if (ops != NULL && ops->destroy_conversation != NULL)
 		ops->destroy_conversation(conv);
 
-	g_list_foreach(conv->logs, (GFunc)gaim_log_free, NULL);
-	g_list_free(conv->logs);
+	gaim_conversation_close_logs(conv);
 
 	GAIM_DBUS_UNREGISTER_POINTER(conv);
 	g_free(conv);
@@ -706,9 +715,11 @@
 {
 	g_return_if_fail(conv != NULL);
 
-	conv->logging = log;
-
-	gaim_conversation_update(conv, GAIM_CONV_UPDATE_LOGGING);
+	if (conv->logging != log)
+	{
+		conv->logging = log;
+		gaim_conversation_update(conv, GAIM_CONV_UPDATE_LOGGING);
+	}
 }
 
 gboolean
@@ -719,6 +730,16 @@
 	return conv->logging;
 }
 
+void
+gaim_conversation_close_logs(GaimConversation *conv)
+{
+	g_return_if_fail(conv != NULL);
+
+	g_list_foreach(conv->logs, (GFunc)gaim_log_free, NULL);
+	g_list_free(conv->logs);
+	conv->logs = NULL;
+}
+
 GList *
 gaim_conversation_get_send_history(const GaimConversation *conv)
 {
@@ -889,7 +910,12 @@
 	}
 
 	if (gaim_conversation_is_logging(conv)) {
-		GList *log = conv->logs;
+		GList *log;
+
+		if (conv->logs == NULL)
+			open_log(conv);
+
+		log = conv->logs;
 		while (log != NULL) {
 			gaim_log_write((GaimLog *)log->data, flags, alias, mtime, message);
 			log = log->next;