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