Commit 68474ae9 authored by Volker Krause's avatar Volker Krause

Bring ConflictResolver fully to QDateTime

parent c46b6e99
......@@ -24,7 +24,6 @@
#include <KCalCore/Event>
#include <KCalCore/Period>
#include <KCalCore/Duration>
#include <KCalCore/Utils>
#include <QWidget>
#include <QTest>
......@@ -58,7 +57,7 @@ void ConflictResolverTest::initTestCase()
void ConflictResolverTest::init()
{
base = KDateTime::currentLocalDateTime().addDays(1);
base = QDateTime::currentDateTime().addDays(1);
end = base.addSecs(10 * 60 * 60);
resolver = new ConflictResolver(parent, parent);
}
......@@ -72,7 +71,7 @@ void ConflictResolverTest::cleanup()
void ConflictResolverTest::simpleTest()
{
KCalCore::Period meeting(KCalCore::k2q(end).addSecs(-3 * 60 * 60), KCalCore::Duration(2 * 60 * 60));
KCalCore::Period meeting(end.addSecs(-3 * 60 * 60), KCalCore::Duration(2 * 60 * 60));
addAttendee(QStringLiteral("albert@einstein.net"),
KCalCore::FreeBusy::Ptr(new KCalCore::FreeBusy(KCalCore::Period::List()
<< meeting)));
......@@ -88,7 +87,7 @@ void ConflictResolverTest::simpleTest()
QVERIFY(resolver->availableSlots().size() == 2);
KCalCore::Period first = resolver->availableSlots().at(0);
QCOMPARE(first.start(), KCalCore::k2q(base));
QCOMPARE(first.start(), base);
QCOMPARE(first.end(), meeting.start());
KCalCore::Period second = resolver->availableSlots().at(1);
......@@ -96,14 +95,14 @@ void ConflictResolverTest::simpleTest()
QCOMPARE(second.start(), meeting.end().addSecs(resolution)); //add 15 minutes because the
//free block doesn't start until
//the next timeslot
QCOMPARE(second.end(), KCalCore::k2q(end));
QCOMPARE(second.end(), end);
}
void ConflictResolverTest::stillPrettySimpleTest()
{
KCalCore::Period meeting1(KCalCore::k2q(base), KCalCore::Duration(2 * 60 * 60));
KCalCore::Period meeting2(KCalCore::k2q(base).addSecs(60 * 60), KCalCore::Duration(2 * 60 * 60));
KCalCore::Period meeting3(KCalCore::k2q(end).addSecs(-3 * 60 * 60), KCalCore::Duration(2 * 60 * 60));
KCalCore::Period meeting1(base, KCalCore::Duration(2 * 60 * 60));
KCalCore::Period meeting2(base.addSecs(60 * 60), KCalCore::Duration(2 * 60 * 60));
KCalCore::Period meeting3(end.addSecs(-3 * 60 * 60), KCalCore::Duration(2 * 60 * 60));
addAttendee(QStringLiteral("john.f@kennedy.com"),
KCalCore::FreeBusy::Ptr(new KCalCore::FreeBusy(KCalCore::Period::List()
<< meeting1 << meeting3)));
......@@ -134,7 +133,7 @@ void ConflictResolverTest::stillPrettySimpleTest()
QCOMPARE(second.start(), meeting3.end().addSecs(resolution)); //add 15 minutes because the
//free block doesn't start until
//the next timeslot
QCOMPARE(second.end(), KCalCore::k2q(end));
QCOMPARE(second.end(), end);
}
#define _time( h, m ) QDateTime( base.date(), QTime( h, m ) )
......@@ -279,7 +278,7 @@ void ConflictResolverTest::testPeriodBeginsBeforeTimeframeBegins()
QCOMPARE(resolver->availableSlots().size(), 1);
KCalCore::Period freeslot = resolver->availableSlots().at(0);
QCOMPARE(freeslot.start(), _time(8, 45));
QCOMPARE(freeslot.end(), KCalCore::k2q(end));
QCOMPARE(freeslot.end(), end);
}
void ConflictResolverTest::testPeriodEndsAfterTimeframeEnds()
......@@ -306,7 +305,7 @@ void ConflictResolverTest::testPeriodEndsAfterTimeframeEnds()
QCOMPARE(resolver->availableSlots().size(), 1);
KCalCore::Period freeslot = resolver->availableSlots().at(0);
QCOMPARE(freeslot.duration(), KCalCore::Duration(30 * 60));
QCOMPARE(freeslot.start(), KCalCore::k2q(base));
QCOMPARE(freeslot.start(), base);
QCOMPARE(freeslot.end(), _time(8, 00));
}
......
......@@ -55,7 +55,7 @@ private:
QList<CalendarSupport::FreeBusyItem::Ptr> attendees;
QWidget *parent;
IncidenceEditorNG::ConflictResolver *resolver;
KDateTime base, end;
QDateTime base, end;
};
#endif
......@@ -24,8 +24,6 @@
#include "CalendarSupport/FreeBusyItemModel"
#include "incidenceeditor_debug.h"
#include <KCalCore/Utils>
#include <QDate>
static const int DEFAULT_RESOLUTION_SECONDS = 15 * 60; // 15 minutes, 1 slot = 15 minutes
......@@ -131,15 +129,15 @@ void ConflictResolver::setLatestTime(const QTime &newTime)
calculateConflicts();
}
void ConflictResolver::setEarliestDateTime(const KDateTime &newDateTime)
void ConflictResolver::setEarliestDateTime(const QDateTime &newDateTime)
{
mTimeframeConstraint = KCalCore::Period(KCalCore::k2q(newDateTime), mTimeframeConstraint.end());
mTimeframeConstraint = KCalCore::Period(newDateTime, mTimeframeConstraint.end());
calculateConflicts();
}
void ConflictResolver::setLatestDateTime(const KDateTime &newDateTime)
void ConflictResolver::setLatestDateTime(const QDateTime &newDateTime)
{
mTimeframeConstraint = KCalCore::Period(mTimeframeConstraint.start(), KCalCore::k2q(newDateTime));
mTimeframeConstraint = KCalCore::Period(mTimeframeConstraint.start(), newDateTime);
calculateConflicts();
}
......@@ -148,7 +146,7 @@ void ConflictResolver::freebusyDataChanged()
calculateConflicts();
}
int ConflictResolver::tryDate(KDateTime &tryFrom, KDateTime &tryTo)
int ConflictResolver::tryDate(QDateTime &tryFrom, QDateTime &tryTo)
{
int conflicts_count = 0;
for (int i = 0; i < mFBModel->rowCount(); ++i) {
......@@ -171,8 +169,8 @@ int ConflictResolver::tryDate(KDateTime &tryFrom, KDateTime &tryTo)
return conflicts_count;
}
bool ConflictResolver::tryDate(const KCalCore::FreeBusy::Ptr &fb, KDateTime &tryFrom,
KDateTime &tryTo)
bool ConflictResolver::tryDate(const KCalCore::FreeBusy::Ptr &fb, QDateTime &tryFrom,
QDateTime &tryTo)
{
// If we don't have any free/busy information, assume the
// participant is free. Otherwise a participant without available
......@@ -183,14 +181,14 @@ bool ConflictResolver::tryDate(const KCalCore::FreeBusy::Ptr &fb, KDateTime &try
KCalCore::Period::List busyPeriods = fb->busyPeriods();
for (auto it = busyPeriods.begin(); it != busyPeriods.end(); ++it) {
if ((*it).end() <= KCalCore::k2q(tryFrom) // busy period ends before try period
|| (*it).start() >= KCalCore::k2q(tryTo)) { // busy period starts after try period
if ((*it).end() <= tryFrom // busy period ends before try period
|| (*it).start() >= tryTo) { // busy period starts after try period
continue;
} else {
// the current busy period blocks the try period, try
// after the end of the current busy period
const int secsDuration = tryFrom.secsTo(tryTo);
tryFrom = KCalCore::q2k((*it).end());
tryFrom = (*it).end();
tryTo = tryFrom.addSecs(secsDuration);
// try again with the new try period
tryDate(fb, tryFrom, tryTo);
......@@ -203,19 +201,19 @@ bool ConflictResolver::tryDate(const KCalCore::FreeBusy::Ptr &fb, KDateTime &try
bool ConflictResolver::findFreeSlot(const KCalCore::Period &dateTimeRange)
{
KDateTime dtFrom = KCalCore::q2k(dateTimeRange.start());
KDateTime dtTo = KCalCore::q2k(dateTimeRange.end());
QDateTime dtFrom = dateTimeRange.start();
QDateTime dtTo = dateTimeRange.end();
if (tryDate(dtFrom, dtTo)) {
// Current time is acceptable
return true;
}
KDateTime tryFrom = dtFrom;
KDateTime tryTo = dtTo;
QDateTime tryFrom = dtFrom;
QDateTime tryTo = dtTo;
// Make sure that we never suggest a date in the past, even if the
// user originally scheduled the meeting to be in the past.
KDateTime now = KDateTime::currentUtcDateTime();
QDateTime now = QDateTime::currentDateTimeUtc();
if (tryFrom < now) {
// The slot to look for is at least partially in the past.
const int secs = tryFrom.secsTo(tryTo);
......@@ -465,8 +463,8 @@ void ConflictResolver::findAllFreeSlots()
void ConflictResolver::calculateConflicts()
{
KDateTime start = KCalCore::q2k(mTimeframeConstraint.start());
KDateTime end = KCalCore::q2k(mTimeframeConstraint.end());
QDateTime start = mTimeframeConstraint.start();
QDateTime end = mTimeframeConstraint.end();
const int count = tryDate(start, end);
Q_EMIT conflictsDetected(count);
......
......@@ -120,7 +120,7 @@ Q_SIGNALS:
* Emitted when the user changes the start and end dateTimes
* for the incidence.
*/
void dateTimesChanged(const KDateTime &newStart, const KDateTime &newEnd);
void dateTimesChanged(const QDateTime &newStart, const QDateTime &newEnd);
/**
* Emitted when there are conflicts
......@@ -144,8 +144,8 @@ public Q_SLOTS:
void setLatestDate(const QDate &newDate);
void setLatestTime(const QTime &newTime);
void setEarliestDateTime(const KDateTime &newDateTime);
void setLatestDateTime(const KDateTime &newDateTime);
void setEarliestDateTime(const QDateTime &newDateTime);
void setLatestDateTime(const QDateTime &newDateTime);
void freebusyDataChanged();
......@@ -161,7 +161,7 @@ private:
that participant. In other words, the returned slot does not have to
be free for everybody else.
*/
int tryDate(KDateTime &tryFrom, KDateTime &tryTo);
int tryDate(QDateTime &tryFrom, QDateTime &tryTo);
/**
Checks whether the slot specified by (tryFrom, tryTo) is available
......@@ -170,7 +170,7 @@ private:
possible slot for this participant (not necessarily a slot that is
available for all participants).
*/
bool tryDate(const KCalCore::FreeBusy::Ptr &fb, KDateTime &tryFrom, KDateTime &tryTo);
bool tryDate(const KCalCore::FreeBusy::Ptr &fb, QDateTime &tryFrom, QDateTime &tryTo);
/**
* Checks whether the supplied attendee passes the
......
......@@ -41,7 +41,6 @@
#include <KEmailAddress>
#include <KCalUtils/Stringify>
#include <KCalCore/Utils>
#include "incidenceeditor_debug.h"
#include <QTreeView>
......@@ -845,8 +844,8 @@ void IncidenceAttendee::slotEventDurationChanged()
return;
}
mConflictResolver->setEarliestDateTime(KCalCore::q2k(start));
mConflictResolver->setLatestDateTime(KCalCore::q2k(end));
mConflictResolver->setEarliestDateTime(start);
mConflictResolver->setLatestDateTime(end);
updateFBStatus();
}
......
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