summaryrefslogtreecommitdiffstats
path: root/comm/calendar/import-export
diff options
context:
space:
mode:
Diffstat (limited to 'comm/calendar/import-export')
-rw-r--r--comm/calendar/import-export/CalHtmlExport.jsm116
-rw-r--r--comm/calendar/import-export/CalIcsImportExport.jsm55
-rw-r--r--comm/calendar/import-export/calHtmlExport.html71
-rw-r--r--comm/calendar/import-export/components.conf29
-rw-r--r--comm/calendar/import-export/jar.mn7
-rw-r--r--comm/calendar/import-export/moz.build18
6 files changed, 296 insertions, 0 deletions
diff --git a/comm/calendar/import-export/CalHtmlExport.jsm b/comm/calendar/import-export/CalHtmlExport.jsm
new file mode 100644
index 0000000000..82aeba59a7
--- /dev/null
+++ b/comm/calendar/import-export/CalHtmlExport.jsm
@@ -0,0 +1,116 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var EXPORTED_SYMBOLS = ["CalHtmlExporter"];
+
+var { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm");
+
+/**
+ * HTML Export Plugin
+ */
+function CalHtmlExporter() {
+ this.wrappedJSObject = this;
+}
+
+CalHtmlExporter.prototype = {
+ QueryInterface: ChromeUtils.generateQI(["calIExporter"]),
+ classID: Components.ID("{72d9ab35-9b1b-442a-8cd0-ae49f00b159b}"),
+
+ getFileTypes() {
+ let wildmat = "*.html; *.htm";
+ let label = cal.l10n.getCalString("filterHtml", [wildmat]);
+ return [
+ {
+ QueryInterface: ChromeUtils.generateQI(["calIFileType"]),
+ defaultExtension: "html",
+ extensionFilter: wildmat,
+ description: label,
+ },
+ ];
+ },
+
+ exportToStream(aStream, aItems, aTitle) {
+ let document = cal.xml.parseFile("chrome://calendar/content/printing/calHtmlExport.html");
+ let itemContainer = document.getElementById("item-container");
+ document.getElementById("title").textContent = aTitle || cal.l10n.getCalString("HTMLTitle");
+
+ // Sort aItems
+ aItems.sort((a, b) => {
+ let start_a = a[cal.dtz.startDateProp(a)];
+ if (!start_a) {
+ return -1;
+ }
+ let start_b = b[cal.dtz.startDateProp(b)];
+ if (!start_b) {
+ return 1;
+ }
+ return start_a.compare(start_b);
+ });
+
+ for (let item of aItems) {
+ let itemNode = document.getElementById("item-template").cloneNode(true);
+ itemNode.removeAttribute("id");
+
+ let setupTextRow = function (classKey, propValue, prefixKey) {
+ if (propValue) {
+ let prefix = cal.l10n.getCalString(prefixKey);
+ itemNode.querySelector("." + classKey + "key").textContent = prefix;
+ itemNode.querySelector("." + classKey).textContent = propValue;
+ } else {
+ let row = itemNode.querySelector("." + classKey + "row");
+ if (
+ row.nextSibling.nodeType == row.nextSibling.TEXT_NODE ||
+ row.nextSibling.nodeType == row.nextSibling.CDATA_SECTION_NODE
+ ) {
+ row.nextSibling.remove();
+ }
+ row.remove();
+ }
+ };
+
+ let startDate = item[cal.dtz.startDateProp(item)];
+ let endDate = item[cal.dtz.endDateProp(item)];
+ if (startDate || endDate) {
+ // This is a task with a start or due date, format accordingly
+ let prefixWhen = cal.l10n.getCalString("htmlPrefixWhen");
+ itemNode.querySelector(".intervalkey").textContent = prefixWhen;
+
+ let startNode = itemNode.querySelector(".dtstart");
+ let dateString = cal.dtz.formatter.formatItemInterval(item);
+ startNode.setAttribute("title", startDate ? startDate.icalString : "none");
+ startNode.textContent = dateString;
+ } else {
+ let row = itemNode.querySelector(".intervalrow");
+ row.remove();
+ if (
+ row.nextSibling &&
+ (row.nextSibling.nodeType == row.nextSibling.TEXT_NODE ||
+ row.nextSibling.nodeType == row.nextSibling.CDATA_SECTION_NODE)
+ ) {
+ row.nextSibling.remove();
+ }
+ }
+
+ let itemTitle = item.isCompleted
+ ? cal.l10n.getCalString("htmlTaskCompleted", [item.title])
+ : item.title;
+ setupTextRow("summary", itemTitle, "htmlPrefixTitle");
+
+ setupTextRow("location", item.getProperty("LOCATION"), "htmlPrefixLocation");
+ setupTextRow("description", item.getProperty("DESCRIPTION"), "htmlPrefixDescription");
+
+ itemContainer.appendChild(itemNode);
+ }
+
+ let templates = document.getElementById("templates");
+ templates.remove();
+
+ // Convert the javascript string to an array of bytes, using the utf8 encoder
+ let convStream = Cc["@mozilla.org/intl/converter-output-stream;1"].createInstance(
+ Ci.nsIConverterOutputStream
+ );
+ convStream.init(aStream, "UTF-8");
+ convStream.writeString(cal.xml.serializeDOM(document));
+ },
+};
diff --git a/comm/calendar/import-export/CalIcsImportExport.jsm b/comm/calendar/import-export/CalIcsImportExport.jsm
new file mode 100644
index 0000000000..30b5373c3c
--- /dev/null
+++ b/comm/calendar/import-export/CalIcsImportExport.jsm
@@ -0,0 +1,55 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var EXPORTED_SYMBOLS = ["CalIcsImporter", "CalIcsExporter"];
+
+var { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm");
+
+// Shared functions
+function getIcsFileTypes() {
+ return [
+ {
+ QueryInterface: ChromeUtils.generateQI(["calIFileType"]),
+ defaultExtension: "ics",
+ extensionFilter: "*.ics",
+ description: cal.l10n.getCalString("filterIcs", ["*.ics"]),
+ },
+ ];
+}
+
+function CalIcsImporter() {
+ this.wrappedJSObject = this;
+}
+
+CalIcsImporter.prototype = {
+ QueryInterface: ChromeUtils.generateQI(["calIImporter"]),
+ classID: Components.ID("{1e3e33dc-445a-49de-b2b6-15b2a050bb9d}"),
+
+ getFileTypes: getIcsFileTypes,
+
+ importFromStream(aStream) {
+ let parser = Cc["@mozilla.org/calendar/ics-parser;1"].createInstance(Ci.calIIcsParser);
+ parser.parseFromStream(aStream);
+ return parser.getItems();
+ },
+};
+
+function CalIcsExporter() {
+ this.wrappedJSObject = this;
+}
+
+CalIcsExporter.prototype = {
+ QueryInterface: ChromeUtils.generateQI(["calIExporter"]),
+ classID: Components.ID("{a6a524ce-adff-4a0f-bb7d-d1aaad4adc60}"),
+
+ getFileTypes: getIcsFileTypes,
+
+ exportToStream(aStream, aItems, aTitle) {
+ let serializer = Cc["@mozilla.org/calendar/ics-serializer;1"].createInstance(
+ Ci.calIIcsSerializer
+ );
+ serializer.addItems(aItems);
+ serializer.serializeToStream(aStream);
+ },
+};
diff --git a/comm/calendar/import-export/calHtmlExport.html b/comm/calendar/import-export/calHtmlExport.html
new file mode 100644
index 0000000000..920b3b412d
--- /dev/null
+++ b/comm/calendar/import-export/calHtmlExport.html
@@ -0,0 +1,71 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title id="title"></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+ <style type="text/css" id="sheet">
+ .vevent {
+ border: 1px solid black;
+ padding: 0;
+ margin-bottom: 10px;
+ }
+
+ .key {
+ font-style: italic;
+ margin-left: 3px;
+ }
+
+ .value {
+ margin-left: 20px;
+ }
+
+ abbr {
+ border: none;
+ }
+
+ .summarykey {
+ display: none;
+ }
+
+ .summary {
+ font-weight: bold;
+ margin: 0;
+ padding: 3px;
+ }
+
+ .description {
+ white-space: pre-wrap;
+ }
+ </style>
+ </head>
+ <body id="item-container">
+ <!-- Note on the use of the summarykey class:
+ This node is hidden by default for better readability. If you would
+ like to show the key, remove the display style above. -->
+ <div id="templates">
+ <div class="vevent" id="item-template">
+ <div class="row summaryrow">
+ <div class="key summarykey"></div>
+ <div class="value summary"></div>
+ </div>
+ <div class="row intervalrow">
+ <div class="key intervalkey"></div>
+ <div class="value">
+ <abbr class="dtstart"></abbr>
+ </div>
+ </div>
+ <div class="row locationrow">
+ <div class="key locationkey"></div>
+ <div class="value location"></div>
+ </div>
+ <div class="row descriptionrow">
+ <div class="key descriptionkey"></div>
+ <div class="value description"></div>
+ </div>
+ </div>
+ </div>
+ </body>
+</html>
diff --git a/comm/calendar/import-export/components.conf b/comm/calendar/import-export/components.conf
new file mode 100644
index 0000000000..f336c30bc0
--- /dev/null
+++ b/comm/calendar/import-export/components.conf
@@ -0,0 +1,29 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/
+
+Classes = [
+ {
+ 'cid': '{1e3e33dc-445a-49de-b2b6-15b2a050bb9d}',
+ 'contract_ids': ['@mozilla.org/calendar/import;1?type=ics'],
+ 'jsm': 'resource:///modules/CalIcsImportExport.jsm',
+ 'constructor': 'CalIcsImporter',
+ 'categories': {'cal-importers': 'cal-ics-importer'},
+ },
+ {
+ 'cid': '{a6a524ce-adff-4a0f-bb7d-d1aaad4adc60}',
+ 'contract_ids': ['@mozilla.org/calendar/export;1?type=ics'],
+ 'jsm': 'resource:///modules/CalIcsImportExport.jsm',
+ 'constructor': 'CalIcsExporter',
+ 'categories': {'cal-exporters': 'cal-ics-exporter'},
+ },
+ {
+ 'cid': '{72d9ab35-9b1b-442a-8cd0-ae49f00b159b}',
+ 'contract_ids': ['@mozilla.org/calendar/export;1?type=htmllist'],
+ 'jsm': 'resource:///modules/CalHtmlExport.jsm',
+ 'constructor': 'CalHtmlExporter',
+ 'categories': {'cal-exporters': 'cal-html-list-exporter'},
+ },
+]
diff --git a/comm/calendar/import-export/jar.mn b/comm/calendar/import-export/jar.mn
new file mode 100644
index 0000000000..453701b6b0
--- /dev/null
+++ b/comm/calendar/import-export/jar.mn
@@ -0,0 +1,7 @@
+#filter substitution
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, you can obtain one at http://mozilla.org/MPL/2.0/.
+
+calendar.jar:
+ content/printing/calHtmlExport.html (calHtmlExport.html)
diff --git a/comm/calendar/import-export/moz.build b/comm/calendar/import-export/moz.build
new file mode 100644
index 0000000000..f716fbc0b4
--- /dev/null
+++ b/comm/calendar/import-export/moz.build
@@ -0,0 +1,18 @@
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+JAR_MANIFESTS += ["jar.mn"]
+
+EXTRA_JS_MODULES += [
+ "CalHtmlExport.jsm",
+ "CalIcsImportExport.jsm",
+]
+
+XPCOM_MANIFESTS += [
+ "components.conf",
+]
+
+with Files("**"):
+ BUG_COMPONENT = ("Calendar", "Import and Export")