- Basic ICS serialization of events.

- icalComponent getter on calIItemBase to aid in serializing multiple
  components, such as to write out an entire calendar as ICS (say).
- Fix DATE property handling in the ICS service, no thanks at all to libical's
  use of obfuscated void * as its type for everything.
This commit is contained in:
shaver%mozilla.org 2004-12-10 00:15:22 +00:00
Родитель b8ade7319c
Коммит 9d1ce73843
6 изменённых файлов: 137 добавлений и 35 удалений

Просмотреть файл

@ -21,6 +21,7 @@
*
* Contributor(s):
* Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
* Mike Shaver <shaver@mozilla.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -58,6 +59,8 @@ interface calIMutableRecurrenceInfo;
interface calIAttendee;
interface calIIcalComponent;
//
// calIItemBase
//
@ -120,6 +123,11 @@ interface calIItemBase : nsISupports
// the ical string into this event
attribute AUTF8String icalString;
// an icalComponent for this item, suitable for serialization.
// the icalComponent returned is not live: changes in it or this
// item will not be reflected in the other.
readonly attribute calIIcalComponent icalComponent;
//
// alarms
//

Просмотреть файл

@ -60,6 +60,11 @@ calEvent.prototype = {
icsEventPropMap: [
{ cal: "mStartDate", ics: "startTime" },
{ cal: "mEndDate", ics: "endTime" },
{ cal: "mStampDate", ics: "stampTime" } ],
set icalString(value) {
if (this.mImmutable)
throw Components.results.NS_ERROR_FAILURE;
@ -70,10 +75,26 @@ calEvent.prototype = {
throw Components.results.NS_ERROR_INVALID_ARG;
this.setItemBaseFromICS(event);
var propmap = [["mStartDate", "startTime"],
["mEndDate", "endTime"],
["mStampDate", "stampDate"]];
this.mapPropsFromICS(event, propmap);
this.mIsAllDay = this.mStartDate.isDate;
this.mapPropsFromICS(event, this.icsEventPropMap);
this.mIsAllDay = this.mStartDate && this.mStartDate.isDate;
},
get icalString() {
const icssvc = Components.
classes["@mozilla.org/calendar/ics-service;1"].
getService(Components.interfaces.calIICSService);
var calcomp = icssvc.createIcalComponent(ICAL.VCALENDAR_COMPONENT);
calcomp.addSubcomponent(this.icalComponent);
return calcomp.serializeToICS();
},
get icalComponent() {
const icssvc = Components.
classes["@mozilla.org/calendar/ics-service;1"].
getService(Components.interfaces.calIICSService);
var icalcomp = icssvc.createIcalComponent(ICAL.VEVENT_COMPONENT);
this.fillIcalComponentFromBase(icalcomp);
this.mapPropsToICS(icalcomp, this.icsEventPropMap);
return icalcomp;
},
};

Просмотреть файл

@ -105,6 +105,11 @@ calEvent.prototype = {
#undef MEMBER_ATTR
icsEventPropMap: [
{ cal: "mStartDate", ics: "startTime" },
{ cal: "mEndDate", ics: "endTime" },
{ cal: "mStampDate", ics: "stampTime" } ],
set icalString(value) {
if (this.mImmutable)
throw Components.results.NS_ERROR_FAILURE;
@ -115,10 +120,26 @@ calEvent.prototype = {
throw Components.results.NS_ERROR_INVALID_ARG;
this.setItemBaseFromICS(event);
var propmap = [["mStartDate", "startTime"],
["mEndDate", "endTime"],
["mStampDate", "stampDate"]];
this.mapPropsFromICS(event, propmap);
this.mIsAllDay = this.mStartDate.isDate;
this.mapPropsFromICS(event, this.icsEventPropMap);
this.mIsAllDay = this.mStartDate && this.mStartDate.isDate;
},
get icalString() {
const icssvc = Components.
classes["@mozilla.org/calendar/ics-service;1"].
getService(Components.interfaces.calIICSService);
var calcomp = icssvc.createIcalComponent(ICAL.VCALENDAR_COMPONENT);
calcomp.addSubcomponent(this.icalComponent);
return calcomp.serializeToICS();
},
get icalComponent() {
const icssvc = Components.
classes["@mozilla.org/calendar/ics-service;1"].
getService(Components.interfaces.calIICSService);
var icalcomp = icssvc.createIcalComponent(ICAL.VEVENT_COMPONENT);
this.fillIcalComponentFromBase(icalcomp);
this.mapPropsToICS(icalcomp, this.icsEventPropMap);
return icalcomp;
},
};

Просмотреть файл

@ -339,7 +339,7 @@ calIcalComponent::Set##Attrname(calIDateTime *dt) \
icalvalue *val = icalvalue_new_datetime(itt); \
if (!val) \
return NS_ERROR_OUT_OF_MEMORY; \
return SetProperty(ICAL_##ICALNAME##_PROPERTY, val); \
return SetPropertyValue(ICAL_##ICALNAME##_PROPERTY, val); \
}
NS_IMPL_ISUPPORTS1(calIcalComponent, calIIcalComponent)

Просмотреть файл

@ -1,4 +1,6 @@
/* GENERATED FILE; DO NOT EDIT. SOURCE IS calItemBase.js.pre */
const ICAL = Components.interfaces.calIIcalComponent;
function calItemBase() { }
calItemBase.prototype = {
@ -165,27 +167,51 @@ calItemBase.prototype = {
mapPropsFromICS: function(icalcomp, propmap) {
for (var i = 0; i < propmap.length; i++) {
var prop = propmap[i];
this[prop[0]] = icalcomp[prop[1]];
this[prop.cal] = icalcomp[prop.ics];
}
},
mapPropsToICS: function(icalcomp, propmap) {
for (var i = 0; i < propmap.length; i++) {
var prop = propmap[i];
icalcomp[prop.ics] = this[prop.cal];
}
},
icsBasePropMap: [
{ cal: "mCreationDate", ics: "createdTime" },
{ cal: "mLastModifiedTime", ics: "lastModified" },
{ cal: "mGeneration", ics: "version" },
{ cal: "mId", ics: "uid" },
{ cal: "mTitle", ics: "summary" },
{ cal: "mPriority", ics: "priority" },
{ cal: "mMethod", ics: "method" },
{ cal: "mStatus", ics: "status" }],
setItemBaseFromICS: function (icalcomp) {
if (this.mImmutable)
throw Components.results.NS_ERROR_FAILURE;
var propmap = [["mCreationDate", "createdTime"],
["mLastModifiedTime", "lastModified"],
["mGeneration", "version"],
["mId", "uid"],
["mTitle", "summary"],
["mPriority", "priority"],
["mMethod", "method"],
["mStatus", "status"]];
this.mapPropsFromICS(icalcomp, propmap);
if (icalcomp.icalClass == Components.interfaces.calIICSService.VISIBILITY_PUBLIC)
this.mapPropsFromICS(icalcomp, this.icsBasePropMap);
if (icalcomp.icalClass == ICAL.VISIBILITY_PUBLIC)
this.mIsPrivate = false;
else
this.mIsPrivate = true;
}
},
get icalComponent() {
throw Components.results.NS_NOT_IMPLEMENTED;
},
fillIcalComponentFromBase: function (icalcomp) {
this.mapPropsToICS(icalcomp, this.icsBasePropMap);
if (this.mIsPrivate)
icalcomp.icalClass = ICAL.VISIBILITY_PRIVATE;
else
icalcomp.icalClass = ICAL.VISIBILITY_PUBLIC;
},
};
function calItemOccurrence () {

Просмотреть файл

@ -41,6 +41,8 @@
// calItemBase.js
//
const ICAL = Components.interfaces.calIIcalComponent;
function calItemBase() { }
calItemBase.prototype = {
@ -207,27 +209,51 @@ calItemBase.prototype = {
mapPropsFromICS: function(icalcomp, propmap) {
for (var i = 0; i < propmap.length; i++) {
var prop = propmap[i];
this[prop[0]] = icalcomp[prop[1]];
this[prop.cal] = icalcomp[prop.ics];
}
},
mapPropsToICS: function(icalcomp, propmap) {
for (var i = 0; i < propmap.length; i++) {
var prop = propmap[i];
icalcomp[prop.ics] = this[prop.cal];
}
},
icsBasePropMap: [
{ cal: "mCreationDate", ics: "createdTime" },
{ cal: "mLastModifiedTime", ics: "lastModified" },
{ cal: "mGeneration", ics: "version" },
{ cal: "mId", ics: "uid" },
{ cal: "mTitle", ics: "summary" },
{ cal: "mPriority", ics: "priority" },
{ cal: "mMethod", ics: "method" },
{ cal: "mStatus", ics: "status" }],
setItemBaseFromICS: function (icalcomp) {
if (this.mImmutable)
throw Components.results.NS_ERROR_FAILURE;
var propmap = [["mCreationDate", "createdTime"],
["mLastModifiedTime", "lastModified"],
["mGeneration", "version"],
["mId", "uid"],
["mTitle", "summary"],
["mPriority", "priority"],
["mMethod", "method"],
["mStatus", "status"]];
this.mapPropsFromICS(icalcomp, propmap);
if (icalcomp.icalClass == Components.interfaces.calIICSService.VISIBILITY_PUBLIC)
this.mapPropsFromICS(icalcomp, this.icsBasePropMap);
// XXX roundtrip
if (icalcomp.icalClass == ICAL.VISIBILITY_PUBLIC)
this.mIsPrivate = false;
else
this.mIsPrivate = true;
}
},
get icalComponent() {
throw Components.results.NS_NOT_IMPLEMENTED;
},
fillIcalComponentFromBase: function (icalcomp) {
this.mapPropsToICS(icalcomp, this.icsBasePropMap);
// XXX roundtrip
if (this.mIsPrivate)
icalcomp.icalClass = ICAL.VISIBILITY_PRIVATE;
else
icalcomp.icalClass = ICAL.VISIBILITY_PUBLIC;
},
};
function calItemOccurrence () {