/*
- * 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
#include <stdlib.h>
#include "util.h"
+#include "conf.h"
#include "date.h"
#include "cal.h"
/* Test data */
static cal_t cal = {
+ .type = "dummy",
.name = "dummy",
.desc = "dummy calendar",
- .data = NULL,
};
static event_t event = {
.status = 50,
};
-static event_t events[8];
-static todo_t todos[6];
+static int enable;
+
+/* Config parser */
+void dummy_config(const char *group, const char *name, const char *key, const char *value)
+{
+ if (match(group, "dummy") && match(key, "enable"))
+ enable = get_bool(value);
+}
+
+/* Cal functions */
+cal_t *dummy_cals(void)
+{
+ return &cal;
+}
/* Event functions */
-event_t *dummy_events(cal_t *cal, year_t year, month_t month, day_t day, int days)
+event_t *dummy_events(date_t start, date_t end)
{
- for (int i = 0; i < N_ELEMENTS(events); i++) {
- date_t *s = &events[i].start;
- date_t *e = &events[i].end;
- events[i] = event;
+ event_t *last = &event;
+ for (int i = 0; i < 8; i++) {
+ last->next = new0(event_t);
+ last->next->cal = event.cal;
+ last->next->start = event.start;
+ last->next->end = event.end;
+ last->next->name = strcopy(event.name);
+ last->next->desc = strcopy(event.desc);
+
+ date_t *s = &last->next->start;
+ date_t *e = &last->next->end;
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];
+
+ last = last->next;
+ last->next = NULL;
}
- return &events[0];
+ return enable ? event.next : 0;
}
/* Todo functions */
-todo_t *dummy_todos(cal_t *cal, year_t year, month_t month, day_t day, int days)
+todo_t *dummy_todos(date_t start, date_t end)
{
- for (int i = 0; i < N_ELEMENTS(todos); i++) {
- todos[i] = todo;
- todos[i].status = i*20;
- if (i+1 < N_ELEMENTS(todos))
- todos[i].next = &todos[i+1];
+ todo_t *last = &todo;
+ for (int i = 0; i < 6; i++) {
+ last->next = new0(event_t);
+ last->next->cal = todo.cal;
+ last->next->name = strcopy(todo.name);
+ last->next->desc = strcopy(todo.desc);
+ last->next->due = todo.due;
+ last->next->status = todo.status;
+ last = last->next;
+ last->next = NULL;
}
- return &todos[0];
+ return enable ? todo.next : 0;
}