Commit f1ddc1e4 authored by Volker Krause's avatar Volker Krause
Browse files

Adapt to OccurrenceIterator API changes

Allows to remove a bunch of KDateTime usage here.
parent a0de1e80
......@@ -1810,10 +1810,9 @@ bool AgendaView::displayIncidence(const KCalCore::Incidence::Ptr &incidence, bo
KCalCore::Event::Ptr event = CalendarSupport::event(incidence);
const QDate today = QDate::currentDate();
KCalCore::DateTimeList::iterator t;
KDateTime firstVisibleDateTime(d->mSelectedDates.first(), KDateTime::LocalZone);
KDateTime lastVisibleDateTime(d->mSelectedDates.last(), KDateTime::LocalZone);
QDateTime firstVisibleDateTime(d->mSelectedDates.first(), QTime(0, 0, 0), Qt::LocalTime);
QDateTime lastVisibleDateTime(d->mSelectedDates.last(), QTime(23, 59, 59, 999), Qt::LocalTime);
// Optimization, very cheap operation that discards incidences that aren't in the timespan
if (!d->mightBeVisible(incidence)) {
......@@ -1822,10 +1821,10 @@ bool AgendaView::displayIncidence(const KCalCore::Incidence::Ptr &incidence, bo
lastVisibleDateTime.setTime(QTime(23, 59, 59, 59));
firstVisibleDateTime.setTime(QTime(0, 0));
KCalCore::DateTimeList dateTimeList;
KCalCore::SortableList<QDateTime> dateTimeList;
const KDateTime incDtStart = incidence->dtStart().toLocalZone();
const KDateTime incDtEnd = incidence->dateTime(KCalCore::Incidence::RoleEnd).toLocalZone();
const QDateTime incDtStart = KCalCore::k2q(incidence->dtStart().toLocalZone());
const QDateTime incDtEnd = KCalCore::k2q(incidence->dateTime(KCalCore::Incidence::RoleEnd).toLocalZone());
bool alreadyAddedToday = false;
......@@ -1839,13 +1838,13 @@ bool AgendaView::displayIncidence(const KCalCore::Incidence::Ptr &incidence, bo
// if there's a multiday event that starts before firstVisibleDateTime but ends after
// lets include it. timesInInterval() ignores incidences that aren't totaly inside
// the range
const KDateTime startDateTimeWithOffset = firstVisibleDateTime.addDays(-eventDuration);
const QDateTime startDateTimeWithOffset = firstVisibleDateTime.addDays(-eventDuration);
KCalCore::OccurrenceIterator rIt(*calendar(), incidence,
startDateTimeWithOffset, lastVisibleDateTime);
while (rIt.hasNext()) {
rIt.next();
const auto occurrenceDate = rIt.occurrenceStartDate().toLocalZone().dateTime();
const auto occurrenceDate = rIt.occurrenceStartDate().toLocalTime();
const bool makesDayBusy =
preferences()->colorAgendaBusyDays() && makesWholeDayBusy(rIt.incidence());
if (makesDayBusy) {
......@@ -1860,13 +1859,13 @@ bool AgendaView::displayIncidence(const KCalCore::Incidence::Ptr &incidence, bo
}
} else {
KDateTime dateToAdd; // date to add to our date list
KDateTime incidenceStart;
KDateTime incidenceEnd;
QDateTime dateToAdd; // date to add to our date list
QDateTime incidenceStart;
QDateTime incidenceEnd;
if (todo && todo->hasDueDate() && !todo->isOverdue()) {
// If it's not overdue it will be shown at the original date (not today)
dateToAdd = todo->dtDue().toLocalZone();
dateToAdd = KCalCore::k2q(todo->dtDue().toLocalZone());
// To-dos are drawn with the bottom of the rectangle at dtDue
// if dtDue is at 00:00, then it should be displayed in the previous day, at 23:59
......@@ -1880,7 +1879,7 @@ bool AgendaView::displayIncidence(const KCalCore::Incidence::Ptr &incidence, bo
incidenceEnd = incDtEnd;
}
if (dateToAdd.isValid() && dateToAdd.isDateOnly()) {
if (dateToAdd.isValid() && incidence->allDay()) {
// so comparisons with < > actually work
dateToAdd.setTime(QTime(0, 0));
incidenceEnd.setTime(QTime(23, 59, 59, 59));
......@@ -1892,7 +1891,7 @@ bool AgendaView::displayIncidence(const KCalCore::Incidence::Ptr &incidence, bo
}
// ToDo items shall be displayed today if they are overdue
const KDateTime dateTimeToday = KDateTime(today, KDateTime::LocalZone);
const QDateTime dateTimeToday = QDateTime(today, QTime(0, 0), Qt::LocalTime);
if (todo &&
todo->isOverdue() &&
dateTimeToday >= firstVisibleDateTime &&
......@@ -1905,13 +1904,13 @@ bool AgendaView::displayIncidence(const KCalCore::Incidence::Ptr &incidence, bo
}
const bool makesDayBusy = preferences()->colorAgendaBusyDays() && makesWholeDayBusy(incidence);
for (t = dateTimeList.begin(); t != dateTimeList.end(); ++t) {
for (auto t = dateTimeList.begin(); t != dateTimeList.end(); ++t) {
if (makesDayBusy) {
KCalCore::Event::List &busyEvents = d->mBusyDays[(*t).date()];
busyEvents.append(event);
}
d->insertIncidence(incidence, KCalCore::k2q(t->toLocalZone()), KCalCore::k2q(t->toLocalZone()), createSelected);
d->insertIncidence(incidence, t->toLocalTime(), t->toLocalTime(), createSelected);
}
// Can be multiday
......
......@@ -506,7 +506,7 @@ void MonthView::reloadIncidences()
// build global event list
const bool colorMonthBusyDays = preferences()->colorMonthBusyDays();
KCalCore::OccurrenceIterator occurIter(*calendar(), KDateTime(actualStartDateTime()), KDateTime(actualEndDateTime()));
KCalCore::OccurrenceIterator occurIter(*calendar(), actualStartDateTime(), actualEndDateTime());
while (occurIter.hasNext()) {
occurIter.next();
......@@ -536,7 +536,7 @@ void MonthView::reloadIncidences()
calendar(),
item,
occurIter.incidence(),
occurIter.occurrenceStartDate().toLocalZone().date());
occurIter.occurrenceStartDate().toLocalTime().date());
d->scene->mManagerList << manager;
if (d->selectedItemId == item.id() &&
manager->realStartDate() == d->selectedItemDate) {
......
......@@ -32,6 +32,7 @@
#include <CalendarSupport/Utils>
#include <Akonadi/Calendar/IncidenceChanger>
#include <KCalCore/OccurrenceIterator>
#include <KCalCore/Utils>
#include "calendarview_debug.h"
......@@ -124,13 +125,13 @@ void TimelineView::Private::insertIncidence(const Akonadi::Item &aitem, const QD
}
if (incidence->recurs()) {
KCalCore::OccurrenceIterator occurIter(*(q->calendar()), incidence, KDateTime(day, QTime(0, 0, 0)), KDateTime(day, QTime(23, 59, 59)));
KCalCore::OccurrenceIterator occurIter(*(q->calendar()), incidence, QDateTime(day, QTime(0, 0, 0)), QDateTime(day, QTime(23, 59, 59)));
while (occurIter.hasNext()) {
occurIter.next();
const Akonadi::Item akonadiItem = q->calendar()->item(occurIter.incidence());
const KDateTime startOfOccurrence = occurIter.occurrenceStartDate();
const KDateTime endOfOccurrence = occurIter.incidence()->endDateForStart(startOfOccurrence);
item->insertIncidence(akonadiItem, startOfOccurrence.toLocalZone().dateTime(), endOfOccurrence.toLocalZone().dateTime());
const QDateTime startOfOccurrence = occurIter.occurrenceStartDate();
const QDateTime endOfOccurrence = KCalCore::k2q(occurIter.incidence()->endDateForStart(KCalCore::q2k(startOfOccurrence)));
item->insertIncidence(akonadiItem, startOfOccurrence.toLocalTime(), endOfOccurrence.toLocalTime());
}
} else {
if (incidence->dtStart().date() == day ||
......
......@@ -90,16 +90,12 @@ public:
foreach (const KCalCore::Event::Ptr &e, mEventList)
{
Q_ASSERT(e);
KDateTime selectedStart(mTimeSpentView->mStartDate,
QTime(0, 0),
e->dtStart().timeSpec());
QDateTime selectedStart(mTimeSpentView->mStartDate, QTime(0, 0), KCalCore::specToZone(e->dtStart().timeSpec()));
KDateTime selectedEnd(mTimeSpentView->mEndDate.addDays(1),
QTime(0, 0),
e->dtEnd().timeSpec());
QDateTime selectedEnd(mTimeSpentView->mEndDate.addDays(1), QTime(0, 0), KCalCore::specToZone(e->dtEnd().timeSpec()));
KDateTime start;
KDateTime end;
QDateTime start;
QDateTime end;
// duration of all occurrences added
int totalDuration = 0;
......@@ -109,26 +105,22 @@ public:
// timesInInterval only return events that have their start inside the interval
// so we resize the interval by -eventDuration
const auto times = e->recurrence()->timesInInterval(
KCalCore::k2q(selectedStart).addSecs(-eventDuration), KCalCore::k2q(selectedEnd));
const auto times = e->recurrence()->timesInInterval(selectedStart.addSecs(-eventDuration), selectedEnd);
foreach (const QDateTime &dt, times) {
const auto kdt = KCalCore::q2k(dt);
// either the event's start or the event's end must be in the view's interval
if (kdt >= selectedStart ||
kdt.addSecs(eventDuration) >= selectedStart) {
if (dt >= selectedStart || dt.addSecs(eventDuration) >= selectedStart) {
start = kdt > selectedStart ? kdt : selectedStart;
end = kdt.addSecs(eventDuration) < selectedEnd ?
kdt.addSecs(eventDuration) : selectedEnd;
start = dt > selectedStart ? dt : selectedStart;
end = dt.addSecs(eventDuration) < selectedEnd ? dt.addSecs(eventDuration) : selectedEnd;
totalDuration += start.secsTo(end);
}
}
} else {
// The event's start can be before the view's start date or end after the view's end
start = e->dtStart() > selectedStart ? e->dtStart() : selectedStart;
end = e->dtEnd() < selectedEnd ? e->dtEnd() : selectedEnd;
start = KCalCore::k2q(e->dtStart()) > selectedStart ? KCalCore::k2q(e->dtStart()) : selectedStart;
end = KCalCore::k2q(e->dtEnd()) < selectedEnd ? KCalCore::k2q(e->dtEnd()) : selectedEnd;
totalDuration += start.secsTo(end);
}
......
......@@ -29,7 +29,6 @@
#include <CalendarSupport/Utils>
#include <KCalUtils/IncidenceFormatter>
#include <KCalCore/Utils>
#include <KIconLoader>
......@@ -128,17 +127,17 @@ void WhatsNextView::updateView()
} else {
KCalCore::Recurrence *recur = ev->recurrence();
int duration = ev->dtStart().secsTo(ev->dtEnd());
KDateTime start = KCalCore::q2k(recur->getPreviousDateTime(QDateTime(mStartDate, QTime(), Qt::LocalTime)));
KDateTime end = start.addSecs(duration);
KDateTime endDate(mEndDate, QTime(23, 59, 59), KDateTime::LocalZone);
QDateTime start = recur->getPreviousDateTime(QDateTime(mStartDate, QTime(), Qt::LocalTime));
QDateTime end = start.addSecs(duration);
QDateTime endDate(mEndDate, QTime(23, 59, 59), Qt::LocalTime);
if (end.date() >= mStartDate) {
appendEvent(ev, start.toLocalZone().dateTime(), end.toLocalZone().dateTime());
appendEvent(ev, start.toLocalTime(), end.toLocalTime());
}
const auto times = recur->timesInInterval(KCalCore::k2q(start), KCalCore::k2q(endDate));
const auto times = recur->timesInInterval(start, endDate);
int count = times.count();
if (count > 0) {
int i = 0;
if (times[0] == KCalCore::k2q(start)) {
if (times[0] == start) {
++i; // start has already been appended
}
if (!times[count - 1].isValid()) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment