diff --git a/calendar/libxpical/oeICalContainerImpl.cpp b/calendar/libxpical/oeICalContainerImpl.cpp index a77a5edcbe4b..982d46d56a16 100644 --- a/calendar/libxpical/oeICalContainerImpl.cpp +++ b/calendar/libxpical/oeICalContainerImpl.cpp @@ -272,9 +272,9 @@ oeICalContainerImpl::~oeICalContainerImpl() NS_IMPL_ISUPPORTS1(oeICalContainerImpl, oeIICalContainer) NS_IMETHODIMP -oeICalContainerImpl::AddCalendar( const char *server ) { +oeICalContainerImpl::AddCalendar( const char *server, const char *type ) { #ifdef ICAL_DEBUG - printf( "oeICalContainerImpl::AddCalendar(%s)\n", server ); + printf( "oeICalContainerImpl::AddCalendar(%s, %s)\n", server, type ); #endif nsresult rv; @@ -288,7 +288,14 @@ oeICalContainerImpl::AddCalendar( const char *server ) { return NS_OK; } - calendar = do_CreateInstance(OE_ICAL_CONTRACTID, &rv); + nsCAutoString contractid; + contractid.AssignLiteral("@mozilla.org/ical;1"); + if (type && strlen(type)) { + contractid.AppendLiteral("?type="); + contractid.Append(type); + } + printf("\nContractID: %s\n\n",contractid.get()); + calendar = do_CreateInstance(contractid.get(), &rv); if (NS_FAILED(rv)) { return NS_ERROR_FAILURE; } @@ -378,7 +385,7 @@ oeICalContainerImpl::AddCalendars( PRUint32 serverCount, const char **servers ) #endif nsresult rv=NS_OK; for( unsigned int i=0; i calendar; GetCalendar( server , getter_AddRefs(calendar) ); if( !calendar ) { - AddCalendar( server ); + AddCalendar( server, "" ); GetCalendar( server , getter_AddRefs(calendar) ); if( !calendar ) { #ifdef ICAL_DEBUG @@ -921,7 +928,7 @@ NS_IMETHODIMP oeICalContainerImpl::AddTodo(oeIICalTodo *icaltodo, const char *se nsCOMPtr calendar; GetCalendar( server , getter_AddRefs(calendar) ); if( !calendar ) { - AddCalendar( server ); + AddCalendar( server, "" ); GetCalendar( server , getter_AddRefs(calendar) ); if( !calendar ) { #ifdef ICAL_DEBUG @@ -1501,6 +1508,11 @@ NS_IMETHODIMP oeICalContainerFilter::GetContactsArray(nsISupportsArray * *aConta return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMETHODIMP oeICalContainerFilter::SetParent( oeIICal *parent) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP oeICalContainerFilter::GetParent( oeIICal **parent) { return NS_ERROR_NOT_IMPLEMENTED; @@ -1542,10 +1554,13 @@ void oeICalContainerFilter::UpdateAllFilters( PRInt32 icaltype ) nsCOMPtr calendar; m_calendarArray->GetElementAt( i, getter_AddRefs(calendar) ); oeIICalTodo *filter; + //XXX comptr? getter_AddRefs? calendar->GetFilter( &filter ); - oeIDateTime *completed; - filter->GetCompleted( &completed ); - completed->SetTime( completedvalue ); + if (filter) { + oeIDateTime *completed; + filter->GetCompleted( &completed ); + completed->SetTime( completedvalue ); + } } break; diff --git a/calendar/libxpical/oeICalEventImpl.cpp b/calendar/libxpical/oeICalEventImpl.cpp index 76f43abb2d0c..d26739f53817 100644 --- a/calendar/libxpical/oeICalEventImpl.cpp +++ b/calendar/libxpical/oeICalEventImpl.cpp @@ -369,7 +369,7 @@ oeICalEventImpl::~oeICalEventImpl() NS_IMETHODIMP oeICalEventImpl::SetParent( oeIICal *calendar ) { #ifdef ICAL_DEBUG - printf( "oeICalEventImpl::SetParent()\n" ); + printf( "oeICalEventImpl::SetParent()\n"); #endif m_calendar = calendar; return NS_OK; @@ -378,7 +378,7 @@ NS_IMETHODIMP oeICalEventImpl::SetParent( oeIICal *calendar ) NS_IMETHODIMP oeICalEventImpl::GetParent( oeIICal **calendar ) { #ifdef ICAL_DEBUG_ALL - printf( "oeICalEventImpl::GetParent()\n" ); + printf( "oeICalEventImpl::GetParent()\n"); #endif *calendar = m_calendar; NS_ADDREF( *calendar ); diff --git a/calendar/libxpical/oeICalEventImpl.h b/calendar/libxpical/oeICalEventImpl.h index 3258f28651d4..42dcd42eafa3 100644 --- a/calendar/libxpical/oeICalEventImpl.h +++ b/calendar/libxpical/oeICalEventImpl.h @@ -117,7 +117,6 @@ public: bool matchId( const char *id ); icaltimetype GetNextRecurrence( icaltimetype begin, bool *isbeginning ); icaltimetype GetPreviousOccurrence( icaltimetype beforethis ); - NS_IMETHODIMP SetParent( oeIICal *parent ); icaltimetype CalculateEventTime( icaltimetype alarmtime ); void ChopAndAddEventToEnum( struct icaltimetype startdate, nsISimpleEnumerator **eventlist, bool isallday, bool isbeginning ); @@ -166,7 +165,7 @@ private: icaldurationtype GetLength(); nsCOMPtr m_attachments; nsCOMPtr m_contacts; - oeIICal *m_calendar; + nsCOMPtr m_calendar; }; /*******************************************************************************************/ diff --git a/calendar/libxpical/oeICalImpl.cpp b/calendar/libxpical/oeICalImpl.cpp index 22e203787519..31a362f8907e 100644 --- a/calendar/libxpical/oeICalImpl.cpp +++ b/calendar/libxpical/oeICalImpl.cpp @@ -2285,14 +2285,11 @@ oeICalImpl::GetAllTodos(nsISimpleEnumerator **resultList ) printf( "oeICalImpl::GetAllTodos()\n" ); #endif - nsCOMPtr todoEnum; - if( !*resultList ) { - todoEnum = new oeEventEnumerator(); - if (!todoEnum) - return NS_ERROR_OUT_OF_MEMORY; - todoEnum->QueryInterface(NS_GET_IID(nsISimpleEnumerator), (void **)resultList); - } else - todoEnum = (oeEventEnumerator *)*resultList; + oeEventEnumerator *todoEnum = new oeEventEnumerator(); + if (!todoEnum) + return NS_ERROR_OUT_OF_MEMORY; + *resultList = todoEnum; + NS_ADDREF(*resultList); TodoList *tmplistptr = &m_todolist; while( tmplistptr ) { @@ -2796,6 +2793,11 @@ NS_IMETHODIMP oeICalFilter::GetContactsArray(nsISupportsArray * *aContactsArray) return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMETHODIMP oeICalFilter::SetParent( oeIICal *parent) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP oeICalFilter::GetParent( oeIICal **parent) { return NS_ERROR_NOT_IMPLEMENTED; diff --git a/calendar/libxpical/oeICalTodoImpl.cpp b/calendar/libxpical/oeICalTodoImpl.cpp index c865bba0a33e..98d218661913 100644 --- a/calendar/libxpical/oeICalTodoImpl.cpp +++ b/calendar/libxpical/oeICalTodoImpl.cpp @@ -127,11 +127,6 @@ oeICalTodoImpl::~oeICalTodoImpl() mEvent->Release(); } -NS_IMETHODIMP oeICalTodoImpl::SetParent( oeIICal *calendar ) -{ - return mEvent->SetParent( calendar ); -} - bool oeICalTodoImpl::matchId( const char *id ) { return mEvent->matchId( id ); } diff --git a/calendar/libxpical/oeICalTodoImpl.h b/calendar/libxpical/oeICalTodoImpl.h index 465571245d16..99185af9d6eb 100644 --- a/calendar/libxpical/oeICalTodoImpl.h +++ b/calendar/libxpical/oeICalTodoImpl.h @@ -69,7 +69,6 @@ public: icalcomponent *AsIcalComponent(); NS_IMETHOD Clone(oeIICalTodo **_retval); bool matchId( const char *id ); - NS_IMETHODIMP SetParent( oeIICal *parent ); oeICalEventImpl *GetBaseEvent(); private: int m_percent; diff --git a/calendar/libxpical/oeIICal.idl b/calendar/libxpical/oeIICal.idl index 768a8cbca2e6..288e71dfb822 100644 --- a/calendar/libxpical/oeIICal.idl +++ b/calendar/libxpical/oeIICal.idl @@ -104,7 +104,7 @@ interface oeIICalEvent : nsISupports readonly attribute oeIDateTime start; readonly attribute oeIDateTime end; readonly attribute oeIDateTime stamp; - readonly attribute oeIICal parent; + attribute oeIICal parent; readonly attribute Componenttype type; readonly attribute PRTime lastModified; @@ -230,12 +230,17 @@ interface oeIICal : nsISupports oeIICalEvent fetchEvent( in string id ); // nsISimpleEnumerator searchBySQL( in string sqlstr ); nsISimpleEnumerator getAllEvents(); - nsISimpleEnumerator getEventsForMonth( in PRTime date ); - nsISimpleEnumerator getEventsForWeek( in PRTime date ); - nsISimpleEnumerator getEventsForDay( in PRTime date ); - nsISimpleEnumerator getEventsForRange( in PRTime begindate, in PRTime enddate ); - nsISimpleEnumerator getNextNEvents( in PRTime begindate, in long count ); - nsISimpleEnumerator getFirstEventsForRange( in PRTime begindate, in PRTime enddate ); + /** + * For all the getEvents* and get*EventForRange methods: + * Get events for a certain range. items are oeIICalEventDisplay + */ + nsISimpleEnumerator getEventsForMonth( in PRTime date ); + nsISimpleEnumerator getEventsForWeek( in PRTime date ); + nsISimpleEnumerator getEventsForDay( in PRTime date ); + nsISimpleEnumerator getEventsForRange( in PRTime begindate, in PRTime enddate ); + + nsISimpleEnumerator getNextNEvents( in PRTime begindate, in long count ); + nsISimpleEnumerator getFirstEventsForRange( in PRTime begindate, in PRTime enddate ); string addTodo( in oeIICalTodo icaltodo ); string modifyTodo( in oeIICalTodo icaltodo ); @@ -253,7 +258,20 @@ interface oeIICalContainer : nsISupports attribute boolean batchMode; readonly attribute oeIICalTodo filter; - void addCalendar( in string server ); + + /** + * Add a calendar to the container. + * @param server + * a string indicating the server url + * @param type + * a string idicating which type of calendar to add. + * an object with contractid of @mozilla.org/ical;1?type= + * will be created and added. The object should implement + * oeIICal. + * When empty, @mozilla.org/ical;1 will be used + */ + void addCalendar( in string server, in string type ); + void removeCalendar( in string server ); oeIICal getCalendar( in string server ); void addCalendars( in unsigned long serverCount, [array, size_is(serverCount)] in string servers ); @@ -265,13 +283,26 @@ interface oeIICalContainer : nsISupports string modifyEvent( in oeIICalEvent icalevent ); void deleteEvent( in string id ); oeIICalEvent fetchEvent( in string id ); - nsISimpleEnumerator getAllEvents(); - nsISimpleEnumerator getEventsForMonth( in PRTime date ); - nsISimpleEnumerator getEventsForWeek( in PRTime date ); - nsISimpleEnumerator getEventsForDay( in PRTime date ); - nsISimpleEnumerator getEventsForRange( in PRTime begindate, in PRTime enddate ); - nsISimpleEnumerator getNextNEvents( in PRTime begindate, in long count ); - nsISimpleEnumerator getFirstEventsForRange( in PRTime begindate, in PRTime enddate ); + + nsISimpleEnumerator getAllEvents(); + /** + * For all the getEvents* and get*EventForRange methods: + * Get events for a certain range. items are oeIICalEventDisplay + */ + nsISimpleEnumerator getEventsForMonth( in PRTime date ); + /** + * Get the events starting at the beginning of |date| + * until 7 days later + */ + nsISimpleEnumerator getEventsForWeek( in PRTime date ); + nsISimpleEnumerator getEventsForDay( in PRTime date ); + nsISimpleEnumerator getEventsForRange( in PRTime begindate, in PRTime enddate ); + nsISimpleEnumerator getNextNEvents( in PRTime begindate, in long count ); + + /** + * Get the first occurence of the events in the given time range + */ + nsISimpleEnumerator getFirstEventsForRange( in PRTime begindate, in PRTime enddate ); string addTodo( in oeIICalTodo icaltodo, in string server ); string modifyTodo( in oeIICalTodo icaltodo ); diff --git a/calendar/resources/content/calendarManager.js b/calendar/resources/content/calendarManager.js index ac50dbd0bd86..bc47a75d49c4 100644 --- a/calendar/resources/content/calendarManager.js +++ b/calendar/resources/content/calendarManager.js @@ -401,7 +401,8 @@ calendarManager.prototype.addCalendar = function calMan_addCalendar( ThisCalenda { //dump( "\n CALENDAR MANANGER-> add calendar with path "+ThisCalendarObject.getAttribute( "http://home.netscape.com/NC-rdf#path"+"\n\n" ) ); - gICalLib.addCalendar( ThisCalendarObject.getAttribute( "http://home.netscape.com/NC-rdf#path" ) ); + gICalLib.addCalendar( ThisCalendarObject.getAttribute( "http://home.netscape.com/NC-rdf#path" ), + ThisCalendarObject.getAttribute( "http://home.netscape.com/NC-rdf#type" )); //ThisCalendarObject.setAttribute( "http://home.netscape.com/NC-rdf#active", "true" ); @@ -885,7 +886,8 @@ function switchCalendar( event ) { window.setCursor( "wait" ); - gICalLib.addCalendar( calendarNode.getAttribute( "http://home.netscape.com/NC-rdf#path" ) ); + gICalLib.addCalendar( calendarNode.getAttribute( "http://home.netscape.com/NC-rdf#path" ), + calendarNode.getAttribute( "http://home.netscape.com/NC-rdf#type" )); window.setCursor( "default" );