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
|
/*
* simfix - fix received messages from SIM clients in Purple
*
* (C) Copyright 2005-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 <plugin.h>
#include <debug.h>
#include <blist.h>
#include <signals.h>
#include <util.h>
static gboolean
receiving_im_msg_cb(PurpleAccount *account, char **sender, char **message,
PurpleConversation *conv, int *flags, void *data)
{
PurpleBuddy *buddy;
GSList *buds;
gboolean simuser = FALSE;
for (buds = purple_find_buddies(account, *sender); buds; buds = buds->next)
{
buddy = buds->data;
if (purple_blist_node_get_bool((PurpleBlistNode*)buddy, "sim-user"))
simuser = TRUE;
}
if (simuser)
{
char *tmp, *stripped;
tmp = purple_unescape_html(*message);
stripped = purple_markup_strip_html(tmp);
g_free(tmp);
g_free(*message);
*message = stripped;
}
return FALSE;
}
static void
simfix_set_simuser(PurpleBlistNode *node, gpointer data)
{
gboolean simuser = GPOINTER_TO_INT(data);
purple_blist_node_set_bool(node, "sim-user", simuser);
}
static void
simfix_extended_menu_cb(PurpleBlistNode *node, GList **m)
{
PurpleMenuAction *bna = NULL;
if (purple_blist_node_get_flags(node) & PURPLE_BLIST_NODE_FLAG_NO_SAVE)
return;
if(!PURPLE_BLIST_NODE_IS_BUDDY(node))
return;
if (!purple_blist_node_get_bool(node, "sim-user"))
bna = purple_menu_action_new("Set SIM user", PURPLE_CALLBACK(simfix_set_simuser),
GINT_TO_POINTER(TRUE), NULL);
else
bna = purple_menu_action_new("Unset SIM user", PURPLE_CALLBACK(simfix_set_simuser),
GINT_TO_POINTER(FALSE), NULL);
*m = g_list_append(*m, bna);
}
static gboolean
plugin_load(PurplePlugin *plugin)
{
purple_signal_connect(purple_conversations_get_handle(), "receiving-im-msg",
plugin, PURPLE_CALLBACK(receiving_im_msg_cb), NULL);
purple_signal_connect(purple_blist_get_handle(), "blist-node-extended-menu",
plugin, PURPLE_CALLBACK(simfix_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 */
PURPLE_PLUGIN_STANDARD, /**< ui_requirement */
0, /**< flags */
NULL, /**< dependencies */
PURPLE_PRIORITY_DEFAULT, /**< priority */
"core-plugin_pack-simfix", /**< 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
info.name = _("SIM-fix");
info.summary = _("Fix messages from broken SIM clients.");
info.description = _("Fixes messages received from broken SIM clients by "
"stripping HTML from them. The buddy must be on your "
"list and set as a SIM user.");
}
PURPLE_INIT_PLUGIN(simfix, init_plugin, info)
|