void AlarmDialog::addIncidence( const Akonadi::Item &incidenceitem,
                                const QDateTime &reminderAt,
                                const QString &displayText )
{
  Incidence::Ptr incidence = CalendarSupport::incidence( incidenceitem );
  ReminderListItem *item = searchByItem( incidenceitem );
  if ( !item ) {
    item = new ReminderListItem( incidenceitem, mIncidenceTree );
  }
  item->mNotified = false;
  item->mHappening = KDateTime();
  item->mRemindAt = reminderAt;
  item->mTrigger = KDateTime::currentLocalDateTime();
  item->mDisplayText = displayText;
  item->setText( 0, cleanSummary( incidence->summary() ) );

  Event::Ptr event;
  Todo::Ptr todo;

  QString displayStr;
  const KDateTime dateTime = triggerDateForIncidence( incidence, reminderAt,
                                                      displayStr );

  if ( incidence->type() == Incidence::TypeEvent ) {
    item->setIcon( 0, SmallIcon( "view-calendar-day" ) );
  } else if ( incidence->type() == Incidence::TypeTodo ) {
    item->setIcon( 0, SmallIcon( "view-calendar-tasks" ) );
  }

  item->mHappening = dateTime;
  item->setText( 1, displayStr );

  item->setText( 2, IncidenceFormatter::dateTimeToString(
                   item->mTrigger, false, true, KDateTime::Spec::LocalZone() ) );
  QString tip =
    IncidenceFormatter::toolTipStr(
      CalendarSupport::displayName( mCalendar, incidenceitem.parentCollection() ),
      incidence,
      item->mRemindAt.date(), true,
      KDateTime::Spec::LocalZone() );
  if ( !item->mDisplayText.isEmpty() ) {
    tip += "<br>" + item->mDisplayText;
  }
  item->setToolTip( 0, tip );
  item->setToolTip( 1, tip );
  item->setToolTip( 2, tip );
  item->setData( 0, QTreeWidgetItem::UserType, false );

  mIncidenceTree->setCurrentItem( item );
  showDetails();
  slotSave();
}
Пример #2
0
void DndFactoryTest::testPasteTodo()
{
  MemoryCalendar::Ptr calendar( new MemoryCalendar( QString() ) );

  DndFactory factory( calendar );

  Todo::Ptr todo( new Todo() );
  todo->setSummary( QLatin1String( "Summary 1" ) );
  todo->setDtDue( KDateTime( QDate( 2010, 8, 9 ) ) );

  Incidence::List incidencesToPaste;
  incidencesToPaste.append( todo );

  QVERIFY( factory.copyIncidences( incidencesToPaste ) );

  const KDateTime newDateTime( QDate( 2011, 1, 1 ), QTime( 10, 10 ) );

  Incidence::List pastedIncidences = factory.pasteIncidences( newDateTime );
  QVERIFY( pastedIncidences.size() == 1 );

  Incidence::Ptr incidence = pastedIncidences.first();

  QVERIFY( incidence->type() == Incidence::TypeTodo );

  // check if a new uid was generated.
  QVERIFY( incidence->uid() != todo->uid() );

  Todo::Ptr pastedTodo = incidence.staticCast<Todo>();

  QVERIFY( pastedTodo->dtDue() == newDateTime );
  QVERIFY( pastedTodo->summary() == todo->summary() );

}
Пример #3
0
void DndFactoryTest::testPasteAllDayEvent2()
{

  MemoryCalendar::Ptr calendar( new MemoryCalendar( QString() ) );

  DndFactory factory( calendar );

  Event::Ptr allDayEvent( new Event() );
  allDayEvent->setSummary( QLatin1String( "Summary 2" ) );
  allDayEvent->setDtStart( KDateTime( QDate( 2010, 8, 8 ) ) );
  allDayEvent->setDtEnd( KDateTime( QDate( 2010, 8, 9 ) ) );
  const QString originalUid = allDayEvent->uid();

  Incidence::List incidencesToPaste;
  incidencesToPaste.append( allDayEvent );

  QVERIFY( factory.copyIncidences( incidencesToPaste ) );

  const KDateTime newDateTime( QDate( 2011, 1, 1 ) );
  const uint originalLength = allDayEvent->dtStart().secsTo( allDayEvent->dtEnd() );

  // paste at the new time
  Incidence::List pastedIncidences = factory.pasteIncidences( newDateTime );

  // we only copied one incidence
  QVERIFY( pastedIncidences.size() == 1 );

  Incidence::Ptr incidence = pastedIncidences.first();

  QVERIFY( incidence->type() == Incidence::TypeEvent );

  // check if a new uid was generated.
  QVERIFY( incidence->uid() != originalUid );

  // the new dateTime didn't have time component
  QVERIFY( incidence->allDay() );

  Event::Ptr pastedEvent = incidence.staticCast<Event>();
  const uint newLength = pastedEvent->dtStart().secsTo( pastedEvent->dtEnd() );

  kDebug() << "originalLength was " << originalLength << "; and newLength is "
           << newLength << "; old dtStart was " << allDayEvent->dtStart()
           << " and old dtEnd was " << allDayEvent->dtEnd() << endl
           << "; new dtStart is " << pastedEvent->dtStart()
           << " and new dtEnd is " << pastedEvent->dtEnd();

  QVERIFY( originalLength == newLength );
  QVERIFY( pastedEvent->dtStart() == newDateTime );
  QVERIFY( pastedEvent->summary() == allDayEvent->summary() );
}
bool AlarmDialog::openIncidenceEditorNG( const Akonadi::Item &item )
{
  if ( !IncidenceEditorNG::GroupwareIntegration::isActive() ) {
    //TODO: Why do we need this to have a simple editor?
    IncidenceEditorNG::GroupwareIntegration::activate( mCalendar );
  }
  Incidence::Ptr incidence = CalendarSupport::incidence( item );
  IncidenceEditorNG::IncidenceDialog *dialog =
    IncidenceEditorNG::IncidenceDialogFactory::create(
      false, /*doesn't need initial saving*/
      incidence->type(), this );
  dialog->load( item );
  return true;
}
Пример #5
0
void DndFactoryTest::testPasteAllDayEvent()
{

  MemoryCalendar::Ptr calendar( new MemoryCalendar( QString() ) );

  DndFactory factory( calendar );

  Event::Ptr allDayEvent( new Event() );
  allDayEvent->setSummary( QLatin1String( "Summary 1" ) );
  allDayEvent->setDtStart( KDateTime( QDate( 2010, 8, 8 ) ) );
  allDayEvent->setDtEnd( KDateTime( QDate( 2010, 8, 9 ) ) );
  const QString originalUid = allDayEvent->uid();
  const bool originalIsAllDay = allDayEvent->allDay();

  Incidence::List incidencesToPaste;
  incidencesToPaste.append( allDayEvent );

  QVERIFY( factory.copyIncidences( incidencesToPaste ) );

  Incidence::List pastedIncidences = factory.pasteIncidences();
  QVERIFY( pastedIncidences.size() == 1 );

  Incidence::Ptr incidence = pastedIncidences.first();

  QVERIFY( incidence->type() == Incidence::TypeEvent );

  // check if a new uid was generated.
  QVERIFY( incidence->uid() != originalUid );

  // we passed an invalid KDateTime to pasteIncidences() so dates don't change.
  QVERIFY( incidence->allDay() == originalIsAllDay );

  Event::Ptr pastedEvent = incidence.staticCast<Event>();

  QVERIFY( pastedEvent->dtStart() == allDayEvent->dtStart() );
  QVERIFY( pastedEvent->dtEnd() == allDayEvent->dtEnd() );
  QVERIFY( pastedEvent->summary() == allDayEvent->summary() );
}
CallId Scheduler::acceptCancel( const IncidenceBase::Ptr &incidence,
                                ScheduleMessage::Status status,
                                const QString &attendee )
{
  Incidence::Ptr inc = incidence.staticCast<Incidence>();
  if ( !inc ) {
    return -1;
  }

  const CallId callId = ++d->mLatestCallId;
  ResultCode resultCode = ResultCodeSuccess;
  QString errorMessage;

  if ( inc->type() == IncidenceBase::TypeFreeBusy ) {
    // reply to this request is handled in korganizer's incomingdialog
    emitOperationFinished( callId, resultCode, errorMessage );
    return callId;
  }

  const Incidence::List existingIncidences = d->mCalendar->incidencesFromSchedulingID( inc->uid() );
  kDebug() << "Scheduler::acceptCancel="
           << Stringify::scheduleMessageStatus( status ) //krazy2:exclude=kdebug
           << ": found " << existingIncidences.count()
           << " incidences with schedulingID " << inc->schedulingID();

  Incidence::List::ConstIterator incit = existingIncidences.begin();
  for ( ; incit != existingIncidences.end() ; ++incit ) {
    Incidence::Ptr i = *incit;
    kDebug() << "Considering this found event ("
             << ( i->isReadOnly() ? "readonly" : "readwrite" )
             << ") :" << d->mFormat->toString( i );

    // If it's readonly, we can't possible remove it.
    if ( i->isReadOnly() ) {
      continue;
    }

    // Code for new invitations:
    // We cannot check the value of "status" to be RequestNew because
    // "status" comes from a similar check inside libical, where the event
    // is compared to other events in the calendar. But if we have another
    // version of the event around (e.g. shared folder for a group), the
    // status could be RequestNew, Obsolete or Updated.
    kDebug() << "looking in " << i->uid() << "'s attendees";

    // This is supposed to be a new request, not an update - however we want
    // to update the existing one to handle the "clicking more than once
    // on the invitation" case. So check the attendee status of the attendee.
    bool isMine = true;
    const Attendee::List attendees = i->attendees();
    Attendee::List::ConstIterator ait;
    for ( ait = attendees.begin(); ait != attendees.end(); ++ait ) {
      if ( (*ait)->email() == attendee &&
           (*ait)->status() == Attendee::NeedsAction ) {
        // This incidence wasn't created by me - it's probably in a shared
        // folder and meant for someone else, ignore it.
        kDebug() << "ignoring " << i->uid()
                 << " since I'm still NeedsAction there";
        isMine = false;
        break;
      }
    }

    if ( isMine ) {
      //TODO_SERGIO: use ItemDeleteJob and make this async.
      kDebug() << "removing existing incidence " << i->uid();

      Akonadi::Item item = d->mCalendar->itemForIncidenceUid( i->uid() );
      bool emitResult = true;
      if ( item.isValid() ) {
        const int changeId = d->mChanger->deleteIncidence( item );

        if ( changeId >= 0 ) {
          d->mCallIdByChangeId.insert( changeId, callId );
          d->mDeletedIncidenceByChangeId.insert( changeId, i );
          emitResult = false; // will be emitted in the job result's slot.
        } else {
          resultCode = ResultCodeErrorDeletingIncidence;
          errorMessage = QLatin1String( "Error while trying to delete the incidence" );
        }
      } else {
        resultCode = ResultCodeIncidenceNotFound;
        errorMessage = QLatin1String( "Couldn't find incidence in calendar" );
      }

      if ( emitResult ) {
        deleteTransaction( incidence->uid() );
        errorMessage = QLatin1String( "Error deleting incidence" );
        emitOperationFinished( callId, resultCode, errorMessage );
      }

      return callId;
    }
  }

  // in case we didn't find the to-be-removed incidence
  if ( existingIncidences.count() > 0 && inc->revision() > 0 ) {
    KMessageBox::error(
      0,
      i18nc( "@info",
             "The event or task could not be removed from your calendar. "
             "Maybe it has already been deleted or is not owned by you. "
             "Or it might belong to a read-only or disabled calendar." ) );
    resultCode = ResultCodeIncidenceNotFound;
    errorMessage = QLatin1String( "Incidence not found" );
  }
  deleteTransaction( incidence->uid() );
  emitOperationFinished( callId, resultCode, errorMessage );

  return callId;
}
CallId Scheduler::acceptRequest( const IncidenceBase::Ptr &incidence,
                                 ScheduleMessage::Status status,
                                 const QString &email )
{
  Incidence::Ptr inc = incidence.staticCast<Incidence>() ;
  if ( !inc ) {
    kWarning() << "Accept what?";
    return -1;
  }

  const CallId callId = ++d->mLatestCallId;
  ResultCode resultCode = ResultCodeSuccess;
  QString errorMessage;

  if ( inc->type() == IncidenceBase::TypeFreeBusy ) {
    emitOperationFinished( callId, ResultCodeSuccess, QString() );
    // reply to this request is handled in korganizer's incomingdialog
    return callId;
  }

  const Incidence::List existingIncidences = d->mCalendar->incidencesFromSchedulingID( inc->uid() );
  kDebug() << "status=" << Stringify::scheduleMessageStatus( status ) //krazy:exclude=kdebug
           << ": found " << existingIncidences.count()
           << " incidences with schedulingID " << inc->schedulingID()
           << "; uid was = " << inc->uid();

  if ( existingIncidences.isEmpty() ) {
    // Perfectly normal if the incidence doesn't exist. This is probably
    // a new invitation.
    kDebug() << "incidence not found; calendar = " << d->mCalendar.data()
             << "; incidence count = " << d->mCalendar->incidences().count();
  }
  Incidence::List::ConstIterator incit = existingIncidences.begin();
  for ( ; incit != existingIncidences.end() ; ++incit ) {
    Incidence::Ptr existingIncidence = *incit;
    kDebug() << "Considering this found event ("
             << ( existingIncidence->isReadOnly() ? "readonly" : "readwrite" )
             << ") :" << d->mFormat->toString( existingIncidence );
    // If it's readonly, we can't possible update it.
    if ( existingIncidence->isReadOnly() ) {
      continue;
    }
    if ( existingIncidence->revision() <= inc->revision() ) {
      // The new incidence might be an update for the found one
      bool isUpdate = true;
      // Code for new invitations:
      // If you think we could check the value of "status" to be RequestNew:  we can't.
      // It comes from a similar check inside libical, where the event is compared to
      // other events in the calendar. But if we have another version of the event around
      // (e.g. shared folder for a group), the status could be RequestNew, Obsolete or Updated.
      kDebug() << "looking in " << existingIncidence->uid() << "'s attendees";
      // This is supposed to be a new request, not an update - however we want to update
      // the existing one to handle the "clicking more than once on the invitation" case.
      // So check the attendee status of the attendee.
      const Attendee::List attendees = existingIncidence->attendees();
      Attendee::List::ConstIterator ait;
      for ( ait = attendees.begin(); ait != attendees.end(); ++ait ) {
        if( (*ait)->email() == email && (*ait)->status() == Attendee::NeedsAction ) {
          // This incidence wasn't created by me - it's probably in a shared folder
          // and meant for someone else, ignore it.
          kDebug() << "ignoring "
                   << existingIncidence->uid() << " since I'm still NeedsAction there";
          isUpdate = false;
          break;
        }
      }
      if ( isUpdate ) {
        if ( existingIncidence->revision() == inc->revision() &&
             existingIncidence->lastModified() > inc->lastModified() ) {
          // This isn't an update - the found incidence was modified more recently
          deleteTransaction( existingIncidence->uid() );
          errorMessage = QLatin1String( "This isn't an update - "
                                        "the found incidence was modified more recently" );
          kDebug() << errorMessage;
          emitOperationFinished( callId, ResultCodeNotUpdate, errorMessage );

          return callId;
        }
        kDebug() << "replacing existing incidence " << existingIncidence->uid();

        bool emitResult = true;
        const QString oldUid = existingIncidence->uid();
        if ( existingIncidence->type() != inc->type() ) {
          errorMessage = QLatin1String( "Cannot assign two different incidence types" );
          resultCode = ResultCodeDifferentIncidenceTypes;
        } else {
          IncidenceBase *existingIncidenceBase = existingIncidence.data();
          IncidenceBase *incBase = inc.data();
          *existingIncidenceBase = *incBase;
          existingIncidence->setSchedulingID( inc->uid(), oldUid );

          Akonadi::Item item = d->mCalendar->itemForIncidenceUid( oldUid );
          item.setPayload<Incidence::Ptr>( existingIncidence );
          if ( item.isValid() ) {
            const int changeId = d->mChanger->modifyIncidence( item );

            if ( changeId >= 0 ) {
              d->mCallIdByChangeId.insert( changeId, callId );
              emitResult = false; // will be emitted in the job result's slot.
            } else {
              resultCode = ResultCodeErrorUpdatingIncidence;
              errorMessage = QLatin1String( "Error while trying to update the incidence" );
            }
          } else {
            resultCode = ResultCodeIncidenceNotFound;
            errorMessage = QLatin1String( "Couldn't find incidence in calendar" );
          }
        }

        if ( emitResult ) {
          deleteTransaction( incidence->uid() );
          emitOperationFinished( callId, resultCode, errorMessage );
        }
        return callId;
      }
    } else {
      // This isn't an update - the found incidence has a bigger revision number

      deleteTransaction( incidence->uid() );

      errorMessage = QLatin1String( "This isn't an update - "
                                    "the found incidence has a bigger revision number" );
      kDebug() << errorMessage;
      emitOperationFinished( callId, ResultCodeNotUpdate, errorMessage );

      return callId;
    }
  }

  // Move the uid to be the schedulingID and make a unique UID
  inc->setSchedulingID( inc->uid(), CalFormat::createUniqueId() );
  // notify the user in case this is an update and we didn't find the to-be-updated incidence
  if ( existingIncidences.count() == 0 && inc->revision() > 0 ) {
    KMessageBox::information(
      0,
      i18nc( "@info",
             "<para>You accepted an invitation update, but an earlier version of the "
             "item could not be found in your calendar.</para>"
             "<para>This may have occurred because:<list>"
             "<item>the organizer did not include you in the original invitation</item>"
             "<item>you did not accept the original invitation yet</item>"
             "<item>you deleted the original invitation from your calendar</item>"
             "<item>you no longer have access to the calendar containing the invitation</item>"
             "</list></para>"
             "<para>This is not a problem, but we thought you should know.</para>" ),
      i18nc( "@title", "Cannot find invitation to be updated" ), "AcceptCantFindIncidence" );
  }
  kDebug() << "Storing new incidence with scheduling uid=" << inc->schedulingID()
           << " and uid=" << inc->uid();
  const int changeId = d->mChanger->createIncidence( inc );

  if ( changeId > 0 ) {
    d->mCallIdByChangeId[changeId] = callId;
  } else {
    emitOperationFinished( callId, ResultCodeErrorCreatingIncidence,
                           QLatin1String( "Error creating incidence" ) );
  }

  return callId;
}
CallId Scheduler::acceptPublish( const IncidenceBase::Ptr &newIncBase,
                                 ScheduleMessage::Status status,
                                 iTIPMethod method )
{
  if ( newIncBase->type() == IncidenceBase::TypeFreeBusy ) {
    return acceptFreeBusy( newIncBase, method );
  }

  const CallId callId = ++d->mLatestCallId;

  ResultCode resultCode = ResultCodeSuccess;
  QString errorMessage;

  kDebug() << "status=" << Stringify::scheduleMessageStatus( status ); //krazy:exclude=kdebug

  bool emitResult = true;

  Incidence::Ptr newInc = newIncBase.staticCast<Incidence>() ;
  Incidence::Ptr calInc = d->mCalendar->incidence( newIncBase->uid() );
  switch ( status ) {
    case ScheduleMessage::Unknown:
    case ScheduleMessage::PublishNew:
    case ScheduleMessage::PublishUpdate:
      if ( calInc && newInc ) {
        if ( ( newInc->revision() > calInc->revision() ) ||
             ( newInc->revision() == calInc->revision() &&
               newInc->lastModified() > calInc->lastModified() ) ) {
          const QString oldUid = calInc->uid();

          if ( calInc->type() != newInc->type() ) {
            kError() << "assigning different incidence types";
            resultCode = ResultCodeDifferentIncidenceTypes;
            errorMessage = QLatin1String( "Cannot assign two different incidence types" );
          } else {
            IncidenceBase *ci = calInc.data();
            IncidenceBase *ni = newInc.data();
            *ci = *ni;
            calInc->setSchedulingID( newInc->uid(), oldUid );

            Akonadi::Item item = d->mCalendar->itemForIncidenceUid( calInc->uid() );
            item.setPayload<Incidence::Ptr>( calInc );

            if ( item.isValid() ) {
              const int changeId = d->mChanger->modifyIncidence( item );

              if ( changeId >= 0 ) {
                d->mCallIdByChangeId.insert( changeId, callId );
                emitResult = false; // will be emitted in the job result's slot.
              } else {
                resultCode = ResultCodeErrorUpdatingIncidence;
                errorMessage = QLatin1String( "Error while trying to update the incidence" );
              }
            } else {
              resultCode = ResultCodeIncidenceNotFound;
              errorMessage = QLatin1String( "Couldn't find incidence in calendar" );
            }
          }
        } else {
          resultCode = ResultCodeNewIncidenceTooOld;
          errorMessage = QLatin1String( "A newer existing incidence already exists" );
        }
      } else {
        resultCode = ResultCodeInvalidIncidence;
        errorMessage = QLatin1String( "Incidence is invalid" );
      }
      break;
    case ScheduleMessage::Obsolete:
      // Success
      break;
    default:
      resultCode = ResultCodeUnknownStatus;
      errorMessage = QLatin1String( "Unhandled ScheduleMessage status" );
      break;
  }

  if ( emitResult ) {
    deleteTransaction( newIncBase->uid() );
    // Delayed signal, the caller must know this CallId first.
    emitOperationFinished( callId, resultCode, errorMessage );
  }

  return callId;
}
Пример #9
0
void HtmlExport::createTodoList(QTextStream *ts)
{
    Todo::List rawTodoList = d->mCalendar->todos();

    int index = 0;
    while (index < rawTodoList.count()) {
        Todo::Ptr ev = rawTodoList[ index ];
        Todo::Ptr subev = ev;
        const QString uid = ev->relatedTo();
        if (!uid.isEmpty()) {
            Incidence::Ptr inc = d->mCalendar->incidence(uid);
            if (inc && inc->type() == Incidence::TypeTodo) {
                Todo::Ptr todo = inc.staticCast<Todo>();
                if (!rawTodoList.contains(todo)) {
                    rawTodoList.append(todo);
                }
            }
        }
        index = rawTodoList.indexOf(subev);
        ++index;
    }

    // FIXME: Sort list by priorities. This is brute force and should be
    // replaced by a real sorting algorithm.
    Todo::List todoList;
    Todo::List::ConstIterator it;
    for (int i = 1; i <= 9; ++i) {
        for (it = rawTodoList.constBegin(); it != rawTodoList.constEnd(); ++it) {
            if ((*it)->priority() == i && checkSecrecy(*it)) {
                todoList.append(*it);
            }
        }
    }
    for (it = rawTodoList.constBegin(); it != rawTodoList.constEnd(); ++it) {
        if ((*it)->priority() == 0 && checkSecrecy(*it)) {
            todoList.append(*it);
        }
    }

    int columns = 3;
    *ts << "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">" << endl;
    *ts << "  <tr>" << endl;
    *ts << "    <th class=\"sum\">" << i18nc("@title:column", "To-do") << "</th>" << endl;
    *ts << "    <th>" << i18nc("@title:column to-do priority", "Priority") << "</th>" << endl;
    *ts << "    <th>" << i18nc("@title:column to-do percent completed",
                               "Completed") << "</th>" << endl;
    if (d->mSettings->taskDueDate()) {
        *ts << "    <th>" << i18nc("@title:column to-do due date", "Due Date") << "</th>" << endl;
        ++columns;
    }
    if (d->mSettings->taskLocation()) {
        *ts << "    <th>" << i18nc("@title:column to-do location", "Location") << "</th>" << endl;
        ++columns;
    }
    if (d->mSettings->taskCategories()) {
        *ts << "    <th>" << i18nc("@title:column to-do categories", "Categories") << "</th>" << endl;
        ++columns;
    }
    if (d->mSettings->taskAttendees()) {
        *ts << "    <th>" << i18nc("@title:column to-do attendees", "Attendees") << "</th>" << endl;
        ++columns;
    }
    *ts << "  </tr>" << endl;

    // Create top-level list.
    for (it = todoList.constBegin(); it != todoList.constEnd(); ++it) {
        if ((*it)->relatedTo().isEmpty()) {
            createTodo(ts, *it);
        }
    }

    // Create sub-level lists
    for (it = todoList.constBegin(); it != todoList.constEnd(); ++it) {
        Incidence::List relations =  d->mCalendar->relations((*it)->uid());

        if (relations.count()) {
            // Generate sub-to-do list
            *ts << "  <tr>" << endl;
            *ts << "    <td class=\"subhead\" colspan=";
            *ts << "\"" << QString::number(columns) << "\"";
            *ts << "><a name=\"sub" << (*it)->uid() << "\"></a>"
                << i18nc("@title:column sub-to-dos of the parent to-do",
                         "Sub-To-dos of: ") << "<a href=\"#"
                << (*it)->uid() << "\"><b>" << cleanChars((*it)->summary())
                << "</b></a></td>" << endl;
            *ts << "  </tr>" << endl;

            Todo::List sortedList;
            // FIXME: Sort list by priorities. This is brute force and should be
            // replaced by a real sorting algorithm.
            for (int i = 1; i <= 9; ++i) {
                Incidence::List::ConstIterator it2;
                for (it2 = relations.constBegin(); it2 != relations.constEnd(); ++it2) {
                    Todo::Ptr ev3 = (*it2).staticCast<Todo>();
                    if (ev3 && ev3->priority() == i) {
                        sortedList.append(ev3);
                    }
                }
            }
            Incidence::List::ConstIterator it2;
            for (it2 = relations.constBegin(); it2 != relations.constEnd(); ++it2) {
                Todo::Ptr ev3 = (*it2).staticCast<Todo>();
                if (ev3 && ev3->priority() == 0) {
                    sortedList.append(ev3);
                }
            }

            Todo::List::ConstIterator it3;
            for (it3 = sortedList.constBegin(); it3 != sortedList.constEnd(); ++it3) {
                createTodo(ts, *it3);
            }
        }
    }

    *ts << "</table>" << endl;
}