diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-08-13 10:43:33 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-08-13 10:43:33 +0200 |
commit | a902eb51621521d45c648d6a4d06d70d981dfaeb (patch) | |
tree | afc31d4d17fa3939585ad30878b5b690d3b80db3 /module/vcomponent | |
parent | Add TODO's (diff) | |
parent | Comment about generalizing. (diff) | |
download | calp-a902eb51621521d45c648d6a4d06d70d981dfaeb.tar.gz calp-a902eb51621521d45c648d6a4d06d70d981dfaeb.tar.xz |
Merge branch 'calchooser' into master
Diffstat (limited to '')
-rw-r--r-- | module/vcomponent.scm | 4 | ||||
-rw-r--r-- | module/vcomponent/base.scm | 10 | ||||
-rw-r--r-- | module/vcomponent/instance/methods.scm | 19 | ||||
-rw-r--r-- | module/vcomponent/parse/xcal.scm | 31 |
4 files changed, 44 insertions, 20 deletions
diff --git a/module/vcomponent.scm b/module/vcomponent.scm index 66b72162..b4a30c83 100644 --- a/module/vcomponent.scm +++ b/module/vcomponent.scm @@ -17,3 +17,7 @@ [(string? v) ((@ (glob) glob) v)] [else #f]))) +(define-config default-calendar "" + description: "Default calendar to use for operations. Set to empty string to unset" + pre: (ensure string?)) + diff --git a/module/vcomponent/base.scm b/module/vcomponent/base.scm index 3e75e566..7b81fb05 100644 --- a/module/vcomponent/base.scm +++ b/module/vcomponent/base.scm @@ -148,7 +148,7 @@ (hash-map->list cons (get-component-properties component))) (define-public (property-keys component) - (map car (get-component-properties component))) + (hash-map->list (lambda (a _) a) (get-component-properties component))) (define (copy-vline vline) (make-vline (vline-key vline) @@ -169,6 +169,14 @@ (copy-vline value)))) (get-component-properties component))))) +;; updates target with all fields from source. +;; fields in target but not in source left unchanged. +;; parent and children unchanged +(define-public (vcomponent-update! target source) + (for key in (property-keys source) + (set! (prop* target key) + (prop* source key)))) + (define-public (extract field) (lambda (e) (prop e field))) diff --git a/module/vcomponent/instance/methods.scm b/module/vcomponent/instance/methods.scm index 4baf9409..ea3522f9 100644 --- a/module/vcomponent/instance/methods.scm +++ b/module/vcomponent/instance/methods.scm @@ -54,13 +54,18 @@ (slot-set! this 'calendars (load-calendars (slot-ref this 'calendar-files))) - (slot-set! this 'events - (concatenate - (map (lambda (cal) (remove - (extract 'X-HNH-REMOVED) - (filter (lambda (o) (eq? 'VEVENT (type o))) - (children cal)))) - (slot-ref this 'calendars)))) + + (let* ((groups + (group-by + type (concatenate + (map children (slot-ref this 'calendars))))) + (events (awhen (assoc-ref groups 'VEVENT) + (car it))) + (removed remaining (partition (extract 'X-HNH-REMOVED) events))) + + ;; TODO figure out what to do with removed events + + (slot-set! this 'events (append #|removed|# remaining))) (let* ((repeating regular (partition repeating? (slot-ref this 'events)))) (slot-set! this 'fixed-events (sort*! regular date/-time<? (extract 'DTSTART))) diff --git a/module/vcomponent/parse/xcal.scm b/module/vcomponent/parse/xcal.scm index 76bdb251..2c8b7fe8 100644 --- a/module/vcomponent/parse/xcal.scm +++ b/module/vcomponent/parse/xcal.scm @@ -22,6 +22,7 @@ [(boolean) (string=? "true" (car value))] + ;; TODO possibly trim whitespace on text fields [(cal-address uri text unknown) (car value)] [(date) (parse-iso-date (car value))] @@ -126,21 +127,27 @@ (let ((params (handle-parameters parameters)) (tag* (symbol-upcase tag))) (for (type value) in (zip type value) - (set! (prop* component tag*) - (make-vline tag* - (handle-tag - tag (handle-value type params value)) - params))))] + ;; ignore empty fields + ;; mostly for <text/> + (unless (null? value) + (set! (prop* component tag*) + (make-vline tag* + (handle-tag + tag (handle-value type params value)) + params)))))] [(tag (type value ...) ...) (for (type value) in (zip type value) - (let ((params (make-hash-table)) - (tag* (symbol-upcase tag))) - (set! (prop* component tag*) - (make-vline tag* - (handle-tag - tag (handle-value type params value)) - params))))]))) + ;; ignore empty fields + ;; mostly for <text/> + (unless (null? value) + (let ((params (make-hash-table)) + (tag* (symbol-upcase tag))) + (set! (prop* component tag*) + (make-vline tag* + (handle-tag + tag (handle-value type params value)) + params)))))]))) ;; children (awhen (assoc-ref sxcal 'components) |