10 #define MAILCHK_PLUGIN_ID "gtk-mailchk"
13 #define UNREAD_MAIL 0x02
16 static guint timer
= 0;
17 static GtkWidget
*mail
= NULL
;
22 static off_t oldsize
= 0;
28 filename
= g_strdup(g_getenv("MAIL"));
30 filename
= g_strconcat("/var/spool/mail/", g_get_user_name(), NULL
);
32 if (g_stat(filename
, &s
) < 0) {
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
;
55 check_timeout(gpointer data
)
57 gint count
= check_mail();
58 PurpleBuddyList
*list
= purple_get_blist();
63 if (!list
|| !PURPLE_IS_GTK_BLIST(list
) || !(PIDGIN_BLIST(list
)->vbox
))
67 /* guess we better build it then :P */
68 GtkWidget
*vbox
= PIDGIN_BLIST(list
)->vbox
;
70 mail
= gtk_label_new("No mail messages.");
71 gtk_box_pack_start(GTK_BOX(vbox
), mail
, FALSE
, FALSE
, 0);
72 gtk_box_reorder_child(GTK_BOX(vbox
), mail
, 1);
73 g_signal_connect(G_OBJECT(mail
), "destroy", G_CALLBACK(destroy_cb
), NULL
);
74 gtk_widget_show(mail
);
78 purple_sound_play_event(PURPLE_SOUND_POUNCE_DEFAULT
, NULL
);
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.");
85 gtk_label_set_text(GTK_LABEL(mail
), "No mail messages.");
91 signon_cb(PurpleConnection
*gc
)
93 PurpleBuddyList
*list
= purple_get_blist();
94 if (list
&& PURPLE_IS_GTK_BLIST(list
) && !timer
) {
95 check_timeout(NULL
); /* we want the box to be drawn immediately */
96 timer
= purple_timeout_add_seconds(2, check_timeout
, NULL
);
101 signoff_cb(PurpleConnection
*gc
)
103 PurpleBuddyList
*list
= purple_get_blist();
104 if ((!list
|| !PURPLE_IS_GTK_BLIST(list
) || !PIDGIN_BLIST(list
)->vbox
) && timer
) {
105 purple_timeout_remove(timer
);
115 plugin_load(PurplePlugin
*plugin
)
117 PurpleBuddyList
*list
= purple_get_blist();
118 void *conn_handle
= purple_connections_get_handle();
120 if (!check_timeout(NULL
)) {
121 purple_debug_warning("mailchk", "Could not read $MAIL or /var/spool/mail/$USER\n");
125 if (list
&& PURPLE_IS_GTK_BLIST(list
) && PIDGIN_BLIST(list
)->vbox
)
126 timer
= purple_timeout_add_seconds(2, check_timeout
, NULL
);
128 purple_signal_connect(conn_handle
, "signed-on",
129 plugin
, PURPLE_CALLBACK(signon_cb
), NULL
);
130 purple_signal_connect(conn_handle
, "signed-off",
131 plugin
, PURPLE_CALLBACK(signoff_cb
), NULL
);
137 plugin_unload(PurplePlugin
*plugin
)
140 purple_timeout_remove(timer
);
143 gtk_widget_destroy(mail
);
149 static PurplePluginInfo info
=
152 PURPLE_MAJOR_VERSION
,
153 PURPLE_MINOR_VERSION
,
154 PURPLE_PLUGIN_STANDARD
,
158 PURPLE_PRIORITY_DEFAULT
,
162 N_("Checks for new local mail."),
163 N_("Adds a small box to the buddy list that"
164 " shows if you have new mail."),
165 "Eric Warmenhoven <eric@warmenhoven.org>",
177 init_plugin(PurplePlugin
*plugin
)
181 PURPLE_INIT_PLUGIN(mailchk
, init_plugin
, info
)