Mercurial > pidgin
annotate plugins/mailchk.c @ 9509:aecabbe495db
[gaim-migrate @ 10336]
FT --> gtk 2.4 file chooser via request API.
I'm going to try to move some of this from gtkft.c to ft.c
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 11 Jul 2004 19:57:31 +0000 |
parents | 294ae6548d4e |
children | a09ffb82aef1 |
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 { | |
8749
d7b8eb1f0a18
[gaim-migrate @ 9504]
Christian Hammond <chipx86@chipx86.com>
parents:
8598
diff
changeset
|
150 GAIM_PLUGIN_API_VERSION, |
6287 | 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, | |
8993 | 168 NULL, |
169 NULL, | |
6287 | 170 NULL |
5255 | 171 }; |
172 | |
173 static void | |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
174 init_plugin(GaimPlugin *plugin) |
5255 | 175 { |
3551 | 176 } |
177 | |
6063 | 178 GAIM_INIT_PLUGIN(mailchk, init_plugin, info) |