annotate plugins/mailchk.c @ 4785:1e28e7d802a1

[gaim-migrate @ 5105] fix a few things, get rid of a few stale functions, and get rid of the compatibility functions. wee! committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sat, 15 Mar 2003 03:23:30 +0000
parents fac4c73dd5ad
children fefad67de2c7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7 #include "gaim.h"
4576
c7569367ed87 [gaim-migrate @ 4857]
Luke Schierer <lschiere@pidgin.im>
parents: 4575
diff changeset
8 #include "sound.h"
1803
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9 #include <sys/stat.h>
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 #include <sys/types.h>
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11 #include <unistd.h>
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
13 #define ANY_MAIL 0x01
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
14 #define UNREAD_MAIL 0x02
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 #define NEW_MAIL 0x04
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17 static guint32 timer = 0;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
18 static GtkWidget *mail = NULL;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
19
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
20 static gint check_mail()
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21 {
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
22 static off_t oldsize = 0;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
23 gchar *filename;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
24 off_t newsize;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
25 struct stat s;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
26 gint ret = 0;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
27
4655
fac4c73dd5ad [gaim-migrate @ 4966]
Nathan Walp <nwalp@pidgin.im>
parents: 4576
diff changeset
28 filename = g_strdup(g_getenv("MAIL"));
1803
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
29 if (!filename)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
30 filename = g_strconcat("/var/spool/mail/", g_get_user_name(), NULL);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
31
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
32 if (stat(filename, &s) < 0) {
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
33 g_free(filename);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34 return -1;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35 }
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37 newsize = s.st_size;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
38 if (newsize) ret |= ANY_MAIL;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
39 if (s.st_mtime > s.st_atime && newsize) ret |= UNREAD_MAIL;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
40 if (newsize != oldsize && (ret & UNREAD_MAIL)) ret |= NEW_MAIL;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
41 oldsize = newsize;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
42
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
43 g_free(filename);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
44
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
45 return ret;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46 }
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
48 static void maildes()
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49 {
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50 mail = NULL;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
51 }
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
53 static gboolean check_timeout(gpointer data)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54 {
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
55 gint count = check_mail();
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
56
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
57 if (count == -1)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
58 return FALSE;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
59
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
60 if (!blist)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
61 return TRUE;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
62
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
63 if (!mail) {
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
64 /* guess we better build it then :P */
4655
fac4c73dd5ad [gaim-migrate @ 4966]
Nathan Walp <nwalp@pidgin.im>
parents: 4576
diff changeset
65 GList *tmp = gtk_container_get_children(GTK_CONTAINER(blist));
1803
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
66 GtkWidget *vbox2 = (GtkWidget *)tmp->data;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
67
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
68 mail = gtk_label_new("No mail messages.");
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
69 gtk_box_pack_start(GTK_BOX(vbox2), mail, FALSE, FALSE, 0);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
70 gtk_box_reorder_child(GTK_BOX(vbox2), mail, 1);
4165
07a3d1fae88f [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
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
72 gtk_widget_show(mail);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
73 }
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
74
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
75 if (count & NEW_MAIL)
4576
c7569367ed87 [gaim-migrate @ 4857]
Luke Schierer <lschiere@pidgin.im>
parents: 4575
diff changeset
76 gaim_sound_play_event(GAIM_SOUND_POUNCE_DEFAULT);
1803
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
77
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
78 if (count & UNREAD_MAIL)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
79 gtk_label_set_text(GTK_LABEL(mail), "You have new mail!");
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
80 else if (count & ANY_MAIL)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
81 gtk_label_set_text(GTK_LABEL(mail), "You have mail.");
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
82 else
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
83 gtk_label_set_text(GTK_LABEL(mail), "No mail messages.");
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
84
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
85 return TRUE;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
86 }
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
87
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
88 static void mail_signon(struct gaim_connection *gc)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
89 {
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
90 if (blist && !timer)
4168
ebfb80bbe1ed [gaim-migrate @ 4397]
Luke Schierer <lschiere@pidgin.im>
parents: 4165
diff changeset
91 timer = g_timeout_add(2000, check_timeout, NULL);
1803
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
92 }
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
93
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
94 static void mail_signoff(struct gaim_connection *gc)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
95 {
2259
866bf3ced1bc [gaim-migrate @ 2269]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1804
diff changeset
96 if (!blist && timer) {
4168
ebfb80bbe1ed [gaim-migrate @ 4397]
Luke Schierer <lschiere@pidgin.im>
parents: 4165
diff changeset
97 g_source_remove(timer);
2259
866bf3ced1bc [gaim-migrate @ 2269]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1804
diff changeset
98 timer = 0;
866bf3ced1bc [gaim-migrate @ 2269]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1804
diff changeset
99 }
1803
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
100 }
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
101
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
102 char *gaim_plugin_init(GModule *m)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
103 {
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
104 if (!check_timeout(NULL))
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
105 return "Could not read $MAIL or /var/spool/mail/$USER";
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
106 if (blist)
4168
ebfb80bbe1ed [gaim-migrate @ 4397]
Luke Schierer <lschiere@pidgin.im>
parents: 4165
diff changeset
107 timer = g_timeout_add(2000, check_timeout, NULL);
1803
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
108 gaim_signal_connect(m, event_signon, mail_signon, NULL);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
109 gaim_signal_connect(m, event_signoff, mail_signoff, NULL);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
110 return NULL;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
111 }
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
112
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
113 void gaim_plugin_remove()
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
114 {
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
115 if (timer)
4168
ebfb80bbe1ed [gaim-migrate @ 4397]
Luke Schierer <lschiere@pidgin.im>
parents: 4165
diff changeset
116 g_source_remove(timer);
1803
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
117 timer = 0;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
118 if (mail)
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
119 gtk_widget_destroy(mail);
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
120 mail = NULL;
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
121 }
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
122
3551
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3060
diff changeset
123 struct gaim_plugin_description desc;
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3060
diff changeset
124 struct gaim_plugin_description *gaim_plugin_desc() {
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3060
diff changeset
125 desc.api_version = PLUGIN_API_VERSION;
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3060
diff changeset
126 desc.name = g_strdup("Mail Checker");
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3060
diff changeset
127 desc.version = g_strdup(VERSION);
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3060
diff changeset
128 desc.description = g_strdup("Checks for new local mail.");
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3060
diff changeset
129 desc.authors = g_strdup("Eric Warmehoven &lt;eric@warmenhoven.org>");
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3060
diff changeset
130 desc.url = g_strdup(WEBSITE);
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3060
diff changeset
131 return &desc;
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3060
diff changeset
132 }
cd938f18f3f8 [gaim-migrate @ 3626]
Sean Egan <seanegan@gmail.com>
parents: 3060
diff changeset
133
1803
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
134 char *name()
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
135 {
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
136 return "Mail Check";
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
137 }
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
138
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
139 char *description()
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
140 {
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
141 return "Checks for new local mail";
d36f759df56d [gaim-migrate @ 1813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
142 }