]> Pileus Git - lackey/blobdiff - views/week.c
Make morning time configurable
[lackey] / views / week.c
index 1fe5e17ec33ce1e665da0c23dc0dea0af24a522a..9f972521ad8c220f994d5bcc8ca5fe51b8ab15f7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Andy Spencer <andy753421@gmail.com>
+ * Copyright (C) 2012-2013 Andy Spencer <andy753421@gmail.com>
  *
  * 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
@@ -36,7 +36,7 @@ void week_init(WINDOW *_win)
        win   = _win; //    lines    cols    y  x
        times = derwin(win, LINES-2,      5, 0, 0);
        body  = derwin(win, LINES-2, COLS-5, 0, 5);
-       line  = 10*4; // 10:00
+       line  = MORNING*4;
 }
 
 /* Week size */
@@ -53,14 +53,18 @@ void week_draw(void)
        int x = 6;
        int y = 3 - COMPACT;
        const float hstep = (float)(COLS-x)/7.0;
+       event_t *event;
 
        /* Get start of week */
-       year_t  year  = YEAR;
-       month_t month = MONTH;
-       day_t   day   = DAY;
+       year_t  year  = SEL.year;
+       month_t month = SEL.month;
+       day_t   day   = SEL.day;
        int shift = day_of_week(year, month, day);
        add_days(&year, &month, &day, -shift);
 
+       /* Load cal data */
+       cal_load(year, month, day, 7);
+
        /* For today */
        int l = ROUND((shift+0)*hstep);
        int r = ROUND((shift+1)*hstep);
@@ -68,8 +72,8 @@ void week_draw(void)
        /* Print Header */
        int rev = COMPACT ? A_REVERSE | A_BOLD : 0;
        wattron(win, rev);
-       mvwprintw(win, 0, 0, "%-*s",  COLS, month_to_str(MONTH));
-       mvwprintw(win, 1, 0, "%-0*d", COLS, YEAR);
+       mvwprintw(win, 0, 0, "%-*s",  COLS, month_to_str(SEL.month));
+       mvwprintw(win, 1, 0, "%-0*d", COLS, SEL.year);
        wattroff(win, rev);
        mvwhline(win, 0, x+l, ' ', r-l-1);
        mvwhline(win, 1, x+l, ' ', r-l-1);
@@ -84,23 +88,47 @@ void week_draw(void)
        }
        wattroff(win, rev);
 
+       /* Print all day events */
+       int allday = 0;
+       event = EVENTS;
+       add_days(&year, &month, &day, -7);
+       for (int d = 0; d <  7; d++) {
+               int n = 0;
+               while (event && before(&event->start, year, month, day, 24, 0)) {
+                       if (!before(&event->end, year, month, day, 0, 1) &&
+                           get_mins(&event->start, &event->end) > 23*60) {
+                               int s = ROUND(d*hstep);
+                               int w = ROUND((d+1)*hstep) - 1 - s;
+                               event_line(win, event, y+n++, x+s, w, 0);
+                       }
+                       event = event->next;
+                       if (n > allday)
+                               allday = n;
+               }
+               add_days(&year,&month,&day,1);
+       }
+       if (allday && !COMPACT)
+               allday++;
+
        /* Resize body */
-       wshrink(times, y-!COMPACT);
-       wshrink(body,  y-!COMPACT);
+       wshrink(times, y+allday-!COMPACT);
+       wshrink(body,  y+allday-!COMPACT);
+
        /* Print times */
        mvwprintw(times, !COMPACT, 0, "%02d:%02d", ((line/4)-1)%12+1, (line*15)%60);
        for (int h = 0; h < 24; h++)
                mvwprintw(times, !COMPACT+h*4-line, 0, "%02d:%02d", (h-1)%12+1, 0);
 
        /* Print events */
-       event_t *event = EVENTS;
+       event = EVENTS;
        add_days(&year, &month, &day, -7);
        for (int d = 0; d <  7; d++, add_days(&year,&month,&day,1))
        for (int h = 0; h < 24; h++)
        for (int m = 0; m < 60; m+=15)
        while (event && before(&event->start,
                        year, month, day, h+(m+15)/60, (m+15)%60)) {
-               if (!before(&event->start, year, month, day, h, m)) {
+               if (!before(&event->start, year, month, day, h, m) &&
+                   get_mins(&event->start, &event->end) <= 23*60) {
                        int y = h*4 + m/15 - line + !COMPACT;
                        int x = ROUND(d*hstep) + 1;
                        int h = (get_mins(&event->start, &event->end)-1)/15+1;
@@ -113,10 +141,12 @@ void week_draw(void)
        /* Print header lines */
        if (!COMPACT)
                mvwhline(win, y-1, 0, ACS_HLINE, COLS);
+       if (!COMPACT && allday)
+               mvwhline(win, y-1+allday, 0, ACS_HLINE, COLS);
 
        /* Print day lines */
        for (int d = 0; d < 7; d++)
-               mvwvline(body, !COMPACT, ROUND(d*hstep), ACS_VLINE, LINES-y-2+COMPACT);
+               mvwvline(body, !COMPACT, ROUND(d*hstep), ACS_VLINE, LINES-y-2+COMPACT-allday);
        mvwvline_set(body, 0, l, WACS_T_VLINE, LINES-y-1+COMPACT);
        mvwvline_set(body, 0, r, WACS_T_VLINE, LINES-y-1+COMPACT);
        for (int h = (line+3)/4; h < 24; h++) {
@@ -142,7 +172,7 @@ int week_run(int key, mmask_t btn, int row, int col)
        }
        line = CLAMP(line, 0, 24*4);
        if (days)
-               add_days(&YEAR, &MONTH, &DAY, days);
+               add_days(&SEL.year, &SEL.month, &SEL.day, days);
        if (ref) {
                werase(win);
                week_draw();