aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am1
-rw-r--r--src/calcurse.c10
-rw-r--r--src/calcurse.h8
-rw-r--r--src/interaction.c102
-rw-r--r--src/ui-todo.c140
5 files changed, 150 insertions, 111 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index cb44177..7c38cd0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -32,6 +32,7 @@ calcurse_SOURCES = \
sha1.c \
sigs.c \
todo.c \
+ ui-todo.c \
utf8.c \
utils.c \
vars.c \
diff --git a/src/calcurse.c b/src/calcurse.c
index a8dace1..34b93db 100644
--- a/src/calcurse.c
+++ b/src/calcurse.c
@@ -133,7 +133,7 @@ static inline void key_generic_add_appt(void)
static inline void key_generic_add_todo(void)
{
- interact_todo_add();
+ ui_todo_add();
if (todo_hilt() == 0 && todo_nb() == 1)
todo_hilt_increase(1);
wins_update(FLAG_TOD | FLAG_STA);
@@ -148,7 +148,7 @@ static inline void key_add_item(void)
wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
break;
case TOD:
- interact_todo_add();
+ ui_todo_add();
if (todo_hilt() == 0 && todo_nb() == 1)
todo_hilt_increase(1);
wins_update(FLAG_TOD | FLAG_STA);
@@ -165,7 +165,7 @@ static inline void key_edit_item(void)
inday = do_storage(0);
wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
} else if (wins_slctd() == TOD && todo_hilt() != 0) {
- interact_todo_edit();
+ ui_todo_edit();
wins_update(FLAG_TOD | FLAG_STA);
}
}
@@ -177,7 +177,7 @@ static inline void key_del_item(void)
inday = do_storage(0);
wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
} else if (wins_slctd() == TOD && todo_hilt() != 0) {
- interact_todo_delete();
+ ui_todo_delete();
wins_update(FLAG_TOD | FLAG_STA);
}
}
@@ -225,7 +225,7 @@ static inline void key_pipe_item(void)
if (wins_slctd() == APP && apoint_hilt() != 0)
interact_day_item_pipe();
else if (wins_slctd() == TOD && todo_hilt() != 0)
- interact_todo_pipe();
+ ui_todo_pipe();
wins_update(FLAG_ALL);
}
diff --git a/src/calcurse.h b/src/calcurse.h
index dd974a8..1fb7a47 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -738,10 +738,10 @@ void interact_day_item_repeat(void);
void interact_day_item_cut_free(unsigned);
void interact_day_item_copy(unsigned *, unsigned *, unsigned);
void interact_day_item_paste(unsigned *, unsigned *, unsigned);
-void interact_todo_add(void);
-void interact_todo_delete(void);
-void interact_todo_edit(void);
-void interact_todo_pipe(void);
+void ui_todo_add(void);
+void ui_todo_delete(void);
+void ui_todo_edit(void);
+void ui_todo_pipe(void);
/* io.c */
unsigned io_fprintln(const char *, const char *, ...);
diff --git a/src/interaction.c b/src/interaction.c
index 49ebac5..486ad75 100644
--- a/src/interaction.c
+++ b/src/interaction.c
@@ -594,108 +594,6 @@ void interact_day_item_delete(unsigned *nb_events, unsigned *nb_apoints,
apoint_hilt_set(0);
}
-/* Request user to enter a new todo item. */
-void interact_todo_add(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[KEY].p);
- }
- todo_add(todo_input, ch - '0', NULL);
- todo_set_nb(todo_nb() + 1);
- }
-}
-
-/* Delete an item from the ToDo list. */
-void interact_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 ((todo_nb() <= 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(todo_hilt())->note == NULL)
- answer = 1;
- else
- answer = status_ask_choice(erase_warning, erase_choice, nb_erase_choice);
-
- switch (answer) {
- case 1:
- todo_delete(todo_get_item(todo_hilt()));
- todo_set_nb(todo_nb() - 1);
- if (todo_hilt() > 1)
- todo_hilt_decrease(1);
- if (todo_nb() == 0)
- todo_hilt_set(0);
- if (todo_hilt_pos() < 0)
- todo_first_decrease(1);
- break;
- case 2:
- todo_delete_note(todo_get_item(todo_hilt()));
- break;
- default:
- wins_erase_status_bar();
- return;
- }
-}
-
-/* Edit the description of an already existing todo item. */
-void interact_todo_edit(void)
-{
- struct todo *i;
- const char *mesg = _("Enter the new ToDo description :");
-
- status_mesg(mesg, "");
- i = todo_get_item(todo_hilt());
- updatestring(win[STA].p, &i->mesg, 0, 1);
-}
-
-/* Pipe a todo item to an external program. */
-void interact_todo_pipe(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(todo_hilt());
- todo_write(todo, fpout);
-
- fclose(fpout);
- child_wait(NULL, &pout, pid);
- press_any_key();
- }
- wins_unprepare_external();
-}
-
/*
* Ask user for repetition characteristics:
* o repetition type: daily, weekly, monthly, yearly
diff --git a/src/ui-todo.c b/src/ui-todo.c
new file mode 100644
index 0000000..d8f659c
--- /dev/null
+++ b/src/ui-todo.c
@@ -0,0 +1,140 @@
+/*
+ * Calcurse - text-based organizer
+ *
+ * Copyright (c) 2004-2013 calcurse Development Team <misc@calcurse.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the
+ * following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the
+ * following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Send your feedback or comments to : misc@calcurse.org
+ * Calcurse home page : http://calcurse.org
+ *
+ */
+
+#include "calcurse.h"
+
+/* Request user to enter a new todo item. */
+void ui_todo_add(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[KEY].p);
+ }
+ todo_add(todo_input, ch - '0', NULL);
+ todo_set_nb(todo_nb() + 1);
+ }
+}
+
+/* Delete an item from the ToDo list. */
+void ui_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 ((todo_nb() <= 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(todo_hilt())->note == NULL)
+ answer = 1;
+ else
+ answer = status_ask_choice(erase_warning, erase_choice, nb_erase_choice);
+
+ switch (answer) {
+ case 1:
+ todo_delete(todo_get_item(todo_hilt()));
+ todo_set_nb(todo_nb() - 1);
+ if (todo_hilt() > 1)
+ todo_hilt_decrease(1);
+ if (todo_nb() == 0)
+ todo_hilt_set(0);
+ if (todo_hilt_pos() < 0)
+ todo_first_decrease(1);
+ break;
+ case 2:
+ todo_delete_note(todo_get_item(todo_hilt()));
+ break;
+ default:
+ wins_erase_status_bar();
+ return;
+ }
+}
+
+/* Edit the description of an already existing todo item. */
+void ui_todo_edit(void)
+{
+ struct todo *i;
+ const char *mesg = _("Enter the new ToDo description :");
+
+ status_mesg(mesg, "");
+ i = todo_get_item(todo_hilt());
+ updatestring(win[STA].p, &i->mesg, 0, 1);
+}
+
+/* Pipe a todo item to an external program. */
+void ui_todo_pipe(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(todo_hilt());
+ todo_write(todo, fpout);
+
+ fclose(fpout);
+ child_wait(NULL, &pout, pid);
+ press_any_key();
+ }
+ wins_unprepare_external();
+}
+