Mercurial > pidgin
view plugins/mailchk.c @ 6463:eafaf58b61b6
[gaim-migrate @ 6972]
(23:03:49) Robot101: LSchiere: GAIM_{ERROR,WARNING,INFO,...} and EDIT_{GC,GROUP,BUDDY} in ui.h are unused and can be garbage collected
(23:04:10) Robot101: HEH
(23:04:16) Robot101: I never knew core.h had trogdor in it =)
(23:04:26) LSchiere: those are semi-namespaced, does ChipX86|Gone have plans for them?
(23:04:41) Robot101: they're deprecated.
(23:04:46) Robot101: not used anywhere in code
(23:05:01) Robot101: left over garbage from a subsystem rewritten years ago... =)
(23:05:26) LSchiere: icq.c uses GAIM_ERROR
(23:06:05) Robot101: icq.c hasn't had a rat's chance in hell of compiling since about 0.64 =)
(23:06:16) LSchiere: lol, yeah that's probly true
(23:06:30) Robot101: it still uses do_error_dialog
(23:06:35) Robot101: which is, er, gone. =)
(23:06:56) LSchiere: GAIM_LOGO is that used?
(23:07:04) Robot101: no
(23:07:18) Robot101: those 4 were for selecting the icons in the error dialog
(23:07:23) Robot101: which is long gone
(23:07:34) Robot101: and I have NFI what EDIT_* were, but they're not used either
(23:08:06) Robot101: some day soon ui.h will be totally gone
(23:08:07) ***Robot101 drools
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Thu, 14 Aug 2003 03:08:25 +0000 |
parents | 8f94cce8faa5 |
children | 70d5122bc3ff |
line wrap: on
line source
#include "internal.h" #include "blist.h" #include "gtkblist.h" #include "debug.h" #include "sound.h" #include "gtkplugin.h" #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #define MAILCHK_PLUGIN_ID "gtk-mailchk" #define ANY_MAIL 0x01 #define UNREAD_MAIL 0x02 #define NEW_MAIL 0x04 static guint32 timer = 0; static GtkWidget *mail = NULL; static gint check_mail() { static off_t oldsize = 0; gchar *filename; off_t newsize; struct stat s; gint ret = 0; filename = g_strdup(g_getenv("MAIL")); if (!filename) filename = g_strconcat("/var/spool/mail/", g_get_user_name(), NULL); if (stat(filename, &s) < 0) { g_free(filename); return -1; } newsize = s.st_size; 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; oldsize = newsize; g_free(filename); return ret; } static void destroy_cb() { mail = NULL; } static gboolean check_timeout(gpointer data) { gint count = check_mail(); struct gaim_buddy_list *list = gaim_get_blist(); if (count == -1) return FALSE; if (!list || !GAIM_IS_GTK_BLIST(list) || !(GAIM_GTK_BLIST(list)->vbox)) return TRUE; if (!mail) { /* 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); gtk_widget_show(mail); } if (count & NEW_MAIL) gaim_sound_play_event(GAIM_SOUND_POUNCE_DEFAULT); if (count & UNREAD_MAIL) 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."); else gtk_label_set_text(GTK_LABEL(mail), "No mail messages."); return TRUE; } static void signon_cb(GaimConnection *gc) { struct gaim_buddy_list *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) { struct gaim_buddy_list *list = gaim_get_blist(); if ((!list || !GAIM_IS_GTK_BLIST(list) || !GAIM_GTK_BLIST(list)->vbox) && timer) { g_source_remove(timer); timer = 0; } } /* * EXPORTED FUNCTIONS */ static gboolean plugin_load(GaimPlugin *plugin) { struct gaim_buddy_list *list = gaim_get_blist(); if (!check_timeout(NULL)) { gaim_debug(GAIM_DEBUG_WARNING, "mailchk", "Could not read $MAIL or /var/spool/mail/$USER"); return FALSE; } if (list && GAIM_IS_GTK_BLIST(list) && GAIM_GTK_BLIST(list)->vbox) timer = g_timeout_add(2000, check_timeout, NULL); gaim_signal_connect(plugin, event_signon, signon_cb, NULL); gaim_signal_connect(plugin, event_signoff, signoff_cb, NULL); return TRUE; } static gboolean plugin_unload(GaimPlugin *plugin) { if (timer) g_source_remove(timer); timer = 0; if (mail) gtk_widget_destroy(mail); mail = NULL; return TRUE; } static GaimPluginInfo info = { 2, GAIM_PLUGIN_STANDARD, GAIM_GTK_PLUGIN_TYPE, 0, NULL, GAIM_PRIORITY_DEFAULT, MAILCHK_PLUGIN_ID, N_("Mail Checker"), VERSION, N_("Checks for new local mail."), N_("Checks for new local mail."), "Eric Warmenhoven <eric@warmenhoven.org>", GAIM_WEBSITE, plugin_load, plugin_unload, NULL, NULL, NULL }; static void init_plugin(GaimPlugin *plugin) { } GAIM_INIT_PLUGIN(mailchk, init_plugin, info)