| libtinynotify Reference Manual | ||||
|---|---|---|---|---|
| | Description | ||||
The following example shows how to use libtinynotify to handle displaying new mail notification while doing mail fetching for multiple accounts.
In this particular case, a NotifySession is instantiated globally which might not be the sanest solution but it's quite straightforward.
A single Notification is instantiated for the whole mail checking process with a template summary & body. The template is filled with actual numbers when notifications are displayed.
Use of notification_update()
allows libtinynotify to keep track of notification display by server
and replace the outdated notification with the one containing new
numbers.
Example 1. Mail client using libtinynotify
/* compile & link with libtinynotify.pc */
#include <tinynotify.h>
NotifySession notify_session;
/* ... */
void check_new_mail(void) {
Notification n = notification_new("%d new mails",
"%d new messages have been fetched from %d mail accounts.");
MyMailAccount a;
int mail_count = 0;
int acc_count = 0;
for (a = accounts; a; a = a->next) {
int mails_fetched;
/* ... */
if (mails_fetched > 0) {
mail_count += mails_fetched;
acc_count++;
notification_update(n, notify_session,
mail_count, mail_count, acc_count);
}
}
notificaton_free(n);
}
int main(int argc, char *argv[]) {
/* ... */
notify_session = notify_session_new("mymailer", "mailer");
/* ... */
notify_session_free(notify_session);
return 0;
}