#define MAILCHK_PLUGIN_ID "gtk-mailchk" #define MAILCHK_PLUGIN_DOMAIN (g_quark_from_static_string(MAILCHK_PLUGIN_ID)) 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, &st) < 0) { if (newsize) ret |= ANY_MAIL; if (st.st_mtime > st.st_atime && newsize) ret |= UNREAD_MAIL; if (newsize != oldsize && (ret & UNREAD_MAIL)) ret |= NEW_MAIL; check_timeout(gpointer data) gint count = check_mail(); PurpleBuddyList *list = purple_blist_get_default(); if (!list || !(PIDGIN_BLIST(list)->vbox)) /* guess we better build it then :P */ GtkWidget *vbox = PIDGIN_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); purple_sound_play_event(PURPLE_SOUND_POUNCE_DEFAULT, NULL); 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."); signon_cb(PurpleConnection *gc) PurpleBuddyList *list = purple_blist_get_default(); check_timeout(NULL); /* we want the box to be drawn immediately */ timer = g_timeout_add_seconds(2, check_timeout, NULL); signoff_cb(PurpleConnection *gc) PurpleBuddyList *list = purple_blist_get_default(); if ((!list || !PIDGIN_BLIST(list)->vbox) && timer) { static PidginPluginInfo * plugin_query(GError **error) const gchar * const authors[] = { "Eric Warmenhoven <eric@warmenhoven.org>", return pidgin_plugin_info_new( "name", N_("Mail Checker"), "version", DISPLAY_VERSION, "category", N_("Utility"), "summary", N_("Checks for new local mail."), "description", N_("Adds a small box to the buddy list that shows if " "website", PURPLE_WEBSITE, "abi-version", PURPLE_ABI_VERSION, plugin_load(PurplePlugin *plugin, GError **error) PurpleBuddyList *list = purple_blist_get_default(); void *conn_handle = purple_connections_get_handle(); if (!check_timeout(NULL)) { g_set_error(error, MAILCHK_PLUGIN_DOMAIN, 0, _("Could not read $MAIL " "or /var/spool/mail/$USER\n")); if (list && PIDGIN_BLIST(list)->vbox) timer = g_timeout_add_seconds(2, check_timeout, NULL); purple_signal_connect(conn_handle, "signed-on", plugin, PURPLE_CALLBACK(signon_cb), NULL); purple_signal_connect(conn_handle, "signed-off", plugin, PURPLE_CALLBACK(signoff_cb), NULL); plugin_unload(PurplePlugin *plugin, GError **error) gtk_widget_destroy(mail); PURPLE_PLUGIN_INIT(mailchk, plugin_query, plugin_load, plugin_unload);