Mercurial > pidgin.yaz
annotate plugins/mailchk.c @ 4275:5ce5b252cdb1
[gaim-migrate @ 4526]
Nicola's Lichtmaier (niqueco) fixed a possible segfault in the account editor
and cleaned closing it up some.
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Fri, 10 Jan 2003 07:04:23 +0000 |
parents | 59751fe608c5 |
children | 1b52e29f1ffb |
rev | line source |
---|---|
4202
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4168
diff
changeset
|
1 #include "config.h" |
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4168
diff
changeset
|
2 |
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4168
diff
changeset
|
3 #ifndef GAIM_PLUGINS |
1803 | 4 #define GAIM_PLUGINS |
4202
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4168
diff
changeset
|
5 #endif |
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4168
diff
changeset
|
6 |
1803 | 7 #include "gaim.h" |
8 #include <sys/stat.h> | |
9 #include <sys/types.h> | |
10 #include <unistd.h> | |
11 | |
12 #define ANY_MAIL 0x01 | |
13 #define UNREAD_MAIL 0x02 | |
14 #define NEW_MAIL 0x04 | |
15 | |
16 static guint32 timer = 0; | |
17 static GtkWidget *mail = NULL; | |
18 | |
19 static gint check_mail() | |
20 { | |
21 static off_t oldsize = 0; | |
22 gchar *filename; | |
23 off_t newsize; | |
24 struct stat s; | |
25 gint ret = 0; | |
26 | |
27 filename = g_getenv("MAIL"); | |
28 if (!filename) | |
29 filename = g_strconcat("/var/spool/mail/", g_get_user_name(), NULL); | |
30 else | |
31 filename = g_strdup(filename); | |
32 | |
33 if (stat(filename, &s) < 0) { | |
34 g_free(filename); | |
35 return -1; | |
36 } | |
37 | |
38 newsize = s.st_size; | |
39 if (newsize) ret |= ANY_MAIL; | |
40 if (s.st_mtime > s.st_atime && newsize) ret |= UNREAD_MAIL; | |
41 if (newsize != oldsize && (ret & UNREAD_MAIL)) ret |= NEW_MAIL; | |
42 oldsize = newsize; | |
43 | |
44 g_free(filename); | |
45 | |
46 return ret; | |
47 } | |
48 | |
49 static void maildes() | |
50 { | |
51 mail = NULL; | |
52 } | |
53 | |
54 static gboolean check_timeout(gpointer data) | |
55 { | |
56 gint count = check_mail(); | |
57 | |
58 if (count == -1) | |
59 return FALSE; | |
60 | |
61 if (!blist) | |
62 return TRUE; | |
63 | |
64 if (!mail) { | |
65 /* guess we better build it then :P */ | |
66 GList *tmp = gtk_container_children(GTK_CONTAINER(blist)); | |
67 GtkWidget *vbox2 = (GtkWidget *)tmp->data; | |
68 | |
69 mail = gtk_label_new("No mail messages."); | |
70 gtk_box_pack_start(GTK_BOX(vbox2), mail, FALSE, FALSE, 0); | |
71 gtk_box_reorder_child(GTK_BOX(vbox2), mail, 1); | |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
72 g_signal_connect(GTK_OBJECT(mail), "destroy", G_CALLBACK(maildes), NULL); |
1803 | 73 gtk_widget_show(mail); |
74 } | |
75 | |
76 if (count & NEW_MAIL) | |
3060 | 77 play_sound(SND_POUNCE_DEFAULT); |
1803 | 78 |
79 if (count & UNREAD_MAIL) | |
80 gtk_label_set_text(GTK_LABEL(mail), "You have new mail!"); | |
81 else if (count & ANY_MAIL) | |
82 gtk_label_set_text(GTK_LABEL(mail), "You have mail."); | |
83 else | |
84 gtk_label_set_text(GTK_LABEL(mail), "No mail messages."); | |
85 | |
86 return TRUE; | |
87 } | |
88 | |
89 static void mail_signon(struct gaim_connection *gc) | |
90 { | |
91 if (blist && !timer) | |
4168 | 92 timer = g_timeout_add(2000, check_timeout, NULL); |
1803 | 93 } |
94 | |
95 static void mail_signoff(struct gaim_connection *gc) | |
96 { | |
2259
866bf3ced1bc
[gaim-migrate @ 2269]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1804
diff
changeset
|
97 if (!blist && timer) { |
4168 | 98 g_source_remove(timer); |
2259
866bf3ced1bc
[gaim-migrate @ 2269]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1804
diff
changeset
|
99 timer = 0; |
866bf3ced1bc
[gaim-migrate @ 2269]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1804
diff
changeset
|
100 } |
1803 | 101 } |
102 | |
103 char *gaim_plugin_init(GModule *m) | |
104 { | |
105 if (!check_timeout(NULL)) | |
106 return "Could not read $MAIL or /var/spool/mail/$USER"; | |
107 if (blist) | |
4168 | 108 timer = g_timeout_add(2000, check_timeout, NULL); |
1803 | 109 gaim_signal_connect(m, event_signon, mail_signon, NULL); |
110 gaim_signal_connect(m, event_signoff, mail_signoff, NULL); | |
111 return NULL; | |
112 } | |
113 | |
114 void gaim_plugin_remove() | |
115 { | |
116 if (timer) | |
4168 | 117 g_source_remove(timer); |
1803 | 118 timer = 0; |
119 if (mail) | |
120 gtk_widget_destroy(mail); | |
121 mail = NULL; | |
122 } | |
123 | |
3551 | 124 struct gaim_plugin_description desc; |
125 struct gaim_plugin_description *gaim_plugin_desc() { | |
126 desc.api_version = PLUGIN_API_VERSION; | |
127 desc.name = g_strdup("Mail Checker"); | |
128 desc.version = g_strdup(VERSION); | |
129 desc.description = g_strdup("Checks for new local mail."); | |
130 desc.authors = g_strdup("Eric Warmehoven <eric@warmenhoven.org>"); | |
131 desc.url = g_strdup(WEBSITE); | |
132 return &desc; | |
133 } | |
134 | |
1803 | 135 char *name() |
136 { | |
137 return "Mail Check"; | |
138 } | |
139 | |
140 char *description() | |
141 { | |
142 return "Checks for new local mail"; | |
143 } |