From: Andy Spencer Date: Mon, 15 Oct 2012 09:03:05 +0000 (+0000) Subject: Add events view X-Git-Url: http://pileus.org/git/?p=lackey;a=commitdiff_plain;h=f896842729cc916a17d828484821c85ae4140317 Add events view --- diff --git a/makefile b/makefile index 0f58f12..e3f3638 100644 --- a/makefile +++ b/makefile @@ -11,7 +11,7 @@ PROG = lackey PROG_SRC = main screen date event util TEST = test TEST_SRC = test date util -VIEWS = day week month year todo notes settings help +VIEWS = day week month year events todo settings help CALS = dummy ical # Targets diff --git a/src/screen.c b/src/screen.c index 658b9e7..c555e32 100644 --- a/src/screen.c +++ b/src/screen.c @@ -43,14 +43,14 @@ view_t views[] = { { "Month", month_init, month_size, month_draw, month_run, {KEY_F(3), '3', } }, { "Year", year_init, year_size, year_draw, year_run, {KEY_F(4), '4', } }, { "|", NULL, NULL, NULL, NULL, { } }, - { "Todo", todo_init, todo_size, todo_draw, todo_run, {KEY_F(5), '5', } }, - { "Notes", notes_init, notes_size, notes_draw, notes_run, {KEY_F(6), '6', } }, + { "Events", events_init, events_size, events_draw, events_run, {KEY_F(5), '5', } }, + { "Todo", todo_init, todo_size, todo_draw, todo_run, {KEY_F(6), '6', } }, { "|", NULL, NULL, NULL, NULL, { } }, { "Settings", settings_init, settings_size, settings_draw, settings_run, {KEY_F(7), '7', } }, { "Help", help_init, help_size, help_draw, help_run, {KEY_F(8), '8', '?'} }, }; -int active = 0; +int active = 5; /* Local functions */ void draw_header(void) @@ -99,7 +99,7 @@ void event_box(WINDOW *win, event_t *event, int y, int x, int h, int w) if (ldesc) mvwprintw(win, y+l++, x+1, "%.*s", w-2, event->desc); } -void event_line(WINDOW *win, event_t *event, int y, int x, 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 : @@ -107,10 +107,21 @@ void event_line(WINDOW *win, event_t *event, int y, int x, int w) !strcmp(event->cat, "work") ? COLOR_WORK : COLOR_OTHER ; if (color) wattron(win, COLOR_PAIR(color)); - mvwaddch(win, y, x+0, ACS_BLOCK); + mvwaddch(win, y, x++, ACS_BLOCK); if (color) wattroff(win, COLOR_PAIR(color)); - mvwprintw(win, y, x+1, "%-*.*s", w-1, w-1, event->name); + if (full) { + mvwprintw(win, y, x, " %02d:%02d - ", event->start.hour, event->start.min); + x += 9; + } + if (event->name) { + const char *label = event->name ?: event->desc; + mvwprintw(win, y, x, "%-*.*s", w-1, w-1, label); + x += MIN(strlen(label), w-1); + } + if (full && event->loc) { + mvwprintw(win, y, x, " @ %s", event->loc); + } } diff --git a/src/screen.h b/src/screen.h index cf83b6e..9f9d4e9 100644 --- a/src/screen.h +++ b/src/screen.h @@ -26,7 +26,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); +void event_line(WINDOW *win, event_t *event, int y, int x, int w, int full); /* Screen functions */ void screen_init(void); @@ -39,8 +39,8 @@ void day_init(WINDOW *win); void week_init(WINDOW *win); void month_init(WINDOW *win); void year_init(WINDOW *win); +void events_init(WINDOW *win); void todo_init(WINDOW *win); -void notes_init(WINDOW *win); void settings_init(WINDOW *win); void help_init(WINDOW *win); @@ -49,8 +49,8 @@ void day_size(int,int); void week_size(int,int); void month_size(int,int); void year_size(int,int); +void events_size(int,int); void todo_size(int,int); -void notes_size(int,int); void settings_size(int,int); void help_size(int,int); @@ -59,8 +59,8 @@ void day_draw(void); void week_draw(void); void month_draw(void); void year_draw(void); +void events_draw(void); void todo_draw(void); -void notes_draw(void); void settings_draw(void); void help_draw(void); @@ -69,7 +69,7 @@ int day_run(int,mmask_t,int,int); int week_run(int,mmask_t,int,int); int month_run(int,mmask_t,int,int); int year_run(int,mmask_t,int,int); +int events_run(int,mmask_t,int,int); int todo_run(int,mmask_t,int,int); -int notes_run(int,mmask_t,int,int); int settings_run(int,mmask_t,int,int); int help_run(int,mmask_t,int,int); diff --git a/view/events.c b/view/events.c new file mode 100644 index 0000000..8b888cd --- /dev/null +++ b/view/events.c @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2012 Andy Spencer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#define DEBUG + +#include + +#include +#include +#include +#include + +/* Static data */ +static WINDOW *win; +static int line; +static int rows; + +/* Events init */ +void events_init(WINDOW *_win) +{ + win = _win; +} + +/* Events size */ +void events_size(int rows, int cols) +{ +} + +/* Events draw */ +void events_draw(void) +{ + int days = 2*7; + int min = 12; + + date_t start = {YEAR, MONTH, DAY, 0, 0}; + date_t cur = {YEAR, MONTH, DAY-1, 0, 0}; + date_t end = {YEAR, MONTH, DAY, 24, 0}; + add_days(&end.year, &end.month, &end.day, days); + + int row = 0; + int count = 0; + event_t *event = EVENTS; + while (event && (count < min || compare(&event->start, &end) < 0)) { + if (compare(&start, &event->start) <= 0) { + date_t next = event->start; + int newdate = cur.year != next.year || + cur.month != next.month || + cur.day != next.day ; + int newtime = cur.hour != next.hour || + cur.min != next.min ; + if ((newdate || newtime) && row != 0) + row++; + if (newdate && row != 0) + row++; + if (newdate) { + wday_t wday = day_of_week(next.year, next.month, next.day); + wattron(win, A_UNDERLINE); + mvwprintw(win, row-line, 0, "%04d-%02d-%02d", + next.year, next.month+1, next.day+1); + mvwprintw(win, row-line, 13, "%s, %s %d", + day_to_string(wday), month_to_string(next.month), next.day); + wattroff(win, A_UNDERLINE); + row++; + } + event_line(win, event, row++-line, 3, COLS-2, 1); + if (event->name && event->desc) + mvwprintw(win, row++-line, 13, "%s", event->desc); + cur = next; + count += 1; + } + event = event->next; + } + rows = row; +} + +/* Events run */ +int events_run(int key, mmask_t btn, int row, int col) +{ + int scroll = 0; + switch (key) + { + case 'g': scroll = -line; break; + case 'G': scroll = rows; break; + case 'j': scroll = 1; break; + case 'k': scroll = -1; break; + case 'd': scroll = LINES/2; break; + case 'u': scroll = -LINES/2; break; + case 'D': scroll = LINES; break; + case 'U': scroll = -LINES; break; + } + line = CLAMP(line+scroll, 0, rows-1); + if (scroll) { + werase(win); + events_draw(); + wrefresh(win); + } + return 0; +} diff --git a/view/help.c b/view/help.c index 12a0e8f..c98df24 100644 --- a/view/help.c +++ b/view/help.c @@ -35,7 +35,6 @@ void help_size(int rows, int cols) void help_draw(void) { mvwprintw(win, 0, 1, "%s\n", "help"); - wrefresh(win); } /* Help run */ diff --git a/view/month.c b/view/month.c index 2179f4f..fb1ec8c 100644 --- a/view/month.c +++ b/view/month.c @@ -77,7 +77,7 @@ void month_draw(void) while (event && before(&event->start, YEAR, MONTH, d, 24, 0)) { if (!before(&event->start, YEAR, MONTH, d, 0, 0)){ if (y == e) mvwhline(win, y, x-3, ACS_DARROW, 2); - if (y <= e) event_line(win, event, y, x, w); + if (y <= e) event_line(win, event, y, x, w, 0); y++; } event = event->next; diff --git a/view/notes.c b/view/notes.c deleted file mode 100644 index 3414ff3..0000000 --- a/view/notes.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2012 Andy Spencer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include - -/* Static data */ -static WINDOW *win; - -/* Notes init */ -void notes_init(WINDOW *_win) -{ - win = _win; -} - -/* Notes size */ -void notes_size(int rows, int cols) -{ -} - -/* Notes draw */ -void notes_draw(void) -{ - mvwprintw(win, 0, 1, "%s\n", "notes"); - wrefresh(win); -} - -/* Notes run */ -int notes_run(int key, mmask_t btn, int row, int col) -{ - return 0; -} diff --git a/view/settings.c b/view/settings.c index 4015876..29aa2c7 100644 --- a/view/settings.c +++ b/view/settings.c @@ -35,7 +35,6 @@ void settings_size(int rows, int cols) void settings_draw(void) { mvwprintw(win, 0, 1, "%s\n", "settings"); - wrefresh(win); } /* Settings run */ diff --git a/view/todo.c b/view/todo.c index e2658c6..e6027f9 100644 --- a/view/todo.c +++ b/view/todo.c @@ -35,7 +35,6 @@ void todo_size(int rows, int cols) void todo_draw(void) { mvwprintw(win, 0, 1, "%s\n", "todo"); - wrefresh(win); } /* Todo run */