Thu, 06 Mar 2003 17:27:17 +0000
[gaim-migrate @ 4966]
cleanups for some plugins that aren't compiled by default
|
4202
8b92de3b1c07
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4168
diff
changeset
|
1 | #include "config.h" |
|
8b92de3b1c07
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4168
diff
changeset
|
2 | |
|
8b92de3b1c07
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4168
diff
changeset
|
3 | #ifndef GAIM_PLUGINS |
| 1803 | 4 | #define GAIM_PLUGINS |
|
4202
8b92de3b1c07
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4168
diff
changeset
|
5 | #endif |
|
8b92de3b1c07
[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 | ||
| 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 | ||
| 32 | if (stat(filename, &s) < 0) { | |
| 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 | ||
| 48 | static void maildes() | |
| 49 | { | |
| 50 | mail = NULL; | |
| 51 | } | |
| 52 | ||
| 53 | static gboolean check_timeout(gpointer data) | |
| 54 | { | |
| 55 | gint count = check_mail(); | |
| 56 | ||
| 57 | if (count == -1) | |
| 58 | return FALSE; | |
| 59 | ||
| 60 | if (!blist) | |
| 61 | return TRUE; | |
| 62 | ||
| 63 | if (!mail) { | |
| 64 | /* guess we better build it then :P */ | |
| 4655 | 65 | GList *tmp = gtk_container_get_children(GTK_CONTAINER(blist)); |
| 1803 | 66 | GtkWidget *vbox2 = (GtkWidget *)tmp->data; |
| 67 | ||
| 68 | mail = gtk_label_new("No mail messages."); | |
| 69 | gtk_box_pack_start(GTK_BOX(vbox2), mail, FALSE, FALSE, 0); | |
| 70 | gtk_box_reorder_child(GTK_BOX(vbox2), mail, 1); | |
|
4165
9d849f3a4dff
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3551
diff
changeset
|
71 | g_signal_connect(GTK_OBJECT(mail), "destroy", G_CALLBACK(maildes), NULL); |
| 1803 | 72 | gtk_widget_show(mail); |
| 73 | } | |
| 74 | ||
| 75 | if (count & NEW_MAIL) | |
| 4576 | 76 | gaim_sound_play_event(GAIM_SOUND_POUNCE_DEFAULT); |
| 1803 | 77 | |
| 78 | if (count & UNREAD_MAIL) | |
| 79 | gtk_label_set_text(GTK_LABEL(mail), "You have new mail!"); | |
| 80 | else if (count & ANY_MAIL) | |
| 81 | gtk_label_set_text(GTK_LABEL(mail), "You have mail."); | |
| 82 | else | |
| 83 | gtk_label_set_text(GTK_LABEL(mail), "No mail messages."); | |
| 84 | ||
| 85 | return TRUE; | |
| 86 | } | |
| 87 | ||
| 88 | static void mail_signon(struct gaim_connection *gc) | |
| 89 | { | |
| 90 | if (blist && !timer) | |
| 4168 | 91 | timer = g_timeout_add(2000, check_timeout, NULL); |
| 1803 | 92 | } |
| 93 | ||
| 94 | static void mail_signoff(struct gaim_connection *gc) | |
| 95 | { | |
| 2259 | 96 | if (!blist && timer) { |
| 4168 | 97 | g_source_remove(timer); |
| 2259 | 98 | timer = 0; |
| 99 | } | |
| 1803 | 100 | } |
| 101 | ||
| 102 | char *gaim_plugin_init(GModule *m) | |
| 103 | { | |
| 104 | if (!check_timeout(NULL)) | |
| 105 | return "Could not read $MAIL or /var/spool/mail/$USER"; | |
| 106 | if (blist) | |
| 4168 | 107 | timer = g_timeout_add(2000, check_timeout, NULL); |
| 1803 | 108 | gaim_signal_connect(m, event_signon, mail_signon, NULL); |
| 109 | gaim_signal_connect(m, event_signoff, mail_signoff, NULL); | |
| 110 | return NULL; | |
| 111 | } | |
| 112 | ||
| 113 | void gaim_plugin_remove() | |
| 114 | { | |
| 115 | if (timer) | |
| 4168 | 116 | g_source_remove(timer); |
| 1803 | 117 | timer = 0; |
| 118 | if (mail) | |
| 119 | gtk_widget_destroy(mail); | |
| 120 | mail = NULL; | |
| 121 | } | |
| 122 | ||
| 3551 | 123 | struct gaim_plugin_description desc; |
| 124 | struct gaim_plugin_description *gaim_plugin_desc() { | |
| 125 | desc.api_version = PLUGIN_API_VERSION; | |
| 126 | desc.name = g_strdup("Mail Checker"); | |
| 127 | desc.version = g_strdup(VERSION); | |
| 128 | desc.description = g_strdup("Checks for new local mail."); | |
| 129 | desc.authors = g_strdup("Eric Warmehoven <eric@warmenhoven.org>"); | |
| 130 | desc.url = g_strdup(WEBSITE); | |
| 131 | return &desc; | |
| 132 | } | |
| 133 | ||
| 1803 | 134 | char *name() |
| 135 | { | |
| 136 | return "Mail Check"; | |
| 137 | } | |
| 138 | ||
| 139 | char *description() | |
| 140 | { | |
| 141 | return "Checks for new local mail"; | |
| 142 | } |