]> Pileus Git - lackey/blobdiff - view/year.c
Add events to year view
[lackey] / view / year.c
index 16522c836534d22e158a330c380df38f36c30b05..17a5c92d539d44012af23a5bba4e3679d7882130 100644 (file)
 #include <string.h>
 #include <ncurses.h>
 
-#include "main.h"
 #include "util.h"
+#include "date.h"
+#include "event.h"
+#include "screen.h"
 
 /* Constants */
 #define MW (2*7+6)
@@ -30,6 +32,7 @@ static WINDOW *win;
 /* Helper functions */
 static void print_month(month_t month, int y, int x)
 {
+       event_t    *event = EVENTS;
        const char *name  = month_to_string(month);
        const int   start = start_of_month(YEAR, month);
        const char  days  = days_in_month(YEAR, month);
@@ -40,9 +43,22 @@ static void print_month(month_t month, int y, int x)
        for (int d = 0; d < days; d++) {
                int row = (start + d) / 7;
                int col = (start + d) % 7;
-               if (month == MONTH && d == DAY) wattron(win, A_REVERSE);
+
+               int busy = 0;
+               while (event && before(&event->start, YEAR, month, d, 24, 0)) {
+                       if (!before(&event->start, YEAR, month, d, 0, 0))
+                               busy = 1;
+                       event = event->next;
+               }
+
+               int today = month == MONTH && d == DAY;
+
+               int attr  = (busy  ? A_BOLD|A_UNDERLINE : A_DIM)
+                         | (today ? A_REVERSE          : 0    );
+
+               wattron(win, attr);
                mvwprintw(win, y+2+row, x+col*3, "%2d", d+1);
-               if (month == MONTH && d == DAY) wattroff(win, A_REVERSE);
+               wattroff(win, attr);
        }
 }
 
@@ -52,6 +68,11 @@ void year_init(WINDOW *_win)
        win = _win;
 }
 
+/* Year size */
+void year_size(int rows, int cols)
+{
+}
+
 /* Year draw */
 void year_draw(void)
 {