Changeset View
Changeset View
Standalone View
Standalone View
incidenceeditor-ng/conflictresolver.cpp
Show First 20 Lines • Show All 313 Lines • ▼ Show 20 Lines | KCalCore::FreeBusy::Ptr freebusy = | ||||
mFBModel->data( index, FreeBusyItemModel::FreeBusyRole ).value<KCalCore::FreeBusy::Ptr>(); | mFBModel->data( index, FreeBusyItemModel::FreeBusyRole ).value<KCalCore::FreeBusy::Ptr>(); | ||||
if( freebusy ) { | if( freebusy ) { | ||||
filteredFBItems << freebusy; | filteredFBItems << freebusy; | ||||
} | } | ||||
} | } | ||||
// now we know the number of attendees we are calculating for | // now we know the number of attendees we are calculating for | ||||
const int number_attendees = filteredFBItems.size(); | const int number_attendees = filteredFBItems.size(); | ||||
if ( number_attendees <= 0 ) { | |||||
kDebug() << "no attendees match search criteria"; | |||||
return; | |||||
} | |||||
kDebug() << "num attendees: " << number_attendees; | kDebug() << "num attendees: " << number_attendees; | ||||
// this is a 2 dimensional array where the rows are attendees | // this is a 2 dimensional array where the rows are attendees | ||||
// and the columns are 0 or 1 denoting freee or busy respectively. | // and the columns are 0 or 1 denoting freee or busy respectively. | ||||
QVector< QVector<int> > fbTable; | QVector< QVector<int> > fbTable; | ||||
if ( number_attendees > 0 ) { | |||||
// Explanation of the following loop: | // Explanation of the following loop: | ||||
// iterate: through each attendee | // iterate: through each attendee | ||||
// allocate: an array of length <range> and fill it with 0s | // allocate: an array of length <range> and fill it with 0s | ||||
// iterate: through each attendee's busy period | // iterate: through each attendee's busy period | ||||
// if: the period lies inside our timeframe | // if: the period lies inside our timeframe | ||||
// then: | // then: | ||||
// calculate the array index within the timeframe range of the beginning of the busy period | // calculate the array index within the timeframe range of the beginning of the busy period | ||||
// fill from that index until the period ends with a 1, representing busy | // fill from that index until the period ends with a 1, representing busy | ||||
// fi | // fi | ||||
// etareti | // etareti | ||||
// append the allocated array to <fbTable> | // append the allocated array to <fbTable> | ||||
// etareti | // etareti | ||||
foreach ( KCalCore::FreeBusy::Ptr currentFB, filteredFBItems ) { | foreach ( KCalCore::FreeBusy::Ptr currentFB, filteredFBItems ) { | ||||
Q_ASSERT( currentFB ); // sanity check | Q_ASSERT( currentFB ); // sanity check | ||||
KCalCore::Period::List busyPeriods = currentFB->busyPeriods(); | KCalCore::Period::List busyPeriods = currentFB->busyPeriods(); | ||||
QVector<int> fbArray( range ); | QVector<int> fbArray( range ); | ||||
fbArray.fill( 0 ); // initialize to zero | fbArray.fill( 0 ); // initialize to zero | ||||
for ( KCalCore::Period::List::Iterator it = busyPeriods.begin(); | for ( KCalCore::Period::List::Iterator it = busyPeriods.begin(); | ||||
it != busyPeriods.end(); ++it ) { | it != busyPeriods.end(); ++it ) { | ||||
if ( it->end() >= begin && it->start() <= end ) { | if ( it->end() >= begin && it->start() <= end ) { | ||||
int start_index = -1; // Initialize it to an invalid value. | int start_index = -1; // Initialize it to an invalid value. | ||||
int duration = -1; // Initialize it to an invalid value. | int duration = -1; // Initialize it to an invalid value. | ||||
// case1: the period is completely in our timeframe | // case1: the period is completely in our timeframe | ||||
if( it->end() <= end && it->start() >= begin ) { | if( it->end() <= end && it->start() >= begin ) { | ||||
start_index = begin.secsTo( it->start() ) / mSlotResolutionSeconds; | start_index = begin.secsTo( it->start() ) / mSlotResolutionSeconds; | ||||
duration = it->start().secsTo( it->end() ) / mSlotResolutionSeconds; | duration = it->start().secsTo( it->end() ) / mSlotResolutionSeconds; | ||||
duration -= 1; // vector starts at 0 | duration -= 1; // vector starts at 0 | ||||
// case2: the period begins before our timeframe begins | // case2: the period begins before our timeframe begins | ||||
} else if( it->start() <= begin && it->end() <= end ) { | } else if( it->start() <= begin && it->end() <= end ) { | ||||
start_index = 0; | start_index = 0; | ||||
duration = ( begin.secsTo( it->end() ) / mSlotResolutionSeconds ) - 1; | duration = ( begin.secsTo( it->end() ) / mSlotResolutionSeconds ) - 1; | ||||
// case3: the period ends after our timeframe ends | // case3: the period ends after our timeframe ends | ||||
} else if( it->end() >= end && it->start() >= begin ) { | } else if( it->end() >= end && it->start() >= begin ) { | ||||
start_index = begin.secsTo( it->start() ) / mSlotResolutionSeconds; | start_index = begin.secsTo( it->start() ) / mSlotResolutionSeconds; | ||||
duration = range - start_index - 1; | duration = range - start_index - 1; | ||||
// case4: case2+case3: our timeframe is inside the period | // case4: case2+case3: our timeframe is inside the period | ||||
} else if( it->start() <= begin && it->end() >= end ) { | } else if( it->start() <= begin && it->end() >= end ) { | ||||
start_index = 0; | start_index = 0; | ||||
duration = range - 1; | duration = range - 1; | ||||
} else { | } else { | ||||
kFatal() << "impossible condition reached" << it->start() << it->end(); | kFatal() << "impossible condition reached" << it->start() << it->end(); | ||||
} | } | ||||
// kDebug() << start_index << "+" << duration << "=" | // kDebug() << start_index << "+" << duration << "=" | ||||
// << start_index + duration << "<=" << range; | // << start_index + duration << "<=" << range; | ||||
Q_ASSERT( ( start_index + duration ) < range ); // sanity check | Q_ASSERT( ( start_index + duration ) < range ); // sanity check | ||||
for ( int i = start_index; i <= start_index + duration; ++i ) { | for ( int i = start_index; i <= start_index + duration; ++i ) { | ||||
fbArray[i] = 1; | fbArray[i] = 1; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
Q_ASSERT( fbArray.size() == range ); // sanity check | Q_ASSERT( fbArray.size() == range ); // sanity check | ||||
fbTable.append( fbArray ); | fbTable.append( fbArray ); | ||||
} | } | ||||
Q_ASSERT( fbTable.size() == number_attendees ); | Q_ASSERT( fbTable.size() == number_attendees ); | ||||
} else { | |||||
//If we have no information about freebusytime of participants, everything is free | |||||
QVector<int> fbArray( range ); | |||||
fbArray.fill( 0 ); | |||||
fbTable.append( fbArray ); | |||||
} | |||||
// Now, create another array to represent the allowed weekdays constraints | // Now, create another array to represent the allowed weekdays constraints | ||||
// All days which are not allowed, will be marked as busy | // All days which are not allowed, will be marked as busy | ||||
const KCalendarSystem *calSys = KGlobal::locale()->calendar(); | const KCalendarSystem *calSys = KGlobal::locale()->calendar(); | ||||
QVector<int> fbArray( range ); | QVector<int> fbArray( range ); | ||||
fbArray.fill( 0 ); // initialize to zero | fbArray.fill( 0 ); // initialize to zero | ||||
for ( int slot = 0; slot < fbArray.size(); ++slot ) { | for ( int slot = 0; slot < fbArray.size(); ++slot ) { | ||||
const KDateTime dateTime = begin.addSecs( slot * mSlotResolutionSeconds ); | const KDateTime dateTime = begin.addSecs( slot * mSlotResolutionSeconds ); | ||||
▲ Show 20 Lines • Show All 151 Lines • Show Last 20 Lines |