From: Richard L. <rl...@us...> - 2006-01-14 00:06:34
|
Update of /cvsroot/gaim/gaim/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22546/src Modified Files: conversation.c conversation.h gtkconv.c Log Message: 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. Index: conversation.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/conversation.c,v retrieving revision 1.700 retrieving revision 1.701 diff -u -d -p -r1.700 -r1.701 --- conversation.c 12 Jan 2006 15:10:55 -0000 1.700 +++ conversation.c 14 Jan 2006 00:06:24 -0000 1.701 @@ -1463,8 +1463,9 @@ gaim_conv_chat_add_users(GaimConvChat *c 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 @@ gaim_conv_chat_rename_user(GaimConvChat 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); + GList *users = g_list_append(NULL, (char *)user); - gaim_conversation_write(conv, NULL, tmp, GAIM_MESSAGE_SYSTEM, time(NULL)); - } + gaim_conv_chat_remove_users(chat, users, reason); - gaim_signal_emit(gaim_conversations_get_handle(), "chat-buddy-left", - conv, user, 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); - 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)); - } + 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); - if (ops != NULL && ops->chat_remove_users != NULL) - ops->chat_remove_users(conv, users); + 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)) | + gaim_conv_chat_is_user_ignored(chat, user); cb = gaim_conv_chat_cb_find(chat, user); @@ -1750,49 +1693,42 @@ gaim_conv_chat_remove_users(GaimConvChat gaim_conv_chat_cb_destroy(cb); } - 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. */ + /* NOTE: Don't remove them from ignored in case they re-enter. */ + + if (!quiet) { + const char *alias = user; + char *escaped; + char *tmp; - if (!quiet && reason != NULL && *reason != '\0') { - int i; - int size = g_list_length(users); - int max = MIN(10, size); - GList *l; - char *escaped; + if (!(prpl_info->options & OPT_PROTO_UNIQUE_CHATNAME)) { + GaimBuddy *buddy; - *tmp = '\0'; + if ((buddy = gaim_find_buddy(gc->account, user)) != NULL) + alias = gaim_buddy_get_contact_alias(buddy); + } - 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); + escaped = g_markup_escape_text(alias, -1); - if (i < max - 1) - g_strlcat(tmp, ", ", sizeof(tmp)); + 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); } - } - - 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); + g_free(escaped); - 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)); + g_free(tmp); + } - gaim_conversation_write(conv, NULL, tmp, - GAIM_MESSAGE_SYSTEM, time(NULL)); + gaim_signal_emit(gaim_conversations_get_handle(), "chat-buddy-left", + conv, user, reason); } + + if (ops != NULL && ops->chat_remove_users != NULL) + ops->chat_remove_users(conv, users); } void Index: conversation.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/conversation.h,v retrieving revision 1.79 retrieving revision 1.80 diff -u -d -p -r1.79 -r1.80 --- conversation.h 9 Jan 2006 21:29:52 -0000 1.79 +++ conversation.h 14 Jan 2006 00:06:24 -0000 1.80 @@ -156,7 +156,6 @@ struct _GaimConversationUiOps 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); Index: gtkconv.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/gtkconv.c,v retrieving revision 1.726 retrieving revision 1.727 diff -u -d -p -r1.726 -r1.727 --- gtkconv.c 11 Jan 2006 23:23:38 -0000 1.726 +++ gtkconv.c 14 Jan 2006 00:06:24 -0000 1.727 @@ -4892,56 +4892,6 @@ gaim_gtkconv_chat_rename_user(GaimConver } 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 @@ static GaimConversationUiOps conversatio 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 */ |