40 using namespace KCalCore;
43 class KCalCore::FreeBusy::Private
51 Private(
const KCalCore::FreeBusy::Private &other,
FreeBusy *qq ) : q( qq )
57 : q( qq ), mBusyPeriods( busyPeriods )
60 void init(
const KCalCore::FreeBusy::Private &other );
61 void init(
const Event::List &events,
const KDateTime &start,
const KDateTime &end );
67 bool addLocalPeriod(
FreeBusy *fb,
const KDateTime &start,
const KDateTime &end );
70 void KCalCore::FreeBusy::Private::init(
const KCalCore::FreeBusy::Private &other )
72 mDtEnd = other.mDtEnd;
73 mBusyPeriods = other.mBusyPeriods;
78 : d( new KCalCore::
FreeBusy::Private( this ) )
84 d( new KCalCore::
FreeBusy::Private( *other.d, this ) )
89 : d( new KCalCore::
FreeBusy::Private( this ) )
96 : d( new KCalCore::
FreeBusy::Private( this ) )
101 d->init( events, start, end );
105 void FreeBusy::Private::init(
const Event::List &eventList,
106 const KDateTime &start,
const KDateTime &end )
108 int extraDays, i, x, duration;
109 duration = start.daysTo( end );
115 Event::List::ConstIterator it;
116 for ( it = eventList.constBegin(); it != eventList.constEnd(); ++it ) {
129 if ( event->allDay() ) {
131 kDebug() <<
"All-day event";
135 KDateTime st = allDayEvent->dtStart();
136 st.setTime( QTime( 0, 0 ) );
137 KDateTime nd = allDayEvent->dtEnd();
138 nd.setTime( QTime( 23, 59, 59, 999 ) );
139 allDayEvent->setAllDay(
false );
140 allDayEvent->setDtStart( st );
141 allDayEvent->setDtEnd( nd );
143 kDebug() <<
"Use:" << st.toString() <<
"to" << nd.toString();
151 for ( i = 0; i <= duration; ++i ) {
152 day = start.addDays( i ).date();
153 tmpStart.setDate( day );
154 tmpEnd.setDate( day );
156 if ( event->recurs() ) {
157 if ( event->isMultiDay() ) {
160 extraDays =
event->dtStart().daysTo( event->dtEnd() );
161 for ( x = 0; x <= extraDays; ++x ) {
162 if ( event->recursOn( day.addDays( -x ), start.timeSpec() ) ) {
163 tmpStart.setDate( day.addDays( -x ) );
164 tmpStart.setTime( event->dtStart().time() );
165 tmpEnd =
event->duration().end( tmpStart );
167 addLocalPeriod( q, tmpStart, tmpEnd );
172 if ( event->recursOn( day, start.timeSpec() ) ) {
173 tmpStart.setTime( event->dtStart().time() );
174 tmpEnd.setTime( event->dtEnd().time() );
176 addLocalPeriod ( q, tmpStart, tmpEnd );
183 addLocalPeriod( q, event->dtStart(),
event->dtEnd() );
191 : d( new KCalCore::
FreeBusy::Private( this ) )
197 : d( new KCalCore::
FreeBusy::Private( busyPeriods, this ) )
245 return d->mBusyPeriods;
250 qSort( d->mBusyPeriods );
256 foreach (
const Period &p, list ) {
264 d->mBusyPeriods += list;
282 if ( freeBusy->dtStart() <
dtStart() ) {
286 if ( freeBusy->dtEnd() >
dtEnd() ) {
291 Period::List::ConstIterator it;
292 for ( it = periods.constBegin(); it != periods.constEnd(); ++it ) {
293 d->mBusyPeriods.append(
FreeBusyPeriod( ( *it ).start(), ( *it ).end() ) );
299 const KDateTime::Spec &newSpec )
301 if ( oldSpec.isValid() && newSpec.isValid() && oldSpec != newSpec ) {
303 d->mDtEnd = d->mDtEnd.toTimeSpec( oldSpec );
304 d->mDtEnd.setTimeSpec( newSpec );
313 if ( &other !=
this ) {
316 d->init( *( f->d ) );
330 d->mBusyPeriods == fb->d->mBusyPeriods;
348 Q_UNUSED( dateTime );
360 bool FreeBusy::Private::addLocalPeriod(
FreeBusy *fb,
361 const KDateTime &eventStart,
362 const KDateTime &eventEnd )
369 KDateTime start = fb->
dtStart();
370 if ( !( ( ( start.secsTo( eventStart ) >= 0 ) &&
371 ( eventStart.secsTo( mDtEnd ) >= 0 ) ) ||
372 ( ( start.secsTo( eventEnd ) >= 0 ) &&
373 ( eventEnd.secsTo( mDtEnd ) >= 0 ) ) ) ) {
377 if ( eventStart.secsTo( start ) >= 0 ) {
380 tmpStart = eventStart;
383 if ( eventEnd.secsTo( mDtEnd ) <= 0 ) {
390 mBusyPeriods.append( p );
403 return QLatin1String(
"application/x-vnd.akonadi.calendar.freebusy" );
410 return stream << data;
415 QString freeBusyVCal;
416 stream >> freeBusyVCal;
422 kDebug() <<
"Error parsing free/busy";
423 kDebug() << freeBusyVCal;