Continuing calendar interface work. No more Mutable interfaces; there's now a mutability bit on datetime/event/etc. DateTime is implemented using libical, ItemBase/Event/Todo/etc. are in JS.

This commit is contained in:
vladimir%pobox.com 2004-11-16 00:24:17 +00:00
Родитель 7d9bbfb5fa
Коммит 776baefebf
23 изменённых файлов: 679 добавлений и 329 удалений

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

@ -45,6 +45,6 @@ include $(DEPTH)/config/autoconf.mk
MODULE = calbase
MODULE_NAME = calBaseModule
SUBDIRS = public src
SUBDIRS = public src build
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,67 @@
#
# ***** 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 of 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 *****
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = calbasecomps
LIBRARY_NAME = calbasecomps
SHORT_LIBNAME = calbscmp
EXPORT_LIBRARY = 1
IS_COMPONENT = 1
MODULE_NAME = calBaseModule
REQUIRES = \
xpcom \
string \
ical \
calbase
EXPORTS = calBaseCID.h
CPPSRCS = calBaseModule.cpp \
$(NULL)
LOCAL_INCLUDES = \
-I$(srcdir)/../src
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,59 @@
/* -*- Mode: C++; tab-width: 4; 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 CALBASECID_H_
#define CALBASECID_H_
/* C++ */
#define CAL_DATETIME_CID \
{ 0x85475b45, 0x110a, 0x443c, { 0xaf, 0x3f, 0xb6, 0x63, 0x98, 0xa5, 0xa7, 0xcd } }
#define CAL_DATETIME_CONTRACTID \
"@mozilla.org/calendar/datetime;1"
/* JS -- Update these from calItemModule.js */
#define CAL_EVENT_CID \
{ 0x974339d5, 0xab86, 0x4491, { 0xaa, 0xaf, 0x2b, 0x2c, 0xa1, 0x77, 0xc1, 0x2b } }
#define CAL_EVENT_CONTRACTID \
"@mozilla.org/calendar/event;1"
#define CAL_TODO_CID \
{ 0x7af51168, 0x6abe, 0x4a31, { 0x98, 0x4d, 0x6f, 0x8a, 0x39, 0x89, 0x21, 0x2d } }
#define CAL_TODO_CONTRACTID \
"@mozilla.org/calendar/todo;1"
#endif /* CALBASECID_H_ */

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

