#include <libical/ical.h>
#include "util.h"
+#include "conf.h"
#include "date.h"
#include "cal.h"
} ical_t;
/* Static data */
-static ical_t calendars[] = {
- { .location = "data/all.ics" },
-};
+static ical_t *calendars;
/* Helper functions */
static int ical_compare(const void *_a, const void *_b)
cur->name ?: cur->desc ?: "[no summary]");
}
+/* Config parser */
+void ical_config(const char *group, const char *name, const char *key, const char *value)
+{
+ ical_t *cal = NULL, *last = NULL;
+
+ /* Make sure it's valid */
+ if (!match(group, "ical") || !name)
+ return;
+
+ /* Find existing calendar */
+ for (cal = calendars; cal; last = cal, cal = cal->next)
+ if (match(cal->name, name))
+ break;
+
+ /* Create new calendar */
+ if (!cal) {
+ cal = new0(ical_t);
+ cal->name = get_name(name);
+ if (last)
+ last->next = cal;
+ else
+ calendars = cal;
+ return;
+ }
+
+ /* Set calendar values */
+ if (match(key, "location"))
+ cal->location = get_string(value);
+ else if (match(key, "username"))
+ cal->username = get_string(value);
+ else if (match(key, "password"))
+ cal->password = get_string(value);
+}
+
/* Event functions */
event_t *ical_events(date_t _start, date_t _end)
{