Mercurial > projects > pk-update-icon
diff notify.c @ 3:f8ad23e60000
code rework, show notify window just once
author | Pavol Rusnak <stick@gk2.sk> |
---|---|
date | Tue, 27 Sep 2011 12:15:39 +0200 |
parents | 847ae02bc13b |
children | 58a3312a1c59 |
line wrap: on
line diff
--- a/notify.c Tue Sep 27 02:31:31 2011 +0200 +++ b/notify.c Tue Sep 27 12:15:39 2011 +0200 @@ -28,17 +28,22 @@ notify_init(NOTIFY_NAME); } -void send_notify(int normal, int critical) +void send_notify(struct UpdatesInfo *info) { NotifyNotification *ntfy; - char buf[128]; - if (critical > 0) { - snprintf(buf, sizeof(buf), "There are %d software updates available, %d of them critical.", normal + critical, critical); - } else { - snprintf(buf, sizeof(buf), "There are %d software updates available.", normal); - } - ntfy = notify_notification_new(NOTIFY_NAME, buf, critical > 0 ? "software-update-urgent" : "software-update-available"); + ntfy = notify_notification_new(NOTIFY_NAME, notify_text(info), info->critical > 0 ? "software-update-urgent" : "software-update-available"); notify_notification_set_timeout(ntfy, 3000); - notify_notification_set_urgency(ntfy, critical > 0 ? NOTIFY_URGENCY_CRITICAL : NOTIFY_URGENCY_NORMAL); + notify_notification_set_urgency(ntfy, info->critical > 0 ? NOTIFY_URGENCY_CRITICAL : NOTIFY_URGENCY_NORMAL); notify_notification_show(ntfy, NULL); } + +const char *notify_text(struct UpdatesInfo *info) +{ + static char buf[128]; + if (info->critical > 0) { + snprintf(buf, sizeof(buf), "There are %d software updates available, %d of them critical.", info->normal + info->critical, info->critical); + } else { + snprintf(buf, sizeof(buf), "There are %d software updates available.", info->normal); + } + return buf; +}