diff options
| -rw-r--r-- | lisp/ChangeLog | 9 | ||||
| -rw-r--r-- | lisp/calendar/icalendar.el | 66 | ||||
| -rw-r--r-- | test/ChangeLog | 8 | ||||
| -rw-r--r-- | test/automated/icalendar-tests.el | 100 |
4 files changed, 178 insertions, 5 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index c30a2dd9b4d..b232210f3c7 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2014-11-17 Ulf Jasper <ulf.jasper@web.de> | ||
| 2 | |||
| 3 | * calendar/icalendar.el (icalendar-export-alarms): New | ||
| 4 | customizable variable. | ||
| 5 | (icalendar-export-region): Export alarms as specified in | ||
| 6 | `icalendar-export-alarms'. | ||
| 7 | (icalendar--create-ical-alarm, icalendar--do-create-ical-alarm): | ||
| 8 | New functions for exporting alarms. | ||
| 9 | |||
| 1 | 2014-11-17 Paul Eggert <eggert@cs.ucla.edu> | 10 | 2014-11-17 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 11 | ||
| 3 | Port new time stamp handling to old Emacs and to XEmacs. | 12 | Port new time stamp handling to old Emacs and to XEmacs. |
diff --git a/lisp/calendar/icalendar.el b/lisp/calendar/icalendar.el index 9dba6ff2dcf..0bd126d9520 100644 --- a/lisp/calendar/icalendar.el +++ b/lisp/calendar/icalendar.el | |||
| @@ -267,6 +267,28 @@ other sexp entries are enumerated in any case." | |||
| 267 | :type 'boolean | 267 | :type 'boolean |
| 268 | :group 'icalendar) | 268 | :group 'icalendar) |
| 269 | 269 | ||
| 270 | |||
| 271 | (defcustom icalendar-export-alarms | ||
| 272 | nil | ||
| 273 | "Determine if and how alarms are included in exported diary events." | ||
| 274 | :version "25.1" | ||
| 275 | :type '(choice (const :tag "Do not include alarms in export" | ||
| 276 | nil) | ||
| 277 | (list :tag "Create alarms in exported diary entries" | ||
| 278 | (integer :tag "Advance time (minutes)" | ||
| 279 | :value 10) | ||
| 280 | (set :tag "Alarm type" | ||
| 281 | (list :tag "Audio" | ||
| 282 | (const audio :tag "Audio")) | ||
| 283 | (list :tag "Display" | ||
| 284 | (const display :tag "Display")) | ||
| 285 | (list :tag "Email" | ||
| 286 | (const email) | ||
| 287 | (repeat :tag "Attendees" | ||
| 288 | (string :tag "Email")))))) | ||
| 289 | :group 'icalendar) | ||
| 290 | |||
| 291 | |||
| 270 | (defvar icalendar-debug nil | 292 | (defvar icalendar-debug nil |
| 271 | "Enable icalendar debug messages.") | 293 | "Enable icalendar debug messages.") |
| 272 | 294 | ||
| @@ -1026,6 +1048,7 @@ FExport diary data into iCalendar file: ") | |||
| 1026 | (header "") | 1048 | (header "") |
| 1027 | (contents-n-summary) | 1049 | (contents-n-summary) |
| 1028 | (contents) | 1050 | (contents) |
| 1051 | (alarm) | ||
| 1029 | (found-error nil) | 1052 | (found-error nil) |
| 1030 | (nonmarker (concat "^" (regexp-quote diary-nonmarking-symbol) | 1053 | (nonmarker (concat "^" (regexp-quote diary-nonmarking-symbol) |
| 1031 | "?")) | 1054 | "?")) |
| @@ -1088,8 +1111,10 @@ FExport diary data into iCalendar file: ") | |||
| 1088 | (setq header (concat "\nBEGIN:VEVENT\nUID:" | 1111 | (setq header (concat "\nBEGIN:VEVENT\nUID:" |
| 1089 | (or uid | 1112 | (or uid |
| 1090 | (icalendar--create-uid | 1113 | (icalendar--create-uid |
| 1091 | entry-full contents))))) | 1114 | entry-full contents)))) |
| 1092 | (setq result (concat result header contents | 1115 | (setq alarm (icalendar--create-ical-alarm |
| 1116 | (cdr contents-n-summary)))) | ||
| 1117 | (setq result (concat result header contents alarm | ||
| 1093 | "\nEND:VEVENT"))) | 1118 | "\nEND:VEVENT"))) |
| 1094 | (if (consp cns-cons-or-list) | 1119 | (if (consp cns-cons-or-list) |
| 1095 | (list cns-cons-or-list) | 1120 | (list cns-cons-or-list) |
| @@ -1264,6 +1289,43 @@ Returns an alist." | |||
| 1264 | (if url (cons 'url url) nil) | 1289 | (if url (cons 'url url) nil) |
| 1265 | (if uid (cons 'uid uid) nil)))))))) | 1290 | (if uid (cons 'uid uid) nil)))))))) |
| 1266 | 1291 | ||
| 1292 | (defun icalendar--create-ical-alarm (summary) | ||
| 1293 | "Return VALARM blocks for the given SUMMARY." | ||
| 1294 | (when icalendar-export-alarms | ||
| 1295 | (let* ((advance-time (car icalendar-export-alarms)) | ||
| 1296 | (alarm-specs (cadr icalendar-export-alarms)) | ||
| 1297 | (fun (lambda (spec) | ||
| 1298 | (icalendar--do-create-ical-alarm advance-time spec summary)))) | ||
| 1299 | (mapconcat fun alarm-specs "")))) | ||
| 1300 | |||
| 1301 | (defun icalendar--do-create-ical-alarm (advance-time alarm-spec summary) | ||
| 1302 | "Return a VALARM block. | ||
| 1303 | Argument ADVANCE-TIME is a number giving the time when the alarm | ||
| 1304 | fires (minutes before the respective event). Argument ALARM-SPEC | ||
| 1305 | is a list which must be one of '(audio), '(display) or | ||
| 1306 | '(email (ADDRESS1 ...)), see `icalendar-export-alarms'. Argument | ||
| 1307 | SUMMARY is a string which contains a short description for the | ||
| 1308 | alarm." | ||
| 1309 | (let* ((action (car alarm-spec)) | ||
| 1310 | (act (format "\nACTION:%s" | ||
| 1311 | (cdr (assoc action '((audio . "AUDIO") | ||
| 1312 | (display . "DISPLAY") | ||
| 1313 | (email . "EMAIL")))))) | ||
| 1314 | (tri (format "\nTRIGGER:-PT%dM" advance-time)) | ||
| 1315 | (des (if (memq action '(display email)) | ||
| 1316 | (format "\nDESCRIPTION:%s" summary) | ||
| 1317 | "")) | ||
| 1318 | (sum (if (eq action 'email) | ||
| 1319 | (format "\nSUMMARY:%s" summary) | ||
| 1320 | "")) | ||
| 1321 | (att (if (eq action 'email) | ||
| 1322 | (mapconcat (lambda (i) | ||
| 1323 | (format "\nATTENDEE:MAILTO:%s" i)) | ||
| 1324 | (cadr alarm-spec) "") | ||
| 1325 | ""))) | ||
| 1326 | |||
| 1327 | (concat "\nBEGIN:VALARM" act tri des sum att "\nEND:VALARM"))) | ||
| 1328 | |||
| 1267 | ;; subroutines for icalendar-export-region | 1329 | ;; subroutines for icalendar-export-region |
| 1268 | (defun icalendar--convert-ordinary-to-ical (nonmarker entry-main) | 1330 | (defun icalendar--convert-ordinary-to-ical (nonmarker entry-main) |
| 1269 | "Convert \"ordinary\" diary entry to iCalendar format. | 1331 | "Convert \"ordinary\" diary entry to iCalendar format. |
diff --git a/test/ChangeLog b/test/ChangeLog index 47bbfb36a10..6e350cf8ec1 100644 --- a/test/ChangeLog +++ b/test/ChangeLog | |||
| @@ -1,5 +1,13 @@ | |||
| 1 | 2014-11-17 Ulf Jasper <ulf.jasper@web.de> | 1 | 2014-11-17 Ulf Jasper <ulf.jasper@web.de> |
| 2 | 2 | ||
| 3 | * automated/icalendar-tests.el (icalendar-tests--test-export): New | ||
| 4 | optional parameter `alarms'. | ||
| 5 | (icalendar-export-alarms): New test for exporting icalendar | ||
| 6 | alarms. | ||
| 7 | (icalendar-tests--test-cycle): Let `icalendar-export-alarms' be nil. | ||
| 8 | |||
| 9 | 2014-11-17 Ulf Jasper <ulf.jasper@web.de> | ||
| 10 | |||
| 3 | * automated/icalendar-tests.el (icalendar-tests--test-import): | 11 | * automated/icalendar-tests.el (icalendar-tests--test-import): |
| 4 | Mention timezone in doc string. Clean up. | 12 | Mention timezone in doc string. Clean up. |
| 5 | (icalendar-real-world): Add another test case for no-dst | 13 | (icalendar-real-world): Add another test case for no-dst |
diff --git a/test/automated/icalendar-tests.el b/test/automated/icalendar-tests.el index b45806e9777..54546722c8c 100644 --- a/test/automated/icalendar-tests.el +++ b/test/automated/icalendar-tests.el | |||
| @@ -508,18 +508,20 @@ END:VEVENT | |||
| 508 | ;; ====================================================================== | 508 | ;; ====================================================================== |
| 509 | 509 | ||
| 510 | (defun icalendar-tests--test-export (input-iso input-european input-american | 510 | (defun icalendar-tests--test-export (input-iso input-european input-american |
| 511 | expected-output) | 511 | expected-output &optional alarms) |
| 512 | "Perform an export test. | 512 | "Perform an export test. |
| 513 | Argument INPUT-ISO iso style diary string. | 513 | Argument INPUT-ISO iso style diary string. |
| 514 | Argument INPUT-EUROPEAN european style diary string. | 514 | Argument INPUT-EUROPEAN european style diary string. |
| 515 | Argument INPUT-AMERICAN american style diary string. | 515 | Argument INPUT-AMERICAN american style diary string. |
| 516 | Argument EXPECTED-OUTPUT expected iCalendar result string. | 516 | Argument EXPECTED-OUTPUT expected iCalendar result string. |
| 517 | Optional argument ALARMS the value of `icalendar-export-alarms' for this test. | ||
| 517 | 518 | ||
| 518 | European style input data must use german month names. American | 519 | European style input data must use german month names. American |
| 519 | and ISO style input data must use english month names." | 520 | and ISO style input data must use english month names." |
| 520 | (let ((tz (getenv "TZ")) | 521 | (let ((tz (getenv "TZ")) |
| 521 | (calendar-date-style 'iso) | 522 | (calendar-date-style 'iso) |
| 522 | (icalendar-recurring-start-year 2000)) | 523 | (icalendar-recurring-start-year 2000) |
| 524 | (icalendar-export-alarms alarms)) | ||
| 523 | (unwind-protect | 525 | (unwind-protect |
| 524 | (progn | 526 | (progn |
| 525 | ;;; (message "Current time zone: %s" (current-time-zone)) | 527 | ;;; (message "Current time zone: %s" (current-time-zone)) |
| @@ -753,6 +755,97 @@ RRULE:FREQ=DAILY;INTERVAL=1;UNTIL=20010706 | |||
| 753 | SUMMARY:block no end time | 755 | SUMMARY:block no end time |
| 754 | ")) | 756 | ")) |
| 755 | 757 | ||
| 758 | (ert-deftest icalendar-export-alarms () | ||
| 759 | "Perform export test with different settings for exporting alarms." | ||
| 760 | ;; no alarm | ||
| 761 | (icalendar-tests--test-export | ||
| 762 | "2014 Nov 17 19:30 no alarm" | ||
| 763 | "17 Nov 2014 19:30 no alarm" | ||
| 764 | "Nov 17 2014 19:30 no alarm" | ||
| 765 | "DTSTART;VALUE=DATE-TIME:20141117T193000 | ||
| 766 | DTEND;VALUE=DATE-TIME:20141117T203000 | ||
| 767 | SUMMARY:no alarm | ||
| 768 | " | ||
| 769 | nil) | ||
| 770 | |||
| 771 | ;; 10 minutes in advance, audio | ||
| 772 | (icalendar-tests--test-export | ||
| 773 | "2014 Nov 17 19:30 audio alarm" | ||
| 774 | "17 Nov 2014 19:30 audio alarm" | ||
| 775 | "Nov 17 2014 19:30 audio alarm" | ||
| 776 | "DTSTART;VALUE=DATE-TIME:20141117T193000 | ||
| 777 | DTEND;VALUE=DATE-TIME:20141117T203000 | ||
| 778 | SUMMARY:audio alarm | ||
| 779 | BEGIN:VALARM | ||
| 780 | ACTION:AUDIO | ||
| 781 | TRIGGER:-PT10M | ||
| 782 | END:VALARM | ||
| 783 | " | ||
| 784 | '(10 ((audio)))) | ||
| 785 | |||
| 786 | ;; 20 minutes in advance, display | ||
| 787 | (icalendar-tests--test-export | ||
| 788 | "2014 Nov 17 19:30 display alarm" | ||
| 789 | "17 Nov 2014 19:30 display alarm" | ||
| 790 | "Nov 17 2014 19:30 display alarm" | ||
| 791 | "DTSTART;VALUE=DATE-TIME:20141117T193000 | ||
| 792 | DTEND;VALUE=DATE-TIME:20141117T203000 | ||
| 793 | SUMMARY:display alarm | ||
| 794 | BEGIN:VALARM | ||
| 795 | ACTION:DISPLAY | ||
| 796 | TRIGGER:-PT20M | ||
| 797 | DESCRIPTION:display alarm | ||
| 798 | END:VALARM | ||
| 799 | " | ||
| 800 | '(20 ((display)))) | ||
| 801 | |||
| 802 | ;; 66 minutes in advance, email | ||
| 803 | (icalendar-tests--test-export | ||
| 804 | "2014 Nov 17 19:30 email alarm" | ||
| 805 | "17 Nov 2014 19:30 email alarm" | ||
| 806 | "Nov 17 2014 19:30 email alarm" | ||
| 807 | "DTSTART;VALUE=DATE-TIME:20141117T193000 | ||
| 808 | DTEND;VALUE=DATE-TIME:20141117T203000 | ||
| 809 | SUMMARY:email alarm | ||
| 810 | BEGIN:VALARM | ||
| 811 | ACTION:EMAIL | ||
| 812 | TRIGGER:-PT66M | ||
| 813 | DESCRIPTION:email alarm | ||
| 814 | SUMMARY:email alarm | ||
| 815 | ATTENDEE:MAILTO:att.one@email.com | ||
| 816 | ATTENDEE:MAILTO:att.two@email.com | ||
| 817 | END:VALARM | ||
| 818 | " | ||
| 819 | '(66 ((email ("att.one@email.com" "att.two@email.com"))))) | ||
| 820 | |||
| 821 | ;; 2 minutes in advance, all alarms | ||
| 822 | (icalendar-tests--test-export | ||
| 823 | "2014 Nov 17 19:30 all alarms" | ||
| 824 | "17 Nov 2014 19:30 all alarms" | ||
| 825 | "Nov 17 2014 19:30 all alarms" | ||
| 826 | "DTSTART;VALUE=DATE-TIME:20141117T193000 | ||
| 827 | DTEND;VALUE=DATE-TIME:20141117T203000 | ||
| 828 | SUMMARY:all alarms | ||
| 829 | BEGIN:VALARM | ||
| 830 | ACTION:EMAIL | ||
| 831 | TRIGGER:-PT2M | ||
| 832 | DESCRIPTION:all alarms | ||
| 833 | SUMMARY:all alarms | ||
| 834 | ATTENDEE:MAILTO:att.one@email.com | ||
| 835 | ATTENDEE:MAILTO:att.two@email.com | ||
| 836 | END:VALARM | ||
| 837 | BEGIN:VALARM | ||
| 838 | ACTION:AUDIO | ||
| 839 | TRIGGER:-PT2M | ||
| 840 | END:VALARM | ||
| 841 | BEGIN:VALARM | ||
| 842 | ACTION:DISPLAY | ||
| 843 | TRIGGER:-PT2M | ||
| 844 | DESCRIPTION:all alarms | ||
| 845 | END:VALARM | ||
| 846 | " | ||
| 847 | '(2 ((email ("att.one@email.com" "att.two@email.com")) (audio) (display))))) | ||
| 848 | |||
| 756 | ;; ====================================================================== | 849 | ;; ====================================================================== |
| 757 | ;; Import tests | 850 | ;; Import tests |
| 758 | ;; ====================================================================== | 851 | ;; ====================================================================== |
| @@ -1285,7 +1378,8 @@ Argument INPUT icalendar event string." | |||
| 1285 | (icalendar-import-format-status "\n Status: %s") | 1378 | (icalendar-import-format-status "\n Status: %s") |
| 1286 | (icalendar-import-format-url "\n URL: %s") | 1379 | (icalendar-import-format-url "\n URL: %s") |
| 1287 | (icalendar-import-format-class "\n Class: %s") | 1380 | (icalendar-import-format-class "\n Class: %s") |
| 1288 | (icalendar-import-format-class "\n UID: %s")) | 1381 | (icalendar-import-format-class "\n UID: %s") |
| 1382 | (icalendar-export-alarms nil)) | ||
| 1289 | (dolist (calendar-date-style '(iso european american)) | 1383 | (dolist (calendar-date-style '(iso european american)) |
| 1290 | (icalendar-tests--do-test-cycle))))) | 1384 | (icalendar-tests--do-test-cycle))))) |
| 1291 | 1385 | ||