Created
June 17, 2010 13:16
-
-
Save jorgeatorres/442100 to your computer and use it in GitHub Desktop.
gaim plugin to reverse/l337 chats before sending them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This Gaim plugin reverses/1337s text before sending it. | |
*/ | |
#include <glib.h> | |
#include "internal.h" | |
#include "debug.h" | |
#include "conversation.h" | |
#include "notify.h" | |
#include "signals.h" | |
#include "plugin.h" | |
#include "version.h" | |
#include "gtkplugin.h" | |
#include "gtkutils.h" | |
#define TEXT_REVERSE_PLUGIN_ID "gtk-jtorresh-text-reverse" | |
#define DO_REVERSE_KEY "/plugins/gtk/reverse-text/reverse" | |
#define DO_LEET_KEY "/plugins/gtk/reverse-text/leet" | |
typedef struct | |
{ | |
gchar *orig; | |
gchar *replace; | |
} LeetReplacement; | |
static LeetReplacement leet_replacements[52] = { | |
{ "a", "4" }, | |
{ "b", "8" }, | |
{ "e", "3" }, | |
{ "g", "6" }, | |
{ "i", "1" }, | |
{ "l", "|_" }, | |
{ "m", "|\\/|" }, | |
{ "o", "0" }, | |
{ "s", "5" }, | |
{ "t", "7" } | |
}; | |
static gboolean do_reverse = FALSE; | |
static gboolean do_leet = FALSE; | |
static gchar * | |
str_substitute (const gchar *msg, const gchar *orig, const gchar *repl) | |
{ | |
gchar **splitted = g_strsplit (msg, orig, 0); | |
gchar *joined = g_strjoinv (repl, splitted); | |
g_strfreev (splitted); | |
return joined; | |
} | |
static gboolean | |
reverse_text_cb (GaimAccount *account, const char *who, char **message, | |
GaimConversation *conv, GaimMessageFlags flags) | |
{ | |
char *msg = g_strdup (*message); | |
free (*message); | |
if (do_reverse) { | |
if (g_utf8_validate (msg, -1, NULL)) { | |
char *new_msg = g_utf8_strreverse (msg, -1); | |
g_free (msg); | |
msg = new_msg; | |
} else { | |
g_strreverse (msg); | |
} | |
} | |
if (do_leet) { | |
int k; | |
for (k = 0; k < 26; k++) { | |
LeetReplacement lr = leet_replacements[k]; | |
if (g_strrstr (msg, lr.orig) != NULL) { | |
char *new_msg = str_substitute (msg, lr.orig, lr.replace); | |
g_free (msg); | |
msg = new_msg; | |
} | |
} | |
} | |
*message = msg; | |
return FALSE; | |
} | |
static gboolean | |
plugin_load (GaimPlugin *plugin) | |
{ | |
void *handle = gaim_conversations_get_handle (); | |
gaim_signal_connect (handle, "writing-im-msg", plugin, GAIM_CALLBACK (reverse_text_cb), NULL); | |
do_reverse = gaim_prefs_get_bool (DO_REVERSE_KEY); | |
do_leet = gaim_prefs_get_bool (DO_LEET_KEY); | |
return TRUE; | |
} | |
static gboolean | |
plugin_unload (GaimPlugin *plugin) | |
{ | |
void *handle = gaim_conversations_get_handle (); | |
gaim_signal_disconnect (handle, "writing-im-msg", plugin, GAIM_CALLBACK (reverse_text_cb)); | |
return TRUE; | |
} | |
static void | |
toggle_reverse_cb (GtkToggleButton *button) | |
{ | |
do_reverse = gtk_toggle_button_get_active (button); | |
gaim_prefs_set_bool (DO_REVERSE_KEY, do_reverse); | |
} | |
static void | |
toggle_leet_cb (GtkToggleButton *button) | |
{ | |
do_leet = gtk_toggle_button_get_active (button); | |
gaim_prefs_set_bool (DO_LEET_KEY, do_leet); | |
} | |
static GtkWidget * | |
get_config_frame (GaimPlugin *plugin) | |
{ | |
GtkWidget *vbox, *frame, *toggle; | |
vbox = gtk_vbox_new (FALSE, 18); | |
frame = gaim_gtk_make_frame (vbox, "Text Reverse Configuration"); | |
toggle = gtk_check_button_new_with_label ("Send text reversed"); | |
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), do_reverse); | |
g_signal_connect (G_OBJECT (toggle), "toggled", G_CALLBACK (toggle_reverse_cb), NULL); | |
gtk_box_pack_start (GTK_BOX (frame), toggle, FALSE, FALSE, 0); | |
toggle = gtk_check_button_new_with_label ("Send text using 1337 speak"); | |
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), do_leet); | |
g_signal_connect (G_OBJECT (toggle), "toggled", G_CALLBACK (toggle_leet_cb), NULL); | |
gtk_box_pack_end (GTK_BOX (frame), toggle, FALSE, FALSE, 0); | |
gtk_widget_show_all (vbox); | |
return vbox; | |
} | |
static GaimGtkPluginUiInfo ui_info = { | |
get_config_frame | |
}; | |
static GaimPluginInfo info = { | |
GAIM_PLUGIN_MAGIC, | |
GAIM_MAJOR_VERSION, | |
GAIM_MINOR_VERSION, | |
GAIM_PLUGIN_STANDARD, /* type */ | |
GAIM_GTK_PLUGIN_TYPE, /* ui_requirement */ | |
0, /* flags */ | |
NULL, /* dependencies */ | |
GAIM_PRIORITY_DEFAULT, /* priority */ | |
TEXT_REVERSE_PLUGIN_ID, /* id */ | |
"Text Reverse", /* name */ | |
"0.1", /* version */ | |
"Reverses typed text in conversations", /* summary */ | |
NULL, /* description */ | |
"Jorge Torres <jorge@0xfee1dead.org>", /* author */ | |
"http://0xfee1dead.org", /* website */ | |
plugin_load, /* load */ | |
plugin_unload, /* unload */ | |
NULL, /* destroy */ | |
&ui_info, | |
NULL, | |
NULL, | |
NULL | |
}; | |
static void | |
init_plugin (GaimPlugin *plugin) | |
{ | |
gaim_prefs_add_none ("/plugins/gtk/text-reverse"); | |
gaim_prefs_add_bool (DO_REVERSE_KEY, do_reverse); | |
gaim_prefs_add_bool (DO_LEET_KEY, do_leet); | |
} | |
GAIM_INIT_PLUGIN (hello_world, init_plugin, info); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment