/* Fonctions utilitaires concernant les tâches */ #include #include #include #include #include "include/db.h" #include "include/struct.h" #include "include/colors.h" task_t create_task(char* text, time_t due_to) { task_t task; task.id = get_new_task_id(); task.text = text; task.done = false; task.due_to = due_to; return task; } void print_task(task_t task) { printf(YELLOW "=== Tâche " BOLD "[%d]" RESET YELLOW " ===\n" RESET, task.id); printf(BOLD "%s\n" RESET, task.text); printf("Statut: "); if (task.done) { printf(GREEN "Complétée\n" RESET); } else { time_t now = time(0); if (difftime(now, task.due_to) <= 0 || task.due_to == 0) { printf(BLUE "À faire\n" RESET); } else { printf(RED "À faire\n" RESET); } } if (task.due_to != 0) { struct tm * timeinfo; char buffer[80]; timeinfo = localtime(&task.due_to); strftime(buffer,sizeof(buffer),"%d-%m-%Y %H:%M:%S",timeinfo); printf("Dûe le %s\n", buffer); } } void print_task_list(task_list_t* list, bool show_completed) { task_list_t* cur = list; time_t now = time(0); while (cur) { // Show not completed red tasks first task_t t = cur->task; if (!t.done && difftime(now, t.due_to) >= 0 && t.due_to != 0) { printf(BOLD RED "[%d]" RESET " %s\n", t.id, t.text); // Task not completed but should be ! } cur = cur->next; } cur = list; 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 fine } cur = cur->next; } if (show_completed) { cur = list; while (cur) { // Show completed task_t t = cur->task; if (t.done) { printf(BOLD GREEN "[%d]" RESET " %s\n", t.id, t.text); // Task already done } cur = cur->next; } } } void free_task_list(task_list_t* list) { while (list) { task_list_t* next = list->next; free(list->task.text); 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(); }