From be6c4fa9c58c940aa1ee2dedc584765842fafbfa Mon Sep 17 00:00:00 2001 From: augustin64 Date: Sun, 16 Jul 2023 11:06:32 +0200 Subject: [PATCH] Add desktop notifications code --- Makefile | 5 +++-- src/main/include/tasks.h | 5 +++++ src/main/tasks.c | 17 +++++++++++++---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 5372826..80e4f88 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -FLAGS = -g -Wall -Wextra -DLOG_USE_COLOR +FLAGS = -g -Wall -Wextra -DLOG_USE_COLOR `pkg-config --cflags --libs libnotify` LD_FLAGS = -lsqlite3 @@ -33,4 +33,5 @@ uninstall: takl clean: rm out -r - rm ./takl \ No newline at end of file + rm ./takl + rm ./takl-daemon \ No newline at end of file diff --git a/src/main/include/tasks.h b/src/main/include/tasks.h index 55a2836..d8e3c8a 100644 --- a/src/main/include/tasks.h +++ b/src/main/include/tasks.h @@ -23,4 +23,9 @@ Libère la mémoire allouée à une liste de tâches */ void free_task_list(task_list_t* list); +/* +Envoyer une notification avec t +*/ +void desktop_notification(task_t t); + #endif \ No newline at end of file diff --git a/src/main/tasks.c b/src/main/tasks.c index 44bbfbf..ffcc193 100644 --- a/src/main/tasks.c +++ b/src/main/tasks.c @@ -4,6 +4,7 @@ Fonctions utilitaires concernant les tâches #include #include #include +#include #include "include/db.h" #include "include/struct.h" @@ -64,20 +65,20 @@ void print_task_list(task_list_t* list, bool show_completed) { } cur = list; - while (cur) { // Show not completed but not due_to then + while (cur) { // Show not completed but not due_to now then task_t t = cur->task; if (!t.done && (difftime(now, t.due_to) <= 0 || t.due_to == 0)) { - printf(BOLD YELLOW "[%d]" RESET " %s\n", t.id, t.text); // Task not completed but should be ! + printf(BOLD YELLOW "[%d]" RESET " %s\n", t.id, t.text); // Task not completed but fine } cur = cur->next; } if (show_completed) { cur = list; - while (cur) { // Show not completed but not due_to then + while (cur) { // Show completed task_t t = cur->task; if (t.done) { - printf(BOLD GREEN "[%d]" RESET " %s\n", t.id, t.text); // Task not completed but should be ! + printf(BOLD GREEN "[%d]" RESET " %s\n", t.id, t.text); // Task already done } cur = cur->next; } @@ -92,4 +93,12 @@ void free_task_list(task_list_t* list) { free(list); list = next; } +} + +void desktop_notification(task_t t) { + notify_init ("TaKl"); + NotifyNotification * Notif = notify_notification_new ("TaKl Daemon", t.text, "dialog-information"); + notify_notification_show (Notif, NULL); + g_object_unref(G_OBJECT(Notif)); + notify_uninit(); } \ No newline at end of file