commit 7d2ac9894ac70904c0903324f4670ea393ce0b6c
parent 181d84832f9dff30c5634ff248a0ea2c1466d5fb
Author: William Casarin <bill@casarin.me>
Date: Mon, 16 Jan 2017 14:04:35 -0800
initial ical support
Diffstat:
3 files changed, 67 insertions(+), 3 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,5 +1,9 @@
-all: calendar
+BIN ?= calendar
+
+all: $(BIN)
+
+DEPS=libical gtk+-3.0
CFLAGS=-Wall \
-Wextra \
@@ -7,7 +11,15 @@ CFLAGS=-Wall \
-Werror=int-conversion \
-std=c99 \
-g \
- `pkg-config --cflags --libs gtk+-3.0`
+ `pkg-config --cflags --libs $(DEPS)`
-calendar: calendar.c Makefile
+$(BIN): $(BIN).c Makefile
$(CC) $(CFLAGS) -o $@ $<
+
+TAGS:
+ ./scripts/mktags $(DEPS) > $@
+
+clean:
+ rm -f $(BIN)
+
+.PHONY: TAGS clean
diff --git a/calendar.c b/calendar.c
@@ -1,8 +1,10 @@
#include <cairo/cairo.h>
#include <gtk/gtk.h>
+#include <libical/ical.h>
#include <time.h>
#include <string.h>
+#include <stdlib.h>
#include <math.h>
#include <locale.h>
@@ -82,6 +84,7 @@ const double dashed[] = {1.0};
static struct event* events_hit (struct event *, int, double, double);
static int event_hit (struct event *, double, double);
+static icalcomponent* calendar_load_ical(struct cal *cal, char *path);
static void calendar_print_state(struct cal *cal);
static void format_margin_time (char *, int, int);
static void format_locale_time(char *buffer, int bsize, struct tm *tm);
@@ -120,6 +123,40 @@ event_create(struct event *ev) {
return ev;
}
+static char *
+file_load(char *path) {
+ FILE *f = fopen(path, "rb");
+ fseek(f, 0, SEEK_END);
+ long fsize = ftell(f);
+ fseek(f, 0, SEEK_SET);
+
+ char *string = malloc(fsize);
+ fread(string, fsize, 1, f);
+ fclose(f);
+ return string;
+}
+
+static icalcomponent *
+calendar_load_ical(struct cal *cal, char *path) {
+ icalcomponent *prop;
+ icalcomponent_kind kind = ICAL_VEVENT_COMPONENT;
+ // TODO: free icalcomponent somewhere
+ const char *str = file_load(path);
+ icalcomponent *component = icalparser_parse_string(str);
+ if (!component) return NULL;
+ printf("got here\n");
+ icalcomponent *i = icalcomponent_get_first_component(component, kind);
+
+ for(i = icalcomponent_get_first_component(component, kind); i;
+ i = icalcomponent_get_next_component(component, kind))
+ {
+ printf("%s\n", icalcomponent_get_summary(i));
+ }
+
+ free((void*)str);
+ return component;
+}
+
static void
calendar_drop(struct cal *cal, double mx, double my) {
struct event *ev = cal->target;
@@ -540,6 +577,8 @@ int main(int argc, char *argv[])
.minute_round = 30
};
+ calendar_load_ical(&cal, "/home/jb55/Downloads/mycalendar.ics");
+
g_text_color.r = text_col;
g_text_color.g = text_col;
g_text_color.b = text_col;
diff --git a/scripts/mktags b/scripts/mktags
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+DEPS="$@"
+DIRS="$(pkg-config --cflags-only-I $DEPS | sed 's/\ \?-I/ /g')"
+FILES=""
+
+for dir in $(tr ' ' '\n' <<< "$DIRS"); do
+ FILES+=$(find "$dir" -type f -name '*.h')
+done
+
+<<<"$FILES" xargs etags --declarations -o -