Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit c46b6e99 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Port Period and Duration to QDateTime

parent 2b17cb27
......@@ -24,6 +24,7 @@
#include <KCalCore/Event>
#include <KCalCore/Period>
#include <KCalCore/Duration>
#include <KCalCore/Utils>
#include <QWidget>
#include <QTest>
......@@ -71,7 +72,7 @@ void ConflictResolverTest::cleanup()
void ConflictResolverTest::simpleTest()
{
KCalCore::Period meeting(end.addSecs(-3 * 60 * 60), KCalCore::Duration(2 * 60 * 60));
KCalCore::Period meeting(KCalCore::k2q(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)));
......@@ -87,7 +88,7 @@ void ConflictResolverTest::simpleTest()
QVERIFY(resolver->availableSlots().size() == 2);
KCalCore::Period first = resolver->availableSlots().at(0);
QCOMPARE(first.start(), base);
QCOMPARE(first.start(), KCalCore::k2q(base));
QCOMPARE(first.end(), meeting.start());
KCalCore::Period second = resolver->availableSlots().at(1);
......@@ -95,14 +96,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(), end);
QCOMPARE(second.end(), KCalCore::k2q(end));
}
void ConflictResolverTest::stillPrettySimpleTest()
{
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));
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));
addAttendee(QStringLiteral("john.f@kennedy.com"),
KCalCore::FreeBusy::Ptr(new KCalCore::FreeBusy(KCalCore::Period::List()
<< meeting1 << meeting3)));
......@@ -133,10 +134,10 @@ 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(), end);
QCOMPARE(second.end(), KCalCore::k2q(end));
}
#define _time( h, m ) KDateTime( base.date(), QTime( h, m ) )
#define _time( h, m ) QDateTime( base.date(), QTime( h, m ) )
void ConflictResolverTest::akademy2010()
{
......@@ -278,7 +279,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(), end);
QCOMPARE(freeslot.end(), KCalCore::k2q(end));
}
void ConflictResolverTest::testPeriodEndsAfterTimeframeEnds()
......@@ -305,7 +306,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(), base);
QCOMPARE(freeslot.start(), KCalCore::k2q(base));
QCOMPARE(freeslot.end(), _time(8, 00));
}
......
......@@ -24,6 +24,8 @@
#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
......@@ -37,7 +39,7 @@ ConflictResolver::ConflictResolver(QWidget *parentWidget, QObject *parent)
, mWeekdays(7)
, mSlotResolutionSeconds(DEFAULT_RESOLUTION_SECONDS)
{
const KDateTime currentLocalDateTime = KDateTime::currentLocalDateTime();
const QDateTime currentLocalDateTime = QDateTime::currentDateTime();
mTimeframeConstraint = KCalCore::Period(currentLocalDateTime, currentLocalDateTime);
// trigger a reload in case any attendees were inserted before
......@@ -99,7 +101,7 @@ bool ConflictResolver::containsAttendee(const KCalCore::Attendee::Ptr &attendee)
void ConflictResolver::setEarliestDate(const QDate &newDate)
{
KDateTime newStart = mTimeframeConstraint.start();
QDateTime newStart = mTimeframeConstraint.start();
newStart.setDate(newDate);
mTimeframeConstraint = KCalCore::Period(newStart, mTimeframeConstraint.end());
calculateConflicts();
......@@ -107,7 +109,7 @@ void ConflictResolver::setEarliestDate(const QDate &newDate)
void ConflictResolver::setEarliestTime(const QTime &newTime)
{
KDateTime newStart = mTimeframeConstraint.start();
QDateTime newStart = mTimeframeConstraint.start();
newStart.setTime(newTime);
mTimeframeConstraint = KCalCore::Period(newStart, mTimeframeConstraint.end());
calculateConflicts();
......@@ -115,7 +117,7 @@ void ConflictResolver::setEarliestTime(const QTime &newTime)
void ConflictResolver::setLatestDate(const QDate &newDate)
{
KDateTime newEnd = mTimeframeConstraint.end();
QDateTime newEnd = mTimeframeConstraint.end();
newEnd.setDate(newDate);
mTimeframeConstraint = KCalCore::Period(mTimeframeConstraint.start(), newEnd);
calculateConflicts();
......@@ -123,7 +125,7 @@ void ConflictResolver::setLatestDate(const QDate &newDate)
void ConflictResolver::setLatestTime(const QTime &newTime)
{
KDateTime newEnd = mTimeframeConstraint.end();
QDateTime newEnd = mTimeframeConstraint.end();
newEnd.setTime(newTime);
mTimeframeConstraint = KCalCore::Period(mTimeframeConstraint.start(), newEnd);
calculateConflicts();
......@@ -131,13 +133,13 @@ void ConflictResolver::setLatestTime(const QTime &newTime)
void ConflictResolver::setEarliestDateTime(const KDateTime &newDateTime)
{
mTimeframeConstraint = KCalCore::Period(newDateTime, mTimeframeConstraint.end());
mTimeframeConstraint = KCalCore::Period(KCalCore::k2q(newDateTime), mTimeframeConstraint.end());
calculateConflicts();
}
void ConflictResolver::setLatestDateTime(const KDateTime &newDateTime)
{
mTimeframeConstraint = KCalCore::Period(mTimeframeConstraint.start(), newDateTime);
mTimeframeConstraint = KCalCore::Period(mTimeframeConstraint.start(), KCalCore::k2q(newDateTime));
calculateConflicts();
}
......@@ -180,16 +182,15 @@ bool ConflictResolver::tryDate(const KCalCore::FreeBusy::Ptr &fb, KDateTime &try
}
KCalCore::Period::List busyPeriods = fb->busyPeriods();
for (KCalCore::Period::List::Iterator it = busyPeriods.begin();
it != busyPeriods.end(); ++it) {
if ((*it).end() <= tryFrom // busy period ends before try period
|| (*it).start() >= tryTo) { // busy period starts after try period
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
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 = (*it).end();
tryFrom = KCalCore::q2k((*it).end());
tryTo = tryFrom.addSecs(secsDuration);
// try again with the new try period
tryDate(fb, tryFrom, tryTo);
......@@ -202,8 +203,8 @@ bool ConflictResolver::tryDate(const KCalCore::FreeBusy::Ptr &fb, KDateTime &try
bool ConflictResolver::findFreeSlot(const KCalCore::Period &dateTimeRange)
{
KDateTime dtFrom = dateTimeRange.start();
KDateTime dtTo = dateTimeRange.end();
KDateTime dtFrom = KCalCore::q2k(dateTimeRange.start());
KDateTime dtTo = KCalCore::q2k(dateTimeRange.end());
if (tryDate(dtFrom, dtTo)) {
// Current time is acceptable
return true;
......@@ -249,8 +250,8 @@ void ConflictResolver::findAllFreeSlots()
// 4. locate contiguous timeslots with a values of 0. these are the free time blocks.
// define these locally for readability
const KDateTime begin = mTimeframeConstraint.start();
const KDateTime end = mTimeframeConstraint.end();
const QDateTime begin = mTimeframeConstraint.start();
const QDateTime end = mTimeframeConstraint.end();
// calculate the time resolution
// each timeslot in the arrays represents a unit of time
......@@ -273,7 +274,7 @@ void ConflictResolver::findAllFreeSlots()
return;
}
qCDebug(INCIDENCEEDITOR_LOG) << "from " << begin.dateTime() << " to " << end.dateTime()
qCDebug(INCIDENCEEDITOR_LOG) << "from " << begin << " to " << end
<< "; mSlotResolutionSeconds = " << mSlotResolutionSeconds
<< "; range = " << range;
// filter out attendees for which we don't have FB data
......@@ -369,7 +370,7 @@ void ConflictResolver::findAllFreeSlots()
QVector<int> fbArray(range);
fbArray.fill(0); // initialize to zero
for (int slot = 0; slot < fbArray.size(); ++slot) {
const KDateTime dateTime = begin.addSecs(slot * mSlotResolutionSeconds);
const QDateTime dateTime = begin.addSecs(slot * mSlotResolutionSeconds);
const int dayOfWeek = dateTime.date().dayOfWeek() - 1; // bitarray is 0 indexed
if (!mWeekdays[dayOfWeek]) {
fbArray[slot] = 1;
......@@ -418,8 +419,8 @@ void ConflictResolver::findAllFreeSlots()
// convert from our timeslot interval back into to normal seconds
// then calculate the date times of the free block based on
// our initial timeframe
const KDateTime freeBegin = begin.addSecs(free_start_i * mSlotResolutionSeconds);
const KDateTime freeEnd
const QDateTime freeBegin = begin.addSecs(free_start_i * mSlotResolutionSeconds);
const QDateTime freeEnd
= freeBegin.addSecs((free_end_i - free_start_i) * mSlotResolutionSeconds);
// push the free block onto the list
mAvailableSlots << KCalCore::Period(freeBegin, freeEnd);
......@@ -464,8 +465,8 @@ void ConflictResolver::findAllFreeSlots()
void ConflictResolver::calculateConflicts()
{
KDateTime start = mTimeframeConstraint.start();
KDateTime end = mTimeframeConstraint.end();
KDateTime start = KCalCore::q2k(mTimeframeConstraint.start());
KDateTime end = KCalCore::q2k(mTimeframeConstraint.end());
const int count = tryDate(start, end);
Q_EMIT conflictsDetected(count);
......
......@@ -63,9 +63,9 @@ QVariant FreeBusyGanttProxyModel::data(const QModelIndex &index, int role) const
case KGantt::ItemTypeRole:
return KGantt::TypeTask;
case KGantt::StartTimeRole:
return period.start().toLocalZone().dateTime();
return period.start().toLocalTime();
case KGantt::EndTimeRole:
return period.end().toLocalZone().dateTime();
return period.end().toLocalTime();
case Qt::BackgroundRole:
return QColor(Qt::red);
case Qt::ToolTipRole:
......@@ -99,13 +99,13 @@ QString FreeBusyGanttProxyModel::tooltipify(const KCalCore::FreeBusyPeriod &peri
+ i18nc("@info:tooltip period start time",
"Start:") + QStringLiteral("</i>") + QStringLiteral(
"&nbsp;");
toolTip += QLocale().toString(period.start().toLocalZone().dateTime(), QLocale::ShortFormat);
toolTip += QLocale().toString(period.start().toLocalTime(), QLocale::ShortFormat);
toolTip += QStringLiteral("<br>");
toolTip += QStringLiteral("<i>")
+ i18nc("@info:tooltip period end time",
"End:") + QStringLiteral("</i>") + QStringLiteral(
"&nbsp;");
toolTip += QLocale().toString(period.end().toLocalZone().dateTime(), QLocale::ShortFormat);
toolTip += QLocale().toString(period.end().toLocalTime(), QLocale::ShortFormat);
toolTip += QStringLiteral("<br>");
toolTip += QStringLiteral("</qt>");
return toolTip;
......
......@@ -662,15 +662,14 @@ void IncidenceAttendee::updateFBStatus(const KCalCore::Attendee::Ptr &attendee,
const KCalCore::FreeBusy::Ptr &fb)
{
KCalCore::Attendee::List attendees = mDataModel->attendees();
KDateTime startTime = KCalCore::q2k(mDateTime->currentStartDateTime());
KDateTime endTime = KCalCore::q2k(mDateTime->currentEndDateTime());
QDateTime startTime = mDateTime->currentStartDateTime();
QDateTime endTime = mDateTime->currentEndDateTime();
if (attendees.contains(attendee)) {
int row = dataModel()->attendees().indexOf(attendee);
QModelIndex attendeeIndex = dataModel()->index(row, AttendeeTableModel::Available);
if (fb) {
KCalCore::Period::List busyPeriods = fb->busyPeriods();
for (KCalCore::Period::List::Iterator it = busyPeriods.begin(); it != busyPeriods.end();
++it) {
for (auto it = busyPeriods.begin(); it != busyPeriods.end(); ++it) {
// periods started before and laping into the incidence (s < startTime && e >= startTime)
// periods starting in the time of incidende (s >= startTime && s <= endTime)
if (((*it).start() < startTime && (*it).end() > startTime) ||
......
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