diff options
author | Lukas Fleischer <lfleischer@calcurse.org> | 2016-01-17 22:46:24 +0100 |
---|---|---|
committer | Lukas Fleischer <lfleischer@calcurse.org> | 2016-01-18 18:08:34 +0100 |
commit | beea88e5feb6f14b4912c6aa4878c39a7632977c (patch) | |
tree | 6559c7090a687a4b96319b9bc1539050f913f27a /src/todo.c | |
parent | 1a4bf2b0a2a54393c401522611f85c2637d1de88 (diff) | |
download | calcurse-beea88e5feb6f14b4912c6aa4878c39a7632977c.zip |
Use a separate field for the completed status
Add a new field that indicates whether a todo item is completed or not
instead of encoding completed todo items by negative priorities.
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src/todo.c')
-rw-r--r-- | src/todo.c | 30 |
1 files changed, 10 insertions, 20 deletions
@@ -45,7 +45,7 @@ llist_t todolist; static int todo_is_uncompleted(struct todo *todo, void *cbdata) { - return todo->id >= 0; + return !todo->completed; } /* Returns a structure containing the selected item. */ @@ -64,27 +64,20 @@ struct todo *todo_get_item(int item_number, int skip_completed) static int todo_cmp_id(struct todo *a, struct todo *b) { - /* - * As of version 2.6, todo items can have a negative id, which means they - * were completed. To keep them sorted, we need to consider the absolute id - * value. - */ - int abs_a = abs(a->id); - int abs_b = abs(b->id); - - return abs_a < abs_b ? -1 : (abs_a == abs_b ? 0 : 1); + return a->id - b->id; } /* * Add an item in the todo linked list. */ -struct todo *todo_add(char *mesg, int id, char *note) +struct todo *todo_add(char *mesg, int id, int completed, char *note) { struct todo *todo; todo = mem_malloc(sizeof(struct todo)); todo->mesg = mem_strdup(mesg); todo->id = id; + todo->completed = completed; todo->note = (note != NULL && note[0] != '\0') ? mem_strdup(note) : NULL; @@ -96,11 +89,13 @@ struct todo *todo_add(char *mesg, int id, char *note) char *todo_tostr(struct todo *todo) { char *res; + const char *cstr = todo->completed ? "-" : ""; if (todo->note) - asprintf(&res, "[%d]>%s %s", todo->id, todo->note, todo->mesg); + asprintf(&res, "[%s%d]>%s %s", cstr, todo->id, todo->note, + todo->mesg); else - asprintf(&res, "[%d] %s", todo->id, todo->mesg); + asprintf(&res, "[%s%d] %s", cstr, todo->id, todo->mesg); return res; } @@ -144,15 +139,10 @@ void todo_delete(struct todo *todo) mem_free(todo); } -/* - * Flag a todo item (for now on, only the 'completed' state is available). - * Internally, a completed item keeps its priority, but it becomes negative. - * This way, it is easy to retrive its original priority if the user decides - * that in fact it was not completed. - */ +/* Flag a todo item. */ void todo_flag(struct todo *t) { - t->id = -t->id; + t->completed = !t->completed; } /* |