changeset 12867:cf3540702d21

[gaim-migrate @ 15218] A patch from Ranma42 in SF Bug #1220557, with lots of changes by me. This merges gaim_conv_chat_remove_users and gaim_conv_chat_remove_user. As I did with gaim_conv_chat_add_user and gaim_conv_chat_add_users, gaim_conv_chat_remove_user is just a simple wrapper. The conversation UI op chat_remove_user has similarly been removed, in favor of UIs only having to implement one function to remove users. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Sat, 14 Jan 2006 00:06:24 +0000
parents 43d8af815a9d
children 74f6596fab78
files plugins/ChangeLog.API src/conversation.c src/conversation.h src/gtkconv.c
diffstat 4 files changed, 54 insertions(+), 169 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/ChangeLog.API	Fri Jan 13 23:00:43 2006 +0000
+++ b/plugins/ChangeLog.API	Sat Jan 14 00:06:24 2006 +0000
@@ -50,7 +50,7 @@
 	* chat_rename_user in GaimConversationUiOps, added new_alias
 	* GaimConversation.log became GList * GaimConversation.logs, so that a
 	  conversation can have multiple logs at once
-	* gaim_conv_chat_add_user, added extra_msgs list
+	* gaim_conv_chat_add_user, added extra_msgs
 	* gaim_notify_userinfo, removed primary and secondary parameters
 	* GaimNotifyUiOps.notify_userinfo: removed title, primary, and
 	  secondary parameters
@@ -114,7 +114,8 @@
 	  operation for conversations.  Use signal "received-im-msg" or similar.
 	* All warning stuff from the core.
 	* gaim_gtkconv_get_dest_tab_at_xy(), instead use gaim_gtkconv_get_tab_at_xy()
-	* chat_add_user from GaimConversationUiOps
+	* chat_add_user from GaimConversationUiOps: only chat_add_users is used
+	* chat_remove_user from GaimConversationUiOps: only chat_remove_users is used
 	* uc from the GaimBuddy struct
 	* gaim_sound_get_handle()
 	* gaim_debug_vargs()
--- a/src/conversation.c	Fri Jan 13 23:00:43 2006 +0000
+++ b/src/conversation.c	Sat Jan 14 00:06:24 2006 +0000
@@ -1463,8 +1463,9 @@
 	ops  = gaim_conversation_get_ui_ops(conv);
 
 	gc = gaim_conversation_get_gc(conv);
-	if (!gc || !(prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)))
-		return;
+	g_return_if_fail(gc != NULL);
+	prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
+	g_return_if_fail(prpl_info != NULL);
 
 	ul = users;
 	fl = flags;
