зеркало из https://github.com/mozilla/gecko-dev.git
bug 330371: add and implement calIPeriod. r=daniel boelzle
This commit is contained in:
Родитель
d3a79761c5
Коммит
98268029ba
|
@ -44,6 +44,7 @@
|
|||
|
||||
#include "calDateTime.h"
|
||||
#include "calDuration.h"
|
||||
#include "calPeriod.h"
|
||||
#include "calICSService.h"
|
||||
#include "calRecurrenceRule.h"
|
||||
#include "calRecurrenceDate.h"
|
||||
|
@ -53,6 +54,7 @@
|
|||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(calDateTime)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(calDuration)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(calPeriod)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(calICSService)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(calRecurrenceRule)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(calRecurrenceDate)
|
||||
|
@ -60,6 +62,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(calRecurrenceDateSet)
|
|||
|
||||
NS_DECL_CLASSINFO(calDateTime)
|
||||
NS_DECL_CLASSINFO(calDuration)
|
||||
NS_DECL_CLASSINFO(calPeriod)
|
||||
NS_DECL_CLASSINFO(calICSService)
|
||||
NS_DECL_CLASSINFO(calRecurrenceRule)
|
||||
NS_DECL_CLASSINFO(calRecurrenceDate)
|
||||
|
@ -89,6 +92,17 @@ static const nsModuleComponentInfo components[] =
|
|||
NULL,
|
||||
&NS_CLASSINFO_NAME(calDuration)
|
||||
},
|
||||
{ "Calendar Period Object",
|
||||
CAL_PERIOD_CID,
|
||||
CAL_PERIOD_CONTRACTID,
|
||||
calPeriodConstructor,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NS_CI_INTERFACE_GETTER_NAME(calPeriod),
|
||||
NULL,
|
||||
&NS_CLASSINFO_NAME(calPeriod)
|
||||
},
|
||||
{ "ICS parser/serializer",
|
||||
CAL_ICSSERVICE_CID,
|
||||
CAL_ICSSERVICE_CONTRACTID,
|
||||
|
|
|
@ -55,6 +55,7 @@ XPIDLSRCS = calIAlarmService.idl \
|
|||
calICalendarView.idl \
|
||||
calICalendarViewController.idl \
|
||||
calIDateTime.idl \
|
||||
calIPeriod.idl \
|
||||
calIDecoratedView.idl \
|
||||
calIDuration.idl \
|
||||
calIErrors.idl \
|
||||
|
|
|
@ -51,6 +51,11 @@
|
|||
#define CAL_DURATION_CONTRACTID \
|
||||
"@mozilla.org/calendar/duration;1"
|
||||
|
||||
#define CAL_PERIOD_CID \
|
||||
{ 0x12fdd72b, 0xc5b6, 0x4720, { 0x81, 0x66, 0x2d, 0xec, 0xa1, 0x33, 0x82, 0xf5 } }
|
||||
#define CAL_PERIOD_CONTRACTID \
|
||||
"@mozilla.org/calendar/period;1"
|
||||
|
||||
#define CAL_ICSSERVICE_CID \
|
||||
{ 0xf2f65cf2, 0x880e, 0x4960, { 0xb3, 0x7b, 0xae, 0x02, 0x05, 0xb6, 0xe3, 0x42 } }
|
||||
#define CAL_ICSSERVICE_CONTRACTID \
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
/* -*- Mode: idl; 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 mozilla calendar code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Michiel van Leeuwen <michiel@exedo.nl>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* 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 "nsISupports.idl"
|
||||
|
||||
interface calIDateTime;
|
||||
interface calIDuration;
|
||||
|
||||
[ptr] native icalperiodtypeptr(struct icalperiodtype);
|
||||
|
||||
[scriptable,uuid(03cde9c7-c864-4109-8bea-ebbff01cbab9)]
|
||||
interface calIPeriod : nsISupports
|
||||
{
|
||||
/**
|
||||
* isMutable is true if this instance is modifiable.
|
||||
* If isMutable is false, any attempts to modify
|
||||
* the object will throw CAL_ERROR_ITEM_IS_MUTABLE.
|
||||
*/
|
||||
readonly attribute boolean isMutable;
|
||||
|
||||
/**
|
||||
* Make this calIPeriod instance immutable.
|
||||
*/
|
||||
void makeImmutable();
|
||||
|
||||
/**
|
||||
* Clone this calIPeriod instance into a new
|
||||
* mutable object.
|
||||
*/
|
||||
calIPeriod clone();
|
||||
|
||||
/**
|
||||
* The start datetime of this period
|
||||
*/
|
||||
attribute calIDateTime start;
|
||||
|
||||
/**
|
||||
* The end datetime of this period
|
||||
*/
|
||||
attribute calIDateTime end;
|
||||
|
||||
/**
|
||||
* The duration, equal to end-start
|
||||
*/
|
||||
readonly attribute calIDuration duration;
|
||||
|
||||
|
||||
/**
|
||||
* Return a string representation of this instance.
|
||||
*/
|
||||
AUTF8String toString();
|
||||
|
||||
[noscript,notxpcom] void toIcalPeriod(in icalperiodtypeptr idt);
|
||||
|
||||
/**
|
||||
* This object as an iCalendar DURATION string
|
||||
*/
|
||||
attribute ACString icalString;
|
||||
};
|
|
@ -64,6 +64,7 @@ XPIDLSRCS = \
|
|||
|
||||
CPPSRCS = calDateTime.cpp \
|
||||
calDuration.cpp \
|
||||
calPeriod.cpp \
|
||||
calICSService.cpp \
|
||||
calRecurrenceRule.cpp \
|
||||
calRecurrenceDate.cpp \
|
||||
|
|
|
@ -0,0 +1,196 @@
|
|||
/* -*- 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 mozilla calendar code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Michiel van Leeuwen <mvl@exedo.nl>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* 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 "calPeriod.h"
|
||||
#include "calBaseCID.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1_CI(calPeriod, calIPeriod)
|
||||
|
||||
calPeriod::calPeriod()
|
||||
: mImmutable(PR_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
calPeriod::calPeriod(const calPeriod& cpt)
|
||||
: mImmutable(PR_FALSE)
|
||||
{
|
||||
if (cpt.mStart)
|
||||
cpt.mStart->Clone(getter_AddRefs(mStart));
|
||||
if (cpt.mEnd)
|
||||
cpt.mEnd->Clone(getter_AddRefs(mEnd));
|
||||
}
|
||||
|
||||
calPeriod::calPeriod(struct icalperiodtype *aPeriodPtr)
|
||||
: mImmutable(PR_FALSE)
|
||||
{
|
||||
FromIcalPeriod(aPeriodPtr);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calPeriod::GetIsMutable(PRBool *aResult)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
|
||||
*aResult = !mImmutable;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calPeriod::MakeImmutable()
|
||||
{
|
||||
if (mImmutable)
|
||||
return NS_ERROR_OBJECT_IS_IMMUTABLE;
|
||||
|
||||
mImmutable = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calPeriod::Clone(calIPeriod **aResult)
|
||||
{
|
||||
calPeriod *cpt = new calPeriod(*this);
|
||||
if (!cpt)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(*aResult = cpt);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP calPeriod::GetStart(calIDateTime **_retval)
|
||||
{
|
||||
*_retval = mStart;
|
||||
NS_IF_ADDREF(*_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP calPeriod::SetStart(calIDateTime *aValue)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aValue);
|
||||
if (mImmutable)
|
||||
return NS_ERROR_CALENDAR_IMMUTABLE;
|
||||
// rfc2445 says that periods are always in utc. libical ignore that,
|
||||
// so we need the conversion here.
|
||||
aValue->GetInTimezone(NS_LITERAL_CSTRING("UTC"), getter_AddRefs(mStart));
|
||||
return mStart->MakeImmutable();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP calPeriod::GetEnd(calIDateTime **_retval)
|
||||
{
|
||||
//XXX clone?
|
||||
*_retval = mEnd;
|
||||
NS_IF_ADDREF(*_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP calPeriod::SetEnd(calIDateTime *aValue)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aValue);
|
||||
if (mImmutable)
|
||||
return NS_ERROR_CALENDAR_IMMUTABLE;
|
||||
aValue->GetInTimezone(NS_LITERAL_CSTRING("UTC"), getter_AddRefs(mEnd));
|
||||
return mEnd->MakeImmutable();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP calPeriod::GetDuration(calIDuration **_retval)
|
||||
{
|
||||
if (!mStart || !mEnd)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<calIDuration> duration;
|
||||
mEnd->SubtractDate(mStart, getter_AddRefs(duration));
|
||||
*_retval = duration;
|
||||
NS_IF_ADDREF(*_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calPeriod::ToString(nsACString& aResult)
|
||||
{
|
||||
return GetIcalString(aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(void)
|
||||
calPeriod::ToIcalPeriod(struct icalperiodtype *icalp)
|
||||
{
|
||||
// makes no sense to create a duration without bath a start and end
|
||||
if (!mStart || !mEnd) {
|
||||
*icalp = icalperiodtype_null_period();
|
||||
return;
|
||||
}
|
||||
|
||||
mStart->ToIcalTime(&icalp->start);
|
||||
mEnd->ToIcalTime(&icalp->end);
|
||||
}
|
||||
|
||||
void
|
||||
calPeriod::FromIcalPeriod(struct icalperiodtype *icalp)
|
||||
{
|
||||
mStart = new calDateTime(&(icalp->start));
|
||||
mStart->MakeImmutable();
|
||||
mEnd = new calDateTime(&(icalp->end));
|
||||
mEnd->MakeImmutable();
|
||||
return;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calPeriod::GetIcalString(nsACString& aResult)
|
||||
{
|
||||
struct icalperiodtype ip;
|
||||
ToIcalPeriod(&ip);
|
||||
|
||||
// note that ics is owned by libical, so we don't need to free
|
||||
const char *ics = icalperiodtype_as_ical_string(ip);
|
||||
|
||||
if (ics) {
|
||||
aResult.Assign(ics);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calPeriod::SetIcalString(const nsACString& aIcalString)
|
||||
{
|
||||
struct icalperiodtype ip;
|
||||
ip = icalperiodtype_from_string(nsPromiseFlatCString(aIcalString).get());
|
||||
//XXX Shortcut. Assumes nobody tried to overrule our impl. of calIDateTime
|
||||
// Should use NS_NEWXPCOM()
|
||||
mStart = new calDateTime(&ip.start);
|
||||
mEnd = new calDateTime(&ip.end);
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
/* -*- 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 mozilla calendar code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Michiel van Leeuwen <mvl@exedo.nl>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* 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 CALPERIOD_H_
|
||||
#define CALPERIOD_H_
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "calIPeriod.h"
|
||||
#include "calDateTime.h"
|
||||
#include "calIDuration.h"
|
||||
|
||||
extern "C" {
|
||||
#include "ical.h"
|
||||
}
|
||||
|
||||
class calPeriod : public calIPeriod
|
||||
{
|
||||
public:
|
||||
calPeriod ();
|
||||
explicit calPeriod (const calPeriod& cpt);
|
||||
explicit calPeriod (struct icalperiodtype *aPeriodPtr);
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// calIPeriod interface
|
||||
NS_DECL_CALIPERIOD
|
||||
|
||||
protected:
|
||||
PRBool mImmutable;
|
||||
|
||||
//struct icaldurationtype mPeriod;
|
||||
nsCOMPtr<calIDateTime> mStart;
|
||||
nsCOMPtr<calIDateTime> mEnd;
|
||||
|
||||
void FromIcalPeriod(struct icalperiodtype *icalp);
|
||||
};
|
||||
|
||||
#endif /* CALPERIOD_H_ */
|
||||
|
Загрузка…
Ссылка в новой задаче