5 #include <sys/inotify.h>
6 #include <sys/socket.h>
8 #include <notification.h>
10 #include <libwlmessage.h>
16 void sigint_handler (int s)
18 inotify_rm_watch (fd, wd);
23 void display_notifications ()
25 notification_h noti = NULL;
26 notification_list_h notification_list = NULL;
27 notification_list_h get_list = NULL;
32 char *image_path = NULL;
34 enum { NOTIF_TYPE_INFO, NOTIF_TYPE_USERPROMPT, NOTIF_TYPE_USERCONFIRM } type = 0;
35 int clicked_button = 0;
37 notification_get_list (NOTIFICATION_TYPE_NOTI, -1, ¬ification_list);
38 if (notification_list) {
39 get_list = notification_list_get_head (notification_list);
41 noti = notification_list_get_data (get_list);
42 notification_get_pkgname (noti, &pkgname);
44 notification_get_application (noti, &pkgname);
45 notification_get_title (noti, &title, NULL);
46 notification_get_text (noti, NOTIFICATION_TEXT_TYPE_CONTENT, &content);
47 notification_get_image (noti, NOTIFICATION_IMAGE_TYPE_ICON, &image_path);
49 /* react specifically to the source framework and event (TODO : plugins !) */
50 if (!strcmp(pkgname, "bt-agent")) {
51 notification_get_text (noti, NOTIFICATION_TEXT_TYPE_INFO_1, &info1);
53 if ( (!strcmp(info1, "RequestPinCode")) || (!strcmp(info1, "RequestPasskey")) ) {
54 type = NOTIF_TYPE_USERPROMPT;
56 else if (!strcmp(info1, "RequestConfirmation")) {
57 type = NOTIF_TYPE_USERCONFIRM;
58 content = strdup("Please confirm");
64 struct wlmessage *wlmessage = wlmessage_create ();
66 wlmessage_set_title (wlmessage, title);
68 wlmessage_set_icon (wlmessage, image_path);
70 wlmessage_set_message (wlmessage, content);
72 wlmessage_set_message (wlmessage, "<Default>");
73 if (type == NOTIF_TYPE_USERPROMPT)
74 wlmessage_set_textfield (wlmessage, "");
75 if (type == NOTIF_TYPE_USERCONFIRM) {
76 wlmessage_add_button (wlmessage, 1, "Yes");
77 wlmessage_add_button (wlmessage, 0, "No");
79 wlmessage_add_button (wlmessage, 0, "Ok");
82 clicked_button = wlmessage_show (wlmessage, NULL);
84 if (clicked_button < 0) {
85 wlmessage_destroy (wlmessage);
87 } else if ((clicked_button == 1) && (type == NOTIF_TYPE_USERCONFIRM)) {
88 if (!strcmp(pkgname, "bt-agent")) {
89 struct sockaddr_un addr;
90 int socket_fd, nbytes;
93 socket_fd = socket(PF_UNIX, SOCK_STREAM, 0);
95 memset (&addr, 0, sizeof(struct sockaddr_un));
96 addr.sun_family = AF_UNIX;
97 snprintf (addr.sun_path, UNIX_PATH_MAX, "/tmp/.bluetooth.service");
99 if (connect (socket_fd,
100 (struct sockaddr *)&addr,
101 sizeof(struct sockaddr_un)) != 0) {
102 fprintf(stderr, "Cannot connect to /tmp/.bluetooth.service\n");
104 nbytes = snprintf(buffer, 256, "1 clicked");
105 write (socket_fd, buffer, nbytes);
110 wlmessage_destroy (wlmessage);
113 fprintf(stderr, "\nNew Notification : %s\n", title);
114 fprintf(stderr, "Icon : %s\n", image_path);
115 fprintf(stderr, "Message : %s\n", content);
118 get_list = notification_list_remove(get_list, noti);
119 notification_delete(noti);
124 int main (int argc, char **argv)
128 /* display notifications once, so it stays useful without inotify */
129 display_notifications ();
131 fd = inotify_init ();
133 fprintf (stderr, "ERROR: cannot initialize inotify\n");
134 fprintf (stderr, "Verify that your kernel integrates it\n");
138 signal (SIGINT, sigint_handler);
139 wd = inotify_add_watch (fd, "/usr/dbspace/.notification.db", IN_MODIFY);
141 read (fd, buffer, sizeof(buffer));
142 display_notifications ();