changeset 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 922d0483ca88
files plugins/ChangeLog.API src/conversation.c src/conversation.h src/gtkconv.c
diffstat 4 files changed, 83 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/ChangeLog.API	Sat Oct 15 19:25:18 2005 +0000
+++ b/plugins/ChangeLog.API	Sun Oct 16 18:15:47 2005 +0000
@@ -117,6 +117,8 @@
 	           instead
 	* Removed: serv_change_passwd(); use gaim_account_change_password()
 	           instead
+	* Added:   gaim_conversation_close_logs(), to force a conversation's
+	           log(s) to be closed. New logs will be opened as necessary.
 
 	Signals:
 	* Changed: "received-im-msg" and "received-chat-msg" to match, both
--- 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;
--- a/src/conversation.h	Sat Oct 15 19:25:18 2005 +0000
+++ b/src/conversation.h	Sun Oct 16 18:15:47 2005 +0000
@@ -417,6 +417,17 @@
 gboolean gaim_conversation_is_logging(const GaimConversation *conv);
 
 /**
+ * Closes any open logs for this conversation.
+ *
+ * Note that new logs will be opened as necessary (e.g. upon receipt of a
+ * message, if the conversation has logging enabled. To disable logging for
+ * the remainder of the conversation, use gaim_conversation_set_logging().
+ *
+ * @param conv The conversation.
+ */
+void gaim_conversation_close_logs(GaimConversation *conv);
+
+/**
  * Returns the specified conversation's send history.
  *
  * @param conv The conversation.
--- a/src/gtkconv.c	Sat Oct 15 19:25:18 2005 +0000
+++ b/src/gtkconv.c	Sun Oct 16 18:15:47 2005 +0000
@@ -1891,6 +1891,26 @@
 }
 
 static void
+gaim_gtkconv_set_active_conversation(GaimConversation *conv)
+{
+	GaimGtkConversation *gtkconv;
+
+	g_return_if_fail(conv != NULL);
+
+	gtkconv = GAIM_GTK_CONVERSATION(conv);
+
+	if (gtkconv->active_conv == conv)
+		return;
+
+	gaim_conversation_close_logs(gtkconv->active_conv);
+
+	gtkconv->active_conv = conv;
+
+	gaim_conversation_set_logging(conv,
+		gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gtkconv->win->menu.logging)));
+}
+
+static void
 gaim_gtkconv_switch_active_conversation(GaimConversation *conv)
 {
 	GaimGtkConversation *gtkconv;
@@ -1899,14 +1919,11 @@
 
 	gtkconv = GAIM_GTK_CONVERSATION(conv);
 
-	gtkconv->active_conv = conv;
+	gaim_gtkconv_set_active_conversation(conv);
 
 	gray_stuff_out(gtkconv);
 	update_typing_icon(gtkconv);
 
-	gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtkconv->win->menu.logging),
-	                               gaim_conversation_is_logging(conv));
-
 	gtk_window_set_title(GTK_WINDOW(gtkconv->win->window),
 	                     gtk_label_get_text(GTK_LABEL(gtkconv->tab_label)));
 
@@ -3899,7 +3916,7 @@
 	GaimGtkConversation *gtkconv;
 
 	gtkconv = GAIM_GTK_CONVERSATION(conv);
-	gtkconv->active_conv = conv;
+	gaim_gtkconv_set_active_conversation(conv);
 
 	gtkconv->u.im->a_virgin = FALSE;
 
@@ -3913,7 +3930,7 @@
 	GaimGtkConversation *gtkconv;
 
 	gtkconv = GAIM_GTK_CONVERSATION(conv);
-	gtkconv->active_conv = conv;
+	gaim_gtkconv_set_active_conversation(conv);
 
 	flags |= GAIM_MESSAGE_COLORIZE;
 
@@ -4025,7 +4042,7 @@
 
 	/* Set the active conversation to the one that just messaged us. */
 	/* TODO: consider not doing this if the account is offline or something */
-	gtkconv->active_conv = conv;
+	gaim_gtkconv_set_active_conversation(conv);
 
 	gc = gaim_conversation_get_gc(conv);
 	account = gaim_conversation_get_account(conv);
@@ -6095,6 +6112,9 @@
 
 	/* Update the menubar */
 
+	gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtkconv->win->menu.logging),
+	                               gaim_conversation_is_logging(conv));
+
 	generate_send_to_items(win);
 
 	gaim_gtkconv_switch_active_conversation(conv);