Mercurial > pidgin
annotate plugins/mailchk.c @ 4576:c7569367ed87
[gaim-migrate @ 4857]
"Sender: darkrain
I tried your patch, but my system (debian unstable) barfed
building it.
The first problem was that sound.h was included before
gaim.h, so I moved it to be included after gaim.h.
Then, I changed the other line (the one about playing the
actualy sound) to read:
gaim_sound_play_event(GAIM_SOUND_POUNCE_DEFAULT); "
now it should actually work :-)
committer: Tailor Script <tailor@pidgin.im>
| author | Luke Schierer <lschiere@pidgin.im> |
|---|---|
| date | Wed, 12 Feb 2003 03:12:03 +0000 |
| parents | 1b52e29f1ffb |
| children | fac4c73dd5ad |
| rev | line source |
|---|---|
|
4202
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4168
diff
changeset
|
1 #include "config.h" |
|
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4168
diff
changeset
|
2 |
|
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4168
diff
changeset
|
3 #ifndef GAIM_PLUGINS |
| 1803 | 4 #define GAIM_PLUGINS |
|
4202
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4168
diff
changeset
|
5 #endif |
|
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4168
diff
changeset
|
6 |
| 1803 | 7 #include "gaim.h" |
| 4576 | 8 #include "sound.h" |
| 1803 | 9 #include <sys/stat.h> |
| 10 #include <sys/types.h> | |
| 11 #include <unistd.h> | |
| 12 | |
| 13 #define ANY_MAIL 0x01 | |
| 14 #define UNREAD_MAIL 0x02 | |
| 15 #define NEW_MAIL 0x04 | |
| 16 | |
| 17 static guint32 timer = 0; | |
| 18 static GtkWidget *mail = NULL; | |
| 19 | |
| 20 static gint check_mail() | |
| 21 { | |
| 22 static off_t oldsize = 0; | |
| 23 gchar *filename; | |
| 24 off_t newsize; | |
| 25 struct stat s; | |
| 26 gint ret = 0; | |
| 27 | |
| 28 filename = g_getenv("MAIL"); | |
| 29 if (!filename) | |
| 30 filename = g_strconcat("/var/spool/mail/", g_get_user_name(), NULL); | |
| 31 else | |
| 32 filename = g_strdup(filename); | |
| 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 | |
| 50 static void maildes() | |
| 51 { | |
| 52 mail = NULL; | |
| 53 } | |
| 54 | |
| 55 static gboolean check_timeout(gpointer data) | |
| 56 { | |
| 57 gint count = check_mail(); | |
| 58 | |
| 59 if (count == -1) | |
| 60 return FALSE; | |
| 61 | |
| 62 if (!blist) | |
| 63 return TRUE; | |
| 64 | |
| 65 if (!mail) { | |
| 66 /* guess we better build it then :P */ | |
| 67 GList *tmp = gtk_container_children(GTK_CONTAINER(blist)); | |
| 68 GtkWidget *vbox2 = (GtkWidget *)tmp->data; | |
| 69 | |
| 70 mail = gtk_label_new("No mail messages."); | |
| 71 gtk_box_pack_start(GTK_BOX(vbox2), mail, FALSE, FALSE, 0); | |
| 72 gtk_box_reorder_child(GTK_BOX(vbox2), mail, 1); | |
|
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
73 g_signal_connect(GTK_OBJECT(mail), "destroy", G_CALLBACK(maildes), 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 | |
| 90 static void mail_signon(struct gaim_connection *gc) | |
| 91 { | |
| 92 if (blist && !timer) | |
| 4168 | 93 timer = g_timeout_add(2000, check_timeout, NULL); |
| 1803 | 94 } |
| 95 | |
| 96 static void mail_signoff(struct gaim_connection *gc) | |
| 97 { | |
|
2259
866bf3ced1bc
[gaim-migrate @ 2269]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1804
diff
changeset
|
98 if (!blist && timer) { |
| 4168 | 99 g_source_remove(timer); |
|
2259
866bf3ced1bc
[gaim-migrate @ 2269]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1804
diff
changeset
|
100 timer = 0; |
|
866bf3ced1bc
[gaim-migrate @ 2269]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1804
diff
changeset
|
101 } |
| 1803 | 102 } |
| 103 | |
| 104 char *gaim_plugin_init(GModule *m) | |
| 105 { | |
| 106 if (!check_timeout(NULL)) | |
| 107 return "Could not read $MAIL or /var/spool/mail/$USER"; | |
| 108 if (blist) | |
| 4168 | 109 timer = g_timeout_add(2000, check_timeout, NULL); |
| 1803 | 110 gaim_signal_connect(m, event_signon, mail_signon, NULL); |
| 111 gaim_signal_connect(m, event_signoff, mail_signoff, NULL); | |
| 112 return NULL; | |
| 113 } | |
| 114 | |
| 115 void gaim_plugin_remove() | |
| 116 { | |
| 117 if (timer) | |
| 4168 | 118 g_source_remove(timer); |
| 1803 | 119 timer = 0; |
| 120 if (mail) | |
| 121 gtk_widget_destroy(mail); | |
| 122 mail = NULL; | |
| 123 } | |
| 124 | |
| 3551 | 125 struct gaim_plugin_description desc; |
| 126 struct gaim_plugin_description *gaim_plugin_desc() { | |
| 127 desc.api_version = PLUGIN_API_VERSION; | |
| 128 desc.name = g_strdup("Mail Checker"); | |
| 129 desc.version = g_strdup(VERSION); | |
| 130 desc.description = g_strdup("Checks for new local mail."); | |
| 131 desc.authors = g_strdup("Eric Warmehoven <eric@warmenhoven.org>"); | |
| 132 desc.url = g_strdup(WEBSITE); | |
| 133 return &desc; | |
| 134 } | |
| 135 | |
| 1803 | 136 char *name() |
| 137 { | |
| 138 return "Mail Check"; | |
| 139 } | |
| 140 | |
| 141 char *description() | |
| 142 { | |
| 143 return "Checks for new local mail"; | |
| 144 } |
