Compare commits
2 Commits
61de4adf18
...
114c5f901f
Author | SHA1 | Date | |
---|---|---|---|
114c5f901f | |||
be6c4fa9c5 |
5
Makefile
5
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
|
||||
rm ./takl
|
||||
rm ./takl-daemon
|
49
src/daemon.c
49
src/daemon.c
@ -1,16 +1,65 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "main/include/colors.h"
|
||||
#include "main/include/config.h"
|
||||
#include "main/include/tasks.h"
|
||||
#include "main/include/db.h"
|
||||
|
||||
#include "log/log.h"
|
||||
|
||||
task_t next_task(task_list_t* tasks) {
|
||||
time_t now = time(0);
|
||||
|
||||
task_t next;
|
||||
next.due_to = 0;
|
||||
|
||||
task_list_t* cur = tasks;
|
||||
|
||||
while (cur) {
|
||||
task_t t = cur->task;
|
||||
|
||||
if (!t.done && (difftime(now, t.due_to) <= 0 || t.due_to == 0)) { // La tâche a une échéance, qui n'est pas passée
|
||||
if (next.due_to == 0 || difftime(next.due_to, t.due_to) >= 0) {
|
||||
next = t;
|
||||
}
|
||||
}
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
return next;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
log_info("TaKl " VERSION " -- Daemon started");
|
||||
|
||||
task_list_t* tasks = get_task_list(false);
|
||||
|
||||
while (1) {
|
||||
task_t next = next_task(tasks);
|
||||
|
||||
if (next.due_to == 0) {
|
||||
log_fatal("Plus de tâches avec échéance dans la liste");
|
||||
free_task_list(tasks);
|
||||
return 1;
|
||||
}
|
||||
|
||||
time_t now = time(0);
|
||||
double wait = difftime(next.due_to, now) + 5;
|
||||
log_debug("Attente de %0.1lfs", wait);
|
||||
sleep(wait);
|
||||
|
||||
log_debug("Envoi de la notification tâche [%d]", next.id);
|
||||
desktop_notification(next);
|
||||
//! si deux tâches sont à la même date à moins de 0.1s près,
|
||||
//! l'une des deux seulement sera affichée
|
||||
}
|
||||
|
||||
free_task_list(tasks);
|
||||
return 0;
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
#ifndef DEF_CONFIG_H
|
||||
#define DEF_CONFIG_H
|
||||
|
||||
#define VERSION "1.0.2"
|
||||
#define VERSION "1.0.3"
|
||||
|
||||
// By default, $HOME/.config/takl.sqlite3 is used. You can change this behaviour here
|
||||
//#define DB_FILE "takl.sqlite3"
|
||||
|
@ -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
|
@ -4,6 +4,7 @@ Fonctions utilitaires concernant les tâches
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <libnotify/notify.h>
|
||||
|
||||
#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();
|
||||
}
|
Loading…
Reference in New Issue
Block a user