Commit b14b742a authored by Glen Ditchfield's avatar Glen Ditchfield 🐛 Committed by David Faure
Browse files

Synchronize "floating" status of date-times

RFC5545 states that the DTEND and DUE properties must be specified with
local ("floating") times if and only if DTSTART is local.  This patch
ensures that the incidence editor obeys that rule by setting the two
timezone combo boxes to the same time zone if either of them changes to
or from the "floating" time zone.

- `updateStartSpec()` and `updateEndSpec()` synchronize the combo boxes.
- `enableStartEdit()` and `enableEndEdit()` no longer change time zones
  when a todo's start or due time is enabled or disabled.  Disabling
  one would set both to "floating"!
- `identical()` ensures that all changes to time zones are detected.

@dfaure
parent 21effd9e
Pipeline #152782 passed with stage
in 1 minute and 11 seconds
......@@ -17,6 +17,11 @@
using namespace IncidenceEditorNG;
static bool identical(QDateTime dt1, QDateTime dt2)
{
return dt1 == dt2 && dt1.timeSpec() == dt2.timeSpec() && dt1.timeZone() == dt2.timeZone();
}
/**
* Returns true if the incidence's dates are equal to the default ones specified in config.
*/
......@@ -275,8 +280,12 @@ void IncidenceDateTime::updateStartSpec()
{
const QDate prevDate = mCurrentStartDateTime.date();
if (mUi->mEndCheck->isChecked() && currentEndDateTime().timeZone() == mCurrentStartDateTime.timeZone()) {
mUi->mTimeZoneComboEnd->setFloating(mUi->mTimeZoneComboStart->isFloating(), mUi->mTimeZoneComboStart->selectedTimeZone());
// RFC 5545 states that both date-times must be "floating" if either is.
// Otherwise, for the user's convenience, if both combos used to be the same
// then keep them the same.
if ( (mUi->mTimeZoneComboStart->isFloating() != mUi->mTimeZoneComboEnd->isFloating())
|| currentEndDateTime().timeZone() == mCurrentStartDateTime.timeZone() ) {
mUi->mTimeZoneComboEnd->setCurrentIndex(mUi->mTimeZoneComboStart->currentIndex());
}
mUi->mTimeZoneComboStart->applyTimeZoneTo(mCurrentStartDateTime);
......@@ -292,6 +301,15 @@ void IncidenceDateTime::updateStartSpec()
}
}
void IncidenceDateTime::updateEndSpec()
{
// RFC 5545 states that both date-times must be "floating" if either is.
if (mUi->mTimeZoneComboStart->isFloating() != mUi->mTimeZoneComboEnd->isFloating()) {
mUi->mTimeZoneComboStart->setCurrentIndex(mUi->mTimeZoneComboEnd->currentIndex());
}
checkDirtyStatus();
}
/// private slots for Todo
void IncidenceDateTime::enableStartEdit(bool enable)
......@@ -315,7 +333,6 @@ void IncidenceDateTime::enableStartEdit(bool enable)
mUi->mTimeZoneComboStart->setEnabled(false);
}
mUi->mTimeZoneComboStart->setFloating(!mUi->mTimeZoneComboStart->isEnabled());
checkDirtyStatus();
}
......@@ -340,7 +357,6 @@ void IncidenceDateTime::enableEndEdit(bool enable)
mUi->mTimeZoneComboEnd->setEnabled(false);
}
mUi->mTimeZoneComboEnd->setFloating(!mUi->mTimeZoneComboEnd->isEnabled());
checkDirtyStatus();
}
......@@ -424,12 +440,12 @@ bool IncidenceDateTime::isDirty(const KCalendarCore::Todo::Ptr &todo) const
// Use mActiveStartTime. This is the QTimeZone selected on load coming from
// the combobox. We use this one as it can slightly differ (e.g. missing
// country code in the incidence time spec) from the incidence.
if (currentStartDateTime() != mInitialStartDT) {
if (!identical(currentStartDateTime(), mInitialStartDT)) {
return true;
}
}
if (mUi->mEndCheck->isChecked() && currentEndDateTime() != mInitialEndDT) {
if (mUi->mEndCheck->isChecked() && !identical(currentEndDateTime(), mInitialEndDT)) {
return true;
}
......@@ -457,8 +473,7 @@ bool IncidenceDateTime::isDirty(const KCalendarCore::Event::Ptr &event) const
return true;
}
} else {
if (currentStartDateTime() != mInitialStartDT || currentEndDateTime() != mInitialEndDT
|| currentStartDateTime().timeZone() != mInitialStartDT.timeZone() || currentEndDateTime().timeZone() != mInitialEndDT.timeZone()) {
if (!identical(currentStartDateTime(), mInitialStartDT) || !identical(currentEndDateTime(), mInitialEndDT)) {
return true;
}
}
......@@ -477,7 +492,7 @@ bool IncidenceDateTime::isDirty(const KCalendarCore::Journal::Ptr &journal) cons
return true;
}
} else {
if (currentStartDateTime() != mInitialStartDT) {
if (!identical(currentStartDateTime(), mInitialStartDT)) {
return true;
}
}
......@@ -530,7 +545,7 @@ void IncidenceDateTime::load(const KCalendarCore::Event::Ptr &event, bool isTemp
connect(mUi->mTimeZoneComboEnd,
static_cast<void (IncidenceEditorNG::KTimeZoneComboBox::*)(int)>(&IncidenceEditorNG::KTimeZoneComboBox::currentIndexChanged),
this,
&IncidenceDateTime::checkDirtyStatus);
&IncidenceDateTime::updateEndSpec);
mUi->mWholeDayCheck->setChecked(event->allDay());
enableTimeEdits();
......@@ -585,12 +600,8 @@ void IncidenceDateTime::load(const KCalendarCore::Journal::Ptr &journal, bool is
}
} else {
QDateTime startDT = journal->dtStart();
// Convert UTC to local timezone, if needed (i.e. for kolab #204059)
if (startDT.timeZone() == QTimeZone::utc()) {
startDT = startDT.toLocalTime();
}
setDateTimes(startDT, QDateTime());
// Journals do not have end dates, so pick an arbitrary suitable date.
setDateTimes(startDT, startDT);
}
}
......@@ -639,7 +650,7 @@ void IncidenceDateTime::load(const KCalendarCore::Todo::Ptr &todo, bool isTempla
connect(mUi->mTimeZoneComboEnd,
static_cast<void (IncidenceEditorNG::KTimeZoneComboBox::*)(int)>(&IncidenceEditorNG::KTimeZoneComboBox::currentIndexChanged),
this,
&IncidenceDateTime::checkDirtyStatus);
&IncidenceDateTime::updateEndSpec);
const QDateTime rightNow = QDateTime::currentDateTime();
if (isTemplate) {
......
......@@ -83,6 +83,7 @@ private Q_SLOTS: /// General
void updateStartTime(const QTime &newTime);
void updateStartDate(const QDate &newDate);
void updateStartSpec();
void updateEndSpec();
void updateStartToolTips();
void updateEndToolTips();
......
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