added calRecurrenceInfo, using libical to calculate recurrence; fixed calDateTime jsDate timezone handling; added calTodo implementation

This commit is contained in:
vladimir%pobox.com 2004-12-01 23:36:16 +00:00
Родитель e8616ca037
Коммит c77a324d89
18 изменённых файлов: 806 добавлений и 63 удалений

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

@ -40,11 +40,13 @@
#include "calDateTime.h"
#include "calICSService.h"
#include "calRecurrenceInfo.h"
#include "calBaseCID.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(calDateTime)
NS_GENERIC_FACTORY_CONSTRUCTOR(calICSService)
NS_GENERIC_FACTORY_CONSTRUCTOR(calRecurrenceInfo)
static const nsModuleComponentInfo components[] =
{
@ -55,7 +57,11 @@ static const nsModuleComponentInfo components[] =
{ "ICS parser/serializer",
CAL_ICSSERVICE_CID,
CAL_ICSSERVICE_CONTRACTID,
calICSServiceConstructor }
calICSServiceConstructor },
{ "Calendar Recurrence Object",
CAL_RECURRENCEINFO_CID,
CAL_RECURRENCEINFO_CONTRACTID,
calRecurrenceInfoConstructor }
};
NS_IMPL_NSGETMODULE(calBaseModule, components)

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

@ -51,6 +51,11 @@
#define CAL_ICSSERVICE_CONTRACTID \
"@mozilla.org/calendar/ics-service;1"
#define CAL_RECURRENCEINFO_CID \
{ 0x04027036, 0x5884, 0x4a30, { 0xb4, 0xaf, 0xf2, 0xca, 0xd7, 0x9f, 0x6e, 0xdf } }
#define CAL_RECURRENCEINFO_CONTRACTID \
"@mozilla.org/calendar/recurrence-info;1"
/* JS -- Update these from calItemModule.js */
#define CAL_EVENT_CID \
{ 0x974339d5, 0xab86, 0x4491, { 0xaa, 0xaf, 0x2b, 0x2c, 0xa1, 0x77, 0xc1, 0x2b } }

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

@ -121,6 +121,10 @@ interface calIDateTime : nsISupports
// item in the given timezone
calIDateTime getInTimezone (in string aTimezone);
// add the given calIDateTime, treating it as a duration, to
// this item
void addDuration (in calIDateTime aDuration);
//
// Some helper getters for calculating useful ranges
//

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

@ -57,6 +57,9 @@ interface calIEvent : calIItemBase
attribute calIDateTime endDate;
attribute calIDateTime stampDate; // ??
// calculated as endDate - startDate
readonly attribute calIDateTime duration;
// all day event?
attribute boolean isAllDay;
};

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

