aboutsummaryrefslogtreecommitdiff
path: root/module/vcomponent.scm
diff options
context:
space:
mode:
Diffstat (limited to 'module/vcomponent.scm')
-rw-r--r--module/vcomponent.scm172
1 files changed, 85 insertions, 87 deletions
diff --git a/module/vcomponent.scm b/module/vcomponent.scm
index cc79b646..871ac2e7 100644
--- a/module/vcomponent.scm
+++ b/module/vcomponent.scm
@@ -1,17 +1,17 @@
(define-module (vcomponent)
- #:use-module ((vcomponent primitive) :select (%vcomponent-make))
#:use-module (vcomponent datetime)
#:use-module (vcomponent recurrence)
#:use-module (vcomponent timezone)
#:use-module (vcomponent base)
+ #:use-module (vcomponent parse)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-19)
#:use-module (srfi srfi-19 util)
#:use-module (srfi srfi-19 setters)
#:use-module (srfi srfi-26)
#:use-module (util)
- #:export (make-vcomponent)
- #:re-export (repeating?))
+ #:export (parse-calendar)
+ #:re-export (repeating? make-vcomponent))
;; All VTIMEZONE's seem to be in "local" time in relation to
;; themselves. Therefore, a simple comparison should work,
@@ -26,29 +26,29 @@
(define (parse-dates! cal)
"Parse all start times into scheme date objects."
- (for tz in (children cal 'VTIMEZONE)
+ (for tz in (filter (lambda (o) (eq? 'VTIMEZONE (type o))) (children cal))
(for-each (lambda (p) (mod! (attr p "DTSTART") string->time-utc))
(children tz))
;; TZSET is the generated recurrence set of a timezone
(set! (attr tz 'X-HNH-TZSET)
- (make-tz-set tz)
- #;
- ((@ (srfi srfi-41) stream)
- (list
- (car (children tz))
- (cadr (children tz))))
- ))
-
- (for ev in (children cal 'VEVENT)
+ (make-tz-set tz)))
+
+ (for ev in (filter (lambda (o) (eq? 'VEVENT (type o))) (children cal))
(define dptr (attr* ev 'DTSTART))
(define eptr (attr* ev 'DTEND))
- (define date (parse-datetime (value dptr)))
+ (define date (parse-datetime (value dptr)))
(define end-date
- (if (value eptr)
- (parse-datetime (value eptr))
- (set (date-hour date) = (+ 1))))
+ (cond ;; [(attr ev 'DURATION) => (lambda (d) (add-duration ...))]
+ [(not eptr)
+ (let ((d (set (date-hour date) = (+ 1))))
+ (set! (attr ev 'DTEND) d
+ eptr (attr* ev 'DTEND))
+ d)]
+ [(value eptr) => parse-datetime]
+ [else
+ (set (date-hour date) = (+ 1))]))
(set! (value dptr) (date->time-utc date)
(value eptr) (date->time-utc end-date))
@@ -63,78 +63,76 @@
(value eptr) (date->time-utc end-date)))))
-;; (define-public value caar)
-;; (define-public next cdr)
-;; (define-public next! pop!)
-
-
-;; (define-public (reset! attr-list)
-;; (while (not (car attr-list))
-;; (next! attr-list))
-;; (next! attr-list))
-
-;; value
-;; (define-public v
-;; (make-procedure-with-setter car set-car!))
-
-
-
-(define* (make-vcomponent #:optional path)
- (if (not path)
- (%vcomponent-make)
- (let* ((root (%vcomponent-make path))
- (component
- (case (string->symbol (or (attr root "X-HNH-SOURCETYPE") "no-type"))
- ;; == Single ICS file ==
- ;; Remove the abstract ROOT component,
- ;; returning the wanted VCALENDAR component
- ((file)
- ;; TODO test this when an empty file is given.
- (car (children root)))
-
- ;; == Assume vdir ==
- ;; Also removes the abstract ROOT component, but also
- ;; merges all VCALENDAR's children into the a newly
- ;; created VCALENDAR component, and return that component.
- ;;
- ;; TODO the other VCALENDAR components might not get thrown away,
- ;; this since I protect them from the GC in the C code.
- ((vdir)
- (let ((accum (make-vcomponent))
- (ch (children root)))
- (set! (type accum) "VCALENDAR")
-
- (unless (null? ch)
- (for key in (attributes (car ch))
- (set! (attr accum key) (attr (car ch) key))))
-
+(define* (parse-calendar path)
+ (let ((root (parse-cal-path path)))
+ (let* ((component
+ (case (string->symbol (or (attr root "X-HNH-SOURCETYPE") "no-type"))
+ ;; == Single ICS file ==
+ ;; Remove the abstract ROOT component,
+ ;; returning the wanted VCALENDAR component
+ ((file)
+ ;; TODO test this when an empty file is given.
+ (car (children root)))
+
+ ;; == Assume vdir ==
+ ;; Also removes the abstract ROOT component, but also
+ ;; merges all VCALENDAR's children into the a newly
+ ;; created VCALENDAR component, and return that component.
+ ;;
+ ;; TODO the other VCALENDAR components might not get thrown away,
+ ;; this since I protect them from the GC in the C code.
+ ((vdir)
+ (let ((accum (make-vcomponent 'VCALENDAR))
+ (ch (children root)))
+
+ ;; Copy attributes from our parsed VCALENDAR
+ ;; to our newly created one.
+ (unless (null? ch)
+ (for key in (attributes (car ch))
+ (set! (attr accum key) (attr (car ch) key))))
+
+ ;; Merge all children
+ (let ((tz '()))
(for cal in ch
(for component in (children cal)
(case (type component)
((VTIMEZONE)
+ (set! tz (cons component tz))
+ #;
(unless (find (lambda (z)
- (string=? (attr z "TZID")
- (attr component "TZID")))
- (children accum 'VTIMEZONE))
- (push-child! accum component)))
- (else (push-child! accum component)))))
- ;; return
- accum))
-
- ((no-type) (throw 'no-type))
-
- (else (throw 'something)))))
-
- (parse-dates! component)
-
- (unless (attr component "NAME")
- (set! (attr component "NAME")
- (or (attr component "X-WR-CALNAME")
- (attr root "NAME"))))
-
- (unless (attr component "COLOR")
- (set! (attr component "COLOR")
- (attr root "COLOR")))
-
- ;; return
- component)))
+ (string=? (attr z "TZID")
+ (attr component "TZID")))
+ (filter (lambda (o) (eq? 'VTIMEZONE (type o)))
+ (children accum)))
+ (add-child! accum component)))
+ ((VEVENT)
+ (add-child! accum component)
+ )
+ (else => (lambda (type)
+ (format (current-error-port)
+ "Got unexpected component of type ~a~%" type))
+ #; (add-child! accum component)
+ ))))
+
+ (unless (null? tz)
+ (add-child! accum (car tz)))
+ )
+ ;; return
+ accum))
+
+ ((no-type) (error 'no-type)))))
+
+ (parse-dates! component)
+
+ (unless (attr component "NAME")
+ (set! (attr component "NAME")
+ (or (attr component "X-WR-CALNAME")
+ (attr root "NAME")
+ "[NAMELESS]")))
+
+ (unless (attr component "COLOR")
+ (set! (attr component "COLOR")
+ (attr root "COLOR")))
+
+ ;; return
+ component)))