]> Pileus Git - lackey/commitdiff
Add todo view
authorAndy Spencer <andy753421@gmail.com>
Sun, 21 Oct 2012 07:52:07 +0000 (07:52 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 22 Oct 2012 00:35:46 +0000 (00:35 +0000)
cals/dummy.c
cals/ical.c
doc/screen.txt
src/cal.c
src/cal.h
src/view.c
src/view.h
views/todo.c

index 62e1dd38c3a9f5ccd1771f115163947e4f56b5b4..e68d4e66b6b482f34450a0e593a843bfd73dd635 100644 (file)
@@ -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",
        .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 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)
 
 /* 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];
 }
        }
        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];
+}
index b39f901512f58dee046d93ff4f1d20ef7d7ecae9..028385b7e9e7d24884ec4c3df41e173cd95cf59e 100644 (file)
@@ -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, 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)
 {
 /* Test functions */
 void ical_printr(icalcomponent *comp, int depth)
 {
index 4fc812ac89d65d180f025a6279b9382cf347d513..7624e7451f4de9950075c6b06240be41d0e3296c 100644 (file)
@@ -170,8 +170,22 @@ Todo view
    ┌─────────────────────────────────────────────────────────────────────┐
    │ Day  Week  Month  Year │ Events Todo │ Settings  Help               │
    │ ─────────────────────────────────────────────────────────────────── │
    ┌─────────────────────────────────────────────────────────────────────┐
    │ 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                     │
    │                                                                     │
    │                                                                     │
    │                                                                     │
    │                                                                     │
    │                                                                     │
    │                                                                     │
index 800a7f8b0f7fd00e6f3698f5edd6751c1918e35b..5e8d0c4375ada0f855bf88d8b183ba3e514fcc47 100644 (file)
--- a/src/cal.c
+++ b/src/cal.c
 
 /* Global data */
 event_t *EVENTS;
 
 /* Global data */
 event_t *EVENTS;
+todo_t  *TODOS;
 
 /* Initialize */
 void cal_init(void)
 {
        EVENTS = cal_events(2012, JAN, 0, 366);
 
 /* 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);
 
        /* 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)
 }
 
 /* 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);
 }
 }
index 3191733f24b70451cbdd4638aa8e4763a43dd223..ea5b9586f3bea253fc0120cc01c4f5653bfc9ba5 100644 (file)
--- a/src/cal.h
+++ b/src/cal.h
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* 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;
 
 typedef struct {
        char *name;
        char *desc;
        void *data;
 } cal_t;
 
-/* Calendar items */
+/* Calendar item types */
 typedef struct event_t {
 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 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;
 
        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;
 /* 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);
 
 /* 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 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);
 /* Test fuctions */
 void ical_test(void);
index d91dae948057d02145d446c1558e0eed7713e69f..ac33fc87f784b2c9c53359b69fde1cea0841aaf2 100644 (file)
@@ -50,10 +50,10 @@ view_t views[] = {
        { "Help",     help_init,     help_size,     help_draw,     help_run,     {KEY_F(8), '8', '?'} },
 };
 
        { "Help",     help_init,     help_size,     help_draw,     help_run,     {KEY_F(8), '8', '?'} },
 };
 
-int active = 5;
+int active = 6;
 
 /* Local functions */
 
 /* Local functions */
-void draw_header(void)
+static void draw_header(void)
 {
        move(0, 0);
        attron(COLOR_PAIR(COLOR_TITLE));
 {
        move(0, 0);
        attron(COLOR_PAIR(COLOR_TITLE));
@@ -69,16 +69,21 @@ void draw_header(void)
        refresh();
 }
 
        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;
 
 /* 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));
 
 
        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)
 {
 
 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);
 
        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)
 
 /* View init */
 void view_init(void)
index f263353b7cce78a71c091573f7e304ad888bc603..033cae551c59132db4115a635537a22fff8b1c9d 100644 (file)
@@ -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);
 /* 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);
 
 /* View functions */
 void view_init(void);
index e6027f9dedf0c2c4d5f627d520b97cf7b09d6257..27fdfcd93a871ba967a86166a2943d62b7409baa 100644 (file)
 
 #include <ncurses.h>
 
 
 #include <ncurses.h>
 
+#include "util.h"
+#include "date.h"
+#include "cal.h"
+#include "view.h"
+
 /* Static data */
 static WINDOW *win;
 
 /* 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)
 {
 /* Todo init */
 void todo_init(WINDOW *_win)
 {
@@ -34,11 +74,32 @@ void todo_size(int rows, int cols)
 /* Todo draw */
 void todo_draw(void)
 {
 /* 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)
 {
 }
 
 /* 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;
 }
        return 0;
 }