зеркало из https://github.com/mozilla/pjs.git
Adding first version of oeICalTodo component
This commit is contained in:
Родитель
0ff578acde
Коммит
5dcbb5342e
|
@ -59,6 +59,7 @@ XPIDLSRCS = oeIICal.idl
|
||||||
|
|
||||||
CPPSRCS = \
|
CPPSRCS = \
|
||||||
oeICalEventImpl.cpp \
|
oeICalEventImpl.cpp \
|
||||||
|
oeICalTodoImpl.cpp \
|
||||||
oeICalFactory.cpp \
|
oeICalFactory.cpp \
|
||||||
oeICalImpl.cpp \
|
oeICalImpl.cpp \
|
||||||
oeDateTimeImpl.cpp \
|
oeDateTimeImpl.cpp \
|
||||||
|
|
|
@ -0,0 +1,277 @@
|
||||||
|
/* ***** 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
|
||||||
|
* Chris Charabaruk <ccharabaruk@meldstar.com>.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s): Chris Charabaruk <ccharabaruk@meldstar.com>
|
||||||
|
* Mostafa Hosseini <mostafah@oeone.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 WIN32
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "oeICalEventImpl.h"
|
||||||
|
#include "oeICalTodoImpl.h"
|
||||||
|
#include "nsMemory.h"
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
|
|
||||||
|
#define strcasecmp strcmp
|
||||||
|
|
||||||
|
#define RECUR_NONE 0
|
||||||
|
#define RECUR_DAILY 1
|
||||||
|
#define RECUR_WEEKLY 2
|
||||||
|
#define RECUR_MONTHLY_MDAY 3
|
||||||
|
#define RECUR_MONTHLY_WDAY 4
|
||||||
|
#define RECUR_YEARLY 5
|
||||||
|
|
||||||
|
/* Implementation file */
|
||||||
|
NS_IMPL_ISUPPORTS1(oeICalTodoImpl, oeIICalTodo)
|
||||||
|
|
||||||
|
icaltimetype ConvertFromPrtime( PRTime indate );
|
||||||
|
PRTime ConvertToPrtime ( icaltimetype indate );
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
NS_NewICalTodo( oeIICalTodo** inst )
|
||||||
|
{
|
||||||
|
NS_PRECONDITION(inst != nsnull, "null ptr");
|
||||||
|
if (! inst)
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
|
*inst = new oeICalTodoImpl();
|
||||||
|
if (! *inst)
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
NS_ADDREF(*inst);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
oeICalTodoImpl::oeICalTodoImpl()
|
||||||
|
{
|
||||||
|
#ifdef ICAL_DEBUG
|
||||||
|
printf( "oeICalTodoImpl::oeICalTodoImpl()\n" );
|
||||||
|
#endif
|
||||||
|
NS_INIT_ISUPPORTS();
|
||||||
|
|
||||||
|
mEvent = new oeICalEventImpl();
|
||||||
|
|
||||||
|
/* member initializers and constructor code */
|
||||||
|
nsresult rv;
|
||||||
|
if( NS_FAILED( rv = NS_NewDateTime((oeIDateTime**) &m_due ))) {
|
||||||
|
m_due = nsnull;
|
||||||
|
}
|
||||||
|
if( NS_FAILED( rv = NS_NewDateTime((oeIDateTime**) &m_completed ))) {
|
||||||
|
m_completed = nsnull;
|
||||||
|
}
|
||||||
|
m_percent = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
oeICalTodoImpl::~oeICalTodoImpl()
|
||||||
|
{
|
||||||
|
#ifdef ICAL_DEBUG
|
||||||
|
printf( "oeICalTodoImpl::~oeICalTodoImpl( %d )\n", mRefCnt );
|
||||||
|
#endif
|
||||||
|
/* destructor code */
|
||||||
|
if( m_due )
|
||||||
|
m_due->Release();
|
||||||
|
if( m_completed )
|
||||||
|
m_completed->Release();
|
||||||
|
mEvent->Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* readonly attribute oeIDateTime due; */
|
||||||
|
NS_IMETHODIMP oeICalTodoImpl::GetDue(oeIDateTime * *due)
|
||||||
|
{
|
||||||
|
*due = m_due;
|
||||||
|
NS_ADDREF(*due);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* areadonly attribute oeIDateTime completed; */
|
||||||
|
NS_IMETHODIMP oeICalTodoImpl::GetCompleted(oeIDateTime * *completed)
|
||||||
|
{
|
||||||
|
*completed = m_completed;
|
||||||
|
NS_ADDREF(*completed);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* attribute short percent; */
|
||||||
|
NS_IMETHODIMP oeICalTodoImpl::GetPercent(PRInt16 *aRetVal)
|
||||||
|
{
|
||||||
|
#ifdef ICAL_DEBUG_ALL
|
||||||
|
printf( "GetPercent() = " );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
*aRetVal = m_percent;
|
||||||
|
|
||||||
|
#ifdef ICAL_DEBUG_ALL
|
||||||
|
printf( "%d\n", *aRetVal );
|
||||||
|
#endif
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
NS_IMETHODIMP oeICalTodoImpl::SetPercent(PRInt16 aNewVal)
|
||||||
|
{
|
||||||
|
#ifdef ICAL_DEBUG_ALL
|
||||||
|
printf( "SetPercent( %d )\n", aNewVal );
|
||||||
|
#endif
|
||||||
|
m_percent = aNewVal;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP oeICalTodoImpl::Clone( oeIICalTodo **ev )
|
||||||
|
{
|
||||||
|
#ifdef ICAL_DEBUG_ALL
|
||||||
|
printf( "oeICalTodoImpl::Clone()\n" );
|
||||||
|
#endif
|
||||||
|
nsresult rv;
|
||||||
|
oeICalTodoImpl *icaltodo =nsnull;
|
||||||
|
if( NS_FAILED( rv = NS_NewICalTodo( (oeIICalTodo**) &icaltodo ) ) ) {
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
icalcomponent *vcalendar = AsIcalComponent();
|
||||||
|
if ( !vcalendar ) {
|
||||||
|
#ifdef ICAL_DEBUG
|
||||||
|
printf( "oeICalTodoImpl::Clone() failed!\n" );
|
||||||
|
#endif
|
||||||
|
icaltodo->Release();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
icalcomponent *vtodo = icalcomponent_get_first_component( vcalendar, ICAL_VTODO_COMPONENT );
|
||||||
|
if( !(icaltodo->ParseIcalComponent( vtodo )) ) {
|
||||||
|
#ifdef ICAL_DEBUG
|
||||||
|
printf( "oeICalTodoImpl::Clone() failed.\n" );
|
||||||
|
#endif
|
||||||
|
icaltodo->Release();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
*ev = icaltodo;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool oeICalTodoImpl::ParseIcalComponent( icalcomponent *comp )
|
||||||
|
{
|
||||||
|
#ifdef ICAL_DEBUG_ALL
|
||||||
|
printf( "ParseIcalComponent()\n" );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//something like this first
|
||||||
|
//mEvent->ParseIcalComponent( comp );
|
||||||
|
//then go on with the extra properties
|
||||||
|
|
||||||
|
icalcomponent *vtodo=nsnull;
|
||||||
|
icalcomponent_kind kind = icalcomponent_isa( comp );
|
||||||
|
|
||||||
|
if( kind == ICAL_VCALENDAR_COMPONENT )
|
||||||
|
vtodo = icalcomponent_get_first_component( comp , ICAL_VTODO_COMPONENT );
|
||||||
|
else if( kind == ICAL_VTODO_COMPONENT )
|
||||||
|
vtodo = comp;
|
||||||
|
|
||||||
|
if ( !vtodo ) {
|
||||||
|
#ifdef ICAL_DEBUG
|
||||||
|
printf( "oeICalTodoImpl::ParseIcalComponent() failed: vtodo is NULL!\n" );
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//percent
|
||||||
|
icalproperty *prop = icalcomponent_get_first_property( vtodo, ICAL_PERCENTCOMPLETE_PROPERTY );
|
||||||
|
if ( prop != 0) {
|
||||||
|
m_percent = icalproperty_get_percentcomplete( prop );
|
||||||
|
} else {
|
||||||
|
m_percent = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//completed
|
||||||
|
prop = icalcomponent_get_first_property( vtodo, ICAL_COMPLETED_PROPERTY );
|
||||||
|
if (prop != 0) {
|
||||||
|
icaltimetype completed;
|
||||||
|
completed = icalproperty_get_completed( prop );
|
||||||
|
m_completed->m_datetime = completed;
|
||||||
|
} else {
|
||||||
|
m_completed->m_datetime = icaltime_null_time();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
icalcomponent* oeICalTodoImpl::AsIcalComponent()
|
||||||
|
{
|
||||||
|
#ifdef ICAL_DEBUG_ALL
|
||||||
|
printf( "AsIcalComponent()\n" );
|
||||||
|
#endif
|
||||||
|
icalcomponent *newcalendar;
|
||||||
|
|
||||||
|
newcalendar = icalcomponent_new_vcalendar();
|
||||||
|
if ( !newcalendar ) {
|
||||||
|
#ifdef ICAL_DEBUG
|
||||||
|
printf( "oeICalEventImpl::AsIcalComponent() failed: Cannot create VCALENDAR!\n" );
|
||||||
|
#endif
|
||||||
|
return nsnull;
|
||||||
|
}
|
||||||
|
icalcomponent *vtodo = icalcomponent_new_vtodo();
|
||||||
|
|
||||||
|
//percent
|
||||||
|
icalproperty *prop = icalproperty_new_percentcomplete( m_percent );
|
||||||
|
icalcomponent_add_property( vtodo, prop );
|
||||||
|
|
||||||
|
//Create due if does not exist
|
||||||
|
if( icaltime_is_null_time( m_due->m_datetime ) ) {
|
||||||
|
//Set to the same as start date 23:59
|
||||||
|
//MUST USE mEvent's STARTDATE m_due->m_datetime = m_start->m_datetime;
|
||||||
|
m_due->SetHour( 23 ); m_due->SetMinute( 59 );
|
||||||
|
}
|
||||||
|
|
||||||
|
//due
|
||||||
|
PRBool m_allday;
|
||||||
|
GetAllDay ( &m_allday );
|
||||||
|
if( m_allday ) {
|
||||||
|
m_due->SetHour( 23 );
|
||||||
|
m_due->SetMinute( 59 );
|
||||||
|
}
|
||||||
|
prop = icalproperty_new_due( m_due->m_datetime );
|
||||||
|
icalcomponent_add_property( vtodo, prop );
|
||||||
|
|
||||||
|
//completed
|
||||||
|
if( m_completed ) {
|
||||||
|
prop = icalproperty_new_completed( m_completed->m_datetime );
|
||||||
|
icalcomponent_add_property( vtodo, prop );
|
||||||
|
}
|
||||||
|
|
||||||
|
//add event to newcalendar
|
||||||
|
icalcomponent_add_component( newcalendar, vtodo );
|
||||||
|
|
||||||
|
//!!!!!!!!!!!!!!
|
||||||
|
//NOW FIND A WAY TO ADD PROPERTIES FROM mEvent
|
||||||
|
|
||||||
|
return newcalendar;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* End of implementation class template. */
|
|
@ -0,0 +1,103 @@
|
||||||
|
/* ***** 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
|
||||||
|
* Chris Charabaruk <ccharabaruk@meldstar.com>.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s): Chris Charabaruk <ccharabaruk@meldstar.com>
|
||||||
|
* Mostafa Hosseini <mostafah@oeone.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 _OEICALTODOIMPL_H_
|
||||||
|
#define _OEICALTODOIMPL_H_
|
||||||
|
|
||||||
|
#include "oeIICal.h"
|
||||||
|
#include "oeDateTimeImpl.h"
|
||||||
|
#include "nsISimpleEnumerator.h"
|
||||||
|
#include "nsISupportsPrimitives.h"
|
||||||
|
#include "nsSupportsPrimitives.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "ical.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
#define OE_ICALTODO_CID \
|
||||||
|
{ 0x0c06905a, 0x1dd2, 0x11b2, { 0xba, 0x61, 0xc9, 0x5d, 0x84, 0x0b, 0x01, 0xef } }
|
||||||
|
|
||||||
|
#define OE_ICALTODO_CONTRACTID "@mozilla.org/icaltodo;1"
|
||||||
|
|
||||||
|
/* oeICalTodo Header file */
|
||||||
|
class oeICalTodoImpl : public oeIICalTodo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
NS_FORWARD_OEIICALEVENT(mEvent->)
|
||||||
|
NS_DECL_OEIICALTODO
|
||||||
|
|
||||||
|
oeICalTodoImpl();
|
||||||
|
virtual ~oeICalTodoImpl();
|
||||||
|
/* additional members */
|
||||||
|
bool ParseIcalComponent( icalcomponent *vcalendar );
|
||||||
|
icalcomponent *AsIcalComponent();
|
||||||
|
NS_IMETHOD Clone(oeIICalTodo **_retval);
|
||||||
|
private:
|
||||||
|
/* char *m_id;
|
||||||
|
char *m_syncid;
|
||||||
|
char *m_title;
|
||||||
|
char *m_description;
|
||||||
|
char *m_location;
|
||||||
|
char *m_category;
|
||||||
|
bool m_isprivate;
|
||||||
|
bool m_allday;
|
||||||
|
bool m_hasalarm;
|
||||||
|
unsigned long m_alarmlength;
|
||||||
|
char *m_alarmunits;
|
||||||
|
char *m_alarmemail;
|
||||||
|
char *m_inviteemail;
|
||||||
|
short m_recurtype;
|
||||||
|
unsigned long m_recurinterval;
|
||||||
|
bool m_recur;
|
||||||
|
bool m_recurforever;
|
||||||
|
char *m_recurunits;
|
||||||
|
short m_recurweekdays;
|
||||||
|
short m_recurweeknumber;
|
||||||
|
oeDateTimeImpl *m_start;
|
||||||
|
oeDateTimeImpl *m_end;
|
||||||
|
oeDateTimeImpl *m_recurend;
|
||||||
|
icaltimetype m_lastalarmack;
|
||||||
|
std::vector<PRTime> m_exceptiondates;
|
||||||
|
std::vector<PRTime> m_snoozetimes;*/
|
||||||
|
int m_percent;
|
||||||
|
oeDateTimeImpl *m_completed;
|
||||||
|
oeDateTimeImpl *m_due;
|
||||||
|
nsCOMPtr<oeIICalEvent> mEvent;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -19,6 +19,7 @@
|
||||||
* the Initial Developer. All Rights Reserved.
|
* the Initial Developer. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Contributor(s): Mostafa Hosseini <mostafah@oeone.com>
|
* Contributor(s): Mostafa Hosseini <mostafah@oeone.com>
|
||||||
|
* Chris Charabaruk <ccharabaruk@meldstar.com>
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* 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
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
@ -100,6 +101,14 @@ interface oeIICalEvent : nsISupports
|
||||||
oeIICalEvent clone();
|
oeIICalEvent clone();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[scriptable, uuid(d44987b4-1dd1-11b2-9783-8a78ed685caf)]
|
||||||
|
interface oeIICalTodo : oeIICalEvent
|
||||||
|
{
|
||||||
|
readonly attribute oeIDateTime due;
|
||||||
|
readonly attribute oeIDateTime completed;
|
||||||
|
attribute short percent;
|
||||||
|
};
|
||||||
|
|
||||||
[scriptable, uuid(b8584baa-1507-40d4-b542-5a2758e1c86d)]
|
[scriptable, uuid(b8584baa-1507-40d4-b542-5a2758e1c86d)]
|
||||||
interface oeIICalObserver : nsISupports
|
interface oeIICalObserver : nsISupports
|
||||||
{
|
{
|
||||||
|
|
Загрузка…
Ссылка в новой задаче