void KOTodoView::setNewDate( QDate date ) { if ( !mActiveItem || !mChanger ) return; Todo *todo = mActiveItem->todo(); if ( !todo ) return; if ( !todo->isReadOnly() && mChanger->beginChange( todo ) ) { Todo *oldTodo = todo->clone(); QDateTime dt; dt.setDate( date ); if ( !todo->doesFloat() ) dt.setTime( todo->dtDue().time() ); if ( date.isNull() ) todo->setHasDueDate( false ); else if ( !todo->hasDueDate() ) todo->setHasDueDate( true ); todo->setDtDue( dt ); mActiveItem->construct(); mChanger->changeIncidence( oldTodo, todo, KOGlobals::COMPLETION_MODIFIED ); mChanger->endChange( todo ); delete oldTodo; } else { kdDebug(5850) << "No active item, active item is read-only, or locking failed" << endl; } }
Incidence * pasteIncidence( Incidence *inc, const QDate &newDate, const QTime *newTime = 0 ) { if ( inc ) { inc = inc->clone(); inc->recreate(); } if ( inc && newDate.isValid() ) { if ( inc->type() == "Event" ) { Event *anEvent = static_cast<Event*>( inc ); // Calculate length of event int daysOffset = anEvent->dtStart().date().daysTo( anEvent->dtEnd().date() ); // new end date if event starts at the same time on the new day KDateTime endDate( anEvent->dtEnd() ); endDate.setDate( newDate.addDays( daysOffset ) ); KDateTime startDate( anEvent->dtStart() ); startDate.setDate( newDate ); if ( newTime ) { // additional offset for new time of day int addSecsOffset( anEvent->dtStart().time().secsTo( *newTime ) ); endDate=endDate.addSecs( addSecsOffset ); startDate.setTime( *newTime ); } anEvent->setDtStart( startDate ); anEvent->setDtEnd( endDate ); } else if ( inc->type() == "Todo" ) { Todo *anTodo = static_cast<Todo*>( inc ); KDateTime dueDate( anTodo->dtDue() ); dueDate.setDate( newDate ); if ( newTime ) { dueDate.setTime( *newTime ); } anTodo->setDtDue( dueDate ); } else if ( inc->type() == "Journal" ) { Journal *anJournal = static_cast<Journal*>( inc ); KDateTime startDate( anJournal->dtStart() ); startDate.setDate( newDate ); if ( newTime ) { startDate.setTime( *newTime ); } else { startDate.setTime( QTime( 0, 0, 0 ) ); } anJournal->setDtStart( startDate ); } else { kDebug() << "Trying to paste unknown incidence of type" << inc->type(); } } return inc; }
bool Todo::operator==( const Todo &todo ) const { return Incidence::operator==( todo ) && dtDue() == todo.dtDue() && hasDueDate() == todo.hasDueDate() && hasStartDate() == todo.hasStartDate() && completed() == todo.completed() && hasCompletedDate() == todo.hasCompletedDate() && percentComplete() == todo.percentComplete(); }
void KOWhatsNextView::updateView() { KIconLoader kil("kdepim"); QString *ipath = new QString(); kil.loadIcon("kdepim",KIcon::NoGroup,32,KIcon::DefaultState,ipath); mText = "<table width=\"100%\">\n"; mText += "<tr bgcolor=\"#3679AD\"><td><h1>"; mText += "<img src=\""; mText += *ipath; mText += "\">"; mText += "<font color=\"white\"> "; mText += i18n("What's Next?") + "</font></h1>"; mText += "</td></tr>\n<tr><td>"; mText += "<h2>"; if ( mStartDate.daysTo( mEndDate ) < 1 ) { mText += KGlobal::locale()->formatDate( mStartDate ); } else { mText += i18n("Date from - to", "%1 - %2") .arg( KGlobal::locale()->formatDate( mStartDate ) ) .arg( KGlobal::locale()->formatDate( mEndDate ) ); } mText+="</h2>\n"; Event::List events; for ( QDate date = mStartDate; date <= mEndDate; date = date.addDays( 1 ) ) events += calendar()->events(date, EventSortStartDate, SortDirectionAscending); if (events.count() > 0) { mText += "<p></p>"; kil.loadIcon("appointment",KIcon::NoGroup,22,KIcon::DefaultState,ipath); mText += "<h2><img src=\""; mText += *ipath; mText += "\">"; mText += i18n("Events:") + "</h2>\n"; mText += "<table>\n"; Event::List::ConstIterator it; for( it = events.begin(); it != events.end(); ++it ) { Event *ev = *it; if ( !ev->doesRecur() ){ appendEvent(ev); } else { // FIXME: This should actually be cleaned up. Libkcal should // provide a method to return a list of all recurrences in a // given time span. Recurrence *recur = ev->recurrence(); int duration = ev->dtStart().secsTo( ev->dtEnd() ); QDateTime start = recur->getPreviousDateTime( QDateTime( mStartDate, QTime() ) ); QDateTime end = start.addSecs( duration ); if ( end.date() >= mStartDate ) { appendEvent( ev, start, end ); } start = recur->getNextDateTime( start ); while ( start.isValid() && start.date() <= mEndDate ) { appendEvent( ev, start ); start = recur->getNextDateTime( start ); } } } mText += "</table>\n"; } mTodos.clear(); Todo::List todos = calendar()->todos( TodoSortDueDate, SortDirectionAscending ); if ( todos.count() > 0 ) { kil.loadIcon("todo",KIcon::NoGroup,22,KIcon::DefaultState,ipath); mText += "<h2><img src=\""; mText += *ipath; mText += "\">"; mText += i18n("To-do:") + "</h2>\n"; mText += "<ul>\n"; Todo::List::ConstIterator it; for( it = todos.begin(); it != todos.end(); ++it ) { Todo *todo = *it; if ( !todo->isCompleted() && todo->hasDueDate() && todo->dtDue().date() <= mEndDate ) appendTodo(todo); } bool gotone = false; int priority = 1; while (!gotone && priority<=9 ) { for( it = todos.begin(); it != todos.end(); ++it ) { Todo *todo = *it; if (!todo->isCompleted() && (todo->priority() == priority) ) { appendTodo(todo); gotone = true; } } priority++; kdDebug(5850) << "adding the todos..." << endl; } mText += "</ul>\n"; } QStringList myEmails( KOPrefs::instance()->allEmails() ); int replies = 0; events = calendar()->events( QDate::currentDate(), QDate(2975,12,6) ); Event::List::ConstIterator it2; for( it2 = events.begin(); it2 != events.end(); ++it2 ) { Event *ev = *it2; Attendee *me = ev->attendeeByMails( myEmails ); if (me!=0) { if (me->status()==Attendee::NeedsAction && me->RSVP()) { if (replies == 0) { mText += "<p></p>"; kil.loadIcon("reply",KIcon::NoGroup,22,KIcon::DefaultState,ipath); mText += "<h2><img src=\""; mText += *ipath; mText += "\">"; mText += i18n("Events and to-dos that need a reply:") + "</h2>\n"; mText += "<table>\n"; } replies++; appendEvent( ev ); } } } todos = calendar()->todos(); Todo::List::ConstIterator it3; for( it3 = todos.begin(); it3 != todos.end(); ++it3 ) { Todo *to = *it3; Attendee *me = to->attendeeByMails( myEmails ); if (me!=0) { if (me->status()==Attendee::NeedsAction && me->RSVP()) { if (replies == 0) { mText += "<p></p>"; kil.loadIcon("reply",KIcon::NoGroup,22,KIcon::DefaultState,ipath); mText += "<h2><img src=\""; mText += *ipath; mText += "\">"; mText += i18n("Events and to-dos that need a reply:") + "</h2>\n"; mText += "<table>\n"; } replies++; appendEvent(to); } } kdDebug () << "check for todo-replies..." << endl; } if (replies > 0 ) mText += "</table>\n"; mText += "</td></tr>\n</table>\n"; kdDebug(5850) << "KOWhatsNextView::updateView: text: " << mText << endl; delete ipath; mView->setText(mText); }
void SearchDialog::search(const QRegExp &re) { QDate startDt = mStartDate->date(); QDate endDt = mEndDate->date(); Event::List events; if(mEventsCheck->isChecked()) { events = mCalendar->events(startDt, endDt, mInclusiveCheck->isChecked()); } Todo::List todos; if(mTodosCheck->isChecked()) { if(mIncludeUndatedTodos->isChecked()) { Todo::List alltodos = mCalendar->todos(); Todo::List::iterator it; Todo *todo; for(it = alltodos.begin(); it != alltodos.end(); ++it) { todo = *it; if((!todo->hasStartDate() && !todo->hasDueDate()) || // undated (todo->hasStartDate() && (todo->dtStart() >= startDt) && (todo->dtStart() <= endDt)) || // start dt in range (todo->hasDueDate() && (todo->dtDue().date() >= startDt) && (todo->dtDue() <= endDt)) || // due dt in range (todo->hasCompletedDate() && (todo->completed().date() >= startDt) && (todo->completed() <= endDt))) // completed dt in range { todos.append(todo); } } } else { QDate dt = startDt; while(dt <= endDt) { todos += mCalendar->todos(dt); dt = dt.addDays(1); } } } Journal::List journals; if(mJournalsCheck->isChecked()) { QDate dt = startDt; while(dt <= endDt) { journals += mCalendar->journals(dt); dt = dt.addDays(1); } } Incidence::List allIncidences = Calendar::mergeIncidenceList(events, todos, journals); mMatchedEvents.clear(); Incidence::List::ConstIterator it; for(it = allIncidences.begin(); it != allIncidences.end(); ++it) { Incidence *ev = *it; if(mSummaryCheck->isChecked()) { #if QT_VERSION >= 300 if(re.search(ev->summary()) != -1) { #else if(re.match(ev->summary()) != -1) { #endif mMatchedEvents.append(ev); continue; } } if(mDescriptionCheck->isChecked()) { #if QT_VERSION >= 300 if(re.search(ev->description()) != -1) { #else if(re.match(ev->description()) != -1) { #endif mMatchedEvents.append(ev); continue; } } if(mCategoryCheck->isChecked()) { #if QT_VERSION >= 300 if(re.search(ev->categoriesStr()) != -1) { #else if(re.match(ev->categoriesStr()) != -1) { #endif mMatchedEvents.append(ev); continue; } } } }
/** Dissociate a single occurrence or all future occurrences from a recurring sequence. The new incidence is returned, but not automatically inserted into the calendar, which is left to the calling application */ Incidence *Calendar::dissociateOccurrence(Incidence *incidence, QDate date, bool single) { if(!incidence || !incidence->doesRecur()) return 0; Incidence *newInc = incidence->clone(); newInc->recreate(); newInc->setRelatedTo(incidence); Recurrence *recur = newInc->recurrence(); if(single) { recur->clear(); } else { // Adjust the recurrence for the future incidences. In particular // adjust the "end after n occurrences" rules! "No end date" and "end by ..." // don't need to be modified. int duration = recur->duration(); if(duration > 0) { int doneduration = recur->durationTo(date.addDays(-1)); if(doneduration >= duration) { kdDebug(5850) << "The dissociated event already occurred more often " << "than it was supposed to ever occur. ERROR!" << endl; recur->clear(); } else { recur->setDuration(duration - doneduration); } } } // Adjust the date of the incidence if(incidence->type() == "Event") { Event *ev = static_cast<Event *>(newInc); QDateTime start(ev->dtStart()); int daysTo = start.date().daysTo(date); ev->setDtStart(start.addDays(daysTo)); ev->setDtEnd(ev->dtEnd().addDays(daysTo)); } else if(incidence->type() == "Todo") { Todo *td = static_cast<Todo *>(newInc); bool haveOffset = false; int daysTo = 0; if(td->hasDueDate()) { QDateTime due(td->dtDue()); daysTo = due.date().daysTo(date); td->setDtDue(due.addDays(daysTo), true); haveOffset = true; } if(td->hasStartDate()) { QDateTime start(td->dtStart()); if(!haveOffset) daysTo = start.date().daysTo(date); td->setDtStart(start.addDays(daysTo)); haveOffset = true; } } recur = incidence->recurrence(); if(recur) { if(single) { recur->addExDate(date); } else { // Make sure the recurrence of the past events ends // at the corresponding day recur->setEndDate(date.addDays(-1)); } } return newInc; }