@ -0,0 +1,55 @@
/* -*- Mode: C++; tab-width: 4; 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 "nsIGenericFactory.h"
#include "calDateTime.h"
#include "calBaseCID.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(calDateTime)
static const nsModuleComponentInfo components[] =
{
{ "Calendar DateTime Object",
CAL_DATETIME_CID,
CAL_DATETIME_CONTRACTID,
calDateTimeConstructor }
};
NS_IMPL_NSGETMODULE(calBaseModule, components)

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

@ -41,91 +41,29 @@
[scriptable, uuid(5678d4a3-2543-4ece-afbb-079292f2866e)]
interface calIDateTime : nsISupports
{
// this thing's base PRTime value, in UTC
readonly attribute PRTime utcTime;
// returns true if this thing is able to be modified;
// if the item is not mutable, attempts to modify
// any data will throw CAL_ERROR_ITEM_IS_IMMUTABLE
readonly attribute boolean isMutable;
//
// These are all in the currently-specified
// timezone
//
// makes this item immutable
void makeImmutable();
// Year, fully exploded (e.g. "1989", "2004")
readonly attribute short year;
// Month, 0-11
readonly attribute short month;
// Day, 1 through whatever
readonly attribute short day;
// Hour, 0-23
readonly attribute short hour;
// Minute, 0-59
readonly attribute short minute;
// Second, 0-59
readonly attribute short second;
// Microsecond, 0-99999
readonly attribute long microsecond;
// Day of the week, 0-6, Sunday = 0
readonly attribute short weekday;
// Day of the year, 0-365/366
readonly attribute short yearday;
// timezone; if null, it is GMT/UTC
// setting this changes the value of the year/month/day/etc. fields
// to be the new value of utcTime in that timezone
readonly attribute string timezone;
// this thing's PRTime value in the local timezone
readonly attribute PRTime localTime;
// clone always returns a mutable event
calIDateTime clone();
// true if this thing is set/valid
readonly attribute boolean valid;
//
// Methods
//
// return a string representation of this date/time
// in the current locale
AUTF8String toString();
// this thing's base PRTime value, either
// as UTC or as local. Setting this
// will explode the PRTime value to
// year/etc.
attribute PRTime nativeTime;
//
// Some helper getters for calculating useful ranges
//
// the start/end of the current object's week
readonly attribute calIDateTime startOfWeek;
readonly attribute calIDateTime endOfWeek;
// the start/end of the current object's month
readonly attribute calIDateTime startOfMonth;
readonly attribute calIDateTime endOfMonth;
// the start/end of the current object's year
readonly attribute calIDateTime startOfYear;
readonly attribute calIDateTime endOfYear;
};
//
// mutable version of the above
//
[scriptable, uuid(188729d7-77a3-43c9-b878-e268c786a3c4)]
interface calIMutableDateTime : nsISupports
{
// this thing's base PRTime value, in UTC
attribute PRTime utcTime;
//
// These are all in the currently-specified
// timezone
// Date/Time components. Setting any of these causes the DateTime
// to become invalid, until normalize() is called.
//
// Year, fully exploded (e.g. "1989", "2004")
@ -134,7 +72,7 @@ interface calIMutableDateTime : nsISupports
// Month, 0-11
attribute short month;
// Day, 1 through whatever
// Day, 1 through whatever XXX - does libical want 1.. or 0..?
attribute short day;
// Hour, 0-23
@ -146,8 +84,18 @@ interface calIMutableDateTime : nsISupports
// Second, 0-59
attribute short second;
// Microsecond, 0-99999
attribute long microsecond;
// whether this thing indicates a time in UTC, or in the local time
// zone
attribute PRBool isUtc;
// an associated timezone that's the preferred way of representing
// this object. If this is null, then there is no preferred
// timezone, and UTC or localtime is assumed (based on isUtc).
attribute string timezone;
//
// computed values
//
// Day of the week, 0-6, Sunday = 0
readonly attribute short weekday;
@ -155,35 +103,24 @@ interface calIMutableDateTime : nsISupports
// Day of the year, 0-365/366
readonly attribute short yearday;
// timezone; if null, it is GMT/UTC
// setting this changes the value of the year/month/day/etc. fields
// to be the new value of utcTime in that timezone
attribute string timezone;
// this thing's PRTime value in the local timezone
attribute PRTime localTime;
// true if this thing is set/valid
readonly attribute boolean valid;
//
// Methods
//
// reset this thing (set valid to false, everything else to 0)
void clear();
// adjust this time to be + the specified values (may be negative)
void modifyTime(in short years,
in short months,
in short days,
in short hours,
in short minutes);
// return a string representation of this date/time
// in the current locale
AUTF8String toString();
// normalize and validate the expanded-out values
void normalize();
// sets this thing to a time in the given timezone
void setTimeInTimezone (in PRTime aTime, in string aTimezone);
// gets a new calIDateTime object representing this
// item in the given timezone
calIDateTime getInTimezone (in string aTimezone);
//
// Some helper getters for calculating useful ranges
//

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

@ -53,24 +53,10 @@ interface calIEvent : calIItemBase
// these attributes are marked readonly, as the calIDates are owned
// by the event; however, the actual caIDate objects are not read
// only and are intended to be manipulated to adjust dates.
readonly attribute calIDateTime startDate;
readonly attribute calIDateTime endDate;
readonly attribute calIDateTime stampDate; // ??
attribute calIDateTime startDate;
attribute calIDateTime endDate;
attribute calIDateTime stampDate; // ??
// all day event?
readonly attribute boolean isAllDay;
};
//
// calIMutableEvent
//
[scriptable, uuid(383973d2-88c5-4bf1-a5ff-2d879a1b8675)]
interface calIMutableEvent : calIItemBase
{
readonly attribute calIMutableDateTime startDate;
readonly attribute calIMutableDateTime endDate;
readonly attribute calIMutableDateTime stampDate;
attribute boolean isAllDay;
};

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

@ -63,10 +63,16 @@ interface calIMutableRecurrenceInfo;
[scriptable, uuid(096b8cc5-113c-40fb-bc52-d64e3992980c)]
interface calIItemBase : nsISupports
{
//
// Return a mutable version of this item
//
calIMutableItemBase getMutable();
// returns true if this thing is able to be modified;
// if the item is not mutable, attempts to modify
// any data will throw CAL_ERROR_ITEM_IS_IMMUTABLE
readonly attribute boolean isMutable;
// makes this item immutable
void makeImmutable();
// clone always returns a mutable event
calIItemBase clone();
//
// the generation number of this item; 0 means
@ -87,85 +93,7 @@ interface calIItemBase : nsISupports
readonly attribute calIDateTime creationDate;
// last time any attribute was modified on this item, in UTC
readonly attribute PRTime lastModifiedTime;
// the calICalendar to which this event belongs
readonly attribute calICalendar parent;
// the ID of this event
readonly attribute AUTF8String id;
// event title
readonly attribute AUTF8String title;
// event priority
readonly attribute short priority;
readonly attribute boolean isPrivate;
// event/status of the event (see consts above)
readonly attribute long method;
readonly attribute long status;
// ical interop; writing this means parsing
// the ical string into this event
readonly attribute AUTF8String icalString;
//
// alarms
//
readonly attribute boolean hasAlarm;
readonly attribute calIDateTime alarmTime;
//
// recurrence
//
readonly attribute calIRecurrenceInfo recurrenceInfo;
// attachments
// array of nsIMsgAttachment
readonly attribute nsIArray attachments;
// contacts
// array of nsIAbCard
readonly attribute nsIArray contacts;
//
// other properties come in through a property bag
//
// 'description' - description (string)
// 'location' - location (string)
// 'categories' - categories (string)
// 'syncId' - sync id (string)
// 'inviteEmailAddress' - string
// alarmLength/alarmUnits/alarmEmailAddress/lastAlarmAck
// recurInterval/recurCount/recurWeekdays/recurWeeknumber
// Ideally, /all/ of the properties on the event should
// be available via the property bag. (And maybe the
// nsIItemBase impl should be QI'able to
// nsIWritablePropertyBag also)
readonly attribute nsIPropertyBag properties;
};
//
// calIMutableItemBase
//
// Mutable version of the above
//
[scriptable, uuid(56ca7d46-2412-466f-9dea-fb141ae95de0)]
interface calIMutableItemBase : nsISupports
{
// the base item that this is a mutable item of
readonly attribute calIItemBase baseItem;
readonly attribute long generation;
// the time when this item was created
attribute calIMutableDateTime creationDate;
// last time any attribute was modified on this item, in UTC
readonly attribute PRTime lastModifiedTime;
attribute PRTime lastModifiedTime;
// the calICalendar to which this event belongs
attribute calICalendar parent;
@ -192,20 +120,22 @@ interface calIMutableItemBase : nsISupports
// alarms
//
attribute boolean hasAlarm;
attribute calIMutableDateTime alarmTime;
attribute calIDateTime alarmTime;
//
// recurrence
//
readonly attribute calIMutableRecurrenceInfo recurrenceInfo;
readonly attribute calIRecurrenceInfo recurrenceInfo;
// attachments
// array of nsIMsgAttachment
readonly attribute nsIMutableArray attachments;
// if this item is mutable, the returned array will be a nsIMutableArray
readonly attribute nsIArray attachments;
// contacts
// array of nsIAbCard
readonly attribute nsIMutableArray contacts;
// if this item is mutable, the returned array will be a nsIMutableArray
readonly attribute nsIArray contacts;
//
// other properties come in through a property bag
@ -224,7 +154,8 @@ interface calIMutableItemBase : nsISupports
// nsIItemBase impl should be QI'able to
// nsIWritablePropertyBag also)
readonly attribute nsIWritablePropertyBag properties;
// if this item is mutable, the returned bag will be a nsIWritablePropertyBag
readonly attribute nsIPropertyBag properties;
};
//

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

@ -47,6 +47,18 @@ interface calIItemOccurrence;
[scriptable, uuid(a6a458cf-052c-45d1-bee7-b700ad21109a)]
interface calIRecurrenceInfo : nsISupports
{
// returns true if this thing is able to be modified;
// if the item is not mutable, attempts to modify
// any data will throw CAL_ERROR_ITEM_IS_IMMUTABLE
readonly attribute boolean isMutable;
// makes this item immutable
void makeImmutable();
// clone always returns a mutable event
calIItemBase clone();
//
//
// recurrence
//
@ -57,10 +69,10 @@ interface calIRecurrenceInfo : nsISupports
const long CAL_ITEM_RECUR_TYPE_MONTHLY = 4;
const long CAL_ITEM_RECUR_TYPE_YEARLY = 5;
readonly attribute long recurType;
readonly attribute calIDateTime recurEnd; // if null, then forever
attribute long recurType;
attribute calIDateTime recurEnd; // if null, then forever
// array of calIDateTime
readonly attribute nsIArray recurrenceExceptions;
attribute nsIArray recurrenceExceptions;
// rest of recurrence in properties (?)
// return the next display item for this event,
@ -77,26 +89,3 @@ interface calIRecurrenceInfo : nsISupports
in calIDateTime aEndTime);
};
[scriptable, uuid(ee300ea5-9bfa-4566-9ae1-23adf79088a8)]
interface calIMutableRecurrenceInfo : nsISupports
{
attribute long recurType;
attribute calIDateTime recurEnd; // if null, then forever
// array of calIDateTime
readonly attribute nsIMutableArray recurrenceExceptions;
// rest of recurrence in properties (?)
// return the next display item for this 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);
// return array of calIDisplayItems, representing all
// occurances of this event between start and end.
nsIArray getAllOccurrences (in calIDateTime aStartTime,
in calIDateTime aEndTime);
};

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

@ -54,18 +54,6 @@ interface calITodo : calIItemBase
readonly attribute calIDateTime entryTime;
readonly attribute calIDateTime dueDate;
readonly attribute calIDateTime completedDate;
readonly attribute short percentComplete;
};
//
// calIMutableTodo
//
[scriptable, uuid(d4e00ebe-e9cd-41ee-bd4f-8015071adb97)]
interface calIMutableTodo : calIItemBase
{
readonly attribute calIMutableDateTime entryTime;
readonly attribute calIMutableDateTime dueDate;
readonly attribute calIMutableDateTime completedDate;
attribute short percentComplete;
};

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

@ -49,12 +49,18 @@ MODULE_NAME = calBaseModule
FORCE_STATIC_LIB = 1
GRE_MODULE = 1
#REQUIRES = xpcom \
# string \
REQUIRES = xpcom \
string \
ical \
$(NULL)
# storage \
# sqlite3 \
# $(NULL)
CPPSRCS = \
calDateTime.cpp
#CPPSRCS = \
# calItemBase.cpp \
# calEvent.cpp \

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

@ -39,6 +39,10 @@
#ifndef CALATTRIBUTEHELPERS_H_
#define CALATTRIBUTEHELPERS_H_
#ifndef UPDATE_LAST_MODIFIED
#define UPDATE_LAST_MODIFIED /**/
#endif
/**
** A few helpers for declaring simple attribute getters and setters in
** calItemBase derivatives
@ -55,7 +59,9 @@ cname::Get##name (mtype &_retval) { \
#define CAL_STRINGTYPE_ATTR_SETTER(cname,mtype,name) \
NS_IMETHODIMP \
cname::Set##name (const mtype &aValue) { \
if (mImmutable) return NS_ERROR_FAILURE; \
m##name.Assign(aValue); \
UPDATE_LAST_MODIFIED; \
return NS_OK; \
}
@ -74,9 +80,10 @@ cname::Get##name (mtype *_retval) { \
#define CAL_VALUETYPE_ATTR_SETTER(cname,mtype,name) \
NS_IMETHODIMP \
cname::Set##name (mtype aValue) { \
if (mImmutable) return NS_ERROR_FAILURE; \
if (m##name != aValue) { \
m##name = aValue; \
mLastModifiedTime = PR_Now(); \
UPDATE_LAST_MODIFIED; \
} \
return NS_OK; \
}
@ -96,9 +103,10 @@ cname::Get##name (mtype **_retval) { \
#define CAL_ISUPPORTS_ATTR_SETTER(cname,mtype,name) \
NS_IMETHODIMP \
cname::Set##name (mtype *aValue) { \
if (mImmutable) return NS_ERROR_FAILURE; \
if (m##name != aValue) { \
m##name = aValue; \
mLastModifiedTime = PR_Now(); \
UPDATE_LAST_MODIFIED; \
} \
return NS_OK; \
}

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

@ -0,0 +1,266 @@
/* -*- Mode: C++; tab-width: 4; 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 "calDateTime.h"
#include "calAttributeHelpers.h"
extern "C" {
#include "ical.h"
}
NS_IMPL_ISUPPORTS1(calDateTime, calIDateTime)
calDateTime::calDateTime()
: mValid(PR_FALSE)
{
}
calDateTime::calDateTime(struct icaltimetype *atimeptr)
{
fromIcalTime(atimeptr);
mValid = PR_TRUE;
}
NS_IMETHODIMP
calDateTime::GetIsMutable(PRBool *aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = !mImmutable;
return NS_OK;
}
NS_IMETHODIMP
calDateTime::MakeImmutable()
{
if (mImmutable)
return NS_ERROR_FAILURE; // XXX another error code
mImmutable = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
calDateTime::Clone(calIDateTime **aResult)
{
calDateTime *cdt = new calDateTime();
if (!cdt)
return NS_ERROR_OUT_OF_MEMORY;
// bitwise copy everything
cdt->mValid = mValid;
cdt->mNativeTime = mNativeTime;
cdt->mYear = mYear;
cdt->mMonth = mMonth;
cdt->mDay = mDay;
cdt->mHour = mHour;
cdt->mMinute = mMinute;
cdt->mSecond = mSecond;
cdt->mIsUtc = mIsUtc;
cdt->mWeekday = mWeekday;
cdt->mYearday = mYearday;
cdt->mLastModified = PR_Now();
// copies are always mutable
cdt->mImmutable = PR_FALSE;
NS_ADDREF(*aResult = cdt);
return NS_OK;
}
CAL_VALUETYPE_ATTR_GETTER(calDateTime, PRBool, Valid)
CAL_VALUETYPE_ATTR(calDateTime, PRTime, NativeTime)
CAL_VALUETYPE_ATTR(calDateTime, PRInt16, Year)
CAL_VALUETYPE_ATTR(calDateTime, PRInt16, Month)
CAL_VALUETYPE_ATTR(calDateTime, PRInt16, Day)
CAL_VALUETYPE_ATTR(calDateTime, PRInt16, Hour)
CAL_VALUETYPE_ATTR(calDateTime, PRInt16, Minute)
CAL_VALUETYPE_ATTR(calDateTime, PRInt16, Second)
CAL_VALUETYPE_ATTR(calDateTime, PRBool, IsUtc)
CAL_VALUETYPE_ATTR_GETTER(calDateTime, PRInt16, Weekday)
CAL_VALUETYPE_ATTR_GETTER(calDateTime, PRInt16, Yearday)
NS_IMETHODIMP
calDateTime::Normalize()
{
struct icaltimetype icalt;
toIcalTime(&icalt);
icalt = icaltime_normalize(icalt);
fromIcalTime(&icalt);
mValid = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
calDateTime::ToString(nsACString& aResult)
{
aResult.Assign("FOO");
return NS_OK;
}
NS_IMETHODIMP
calDateTime::SetTimeInTimezone(PRTime aTime, const char *aTimezone)
{
struct icaltimetype icalt;
time_t tt;
PRInt64 temp, million;
LL_I2L(million, PR_USEC_PER_SEC);
LL_DIV(temp, aTime, million);
PRInt32 sectime;
LL_L2I(sectime, temp);
tt = sectime;
icalt = icaltime_from_timet(tt, 0);
icalt = icaltime_as_utc(icalt, aTimezone);
fromIcalTime(&icalt);
return NS_OK;
}
NS_IMETHODIMP
calDateTime::GetInTimezone(const char *aTimezone, calIDateTime **aResult)
{
struct icaltimetype icalt;
toIcalTime(&icalt);
icalt = icaltime_as_zone(icalt, aTimezone);
calDateTime *cdt = new calDateTime(&icalt);
if (!cdt)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF (*aResult = cdt);
return NS_OK;
}
NS_IMETHODIMP
calDateTime::GetStartOfWeek(calIDateTime **aResult)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
calDateTime::GetEndOfWeek(calIDateTime **aResult)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
calDateTime::GetStartOfMonth(calIDateTime **aResult)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
calDateTime::GetEndOfMonth(calIDateTime **aResult)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
calDateTime::GetStartOfYear(calIDateTime **aResult)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
calDateTime::GetEndOfYear(calIDateTime **aResult)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/**
** utility/protected methods
**/
void
calDateTime::toIcalTime(icaltimetype *icalt)
{
icalt->year = mYear;
icalt->month = mMonth;
icalt->day = mDay;
icalt->hour = mHour;
icalt->minute = mMinute;
icalt->second = mSecond;
if (mIsUtc)
icalt->is_utc = 1;
else
icalt->is_utc = 0;
}
void
calDateTime::fromIcalTime(icaltimetype *icalt)
{
mYear = icalt->year;
mMonth = icalt->month;
mDay = icalt->day;
mHour = icalt->hour;
mMinute = icalt->minute;
mSecond = icalt->second;
if (icalt->is_utc)
mIsUtc = PR_TRUE;
else
mIsUtc = PR_FALSE;
// reconstruct nativetime
time_t tt = icaltime_as_timet(*icalt);
PRInt64 temp, million;
LL_I2L(million, PR_USEC_PER_SEC);
LL_I2L(temp, tt);
LL_MUL(temp, temp, million);
mNativeTime = temp;
// reconstruct weekday/yearday
mWeekday = icaltime_day_of_week(*icalt);
mYearday = icaltime_day_of_year(*icalt);
}

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

