Browse Source

Export BBDB anniversaries to iCalendar.

When the variable `org-icalendar-include-bbdb-anniversaries' is set.
Carsten Dominik 16 years ago
parent
commit
b15e173215
3 changed files with 48 additions and 0 deletions
  1. 6 0
      lisp/ChangeLog
  2. 33 0
      lisp/org-bbdb.el
  3. 9 0
      lisp/org-icalendar.el

+ 6 - 0
lisp/ChangeLog

@@ -1,5 +1,11 @@
 2009-06-11  Carsten Dominik  <carsten.dominik@gmail.com>
 
+	* org-icalendar.el (org-icalendar-include-bbdb-anniversaries): New
+	option.
+	(org-export-icalendar): Call `org-bbdb-anniv-export-ical'.
+
+	* org-bbdb.el (org-bbdb-anniv-export-ical): New function.
+
 	* org-list.el (org-get-checkbox-statistics-face): Use the new
 	faces.
 

+ 33 - 0
lisp/org-bbdb.el

@@ -347,6 +347,39 @@ This is used by Org to re-create the anniversary hash table."
   (concat "bbdb:"
 	  (bbdb-record-name (car (bbdb-completing-read-record "Name: ")))))
 
+(defun org-bbdb-anniv-export-ical ()
+ "Extract anniversaries from BBDB and convert them to icalendar format."
+ (require 'bbdb)
+ (require 'diary-lib)
+ (unless (hash-table-p org-bbdb-anniv-hash)
+   (setq org-bbdb-anniv-hash
+	  (make-hash-table :test 'equal :size 366)))
+ (when (or org-bbdb-updated-p
+           (= 0 (hash-table-count org-bbdb-anniv-hash)))
+   (org-bbdb-make-anniv-hash))
+ 
+ (defun org-bbdb-format-vevent (key recs)
+   (while (setq rec (pop recs))
+     (princ (format "BEGIN:VEVENT
+UID: ANNIV-%4i%02i%02i-%s
+DTSTART:%4i%02i%02i
+SUMMARY:%s\n"
+                      (nth 0 rec)
+                      (nth 0 key)
+                      (nth 1 key)
+		      (mapconcat 'identity
+				 (org-split-string (nth 1 rec) "[^a-zA-Z0-90]+")
+				 "-")
+                      (nth 0 rec)
+                      (nth 0 key)
+                      (nth 1 key)
+                      (nth 1 rec)))
+     (if (setq categ (nth 2 rec))
+         (princ (format "CATEGORIES:%s\n" (upcase categ))))
+     (princ "RRULE:FREQ=YEARLY
+END:VEVENT\n")))
+ (maphash 'org-bbdb-format-vevent org-bbdb-anniv-hash))
+
 (provide 'org-bbdb)
 
 ;; arch-tag: 9e4f275d-d080-48c1-b040-62247f66b5c2

+ 9 - 0
lisp/org-icalendar.el

@@ -110,6 +110,12 @@ all         include both done and not done items."
 	  (const :tag "Unblocked" unblocked)
 	  (const :tag "All" all)))
 
+(defcustom org-icalendar-include-bbdb-anniversaries nil
+  "Non-nil means, a combined iCalendar files should include anniversaries.
+The anniversaries are define in the BBDB database."
+  :group 'org-export-icalendar
+  :type 'boolean)
+
 (defcustom org-icalendar-include-sexps t
   "Non-nil means, export to iCalendar files should also cover sexp entries.
 These are entries like in the diary, but directly in an Org-mode file."
@@ -214,6 +220,9 @@ file and store it under the name `org-combined-agenda-icalendar-file'."
 	      (org-start-icalendar-file category))
 	    (org-print-icalendar-entries combine)
 	    (when (or (and combine (not files)) (not combine))
+	      (when (and combine org-icalendar-include-bbdb-anniversaries)
+		(require 'org-bbdb)
+		(org-bbdb-anniv-export-ical))
 	      (org-finish-icalendar-file)
 	      (set-buffer ical-buffer)
 	      (run-hooks 'org-before-save-iCalendar-file-hook)