Mercurial > pidgin
comparison src/conversation.c @ 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 | 3612e3e5dc3d |
| children | 129a83f22349 |
comparison
equal
deleted
inserted
replaced
| 12866:43d8af815a9d | 12867:cf3540702d21 |
|---|---|
| 1461 | 1461 |
| 1462 conv = gaim_conv_chat_get_conversation(chat); | 1462 conv = gaim_conv_chat_get_conversation(chat); |
| 1463 ops = gaim_conversation_get_ui_ops(conv); | 1463 ops = gaim_conversation_get_ui_ops(conv); |
| 1464 | 1464 |
| 1465 gc = gaim_conversation_get_gc(conv); | 1465 gc = gaim_conversation_get_gc(conv); |
| 1466 if (!gc || !(prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl))) | 1466 g_return_if_fail(gc != NULL); |
| 1467 return; | 1467 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); |
| 1468 g_return_if_fail(prpl_info != NULL); | |
| 1468 | 1469 |
| 1469 ul = users; | 1470 ul = users; |
| 1470 fl = flags; | 1471 fl = flags; |
| 1471 while ((ul != NULL) && (fl != NULL)) { | 1472 while ((ul != NULL) && (fl != NULL)) { |
| 1472 const char *user = (const char *)ul->data; | 1473 const char *user = (const char *)ul->data; |
| 1646 } | 1647 } |
| 1647 | 1648 |
| 1648 void | 1649 void |
| 1649 gaim_conv_chat_remove_user(GaimConvChat *chat, const char *user, const char *reason) | 1650 gaim_conv_chat_remove_user(GaimConvChat *chat, const char *user, const char *reason) |
| 1650 { | 1651 { |
| 1652 GList *users = g_list_append(NULL, (char *)user); | |
| 1653 | |
| 1654 gaim_conv_chat_remove_users(chat, users, reason); | |
| 1655 | |
| 1656 g_list_free(users); | |
| 1657 } | |
| 1658 | |
| 1659 void | |
| 1660 gaim_conv_chat_remove_users(GaimConvChat *chat, GList *users, const char *reason) | |
| 1661 { | |
| 1651 GaimConversation *conv; | 1662 GaimConversation *conv; |
| 1663 GaimConnection *gc; | |
| 1664 GaimPluginProtocolInfo *prpl_info; | |
| 1652 GaimConversationUiOps *ops; | 1665 GaimConversationUiOps *ops; |
| 1653 GaimConvChatBuddy *cb; | 1666 GaimConvChatBuddy *cb; |
| 1654 char tmp[BUF_LONG]; | 1667 GList *l; |
| 1655 gboolean quiet; | 1668 gboolean quiet; |
| 1656 const char *alias = user; | |
| 1657 | |
| 1658 g_return_if_fail(chat != NULL); | |
| 1659 g_return_if_fail(user != NULL); | |
| 1660 | |
| 1661 conv = gaim_conv_chat_get_conversation(chat); | |
| 1662 ops = gaim_conversation_get_ui_ops(conv); | |
| 1663 | |
| 1664 quiet = GPOINTER_TO_INT(gaim_signal_emit_return_1(gaim_conversations_get_handle(), | |
| 1665 "chat-buddy-leaving", conv, user, reason)) | | |
| 1666 gaim_conv_chat_is_user_ignored(chat, user); | |
| 1667 | |
| 1668 if (ops != NULL && ops->chat_remove_user != NULL) | |
| 1669 ops->chat_remove_user(conv, user); | |
| 1670 | |
| 1671 cb = gaim_conv_chat_cb_find(chat, user); | |
| 1672 | |
| 1673 if (cb) { | |
| 1674 gaim_conv_chat_set_users(chat, | |
| 1675 g_list_remove(gaim_conv_chat_get_users(chat), cb)); | |
| 1676 gaim_conv_chat_cb_destroy(cb); | |
| 1677 } | |
| 1678 | |
| 1679 /* NOTE: Don't remove them from ignored in case they re-enter. */ | |
| 1680 | |
| 1681 if (!quiet) { | |
| 1682 GaimConnection *gc = gaim_conversation_get_gc(conv); | |
| 1683 GaimPluginProtocolInfo *prpl_info; | |
| 1684 char *escaped; | |
| 1685 | |
| 1686 if (!gc || !(prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl))) | |
| 1687 return; | |
| 1688 | |
| 1689 if (!(prpl_info->options & OPT_PROTO_UNIQUE_CHATNAME)) { | |
| 1690 GaimBuddy *buddy; | |
| 1691 | |
| 1692 if ((buddy = gaim_find_buddy(gc->account, user)) != NULL) | |
| 1693 alias = gaim_buddy_get_contact_alias(buddy); | |
| 1694 } | |
| 1695 escaped = g_markup_escape_text(alias, -1); | |
| 1696 | |
| 1697 if (reason != NULL && *reason != '\0') | |
| 1698 { | |
| 1699 char *escaped2 = g_markup_escape_text(reason, -1); | |
| 1700 g_snprintf(tmp, sizeof(tmp), | |
| 1701 _("%s left the room (%s)."), escaped, escaped2); | |
| 1702 g_free(escaped2); | |
| 1703 } | |
| 1704 else | |
| 1705 g_snprintf(tmp, sizeof(tmp), _("%s left the room."), escaped); | |
| 1706 | |
| 1707 g_free(escaped); | |
| 1708 | |
| 1709 gaim_conversation_write(conv, NULL, tmp, GAIM_MESSAGE_SYSTEM, time(NULL)); | |
| 1710 } | |
| 1711 | |
| 1712 gaim_signal_emit(gaim_conversations_get_handle(), "chat-buddy-left", | |
| 1713 conv, user, reason); | |
| 1714 } | |
| 1715 | |
| 1716 void | |
| 1717 gaim_conv_chat_remove_users(GaimConvChat *chat, GList *users, const char *reason) | |
| 1718 { | |
| 1719 GaimConversation *conv; | |
| 1720 GaimConversationUiOps *ops; | |
| 1721 GaimConvChatBuddy *cb; | |
| 1722 char tmp[BUF_LONG]; | |
| 1723 GList *l; | |
| 1724 gboolean quiet = FALSE; | |
| 1725 | 1669 |
| 1726 g_return_if_fail(chat != NULL); | 1670 g_return_if_fail(chat != NULL); |
| 1727 g_return_if_fail(users != NULL); | 1671 g_return_if_fail(users != NULL); |
| 1728 | 1672 |
| 1729 conv = gaim_conv_chat_get_conversation(chat); | 1673 conv = gaim_conv_chat_get_conversation(chat); |
| 1674 | |
| 1675 gc = gaim_conversation_get_gc(conv); | |
| 1676 g_return_if_fail(gc != NULL); | |
| 1677 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
| 1678 g_return_if_fail(prpl_info != NULL); | |
| 1679 | |
| 1730 ops = gaim_conversation_get_ui_ops(conv); | 1680 ops = gaim_conversation_get_ui_ops(conv); |
| 1731 | 1681 |
| 1732 for (l = users; l != NULL; l = l->next) { | 1682 for (l = users; l != NULL; l = l->next) { |
| 1733 const char *user = (const char *)l->data; | 1683 const char *user = (const char *)l->data; |
| 1734 | |
| 1735 quiet = GPOINTER_TO_INT(gaim_signal_emit_return_1(gaim_conversations_get_handle(), | 1684 quiet = GPOINTER_TO_INT(gaim_signal_emit_return_1(gaim_conversations_get_handle(), |
| 1736 "chat-buddy-leaving", conv, user, reason)); | 1685 "chat-buddy-leaving", conv, user, reason)) | |
| 1737 } | 1686 gaim_conv_chat_is_user_ignored(chat, user); |
| 1738 | |
| 1739 if (ops != NULL && ops->chat_remove_users != NULL) | |
| 1740 ops->chat_remove_users(conv, users); | |
| 1741 | |
| 1742 for (l = users; l != NULL; l = l->next) { | |
| 1743 const char *user = (const char *)l->data; | |
| 1744 | 1687 |
| 1745 cb = gaim_conv_chat_cb_find(chat, user); | 1688 cb = gaim_conv_chat_cb_find(chat, user); |
| 1746 | 1689 |
| 1747 if (cb) { | 1690 if (cb) { |
| 1748 gaim_conv_chat_set_users(chat, | 1691 gaim_conv_chat_set_users(chat, |
| 1749 g_list_remove(gaim_conv_chat_get_users(chat), cb)); | 1692 g_list_remove(gaim_conv_chat_get_users(chat), cb)); |
| 1750 gaim_conv_chat_cb_destroy(cb); | 1693 gaim_conv_chat_cb_destroy(cb); |
| 1751 } | 1694 } |
| 1752 | 1695 |
| 1696 /* NOTE: Don't remove them from ignored in case they re-enter. */ | |
| 1697 | |
| 1698 if (!quiet) { | |
| 1699 const char *alias = user; | |
| 1700 char *escaped; | |
| 1701 char *tmp; | |
| 1702 | |
| 1703 if (!(prpl_info->options & OPT_PROTO_UNIQUE_CHATNAME)) { | |
| 1704 GaimBuddy *buddy; | |
| 1705 | |
| 1706 if ((buddy = gaim_find_buddy(gc->account, user)) != NULL) | |
| 1707 alias = gaim_buddy_get_contact_alias(buddy); | |
| 1708 } | |
| 1709 | |
| 1710 escaped = g_markup_escape_text(alias, -1); | |
| 1711 | |
| 1712 if (reason == NULL || !*reason) | |
| 1713 tmp = g_strdup_printf(_("%s left the room."), escaped); | |
| 1714 else { | |
| 1715 char *escaped2 = g_markup_escape_text(reason, -1); | |
| 1716 tmp = g_strdup_printf(_("%s left the room (%s)."), | |
| 1717 escaped, escaped2); | |
| 1718 g_free(escaped2); | |
| 1719 } | |
| 1720 g_free(escaped); | |
| 1721 | |
| 1722 gaim_conversation_write(conv, NULL, tmp, GAIM_MESSAGE_SYSTEM, time(NULL)); | |
| 1723 g_free(tmp); | |
| 1724 } | |
| 1725 | |
| 1753 gaim_signal_emit(gaim_conversations_get_handle(), "chat-buddy-left", | 1726 gaim_signal_emit(gaim_conversations_get_handle(), "chat-buddy-left", |
| 1754 conv, user, reason); | 1727 conv, user, reason); |
| 1755 } | 1728 } |
| 1756 | 1729 |
| 1757 /* NOTE: Don't remove them from ignored in case they re-enter. */ | 1730 if (ops != NULL && ops->chat_remove_users != NULL) |
| 1758 | 1731 ops->chat_remove_users(conv, users); |
| 1759 if (!quiet && reason != NULL && *reason != '\0') { | |
| 1760 int i; | |
| 1761 int size = g_list_length(users); | |
| 1762 int max = MIN(10, size); | |
| 1763 GList *l; | |
| 1764 char *escaped; | |
| 1765 | |
| 1766 *tmp = '\0'; | |
| 1767 | |
| 1768 for (l = users, i = 0; i < max; i++, l = l->next) | |
| 1769 { | |
| 1770 if (!gaim_conv_chat_is_user_ignored(chat, (char *)l->data)) | |
| 1771 { | |
| 1772 escaped = g_markup_escape_text((char *)l->data, -1); | |
| 1773 g_strlcat(tmp, escaped, sizeof(tmp)); | |
| 1774 g_free(escaped); | |
| 1775 | |
| 1776 if (i < max - 1) | |
| 1777 g_strlcat(tmp, ", ", sizeof(tmp)); | |
| 1778 } | |
| 1779 } | |
| 1780 | |
| 1781 if (size > 10) | |
| 1782 /* | |
| 1783 * This should probably use ngettext(), but this function | |
| 1784 * isn't called from anywhere, so I'm going to leave it. | |
| 1785 */ | |
| 1786 g_snprintf(tmp, sizeof(tmp), | |
| 1787 _("(+%d more)"), size - 10); | |
| 1788 | |
| 1789 escaped = g_markup_escape_text(reason, -1); | |
| 1790 g_snprintf(tmp, sizeof(tmp), _(" left the room (%s)."), escaped); | |
| 1791 g_free(escaped); | |
| 1792 | |
| 1793 gaim_conversation_write(conv, NULL, tmp, | |
| 1794 GAIM_MESSAGE_SYSTEM, time(NULL)); | |
| 1795 } | |
| 1796 } | 1732 } |
| 1797 | 1733 |
| 1798 void | 1734 void |
| 1799 gaim_conv_chat_clear_users(GaimConvChat *chat) | 1735 gaim_conv_chat_clear_users(GaimConvChat *chat) |
| 1800 { | 1736 { |
