summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--korganizer/komonthview.cpp15
-rw-r--r--libkcal/recurrence.cpp26
2 files changed, 10 insertions, 31 deletions
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp
index cb69832..004ff50 100644
--- a/korganizer/komonthview.cpp
+++ b/korganizer/komonthview.cpp
@@ -1215,142 +1215,133 @@ void KOMonthView::showDates(const QDate &start, const QDate &)
date = date.addDays( 7 );
}
updateView();
}
void KOMonthView::showEvents(QPtrList<Event>)
{
qDebug("KOMonthView::selectEvents is not implemented yet. ");
}
void KOMonthView::changeEventDisplay(Event *, int)
{
// this should be re-written to be much more efficient, but this
// quick-and-dirty-hack gets the job done for right now.
updateView();
}
void KOMonthView::updateView()
{
if ( !updatePossible )
return;
//QTime ti;
//ti.start();
clearSelection();
QPtrVector<MonthViewCell> *cells;
if ( mShowWeekView ) {
cells = &mCellsW;
} else {
cells = &mCells;
}
#if 1
int i;
int timeSpan = (*cells).size()-1;
if ( KOPrefs::instance()->mMonthViewWeek )
timeSpan = 6;
for( i = 0; i < timeSpan + 1; ++i ) {
(*cells)[i]->startUpdateCell();
}
QPtrList<Event> events = calendar()->events();
Event *event;
QDateTime dt;
bool ok;
QDate endDate = mStartDate.addDays( timeSpan );
for( event = events.first(); event; event = events.next() ) { // for event
if ( event->doesRecur() ) {
bool last;
- qDebug("********************************************** ");
- qDebug("Event summary: %s ", event->summary().latin1());
QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last );
QDateTime incidenceEnd;
int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() );
- qDebug("eventlen %d ", eventlen);
bool invalid = false;
while( true ) {
if ( incidenceStart.isValid() ) {
incidenceEnd = incidenceStart.addDays( eventlen );
int st = incidenceStart.date().daysTo( endDate );
if ( st >= 0 ) { // start before timeend
int end = mStartDate.daysTo( incidenceEnd.date() );
if ( end >= 0 ) { // end after timestart --- got one!
//normalize
st = timeSpan - st;
if ( st < 0 ) st = 0;
if ( end > timeSpan ) end = timeSpan;
int iii;
//qDebug("found %s %d %d ",event->summary().latin1(), st, end );
for ( iii = st;iii<= end;++iii)
(*cells)[iii]->insertEvent( event );
}
}
} else {
if ( invalid )
break;
invalid = true;
- qDebug("invalid %s", event->summary().latin1());
+ //qDebug("invalid %s", event->summary().latin1());
incidenceStart = QDateTime( mStartDate ).addSecs( -2 );;
}
if ( last )
break;
bool ok;
- qDebug("TRY next occurence %s ", incidenceStart.toString().latin1());
incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok );
- if ( ! ok ) {
- qDebug("NOT OK ");
+ if ( ! ok )
break;
- }
- if ( incidenceStart.date() > endDate ) {
- qDebug("incidenceStart.date() > endDate ");
+ if ( incidenceStart.date() > endDate )
break;
}
- qDebug("next occurence %s ", incidenceStart.toString().latin1());
- }
} else { // no recur
int st = event->dtStart().date().daysTo( endDate );
if ( st >= 0 ) { // start before timeend
int end = mStartDate.daysTo( event->dtEnd().date() );
if ( end >= 0 ) { // end after timestart --- got one!
//normalize
st = timeSpan - st;
if ( st < 0 ) st = 0;
if ( end > timeSpan ) end = timeSpan;
int iii;
for ( iii = st;iii<= end;++iii)
(*cells)[iii]->insertEvent( event );
}
}
}
}
// insert due todos
QPtrList<Todo> todos = calendar()->todos( );
Todo *todo;
for(todo = todos.first(); todo; todo = todos.next()) {
//insertTodo( todo );
if ( todo->hasDueDate() ) {
int day = mStartDate.daysTo( todo->dtDue().date() );
if ( day >= 0 && day < timeSpan + 1) {
(*cells)[day]->insertTodo( todo );
}
}
}
for( i = 0; i < timeSpan+1; ++i ) {
(*cells)[i]->finishUpdateCell();
}
processSelectionChange();
(*cells)[0]->setFocus();
#else
// old code
//qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ");
int i;
for( i = 0; i < (*cells).count(); ++i ) {
(*cells)[i]->updateCell();
}
//qDebug("KOMonthView::updateView() ");
processSelectionChange();
// qDebug("---------------------------------------------------------------------+ ");
(*cells)[0]->setFocus();
diff --git a/libkcal/recurrence.cpp b/libkcal/recurrence.cpp
index 8a175c9..6ee5499 100644
--- a/libkcal/recurrence.cpp
+++ b/libkcal/recurrence.cpp
@@ -931,97 +931,97 @@ QDateTime Recurrence::getPreviousDateTime(const QDateTime &afterDateTime, bool *
count = rDuration;
if (last && count == rDuration)
*last = true;
}
QDateTime endtime = mRecurStart.addSecs((count - 1)*freq);
if (rDuration == 0) {
if (endtime > rEndDateTime)
endtime = rEndDateTime;
if (last && endtime == rEndDateTime)
*last = true;
}
return endtime;
}
QDate Recurrence::getPreviousDate(const QDate &afterDate, bool *last) const
{
if (last)
*last = false;
switch (recurs)
{
case rMinutely:
case rHourly:
return getPreviousDateTime(QDateTime(afterDate, QTime(0,0,0)), last).date();
case rDaily:
case rWeekly:
case rMonthlyPos:
case rMonthlyDay:
case rYearlyMonth:
case rYearlyDay:
case rYearlyPos:
return getPreviousDateNoTime(afterDate, last);
default:
return QDate();
}
}
/***************************** PROTECTED FUNCTIONS ***************************/
bool Recurrence::recursSecondly(const QDate &qd, int secondFreq) const
{
if ((qd >= mRecurStart.date()) &&
((rDuration > 0) && (qd <= endDate()) ||
((rDuration == 0) && (qd <= rEndDateTime.date())) ||
(rDuration == -1))) {
// The date queried falls within the range of the event.
if (secondFreq < 24*3600)
return true; // the event recurs at least once each day
- int after = mRecurStart.secsTo(QDateTime(qd));
+ int after = mRecurStart.secsTo(QDateTime(qd)) - 1;
if (after / secondFreq != (after + 24*3600) / secondFreq)
return true;
}
return false;
}
bool Recurrence::recursMinutelyAt(const QDateTime &dt, int minuteFreq) const
{
if ((dt >= mRecurStart) &&
((rDuration > 0) && (dt <= endDateTime()) ||
((rDuration == 0) && (dt <= rEndDateTime)) ||
(rDuration == -1))) {
// The time queried falls within the range of the event.
if (((mRecurStart.secsTo(dt) / 60) % minuteFreq) == 0)
return true;
}
return false;
}
bool Recurrence::recursDaily(const QDate &qd) const
{
QDate dStart = mRecurStart.date();
if ((dStart.daysTo(qd) % rFreq) == 0) {
// The date is a day which recurs
if (qd >= dStart
&& ((rDuration > 0 && qd <= endDate()) ||
(rDuration == 0 && qd <= rEndDateTime.date()) ||
rDuration == -1)) {
// The date queried falls within the range of the event.
return true;
}
}
return false;
}
bool Recurrence::recursWeekly(const QDate &qd) const
{
QDate dStart = mRecurStart.date();
if ((dStart.daysTo(qd)/7) % rFreq == 0) {
// The date is in a week which recurs
if (qd >= dStart
&& ((rDuration > 0 && qd <= endDate()) ||
(rDuration == 0 && qd <= rEndDateTime.date()) ||
rDuration == -1)) {
// The date queried falls within the range of the event.
// check if the bits set match today.
int i = qd.dayOfWeek()-1;
if (rDays.testBit((uint) i))
@@ -1143,198 +1143,195 @@ bool Recurrence::recursYearlyByPos(const QDate &qd) const
return false;
}
bool Recurrence::recursYearlyByDay(const QDate &qd) const
{
QDate dStart = mRecurStart.date();
// calculate how many years ahead this date is from the original
// event's date
int yearsAhead = (qd.year() - dStart.year());
if (yearsAhead % rFreq == 0) {
// The date is in a year which recurs
if (qd >= dStart
&& ((rDuration > 0 && qd <= endDate()) ||
(rDuration == 0 && qd <= rEndDateTime.date()) ||
rDuration == -1)) {
// The date queried falls within the range of the event.
int i = qd.dayOfYear();
for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) {
if (i == *qlin.current())
return true;
}
}
}
return false;
}
/* Get the date of the next recurrence, after the specified date.
* If 'last' is non-null, '*last' is set to true if the next recurrence is the
* last recurrence, else false.
* Reply = date of next recurrence, or invalid date if none.
*/
QDate Recurrence::getNextDateNoTime(const QDate &preDate, bool *last) const
{
if (last)
*last = false;
QDate dStart = mRecurStart.date();
if (preDate < dStart)
return dStart;
QDate earliestDate = preDate.addDays(1);
QDate nextDate;
switch (recurs) {
case rDaily:
nextDate = dStart.addDays((dStart.daysTo(preDate)/rFreq + 1) * rFreq);
break;
case rWeekly: {
- QDate start = dStart.addDays(1 - dStart.dayOfWeek()); // start of week for dStart
+ QDate start = dStart.addDays(-((dStart.dayOfWeek() - rWeekStart + 7)%7)); // start of week for dStart
int earliestDayOfWeek = earliestDate.dayOfWeek();
int weeksAhead = start.daysTo(earliestDate) / 7;
int notThisWeek = weeksAhead % rFreq; // zero if this week is a recurring week
weeksAhead -= notThisWeek; // latest week which recurred
int weekday = 0;
// First check for any remaining day this week, if this week is a recurring week
if (!notThisWeek)
weekday = getFirstDayInWeek(earliestDayOfWeek);
// Check for a day in the next scheduled week
- if (!weekday && earliestDayOfWeek > 1)
+ if (!weekday )
weekday = getFirstDayInWeek(rWeekStart) + rFreq*7;
- if (weekday)
nextDate = start.addDays(weeksAhead*7 + weekday - 1);
break;
}
case rMonthlyDay:
case rMonthlyPos: {
int startYear = dStart.year();
int startMonth = dStart.month(); // 1..12
int earliestYear = earliestDate.year();
int monthsAhead = (earliestYear - startYear)*12 + earliestDate.month() - startMonth;
int notThisMonth = monthsAhead % rFreq; // zero if this month is a recurring month
monthsAhead -= notThisMonth; // latest month which recurred
// Check for the first later day in the current month
if (!notThisMonth)
nextDate = getFirstDateInMonth(earliestDate);
- if (!nextDate.isValid() && earliestDate.day() > 1) {
+ if (!nextDate.isValid() ) {
// Check for a day in the next scheduled month
int months = startMonth - 1 + monthsAhead + rFreq;
nextDate = getFirstDateInMonth(QDate(startYear + months/12, months%12 + 1, 1));
}
break;
}
case rYearlyMonth:
case rYearlyPos:
case rYearlyDay: {
int startYear = dStart.year();
int yearsAhead = earliestDate.year() - startYear;
int notThisYear = yearsAhead % rFreq; // zero if this year is a recurring year
yearsAhead -= notThisYear; // latest year which recurred
// Check for the first later date in the current year
if (!notThisYear)
nextDate = getFirstDateInYear(earliestDate);
// Check for a date in the next scheduled year
if (!nextDate.isValid() && earliestDate.dayOfYear() > 1)
nextDate = getFirstDateInYear(QDate(startYear + yearsAhead + rFreq, 1, 1));
break;
}
case rNone:
default:
return QDate();
}
if (rDuration >= 0 && nextDate.isValid()) {
// Check that the date found is within the range of the recurrence
QDate end = endDate();
if (nextDate > end)
return QDate();
if (last && nextDate == end)
*last = true;
}
return nextDate;
}
/* Get the date of the last previous recurrence, before the specified date.
* Reply = date of previous recurrence, or invalid date if none.
*/
QDate Recurrence::getPreviousDateNoTime(const QDate &afterDate, bool *last) const
{
if (last)
*last = false;
QDate dStart = mRecurStart.date();
QDate latestDate = afterDate.addDays(-1);
if (latestDate < dStart)
return QDate();
QDate prevDate;
switch (recurs) {
case rDaily:
prevDate = dStart.addDays((dStart.daysTo(latestDate) / rFreq) * rFreq);
break;
case rWeekly: {
- QDate start = dStart.addDays(1 - dStart.dayOfWeek()); // start of week for dStart
+ QDate start = dStart.addDays(-((dStart.dayOfWeek() - rWeekStart + 7)%7)); // start of week for dStart
int latestDayOfWeek = latestDate.dayOfWeek();
int weeksAhead = start.daysTo(latestDate) / 7;
int notThisWeek = weeksAhead % rFreq; // zero if this week is a recurring week
weeksAhead -= notThisWeek; // latest week which recurred
int weekday = 0;
// First check for any previous day this week, if this week is a recurring week
if (!notThisWeek)
weekday = getLastDayInWeek(latestDayOfWeek);
// Check for a day in the previous scheduled week
if (!weekday) {
- int weekEnd = (rWeekStart + 5)%7 + 1;
- if (latestDayOfWeek < weekEnd) {
if (!notThisWeek)
weeksAhead -= rFreq;
+ int weekEnd = (rWeekStart + 5)%7 + 1;
weekday = getLastDayInWeek(weekEnd);
}
- }
if (weekday)
prevDate = start.addDays(weeksAhead*7 + weekday - 1);
break;
}
case rMonthlyDay:
case rMonthlyPos: {
int startYear = dStart.year();
int startMonth = dStart.month(); // 1..12
int latestYear = latestDate.year();
int monthsAhead = (latestYear - startYear)*12 + latestDate.month() - startMonth;
int notThisMonth = monthsAhead % rFreq; // zero if this month is a recurring month
monthsAhead -= notThisMonth; // latest month which recurred
// Check for the last earlier day in the current month
if (!notThisMonth)
prevDate = getLastDateInMonth(latestDate);
if (!prevDate.isValid() && latestDate.day() < latestDate.daysInMonth()) {
// Check for a day in the previous scheduled month
if (!notThisMonth)
monthsAhead -= rFreq;
int months = startMonth + monthsAhead; // get the month after the one that recurs
prevDate = getLastDateInMonth(QDate(startYear + months/12, months%12 + 1, 1).addDays(-1));
}
break;
}
case rYearlyMonth:
case rYearlyPos:
case rYearlyDay: {
int startYear = dStart.year();
int yearsAhead = latestDate.year() - startYear;
int notThisYear = yearsAhead % rFreq; // zero if this year is a recurring year
yearsAhead -= notThisYear; // latest year which recurred
// Check for the first later date in the current year
if (!notThisYear)
prevDate = getLastDateInYear(latestDate);
if (!prevDate.isValid() && latestDate.dayOfYear() < latestDate.daysInYear()) {
// Check for a date in the next scheduled year
if (!notThisYear)
yearsAhead -= rFreq;
prevDate = getLastDateInYear(QDate(startYear + yearsAhead, 12, 31));
}
break;
}
case rNone:
default:
return QDate();
}
if (prevDate.isValid()) {
@@ -3355,59 +3352,50 @@ QDate Recurrence::getLastDateInYear(const QDate &latestDate) const
case rMar1:
if (latestMonth >= 3)
return QDate(latestYear, 3, 1);
break;
case rFeb28:
return QDate(latestYear, 2, 28);
case rFeb29:
break;
}
}
}
}
break;
}
case rYearlyPos: {
QValueList<int> dayList;
int latestYear = latestDate.year();
int latestMonth = latestDate.month();
int latestDay = latestDate.day();
for (it.toLast(); it.current(); --it) {
int month = *it.current();
if (month <= latestMonth) {
QDate monthBegin(latestYear, month, 1);
getMonthlyPosDays(dayList, monthBegin.daysInMonth(), monthBegin.dayOfWeek());
for (QValueList<int>::ConstIterator id = dayList.fromLast(); id != dayList.end(); --id) {
if (*id <= latestDay)
return monthBegin.addDays(*id - 1);
}
latestDay = 31;
}
}
break;
}
case rYearlyDay: {
int latestDay = latestDate.dayOfYear();
for (it.toLast(); it.current(); --it) {
int day = *it.current();
if (day <= latestDay)
return latestDate.addDays(day - latestDay);
}
break;
}
}
return QDate();
}
void Recurrence::dump() const
{
- kdDebug() << "Recurrence::dump():" << endl;
-
- kdDebug() << " type: " << recurs << endl;
-
- kdDebug() << " rDays: " << endl;
- int i;
- for( i = 0; i < 7; ++i ) {
- kdDebug() << " " << i << ": "
- << ( rDays.testBit( i ) ? "true" : "false" ) << endl;
- }
+ ;
}