gee
oldstatus
2005-09-19, Nathan Walp
#include "conversation.h" #define MAILCHK_PLUGIN_ID "gtk-mailchk" static guint32 timer = 0; static GtkWidget *mail = NULL; static off_t oldsize = 0; filename = g_strdup(g_getenv("MAIL")); filename = g_strconcat("/var/spool/mail/", g_get_user_name(), NULL); if (g_stat(filename, &s) < 0) { if (newsize) ret |= ANY_MAIL; if (s.st_mtime > s.st_atime && newsize) ret |= UNREAD_MAIL; if (newsize != oldsize && (ret & UNREAD_MAIL)) ret |= NEW_MAIL; static gboolean check_timeout(gpointer data) gint count = check_mail(); GaimBuddyList *list = gaim_get_blist(); if (!list || !GAIM_IS_GTK_BLIST(list) || !(GAIM_GTK_BLIST(list)->vbox)) /* guess we better build it then :P */ GtkWidget *vbox = GAIM_GTK_BLIST(list)->vbox; mail = gtk_label_new("No mail messages."); gtk_box_pack_start(GTK_BOX(vbox), mail, FALSE, FALSE, 0); gtk_box_reorder_child(GTK_BOX(vbox), mail, 1); g_signal_connect(G_OBJECT(mail), "destroy", G_CALLBACK(destroy_cb), NULL); gaim_sound_play_event(GAIM_SOUND_POUNCE_DEFAULT); gtk_label_set_text(GTK_LABEL(mail), "You have new mail!"); else if (count & ANY_MAIL) gtk_label_set_text(GTK_LABEL(mail), "You have mail."); gtk_label_set_text(GTK_LABEL(mail), "No mail messages."); static void signon_cb(GaimConnection *gc) GaimBuddyList *list = gaim_get_blist(); if (list && GAIM_IS_GTK_BLIST(list) && !timer) { check_timeout(NULL); /* we want the box to be drawn immediately */ timer = g_timeout_add(2000, check_timeout, NULL); static void signoff_cb(GaimConnection *gc) GaimBuddyList *list = gaim_get_blist(); if ((!list || !GAIM_IS_GTK_BLIST(list) || !GAIM_GTK_BLIST(list)->vbox) && timer) { plugin_load(GaimPlugin *plugin) GaimBuddyList *list = gaim_get_blist(); void *conn_handle = gaim_connections_get_handle(); if (!check_timeout(NULL)) { gaim_debug_warning("mailchk", "Could not read $MAIL or /var/spool/mail/$USER"); if (list && GAIM_IS_GTK_BLIST(list) && GAIM_GTK_BLIST(list)->vbox) timer = g_timeout_add(2000, check_timeout, NULL); gaim_signal_connect(conn_handle, "signed-on", plugin, GAIM_CALLBACK(signon_cb), NULL); gaim_signal_connect(conn_handle, "signed-off", plugin, GAIM_CALLBACK(signoff_cb), NULL); plugin_unload(GaimPlugin *plugin) gtk_widget_destroy(mail); static GaimPluginInfo info = N_("Checks for new local mail."), N_("Adds a small box to the buddy list that" " shows if you have new mail."), "Eric Warmenhoven <eric@warmenhoven.org>", init_plugin(GaimPlugin *plugin) GAIM_INIT_PLUGIN(mailchk, init_plugin, info)