grim/purple-plugin-pack
--leaks
org.guifications.plugins
2009-04-15, darkrain42
* msglen - Adds the current message's length to the menutray of a conversation * Copyright (C) 2008 Gary Kramlich <grim@reaperworld.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 <conversation.h> /****************************************************************************** *****************************************************************************/ PurpleConversation *conv; /****************************************************************************** *****************************************************************************/ static GHashTable *data = NULL; /****************************************************************************** *****************************************************************************/ msg_len_data_free(MsgLenData *mld) { if(mld->label && GTK_IS_LABEL(mld->label)) gtk_widget_destroy(mld->label); msg_len_data_free_helper(gpointer k, gpointer v, gpointer d) { MsgLenData *mld = (MsgLenData *)v; static void msg_len_update(PidginWindow *win, PurpleConversation *conv); msg_len_key_released_cb(GtkWidget *w, GdkEventKey *e, gpointer d) { MsgLenData *mld = (MsgLenData *)d; msg_len_update(mld->win, mld->conv); msg_len_add_signal(PidginConversation *pconv, MsgLenData *mld) { g_signal_connect(G_OBJECT(pconv->entry), G_CALLBACK(msg_len_key_released_cb), mld); msg_len_find_data(PidginWindow *win) { mld = g_hash_table_lookup(data, win); mld = g_new0(MsgLenData, 1); mld->label = gtk_label_new(""); pidgin_menu_tray_append(PIDGIN_MENU_TRAY(win->menu.tray), mld->label, gtk_widget_show(mld->label); g_signal_connect_swapped(G_OBJECT(mld->label), "destroy", G_CALLBACK(g_nullify_pointer), &mld->label); msg_len_update(PidginWindow *win, PurpleConversation *conv) { PidginConversation *gtkconv = NULL; gtkconv = PIDGIN_CONVERSATION(conv); mld = msg_len_find_data(win); count = gtk_text_buffer_get_char_count(gtkconv->entry_buffer); text = g_strdup_printf("%d", count); gtk_label_set_text(GTK_LABEL(mld->label), text); g_hash_table_insert(data, win, mld); /****************************************************************************** *****************************************************************************/ msg_len_conv_created_cb(PurpleConversation *conv, gpointer d) { PidginConversation *pconv = PIDGIN_CONVERSATION(conv); PidginWindow *win = pidgin_conv_get_window(pconv); mld = msg_len_find_data(win); msg_len_add_signal(pconv, mld); msg_len_update(win, conv); msg_len_conv_destroyed_cb(PurpleConversation *conv, gpointer d) { g_hash_table_remove(data, conv); msg_len_conv_switched_cb(PurpleConversation *conv, gpointer d) { PidginConversation *pconv = PIDGIN_CONVERSATION(conv); PidginWindow *win = pidgin_conv_get_window(pconv); msg_len_update(win, conv); /****************************************************************************** *****************************************************************************/ plugin_load(PurplePlugin *plugin) { void *conv_handle = purple_conversations_get_handle(); data = g_hash_table_new_full(g_direct_hash, g_direct_equal, purple_signal_connect(conv_handle, "conversation-created", plugin, PURPLE_CALLBACK(msg_len_conv_created_cb), NULL); purple_signal_connect(conv_handle, "deleting-conversation", plugin, PURPLE_CALLBACK(msg_len_conv_destroyed_cb), NULL); purple_signal_connect(pidgin_conversations_get_handle(), "conversation-switched", plugin, PURPLE_CALLBACK(msg_len_conv_switched_cb), NULL); for(convs = purple_get_conversations(); convs; convs = convs->next) { PurpleConversation *conv = (PurpleConversation *)convs->data; PidginConversation *pconv = PIDGIN_CONVERSATION(conv); MsgLenData *mld = msg_len_find_data(pconv->win); msg_len_add_signal(pconv, mld); msg_len_update(pconv->win, conv); plugin_unload(PurplePlugin *plugin) { g_hash_table_foreach(data, msg_len_data_free_helper, NULL); g_hash_table_destroy(data); static PurplePluginInfo info = { "gtk-plugin_pack-msglen", "Gary Kramlich <grim@reaperworld.com>", init_plugin(PurplePlugin *plugin) { bindtextdomain(GETTEXT_PACKAGE, PP_LOCALEDIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); info.name = _("Message Length"); info.summary = _("Shows the length of your current message in the menu " info.description = info.summary; PURPLE_INIT_PLUGIN(msg_len, init_plugin, info)