Move interaction functions to a separate file
This is a first step to clean up several compilation units and separate the front end from back-end operations. All functions that require user interaction are moved to a new compilation unit "interaction.c". Also, following things are adjusted to the new layout: * Make day_item_get_*() and a few other functions public, so that it can be accessed from the new compilation unit. * Use apoint_hilt(), todo_hilt(), etc. instead of directly accessing static variables. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
108
src/todo.c
108
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,7 +156,7 @@ 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_bynum(unsigned num)
|
||||
{
|
||||
llist_item_t *i = LLIST_NTH(&todolist, num);
|
||||
|
||||
@@ -190,7 +170,7 @@ static void todo_delete_note_bynum(unsigned num)
|
||||
}
|
||||
|
||||
/* Delete an item from the todo linked list. */
|
||||
static void todo_delete_bynum(unsigned num)
|
||||
void todo_delete_bynum(unsigned num)
|
||||
{
|
||||
llist_item_t *i = LLIST_NTH(&todolist, num);
|
||||
|
||||
@@ -218,49 +198,6 @@ void todo_flag(void)
|
||||
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.
|
||||
@@ -318,17 +255,6 @@ void todo_chg_priority(int action)
|
||||
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,
|
||||
@@ -426,34 +352,6 @@ void todo_view_note(const char *pager)
|
||||
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)
|
||||
{
|
||||
mem_free(todo->mesg);
|
||||
|
||||
Reference in New Issue
Block a user