From 001f4cf1d516b1f5c225cc22002578b09a365c2e Mon Sep 17 00:00:00 2001 From: "mostafah%oeone.com" Date: Wed, 30 Oct 2002 15:55:02 +0000 Subject: [PATCH] Fixed some problems with multi-day event displaydates --- calendar/libxpical/oeICalContainerImpl.cpp | 3 +- calendar/libxpical/oeICalEventImpl.cpp | 39 +++++++- calendar/libxpical/oeICalEventImpl.h | 2 +- calendar/libxpical/oeICalImpl.cpp | 106 ++++++++++++--------- calendar/libxpical/oeICalImpl.h | 5 +- 5 files changed, 100 insertions(+), 55 deletions(-) diff --git a/calendar/libxpical/oeICalContainerImpl.cpp b/calendar/libxpical/oeICalContainerImpl.cpp index 7dbf3898f161..bf88197218c1 100644 --- a/calendar/libxpical/oeICalContainerImpl.cpp +++ b/calendar/libxpical/oeICalContainerImpl.cpp @@ -633,7 +633,8 @@ oeICalContainerImpl::GetNextNEvents( PRTime datems, PRInt32 maxcount, nsISimpleE while( tmplistptr && countevent ) { oeIICalEvent* tmpevent = tmplistptr->event; - icaltimetype next = ((oeICalEventImpl *)tmpevent)->GetNextRecurrence( checkdate ); + icaltimetype next = ((oeICalEventImpl *)tmpevent)->GetNextRecurrence( checkdate, nsnull ); + next.is_date = false; if( !icaltime_is_null_time( next ) && (icaltime_compare( nextcheckdate, next ) == 0) ) { eventEnum->AddEvent( tmpevent ); PRTime nextdateinms = ConvertToPrtime( nextcheckdate ); diff --git a/calendar/libxpical/oeICalEventImpl.cpp b/calendar/libxpical/oeICalEventImpl.cpp index 33839be6637c..9e1a69040c84 100644 --- a/calendar/libxpical/oeICalEventImpl.cpp +++ b/calendar/libxpical/oeICalEventImpl.cpp @@ -863,7 +863,8 @@ NS_IMETHODIMP oeICalEventImpl::GetNextRecurrence( PRTime begin, PRTime *retval, #endif *isvalid = false; icaltimetype begindate,result; - result = GetNextRecurrence( begindate ); + result = GetNextRecurrence( begindate, nsnull ); + result.is_date = false; if( icaltime_is_null_time( result ) ) return NS_OK; *retval = ConvertToPrtime( result ); @@ -939,7 +940,11 @@ NS_IMETHODIMP oeICalEventImpl::GetPreviousOccurrence( PRTime beforethis, PRTime return NS_OK; } -icaltimetype oeICalEventImpl::GetNextRecurrence( icaltimetype begin ) { +icaltimetype oeICalEventImpl::GetNextRecurrence( icaltimetype begin, bool *isbeginning ) { + + if( isbeginning ) { + *isbeginning = true; + } icaltimetype result = icaltime_null_time(); @@ -955,8 +960,17 @@ icaltimetype oeICalEventImpl::GetNextRecurrence( icaltimetype begin ) { struct icaltimetype nextday = begin; nextday.hour = 0; nextday.minute = 0; nextday.second = 0; icaltime_adjust( &nextday, 1, 0, 0, 0 ); - if( icaltime_compare( nextday, m_end->m_datetime ) < 0 ) + if( icaltime_compare( nextday, m_end->m_datetime ) < 0 ) { + struct icaltimetype afternextday = nextday; + icaltime_adjust( &afternextday, 1, 0, 0, 0 ); + if( icaltime_compare( afternextday, m_end->m_datetime ) < 0 ) { + nextday.is_date = true; + } + if( isbeginning ) { + *isbeginning = false; + } return nextday; + } return result; } @@ -977,6 +991,7 @@ icaltimetype oeICalEventImpl::GetNextRecurrence( icaltimetype begin ) { struct icalrecurrencetype recur = icalproperty_get_rrule(prop); //printf("#### %s\n",icalrecurrencetype_as_string(&recur)); icalrecur_iterator* ritr = icalrecur_iterator_new(recur,m_start->m_datetime); + bool nextpropagationisdate = false; for(next = icalrecur_iterator_next(ritr); !icaltime_is_null_time(next); next = icalrecur_iterator_next(ritr)){ @@ -1020,6 +1035,11 @@ icaltimetype oeICalEventImpl::GetNextRecurrence( icaltimetype begin ) { PRTime nextdayinms = ConvertToPrtime( nextday ); if( !IsExcepted( nextdayinms ) ) { nextpropagation = nextday; + struct icaltimetype afternextday = nextday; + icaltime_adjust( &afternextday, 1, 0, 0, 0 ); + if( icaltime_compare( afternextday, end ) < 0 ) { + nextpropagationisdate = true; + } } } } @@ -1029,8 +1049,18 @@ icaltimetype oeICalEventImpl::GetNextRecurrence( icaltimetype begin ) { if( !icaltime_is_null_time( nextpropagation ) ) { if( icaltime_compare( nextpropagation , result ) < 0 ) { result = nextpropagation; + result.is_date = nextpropagationisdate; + if( isbeginning ) { + *isbeginning = false; + } } } + } else if( !icaltime_is_null_time( nextpropagation ) ) { + result = nextpropagation; + result.is_date = nextpropagationisdate; + if( isbeginning ) { + *isbeginning = false; + } } } @@ -1068,7 +1098,8 @@ icaltimetype oeICalEventImpl::GetNextAlarmTime( icaltimetype begin ) { icaltimetype checkloop = starting; do { - checkloop = GetNextRecurrence( checkloop ); + checkloop = GetNextRecurrence( checkloop, nsnull ); + checkloop.is_date = false; result = checkloop; if( icaltime_is_null_time( checkloop ) ) { break; diff --git a/calendar/libxpical/oeICalEventImpl.h b/calendar/libxpical/oeICalEventImpl.h index a438e8a1bed1..ade9f07cbc6a 100644 --- a/calendar/libxpical/oeICalEventImpl.h +++ b/calendar/libxpical/oeICalEventImpl.h @@ -112,7 +112,7 @@ public: icalcomponent *AsIcalComponent(); icaltimetype GetNextAlarmTime( icaltimetype begin ); bool matchId( const char *id ); - icaltimetype GetNextRecurrence( icaltimetype begin ); + icaltimetype GetNextRecurrence( icaltimetype begin, bool *isbeginning ); icaltimetype GetPreviousOccurrence( icaltimetype beforethis ); NS_IMETHODIMP SetParent( oeIICal *parent ); icaltimetype CalculateEventTime( icaltimetype alarmtime ); diff --git a/calendar/libxpical/oeICalImpl.cpp b/calendar/libxpical/oeICalImpl.cpp index 330315fc4fe5..ceb30415264c 100644 --- a/calendar/libxpical/oeICalImpl.cpp +++ b/calendar/libxpical/oeICalImpl.cpp @@ -1188,7 +1188,7 @@ oeICalImpl::GetAllEvents(nsISimpleEnumerator **resultList ) for ( unsigned int i=0; iGetElementAt( i, (nsISupports **)&tmpevent ); - icaltimetype next = ((oeICalEventImpl *)tmpevent)->GetNextRecurrence( now ); + icaltimetype next = ((oeICalEventImpl *)tmpevent)->GetNextRecurrence( now, nsnull ); if( !icaltime_is_null_time( next ) ) continue; icaltimetype previous = ((oeICalEventImpl *)tmpevent)->GetPreviousOccurrence( checkdate ); @@ -1203,7 +1203,7 @@ oeICalImpl::GetAllEvents(nsISimpleEnumerator **resultList ) for ( unsigned int i=0; iGetElementAt( i, (nsISupports **)&tmpevent ); - icaltimetype next = ((oeICalEventImpl *)tmpevent)->GetNextRecurrence( now ); + icaltimetype next = ((oeICalEventImpl *)tmpevent)->GetNextRecurrence( now, nsnull ); if( !icaltime_is_null_time( next ) ) continue; icaltimetype previous = ((oeICalEventImpl *)tmpevent)->GetPreviousOccurrence( checkdate ); @@ -1228,7 +1228,8 @@ oeICalImpl::GetAllEvents(nsISimpleEnumerator **resultList ) for ( unsigned int i=0; iGetElementAt( i, (nsISupports **)&tmpevent ); - icaltimetype next = ((oeICalEventImpl *)tmpevent)->GetNextRecurrence( checkdate ); + icaltimetype next = ((oeICalEventImpl *)tmpevent)->GetNextRecurrence( checkdate, nsnull ); + next.is_date = false; if( !icaltime_is_null_time( next ) && ( icaltime_is_null_time( soonest ) || (icaltime_compare( soonest, next ) > 0) ) ) { soonest = next; } @@ -1241,7 +1242,8 @@ oeICalImpl::GetAllEvents(nsISimpleEnumerator **resultList ) for ( unsigned int i=0; iGetElementAt( i, (nsISupports **)&tmpevent ); - icaltimetype next = ((oeICalEventImpl *)tmpevent)->GetNextRecurrence( checkdate ); + icaltimetype next = ((oeICalEventImpl *)tmpevent)->GetNextRecurrence( checkdate, nsnull ); + next.is_date = false; if( !icaltime_is_null_time( next ) && (icaltime_compare( nextcheckdate, next ) == 0) ) { eventEnum->AddEvent( tmpevent ); // PRTime nextdateinms = ConvertToPrtime( nextcheckdate ); @@ -1337,51 +1339,56 @@ oeICalImpl::GetEventsForDay( PRTime datems, nsISimpleEnumerator **datelist, nsIS return GetEventsForRange(checkdateinms ,checkenddateinms ,datelist ,eventlist ); } -void oeICalImpl::ChopAndAddEventToEnum( struct icaltimetype initialdisplaydate, - struct icaltimetype checkenddate, - nsISimpleEnumerator **eventlist, oeICalEventImpl* event ) { +void oeICalImpl::ChopAndAddEventToEnum( struct icaltimetype startdate, + nsISimpleEnumerator **eventlist, oeICalEventImpl* event, bool isallday, bool isbeginning ) { nsCOMPtr eventEnum; eventEnum = (oeEventEnumerator *)*eventlist; - oeIDateTime *start; - oeIDateTime *end; - event->GetStart( &start ); - event->GetEnd( &end ); + oeIICalEventDisplay* eventDisplay; + nsresult rv = NS_NewICalEventDisplay( event, &eventDisplay ); + if( NS_FAILED( rv ) ) { + #ifdef ICAL_DEBUG + printf( "oeICalImpl::ChopAndAddEventToEnum() : WARNING Cannot create oeIICalEventDisplay instance: %x\n", rv ); + #endif + return; + } + eventEnum->AddEvent( eventDisplay ); - struct icaltimetype startdate = initialdisplaydate; - struct icaldurationtype eventlength = icaltime_subtract( ((oeDateTimeImpl *)end)->m_datetime, ((oeDateTimeImpl *)start)->m_datetime ); - struct icaltimetype eventenddate = icaltime_add( startdate, eventlength ); + PRTime startdateinms = ConvertToPrtime( startdate ); + eventDisplay->SetDisplayDate( startdateinms ); - do { - struct icaltimetype endofday = startdate; - endofday.hour = 23; endofday.minute = 59; endofday.second = 59; - oeIICalEventDisplay* eventDisplay; - nsresult rv = NS_NewICalEventDisplay( event, &eventDisplay ); - if( NS_FAILED( rv ) ) { - #ifdef ICAL_DEBUG - printf( "oeICalImpl::ChopAndAddEventToEnum() : WARNING Cannot create oeIICalEventDisplay instance: %x\n", rv ); - #endif - return; - } - eventEnum->AddEvent( eventDisplay ); - PRTime startdateinms = ConvertToPrtime( startdate ); - eventDisplay->SetDisplayDate( startdateinms ); - PRTime enddateinms; - - if( icaltime_compare( endofday, eventenddate ) < 0 ) { - enddateinms = ConvertToPrtime( endofday ); - eventDisplay->SetDisplayEndDate( enddateinms ); - startdate = endofday; - icaltime_adjust( &startdate, 0, 0, 0, 1 ); - if( icaltime_compare( startdate, checkenddate ) >= 0 ) - break; + struct icaltimetype endofday = startdate; + endofday.hour = 23; endofday.minute = 59; endofday.second = 59; + + PRTime enddateinms; + if( isallday ) { + enddateinms = ConvertToPrtime( endofday ); + eventDisplay->SetDisplayEndDate( enddateinms ); + } else { + oeIDateTime *end; + event->GetEnd( &end ); + if( isbeginning ) { + oeIDateTime *start; + event->GetStart( &start ); + + struct icaldurationtype eventlength = icaltime_subtract( ((oeDateTimeImpl *)end)->m_datetime, ((oeDateTimeImpl *)start)->m_datetime ); + struct icaltimetype eventenddate = icaltime_add( startdate, eventlength ); + + if( icaltime_compare( endofday, eventenddate ) < 0 ) { + enddateinms = ConvertToPrtime( endofday ); + } else { + enddateinms = ConvertToPrtime( eventenddate ); + } } else { + struct icaltimetype eventenddate = endofday; + eventenddate.hour = ((oeDateTimeImpl *)end)->m_datetime.hour; + eventenddate.minute = ((oeDateTimeImpl *)end)->m_datetime.minute; + eventenddate.second = ((oeDateTimeImpl *)end)->m_datetime.second; enddateinms = ConvertToPrtime( eventenddate ); - eventDisplay->SetDisplayEndDate( enddateinms ); - break; } - } while ( 0 ); + eventDisplay->SetDisplayEndDate( enddateinms ); + } } NS_IMETHODIMP @@ -1423,9 +1430,12 @@ oeICalImpl::GetEventsForRange( PRTime checkdateinms, PRTime checkenddateinms, ns while( tmplistptr ) { if( tmplistptr->event ) { oeIICalEvent* tmpevent = tmplistptr->event; - icaltimetype next = ((oeICalEventImpl *)tmpevent)->GetNextRecurrence( checkdate ); + bool isbeginning; + icaltimetype next = ((oeICalEventImpl *)tmpevent)->GetNextRecurrence( checkdate, &isbeginning ); + bool isallday = next.is_date; + next.is_date = false; if( !icaltime_is_null_time( next ) && (icaltime_compare( nextcheckdate, next ) == 0) ) { - ChopAndAddEventToEnum( nextcheckdate, checkenddate, eventlist, (oeICalEventImpl *)tmpevent ); + ChopAndAddEventToEnum( nextcheckdate, eventlist, (oeICalEventImpl *)tmpevent, isallday, isbeginning ); PRTime nextdateinms = ConvertToPrtime( nextcheckdate ); dateEnum->AddDate( nextdateinms ); } @@ -1481,7 +1491,8 @@ oeICalImpl::GetFirstEventsForRange( PRTime checkdateinms, PRTime checkenddateinm for ( unsigned int i=0; iGetElementAt( i, (nsISupports **)&tmpevent ); - icaltimetype next = ((oeICalEventImpl *)tmpevent)->GetNextRecurrence( checkdate ); + icaltimetype next = ((oeICalEventImpl *)tmpevent)->GetNextRecurrence( checkdate, nsnull ); + next.is_date = false; if( !icaltime_is_null_time( next ) && ( icaltime_is_null_time( soonest ) || (icaltime_compare( soonest, next ) > 0) ) ) { soonest = next; } @@ -1497,7 +1508,8 @@ oeICalImpl::GetFirstEventsForRange( PRTime checkdateinms, PRTime checkenddateinm for ( unsigned int i=0; iGetElementAt( i, (nsISupports **)&tmpevent ); - icaltimetype next = ((oeICalEventImpl *)tmpevent)->GetNextRecurrence( checkdate ); + icaltimetype next = ((oeICalEventImpl *)tmpevent)->GetNextRecurrence( checkdate, nsnull ); + next.is_date = false; if( !icaltime_is_null_time( next ) && (icaltime_compare( nextcheckdate, next ) == 0) ) { eventEnum->AddEvent( tmpevent ); // PRTime nextdateinms = ConvertToPrtime( nextcheckdate ); @@ -1527,7 +1539,8 @@ icaltimetype oeICalImpl::GetNextEvent( icaltimetype starting ) { while( tmplistptr ) { if( tmplistptr->event ) { oeIICalEvent* tmpevent = tmplistptr->event; - icaltimetype next = ((oeICalEventImpl *)tmpevent)->GetNextRecurrence( starting ); + icaltimetype next = ((oeICalEventImpl *)tmpevent)->GetNextRecurrence( starting, nsnull ); + next.is_date = false; if( !icaltime_is_null_time( next ) && ( icaltime_is_null_time( soonest ) || (icaltime_compare( soonest, next ) > 0) ) ) { soonest = next; } @@ -1565,7 +1578,8 @@ oeICalImpl::GetNextNEvents( PRTime datems, PRInt32 maxcount, nsISimpleEnumerator while( tmplistptr && countevent ) { oeIICalEvent* tmpevent = tmplistptr->event; - icaltimetype next = ((oeICalEventImpl *)tmpevent)->GetNextRecurrence( checkdate ); + icaltimetype next = ((oeICalEventImpl *)tmpevent)->GetNextRecurrence( checkdate, nsnull ); + next.is_date = false; if( !icaltime_is_null_time( next ) && (icaltime_compare( nextcheckdate, next ) == 0) ) { eventEnum->AddEvent( tmpevent ); PRTime nextdateinms = ConvertToPrtime( nextcheckdate ); diff --git a/calendar/libxpical/oeICalImpl.h b/calendar/libxpical/oeICalImpl.h index 67c9d043d405..c93782364e54 100644 --- a/calendar/libxpical/oeICalImpl.h +++ b/calendar/libxpical/oeICalImpl.h @@ -251,9 +251,8 @@ private: char serveraddr[200]; oeICalFilter *m_filter; bool SatisfiesFilter( oeIICalTodo *comp ); - void ChopAndAddEventToEnum( struct icaltimetype initialdisplaydate, - struct icaltimetype checkenddate, - nsISimpleEnumerator **eventlist, oeICalEventImpl* event ); + void ChopAndAddEventToEnum( struct icaltimetype startdate, + nsISimpleEnumerator **eventlist, oeICalEventImpl* event, bool isallday, bool isbeginning ); }; #endif