comparison 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
comparison
equal deleted inserted replaced
2:847ae02bc13b 3:f8ad23e60000
26 void init_notify() 26 void init_notify()
27 { 27 {
28 notify_init(NOTIFY_NAME); 28 notify_init(NOTIFY_NAME);
29 } 29 }
30 30
31 void send_notify(int normal, int critical) 31 void send_notify(struct UpdatesInfo *info)
32 { 32 {
33 NotifyNotification *ntfy; 33 NotifyNotification *ntfy;
34 char buf[128]; 34 ntfy = notify_notification_new(NOTIFY_NAME, notify_text(info), info->critical > 0 ? "software-update-urgent" : "software-update-available");
35 if (critical > 0) {
36 snprintf(buf, sizeof(buf), "There are %d software updates available, %d of them critical.", normal + critical, critical);
37 } else {
38 snprintf(buf, sizeof(buf), "There are %d software updates available.", normal);
39 }
40 ntfy = notify_notification_new(NOTIFY_NAME, buf, critical > 0 ? "software-update-urgent" : "software-update-available");
41 notify_notification_set_timeout(ntfy, 3000); 35 notify_notification_set_timeout(ntfy, 3000);
42 notify_notification_set_urgency(ntfy, critical > 0 ? NOTIFY_URGENCY_CRITICAL : NOTIFY_URGENCY_NORMAL); 36 notify_notification_set_urgency(ntfy, info->critical > 0 ? NOTIFY_URGENCY_CRITICAL : NOTIFY_URGENCY_NORMAL);
43 notify_notification_show(ntfy, NULL); 37 notify_notification_show(ntfy, NULL);
44 } 38 }
39
40 const char *notify_text(struct UpdatesInfo *info)
41 {
42 static char buf[128];
43 if (info->critical > 0) {
44 snprintf(buf, sizeof(buf), "There are %d software updates available, %d of them critical.", info->normal + info->critical, info->critical);
45 } else {
46 snprintf(buf, sizeof(buf), "There are %d software updates available.", info->normal);
47 }
48 return buf;
49 }