10 #define MAILCHK_PLUGIN_ID "gtk-mailchk"
11 #define MAILCHK_PLUGIN_DOMAIN (g_quark_from_static_string(MAILCHK_PLUGIN_ID))
14 #define UNREAD_MAIL 0x02
17 static guint timer
= 0;
18 static GtkWidget
*mail
= NULL
;
23 static off_t oldsize
= 0;
29 filename
= g_strdup(g_getenv("MAIL"));
31 filename
= g_strconcat("/var/spool/mail/", g_get_user_name(), NULL
);
33 if (g_stat(filename
, &st
) < 0) {
39 if (newsize
) ret
|= ANY_MAIL
;
40 if (st
.st_mtime
> st
.st_atime
&& newsize
) ret
|= UNREAD_MAIL
;
41 if (newsize
!= oldsize
&& (ret
& UNREAD_MAIL
)) ret
|= NEW_MAIL
;
56 check_timeout(gpointer data
)
58 gint count
= check_mail();
59 PurpleBuddyList
*list
= purple_blist_get_default();
64 if (!list
|| !(PIDGIN_BLIST(list
)->vbox
))
68 /* guess we better build it then :P */
69 GtkWidget
*vbox
= PIDGIN_BLIST(list
)->vbox
;
71 mail
= gtk_label_new("No mail messages.");
72 gtk_box_pack_start(GTK_BOX(vbox
), mail
, FALSE
, FALSE
, 0);
73 gtk_box_reorder_child(GTK_BOX(vbox
), mail
, 1);
74 g_signal_connect(G_OBJECT(mail
), "destroy", G_CALLBACK(destroy_cb
), NULL
);
75 gtk_widget_show(mail
);
79 purple_sound_play_event(PURPLE_SOUND_POUNCE_DEFAULT
, NULL
);
81 if (count
& UNREAD_MAIL
)
82 gtk_label_set_text(GTK_LABEL(mail
), "You have new mail!");
83 else if (count
& ANY_MAIL
)
84 gtk_label_set_text(GTK_LABEL(mail
), "You have mail.");
86 gtk_label_set_text(GTK_LABEL(mail
), "No mail messages.");
92 signon_cb(PurpleConnection
*gc
)
94 PurpleBuddyList
*list
= purple_blist_get_default();
96 check_timeout(NULL
); /* we want the box to be drawn immediately */
97 timer
= g_timeout_add_seconds(2, check_timeout
, NULL
);
102 signoff_cb(PurpleConnection
*gc
)
104 PurpleBuddyList
*list
= purple_blist_get_default();
105 if ((!list
|| !PIDGIN_BLIST(list
)->vbox
) && timer
) {
106 g_source_remove(timer
);
115 static PidginPluginInfo
*
116 plugin_query(GError
**error
)
118 const gchar
* const authors
[] = {
119 "Eric Warmenhoven <eric@warmenhoven.org>",
123 return pidgin_plugin_info_new(
124 "id", MAILCHK_PLUGIN_ID
,
125 "name", N_("Mail Checker"),
126 "version", DISPLAY_VERSION
,
127 "category", N_("Utility"),
128 "summary", N_("Checks for new local mail."),
129 "description", N_("Adds a small box to the buddy list that shows if "
130 "you have new mail."),
132 "website", PURPLE_WEBSITE
,
133 "abi-version", PURPLE_ABI_VERSION
,
139 plugin_load(PurplePlugin
*plugin
, GError
**error
)
141 PurpleBuddyList
*list
= purple_blist_get_default();
142 void *conn_handle
= purple_connections_get_handle();
144 if (!check_timeout(NULL
)) {
145 g_set_error(error
, MAILCHK_PLUGIN_DOMAIN
, 0, _("Could not read $MAIL "
146 "or /var/spool/mail/$USER\n"));
150 if (list
&& PIDGIN_BLIST(list
)->vbox
)
151 timer
= g_timeout_add_seconds(2, check_timeout
, NULL
);
153 purple_signal_connect(conn_handle
, "signed-on",
154 plugin
, PURPLE_CALLBACK(signon_cb
), NULL
);
155 purple_signal_connect(conn_handle
, "signed-off",
156 plugin
, PURPLE_CALLBACK(signoff_cb
), NULL
);
162 plugin_unload(PurplePlugin
*plugin
, GError
**error
)
165 g_source_remove(timer
);
168 gtk_widget_destroy(mail
);
174 PURPLE_PLUGIN_INIT(mailchk
, plugin_query
, plugin_load
, plugin_unload
);