]> Pileus Git - lackey/commitdiff
Add events view
authorAndy Spencer <andy753421@gmail.com>
Mon, 15 Oct 2012 09:03:05 +0000 (09:03 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 15 Oct 2012 09:03:05 +0000 (09:03 +0000)
makefile
src/screen.c
src/screen.h
view/events.c [new file with mode: 0644]
view/help.c
view/month.c
view/notes.c [deleted file]
view/settings.c
view/todo.c

index 0f58f12ce39f0cc8d66a9fa34a9a3eea10cfd2c3..e3f36381118b90abac4990c83480b1d2456c5e66 100644 (file)
--- 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
index 658b9e74d65db1b869dc877ccaf2abebd686278b..c555e324fdc0c803242641aeef35f64a539a5159 100644 (file)
@@ -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 (l<h && event->desc) 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);
+       }
 }
 
 
index cf83b6e68dabcef7f8dd97c91fc1ed856b0cdcef..9f9d4e9892ea3869842bbd91ec3a54e78c65ed26 100644 (file)
@@ -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 (file)
index 0000000..8b888cd
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2012 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
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#define DEBUG
+
+#include <ncurses.h>
+
+#include <util.h>
+#include <date.h>
+#include <event.h>
+#include <screen.h>
+
+/* 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;
+}
index 12a0e8fb406ca651b94ed24c07c7445d8e8fa12e..c98df24fbb277ed2df9d872309452870e3775419 100644 (file)
@@ -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 */
index 2179f4f2c178f9e611d6a696375eb7311eb70ea5..fb1ec8c46cbf3fe87d3ebba87110c9c53c8d5984 100644 (file)
@@ -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 (file)
index 3414ff3..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2012 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
- * 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 <http://www.gnu.org/licenses/>.
- */
-
-#include <ncurses.h>
-
-/* 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;
-}
index 4015876dd3a9d3b7cc0c2f6595cfb7088e42c56f..29aa2c7d34069b3e4e821cc733ed1488abd3991a 100644 (file)
@@ -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 */
index e2658c6995dad724a5eaece6c08624cdd08bcba4..e6027f9dedf0c2c4d5f627d520b97cf7b09d6257 100644 (file)
@@ -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 */