@ -186,6 +186,10 @@ interface calIItemBase : nsISupports
[scriptable, uuid(b19f3d7e-e848-4139-af3e-505a8023568d)]
interface calIItemOccurrence : nsISupports
{
// Initialize this Occurrence
void initialize (in calIItemBase aItem,
in calIDateTime aStartDate,
in calIDateTime aEndDate);
//
// The parent item for which this is the occurrence item for
//

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

@ -54,7 +54,7 @@ interface calIRecurrenceInfo : nsISupports
void makeImmutable();
// clone always returns a mutable event
calIItemBase clone();
calIRecurrenceInfo clone();
//
// recurrence
@ -85,34 +85,36 @@ interface calIRecurrenceInfo : nsISupports
const long CAL_RECUR_BYHOUR = 10;
const long CAL_RECUR_BYDAY = 11;
const long CAL_RECUR_BYMONTHDAY = 12;
const long CAL_RECUR_BYWEEKNO = 13;
const long CAL_RECUR_BYMONTH = 14;
const long CAL_RECUR_BYSETPOS = 15;
const long CAL_RECUR_BYYEARDAY = 13;
const long CAL_RECUR_BYWEEKNO = 14;
const long CAL_RECUR_BYMONTH = 15;
const long CAL_RECUR_BYSETPOS = 16;
void getComponent (in long aComponentType,
out unsigned long aCount, [array,size_is(aCount),retval] out long aValues);
out unsigned long aCount, [array,size_is(aCount),retval] out short aValues);
void setComponent (in long aComponentType,
in unsigned long aCount, [array,size_is(aCount)] in long aValues);
in unsigned long aCount, [array,size_is(aCount)] in short aValues);
// exceptions
void getExceptions (out unsigned long aCount, [array,size_is(aCount),retval] out calIDateTime aDates);
void setExceptions (in unsigned long aCount, [array, size_is(aCount)] in calIDateTime aDates);
// return the next display item for this event,
// return the next display item for the event,
// where the start time is >= aStartTime
calIItemOccurrence getNextOccurrence (in calIDateTime aStartTime);
// return the previous display item for this event,
// where the start time is < aStartTime
calIItemOccurrence getPreviousOccurrence (in calIDateTime aStartTime);
calIItemOccurrence getNextOccurrence (in calIItemBase aItem, in calIDateTime aStartTime);
// return array of calIItemOccurrence representing all
// occurrences of this event between start and end.
void getOccurrences (in calIDateTime aStartTime,
in calIDateTime aEndTime,
out unsigned long aCount, [array,size_is(aCount),retval] out calIItemOccurrence aItems);
void getOccurrencesBetween (in calIItemBase aItem,
in calIDateTime aStartTime,
in calIDateTime aEndTime,
out unsigned long aCount, [array,size_is(aCount),retval] out calIItemOccurrence aItems);
// return array of calIItemOccurrence representing all
// occurrences of this event.
void getAllOccurrences (out unsigned long aCount, [array,size_is(aCount),retval] out calIItemOccurrence aItems);
// return array of calIItemOccurrence representing all occurrences
// of this event, starting at the given time. if aMaxCount is not
// 0, a max of aMaxCount occurrences is returned
void getOccurrences (in calIItemBase aItem,
in calIDateTime aStartTime,
in unsigned long aMaxCount,
out unsigned long aCount, [array,size_is(aCount),retval] out calIItemOccurrence aItems);
};

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

@ -62,6 +62,7 @@ REQUIRES = xpcom \
CPPSRCS = calDateTime.cpp \
calICSService.cpp \
calRecurrenceInfo.cpp \
$(NULL)
@ -70,6 +71,7 @@ EXTRA_COMPONENTS = \
calEvent.js \
calItemBase.js \
calItemModule.js \
calTodo.js \
$(NULL)
include $(topsrcdir)/config/rules.mk
@ -77,7 +79,7 @@ include $(topsrcdir)/config/rules.mk
#%.js: %.js.pre
# cpp -P -undef $(DEFINES) $(ACDEFINES) $^ > $@
CPP_FODDER = calItemBase calEvent calAttendee
CPP_FODDER = calItemBase calEvent calAttendee calTodo
rebuild:
for i in $(CPP_FODDER); do \

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

