Mercurial > pidgin
annotate plugins/mailchk.c @ 5760:22cbb8e934cb
[gaim-migrate @ 6185]
Ha! Now *this* is a logo!
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Thu, 05 Jun 2003 17:37:05 +0000 |
parents | 1f901484599d |
children | 7d385de2f9cd |
rev | line source |
---|---|
1803 | 1 #include "gaim.h" |
5255 | 2 #include "gtkplugin.h" |
3 #include "blist.h" | |
4 #include "gtkblist.h" | |
4576 | 5 #include "sound.h" |
1803 | 6 #include <sys/stat.h> |
7 #include <sys/types.h> | |
8 #include <unistd.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 | |
19 static gint check_mail() | |
20 { | |
21 static off_t oldsize = 0; | |
22 gchar *filename; | |
23 off_t newsize; | |
24 struct stat s; | |
25 gint ret = 0; | |
26 | |
4655 | 27 filename = g_strdup(g_getenv("MAIL")); |
1803 | 28 if (!filename) |
29 filename = g_strconcat("/var/spool/mail/", g_get_user_name(), NULL); | |
30 | |
31 if (stat(filename, &s) < 0) { | |
32 g_free(filename); | |
33 return -1; | |
34 } | |
35 | |
36 newsize = s.st_size; | |
37 if (newsize) ret |= ANY_MAIL; | |
38 if (s.st_mtime > s.st_atime && newsize) ret |= UNREAD_MAIL; | |
39 if (newsize != oldsize && (ret & UNREAD_MAIL)) ret |= NEW_MAIL; | |
40 oldsize = newsize; | |
41 | |
42 g_free(filename); | |
43 | |
44 return ret; | |
45 } | |
46 | |
5255 | 47 static void destroy_cb() |
1803 | 48 { |
49 mail = NULL; | |
50 } | |
51 | |
52 static gboolean check_timeout(gpointer data) | |
53 { | |
54 gint count = check_mail(); | |
5255 | 55 struct gaim_buddy_list *list = gaim_get_blist(); |
1803 | 56 if (count == -1) |
57 return FALSE; | |
58 | |
5255 | 59 if (!list || !GAIM_GTK_BLIST(list)) |
1803 | 60 return TRUE; |
61 | |
62 if (!mail) { | |
63 /* guess we better build it then :P */ | |
5255 | 64 //GList *tmp = gtk_container_get_children(GTK_CONTAINER(GAIM_GTK_BLIST(list))); |
65 //GtkWidget *vbox2 = (GtkWidget *)tmp->data; | |
66 GtkWidget *vbox = (GtkWidget *)(GAIM_GTK_BLIST(list)->vbox); | |
1803 | 67 |
68 mail = gtk_label_new("No mail messages."); | |
5255 | 69 gtk_box_pack_start(GTK_BOX(vbox), mail, FALSE, FALSE, 0); |
70 gtk_box_reorder_child(GTK_BOX(vbox), mail, 1); | |
5314
1f901484599d
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5255
diff
changeset
|
71 g_signal_connect(G_OBJECT(mail), "destroy", G_CALLBACK(destroy_cb), 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 | |
5255 | 88 static void signon_cb(struct gaim_connection *gc) |
1803 | 89 { |
5255 | 90 struct gaim_buddy_list *list = gaim_get_blist(); |
91 if (list && GAIM_GTK_BLIST(list) && !timer) | |
4168 | 92 timer = g_timeout_add(2000, check_timeout, NULL); |
1803 | 93 } |
94 | |
5255 | 95 static void signoff_cb(struct gaim_connection *gc) |
1803 | 96 { |
5255 | 97 struct gaim_buddy_list *list = gaim_get_blist(); |
98 if ((!list || !GAIM_GTK_BLIST(list)) && 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 | |
5255 | 104 /* |
105 * EXPORTED FUNCTIONS | |
106 */ | |
107 | |
108 static gboolean | |
109 plugin_load(GaimPlugin *plugin) | |
1803 | 110 { |
5255 | 111 struct gaim_buddy_list *list = gaim_get_blist(); |
112 if (!check_timeout(NULL)) { | |
113 gaim_debug(GAIM_DEBUG_WARNING, "mailchk", "Could not read $MAIL or /var/spool/mail/$USER"); | |
114 return FALSE; | |
115 } | |
116 | |
117 if (list && GAIM_GTK_BLIST(list)) | |
4168 | 118 timer = g_timeout_add(2000, check_timeout, NULL); |
5255 | 119 |
120 gaim_signal_connect(plugin, event_signon, signon_cb, NULL); | |
121 gaim_signal_connect(plugin, event_signoff, signoff_cb, NULL); | |
122 | |
123 return TRUE; | |
1803 | 124 } |
125 | |
5255 | 126 static gboolean |
127 plugin_unload(GaimPlugin *plugin) | |
1803 | 128 { |
129 if (timer) | |
4168 | 130 g_source_remove(timer); |
1803 | 131 timer = 0; |
132 if (mail) | |
133 gtk_widget_destroy(mail); | |
134 mail = NULL; | |
5255 | 135 |
136 return TRUE; | |
1803 | 137 } |
138 | |
5255 | 139 static GaimPluginInfo info = |
140 { | |
141 2, /**< api_version */ | |
142 GAIM_PLUGIN_STANDARD, /**< type */ | |
143 GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */ | |
144 0, /**< flags */ | |
145 NULL, /**< dependencies */ | |
146 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
147 | |
148 MAILCHK_PLUGIN_ID, /**< id */ | |
149 N_("Mail Checker"), /**< name */ | |
150 VERSION, /**< version */ | |
151 /** summary */ | |
152 N_("Checks for new local mail."), | |
153 /** description */ | |
154 N_("Checks for new local mail."), | |
155 "Eric Warmenhoven <eric@warmenhoven.org>", /**< author */ | |
156 WEBSITE, /**< homepage */ | |
157 | |
158 plugin_load, /**< load */ | |
159 plugin_unload, /**< unload */ | |
160 NULL, /**< destroy */ | |
161 | |
162 NULL, /**< ui_info */ | |
163 NULL /**< extra_info */ | |
164 }; | |
165 | |
166 static void | |
167 __init_plugin(GaimPlugin *plugin) | |
168 { | |
3551 | 169 } |
170 | |
5255 | 171 GAIM_INIT_PLUGIN(mailchk, __init_plugin, info); |