--- /dev/null
+/*
+ * 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 <stdlib.h>
+
+#include "main.h"
+#include "event.h"
+
+/* Test data */
+static cal_t cal = {
+ .name = "dummy",
+ .desc = "dummy calendar",
+ .data = NULL,
+};
+
+static event_t event = {
+ .cal = &cal,
+ .start = {2012, OCT, 0, 12, 0},
+ .end = {2012, OCT, 0, 13, 0},
+ .name = "dummy event",
+ .desc = "this event is random and does not exist",
+ .next = NULL,
+};
+
+static event_t events[8];
+
+/* Event functions */
+event_t *dummy_get(cal_t *cal, year_t year, month_t month, day_t day, int days)
+{
+ for (int i = 0; i < N_ELEMENTS(events); i++) {
+ datetime_t *s = &events[i].start;
+ datetime_t *e = &events[i].end;
+ events[i] = event;
+ add_days(&s->year, &s->month, &s->day, 7*i);
+ add_days(&e->year, &e->month, &e->day, 7*i);
+ if (i+1 < N_ELEMENTS(events))
+ events[i].next = &events[i+1];
+ }
+ return &events[0];
+}
# Sources
PROG = lackey
TEST = test
-SOURCES = main screen util
+SOURCES = main screen event util
TESTS = test util
VIEWS = day week month year todo notes settings help
+CALS = dummy
# Targets
all: $(PROG) $(TEST)
rm -f src/*.o view/*.o $(PROG) $(TEST)
# Rules
-$(PROG): $(SOURCES:%=src/%.o) $(VIEWS:%=view/%.o)
+$(PROG): $(SOURCES:%=src/%.o) $(VIEWS:%=view/%.o) $(CALS:%=cal/%.o)
$(CC) $(CFLAGS) -o $@ $+ $(LDFLAGS)
-$(TEST): $(TESTS:%=src/%.o) $(VIEWS:%=view/%.o)
+$(TEST): $(TESTS:%=src/%.o) $(VIEWS:%=view/%.o) $(CALS:%=cal/%.o)
$(CC) $(CFLAGS) -o $@ $+ $(LDFLAGS)
%.o: %.c $(SOURCES:%=src/%.h) makefile
--- /dev/null
+/*
+ * 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 "util.h"
+#include "event.h"
+
+/* Event get */
+event_t *event_get(year_t year, month_t month, day_t day, int days)
+{
+ return dummy_get(0, year, month, day, days);
+}
--- /dev/null
+/*
+ * 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/>.
+ */
+
+#ifndef EVENT_H
+#define EVENT_H
+
+#include "util.h"
+
+/* Calendar types */
+typedef struct {
+ char *name;
+ char *desc;
+ void *data;
+} cal_t;
+
+/* Event types */
+typedef struct {
+ year_t year;
+ month_t month;
+ day_t day;
+ hour_t hour;
+ min_t min;
+} datetime_t;
+
+typedef struct event_t {
+ const cal_t *cal;
+ datetime_t start;
+ datetime_t end;
+ const char *name;
+ const char *desc;
+ struct event_t *next;
+} event_t;
+
+/* Event functions */
+event_t *event_get(year_t year, month_t month, day_t day, int days);
+
+/* Calendar implementation functions */
+event_t *dummy_get(cal_t *cal, year_t year, month_t month, day_t day, int days);
+
+#endif
#include "screen.h"
/* Debugging */
-year_t YEAR = 2012;
-month_t MONTH = 8;
-day_t DAY = 29;
+year_t YEAR = 2012;
+month_t MONTH = 8;
+day_t DAY = 29;
+
+event_t *EVENTS = NULL;
/* Static data */
static FILE *debug_fd = NULL;
/* Time setup */
time_t sec = time(NULL);
struct tm *tm = localtime(&sec);
- YEAR = tm->tm_year+1900;
- MONTH = tm->tm_mon;
- DAY = tm->tm_mday-1;
+ YEAR = tm->tm_year+1900;
+ MONTH = tm->tm_mon;
+ DAY = tm->tm_mday-1;
+
+ EVENTS = event_get(2012, JAN, 0, 366);
/* Curses setup */
setlocale(LC_ALL, "");
screen_init();
screen_draw();
+ /* Debug */
+ for (event_t *e = EVENTS; e; e = e->next)
+ debug("event: %04d-%02d-%02d %02d:%02d: %s - %s\n",
+ e->start.year, e->start.month, e->start.day,
+ e->start.hour, e->start.min, e->name, e->desc);
+
/* Run */
while (1) {
MEVENT btn;
#define COLOR_ERROR 2
#include "util.h"
+#include "event.h"
/* Debugging */
-extern year_t YEAR;
-extern month_t MONTH;
-extern day_t DAY;
+extern year_t YEAR;
+extern month_t MONTH;
+extern day_t DAY;
+
+extern event_t *EVENTS;
/* Debug functions */
int debug(char *fmt, ...);
{ "Help", help_init, help_draw, help_run, {KEY_F(8), '8', '?'} },
};
-int active = 0;
+int active = 1;
/* Local functions */
void draw_header(void)
/* Time types */
typedef int year_t;
typedef int day_t;
+typedef int hour_t;
+typedef int min_t;
typedef enum {
JAN = 0,
/* Static data */
static WINDOW *win;
+/* Local functions */
+static void print_event(event_t *event, wday_t day, hour_t hour, min_t min, float hstep)
+{
+ int x = 6+ROUND(day*hstep);
+ int y = 3+hour*4;
+ int l = (event->end.min - event->start.min)/15;
+ mvwprintw(win, y, x, "%s", event->name);
+ debug("event: %s\n", event->name);
+}
+
+static int before(datetime_t *start, int year, int month, int day, int hour, int min)
+{
+ int rval = start->year < year ? 1 : start->year > year ? 0 :
+ start->month < month ? 1 : start->month > month? 0 :
+ start->day < day ? 1 : start->day > day ? 0 :
+ start->hour < hour ? 1 : start->hour > hour ? 0 :
+ start->min < min ? 1 : start->min > min ? 0 : 0;
+ debug("%04d-%02d-%02d %02d:%02d < %04d-%02d-%02d %02d:%02d == %d\n",
+ start->year, start->month, start->day, start->hour, start->min,
+ year, month, day, hour, min, rval);
+ return rval;
+}
+
/* Week init */
void week_init(WINDOW *_win)
{
}
/* Print times */
- int start = 8;
+ hour_t start = 8;
for (int h = 0; h < (LINES-6)/4+1; h++)
mvwprintw(win, 3+h*4, 0,"%02d:%02d", (start+h)%12, 0);
for (int d = 0; d < 7; d++)
mvwvline(win, y, x+ROUND(d*hstep)-1, ACS_VLINE, LINES-y-2);
+ /* Print events */
+ event_t *event = EVENTS;
+ add_days(&year, &month, &day, -7);
+ for (int d = 0; d < 7; d++) {
+ for (int h = 0; h < (LINES-6)/4+1; h++) {
+ for (int m = 0; m < 60; m+=15) {
+ while (event && before(&event->start, year, month, day, start+h+(m+15)/60, (m+15)%60)) {
+ if (!before(&event->start, year, month, day, start+h, m))
+ print_event(event, d, h, m, hstep);
+ event = event->next;
+ }
+ }
+ }
+ add_days(&year, &month, &day, 1);
+ }
+
/* Draw today */
int l = x+ROUND((shift+0)*hstep)-1;
int r = x+ROUND((shift+1)*hstep)-1;
/* Year run */
int year_run(int key, mmask_t btn, int row, int col)
{
- int d = DAY, m = MONTH, y = YEAR;
+ day_t d = DAY;
+ month_t m = MONTH;
+ year_t y = YEAR;
wday_t day = day_of_week(YEAR, MONTH, DAY);
int week = (start_of_month(y, m) + d) / 7;
int dir = 0;