Mercurial > pidgin
annotate plugins/mailchk.c @ 6480:d35482c12d51
[gaim-migrate @ 6994]
iconv -f Windows-1251 -t utf-8 bg.po
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sat, 16 Aug 2003 15:06:14 +0000 |
parents | 8f94cce8faa5 |
children | 70d5122bc3ff |
rev | line source |
---|---|
6287 | 1 #include "internal.h" |
2 | |
5255 | 3 #include "blist.h" |
4 #include "gtkblist.h" | |
6287 | 5 #include "debug.h" |
4576 | 6 #include "sound.h" |
6287 | 7 #include "gtkplugin.h" |
8 | |
1803 | 9 #include <sys/stat.h> |
10 #include <sys/types.h> | |
11 #include <unistd.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(); |
116 if (!check_timeout(NULL)) { | |
117 gaim_debug(GAIM_DEBUG_WARNING, "mailchk", "Could not read $MAIL or /var/spool/mail/$USER"); | |
118 return FALSE; | |
119 } | |
120 | |
6287 | 121 if (list && GAIM_IS_GTK_BLIST(list) && GAIM_GTK_BLIST(list)->vbox) |
4168 | 122 timer = g_timeout_add(2000, check_timeout, NULL); |
5255 | 123 |
124 gaim_signal_connect(plugin, event_signon, signon_cb, NULL); | |
125 gaim_signal_connect(plugin, event_signoff, signoff_cb, NULL); | |
126 | |
127 return TRUE; | |
1803 | 128 } |
129 | |
5255 | 130 static gboolean |
131 plugin_unload(GaimPlugin *plugin) | |
1803 | 132 { |
133 if (timer) | |
4168 | 134 g_source_remove(timer); |
1803 | 135 timer = 0; |
136 if (mail) | |
137 gtk_widget_destroy(mail); | |
138 mail = NULL; | |
5255 | 139 |
140 return TRUE; | |
1803 | 141 } |
142 | |
5255 | 143 static GaimPluginInfo info = |
144 { | |
6287 | 145 2, |
146 GAIM_PLUGIN_STANDARD, | |
147 GAIM_GTK_PLUGIN_TYPE, | |
148 0, | |
149 NULL, | |
150 GAIM_PRIORITY_DEFAULT, | |
151 MAILCHK_PLUGIN_ID, | |
152 N_("Mail Checker"), | |
153 VERSION, | |
5255 | 154 N_("Checks for new local mail."), |
155 N_("Checks for new local mail."), | |
6287 | 156 "Eric Warmenhoven <eric@warmenhoven.org>", |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6287
diff
changeset
|
157 GAIM_WEBSITE, |
6287 | 158 plugin_load, |
159 plugin_unload, | |
160 NULL, | |
161 NULL, | |
162 NULL | |
5255 | 163 }; |
164 | |
165 static void | |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
166 init_plugin(GaimPlugin *plugin) |
5255 | 167 { |
3551 | 168 } |
169 | |
6063 | 170 GAIM_INIT_PLUGIN(mailchk, init_plugin, info) |