annotate notify.c @ 5:e4ff04df085c

use libnotify's pkgconfig for buildflags
author Pavol Rusnak <stick@gk2.sk>
date Thu, 06 Oct 2011 15:38:49 +0200
parents f8ad23e60000
children 58a3312a1c59
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 0
diff changeset
1 /*
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 0
diff changeset
2 * Copyright (C) 2011 Pavol Rusnak <stick@gk2.sk>
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 0
diff changeset
3 *
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 0
diff changeset
4 * Licensed under the GNU General Public License Version 2
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 0
diff changeset
5 *
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 0
diff changeset
6 * This program is free software; you can redistribute it and/or modify
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 0
diff changeset
7 * it under the terms of the GNU General Public License as published by
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 0
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 0
diff changeset
9 * (at your option) any later version.
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 0
diff changeset
10 *
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 0
diff changeset
11 * This program is distributed in the hope that it will be useful,
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 0
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 0
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 0
diff changeset
14 * GNU General Public License for more details.
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 0
diff changeset
15 *
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 0
diff changeset
16 * You should have received a copy of the GNU General Public License
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 0
diff changeset
17 * along with this program; if not, write to the Free Software
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 0
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 0
diff changeset
19 */
847ae02bc13b added GPLv2 headers
Pavol Rusnak <stick@gk2.sk>
parents: 0
diff changeset
20
0
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
21 #include <libnotify/notify.h>
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
22 #include "notify.h"
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
23
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
24 #define NOTIFY_NAME "Software Update"
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
25
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
26 void init_notify()
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
27 {
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
28 notify_init(NOTIFY_NAME);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
29 }
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
30
3
f8ad23e60000 code rework, show notify window just once
Pavol Rusnak <stick@gk2.sk>
parents: 2
diff changeset
31 void send_notify(struct UpdatesInfo *info)
0
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
32 {
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
33 NotifyNotification *ntfy;
3
f8ad23e60000 code rework, show notify window just once
Pavol Rusnak <stick@gk2.sk>
parents: 2
diff changeset
34 ntfy = notify_notification_new(NOTIFY_NAME, notify_text(info), info->critical > 0 ? "software-update-urgent" : "software-update-available");
0
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
35 notify_notification_set_timeout(ntfy, 3000);
3
f8ad23e60000 code rework, show notify window just once
Pavol Rusnak <stick@gk2.sk>
parents: 2
diff changeset
36 notify_notification_set_urgency(ntfy, info->critical > 0 ? NOTIFY_URGENCY_CRITICAL : NOTIFY_URGENCY_NORMAL);
0
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
37 notify_notification_show(ntfy, NULL);
f5e03fc667f8 initial commit
Pavol Rusnak <stick@gk2.sk>
parents:
diff changeset
38 }
3
f8ad23e60000 code rework, show notify window just once
Pavol Rusnak <stick@gk2.sk>
parents: 2
diff changeset
39
f8ad23e60000 code rework, show notify window just once
Pavol Rusnak <stick@gk2.sk>
parents: 2
diff changeset
40 const char *notify_text(struct UpdatesInfo *info)
f8ad23e60000 code rework, show notify window just once
Pavol Rusnak <stick@gk2.sk>
parents: 2
diff changeset
41 {
f8ad23e60000 code rework, show notify window just once
Pavol Rusnak <stick@gk2.sk>
parents: 2
diff changeset
42 static char buf[128];
f8ad23e60000 code rework, show notify window just once
Pavol Rusnak <stick@gk2.sk>
parents: 2
diff changeset
43 if (info->critical > 0) {
f8ad23e60000 code rework, show notify window just once
Pavol Rusnak <stick@gk2.sk>
parents: 2
diff changeset
44 snprintf(buf, sizeof(buf), "There are %d software updates available, %d of them critical.", info->normal + info->critical, info->critical);
f8ad23e60000 code rework, show notify window just once
Pavol Rusnak <stick@gk2.sk>
parents: 2
diff changeset
45 } else {
f8ad23e60000 code rework, show notify window just once
Pavol Rusnak <stick@gk2.sk>
parents: 2
diff changeset
46 snprintf(buf, sizeof(buf), "There are %d software updates available.", info->normal);
f8ad23e60000 code rework, show notify window just once
Pavol Rusnak <stick@gk2.sk>
parents: 2
diff changeset
47 }
f8ad23e60000 code rework, show notify window just once
Pavol Rusnak <stick@gk2.sk>
parents: 2
diff changeset
48 return buf;
f8ad23e60000 code rework, show notify window just once
Pavol Rusnak <stick@gk2.sk>
parents: 2
diff changeset
49 }