@@ -1648,99 +1649,41 @@
 void
 gaim_conv_chat_remove_user(GaimConvChat *chat, const char *user, const char *reason)
 {
-	GaimConversation *conv;
-	GaimConversationUiOps *ops;
-	GaimConvChatBuddy *cb;
-	char tmp[BUF_LONG];
-	gboolean quiet;
-	const char *alias = user;
-
-	g_return_if_fail(chat != NULL);
-	g_return_if_fail(user != NULL);
-
-	conv = gaim_conv_chat_get_conversation(chat);
-	ops  = gaim_conversation_get_ui_ops(conv);
-
-	quiet = GPOINTER_TO_INT(gaim_signal_emit_return_1(gaim_conversations_get_handle(),
-				"chat-buddy-leaving", conv, user, reason)) |
-			gaim_conv_chat_is_user_ignored(chat, user);
-
-	if (ops != NULL && ops->chat_remove_user != NULL)
-		ops->chat_remove_user(conv, user);
-
-	cb = gaim_conv_chat_cb_find(chat, user);
-
-	if (cb) {
-		gaim_conv_chat_set_users(chat,
-				g_list_remove(gaim_conv_chat_get_users(chat), cb));
-		gaim_conv_chat_cb_destroy(cb);
-	}
-
-	/* NOTE: Don't remove them from ignored in case they re-enter. */
-
-	if (!quiet) {
-		GaimConnection *gc = gaim_conversation_get_gc(conv);
-		GaimPluginProtocolInfo *prpl_info;
-		char *escaped;
-
-		if (!gc || !(prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)))
-			return;
-
-		if (!(prpl_info->options & OPT_PROTO_UNIQUE_CHATNAME)) {
-			GaimBuddy *buddy;
-
-			if ((buddy = gaim_find_buddy(gc->account, user)) != NULL)
-				alias = gaim_buddy_get_contact_alias(buddy);
-		}
-		escaped = g_markup_escape_text(alias, -1);
-
-		if (reason != NULL && *reason != '\0')
-		{
-			char *escaped2 = g_markup_escape_text(reason, -1);
-			g_snprintf(tmp, sizeof(tmp),
-					   _("%s left the room (%s)."), escaped, escaped2);
-			g_free(escaped2);
-		}
-		else
-			g_snprintf(tmp, sizeof(tmp), _("%s left the room."), escaped);
-
-		g_free(escaped);
-
-		gaim_conversation_write(conv, NULL, tmp, GAIM_MESSAGE_SYSTEM, time(NULL));
-	}
-
-	gaim_signal_emit(gaim_conversations_get_handle(), "chat-buddy-left",
-					 conv, user, reason);
+	GList *users = g_list_append(NULL, (char *)user);
+
+	gaim_conv_chat_remove_users(chat, users, reason);
+
+	g_list_free(users);
 }
 
 void
 gaim_conv_chat_remove_users(GaimConvChat *chat, GList *users, const char *reason)
 {
 	GaimConversation *conv;
+	GaimConnection *gc;
+	GaimPluginProtocolInfo *prpl_info;
 	GaimConversationUiOps *ops;
 	GaimConvChatBuddy *cb;
-	char tmp[BUF_LONG];
 	GList *l;
-	gboolean quiet = FALSE;
+	gboolean quiet;
 
 	g_return_if_fail(chat  != NULL);
 	g_return_if_fail(users != NULL);
 
 	conv = gaim_conv_chat_get_conversation(chat);
+
+	gc = gaim_conversation_get_gc(conv);
+	g_return_if_fail(gc != NULL);
+	prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
+	g_return_if_fail(prpl_info != NULL);
+
 	ops  = gaim_conversation_get_ui_ops(conv);
 
 	for (l = users; l != NULL; l = l->next) {
 		const char *user = (const char *)l->data;
-
 		quiet = GPOINTER_TO_INT(gaim_signal_emit_return_1(gaim_conversations_get_handle(),
-								"chat-buddy-leaving", conv, user, reason));
-	}
-
-	if (ops != NULL && ops->chat_remove_users != NULL)
-		ops->chat_remove_users(conv, users);
-
-	for (l = users; l != NULL; l = l->next) {
-		const char *user = (const char *)l->data;
+					"chat-buddy-leaving", conv, user, reason)) |
+				gaim_conv_chat_is_user_ignored(chat, user);
 
 		cb = gaim_conv_chat_cb_find(chat, user);
 
@@ -1750,49 +1693,42 @@
 			gaim_conv_chat_cb_destroy(cb);
 		}
 
+		/* NOTE: Don't remove them from ignored in case they re-enter. */
+	
+		if (!quiet) {
+			const char *alias = user;
+			char *escaped;
+			char *tmp;
+
+			if (!(prpl_info->options & OPT_PROTO_UNIQUE_CHATNAME)) {
+				GaimBuddy *buddy;
+
+				if ((buddy = gaim_find_buddy(gc->account, user)) != NULL)
+					alias = gaim_buddy_get_contact_alias(buddy);
+			}
+
+			escaped = g_markup_escape_text(alias, -1);
+
+			if (reason == NULL || !*reason)
+				tmp = g_strdup_printf(_("%s left the room."), escaped);
+			else {
+				char *escaped2 = g_markup_escape_text(reason, -1);
+				tmp = g_strdup_printf(_("%s left the room (%s)."),
+									  escaped, escaped2);
+				g_free(escaped2);
+			}
+			g_free(escaped);
+
+			gaim_conversation_write(conv, NULL, tmp, GAIM_MESSAGE_SYSTEM, time(NULL));
+			g_free(tmp);
+		}
+
 		gaim_signal_emit(gaim_conversations_get_handle(), "chat-buddy-left",
 						 conv, user, reason);
 	}
 