@ -0,0 +1,86 @@
/* -*- Mode: C++; tab-width: 4; 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 CALDATETIME_H_
#define CALDATETIME_H_
#include "nsString.h"
#include "calIDateTime.h"
struct icaltimetype;
class calDateTime : public calIDateTime
{
public:
calDateTime ();
calDateTime (struct icaltimetype *timeptr);
// nsISupports interface
NS_DECL_ISUPPORTS
// calIDateTime interface
NS_DECL_CALIDATETIME
protected:
PRBool mImmutable;
PRBool mValid;
PRTime mNativeTime;
PRInt16 mYear;
PRInt16 mMonth;
PRInt16 mDay;
PRInt16 mHour;
PRInt16 mMinute;
PRInt16 mSecond;
PRBool mIsUtc;
PRInt16 mWeekday;
PRInt16 mYearday;
void toIcalTime(icaltimetype *icalt);
void fromIcalTime(icaltimetype *icalt);
PRTime mLastModified;
};
#endif /* CALDATETIME_H_ */

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

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

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

@ -61,9 +61,20 @@ calEvent.prototype = {
return this;
},
clone: function () {
var m = new calEvent();
this.cloneItemBaseInto(m);
m.mStartDate = this.mStartDate.clone();
m.mEndDate = this.mEndDate.clone();
m.mStampDate = this.mStampDate.clone();
return m;
},
#define MEMBER_ATTR(varname, initvalue, attrname) \
varname: initvalue, \
get attrname() { return this.varname; }
get attrname() { return this.varname; } \
set attrname(v) { if (this.mImmutable) throw Components.results.NS_ERROR_FAILURE; else this.varname = v; }
MEMBER_ATTR(mStartDate, null, startDate),
MEMBER_ATTR(mEndDate, null, endDate),

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

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

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

