From: Andy Spencer Date: Sun, 21 Oct 2012 07:52:07 +0000 (+0000) Subject: Add todo view X-Git-Url: http://pileus.org/git/?p=lackey;a=commitdiff_plain;h=ef789a1e6c0fa2262690f7c19824d2829f1e2a3f Add todo view --- diff --git a/cals/dummy.c b/cals/dummy.c index 62e1dd3..e68d4e6 100644 --- a/cals/dummy.c +++ b/cals/dummy.c @@ -34,10 +34,18 @@ static event_t event = { .end = {2012, OCT, 0, 13, 0}, .name = "dummy event", .desc = "this event is random and does not exist", - .next = NULL, +}; + +static todo_t todo = { + .cal = &cal, + .name = "dummy todo", + .desc = "this todo is random and does not exist", + .due = {2012, OCT, 0, 13, 0}, + .status = 50, }; static event_t events[8]; +static todo_t todos[6]; /* Event functions */ event_t *dummy_events(cal_t *cal, year_t year, month_t month, day_t day, int days) @@ -53,3 +61,15 @@ event_t *dummy_events(cal_t *cal, year_t year, month_t month, day_t day, int day } return &events[0]; } + +/* Todo functions */ +todo_t *dummy_todos(cal_t *cal, year_t year, month_t month, day_t day, int days) +{ + for (int i = 0; i < N_ELEMENTS(todos); i++) { + todos[i] = todo; + todos[i].status = i*20; + if (i+1 < N_ELEMENTS(todos)) + todos[i].next = &todos[i+1]; + } + return &todos[0]; +} diff --git a/cals/ical.c b/cals/ical.c index b39f901..028385b 100644 --- a/cals/ical.c +++ b/cals/ical.c @@ -160,6 +160,12 @@ event_t *ical_events(cal_t *cal, year_t year, month_t month, day_t day, int days /* Todo, memory management */ } +/* Todo functions */ +todo_t *ical_todos(cal_t *cal, year_t year, month_t month, day_t day, int days) +{ + return NULL; +} + /* Test functions */ void ical_printr(icalcomponent *comp, int depth) { diff --git a/doc/screen.txt b/doc/screen.txt index 4fc812a..7624e74 100644 --- a/doc/screen.txt +++ b/doc/screen.txt @@ -170,8 +170,22 @@ Todo view ┌─────────────────────────────────────────────────────────────────────┐ │ Day Week Month Year │ Events Todo │ Settings Help │ │ ─────────────────────────────────────────────────────────────────── │ + │ Due Date Status Desription [nsf] │ + │ ─────────────────────────────────────────────────────────────────── │ │ │ - │ ??? │ + │ New tasks │ + │ 2012-10-01 12:00 new Some task │ + │ 2012-10-01 12:00 new Some task │ + │ 2012-10-01 12:00 new Some task │ + │ │ + │ Started Tasks │ + │ 2012-10-01 13:00 10% Other Tasks │ + │ 2012-10-01 13:00 10% Other Tasks │ + │ 2012-10-01 13:00 10% Other Tasks │ + │ │ + │ Finished tasks: │ + │ 2012-10-01 14:00 done Some finished task │ + │ 2012-10-01 14:00 done Other finsihed task │ │ │ │ │ │ │ diff --git a/src/cal.c b/src/cal.c index 800a7f8..5e8d0c4 100644 --- a/src/cal.c +++ b/src/cal.c @@ -21,22 +21,35 @@ /* Global data */ event_t *EVENTS; +todo_t *TODOS; /* Initialize */ void cal_init(void) { EVENTS = cal_events(2012, JAN, 0, 366); + TODOS = cal_todos(2012, JAN, 0, 366); /* Debug */ for (event_t *e = EVENTS; e; e = e->next) debug("event: %04d-%02d-%02d %02d:%02d: %s - %s\n", e->start.year, e->start.month, e->start.day, e->start.hour, e->start.min, e->name, e->desc); + for (todo_t *e = TODOS; e; e = e->next) + debug("todo: %04d-%02d-%02d %02d:%02d: %s - %s\n", + e->start.year, e->start.month, e->start.day, + e->start.hour, e->start.min, e->name, e->desc); } /* Get events */ event_t *cal_events(year_t year, month_t month, day_t day, int days) { return ical_events(0, year, month, day, days) - ?: dummy_events(0, year, month, day, days); + ?: dummy_events(0, year, month, day, days); +} + +/* Get todos */ +todo_t *cal_todos(year_t year, month_t month, day_t day, int days) +{ + return ical_todos(0, year, month, day, days) + ?: dummy_todos(0, year, month, day, days); } diff --git a/src/cal.h b/src/cal.h index 3191733..ea5b958 100644 --- a/src/cal.h +++ b/src/cal.h @@ -15,35 +15,58 @@ * along with this program. If not, see . */ -/* Calendar types */ +/* Cal status types */ +typedef enum { + NEW = 0, + DONE = 100, +} status_t; + +/* Calendar type */ typedef struct { char *name; char *desc; void *data; } cal_t; -/* Calendar items */ +/* Calendar item types */ typedef struct event_t { - const cal_t *cal; const char *name; const char *desc; const char *loc; const char *cat; date_t start; date_t end; + const cal_t *cal; struct event_t *next; } event_t; +typedef struct todo_t { + const char *name; + const char *desc; + const char *cat; + status_t status; + date_t start; + date_t due; + cal_t *cal; + struct todo_t *next; +} todo_t; + /* Global data */ extern event_t *EVENTS; +extern todo_t *TODOS; /* Calendar functions */ void cal_init(void); event_t *cal_events(year_t year, month_t month, day_t day, int days); +todo_t *cal_todos(year_t year, month_t month, day_t day, int days); /* Calendar event functions */ event_t *dummy_events(cal_t *cal, year_t year, month_t month, day_t day, int days); event_t *ical_events(cal_t *cal, year_t year, month_t month, day_t day, int days); +/* Calendar todo functions */ +todo_t *dummy_todos(cal_t *cal, year_t year, month_t month, day_t day, int days); +todo_t *ical_todos(cal_t *cal, year_t year, month_t month, day_t day, int days); + /* Test fuctions */ void ical_test(void); diff --git a/src/view.c b/src/view.c index d91dae9..ac33fc8 100644 --- a/src/view.c +++ b/src/view.c @@ -50,10 +50,10 @@ view_t views[] = { { "Help", help_init, help_size, help_draw, help_run, {KEY_F(8), '8', '?'} }, }; -int active = 5; +int active = 6; /* Local functions */ -void draw_header(void) +static void draw_header(void) { move(0, 0); attron(COLOR_PAIR(COLOR_TITLE)); @@ -69,16 +69,21 @@ void draw_header(void) refresh(); } +static int get_color(const char *cat) +{ + return cat == NULL ? 0 : + !strcmp(cat, "class") ? COLOR_CLASS : + !strcmp(cat, "ec") ? COLOR_EC : + !strcmp(cat, "work") ? COLOR_WORK : COLOR_OTHER ; +} + /* Helper functions */ void event_box(WINDOW *win, event_t *event, int y, int x, int h, int w) { int l = 0; int s = y < 0 ? -y-1 : 0; - int color = event->cat == NULL ? 0 : - !strcmp(event->cat, "class") ? COLOR_CLASS : - !strcmp(event->cat, "ec") ? COLOR_EC : - !strcmp(event->cat, "work") ? COLOR_WORK : COLOR_OTHER ; + int color = get_color(event->cat); if (color) wattron(win, COLOR_PAIR(color)); @@ -101,10 +106,7 @@ void event_box(WINDOW *win, event_t *event, int y, int x, int h, int w) void event_line(WINDOW *win, event_t *event, int y, int x, int w, int full) { - int color = event->cat == NULL ? 0 : - !strcmp(event->cat, "class") ? COLOR_CLASS : - !strcmp(event->cat, "ec") ? COLOR_EC : - !strcmp(event->cat, "work") ? COLOR_WORK : COLOR_OTHER ; + int color = get_color(event->cat); if (color) wattron(win, COLOR_PAIR(color)); mvwaddch(win, y, x++, ACS_BLOCK); @@ -124,6 +126,24 @@ void event_line(WINDOW *win, event_t *event, int y, int x, int w, int full) } } +void todo_line(WINDOW *win, todo_t *todo, int y, int x, int w, int full) +{ + char perc[16]; + sprintf(perc, "%2d%%", todo->status); + + int color = get_color(todo->cat); + if (color) wattron(win, COLOR_PAIR(color)); + mvwaddch(win, y, 2, ACS_BLOCK); + if (color) wattroff(win, COLOR_PAIR(color)); + + mvwprintw(win, y, 4, "%04d-%02d-%02d %2d:%02d", + todo->due.year, todo->due.month+1, todo->due.day+1, + todo->due.hour, todo->due.min); + mvwprintw(win, y, 22, "%s", + todo->status == NEW ? "new" : + todo->status == DONE ? "done" : perc); + mvwprintw(win, y, 30, "%s: %s", todo->name, todo->desc); +} /* View init */ void view_init(void) diff --git a/src/view.h b/src/view.h index f263353..033cae5 100644 --- a/src/view.h +++ b/src/view.h @@ -27,6 +27,7 @@ /* Helper functions */ void event_box(WINDOW *win, event_t *event, int y, int x, int h, int w); void event_line(WINDOW *win, event_t *event, int y, int x, int w, int full); +void todo_line(WINDOW *win, todo_t *todo, int y, int x, int w, int full); /* View functions */ void view_init(void); diff --git a/views/todo.c b/views/todo.c index e6027f9..27fdfcd 100644 --- a/views/todo.c +++ b/views/todo.c @@ -17,9 +17,49 @@ #include +#include "util.h" +#include "date.h" +#include "cal.h" +#include "view.h" + /* Static data */ static WINDOW *win; +static int show_new = 1; +static int show_started = 1; +static int show_finished = 1; + +/* Helper functions */ +static int print_todos(WINDOW *win, int y, todo_t *todos, status_t low, status_t high) +{ + int n = 0; + for (todo_t *cur = todos; cur; cur = cur->next) + if (low <= cur->status && cur->status <= high) + todo_line(win, cur, y+n++, 2, COLS-2, 1); + return n; +} + +static int print_group(WINDOW *win, int y, todo_t *todos, + int show, const char *label, status_t low, status_t high) +{ + int n = 1; + + /* Label */ + mvwprintw(win, y, 0, "%s", label); + + /* Todos */ + if (show) + n = print_todos(win, y+1, todos, low, high); + + /* Status */ + if (!show) + mvwprintw(win, y+1, 4, "[hidden]"); + if (n == 0) + mvwprintw(win, y+1, 4, "[no tasks]"); + + return y+1+MAX(n,1)+1; +} + /* Todo init */ void todo_init(WINDOW *_win) { @@ -34,11 +74,32 @@ void todo_size(int rows, int cols) /* Todo draw */ void todo_draw(void) { - mvwprintw(win, 0, 1, "%s\n", "todo"); + int y = 0; + + y = print_group(win, y, TODOS, + show_new, "New Tasks", NEW, NEW); + + y = print_group(win, y, TODOS, + show_started, "Started Tasks", NEW+1, DONE-1); + + y = print_group(win, y, TODOS, + show_finished, "Finished Tasks", DONE, DONE); } /* Todo run */ int todo_run(int key, mmask_t btn, int row, int col) { + int ref = 0; + switch (key) + { + case 'n': ref = 1; show_new ^= 1; break; + case 's': ref = 1; show_started ^= 1; break; + case 'f': ref = 1; show_finished ^= 1; break; + } + if (ref) { + werase(win); + todo_draw(); + wrefresh(win); + } return 0; }