.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)
}
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];
+}
/* 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)
{
┌─────────────────────────────────────────────────────────────────────┐
│ 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 │
│ │
│ │
│ │
/* 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);
}
* 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;
-/* 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);
{ "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));
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));
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);
}
}
+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)
/* 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);
#include <ncurses.h>
+#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)
{
/* 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;
}