2 * Copyright (C) 2012-2013 Andy Spencer <andy753421@gmail.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 void events_init(WINDOW *_win)
38 void events_size(int rows, int cols)
43 void events_draw(void)
48 date_t start = {SEL.year, SEL.month, SEL.day, 0, 0};
49 date_t cur = {SEL.year, SEL.month, SEL.day-1, 0, 0};
50 date_t end = {SEL.year, SEL.month, SEL.day, 24, 0};
51 add_days(&end.year, &end.month, &end.day, days);
52 cal_load(SEL.year, SEL.month, SEL.day, days);
56 event_t *event = EVENTS;
57 while (event && (count < min || compare(&event->start, &end) < 0)) {
58 if (compare(&start, &event->start) <= 0) {
59 date_t next = event->start;
60 int newdate = cur.year != next.year ||
61 cur.month != next.month ||
63 int newtime = cur.hour != next.hour ||
67 if (EVENT == NULL || compare(&EVENT->start, &start) < 0)
70 /* Spacing before the date */
71 if ((newdate || newtime) && row != 0)
73 if (newdate && row != 0)
78 wday_t wday = day_of_week(next.year, next.month, next.day);
80 mvwprintw(win, row-line, 0, "%04d-%02d-%02d",
81 next.year, next.month+1, next.day+1);
82 mvwprintw(win, row-line, 13, "%s, %s %d",
83 day_to_string(wday), month_to_string(next.month), next.day+1);
84 wattroff(win, A_BOLD);
88 /* Print event info */
89 event_line(win, event, row++-line, 4, COLS-4,
90 SHOW_DETAILS | SHOW_ACTIVE);
91 if (event->name && event->desc) {
92 int n = MIN(COLS-14, strcspn(event->desc, "\n"));
93 mvwprintw(win, row++-line, 14, "%.*s", n, event->desc);
105 int events_run(int key, mmask_t btn, int row, int col)
107 int scroll = 0, move = 0;
110 case 'g': scroll = -line; break;
111 case 'G': scroll = rows; break;
112 case '\005': scroll = 1; break; // ctrl-e
113 case '\031': scroll = -1; break; // ctrl-y
114 case 'd': scroll = LINES/2; break;
115 case 'u': scroll = -LINES/2; break;
116 case 'D': scroll = LINES; break;
117 case 'U': scroll = -LINES; break;
118 case 'j': move = 1; break;
119 case 'k': move = -1; break;
120 case 'e': view_edit(EDIT_EVENT); return 1;
121 case '\012': view_edit(EDIT_EVENT); return 1; // enter
123 line = CLAMP(line+scroll, 0, rows-1);
124 for (int i=0; i<move && EVENT && EVENT->next; i++)
126 for (int i=0; i>move && EVENT && EVENT->prev; i--)
128 if (scroll || move) {
133 return scroll || move;