@ -44,7 +44,7 @@ calItemBase.prototype = {
mLastModifiedTime: 0, get lastModifiedTime() { return this.mLastModifiedTime; },
mParent: null, get parent() { return this.mParent; },
mId: null, get id() { return this.mId; },
mTitle: null, get title() { return this.mTitle; },
mTitle: "", get title() { return this.mTitle; },
mPriority: 0, get priority() { return this.mPriority; },
mIsPrivate: 0, get isPrivate() { return this.mIsPrivate; },
mMethod: 0, get method() { return this.mMethod; },

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

@ -53,10 +53,25 @@ calItemBase.prototype = {
return this;
},
getMutable: function () {
var m = new calMutableItemBase();
mImmutable: false,
get isMutable() { return this. mImmutable; },
makeImmutable: function() {
if (this.mImmutable)
throw Components.results.NS_ERROR_FAILURE;
// make all our components immutable
this.mCreationDate.makeImmutable();
this.mRecurrenceInfo.makeImmutable();
this.mAlarmTime.makeImmutable();
this.mImmutable = true;
}
// for subclasses to use; copies the ItemBase's values
// into m
cloneItemBaseInto: function (m) {
m.mImmutable = false;
m.mGeneration = this.mGeneration;
m.mCreationDate = this.mCreationDate.getMutable();
m.mLastModifiedTime = this.mLastModifiedTime;
m.mParent = this.mParent;
m.mId = this.mId;
@ -66,8 +81,10 @@ calItemBase.prototype = {
m.mMethod = this.mMethod;
m.mStatus = this.mStatus;
m.mHasAlarm = this.mHasAlarm;
m.mAlarmTime = this.mAlarmTime.getMutable();
m.mRecurrenceInfo = this.mRecurrenceInfo.getMutable();
m.mRecurrenceInfo = this.mRecurrenceInfo.clone();
m.mCreationDate = this.mCreationDate.clone();
m.mAlarmTime = this.mAlarmTime.clone();
// these need fixing
m.mAttachments = this.mAttachments;
@ -79,7 +96,8 @@ calItemBase.prototype = {
#define MEMBER_ATTR(varname, initvalue, attrname) \
varname: initvalue, \
get attrname() { return this.varname; }
get attrname() { return this.varname; } \
set attrname(v) { if (this.mImmutable) throw Components.results.NS_ERROR_FAILURE; else this.varname = v; }
MEMBER_ATTR(mGeneration, 0, generation),
MEMBER_ATTR(mCreationDate, null, creationDate),
@ -102,12 +120,14 @@ calItemBase.prototype = {
#undef MEMBER_ATTR
};
function calMutableItemBase() { }
function calItemOccurrence () {
this.wrappedJSObject = this;
}
calMutableItemBase.prototype = {
calItemOccurrence.prototype = {
QueryInterface: function (aIID) {
if (!aIID.equals(Components.interfaces.nsISupports) &&
!aIID.equals(Components.interfaces.calIMutableItemBase))
!aIID.equals(Components.interfaces.calIItemOccurrence))
{
throw Components.results.NS_ERROR_NO_INTERFACE;
}
@ -115,28 +135,10 @@ calMutableItemBase.prototype = {
return this;
},
#define MEMBER_ATTR(varname, initvalue, attrname) \
varname: initvalue, \
get attrname() { return this.varname; }, \
set attrname(v) { this.varname = v; }
item: null,
occurrenceStartDate: null,
occurrenceEndDate: null,
MEMBER_ATTR(mGeneration, 0, generation),
MEMBER_ATTR(mCreationDate, null, creationDate),
MEMBER_ATTR(mLastModifiedTime, 0, lastModifiedTime),
MEMBER_ATTR(mParent, null, parent),
MEMBER_ATTR(mId, null, id),
MEMBER_ATTR(mTitle, null, title),
MEMBER_ATTR(mPriority, 0, priority),
MEMBER_ATTR(mIsPrivate, 0, isPrivate),
MEMBER_ATTR(mMethod, 0, method),
MEMBER_ATTR(mStatus, 0, status),
MEMBER_ATTR(mIcalString, "", icalString),
MEMBER_ATTR(mHasAlarm, false, hasAlarm),
MEMBER_ATTR(mAlarmTime, null, alarmTime),
MEMBER_ATTR(mRecurrenceInfo, null, recurrenceInfo),
MEMBER_ATTR(mAttachments, null, attachments),
MEMBER_ATTR(mContacts, null, contacts),
MEMBER_ATTR(mProperties, null, properties)
#undef MEMBER_ATTR
next: null,
previous: null
};

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

@ -37,18 +37,13 @@
* ***** END LICENSE BLOCK ***** */
var calItemModule = {
/* Update these in calBaseCID.h */
mEventCID: Components.ID("{974339d5-ab86-4491-aaaf-2b2ca177c12b}"),
mEventContractId: "@mozilla.org/calendar/event;1",
mMutableEventCID: Components.ID("{943c81f5-da08-441e-918e-266f17866180}"),
mMutableEventContractId: "@mozilla.org/calendar/mutableevent;1",
mTodoCID: Components.ID("{7af51168-6abe-4a31-984d-6f8a3989212d}"),
mTodoContractId: "@mozilla.org/calendar/todo;1",
mMutableTodoCID: Components.ID("{46f8bfd1-84e9-4c57-9c5c-e8c2a8386e73}"),
mMutableTodoContractId: "@mozilla.org/calendar/mutabletodo;1",
mScriptsLoaded: false,
loadScripts: function () {
if (this.mScriptsLoaded)
@ -85,8 +80,8 @@ var calItemModule = {
registerSelf: function (compMgr, fileSpec, location, type) {
compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
var cids = [ this.mEventCID, this.mMutableEventCID, this.mTodoCID, this.mMutableTodoCID ];
var contractids = [ this.mEventContractId, this.mMutableEventContractId, this.mTodoContractId, this.mMutableTodoContractId ];
var cids = [ this.mEventCID, this.mTodoCID ];
var contractids = [ this.mEventContractId, this.mTodoContractId ];
for (var i = 0; i < cids.length; i++) {
dump ("calItemModule: registering " + contractids[i] + "\n");
@ -109,15 +104,9 @@ var calItemModule = {
if (cid.equals(this.mEventCID))
return this.mEventFactory;
if (cid.equals(this.mMutableEventCID))
return this.mMutableEventFactory;
if (cid.equals(this.mTodoCID))
return this.mTodoFactory;
if (cid.equals(this.mMutableTodoCID))
return this.mMutableTodoFactory;
throw Components.results.NS_ERROR_NO_INTERFACE;
},
@ -136,21 +125,6 @@ var calItemModule = {
}
},
mMutableEventFactory: {
QueryInterface: function (aIID) {
if (!aIID.equals(Components.interfaces.nsISupports) &&
!aIID.equals(Components.interfaces.nsIFactory))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
},
createInstance: function (outer, iid) {
if (outer != null)
throw Components.results.NS_ERROR_NO_AGGREGATION;
return (new calMutableEvent()).QueryInterface(iid);
}
},
mTodoFactory: {
QueryInterface: function (aIID) {
if (!aIID.equals(Components.interfaces.nsISupports) &&
@ -166,21 +140,6 @@ var calItemModule = {
}
},
mMutableTodoFactory: {
QueryInterface: function (aIID) {
if (!aIID.equals(Components.interfaces.nsISupports) &&
!aIID.equals(Components.interfaces.nsIFactory))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
},
createInstance: function (outer, iid) {
if (outer != null)
throw Components.results.NS_ERROR_NO_AGGREGATION;
return (new calMutableTodo()).QueryInterface(iid);
}
},
canUnload: function(compMgr) {
return true;
}

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

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