Mercurial > pidgin
annotate plugins/mailchk.c @ 11249:b4b1be482b4e
[gaim-migrate @ 13418]
sf patch #1235519, from Sadrul Habib Chowdhury
This is a pretty big patch that makes Gaim correctly save and restore
the current status (away/available, away message, available message,
invisible, etc).
The GaimGtkStatusBoxWidget thing I think defaults to "Available"
every time its created, which overrides the setting that was saved
to the XML file. So that still needs to be fixed before this will
really work.
Anyway, mad props to Sadrul for putting up with my requests on this patch
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Sat, 13 Aug 2005 05:22:09 +0000 |
| parents | 50224ac8184d |
| children | bb0d7b719af2 |
| rev | line source |
|---|---|
| 6287 | 1 #include "internal.h" |
| 2 | |
| 3 #include "debug.h" | |
| 4576 | 4 #include "sound.h" |
| 9954 | 5 #include "version.h" |
| 6677 | 6 |
| 7 #include "gtkblist.h" | |
| 6287 | 8 #include "gtkplugin.h" |
| 9 | |
| 5255 | 10 #define MAILCHK_PLUGIN_ID "gtk-mailchk" |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4655
diff
changeset
|
11 |
| 1803 | 12 #define ANY_MAIL 0x01 |
| 13 #define UNREAD_MAIL 0x02 | |
| 14 #define NEW_MAIL 0x04 | |
| 15 | |
| 16 static guint32 timer = 0; | |
| 17 static GtkWidget *mail = NULL; | |
| 18 | |
| 10218 | 19 static gint |
| 20 check_mail() | |
| 1803 | 21 { |
| 22 static off_t oldsize = 0; | |
| 23 gchar *filename; | |
| 24 off_t newsize; | |
| 25 struct stat s; | |
| 26 gint ret = 0; | |
| 27 | |
| 4655 | 28 filename = g_strdup(g_getenv("MAIL")); |
| 1803 | 29 if (!filename) |
| 30 filename = g_strconcat("/var/spool/mail/", g_get_user_name(), NULL); | |
| 31 | |
|
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10218
diff
changeset
|
32 if (g_stat(filename, &s) < 0) { |
| 1803 | 33 g_free(filename); |
| 34 return -1; | |
| 35 } | |
| 36 | |
| 37 newsize = s.st_size; | |
| 38 if (newsize) ret |= ANY_MAIL; | |
| 39 if (s.st_mtime > s.st_atime && newsize) ret |= UNREAD_MAIL; | |
| 40 if (newsize != oldsize && (ret & UNREAD_MAIL)) ret |= NEW_MAIL; | |
| 41 oldsize = newsize; | |
| 42 | |
| 43 g_free(filename); | |
| 44 | |
| 45 return ret; | |
| 46 } | |
| 47 | |
| 10218 | 48 static void |
| 49 destroy_cb() | |
| 1803 | 50 { |
| 51 mail = NULL; | |
| 52 } | |
| 53 | |
| 10218 | 54 static gboolean |
| 55 check_timeout(gpointer data) | |
| 1803 | 56 { |
| 57 gint count = check_mail(); | |
| 8598 | 58 GaimBuddyList *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 | |
| 10218 | 90 static void |
| 91 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 | |
| 10218 | 100 static void |
| 101 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 |
|
11033
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10589
diff
changeset
|
120 gaim_debug_register_category("mailchk"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10589
diff
changeset
|
121 |
| 5255 | 122 if (!check_timeout(NULL)) { |
| 8598 | 123 gaim_debug_warning("mailchk", "Could not read $MAIL or /var/spool/mail/$USER"); |
| 5255 | 124 return FALSE; |
| 125 } | |
| 126 | |
| 6287 | 127 if (list && GAIM_IS_GTK_BLIST(list) && GAIM_GTK_BLIST(list)->vbox) |
| 4168 | 128 timer = g_timeout_add(2000, check_timeout, NULL); |
| 5255 | 129 |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
130 gaim_signal_connect(conn_handle, "signed-on", |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
131 plugin, GAIM_CALLBACK(signon_cb), NULL); |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
132 gaim_signal_connect(conn_handle, "signed-off", |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
133 plugin, GAIM_CALLBACK(signoff_cb), NULL); |
| 5255 | 134 |
| 135 return TRUE; | |
| 1803 | 136 } |
| 137 | |
| 5255 | 138 static gboolean |
| 139 plugin_unload(GaimPlugin *plugin) | |
| 1803 | 140 { |
| 141 if (timer) | |
| 4168 | 142 g_source_remove(timer); |
| 1803 | 143 timer = 0; |
| 144 if (mail) | |
| 145 gtk_widget_destroy(mail); | |
| 146 mail = NULL; | |
| 5255 | 147 |
|
11033
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10589
diff
changeset
|
148 gaim_debug_unregister_category("mailchk"); |
|
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10589
diff
changeset
|
149 |
| 5255 | 150 return TRUE; |
| 1803 | 151 } |
| 152 | |
| 5255 | 153 static GaimPluginInfo info = |
| 154 { | |
| 9954 | 155 GAIM_PLUGIN_MAGIC, |
| 156 GAIM_MAJOR_VERSION, | |
| 157 GAIM_MINOR_VERSION, | |
| 6287 | 158 GAIM_PLUGIN_STANDARD, |
| 159 GAIM_GTK_PLUGIN_TYPE, | |
| 160 0, | |
| 161 NULL, | |
| 162 GAIM_PRIORITY_DEFAULT, | |
| 163 MAILCHK_PLUGIN_ID, | |
| 164 N_("Mail Checker"), | |
| 165 VERSION, | |
| 5255 | 166 N_("Checks for new local mail."), |
| 8598 | 167 N_("Adds a small box to the buddy list that" |
| 168 " shows if you have new mail."), | |
| 6287 | 169 "Eric Warmenhoven <eric@warmenhoven.org>", |
|
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6287
diff
changeset
|
170 GAIM_WEBSITE, |
| 6287 | 171 plugin_load, |
| 172 plugin_unload, | |
| 173 NULL, | |
| 174 NULL, | |
| 8993 | 175 NULL, |
| 176 NULL, | |
| 6287 | 177 NULL |
| 5255 | 178 }; |
| 179 | |
| 180 static void | |
|
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
181 init_plugin(GaimPlugin *plugin) |
| 5255 | 182 { |
| 3551 | 183 } |
| 184 | |
| 6063 | 185 GAIM_INIT_PLUGIN(mailchk, init_plugin, info) |
