From cc0afaa75d95225665f304933a146fb33ce1aa5a Mon Sep 17 00:00:00 2001 From: Manuel Bachmann Date: Sun, 1 Jun 2014 11:56:54 +0200 Subject: [PATCH] Add missing source. Change-Id: I793f45c1a2937a93e2c97569268d817564c7dcfa Signed-off-by: Manuel Bachmann --- notification_display_service.c | 81 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 notification_display_service.c diff --git a/notification_display_service.c b/notification_display_service.c new file mode 100644 index 0000000..3e25ea5 --- /dev/null +++ b/notification_display_service.c @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#include +#ifdef HAVE_WAYLAND +#include +#endif + + +int fd, wd; + +void sigint_handler (int s) +{ + inotify_rm_watch (fd, wd); + close (fd); + exit (0); +} + +void display_notifications () +{ + notification_h noti = NULL; + notification_list_h notification_list = NULL; + notification_list_h get_list = NULL; + + char *pkgname = NULL; + char *title = NULL; + char *content = NULL; + char *image_path = NULL; + + notification_get_list (NOTIFICATION_TYPE_NOTI, -1, ¬ification_list); + if (notification_list) { + get_list = notification_list_get_head (notification_list); + while (get_list) { + noti = notification_list_get_data (get_list); + notification_get_pkgname (noti, &pkgname); + if (pkgname == NULL) + notification_get_application (noti, &pkgname); + notification_get_title (noti, &title, NULL); + notification_get_text (noti, NOTIFICATION_TEXT_TYPE_CONTENT, &content); + notification_get_image (noti, NOTIFICATION_IMAGE_TYPE_ICON, &image_path); + +# ifdef HAVE_WAYLAND + struct wlmessage *wlmessage = wlmessage_create (); + wlmessage_set_title (wlmessage, title); + wlmessage_set_icon (wlmessage, image_path); + wlmessage_set_message (wlmessage, content); + wlmessage_add_button (wlmessage, 0, "Ok"); + wlmessage_show (wlmessage, NULL); + wlmessage_destroy (wlmessage); +# endif + + notification_delete (noti); + get_list = notification_list_get_head (notification_list); + } + } +} + +int main (int argc, char **argv) +{ + char buffer[8192]; + + /* display notifications once, so it stays useful without inotify */ + display_notifications (); + + fd = inotify_init (); + if (fd < 0) { + fprintf (stderr, "ERROR: cannot initialize inotify\n"); + fprintf (stderr, "Verify that your kernel integrates it\n"); + return -1; + } + + signal (SIGINT, sigint_handler); + wd = inotify_add_watch (fd, "/opt/dbspace/.notification.db", IN_MODIFY); + while (1) { + read (fd, buffer, sizeof(buffer)); + display_notifications (); + } + + return 0; +} -- 2.7.4