@ -18,16 +18,16 @@ calAttendee.prototype = {
get isMutable() { return !this.mImmutable; },
makeImmutable : function() {
this.mImmutable = true;
this.mImmutable = true;
},
clone: function() {
var a = new calAttendee();
var allProps = ["id", "commonName", "rsvp", "role", "participantStatus",
"userType"];
for (var i in allProps)
a[allProps[i]] = this[allProps[i]];
return a;
var a = new calAttendee();
var allProps = ["id", "commonName", "rsvp", "role", "participantStatus",
"userType"];
for (var i in allProps)
a[allProps[i]] = this[allProps[i]];
return a;
},

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

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
@ -170,6 +170,32 @@ calDateTime::Normalize()
return NS_OK;
}
NS_IMETHODIMP
calDateTime::AddDuration(calIDateTime *aDuration)
{
NS_ENSURE_ARG_POINTER(aDuration);
nsresult rv;
PRInt16 y, mo, d, h, m, s;
aDuration->GetYear(&y);
aDuration->GetMonth(&mo);
aDuration->GetDay(&d);
aDuration->GetHour(&h);
aDuration->GetMinute(&m);
aDuration->GetSecond(&s);
mYear += y;
mMonth += mo;
mDay += d;
mHour += h;
mMinute += m;
mSecond += s;
mLastModified = PR_Now();
return Normalize();
}
NS_IMETHODIMP
calDateTime::ToString(nsACString& aResult)
{
@ -196,7 +222,8 @@ calDateTime::SetTimeInTimezone(PRTime aTime, const char *aTimezone)
tt = sectime;
icalt = icaltime_from_timet(tt, 0);
icalt = icaltime_as_utc(icalt, aTimezone);
if (aTimezone && (strncmp(aTimezone, "UTC", 3) != 0))
icalt = icaltime_as_utc(icalt, aTimezone);
FromIcalTime(&icalt);
@ -304,7 +331,7 @@ calDateTime::FromIcalTime(icaltimetype *icalt)
}
/*
* nsIXPCScriptable ipl
* nsIXPCScriptable impl
*/
/* readonly attribute string className; */
@ -312,7 +339,7 @@ NS_IMETHODIMP
calDateTime::GetClassName(char * *aClassName)
{
NS_ENSURE_ARG_POINTER(aClassName);
*aClassName = (char *) nsMemory::Clone("calDateTime", 12);
*aClassName = (char *) nsMemory::Clone("mozStorageStatementRow", 23);
if (!*aClassName)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
@ -339,8 +366,14 @@ calDateTime::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
nsDependentString jsid((PRUnichar *)::JS_GetStringChars(JSVAL_TO_STRING(id)),
::JS_GetStringLength(JSVAL_TO_STRING(id)));
if (jsid.EqualsLiteral("jsDate")) {
JSObject *obj = ::js_NewDateObject(cx, mYear, mMonth, mDay,
mHour, mMinute, mSecond);
PRTime tmp, thousand;
jsdouble msec;
LL_I2L(thousand, 1000);
LL_DIV(tmp, mNativeTime, thousand);
LL_L2D(msec, tmp);
JSObject *obj = ::js_NewDateObjectMsec(cx, msec);
*vp = OBJECT_TO_JSVAL(obj);
*_retval = PR_TRUE;
return NS_OK;
@ -372,7 +405,7 @@ calDateTime::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
LL_I2L(thousands, 1000);
LL_MUL(utcTime, utcTime, thousands);
mIsUtc = PR_TRUE;
mIsUtc = PR_FALSE;
mTimezone.AssignLiteral("");
nsresult rv = SetNativeTime(utcTime);

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

@ -27,26 +27,27 @@ calEvent.prototype = {
clone: function () {
var m = new calEvent();
this.cloneItemBaseInto(m);
if (this.mStartDate)
m.mStartDate = this.mStartDate.clone();
if (this.mEndDate)
m.mEndDate = this.mEndDate.clone();
if (this.mStampDate)
m.mStampDate = this.mStampDate.clone();
m.mStartDate = this.mStartDate.clone();
m.mEndDate = this.mEndDate.clone();
m.mStampDate = this.mStampDate.clone();
return m;
},
makeImmutable: function () {
if (this.mStartDate)
this.mStartDate.makeImmutable();
if (this.mEndDate)
this.mEndDate.makeImmutable();
if (this.mStampDate)
this.mStampDate.makeImmutable();
this.mStartDate.makeImmutable();
this.mEndDate.makeImmutable();
this.mStampDate.makeImmutable();
this.makeItemBaseImmutable();
},
get duration() {
var dur = createCalDateTime();
dur.setTimeInTimezone (this.mEndDate.nativeTime - this.mStartDate.nativeTime, null);
return dur;
},

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

@ -72,26 +72,27 @@ calEvent.prototype = {
clone: function () {
var m = new calEvent();
this.cloneItemBaseInto(m);
if (this.mStartDate)
m.mStartDate = this.mStartDate.clone();
if (this.mEndDate)
m.mEndDate = this.mEndDate.clone();
if (this.mStampDate)
m.mStampDate = this.mStampDate.clone();
m.mStartDate = this.mStartDate.clone();
m.mEndDate = this.mEndDate.clone();
m.mStampDate = this.mStampDate.clone();
return m;
},
makeImmutable: function () {
if (this.mStartDate)
this.mStartDate.makeImmutable();
if (this.mEndDate)
this.mEndDate.makeImmutable();
if (this.mStampDate)
this.mStampDate.makeImmutable();
this.mStartDate.makeImmutable();
this.mEndDate.makeImmutable();
this.mStampDate.makeImmutable();
this.makeItemBaseImmutable();
},
get duration() {
var dur = createCalDateTime();
dur.setTimeInTimezone (this.mEndDate.nativeTime - this.mStartDate.nativeTime, null);
return dur;
},
#define MEMBER_ATTR(varname, initvalue, attrname) \
varname: initvalue, \
get attrname() { return this.varname; }, \

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

@ -169,12 +169,28 @@ calItemOccurrence.prototype = {
return this;
},
initialize: function (aItem, aStartDate, aEndDate) {
this.item = aItem;
this.occurrenceStartDate = aStartDate.clone();
this.occurrenceStartDate.makeImmutable();
this.occurrenceEndDate = aEndDate.clone();
this.occurrenceEndDate.makeImmutable();
},
item: null,
occurrenceStartDate: null,
occurrenceEndDate: null,
next: null,
previous: null
get next() {
if (this.item.recurrenceInfo)
return this.item.recurrenceInfo.getNextOccurrence(this.item, aEndDate);
return null;
},
get previous() {
if (this.item.recurrenceInfo)
return this.item.recurrenceInfo.getPreviousOccurrence(this.item, aStartDate);
return null;
}
};

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

@ -211,12 +211,28 @@ calItemOccurrence.prototype = {
return this;
},
initialize: function (aItem, aStartDate, aEndDate) {
this.item = aItem;
this.occurrenceStartDate = aStartDate.clone();
this.occurrenceStartDate.makeImmutable();
this.occurrenceEndDate = aEndDate.clone();
this.occurrenceEndDate.makeImmutable();
},
item: null,
occurrenceStartDate: null,
occurrenceEndDate: null,
next: null,
previous: null
get next() {
if (this.item.recurrenceInfo)
return this.item.recurrenceInfo.getNextOccurrence(this.item, aEndDate);
return null;
},
get previous() {
if (this.item.recurrenceInfo)
return this.item.recurrenceInfo.getPreviousOccurrence(this.item, aStartDate);
return null;
}
};
//

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

@ -52,7 +52,7 @@ const componentData =
{cid: Components.ID("{7af51168-6abe-4a31-984d-6f8a3989212d}"),
contractid: "@mozilla.org/calendar/todo;1",
script: null,
script: "calTodo.js",
constructor: "calTodo"},
{cid: Components.ID("{bad672b3-30b8-4ecd-8075-7153313d1f2c}"),

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

@ -0,0 +1,418 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Oracle Corporation code.
*
* The Initial Developer of the Original Code is
* Oracle Corporation
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
*
* 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
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "calRecurrenceInfo.h"
#include "calDateTime.h"
#include "calIItemBase.h"
#include "nsCOMArray.h"
extern "C" {
#include "ical.h"
}
NS_IMPL_ISUPPORTS1(calRecurrenceInfo, calIRecurrenceInfo)
calRecurrenceInfo::calRecurrenceInfo()
: mImmutable(PR_FALSE)
{
mIcalRecur = new struct icalrecurrencetype;
icalrecurrencetype_clear(mIcalRecur);
}
calRecurrenceInfo::~calRecurrenceInfo()
{
if (mIcalRecur)
delete mIcalRecur;
}
NS_IMETHODIMP
calRecurrenceInfo::GetIsMutable(PRBool *aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = !mImmutable;
return NS_OK;
}
NS_IMETHODIMP
calRecurrenceInfo::MakeImmutable()
{
if (mImmutable)
return NS_ERROR_FAILURE; // XXX another error code
mImmutable = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
calRecurrenceInfo::Clone(calIRecurrenceInfo **aResult)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute long recurType; */
NS_IMETHODIMP
calRecurrenceInfo::GetRecurType(PRInt32 *aRecurType)
{
NS_ENSURE_ARG_POINTER(aRecurType);
switch (mIcalRecur->freq) {
#define RECUR_HELPER(x) \
case ICAL_##x##_RECURRENCE: *aRecurType = CAL_RECUR_##x; break
RECUR_HELPER(SECONDLY);
RECUR_HELPER(MINUTELY);
RECUR_HELPER(HOURLY);
RECUR_HELPER(DAILY);
RECUR_HELPER(WEEKLY);
RECUR_HELPER(MONTHLY);
RECUR_HELPER(YEARLY);
#undef RECUR_HELPER
default:
*aRecurType = CAL_RECUR_INVALID;
}
return NS_OK;
}
NS_IMETHODIMP
calRecurrenceInfo::SetRecurType(PRInt32 aRecurType)
{
switch (aRecurType) {
#define RECUR_HELPER(x) \
case CAL_RECUR_##x: mIcalRecur->freq = ICAL_##x##_RECURRENCE; break
RECUR_HELPER(SECONDLY);
RECUR_HELPER(MINUTELY);
RECUR_HELPER(HOURLY);
RECUR_HELPER(DAILY);
RECUR_HELPER(WEEKLY);
RECUR_HELPER(MONTHLY);
RECUR_HELPER(YEARLY);
#undef RECUR_HELPER
case CAL_RECUR_INVALID:
mIcalRecur->freq = ICAL_NO_RECURRENCE;
break;
default:
return NS_ERROR_FAILURE;
}
return NS_OK;
}
/* attribute long recurCount; */
NS_IMETHODIMP
calRecurrenceInfo::GetRecurCount(PRInt32 *aRecurCount)
{
NS_ENSURE_ARG_POINTER(aRecurCount);
*aRecurCount = mIcalRecur->count;
return NS_OK;
}
NS_IMETHODIMP
calRecurrenceInfo::SetRecurCount(PRInt32 aRecurCount)
{
mIcalRecur->count = aRecurCount;
mIcalRecur->until = icaltime_null_time();
return NS_OK;
}
/* attribute calIDateTime recurEnd; */
NS_IMETHODIMP
calRecurrenceInfo::GetRecurEnd(calIDateTime * *aRecurEnd)
{
NS_ENSURE_ARG_POINTER(aRecurEnd);
calDateTime *cdt = new calDateTime(&mIcalRecur->until);
if (!cdt)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF (*aRecurEnd = cdt);
return NS_OK;
}
NS_IMETHODIMP
calRecurrenceInfo::SetRecurEnd(calIDateTime * aRecurEnd)
{
struct icaltimetype itt;
aRecurEnd->ToIcalTime(&itt);
mIcalRecur->until = itt;
mIcalRecur->count = 0;
return NS_OK;
}
/* attribute long interval; */
NS_IMETHODIMP
calRecurrenceInfo::GetInterval(PRInt32 *aInterval)
{
NS_ENSURE_ARG_POINTER(aInterval);
*aInterval = mIcalRecur->interval;
return NS_OK;
}
NS_IMETHODIMP
calRecurrenceInfo::SetInterval(PRInt32 aInterval)
{
mIcalRecur->interval = aInterval;
return NS_OK;
}
/* void getComponent (in long aComponentType, out unsigned long aCount, [array, size_is (aCount), retval] out long aValues); */
NS_IMETHODIMP
calRecurrenceInfo::GetComponent(PRInt32 aComponentType, PRUint32 *aCount, PRInt16 **aValues)
{
NS_ENSURE_ARG_POINTER(aCount);
NS_ENSURE_ARG_POINTER(aValues);
// This little ugly macro counts the number of real entries
// we have in the relevant array, and then clones it to the result.
#define HANDLE_COMPONENT(_comptype,_icalvar,_icalmax) \
if (aComponentType == _comptype) { \
int count; \
for (count = 0; count < _icalmax; count++) { \
if (mIcalRecur->_icalvar[count] == ICAL_RECURRENCE_ARRAY_MAX) \
break; \
} \
if (count) { \
*aValues = (PRInt16*) nsMemory::Clone(mIcalRecur->_icalvar, \
count * sizeof(PRInt16)); \
if (!*aValues) return NS_ERROR_OUT_OF_MEMORY; \
} else { \
*aValues = nsnull; \
} \
*aCount = count; \
}
HANDLE_COMPONENT(CAL_RECUR_BYSECOND, by_second, ICAL_BY_SECOND_SIZE)
else HANDLE_COMPONENT(CAL_RECUR_BYMINUTE, by_minute, ICAL_BY_MINUTE_SIZE)
else HANDLE_COMPONENT(CAL_RECUR_BYHOUR, by_hour, ICAL_BY_HOUR_SIZE)
else HANDLE_COMPONENT(CAL_RECUR_BYDAY, by_day, ICAL_BY_DAY_SIZE) // special
else HANDLE_COMPONENT(CAL_RECUR_BYMONTHDAY, by_month_day, ICAL_BY_MONTHDAY_SIZE)
else HANDLE_COMPONENT(CAL_RECUR_BYYEARDAY, by_year_day, ICAL_BY_YEARDAY_SIZE)
else HANDLE_COMPONENT(CAL_RECUR_BYWEEKNO, by_week_no, ICAL_BY_WEEKNO_SIZE)
else HANDLE_COMPONENT(CAL_RECUR_BYMONTH, by_month, ICAL_BY_MONTH_SIZE)
else HANDLE_COMPONENT(CAL_RECUR_BYSETPOS, by_set_pos, ICAL_BY_SETPOS_SIZE)
else {
// invalid component; XXX - error code
return NS_ERROR_FAILURE;
}
#undef HANDLE_COMPONENT
return NS_OK;
}
/* void setComponent (in long aComponentType, in unsigned long aCount, [array, size_is (aCount)] in long aValues); */
NS_IMETHODIMP
calRecurrenceInfo::SetComponent(PRInt32 aComponentType, PRUint32 aCount, PRInt16 *aValues)
{
NS_ENSURE_ARG_POINTER(aValues);
// Copy the passed-in array into the ical structure array
#define HANDLE_COMPONENT(_comptype,_icalvar,_icalmax) \
if (aComponentType == _comptype) { \
if (aCount > _icalmax) \
return NS_ERROR_FAILURE; \
memcpy(mIcalRecur->_icalvar, aValues, aCount * sizeof(PRInt16)); \
if (aCount < _icalmax) \
mIcalRecur->_icalvar[aCount] = ICAL_RECURRENCE_ARRAY_MAX; \
}
HANDLE_COMPONENT(CAL_RECUR_BYSECOND, by_second, ICAL_BY_SECOND_SIZE)
else HANDLE_COMPONENT(CAL_RECUR_BYMINUTE, by_minute, ICAL_BY_MINUTE_SIZE)
else HANDLE_COMPONENT(CAL_RECUR_BYHOUR, by_hour, ICAL_BY_HOUR_SIZE)
else HANDLE_COMPONENT(CAL_RECUR_BYDAY, by_day, ICAL_BY_DAY_SIZE) // special
else HANDLE_COMPONENT(CAL_RECUR_BYMONTHDAY, by_month_day, ICAL_BY_MONTHDAY_SIZE)
else HANDLE_COMPONENT(CAL_RECUR_BYYEARDAY, by_year_day, ICAL_BY_YEARDAY_SIZE)
else HANDLE_COMPONENT(CAL_RECUR_BYWEEKNO, by_week_no, ICAL_BY_WEEKNO_SIZE)
else HANDLE_COMPONENT(CAL_RECUR_BYMONTH, by_month, ICAL_BY_MONTH_SIZE)
else HANDLE_COMPONENT(CAL_RECUR_BYSETPOS, by_set_pos, ICAL_BY_SETPOS_SIZE)
else {
// invalid component; XXX - error code
return NS_ERROR_FAILURE;
}
#undef HANDLE_COMPONENT
return NS_OK;
}
/* void getExceptions (out unsigned long aCount, [array, size_is (aCount), retval] out calIDateTime aDates); */
NS_IMETHODIMP
calRecurrenceInfo::GetExceptions(PRUint32 *aCount, calIDateTime ***aDates)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void setExceptions (in unsigned long aCount, [array, size_is (aCount)] in calIDateTime aDates); */
NS_IMETHODIMP
calRecurrenceInfo::SetExceptions(PRUint32 aCount, calIDateTime **aDates)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* calIItemOccurrence getNextOccurrence (in calIItemBase aItem, in calIDateTime aStartTime); */
NS_IMETHODIMP
calRecurrenceInfo::GetNextOccurrence(calIItemBase *aItem, calIDateTime *aStartTime, calIItemOccurrence **_retval)
{
NS_ENSURE_ARG_POINTER(aStartTime);
NS_ENSURE_ARG_POINTER(_retval);
nsresult rv;
struct icaltimetype dtstart;
aStartTime->ToIcalTime(&dtstart);
icalrecur_iterator* recur_iter;
recur_iter = icalrecur_iterator_new (*mIcalRecur,
dtstart);
if (!recur_iter)
return NS_ERROR_OUT_OF_MEMORY;
struct icaltimetype next = icalrecur_iterator_next(recur_iter);
if (!icaltime_is_null_time(next)) {
calDateTime *cdt = new calDateTime(&next);
if (!cdt) {
rv = NS_ERROR_OUT_OF_MEMORY;
} else {
nsCOMPtr<calIItemOccurrence> item = do_CreateInstance("@mozilla.org/calendar/item-occurrence;1");
if (!item) {
rv = NS_ERROR_FAILURE;
} else {
rv = item->Initialize(aItem, cdt, cdt); // XXX Fixme duration!
if (NS_SUCCEEDED(rv))
NS_ADDREF (*_retval = item);
}
}
} else {
*_retval = nsnull;
rv = NS_OK;
}
icalrecur_iterator_free(recur_iter);
return rv;
}
/* void getOccurrencesBetween (in calIItemBase aItem, in calIDateTime aStartTime, in calIDateTime aEndTime, out unsigned long aCount, [array, size_is (aCount), retval] out calIItemOccurrence aItems); */
NS_IMETHODIMP
calRecurrenceInfo::GetOccurrencesBetween(calIItemBase *aItem,
calIDateTime *aStartTime,
calIDateTime *aEndTime,
PRUint32 *aCount, calIItemOccurrence ***aItems)
{
NS_ENSURE_ARG_POINTER(aStartTime);
NS_ENSURE_ARG_POINTER(aCount);
NS_ENSURE_ARG_POINTER(aItems);
// make sure there's sanity
//if (!aEndTime &&
nsCOMArray<calIItemOccurrence> items;
struct icaltimetype dtstart, dtend;
aStartTime->ToIcalTime(&dtstart);
if (aEndTime)
aEndTime->ToIcalTime(&dtend);
icalrecur_iterator* recur_iter;
recur_iter = icalrecur_iterator_new (*mIcalRecur,
dtstart);
if (!recur_iter)
return NS_ERROR_OUT_OF_MEMORY;
int count = 0;
struct icaltimetype next = icalrecur_iterator_next(recur_iter);
while (!icaltime_is_null_time(next)) {
if (*aCount && *aCount < count)
break;
if (aEndTime && icaltime_compare(next, dtend) > 0)
break;
nsresult rv = NS_OK;
calDateTime *cdt = new calDateTime(&next);
if (!cdt) {
rv = NS_ERROR_OUT_OF_MEMORY;
} else {
nsCOMPtr<calIItemOccurrence> item = do_CreateInstance("@mozilla.org/calendar/item-occurrence;1");
if (!item) {
rv = NS_ERROR_FAILURE;
} else {
rv = item->Initialize(aItem, cdt, cdt); // XXX Fixme duration!
if (NS_SUCCEEDED(rv)) {
items.AppendObject(item);
}
}
}
if (!NS_SUCCEEDED(rv)) {
icalrecur_iterator_free(recur_iter);
return rv;
}
next = icalrecur_iterator_next(recur_iter);
}
icalrecur_iterator_free(recur_iter);
*aCount = items.Count();
if (*aCount) {
calIItemOccurrence **itemArray = (calIItemOccurrence **) nsMemory::Alloc(sizeof(calIItemOccurrence*) * items.Count());
for (int i = 0; i < items.Count(); i++) {
itemArray[i] = items[i];
NS_ADDREF(itemArray[i]);
}
*aItems = itemArray;
} else {
*aItems = nsnull;
}
return NS_OK;
}
/* void getOccurrences (in calIItemBase aItem, in calIDateTime aStartTime, in long aMaxCount, out unsigned long aCount, [array,size_is(aCount),retval] out calIItemOccurrence aItems); */
NS_IMETHODIMP
calRecurrenceInfo::GetOccurrences(calIItemBase *aItem, calIDateTime *aStartTime, PRUint32 aMaxCount,
PRUint32 *aCount, calIItemOccurrence ***aItems)
{
return NS_OK;
}

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

@ -0,0 +1,63 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Oracle Corporation code.
*
* The Initial Developer of the Original Code is
* Oracle Corporation
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
*
* 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
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef CALRECURRENCEINFO_H_
#define CALRECURRENCEINFO_H_
#include "calIRecurrenceInfo.h"
struct icalrecurrencetype;
class calRecurrenceInfo : public calIRecurrenceInfo
{
public:
calRecurrenceInfo();
~calRecurrenceInfo();
// nsISupports interface
NS_DECL_ISUPPORTS
// calIRecurrenceInfo interface
NS_DECL_CALIRECURRENCEINFO
protected:
PRBool mImmutable;
struct icalrecurrencetype *mIcalRecur;
};
#endif /* CALRECURRENCEINFO_H_ */

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

@ -0,0 +1,62 @@
/* GENERATED FILE; DO NOT EDIT. SOURCE IS calTodo.js.pre */
function calTodo() {
this.wrappedJSObject = this;
this.initItemBase();
this.initTodo();
}
var calItemBase;
calTodo.prototype = {
__proto__: calItemBase ? (new calItemBase()) : {},
QueryInterface: function (aIID) {
if (!aIID.equals(Components.interfaces.nsISupports) &&
!aIID.equals(Components.interfaces.calIItemBase) &&
!aIID.equals(Components.interfaces.calITodo))
{
throw Components.results.NS_ERROR_NO_INTERFACE;
}
return this;
},
initTodo: function () {
this.mEntryTime = createCalDateTime();
this.mDueDate = createCalDateTime();
this.mCompletedDate = createCalDateTime();
this.mPercentComplete = 0;
},
clone: function () {
var m = new calEvent();
this.cloneItemBaseInto(m);
m.mEntryDate = this.mEntryDate.clone();
m.mDueDate = this.mDueDate.clone();
m.mCompletedDate = this.mCompletedDate.clone();
m.mPercentComplete = this.mPercentComplete;
return m;
},
makeImmutable: function () {
this.mEntryDate.makeImmutable();
this.mDueDate.makeImmutable();
this.mCompletedDate.makeImmutable();
this.makeItemBaseImmutable();
},
mEntryDate: null, get entryDate() { return this.mEntryDate; }, set entryDate(v) { if (this.mImmutable) throw Components.results.NS_ERROR_FAILURE; else this.mEntryDate = v; },
mEndDate: null, get endDate() { return this.mEndDate; }, set endDate(v) { if (this.mImmutable) throw Components.results.NS_ERROR_FAILURE; else this.mEndDate = v; },
mCompletedDate: null, get completedDate() { return this.mCompletedDate; }, set completedDate(v) { if (this.mImmutable) throw Components.results.NS_ERROR_FAILURE; else this.mCompletedDate = v; },
mPercentComplete: 0, get percentComplete() { return this.mPercentComplete; }, set percentComplete(v) { if (this.mImmutable) throw Components.results.NS_ERROR_FAILURE; else this.mPercentComplete = v; },
};

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

@ -0,0 +1,107 @@
/* -*- Mode: javascript; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Oracle Corporation code.
*
* The Initial Developer of the Original Code is
* Oracle Corporation
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
*
* 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
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
//
// calTodo.js
//
//
// constructor
//
function calTodo() {
this.wrappedJSObject = this;
this.initItemBase();
this.initTodo();
}
// var trickery to suppress lib-as-component errors from loader
var calItemBase;
calTodo.prototype = {
__proto__: calItemBase ? (new calItemBase()) : {},
QueryInterface: function (aIID) {
if (!aIID.equals(Components.interfaces.nsISupports) &&
!aIID.equals(Components.interfaces.calIItemBase) &&
!aIID.equals(Components.interfaces.calITodo))
{
throw Components.results.NS_ERROR_NO_INTERFACE;
}
return this;
},
initTodo: function () {
this.mEntryTime = createCalDateTime();
this.mDueDate = createCalDateTime();
this.mCompletedDate = createCalDateTime();
this.mPercentComplete = 0;
},
clone: function () {
var m = new calEvent();
this.cloneItemBaseInto(m);
m.mEntryDate = this.mEntryDate.clone();
m.mDueDate = this.mDueDate.clone();
m.mCompletedDate = this.mCompletedDate.clone();
m.mPercentComplete = this.mPercentComplete;
return m;
},
makeImmutable: function () {
this.mEntryDate.makeImmutable();
this.mDueDate.makeImmutable();
this.mCompletedDate.makeImmutable();
this.makeItemBaseImmutable();
},
#define MEMBER_ATTR(varname, initvalue, attrname) \
varname: initvalue, \
get attrname() { return this.varname; }, \
set attrname(v) { if (this.mImmutable) throw Components.results.NS_ERROR_FAILURE; else this.varname = v; }
MEMBER_ATTR(mEntryDate, null, entryDate),
MEMBER_ATTR(mEndDate, null, endDate),
MEMBER_ATTR(mCompletedDate, null, completedDate),
MEMBER_ATTR(mPercentComplete, 0, percentComplete),
#undef MEMBER_ATTR
};