2023-07-13 12:00:05 +02:00
|
|
|
/*
|
|
|
|
Fonctions utilitaires concernant les tâches
|
|
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
2023-07-16 11:06:32 +02:00
|
|
|
#include <libnotify/notify.h>
|
2023-07-13 12:00:05 +02:00
|
|
|
|
|
|
|
#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;
|
2023-07-16 11:06:32 +02:00
|
|
|
while (cur) { // Show not completed but not due_to now then
|
2023-07-13 12:00:05 +02:00
|
|
|
task_t t = cur->task;
|
|
|
|
if (!t.done && (difftime(now, t.due_to) <= 0 || t.due_to == 0)) {
|
2023-07-16 11:06:32 +02:00
|
|
|
printf(BOLD YELLOW "[%d]" RESET " %s\n", t.id, t.text); // Task not completed but fine
|
2023-07-13 12:00:05 +02:00
|
|
|
}
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (show_completed) {
|
|
|
|
cur = list;
|
2023-07-16 11:06:32 +02:00
|
|
|
while (cur) { // Show completed
|
2023-07-13 12:00:05 +02:00
|
|
|
task_t t = cur->task;
|
|
|
|
if (t.done) {
|
2023-07-16 11:06:32 +02:00
|
|
|
printf(BOLD GREEN "[%d]" RESET " %s\n", t.id, t.text); // Task already done
|
2023-07-13 12:00:05 +02:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2023-07-16 11:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2023-07-13 12:00:05 +02:00
|
|
|
}
|