Mercurial > pidgin
comparison plugins/mailchk.c @ 1803:d36f759df56d
[gaim-migrate @ 1813]
mailcheck plugin
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Sat, 05 May 2001 00:15:23 +0000 |
parents | |
children | c7b288ea3892 |
comparison
equal
deleted
inserted
replaced
1802:44e9d786a28c | 1803:d36f759df56d |
---|---|
1 #define GAIM_PLUGINS | |
2 #include "gaim.h" | |
3 #include <sys/stat.h> | |
4 #include <sys/types.h> | |
5 #include <unistd.h> | |
6 | |
7 #define ANY_MAIL 0x01 | |
8 #define UNREAD_MAIL 0x02 | |
9 #define NEW_MAIL 0x04 | |
10 | |
11 static guint32 timer = 0; | |
12 static GtkWidget *mail = NULL; | |
13 | |
14 static gint check_mail() | |
15 { | |
16 static off_t oldsize = 0; | |
17 gchar *filename; | |
18 off_t newsize; | |
19 struct stat s; | |
20 gint ret = 0; | |
21 | |
22 filename = g_getenv("MAIL"); | |
23 if (!filename) | |
24 filename = g_strconcat("/var/spool/mail/", g_get_user_name(), NULL); | |
25 else | |
26 filename = g_strdup(filename); | |
27 | |
28 if (stat(filename, &s) < 0) { | |
29 g_free(filename); | |
30 return -1; | |
31 } | |
32 | |
33 newsize = s.st_size; | |
34 if (newsize) ret |= ANY_MAIL; | |
35 if (s.st_mtime > s.st_atime && newsize) ret |= UNREAD_MAIL; | |
36 if (newsize != oldsize && (ret & UNREAD_MAIL)) ret |= NEW_MAIL; | |
37 oldsize = newsize; | |
38 | |
39 g_free(filename); | |
40 | |
41 return ret; | |
42 } | |
43 | |
44 static void maildes() | |
45 { | |
46 mail = NULL; | |
47 } | |
48 | |
49 static gboolean check_timeout(gpointer data) | |
50 { | |
51 gint count = check_mail(); | |
52 char buf[256]; | |
53 | |
54 if (count == -1) | |
55 return FALSE; | |
56 | |
57 if (!blist) | |
58 return TRUE; | |
59 | |
60 if (!mail) { | |
61 /* guess we better build it then :P */ | |
62 GList *tmp = gtk_container_children(GTK_CONTAINER(blist)); | |
63 GtkWidget *vbox2 = (GtkWidget *)tmp->data; | |
64 | |
65 mail = gtk_label_new("No mail messages."); | |
66 gtk_label_set_justify(GTK_LABEL(mail), GTK_JUSTIFY_LEFT); | |
67 gtk_box_pack_start(GTK_BOX(vbox2), mail, FALSE, FALSE, 0); | |
68 gtk_box_reorder_child(GTK_BOX(vbox2), mail, 1); | |
69 gtk_signal_connect(GTK_OBJECT(mail), "destroy", GTK_SIGNAL_FUNC(maildes), NULL); | |
70 gtk_widget_show(mail); | |
71 } | |
72 | |
73 if (count & NEW_MAIL) | |
74 play_sound(POUNCE_DEFAULT); | |
75 | |
76 if (count & UNREAD_MAIL) | |
77 gtk_label_set_text(GTK_LABEL(mail), "You have new mail!"); | |
78 else if (count & ANY_MAIL) | |
79 gtk_label_set_text(GTK_LABEL(mail), "You have mail."); | |
80 else | |
81 gtk_label_set_text(GTK_LABEL(mail), "No mail messages."); | |
82 | |
83 return TRUE; | |
84 } | |
85 | |
86 static void mail_signon(struct gaim_connection *gc) | |
87 { | |
88 if (blist && !timer) | |
89 timer = gtk_timeout_add(2000, check_timeout, NULL); | |
90 } | |
91 | |
92 static void mail_signoff(struct gaim_connection *gc) | |
93 { | |
94 if (timer) | |
95 gtk_timeout_remove(timer); | |
96 timer = 0; | |
97 } | |
98 | |
99 char *gaim_plugin_init(GModule *m) | |
100 { | |
101 if (!check_timeout(NULL)) | |
102 return "Could not read $MAIL or /var/spool/mail/$USER"; | |
103 if (blist) | |
104 timer = gtk_timeout_add(2000, check_timeout, NULL); | |
105 gaim_signal_connect(m, event_signon, mail_signon, NULL); | |
106 gaim_signal_connect(m, event_signoff, mail_signoff, NULL); | |
107 return NULL; | |
108 } | |
109 | |
110 void gaim_plugin_remove() | |
111 { | |
112 if (timer) | |
113 gtk_timeout_remove(timer); | |
114 timer = 0; | |
115 if (mail) | |
116 gtk_widget_destroy(mail); | |
117 mail = NULL; | |
118 } | |
119 | |
120 char *name() | |
121 { | |
122 return "Mail Check"; | |
123 } | |
124 | |
125 char *description() | |
126 { | |
127 return "Checks for new local mail"; | |
128 } |