Mercurial > pidgin.yaz
annotate plugins/mailchk.c @ 7343:3e28b2646afd
[gaim-migrate @ 7934]
We'll keep it!
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 27 Oct 2003 04:03:53 +0000 |
parents | cce494e69d68 |
children | 58e02f309485 |
rev | line source |
---|---|
6287 | 1 #include "internal.h" |
6677 | 2 #include "gtkinternal.h" |
6287 | 3 |
5255 | 4 #include "blist.h" |
6677 | 5 #include "conversation.h" |
6287 | 6 #include "debug.h" |
6677 | 7 #include "signals.h" |
4576 | 8 #include "sound.h" |
6677 | 9 |
10 #include "gtkblist.h" | |
6287 | 11 #include "gtkplugin.h" |
12 | |
5255 | 13 #define MAILCHK_PLUGIN_ID "gtk-mailchk" |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4655
diff
changeset
|
14 |
1803 | 15 #define ANY_MAIL 0x01 |
16 #define UNREAD_MAIL 0x02 | |
17 #define NEW_MAIL 0x04 | |
18 | |
19 static guint32 timer = 0; | |
20 static GtkWidget *mail = NULL; | |
21 | |
22 static gint check_mail() | |
23 { | |
24 static off_t oldsize = 0; | |
25 gchar *filename; | |
26 off_t newsize; | |
27 struct stat s; | |
28 gint ret = 0; | |
29 | |
4655 | 30 filename = g_strdup(g_getenv("MAIL")); |
1803 | 31 if (!filename) |
32 filename = g_strconcat("/var/spool/mail/", g_get_user_name(), NULL); | |
33 | |
34 if (stat(filename, &s) < 0) { | |
35 g_free(filename); | |
36 return -1; | |
37 } | |
38 | |
39 newsize = s.st_size; | |
40 if (newsize) ret |= ANY_MAIL; | |
41 if (s.st_mtime > s.st_atime && newsize) ret |= UNREAD_MAIL; | |
42 if (newsize != oldsize && (ret & UNREAD_MAIL)) ret |= NEW_MAIL; | |
43 oldsize = newsize; | |
44 | |
45 g_free(filename); | |
46 | |
47 return ret; | |
48 } | |
49 | |
5255 | 50 static void destroy_cb() |
1803 | 51 { |
52 mail = NULL; | |
53 } | |
54 | |
55 static gboolean check_timeout(gpointer data) | |
56 { | |
57 gint count = check_mail(); | |
5255 | 58 struct gaim_buddy_list *list = gaim_get_blist(); |
6287 | 59 |
1803 | 60 if (count == -1) |
61 return FALSE; | |
62 | |
6287 | 63 if (!list || !GAIM_IS_GTK_BLIST(list) || !(GAIM_GTK_BLIST(list)->vbox)) |
1803 | 64 return TRUE; |
65 | |
66 if (!mail) { | |
67 /* guess we better build it then :P */ | |
6287 | 68 GtkWidget *vbox = GAIM_GTK_BLIST(list)->vbox; |
1803 | 69 |
70 mail = gtk_label_new("No mail messages."); | |
5255 | 71 gtk_box_pack_start(GTK_BOX(vbox), mail, FALSE, FALSE, 0); |
72 gtk_box_reorder_child(GTK_BOX(vbox), mail, 1); | |
5314
1f901484599d
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5255
diff
changeset
|
73 g_signal_connect(G_OBJECT(mail), "destroy", G_CALLBACK(destroy_cb), NULL); |
1803 | 74 gtk_widget_show(mail); |
75 } | |
76 | |
77 if (count & NEW_MAIL) | |
4576 | 78 gaim_sound_play_event(GAIM_SOUND_POUNCE_DEFAULT); |
1803 | 79 |
80 if (count & UNREAD_MAIL) | |
81 gtk_label_set_text(GTK_LABEL(mail), "You have new mail!"); | |
82 else if (count & ANY_MAIL) | |
83 gtk_label_set_text(GTK_LABEL(mail), "You have mail."); | |
84 else | |
85 gtk_label_set_text(GTK_LABEL(mail), "No mail messages."); | |
86 | |
87 return TRUE; | |
88 } | |
89 | |
6287 | 90 static void signon_cb(GaimConnection *gc) |
1803 | 91 { |
5255 | 92 struct gaim_buddy_list *list = gaim_get_blist(); |
6287 | 93 if (list && GAIM_IS_GTK_BLIST(list) && !timer) { |
94 check_timeout(NULL); /* we want the box to be drawn immediately */ | |
4168 | 95 timer = g_timeout_add(2000, check_timeout, NULL); |
6287 | 96 } |
1803 | 97 } |
98 | |
6287 | 99 static void signoff_cb(GaimConnection *gc) |
1803 | 100 { |
5255 | 101 struct gaim_buddy_list *list = gaim_get_blist(); |
6287 | 102 if ((!list || !GAIM_IS_GTK_BLIST(list) || !GAIM_GTK_BLIST(list)->vbox) && timer) { |
4168 | 103 g_source_remove(timer); |
2259
866bf3ced1bc
[gaim-migrate @ 2269]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1804
diff
changeset
|
104 timer = 0; |
866bf3ced1bc
[gaim-migrate @ 2269]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1804
diff
changeset
|
105 } |
1803 | 106 } |
107 | |
5255 | 108 /* |
109 * EXPORTED FUNCTIONS | |
110 */ | |
111 | |
112 static gboolean | |
113 plugin_load(GaimPlugin *plugin) | |
1803 | 114 { |
5255 | 115 struct gaim_buddy_list *list = gaim_get_blist(); |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
116 void *conn_handle = gaim_connections_get_handle(); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
117 |
5255 | 118 if (!check_timeout(NULL)) { |
119 gaim_debug(GAIM_DEBUG_WARNING, "mailchk", "Could not read $MAIL or /var/spool/mail/$USER"); | |
120 return FALSE; | |
121 } | |
122 | |
6287 | 123 if (list && GAIM_IS_GTK_BLIST(list) && GAIM_GTK_BLIST(list)->vbox) |
4168 | 124 timer = g_timeout_add(2000, check_timeout, NULL); |
5255 | 125 |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
126 gaim_signal_connect(conn_handle, "signed-on", |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
127 plugin, GAIM_CALLBACK(signon_cb), NULL); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
128 gaim_signal_connect(conn_handle, "signed-off", |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
129 plugin, GAIM_CALLBACK(signoff_cb), NULL); |
5255 | 130 |
131 return TRUE; | |
1803 | 132 } |
133 | |
5255 | 134 static gboolean |
135 plugin_unload(GaimPlugin *plugin) | |
1803 | 136 { |
137 if (timer) | |
4168 | 138 g_source_remove(timer); |
1803 | 139 timer = 0; |
140 if (mail) | |
141 gtk_widget_destroy(mail); | |
142 mail = NULL; | |
5255 | 143 |
144 return TRUE; | |
1803 | 145 } |
146 | |
5255 | 147 static GaimPluginInfo info = |
148 { | |
6287 | 149 2, |
150 GAIM_PLUGIN_STANDARD, | |
151 GAIM_GTK_PLUGIN_TYPE, | |
152 0, | |
153 NULL, | |
154 GAIM_PRIORITY_DEFAULT, | |
155 MAILCHK_PLUGIN_ID, | |
156 N_("Mail Checker"), | |
157 VERSION, | |
5255 | 158 N_("Checks for new local mail."), |
159 N_("Checks for new local mail."), | |
6287 | 160 "Eric Warmenhoven <eric@warmenhoven.org>", |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6287
diff
changeset
|
161 GAIM_WEBSITE, |
6287 | 162 plugin_load, |
163 plugin_unload, | |
164 NULL, | |
165 NULL, | |
166 NULL | |
5255 | 167 }; |
168 | |
169 static void | |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
170 init_plugin(GaimPlugin *plugin) |
5255 | 171 { |
3551 | 172 } |
173 | |
6063 | 174 GAIM_INIT_PLUGIN(mailchk, init_plugin, info) |