summaryrefslogtreecommitdiffstats
path: root/src/todo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/todo.c')
-rw-r--r--src/todo.c171
1 files changed, 23 insertions, 148 deletions
diff --git a/src/todo.c b/src/todo.c
index bb29f61..2a207e2 100644
--- a/src/todo.c
+++ b/src/todo.c
@@ -47,7 +47,7 @@ static int first = 1;
static char *msgsav;
/* Returns a structure containing the selected item. */
-static struct todo *todo_get_item(int item_number)
+struct todo *todo_get_item(int item_number)
{
return LLIST_GET_DATA(LLIST_NTH(&todolist, item_number - 1));
}
@@ -117,26 +117,6 @@ char *todo_saved_mesg(void)
return msgsav;
}
-/* Request user to enter a new todo item. */
-void todo_new_item(void)
-{
- int ch = 0;
- const char *mesg = _("Enter the new ToDo item : ");
- const char *mesg_id =
- _("Enter the ToDo priority [1 (highest) - 9 (lowest)] :");
- char todo_input[BUFSIZ] = "";
-
- status_mesg(mesg, "");
- if (getstring(win[STA].p, todo_input, BUFSIZ, 0, 1) == GETSTRING_VALID) {
- while ((ch < '1') || (ch > '9')) {
- status_mesg(mesg_id, "");
- ch = wgetch(win[STA].p);
- }
- todo_add(todo_input, ch - '0', NULL);
- todos++;
- }
-}
-
static int todo_cmp_id(struct todo *a, struct todo *b)
{
/*
@@ -176,27 +156,20 @@ void todo_write(struct todo *todo, FILE * f)
}
/* Delete a note previously attached to a todo item. */
-static void todo_delete_note_bynum(unsigned num)
+void todo_delete_note(struct todo *todo)
{
- llist_item_t *i = LLIST_NTH(&todolist, num);
-
- if (!i)
- EXIT(_("no such todo"));
- struct todo *todo = LLIST_TS_GET_DATA(i);
-
if (!todo->note)
EXIT(_("no note attached"));
erase_note(&todo->note);
}
/* Delete an item from the todo linked list. */
-static void todo_delete_bynum(unsigned num)
+void todo_delete(struct todo *todo)
{
- llist_item_t *i = LLIST_NTH(&todolist, num);
+ llist_item_t *i = LLIST_FIND_FIRST(&todolist, todo, NULL);
if (!i)
EXIT(_("no such todo"));
- struct todo *todo = LLIST_TS_GET_DATA(i);
LLIST_REMOVE(&todolist, i);
mem_free(todo->mesg);
@@ -210,57 +183,11 @@ static void todo_delete_bynum(unsigned num)
* This way, it is easy to retrive its original priority if the user decides
* that in fact it was not completed.
*/
-void todo_flag(void)
+void todo_flag(struct todo *t)
{
- struct todo *t;
-
- t = todo_get_item(hilt);
t->id = -t->id;
}
-/* Delete an item from the ToDo list. */
-void todo_delete(void)
-{
- const char *del_todo_str = _("Do you really want to delete this task ?");
- const char *erase_warning =
- _("This item has a note attached to it. "
- "Delete (t)odo or just its (n)ote ?");
- const char *erase_choice = _("[tn]");
- const int nb_erase_choice = 2;
- int answer;
-
- if ((todos <= 0) ||
- (conf.confirm_delete && (status_ask_bool(del_todo_str) != 1))) {
- wins_erase_status_bar();
- return;
- }
-
- /* This todo item doesn't have any note associated. */
- if (todo_get_item(hilt)->note == NULL)
- answer = 1;
- else
- answer = status_ask_choice(erase_warning, erase_choice, nb_erase_choice);
-
- switch (answer) {
- case 1:
- todo_delete_bynum(hilt - 1);
- todos--;
- if (hilt > 1)
- hilt--;
- if (todos == 0)
- hilt = 0;
- if (hilt - first < 0)
- first--;
- break;
- case 2:
- todo_delete_note_bynum(hilt - 1);
- break;
- default:
- wins_erase_status_bar();
- return;
- }
-}
-
/*
* Returns the position into the linked list corresponding to the
* given todo item.
@@ -281,54 +208,30 @@ static int todo_get_position(struct todo *needle)
}
/* Change an item priority by pressing '+' or '-' inside TODO panel. */
-void todo_chg_priority(int action)
+void todo_chg_priority(struct todo *backup, int diff)
{
- struct todo *backup;
char backup_mesg[BUFSIZ];
int backup_id;
char backup_note[MAX_NOTESIZ + 1];
- backup = todo_get_item(hilt);
strncpy(backup_mesg, backup->mesg, strlen(backup->mesg) + 1);
backup_id = backup->id;
if (backup->note)
strncpy(backup_note, backup->note, MAX_NOTESIZ + 1);
else
backup_note[0] = '\0';
- switch (action) {
- case KEY_RAISE_PRIORITY:
- if (backup_id > 1)
- backup_id--;
- else
- return;
- break;
- case KEY_LOWER_PRIORITY:
- if (backup_id > 0 && backup_id < 9)
- backup_id++;
- else
- return;
- break;
- default:
- EXIT(_("no such action"));
- /* NOTREACHED */
- }
- todo_delete_bynum(hilt - 1);
+ backup_id += diff;
+ if (backup_id < 1)
+ backup_id = 1;
+ else if (backup_id > 9)
+ backup_id = 9;
+
+ todo_delete(todo_get_item(hilt));
backup = todo_add(backup_mesg, backup_id, backup_note);
hilt = todo_get_position(backup);
}
-/* Edit the description of an already existing todo item. */
-void todo_edit_item(void)
-{
- struct todo *i;
- const char *mesg = _("Enter the new ToDo description :");
-
- status_mesg(mesg, "");
- i = todo_get_item(hilt);
- updatestring(win[STA].p, &i->mesg, 0, 1);
-}
-
/* Display todo items in the corresponding panel. */
static void
display_todo_item(int incolor, char *msg, int prio, int note, int width, int y,
@@ -372,13 +275,16 @@ void todo_update_panel(int which_pan)
llist_item_t *i;
int len = win[TOD].w - 8;
int num_todo = 0;
- int y_offset = 3, x_offset = 1;
+ int title_lines = conf.compact_panels ? 1 : 3;
+ int y_offset = title_lines, x_offset = 1;
int t_realpos = -1;
- int title_lines = 3;
int todo_lines = 1;
int max_items = win[TOD].h - 4;
int incolor = -1;
+ if ((int)win[TOD].h < 4)
+ return;
+
/* Print todo item in the panel. */
erase_window_part(win[TOD].p, 1, title_lines, win[TOD].w - 2, win[TOD].h - 2);
LLIST_FOREACH(&todolist, i) {
@@ -397,9 +303,8 @@ void todo_update_panel(int which_pan)
/* Draw the scrollbar if necessary. */
if (todos > max_items) {
- float ratio = ((float)max_items) / ((float)todos);
- int sbar_length = (int)(ratio * (max_items + 1));
- int highend = (int)(ratio * first);
+ int sbar_length = max_items * (max_items + 1) / todos;
+ int highend = max_items * first / todos;
unsigned hilt_bar = (which_pan == TOD) ? 1 : 0;
int sbar_top = highend + title_lines;
@@ -413,48 +318,18 @@ void todo_update_panel(int which_pan)
}
/* Attach a note to a todo */
-void todo_edit_note(const char *editor)
+void todo_edit_note(struct todo *i, const char *editor)
{
- struct todo *i = todo_get_item(hilt);
edit_note(&i->note, editor);
}
/* View a note previously attached to a todo */
-void todo_view_note(const char *pager)
+void todo_view_note(struct todo *i, const char *pager)
{
- struct todo *i = todo_get_item(hilt);
view_note(i->note, pager);
}
-/* Pipe a todo item to an external program. */
-void todo_pipe_item(void)
-{
- char cmd[BUFSIZ] = "";
- char const *arg[] = { cmd, NULL };
- int pout;
- int pid;
- FILE *fpout;
- struct todo *todo;
-
- status_mesg(_("Pipe item to external command:"), "");
- if (getstring(win[STA].p, cmd, BUFSIZ, 0, 1) != GETSTRING_VALID)
- return;
-
- wins_prepare_external();
- if ((pid = shell_exec(NULL, &pout, *arg, arg))) {
- fpout = fdopen(pout, "w");
-
- todo = todo_get_item(hilt);
- todo_write(todo, fpout);
-
- fclose(fpout);
- child_wait(NULL, &pout, pid);
- press_any_key();
- }
- wins_unprepare_external();
-}
-
-static void todo_free(struct todo *todo)
+void todo_free(struct todo *todo)
{
mem_free(todo->mesg);
erase_note(&todo->note);