Esempio n. 1
0
void CompatPre32::fixRecurrence( const Incidence::Ptr &incidence )
{
  Recurrence *recurrence = incidence->recurrence();
  if ( recurrence->recurs() &&  recurrence->duration() > 0 ) {
    recurrence->setDuration( recurrence->duration() + incidence->recurrence()->exDates().count() );
  }
  // Call base class method now that everything else is done
  CompatPre35::fixRecurrence( incidence );
}
Esempio n. 2
0
/** 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;
}