5 #include <sys/inotify.h>
6 #include <notification.h>
8 #include <libwlmessage.h>
14 void sigint_handler (int s)
16 inotify_rm_watch (fd, wd);
21 void display_notifications ()
23 notification_h noti = NULL;
24 notification_list_h notification_list = NULL;
25 notification_list_h get_list = NULL;
30 char *image_path = NULL;
32 enum { NOTIF_TYPE_INFO, NOTIF_TYPE_USERPROMPT, NOTIF_TYPE_USERCONFIRM } type = 0;
35 notification_get_list (NOTIFICATION_TYPE_NOTI, -1, ¬ification_list);
36 if (notification_list) {
37 get_list = notification_list_get_head (notification_list);
39 noti = notification_list_get_data (get_list);
40 notification_get_pkgname (noti, &pkgname);
42 notification_get_application (noti, &pkgname);
43 notification_get_title (noti, &title, NULL);
44 notification_get_text (noti, NOTIFICATION_TEXT_TYPE_CONTENT, &content);
45 notification_get_image (noti, NOTIFICATION_IMAGE_TYPE_ICON, &image_path);
47 /* react specifically to the source framework and event (TODO : plugins !) */
48 if (!strcmp(pkgname, "bt-agent")) {
49 notification_get_text (noti, NOTIFICATION_TEXT_TYPE_INFO_1, &info1);
51 if ( (!strcmp(info1, "RequestPinCode")) || (!strcmp(info1, "RequestPasskey")) ) {
52 type = NOTIF_TYPE_USERPROMPT;
54 else if (!strcmp(info1, "RequestConfirmation")) {
55 type = NOTIF_TYPE_USERCONFIRM;
56 content = "Please confirm";
62 struct wlmessage *wlmessage = wlmessage_create ();
64 wlmessage_set_title (wlmessage, title);
66 wlmessage_set_icon (wlmessage, image_path);
68 wlmessage_set_message (wlmessage, content);
70 wlmessage_set_message (wlmessage, "<Default>");
71 if (type == NOTIF_TYPE_USERPROMPT)
72 wlmessage_set_textfield (wlmessage, "");
73 if (type == NOTIF_TYPE_USERCONFIRM) {
74 wlmessage_add_button (wlmessage, 1, "Yes");
75 wlmessage_add_button (wlmessage, 0, "No");
77 wlmessage_add_button (wlmessage, 0, "Ok");
80 if (wlmessage_show (wlmessage, NULL) < 0) {
81 wlmessage_destroy (wlmessage);
84 wlmessage_destroy (wlmessage);
87 fprintf(stderr, "\nNew Notification : %s\n", title);
88 fprintf(stderr, "Icon : %s\n", image_path);
89 fprintf(stderr, "Message : %s\n", content);
92 get_list = notification_list_remove(get_list, noti);
93 notification_delete(noti);
98 int main (int argc, char **argv)
102 /* display notifications once, so it stays useful without inotify */
103 display_notifications ();
105 fd = inotify_init ();
107 fprintf (stderr, "ERROR: cannot initialize inotify\n");
108 fprintf (stderr, "Verify that your kernel integrates it\n");
112 signal (SIGINT, sigint_handler);
113 wd = inotify_add_watch (fd, "/usr/dbspace/.notification.db", IN_MODIFY);
115 read (fd, buffer, sizeof(buffer));
116 display_notifications ();