aboutsummaryrefslogtreecommitdiff
path: root/module/vcomponent/base.scm
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@hornquist.se>2019-11-03 13:57:46 +0100
committerHugo Hörnquist <hugo@hornquist.se>2019-11-03 13:57:46 +0100
commitcecffe9ebdd0bb1efb628da320039fec9e6cba39 (patch)
treee0268ee169f4c12e1f2b3dbd7ec9976742ba9944 /module/vcomponent/base.scm
parentRemove make-vcomponent. (diff)
downloadcalp-cecffe9ebdd0bb1efb628da320039fec9e6cba39.tar.gz
calp-cecffe9ebdd0bb1efb628da320039fec9e6cba39.tar.xz
Move stuff between vcomponent/{base,parse}.
Diffstat (limited to 'module/vcomponent/base.scm')
-rw-r--r--module/vcomponent/base.scm89
1 files changed, 61 insertions, 28 deletions
diff --git a/module/vcomponent/base.scm b/module/vcomponent/base.scm
index 60a27f94..52bbe0c3 100644
--- a/module/vcomponent/base.scm
+++ b/module/vcomponent/base.scm
@@ -1,23 +1,66 @@
(define-module (vcomponent base)
:use-module (util)
:use-module (srfi srfi-1)
+ :use-module (srfi srfi-9)
:use-module (srfi srfi-17)
- :use-module (vcomponent parse)
:use-module (ice-9 hash-table)
:use-module ((ice-9 optargs) :select (define*-public))
- :re-export (add-child! make-vcomponent))
-
-(define-public (parse-cal-path path)
- (let ((parent (make-vcomponent)))
- (for-each (lambda (child) (add-child! parent child))
- (read-vcalendar path))
- (set-attribute!
- parent 'X-HNH-SOURCETYPE
- (if (null? (get-component-children parent))
- "vdir"
- (get-attribute-value (car (get-component-children parent))
- 'X-HNH-SOURCETYPE "vdir")))
- parent))
+ )
+
+
+
+;; The <vline> type is a bit to many times refered to as a attr ptr.
+(define-record-type <vline>
+ (make-vline% value parameters)
+ vline?
+ (value get-vline-value set-vline-value!)
+ (parameters get-vline-parameters))
+
+(define*-public (make-vline value #:optional ht)
+ (make-vline% value (or ht (make-hash-table))))
+
+(define-record-type <vcomponent>
+ (make-vcomponent% type children parent attributes)
+ vcomponent?
+ (type type)
+ (children children set-component-children!)
+ (parent get-component-parent set-component-parent!)
+ (attributes get-component-attributes))
+(export children type)
+
+;; TODO should this also update the parent
+(define-public parent
+ (make-procedure-with-setter
+ get-component-parent set-component-parent!))
+
+(define*-public (make-vcomponent #:optional (type 'VIRTUAL))
+ (make-vcomponent% type '() #f (make-hash-table)))
+
+(define-public (add-child! parent child)
+ (set-component-children! parent (cons child (children parent)))
+ (set-component-parent! child parent))
+
+(define* (get-attribute-value component key #:optional default)
+ (cond [(hashq-ref (get-component-attributes component)
+ key #f)
+ => get-vline-value]
+ [else default]))
+
+(define (get-attribute component key)
+ (hashq-ref (get-component-attributes component)
+ key))
+
+(define (set-attribute! component key value)
+ (let ((ht (get-component-attributes component)))
+ (cond [(hashq-ref ht key #f)
+ => (lambda (vline) (set-vline-value! vline value))]
+ [else (hashq-set! ht key (make-vline value))])))
+
+(define-public (set-vline! component key vline)
+ (hashq-set! (get-component-attributes component)
+ key vline))
+
+
;; vline → value
(define-public value
@@ -57,30 +100,20 @@
;; Returns the properties of attribute as an assoc list.
;; @code{(map car <>)} leads to available properties.
(define-public (properties attrptr)
- (hash-map->list cons (get-attribute-parameters attrptr)))
-
-(define-public type (make-procedure-with-setter
- (lambda (c) (component-type c))
- (lambda (c v) ; struct-set! c 0 v
- (format (current-error-port)
- "This method is a deprecated NOOP"))))
-
-(define-public parent get-component-parent)
+ (hash-map->list cons (get-vline-parameters attrptr)))
(define-public (attributes component)
(map car (hash-map->list cons (get-component-attributes component))))
-(define*-public children get-component-children)
-
(define (copy-vline vline)
(make-vline (get-vline-value vline)
;; TODO deep-copy on properties?
(get-vline-parameters vline)))
(define-public (copy-vcomponent component)
- (make-vcomponent% (component-type component)
- (get-component-children component)
- (get-component-parent component)
+ (make-vcomponent% (type component)
+ (children component)
+ (parent component)
;; attributes
(alist->hashq-table
(hash-map->list (lambda (key value) (cons key (copy-vline value)))