Mercurial > pidgin.yaz
annotate plugins/mailchk.c @ 8658:4133c85d76f7
[gaim-migrate @ 9410]
Fix the problem mentioned on gaim-devel:
"Crash when 'Log your own signons/idleness/awayness' is on and a
connection is cancelled while connecting"
There is a flaw in Gaim here.
"You have signed on" can be written to the system log before "You have
signed off." This happens when you disconnect an account while it is
connected. It's an extremely minor problem and I don't feel like
fixing it.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Wed, 14 Apr 2004 04:04:42 +0000 |
parents | 58e02f309485 |
children | d7b8eb1f0a18 |
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" |
8598 | 12 #include "gtksound.h" |
6287 | 13 |
5255 | 14 #define MAILCHK_PLUGIN_ID "gtk-mailchk" |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4655
diff
changeset
|
15 |
1803 | 16 #define ANY_MAIL 0x01 |
17 #define UNREAD_MAIL 0x02 | |
18 #define NEW_MAIL 0x04 | |
19 | |
20 static guint32 timer = 0; | |
21 static GtkWidget *mail = NULL; | |
22 | |
23 static gint check_mail() | |
24 { | |
25 static off_t oldsize = 0; | |
26 gchar *filename; | |
27 off_t newsize; | |
28 struct stat s; | |
29 gint ret = 0; | |
30 | |
4655 | 31 filename = g_strdup(g_getenv("MAIL")); |
1803 | 32 if (!filename) |
33 filename = g_strconcat("/var/spool/mail/", g_get_user_name(), NULL); | |
34 | |
35 if (stat(filename, &s) < 0) { | |
36 g_free(filename); | |
37 return -1; | |
38 } | |
39 | |
40 newsize = s.st_size; | |
41 if (newsize) ret |= ANY_MAIL; | |
42 if (s.st_mtime > s.st_atime && newsize) ret |= UNREAD_MAIL; | |
43 if (newsize != oldsize && (ret & UNREAD_MAIL)) ret |= NEW_MAIL; | |
44 oldsize = newsize; | |
45 | |
46 g_free(filename); | |
47 | |
48 return ret; | |
49 } | |
50 | |
5255 | 51 static void destroy_cb() |
1803 | 52 { |
53 mail = NULL; | |
54 } | |
55 | |
56 static gboolean check_timeout(gpointer data) | |
57 { | |
58 gint count = check_mail(); | |
8598 | 59 GaimBuddyList *list = gaim_get_blist(); |
6287 | 60 |
1803 | 61 if (count == -1) |
62 return FALSE; | |
63 | |
6287 | 64 if (!list || !GAIM_IS_GTK_BLIST(list) || !(GAIM_GTK_BLIST(list)->vbox)) |
1803 | 65 return TRUE; |
66 | |
67 if (!mail) { | |
68 /* guess we better build it then :P */ | |
6287 | 69 GtkWidget *vbox = GAIM_GTK_BLIST(list)->vbox; |
1803 | 70 |
71 mail = gtk_label_new("No mail messages."); | |
5255 | 72 gtk_box_pack_start(GTK_BOX(vbox), mail, FALSE, FALSE, 0); |
73 gtk_box_reorder_child(GTK_BOX(vbox), mail, 1); | |
5314
1f901484599d
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5255
diff
changeset
|
74 g_signal_connect(G_OBJECT(mail), "destroy", G_CALLBACK(destroy_cb), NULL); |
1803 | 75 gtk_widget_show(mail); |
76 } | |
77 | |
78 if (count & NEW_MAIL) | |
4576 | 79 gaim_sound_play_event(GAIM_SOUND_POUNCE_DEFAULT); |
1803 | 80 |
81 if (count & UNREAD_MAIL) | |
82 gtk_label_set_text(GTK_LABEL(mail), "You have new mail!"); | |
83 else if (count & ANY_MAIL) | |
84 gtk_label_set_text(GTK_LABEL(mail), "You have mail."); | |
85 else | |
86 gtk_label_set_text(GTK_LABEL(mail), "No mail messages."); | |
87 | |
88 return TRUE; | |
89 } | |
90 | |
6287 | 91 static void signon_cb(GaimConnection *gc) |
1803 | 92 { |
8598 | 93 GaimBuddyList *list = gaim_get_blist(); |
6287 | 94 if (list && GAIM_IS_GTK_BLIST(list) && !timer) { |
95 check_timeout(NULL); /* we want the box to be drawn immediately */ | |
4168 | 96 timer = g_timeout_add(2000, check_timeout, NULL); |
6287 | 97 } |
1803 | 98 } |
99 | |
6287 | 100 static void signoff_cb(GaimConnection *gc) |
1803 | 101 { |
8598 | 102 GaimBuddyList *list = gaim_get_blist(); |
6287 | 103 if ((!list || !GAIM_IS_GTK_BLIST(list) || !GAIM_GTK_BLIST(list)->vbox) && timer) { |
4168 | 104 g_source_remove(timer); |
2259
866bf3ced1bc
[gaim-migrate @ 2269]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1804
diff
changeset
|
105 timer = 0; |
866bf3ced1bc
[gaim-migrate @ 2269]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1804
diff
changeset
|
106 } |
1803 | 107 } |
108 | |
5255 | 109 /* |
110 * EXPORTED FUNCTIONS | |
111 */ | |
112 | |
113 static gboolean | |
114 plugin_load(GaimPlugin *plugin) | |
1803 | 115 { |
8598 | 116 GaimBuddyList *list = gaim_get_blist(); |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
117 void *conn_handle = gaim_connections_get_handle(); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
118 |
5255 | 119 if (!check_timeout(NULL)) { |
8598 | 120 gaim_debug_warning("mailchk", "Could not read $MAIL or /var/spool/mail/$USER"); |
5255 | 121 return FALSE; |
122 } | |
123 | |
6287 | 124 if (list && GAIM_IS_GTK_BLIST(list) && GAIM_GTK_BLIST(list)->vbox) |
4168 | 125 timer = g_timeout_add(2000, check_timeout, NULL); |
5255 | 126 |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
127 gaim_signal_connect(conn_handle, "signed-on", |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
128 plugin, GAIM_CALLBACK(signon_cb), NULL); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
129 gaim_signal_connect(conn_handle, "signed-off", |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
130 plugin, GAIM_CALLBACK(signoff_cb), NULL); |
5255 | 131 |
132 return TRUE; | |
1803 | 133 } |
134 | |
5255 | 135 static gboolean |
136 plugin_unload(GaimPlugin *plugin) | |
1803 | 137 { |
138 if (timer) | |
4168 | 139 g_source_remove(timer); |
1803 | 140 timer = 0; |
141 if (mail) | |
142 gtk_widget_destroy(mail); | |
143 mail = NULL; | |
5255 | 144 |
145 return TRUE; | |
1803 | 146 } |
147 | |
5255 | 148 static GaimPluginInfo info = |
149 { | |
6287 | 150 2, |
151 GAIM_PLUGIN_STANDARD, | |
152 GAIM_GTK_PLUGIN_TYPE, | |
153 0, | |
154 NULL, | |
155 GAIM_PRIORITY_DEFAULT, | |
156 MAILCHK_PLUGIN_ID, | |
157 N_("Mail Checker"), | |
158 VERSION, | |
5255 | 159 N_("Checks for new local mail."), |
8598 | 160 N_("Adds a small box to the buddy list that" |
161 " shows if you have new mail."), | |
6287 | 162 "Eric Warmenhoven <eric@warmenhoven.org>", |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6287
diff
changeset
|
163 GAIM_WEBSITE, |
6287 | 164 plugin_load, |
165 plugin_unload, | |
166 NULL, | |
167 NULL, | |
168 NULL | |
5255 | 169 }; |
170 | |
171 static void | |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
172 init_plugin(GaimPlugin *plugin) |
5255 | 173 { |
3551 | 174 } |
175 | |
6063 | 176 GAIM_INIT_PLUGIN(mailchk, init_plugin, info) |