1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
/*
* GroupMsg - Send an IM to a group of buddies
* Copyright (C) 2004-2008 Stu Tomlinson <stu@nosnilmot.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301, USA.
*/
/* If you can't figure out what this line is for, DON'T TOUCH IT. */
#include "../common/pp_internal.h"
#include <debug.h>
#include <notify.h>
#include <prpl.h>
#include <request.h>
#include <signals.h>
#include <util.h>
static void
dont_do_it_cb(GList *list, const char *text)
{
g_list_free(list);
}
static void
do_it_cb(GList *list, const char *message)
{
char *stripped;
GList *l;
PurpleBuddy *b;
PurpleConversation *conv = NULL;
purple_markup_html_to_xhtml(message, NULL, &stripped);
for (l = list; l; l = l->next) {
b = l->data;
conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, b->account, b->name);
if(conv) {
if (b->account->gc->flags & PURPLE_CONNECTION_HTML)
purple_conv_im_send(PURPLE_CONV_IM(conv), message);
else
purple_conv_im_send(PURPLE_CONV_IM(conv), stripped);
}
}
g_free(stripped);
g_list_free(list);
}
static void
groupmsg_sendto_group(PurpleBlistNode *node, gpointer data)
{
PurpleBlistNode *n;
PurpleBuddy *b;
PurpleGroup *group;
GList *list = NULL;
gchar *tmp = NULL, *tmp2 = NULL;
guint llen = 0;
group = (PurpleGroup *)node;
for (n = node->child; n; n = n->next) {
if (PURPLE_BLIST_NODE_IS_CHAT(n))
continue;
if (PURPLE_BLIST_NODE_IS_CONTACT(n)) {
b = purple_contact_get_priority_buddy((PurpleContact*)n);
} else
b = (PurpleBuddy *)n;
if(b == NULL || !PURPLE_BUDDY_IS_ONLINE(b))
continue;
tmp2 = tmp;
if(tmp != NULL)
tmp = g_strdup_printf(" %s (%s)\n%s", purple_buddy_get_alias(b), b->name, tmp2);
else
tmp = g_strdup_printf(" %s (%s)", purple_buddy_get_alias(b), b->name);
g_free(tmp2);
list = g_list_append(list, b);
}
if (tmp == NULL) {
tmp = g_strdup_printf(_("There are no buddies online in group %s"), group->name);
purple_notify_error(NULL, NULL, "No buddies", tmp);
g_free(tmp);
g_list_free(list);
return;
}
if((llen = g_list_length(list)) > 6) {
g_free(tmp);
/* there should probably be more detailed handling here for singular vs
* plural here, but I'm too lazy to do it, and this is for messaging a
* group, which should be multiple people anyway */
tmp = g_strdup_printf(_("Your message will be sent to and probably annoy "
"ALL %u PEOPLE in the group %s!"), llen, group->name);
} else {
tmp2 = tmp;
tmp = g_strdup_printf(_("Your message will be sent to these buddies:\n%s"), tmp2);
g_free(tmp2);
}
purple_request_input(group, _("Spam"),
_("Please enter the message to send"),
tmp,
"", TRUE, FALSE, "html",
_("Send"), G_CALLBACK(do_it_cb),
_("Cancel"), G_CALLBACK(dont_do_it_cb),
NULL, NULL, NULL, list);
g_free(tmp);
}
static void
groupmsg_extended_menu_cb(PurpleBlistNode *node, GList **m)
{
PurpleMenuAction *bna = NULL;
if(!PURPLE_BLIST_NODE_IS_GROUP(node))
return;
*m = g_list_append(*m, bna);
bna = purple_menu_action_new("Group IM", PURPLE_CALLBACK(groupmsg_sendto_group), NULL, NULL);
*m = g_list_append(*m, bna);
}
static gboolean
plugin_load(PurplePlugin *plugin)
{
purple_signal_connect(purple_blist_get_handle(), "blist-node-extended-menu",
plugin, PURPLE_CALLBACK(groupmsg_extended_menu_cb), NULL);
return TRUE;
}
static PurplePluginInfo info =
{
PURPLE_PLUGIN_MAGIC, /**< magic */
PURPLE_MAJOR_VERSION, /**< major version */
PURPLE_MINOR_VERSION, /**< minor version */
PURPLE_PLUGIN_STANDARD, /**< type */
NULL, /**< ui_requirement */
0, /**< flags */
NULL, /**< dependencies */
PURPLE_PRIORITY_DEFAULT, /**< priority */
"core-plugin_pack-groupmsg", /**< id */
NULL, /**< name */
PP_VERSION, /**< version */
NULL, /**< summary */
NULL, /** description */
"Stu Tomlinson <stu@nosnilmot.com>", /**< author */
PP_WEBSITE, /**< homepage */
plugin_load, /**< load */
NULL, /**< unload */
NULL, /**< destroy */
NULL, /**< ui_info */
NULL, /**< extra_info */
NULL, /**< prefs_info */
NULL, /**< actions */
NULL, /**< reserved 1 */
NULL, /**< reserved 2 */
NULL, /**< reserved 3 */
NULL /**< reserved 4 */
};
static void
init_plugin(PurplePlugin *plugin) {
#ifdef ENABLE_NLS
bindtextdomain(GETTEXT_PACKAGE, PP_LOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
#endif /* ENABLE_NLS */
info.name = _("Group IM");
info.summary = _("Send an IM to a group of buddies.");
info.description = _("Adds the option to send an IM to every online "
"buddy in a group.");
}
PURPLE_INIT_PLUGIN(groupmsg, init_plugin, info)
|