Navigation Menu

Skip to content

Commit

Permalink
Add a flag not to update the lastModified field automatically.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcaliste committed Feb 25, 2021
1 parent 539c89c commit d82e9a5
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 2 deletions.
47 changes: 47 additions & 0 deletions autotests/testmemorycalendar.cpp
Expand Up @@ -448,3 +448,50 @@ void MemoryCalendarTest::testDeleteIncidence()
QVERIFY(cal->incidence(event->uid(), exception2->recurrenceId()).isNull());
QVERIFY(cal->incidence(event->uid()).isNull());
}

void MemoryCalendarTest::testUpdateIncidence()
{
MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc()));

const QDateTime dt(QDate(2021, 02, 25), QTime(14, 0), Qt::UTC);
Event::Ptr event(new Event());
event->setCreated(dt);
event->setLastModified(dt);
event->setDtStart(dt);
event->setDtEnd(dt.addSecs(3600));

// Adding event to cal, makes cal an observer of event.
QVERIFY(cal->addIncidence(event));
QCOMPARE(cal->rawEventsForDate(dt).count(), 1);

QVERIFY(cal->updateLastModifiedOnChange());

const QDateTime now = QDateTime::currentDateTimeUtc();

// Any single modfication is updating the lastModified field.
event->setSummary(QString::fromLatin1("test"));
QVERIFY(event->lastModified().secsTo(now) < 5);

// Reset lastModified field.
event->setLastModified(dt);
QCOMPARE(event->lastModified(), dt);

// Any modification within a startUpdates()/endUpdates() should not touch
// lastModified field, before the changes are completed.
event->startUpdates();
QVERIFY(cal->rawEventsForDate(dt).isEmpty());
event->setSummary(QString::fromLatin1("test again"));
QCOMPARE(event->lastModified(), dt);
event->endUpdates();
QVERIFY(event->lastModified().secsTo(now) < 5);
QCOMPARE(cal->rawEventsForDate(dt).count(), 1);

// Reset lastModified field.
event->setLastModified(dt);
QCOMPARE(event->lastModified(), dt);

// Don't update lastModified on change.
cal->setUpdateLastModifiedOnChange(false);
event->setSummary(QString::fromLatin1("last test"));
QCOMPARE(event->lastModified(), dt);
}
1 change: 1 addition & 0 deletions autotests/testmemorycalendar.h
Expand Up @@ -27,6 +27,7 @@ private Q_SLOTS:
void testRawEventsForDate();
void testVisibility();
void testDeleteIncidence();
void testUpdateIncidence();
};

#endif
17 changes: 15 additions & 2 deletions src/memorycalendar.cpp
Expand Up @@ -41,7 +41,7 @@ class Q_DECL_HIDDEN KCalendarCore::MemoryCalendar::Private

public:
Private(MemoryCalendar *qq)
: q(qq), mFormat(nullptr)
: q(qq), mFormat(nullptr), mUpdateLastModified(true)
{
}
~Private()
Expand All @@ -51,6 +51,7 @@ class Q_DECL_HIDDEN KCalendarCore::MemoryCalendar::Private
MemoryCalendar *q;
CalFormat *mFormat; // calendar format
QString mIncidenceBeingUpdated; // Instance identifier of Incidence currently being updated
bool mUpdateLastModified; // Call setLastModified() on incidence modific ations


/**
Expand Down Expand Up @@ -529,6 +530,16 @@ Alarm::List MemoryCalendar::alarms(const QDateTime &from, const QDateTime &to, b
return alarmList;
}

bool MemoryCalendar::updateLastModifiedOnChange() const
{
return d->mUpdateLastModified;
}

void MemoryCalendar::setUpdateLastModifiedOnChange(bool update)
{
d->mUpdateLastModified = update;
}

void MemoryCalendar::incidenceUpdate(const QString &uid, const QDateTime &recurrenceId)
{
Incidence::Ptr inc = incidence(uid, recurrenceId);
Expand Down Expand Up @@ -564,7 +575,9 @@ void MemoryCalendar::incidenceUpdated(const QString &uid, const QDateTime &recur

d->mIncidenceBeingUpdated = QString();

inc->setLastModified(QDateTime::currentDateTimeUtc());
if (d->mUpdateLastModified) {
inc->setLastModified(QDateTime::currentDateTimeUtc());
}
// we should probably update the revision number here,
// or internally in the Event itself when certain things change.
// need to verify with ical documentation.
Expand Down
19 changes: 19 additions & 0 deletions src/memorycalendar.h
Expand Up @@ -293,6 +293,25 @@ class KCALENDARCORE_EXPORT MemoryCalendar : public Calendar
*/
Q_REQUIRED_RESULT Alarm::List alarmsTo(const QDateTime &to) const; // TODO KF6 remove, already defined in Calendar

/**
Return true if the memory calendar is updating the lastModified field
of incidence owned by the calendar on any incidence change.
@since 5.80
*/
bool updateLastModifiedOnChange() const;

/**
Govern if the memory calendar is changing the lastModified field of incidence
it owns, on incidence updates.
@param update, when true, the lastModified field of an incidence owned by the
calendar is set to the current date time on any change of the incidence.
@since 5.80
*/
void setUpdateLastModifiedOnChange(bool update);

/**
@copydoc Calendar::incidenceUpdate(const QString &,const QDateTime &)
*/
Expand Down

0 comments on commit d82e9a5

Please sign in to comment.