зеркало из https://github.com/mozilla/pjs.git
More ICS parsing work:
- richer support for property manipulation - includes X-PROPERTY capabilities - stubbed-in property-parameter support
This commit is contained in:
Родитель
3cc3106e8e
Коммит
c056845cb8
|
@ -41,6 +41,8 @@
|
|||
interface calIItemBase;
|
||||
interface calIDateTime;
|
||||
|
||||
interface calIIcalProperty;
|
||||
|
||||
[scriptable,uuid(4d7e456b-cfd0-4ebf-8794-c57789dafdc3)]
|
||||
interface calIIcalComponent : nsISupports
|
||||
{
|
||||
|
@ -124,6 +126,60 @@ interface calIIcalComponent : nsISupports
|
|||
AUTF8String serializeToICS();
|
||||
|
||||
void addSubcomponent(in calIIcalComponent comp);
|
||||
void removeSubcomponent(in calIIcalComponent comp);
|
||||
|
||||
const PRUint32 ANY_PROPERTY = 0;
|
||||
const PRUint32 ACTION_PROPERTY = 1;
|
||||
const PRUint32 ATTACH_PROPERTY = 2;
|
||||
const PRUint32 ATTENDEE_PROPERTY = 3;
|
||||
calIIcalProperty getFirstProperty(in PRUint32 kind);
|
||||
calIIcalProperty getNextProperty(in PRUint32 kind);
|
||||
calIIcalProperty addProperty(in PRUint32 kind);
|
||||
void removeProperty(in calIIcalProperty prop);
|
||||
|
||||
calIIcalProperty getFirstXProperty(in AUTF8String xpropname);
|
||||
calIIcalProperty getNextXProperty(in AUTF8String xpropname);
|
||||
calIIcalProperty addXProperty(in AUTF8String xpropname,
|
||||
in AUTF8String xpropval);
|
||||
};
|
||||
|
||||
[scriptable,uuid(17349a10-5d80-47fa-9bea-f22957357675)]
|
||||
interface calIIcalProperty : nsISupports
|
||||
{
|
||||
attribute AUTF8String stringValue;
|
||||
readonly attribute PRUint32 isA;
|
||||
|
||||
AUTF8String getXParameter(in AUTF8String xparamname);
|
||||
void setXParameter(in AUTF8String xparamname, in AUTF8String xparamval);
|
||||
void removeXParameter(in AUTF8String xparamname);
|
||||
|
||||
const PRUint32 ALTREP_PARAMETER = 1;
|
||||
const PRUint32 CN_PARAMETER = 2;
|
||||
const PRUint32 CUTYPE_PARAMETER = 3;
|
||||
const PRUint32 DELEGATEDFROM_PARAMETER = 4;
|
||||
const PRUint32 DELEGATEDTO_PARAMETER = 5;
|
||||
const PRUint32 DIR_PARAMETER = 6;
|
||||
const PRUint32 ENCODING_PARAMETER = 7;
|
||||
const PRUint32 FBTYPE_PARAMETER = 8;
|
||||
const PRUint32 FMTTYPE_PARAMETER = 9;
|
||||
const PRUint32 LANGUAGE_PARAMETER = 10;
|
||||
const PRUint32 MEMBER_PARAMETER = 11;
|
||||
const PRUint32 PARTSTAT_PARAMETER = 12;
|
||||
const PRUint32 RANGE_PARAMETER = 13;
|
||||
const PRUint32 RELATED_PARAMETER = 14;
|
||||
const PRUint32 RELTYPE_PARAMETER = 15;
|
||||
const PRUint32 ROLE_PARAMETER = 16;
|
||||
const PRUint32 RSVP_PARAMETER = 17;
|
||||
const PRUint32 SENTBY_PARAMETER = 18;
|
||||
const PRUint32 TZID_PARAMETER = 19;
|
||||
const PRUint32 VALUE_PARAMETER = 20;
|
||||
/* const PRUint32 X_PARAMETER = 21; */
|
||||
const PRUint32 XLICCOMPARETYPE_PARAMETER = 22;
|
||||
const PRUint32 XLICERRORTYPE_PARAMETER = 23;
|
||||
|
||||
AUTF8String getParameter(in PRUint32 kind);
|
||||
void setParameter(in PRUint32 kind, in AUTF8String value);
|
||||
void removeParameter(in PRUint32 kind);
|
||||
};
|
||||
|
||||
[scriptable,uuid(c788a1dc-0929-4029-9a14-e1bc654eafad)]
|
||||
|
|
|
@ -50,11 +50,106 @@ extern "C" {
|
|||
# include "ical.h"
|
||||
}
|
||||
|
||||
class calIcalProperty : public calIIcalProperty
|
||||
{
|
||||
public:
|
||||
calIcalProperty(icalproperty *prop, calIIcalComponent *parent) :
|
||||
mProperty(prop), mParent(parent) { }
|
||||
virtual ~calIcalProperty()
|
||||
{
|
||||
if (!mParent)
|
||||
icalproperty_free(mProperty);
|
||||
}
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_CALIICALPROPERTY
|
||||
|
||||
friend class calIcalComponent;
|
||||
protected:
|
||||
icalproperty *mProperty;
|
||||
nsCOMPtr<calIIcalComponent> mParent;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(calIcalProperty, calIIcalProperty)
|
||||
|
||||
NS_IMETHODIMP
|
||||
calIcalProperty::GetIsA(PRUint32 *isa)
|
||||
{
|
||||
*isa = (PRUint32)icalproperty_isa(mProperty);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calIcalProperty::GetStringValue(nsACString &str)
|
||||
{
|
||||
const char *icalstr = icalproperty_get_value_as_string(mProperty);
|
||||
if (!icalstr) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Error getting string value: %d (%s)\n",
|
||||
icalerrno, icalerror_strerror(icalerrno));
|
||||
#endif
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
str.Assign(icalstr);
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calIcalProperty::SetStringValue(const nsACString &str)
|
||||
{
|
||||
const char *kindstr =
|
||||
icalvalue_kind_to_string(icalproperty_kind_to_value_kind(icalproperty_isa(mProperty)));
|
||||
icalproperty_set_value_from_string(mProperty,
|
||||
PromiseFlatCString(str).get(),
|
||||
kindstr);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calIcalProperty::GetXParameter(const nsACString &xparamname,
|
||||
nsACString &xparamvalue)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calIcalProperty::SetXParameter(const nsACString &xparamname,
|
||||
const nsACString &xparamvalue)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
calIcalProperty::RemoveXParameter(const nsACString &xparamname)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calIcalProperty::GetParameter(PRUint32 kind, nsACString &value)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calIcalProperty::SetParameter(PRUint32 kind, const nsACString &value)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calIcalProperty::RemoveParameter(PRUint32 kind)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
class calIcalComponent : public calIIcalComponent
|
||||
{
|
||||
public:
|
||||
calIcalComponent(icalcomponent *ical,
|
||||
calIcalComponent *parent) :
|
||||
calIcalComponent(icalcomponent *ical, calIIcalComponent *parent) :
|
||||
mComponent(ical), mParent(parent) { }
|
||||
|
||||
virtual ~calIcalComponent()
|
||||
|
@ -110,7 +205,7 @@ protected:
|
|||
void ClearAllProperties(icalproperty_kind kind);
|
||||
|
||||
icalcomponent *mComponent;
|
||||
nsCOMPtr<calIcalComponent> mParent;
|
||||
nsCOMPtr<calIIcalComponent> mParent;
|
||||
};
|
||||
|
||||
nsresult
|
||||
|
@ -127,7 +222,7 @@ calIcalComponent::SetProperty(icalproperty_kind kind, icalvalue *val)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
#define STRING_ATTRIBUTE(Attrname, ICALNAME) \
|
||||
#define COMP_STRING_ATTRIBUTE(Attrname, ICALNAME) \
|
||||
NS_IMETHODIMP \
|
||||
calIcalComponent::Get##Attrname(nsACString &str) \
|
||||
{ \
|
||||
|
@ -140,7 +235,7 @@ calIcalComponent::Set##Attrname(const nsACString &str) \
|
|||
return SetStringProperty(ICAL_##ICALNAME##_PROPERTY, str); \
|
||||
}
|
||||
|
||||
#define INT_ATTRIBUTE(Attrname, ICALNAME) \
|
||||
#define COMP_INT_ATTRIBUTE(Attrname, ICALNAME) \
|
||||
NS_IMETHODIMP \
|
||||
calIcalComponent::Get##Attrname(PRUint32 *valp) \
|
||||
{ \
|
||||
|
@ -153,7 +248,7 @@ calIcalComponent::Set##Attrname(PRUint32 val) \
|
|||
return SetIntProperty(ICAL_##ICALNAME##_PROPERTY, val); \
|
||||
} \
|
||||
|
||||
#define RO_DATE_ATTRIBUTE(Attrname, ICALNAME) \
|
||||
#define RO_COMP_DATE_ATTRIBUTE(Attrname, ICALNAME) \
|
||||
NS_IMETHODIMP \
|
||||
calIcalComponent::Get##Attrname(calIDateTime **dtp) \
|
||||
{ \
|
||||
|
@ -174,8 +269,8 @@ calIcalComponent::Get##Attrname(calIDateTime **dtp) \
|
|||
return NS_OK; \
|
||||
}
|
||||
|
||||
#define DATE_ATTRIBUTE(Attrname, ICALNAME) \
|
||||
RO_DATE_ATTRIBUTE(Attrname, ICALNAME) \
|
||||
#define COMP_DATE_ATTRIBUTE(Attrname, ICALNAME) \
|
||||
RO_COMP_DATE_ATTRIBUTE(Attrname, ICALNAME) \
|
||||
\
|
||||
NS_IMETHODIMP \
|
||||
calIcalComponent::Set##Attrname(calIDateTime *dt) \
|
||||
|
@ -195,7 +290,8 @@ calIcalComponent::GetFirstSubcomponent(PRUint32 componentType,
|
|||
calIIcalComponent **subcomp)
|
||||
{
|
||||
icalcomponent *ical =
|
||||
icalcomponent_get_first_component(mComponent, (icalcomponent_kind)componentType);
|
||||
icalcomponent_get_first_component(mComponent,
|
||||
(icalcomponent_kind)componentType);
|
||||
if (!ical) {
|
||||
*subcomp = nsnull;
|
||||
return NS_OK;
|
||||
|
@ -213,7 +309,8 @@ calIcalComponent::GetNextSubcomponent(PRUint32 componentType,
|
|||
calIIcalComponent **subcomp)
|
||||
{
|
||||
icalcomponent *ical =
|
||||
icalcomponent_get_next_component(mComponent, (icalcomponent_kind)componentType);
|
||||
icalcomponent_get_next_component(mComponent,
|
||||
(icalcomponent_kind)componentType);
|
||||
if (!ical) {
|
||||
*subcomp = nsnull;
|
||||
return NS_OK;
|
||||
|
@ -233,26 +330,26 @@ calIcalComponent::GetIsA(PRUint32 *isa)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
STRING_ATTRIBUTE(Uid, UID)
|
||||
STRING_ATTRIBUTE(Prodid, PRODID)
|
||||
STRING_ATTRIBUTE(Version, VERSION)
|
||||
INT_ATTRIBUTE(Method, METHOD)
|
||||
INT_ATTRIBUTE(Status, STATUS)
|
||||
INT_ATTRIBUTE(Transp, TRANSP)
|
||||
STRING_ATTRIBUTE(Summary, SUMMARY)
|
||||
STRING_ATTRIBUTE(Description, DESCRIPTION)
|
||||
STRING_ATTRIBUTE(Location, LOCATION)
|
||||
STRING_ATTRIBUTE(Categories, CATEGORIES)
|
||||
STRING_ATTRIBUTE(URL, URL)
|
||||
INT_ATTRIBUTE(Priority, PRIORITY)
|
||||
INT_ATTRIBUTE(IcalClass, CLASS)
|
||||
DATE_ATTRIBUTE(StartTime, DTSTART)
|
||||
DATE_ATTRIBUTE(EndTime, DTEND)
|
||||
DATE_ATTRIBUTE(DueTime, DUE)
|
||||
DATE_ATTRIBUTE(StampTime, DTSTAMP)
|
||||
DATE_ATTRIBUTE(LastModified, LASTMODIFIED)
|
||||
DATE_ATTRIBUTE(CreatedTime, CREATED)
|
||||
DATE_ATTRIBUTE(CompletedTime, COMPLETED)
|
||||
COMP_STRING_ATTRIBUTE(Uid, UID)
|
||||
COMP_STRING_ATTRIBUTE(Prodid, PRODID)
|
||||
COMP_STRING_ATTRIBUTE(Version, VERSION)
|
||||
COMP_INT_ATTRIBUTE(Method, METHOD)
|
||||
COMP_INT_ATTRIBUTE(Status, STATUS)
|
||||
COMP_INT_ATTRIBUTE(Transp, TRANSP)
|
||||
COMP_STRING_ATTRIBUTE(Summary, SUMMARY)
|
||||
COMP_STRING_ATTRIBUTE(Description, DESCRIPTION)
|
||||
COMP_STRING_ATTRIBUTE(Location, LOCATION)
|
||||
COMP_STRING_ATTRIBUTE(Categories, CATEGORIES)
|
||||
COMP_STRING_ATTRIBUTE(URL, URL)
|
||||
COMP_INT_ATTRIBUTE(Priority, PRIORITY)
|
||||
COMP_INT_ATTRIBUTE(IcalClass, CLASS)
|
||||
COMP_DATE_ATTRIBUTE(StartTime, DTSTART)
|
||||
COMP_DATE_ATTRIBUTE(EndTime, DTEND)
|
||||
COMP_DATE_ATTRIBUTE(DueTime, DUE)
|
||||
COMP_DATE_ATTRIBUTE(StampTime, DTSTAMP)
|
||||
COMP_DATE_ATTRIBUTE(LastModified, LASTMODIFIED)
|
||||
COMP_DATE_ATTRIBUTE(CreatedTime, CREATED)
|
||||
COMP_DATE_ATTRIBUTE(CompletedTime, COMPLETED)
|
||||
|
||||
NS_IMETHODIMP
|
||||
calIcalComponent::GetAttendees(PRUint32 *count, char ***attendees)
|
||||
|
@ -347,6 +444,138 @@ calIcalComponent::AddSubcomponent(calIIcalComponent *comp)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calIcalComponent::RemoveSubcomponent(calIIcalComponent *comp)
|
||||
{
|
||||
calIcalComponent *ical = NS_STATIC_CAST(calIcalComponent *, comp);
|
||||
icalcomponent_remove_component(mComponent, ical->mComponent);
|
||||
ical->mParent = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calIcalComponent::GetFirstProperty(PRUint32 kind, calIIcalProperty **prop)
|
||||
{
|
||||
icalproperty *icalprop =
|
||||
icalcomponent_get_first_property(mComponent, (icalproperty_kind)kind);
|
||||
if (!icalprop) {
|
||||
*prop = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*prop = new calIcalProperty(icalprop, this);
|
||||
if (!*prop)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(*prop);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calIcalComponent::GetNextProperty(PRUint32 kind, calIIcalProperty **prop)
|
||||
{
|
||||
icalproperty *icalprop =
|
||||
icalcomponent_get_next_property(mComponent, (icalproperty_kind)kind);
|
||||
if (!icalprop) {
|
||||
*prop = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*prop = new calIcalProperty(icalprop, this);
|
||||
if (!*prop)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(*prop);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calIcalComponent::AddProperty(PRUint32 kind, calIIcalProperty **prop)
|
||||
{
|
||||
icalproperty *icalprop = icalproperty_new((icalproperty_kind)kind);
|
||||
if (!icalprop)
|
||||
return NS_ERROR_OUT_OF_MEMORY; // XXX translate
|
||||
*prop = new calIcalProperty(icalprop, this);
|
||||
if (!*prop)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(*prop);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calIcalComponent::RemoveProperty(calIIcalProperty *prop)
|
||||
{
|
||||
// XXX like AddSubcomponent, this is questionable
|
||||
calIcalProperty *ical = NS_STATIC_CAST(calIcalProperty *, prop);
|
||||
icalcomponent_remove_property(mComponent, ical->mProperty);
|
||||
ical->mParent = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calIcalComponent::GetFirstXProperty(const nsACString &xpropname,
|
||||
calIIcalProperty **prop)
|
||||
{
|
||||
for (icalproperty *icalprop =
|
||||
icalcomponent_get_first_property(mComponent, ICAL_X_PROPERTY);
|
||||
icalprop;
|
||||
icalprop = icalcomponent_get_next_property(mComponent,
|
||||
ICAL_X_PROPERTY)) {
|
||||
|
||||
if (xpropname.Equals(icalproperty_get_x_name(icalprop))) {
|
||||
*prop = new calIcalProperty(icalprop, this);
|
||||
if (!*prop)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(*prop);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
}
|
||||
*prop = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calIcalComponent::GetNextXProperty(const nsACString &xpropname,
|
||||
calIIcalProperty **prop)
|
||||
{
|
||||
for (icalproperty *icalprop =
|
||||
icalcomponent_get_next_property(mComponent, ICAL_X_PROPERTY);
|
||||
icalprop;
|
||||
icalprop = icalcomponent_get_next_property(mComponent,
|
||||
ICAL_X_PROPERTY)) {
|
||||
|
||||
if (xpropname.Equals(icalproperty_get_x_name(icalprop))) {
|
||||
*prop = new calIcalProperty(icalprop, this);
|
||||
if (!*prop)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(*prop);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
}
|
||||
*prop = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calIcalComponent::AddXProperty(const nsACString &xpropname,
|
||||
const nsACString &xpropval,
|
||||
calIIcalProperty **prop)
|
||||
{
|
||||
icalproperty* icalprop = icalproperty_new(ICAL_X_PROPERTY);
|
||||
if (!icalprop)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
icalproperty_set_value_from_string(icalprop,
|
||||
PromiseFlatCString(xpropname).get(),
|
||||
PromiseFlatCString(xpropval).get());
|
||||
*prop = new calIcalProperty(icalprop, this);
|
||||
if (!*prop) {
|
||||
icalproperty_free(icalprop);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
NS_ADDREF(*prop);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(calICSService, calIICSService)
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
Загрузка…
Ссылка в новой задаче