-	/* NOTE: Don't remove them from ignored in case they re-enter. */
-
-	if (!quiet && reason != NULL && *reason != '\0') {
-		int i;
-		int size = g_list_length(users);
-		int max = MIN(10, size);
-		GList *l;
-		char *escaped;
-
-		*tmp = '\0';
-
-		for (l = users, i = 0; i < max; i++, l = l->next)
-		{
-			if (!gaim_conv_chat_is_user_ignored(chat, (char *)l->data))
-			{
-				escaped = g_markup_escape_text((char *)l->data, -1);
-				g_strlcat(tmp, escaped, sizeof(tmp));
-				g_free(escaped);
-
-				if (i < max - 1)
-					g_strlcat(tmp, ", ", sizeof(tmp));
-			}
-		}
-
-		if (size > 10)
-			/*
-			 * This should probably use ngettext(), but this function
-			 * isn't called from anywhere, so I'm going to leave it.
-			 */
-			g_snprintf(tmp, sizeof(tmp),
-					   _("(+%d more)"), size - 10);
-
-		escaped = g_markup_escape_text(reason, -1);
-		g_snprintf(tmp, sizeof(tmp), _(" left the room (%s)."), escaped);
-		g_free(escaped);
-
-		gaim_conversation_write(conv, NULL, tmp,
-								GAIM_MESSAGE_SYSTEM, time(NULL));
-	}
+	if (ops != NULL && ops->chat_remove_users != NULL)
+		ops->chat_remove_users(conv, users);
 }
 
 void
--- a/src/conversation.h	Fri Jan 13 23:00:43 2006 +0000
+++ b/src/conversation.h	Sat Jan 14 00:06:24 2006 +0000
@@ -156,7 +156,6 @@
 						   GList *flags, GList *aliases, gboolean new_arrivals);
 	void (*chat_rename_user)(GaimConversation *conv, const char *old_name,
 	                         const char *new_name, const char *new_alias);
-	void (*chat_remove_user)(GaimConversation *conv, const char *user);
 	void (*chat_remove_users)(GaimConversation *conv, GList *users);
 	void (*chat_update_user)(GaimConversation *conv, const char *user);
 
--- a/src/gtkconv.c	Fri Jan 13 23:00:43 2006 +0000
+++ b/src/gtkconv.c	Sat Jan 14 00:06:24 2006 +0000
@@ -4892,56 +4892,6 @@
 }
 
 static void
-gaim_gtkconv_chat_remove_user(GaimConversation *conv, const char *user)
-{
-	GaimConvChat *chat;
-	GaimGtkConversation *gtkconv;
-	GaimGtkChatPane *gtkchat;
-	GtkTreeIter iter;
-	GtkTreeModel *model;
-	char tmp[BUF_LONG];
-	int num_users;
-	int f = 1;
-
-	chat    = GAIM_CONV_CHAT(conv);
-	gtkconv = GAIM_GTK_CONVERSATION(conv);
-	gtkchat = gtkconv->u.chat;
-
-	num_users = g_list_length(gaim_conv_chat_get_users(chat)) - 1;
-
-	model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list));
-
-	if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter))
-		return;
-
-	while (f != 0) {
-		char *val;
-
-		gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, CHAT_USERS_NAME_COLUMN, &val, -1);
-
-		if (!gaim_utf8_strcasecmp(user, val)) {
-			gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
-			g_free(val);
-			break;
-		}
-
-		f = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter);
-
-		g_free(val);
-	}
-
-	if (!gaim_conv_chat_find_user(chat, user))
-		return;
-
-	g_snprintf(tmp, sizeof(tmp),
-			ngettext("%d person in room", "%d people in room",
-				num_users), num_users);
-
-	gtk_label_set_text(GTK_LABEL(gtkchat->count), tmp);
-
-}
-
-static void
 gaim_gtkconv_chat_remove_users(GaimConversation *conv, GList *users)
 {
 	GaimConvChat *chat;
@@ -5639,7 +5589,6 @@
 	gaim_gtkconv_write_conv,         /* write_conv           */
 	gaim_gtkconv_chat_add_users,     /* chat_add_users       */
 	gaim_gtkconv_chat_rename_user,   /* chat_rename_user     */
-	gaim_gtkconv_chat_remove_user,   /* chat_remove_user     */
 	gaim_gtkconv_chat_remove_users,  /* chat_remove_users    */
 	gaim_gtkconv_chat_update_user,   /* chat_update_user     */
 	gaim_gtkconv_present_conversation, /* present            */