aboutsummaryrefslogtreecommitdiff
path: root/vcalendar.scm
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@hornquist.se>2019-03-10 23:36:45 +0100
committerHugo Hörnquist <hugo@hornquist.se>2019-03-10 23:36:45 +0100
commit2cb76416fb78cd6d9a6ffeb7a1ca282cc6d2ffb1 (patch)
treefcc0007f33d996850404523b4ad714840e93a814 /vcalendar.scm
parentAdd with-replaced-attrs. (diff)
downloadcalp-2cb76416fb78cd6d9a6ffeb7a1ca282cc6d2ffb1.tar.gz
calp-2cb76416fb78cd6d9a6ffeb7a1ca282cc6d2ffb1.tar.xz
Update vcalendar to allow symbol keys.
Diffstat (limited to 'vcalendar.scm')
-rw-r--r--vcalendar.scm70
1 files changed, 47 insertions, 23 deletions
diff --git a/vcalendar.scm b/vcalendar.scm
index 2ce5a438..4e595c22 100644
--- a/vcalendar.scm
+++ b/vcalendar.scm
@@ -13,26 +13,6 @@
(mod! (attr ev "DTEND") parse-datetime)))
cal)
-(define-public (make-vcomponent path)
- (parse-dates!
- (if (string-ci=? ".ics" (string-take-right path 4))
- ;; == Single ICS file ==
- ;; Remove the abstract ROOT component,
- ;; returning the wanted VCALENDAR component
- (car (%vcomponent-children
- (%vcomponent-make path)))
- ;; == Assume vdir ==
- ;; Also removes the abstract ROOT component, but also
- ;; merges all VCALENDAR's children into the first
- ;; VCALENDAR, and return that VCALENDAR.
- ;;
- ;; TODO the other VCALENDAR components might not get thrown away,
- ;; this since I protect them from the GC in the C code.
- (reduce (lambda (cal accum)
- (for-each (cut %vcomponent-push-child! accum <>)
- (%vcomponent-children cal))
- accum)
- '() (%vcomponent-children (%vcomponent-make path))))))
(define-public (type-filter t lst)
(filter (lambda (e) (eqv? t (type e)))
@@ -45,8 +25,16 @@
childs)))
(export children)
-(define set-attr! %vcomponent-set-attribute!)
-(define get-attr %vcomponent-get-attribute)
+(define (set-attr! component attr value)
+ (%vcomponent-set-attribute!
+ component
+ (if (symbol? attr) (symbol->string attr) attr)
+ value))
+
+(define (get-attr component attr)
+ (%vcomponent-get-attribute
+ component
+ (if (symbol? attr) (symbol->string attr) attr)))
;; Enables symmetric get and set:
;; (set! (attr ev "KEY") 10)
@@ -55,7 +43,7 @@
(define-public type %vcomponent-type)
(define-public parent %vcomponent-parent)
(define-public push-child! %vcomponent-push-child!)
-(define-public attributes %vcomponent-attribute-list)
+(define-public (attributes component) (map string->symbol (%vcomponent-attribute-list component)))
(define-public copy-vcomponent %vcomponent-shallow-copy)
@@ -71,3 +59,39 @@
(define-public (extract field)
(cut get-attr <> field))
+
+(define-public (key=? k1 k2)
+ (eq?
+ (if (string? k1) (string->symbol k1) k1)
+ (if (string? k2) (string->symbol k2) k2)))
+
+(define-public (make-vcomponent path)
+ (parse-dates!
+ (if (string-ci=? ".ics" (string-take-right path 4))
+ ;; == Single ICS file ==
+ ;; Remove the abstract ROOT component,
+ ;; returning the wanted VCALENDAR component
+ (car (%vcomponent-children
+ (%vcomponent-make path)))
+ ;; == Assume vdir ==
+ ;; Also removes the abstract ROOT component, but also
+ ;; merges all VCALENDAR's children into the first
+ ;; VCALENDAR, and return that VCALENDAR.
+ ;;
+ ;; TODO the other VCALENDAR components might not get thrown away,
+ ;; this since I protect them from the GC in the C code.
+ (reduce (lambda (cal accum)
+ (for-each (lambda (component)
+ (case (type component)
+ ((VTIMEZONE)
+ (let ((zones (children cal 'VTIMEZONE)))
+ (unless (find (lambda (z)
+ (string=? (attr z "TZID")
+ (attr component "TZID")))
+ zones)
+ (%vcomponent-push-child! accum component))))
+ (else (%vcomponent-push-child! accum component))))
+ (%vcomponent-children cal))
+ accum)
+ '() (%vcomponent-children (%vcomponent-make path))))))
+