incidencedatetime.cpp 36.2 KB
Newer Older
1
/*
2
3
  SPDX-FileCopyrightText: 2010 Bertjan Broeksema <broeksema@kde.org>
  SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
4

5
  SPDX-License-Identifier: LGPL-2.0-or-later
6
7
8
*/

#include "incidencedatetime.h"
Volker Krause's avatar
Volker Krause committed
9
#include "incidenceeditor_debug.h"
Laurent Montel's avatar
Laurent Montel committed
10
#include "ui_dialogdesktop.h"
11
12
13
14
15

#include <CalendarSupport/KCalPrefs>

#include <KCalUtils/IncidenceFormatter>

16
#include <QTimeZone>
17
18
19

using namespace IncidenceEditorNG;

20
21
22
23
24
static bool identical(QDateTime dt1, QDateTime dt2)
{
    return dt1 == dt2 && dt1.timeSpec() == dt2.timeSpec() && dt1.timeZone() == dt2.timeZone();
}

25
26
27
/**
 * Returns true if the incidence's dates are equal to the default ones specified in config.
 */
28
static bool incidenceHasDefaultTimes(const KCalendarCore::Incidence::Ptr &incidence)
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{
    if (!incidence || incidence->allDay()) {
        return false;
    }

    QTime defaultDuration = CalendarSupport::KCalPrefs::instance()->defaultDuration().time();
    if (!defaultDuration.isValid()) {
        return false;
    }

    QTime defaultStart = CalendarSupport::KCalPrefs::instance()->mStartTime.time();
    if (!defaultStart.isValid()) {
        return false;
    }

    if (incidence->dtStart().time() == defaultStart) {
45
        if (incidence->type() == KCalendarCore::Incidence::TypeJournal) {
46
47
48
            return true; // no duration to compare with
        }

49
        const QDateTime start = incidence->dtStart();
50
        const QDateTime end = incidence->dateTime(KCalendarCore::Incidence::RoleEnd);
51
52
53
54
55
56
57
58
59
60
61
62
        if (!end.isValid() || !start.isValid()) {
            return false;
        }

        const int durationInSeconds = defaultDuration.hour() * 3600 + defaultDuration.minute() * 60;
        return start.secsTo(end) == durationInSeconds;
    }

    return false;
}

IncidenceDateTime::IncidenceDateTime(Ui::EventOrTodoDesktop *ui)
Laurent Montel's avatar
Laurent Montel committed
63
64
65
    : IncidenceEditor(nullptr)
    , mUi(ui)
    , mTimezoneCombosWereVisibile(false)
66
67
68
69
70
{
    setTimeZonesVisibility(false);
    setObjectName(QStringLiteral("IncidenceDateTime"));

    mUi->mTimeZoneLabel->setVisible(!mUi->mWholeDayCheck->isChecked());
Laurent Montel's avatar
Laurent Montel committed
71
    connect(mUi->mTimeZoneLabel, &QLabel::linkActivated, this, &IncidenceDateTime::toggleTimeZoneVisibility);
72
73
    mUi->mTimeZoneLabel->setContextMenuPolicy(Qt::NoContextMenu);

Laurent Montel's avatar
Laurent Montel committed
74
75
76
77
    const QList<QLineEdit *> lineEdits{mUi->mStartDateEdit->lineEdit(),
                                       mUi->mEndDateEdit->lineEdit(),
                                       mUi->mStartTimeEdit->lineEdit(),
                                       mUi->mEndTimeEdit->lineEdit()};
Laurent Montel's avatar
Laurent Montel committed
78
    for (QLineEdit *lineEdit : lineEdits) {
79
80
81
82
83
84
85
86
87
        if (lineEdit) {
            lineEdit->setClearButtonEnabled(false);
        }
    }

    connect(mUi->mFreeBusyCheck, &QCheckBox::toggled, this, &IncidenceDateTime::checkDirtyStatus);
    connect(mUi->mWholeDayCheck, &QCheckBox::toggled, this, &IncidenceDateTime::enableTimeEdits);
    connect(mUi->mWholeDayCheck, &QCheckBox::toggled, this, &IncidenceDateTime::checkDirtyStatus);

Laurent Montel's avatar
Laurent Montel committed
88
89
    connect(this, &IncidenceDateTime::startDateChanged, this, &IncidenceDateTime::updateStartToolTips);
    connect(this, &IncidenceDateTime::startTimeChanged, this, &IncidenceDateTime::updateStartToolTips);
90
91
    connect(this, &IncidenceDateTime::endDateChanged, this, &IncidenceDateTime::updateEndToolTips);
    connect(this, &IncidenceDateTime::endTimeChanged, this, &IncidenceDateTime::updateEndToolTips);
Laurent Montel's avatar
Laurent Montel committed
92
    connect(mUi->mWholeDayCheck, &QCheckBox::toggled, this, &IncidenceDateTime::updateStartToolTips);
93
94
95
96
97
    connect(mUi->mWholeDayCheck, &QCheckBox::toggled, this, &IncidenceDateTime::updateEndToolTips);
    connect(mUi->mStartCheck, &QCheckBox::toggled, this, &IncidenceDateTime::updateStartToolTips);
    connect(mUi->mEndCheck, &QCheckBox::toggled, this, &IncidenceDateTime::updateEndToolTips);
}

Laurent Montel's avatar
Laurent Montel committed
98
IncidenceDateTime::~IncidenceDateTime() = default;
99
100
101
102
103

bool IncidenceDateTime::eventFilter(QObject *obj, QEvent *event)
{
    if (event->type() == QEvent::FocusIn) {
        if (obj == mUi->mStartDateEdit) {
104
            qCDebug(INCIDENCEEDITOR_LOG) << "emitting startDateTime: " << mUi->mStartDateEdit;
105
106
            Q_EMIT startDateFocus(obj);
        } else if (obj == mUi->mEndDateEdit) {
107
            qCDebug(INCIDENCEEDITOR_LOG) << "emitting endDateTime: " << mUi->mEndDateEdit;
108
109
            Q_EMIT endDateFocus(obj);
        } else if (obj == mUi->mStartTimeEdit) {
110
            qCDebug(INCIDENCEEDITOR_LOG) << "emitting startTimeTime: " << mUi->mStartTimeEdit;
111
112
            Q_EMIT startTimeFocus(obj);
        } else if (obj == mUi->mEndTimeEdit) {
113
            qCDebug(INCIDENCEEDITOR_LOG) << "emitting endTimeTime: " << mUi->mEndTimeEdit;
114
115
116
117
118
119
120
121
122
123
            Q_EMIT endTimeFocus(obj);
        }

        return true;
    } else {
        // standard event processing
        return QObject::eventFilter(obj, event);
    }
}

124
void IncidenceDateTime::load(const KCalendarCore::Incidence::Ptr &incidence)
125
126
127
128
129
{
    if (mLoadedIncidence && *mLoadedIncidence == *incidence) {
        return;
    }

Laurent Montel's avatar
Laurent Montel committed
130
    const bool isTemplate = incidence->customProperty("kdepim", "isTemplate") == QLatin1String("true");
131
    incidence->removeCustomProperty("kdepim", "isTemplate");
132
133
134
135
136
137
    const bool templateOverridesTimes = incidenceHasDefaultTimes(mLoadedIncidence);

    mLoadedIncidence = incidence;
    mLoadingIncidence = true;

    // We can only handle events or todos.
138
    if (KCalendarCore::Todo::Ptr todo = IncidenceDateTime::incidence<KCalendarCore::Todo>()) {
139
        load(todo, isTemplate, templateOverridesTimes);
140
    } else if (KCalendarCore::Event::Ptr event = IncidenceDateTime::incidence<KCalendarCore::Event>()) {
141
        load(event, isTemplate, templateOverridesTimes);
142
    } else if (KCalendarCore::Journal::Ptr journal = IncidenceDateTime::incidence<KCalendarCore::Journal>()) {
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
        load(journal, isTemplate, templateOverridesTimes);
    } else {
        qCDebug(INCIDENCEEDITOR_LOG) << "Not an Incidence.";
    }

    // Set the initial times before calling enableTimeEdits, as enableTimeEdits
    // assumes that the initial times are initialized.
    mInitialStartDT = currentStartDateTime();
    mInitialEndDT = currentEndDateTime();

    enableTimeEdits();

    mWasDirty = false;
    mLoadingIncidence = false;
}

159
void IncidenceDateTime::save(const KCalendarCore::Incidence::Ptr &incidence)
160
{
Laurent Montel's avatar
Laurent Montel committed
161
    if (KCalendarCore::Todo::Ptr todo = IncidenceDateTime::incidence<KCalendarCore::Todo>(incidence)) {
162
        save(todo);
Laurent Montel's avatar
Laurent Montel committed
163
    } else if (KCalendarCore::Event::Ptr event = IncidenceDateTime::incidence<KCalendarCore::Event>(incidence)) {
164
        save(event);
Laurent Montel's avatar
Laurent Montel committed
165
    } else if (KCalendarCore::Journal::Ptr journal = IncidenceDateTime::incidence<KCalendarCore::Journal>(incidence)) {
166
167
        save(journal);
    } else {
Laurent Montel's avatar
Laurent Montel committed
168
        Q_ASSERT_X(false, "IncidenceDateTimeEditor::save", "Only implemented for todos, events and journals");
169
170
171
172
173
    }
}

bool IncidenceDateTime::isDirty() const
{
174
    if (KCalendarCore::Todo::Ptr todo = IncidenceDateTime::incidence<KCalendarCore::Todo>()) {
175
        return isDirty(todo);
176
    } else if (KCalendarCore::Event::Ptr event = IncidenceDateTime::incidence<KCalendarCore::Event>()) {
177
        return isDirty(event);
178
    } else if (KCalendarCore::Journal::Ptr journal = IncidenceDateTime::incidence<KCalendarCore::Journal>()) {
179
180
        return isDirty(journal);
    } else {
Laurent Montel's avatar
Laurent Montel committed
181
        Q_ASSERT_X(false, "IncidenceDateTimeEditor::isDirty", "Only implemented for todos and events");
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
        return false;
    }
}

void IncidenceDateTime::setActiveDate(const QDate &activeDate)
{
    mActiveDate = activeDate;
}

QDate IncidenceDateTime::startDate() const
{
    return currentStartDateTime().date();
}

QDate IncidenceDateTime::endDate() const
{
    return currentEndDateTime().date();
}

QTime IncidenceDateTime::startTime() const
{
    return currentStartDateTime().time();
}

QTime IncidenceDateTime::endTime() const
{
    return currentEndDateTime().time();
}

/// private slots for General

void IncidenceDateTime::setTimeZonesVisibility(bool visible)
{
    static const QString tz(i18nc("@action show or hide the time zone widgets", "Time zones"));
216
    QString placeholder(QStringLiteral("<a href=\"hide\">&lt;&lt; %1</a>"));
217
218
219
    if (visible) {
        placeholder = placeholder.arg(tz);
    } else {
220
        placeholder = QStringLiteral("<a href=\"show\">%1 &gt;&gt;</a>");
221
222
223
224
225
        placeholder = placeholder.arg(tz);
    }
    mUi->mTimeZoneLabel->setText(placeholder);

    mUi->mTimeZoneComboStart->setVisible(visible);
226
    mUi->mTimeZoneComboEnd->setVisible(visible && type() != KCalendarCore::Incidence::TypeJournal);
227
228
229
230
231
232
233
234
235
236
237
238
239
}

void IncidenceDateTime::toggleTimeZoneVisibility()
{
    setTimeZonesVisibility(!mUi->mTimeZoneComboStart->isVisible());
}

void IncidenceDateTime::updateStartTime(const QTime &newTime)
{
    if (!newTime.isValid()) {
        return;
    }

240
    QDateTime endDateTime = currentEndDateTime();
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
    const int secsep = mCurrentStartDateTime.secsTo(endDateTime);
    mCurrentStartDateTime.setTime(newTime);
    if (mUi->mEndCheck->isChecked()) {
        // Only update the end time when it is actually enabled, adjust end time so
        // that the event/todo has the same duration as before.
        endDateTime = mCurrentStartDateTime.addSecs(secsep);
        mUi->mEndTimeEdit->setTime(endDateTime.time());
        mUi->mEndDateEdit->setDate(endDateTime.date());
    }

    Q_EMIT startTimeChanged(mCurrentStartDateTime.time());
    checkDirtyStatus();
}

void IncidenceDateTime::updateStartDate(const QDate &newDate)
{
    if (!newDate.isValid()) {
        return;
    }

261
    const bool dateChanged = mCurrentStartDateTime.date() != newDate;
262

263
    QDateTime endDateTime = currentEndDateTime();
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
    int daysep = mCurrentStartDateTime.daysTo(endDateTime);
    mCurrentStartDateTime.setDate(newDate);
    if (mUi->mEndCheck->isChecked()) {
        // Only update the end time when it is actually enabled, adjust end time so
        // that the event/todo has the same duration as before.
        endDateTime.setDate(mCurrentStartDateTime.date().addDays(daysep));
        mUi->mEndDateEdit->setDate(endDateTime.date());
    }

    checkDirtyStatus();

    if (dateChanged) {
        Q_EMIT startDateChanged(mCurrentStartDateTime.date());
    }
}

void IncidenceDateTime::updateStartSpec()
{
    const QDate prevDate = mCurrentStartDateTime.date();

284
285
286
287
288
289
    // 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());
290
291
    }

292
    mUi->mTimeZoneComboStart->applyTimeZoneTo(mCurrentStartDateTime);
293

294
    const bool dateChanged = mCurrentStartDateTime.date() != prevDate;
295
296
297
298
299

    if (dateChanged) {
        Q_EMIT startDateChanged(mCurrentStartDateTime.date());
    }

300
    if (type() == KCalendarCore::Incidence::TypeJournal) {
301
302
303
304
        checkDirtyStatus();
    }
}

305
306
307
308
309
310
311
312
313
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();
}

314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/// private slots for Todo

void IncidenceDateTime::enableStartEdit(bool enable)
{
    mUi->mStartDateEdit->setEnabled(enable);

    if (mUi->mEndCheck->isChecked() || mUi->mStartCheck->isChecked()) {
        mUi->mWholeDayCheck->setEnabled(true);
        setTimeZoneLabelEnabled(!mUi->mWholeDayCheck->isChecked());
    } else {
        mUi->mWholeDayCheck->setEnabled(false);
        mUi->mWholeDayCheck->setChecked(false);
        setTimeZoneLabelEnabled(false);
    }

    if (enable) {
        mUi->mStartTimeEdit->setEnabled(!mUi->mWholeDayCheck->isChecked());
        mUi->mTimeZoneComboStart->setEnabled(!mUi->mWholeDayCheck->isChecked());
    } else {
        mUi->mStartTimeEdit->setEnabled(false);
        mUi->mTimeZoneComboStart->setEnabled(false);
    }

    checkDirtyStatus();
}

void IncidenceDateTime::enableEndEdit(bool enable)
{
    mUi->mEndDateEdit->setEnabled(enable);

    if (mUi->mEndCheck->isChecked() || mUi->mStartCheck->isChecked()) {
        mUi->mWholeDayCheck->setEnabled(true);
        setTimeZoneLabelEnabled(!mUi->mWholeDayCheck->isChecked());
    } else {
        mUi->mWholeDayCheck->setEnabled(false);
        mUi->mWholeDayCheck->setChecked(false);
        setTimeZoneLabelEnabled(false);
    }

    if (enable) {
        mUi->mEndTimeEdit->setEnabled(!mUi->mWholeDayCheck->isChecked());
        mUi->mTimeZoneComboEnd->setEnabled(!mUi->mWholeDayCheck->isChecked());
    } else {
        mUi->mEndTimeEdit->setEnabled(false);
        mUi->mTimeZoneComboEnd->setEnabled(false);
    }

    checkDirtyStatus();
}

364
bool IncidenceDateTime::timeZonesAreLocal(const QDateTime &start, const QDateTime &end)
365
366
367
{
    // Returns false if the incidence start or end timezone is not the local zone.

Laurent Montel's avatar
Laurent Montel committed
368
    if ((start.isValid() && start.timeZone() != QTimeZone::systemTimeZone()) || (end.isValid() && end.timeZone() != QTimeZone::systemTimeZone())) {
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
        return false;
    } else {
        return true;
    }
}

void IncidenceDateTime::enableTimeEdits()
{
    // NOTE: assumes that the initial times are initialized.
    const bool wholeDayChecked = mUi->mWholeDayCheck->isChecked();

    setTimeZoneLabelEnabled(!wholeDayChecked);

    if (mUi->mStartCheck->isChecked()) {
        mUi->mStartTimeEdit->setEnabled(!wholeDayChecked);
        mUi->mTimeZoneComboStart->setEnabled(!wholeDayChecked);
385
386
387
388
        if (wholeDayChecked)
            mUi->mTimeZoneComboStart->setFloating(true);
        else
            mUi->mTimeZoneComboStart->selectTimeZoneFor(mInitialStartDT);
389
390
391
392
    }
    if (mUi->mEndCheck->isChecked()) {
        mUi->mEndTimeEdit->setEnabled(!wholeDayChecked);
        mUi->mTimeZoneComboEnd->setEnabled(!wholeDayChecked);
393
394
395
396
        if (wholeDayChecked)
            mUi->mTimeZoneComboEnd->setFloating(true);
        else
            mUi->mTimeZoneComboEnd->selectTimeZoneFor(mInitialEndDT);
397
398
399
400
401
402
    }

    /**
       When editing a whole-day event, unchecking mWholeDayCheck shouldn't set both
       times to 00:00. DTSTART must always be smaller than DTEND
     */
Laurent Montel's avatar
Laurent Montel committed
403
404
405
    if (sender() == mUi->mWholeDayCheck && !wholeDayChecked // Somebody unchecked it, the incidence will now have time.
        && mUi->mStartCheck->isChecked() && mUi->mEndCheck->isChecked() // The incidence has both start and end/due dates
        && currentStartDateTime() == currentEndDateTime()) { // DTSTART == DTEND. This is illegal, lets correct it.
406
407
408
409
410
411
        // Not sure about the best time here... doesn't really matter, when someone unchecks mWholeDayCheck, she will
        // always want to set a time.
        mUi->mStartTimeEdit->setTime(QTime(0, 0));
        mUi->mEndTimeEdit->setTime(QTime(1, 0));
    }

412
    const bool currentlyVisible = mUi->mTimeZoneLabel->text().contains(QLatin1String("&lt;&lt;"));
413
414
415
416
417
418
419
420
    setTimeZonesVisibility(!wholeDayChecked && mTimezoneCombosWereVisibile);
    mTimezoneCombosWereVisibile = currentlyVisible;
    if (!wholeDayChecked && !timeZonesAreLocal(currentStartDateTime(), currentEndDateTime())) {
        setTimeZonesVisibility(true);
        mTimezoneCombosWereVisibile = true;
    }
}

421
bool IncidenceDateTime::isDirty(const KCalendarCore::Todo::Ptr &todo) const
422
423
424
{
    Q_ASSERT(todo);

Laurent Montel's avatar
Laurent Montel committed
425
    const bool hasDateTimes = mUi->mStartCheck->isChecked() || mUi->mEndCheck->isChecked();
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440

    // First check the start time/date of the todo
    if (todo->hasStartDate() != mUi->mStartCheck->isChecked()) {
        return true;
    }

    if ((hasDateTimes && todo->allDay()) != mUi->mWholeDayCheck->isChecked()) {
        return true;
    }

    if (todo->hasDueDate() != mUi->mEndCheck->isChecked()) {
        return true;
    }

    if (mUi->mStartCheck->isChecked()) {
441
        // Use mActiveStartTime. This is the QTimeZone selected on load coming from
442
443
        // the combobox. We use this one as it can slightly differ (e.g. missing
        // country code in the incidence time spec) from the incidence.
444
        if (!identical(currentStartDateTime(), mInitialStartDT)) {
445
446
447
448
            return true;
        }
    }

449
    if (mUi->mEndCheck->isChecked() && !identical(currentEndDateTime(), mInitialEndDT)) {
450
451
452
453
454
455
456
457
        return true;
    }

    return false;
}

/// Event specific methods

458
bool IncidenceDateTime::isDirty(const KCalendarCore::Event::Ptr &event) const
459
460
461
462
463
{
    if (event->allDay() != mUi->mWholeDayCheck->isChecked()) {
        return true;
    }

Laurent Montel's avatar
Laurent Montel committed
464
    if (mUi->mFreeBusyCheck->isChecked() && event->transparency() != KCalendarCore::Event::Opaque) {
465
466
467
        return true;
    }

Laurent Montel's avatar
Laurent Montel committed
468
    if (!mUi->mFreeBusyCheck->isChecked() && event->transparency() != KCalendarCore::Event::Transparent) {
469
470
471
472
        return true;
    }

    if (event->allDay()) {
Laurent Montel's avatar
Laurent Montel committed
473
        if (mUi->mStartDateEdit->date() != mInitialStartDT.date() || mUi->mEndDateEdit->date() != mInitialEndDT.date()) {
474
475
476
            return true;
        }
    } else {
477
        if (!identical(currentStartDateTime(), mInitialStartDT) || !identical(currentEndDateTime(), mInitialEndDT)) {
478
479
480
481
482
483
484
            return true;
        }
    }

    return false;
}

485
bool IncidenceDateTime::isDirty(const KCalendarCore::Journal::Ptr &journal) const
486
487
488
489
490
491
492
493
494
495
{
    if (journal->allDay() != mUi->mWholeDayCheck->isChecked()) {
        return true;
    }

    if (journal->allDay()) {
        if (mUi->mStartDateEdit->date() != mInitialStartDT.date()) {
            return true;
        }
    } else {
496
        if (!identical(currentStartDateTime(), mInitialStartDT)) {
497
498
499
500
501
502
503
504
505
            return true;
        }
    }

    return false;
}

/// Private methods

506
QDateTime IncidenceDateTime::currentStartDateTime() const
507
{
508
509
510
    QDateTime dt(mUi->mStartDateEdit->date(), mUi->mStartTimeEdit->time());
    mUi->mTimeZoneComboStart->applyTimeZoneTo(dt);
    return dt;
511
512
}

513
QDateTime IncidenceDateTime::currentEndDateTime() const
514
{
515
516
517
    QDateTime dt(mUi->mEndDateEdit->date(), mUi->mEndTimeEdit->time());
    mUi->mTimeZoneComboEnd->applyTimeZoneTo(dt);
    return dt;
518
519
}

520
void IncidenceDateTime::load(const KCalendarCore::Event::Ptr &event, bool isTemplate, bool templateOverridesTimes)
521
522
523
{
    // First en/disable the necessary ui bits and pieces
    mUi->mStartCheck->setVisible(false);
Laurent Montel's avatar
Laurent Montel committed
524
    mUi->mStartCheck->setChecked(true); // Set to checked so we can reuse enableTimeEdits.
525
    mUi->mEndCheck->setVisible(false);
Laurent Montel's avatar
Laurent Montel committed
526
    mUi->mEndCheck->setChecked(true); // Set to checked so we can reuse enableTimeEdits.
527
528

    // Start time
Laurent Montel's avatar
Laurent Montel committed
529
    connect(mUi->mStartTimeEdit, &KTimeComboBox::timeChanged, this,
Laurent Montel's avatar
Laurent Montel committed
530
            &IncidenceDateTime::updateStartTime); // when editing with mouse, or up/down arrows
Laurent Montel's avatar
Laurent Montel committed
531
    connect(mUi->mStartTimeEdit, &KTimeComboBox::timeEdited, this,
Laurent Montel's avatar
Laurent Montel committed
532
533
            &IncidenceDateTime::updateStartTime); // When editing with any key except up/down
    connect(mUi->mStartDateEdit, &KDateComboBox::dateChanged, this, &IncidenceDateTime::updateStartDate);
Laurent Montel's avatar
Laurent Montel committed
534
    connect(mUi->mTimeZoneComboStart,
Laurent Montel's avatar
Laurent Montel committed
535
            static_cast<void (IncidenceEditorNG::KTimeZoneComboBox::*)(int)>(&IncidenceEditorNG::KTimeZoneComboBox::currentIndexChanged),
Laurent Montel's avatar
Laurent Montel committed
536
537
            this,
            &IncidenceDateTime::updateStartSpec);
538

539
    // End time
Laurent Montel's avatar
Laurent Montel committed
540
541
542
543
544
545
    connect(mUi->mEndTimeEdit, &KTimeComboBox::timeChanged, this, &IncidenceDateTime::checkDirtyStatus);
    connect(mUi->mEndTimeEdit, &KTimeComboBox::timeEdited, this, &IncidenceDateTime::checkDirtyStatus);
    connect(mUi->mEndDateEdit, &KDateComboBox::dateChanged, this, &IncidenceDateTime::checkDirtyStatus);
    connect(mUi->mEndTimeEdit, &KTimeComboBox::timeChanged, this, &IncidenceDateTime::endTimeChanged);
    connect(mUi->mEndTimeEdit, &KTimeComboBox::timeEdited, this, &IncidenceDateTime::endTimeChanged);
    connect(mUi->mEndDateEdit, &KDateComboBox::dateChanged, this, &IncidenceDateTime::endDateChanged);
Laurent Montel's avatar
Laurent Montel committed
546
    connect(mUi->mTimeZoneComboEnd,
Laurent Montel's avatar
Laurent Montel committed
547
            static_cast<void (IncidenceEditorNG::KTimeZoneComboBox::*)(int)>(&IncidenceEditorNG::KTimeZoneComboBox::currentIndexChanged),
Laurent Montel's avatar
Laurent Montel committed
548
            this,
549
            &IncidenceDateTime::updateEndSpec);
550
551
552
553
554
555
556
557
558
    mUi->mWholeDayCheck->setChecked(event->allDay());
    enableTimeEdits();

    if (isTemplate) {
        if (templateOverridesTimes) {
            // We only use the template times if the user didn't override them.
            setTimes(event->dtStart(), event->dtEnd());
        }
    } else {
559
560
        QDateTime startDT = event->dtStart();
        QDateTime endDT = event->dtEnd();
561
562
563
564
        setDateTimes(startDT, endDT);
    }

    switch (event->transparency()) {
565
    case KCalendarCore::Event::Transparent:
566
567
        mUi->mFreeBusyCheck->setChecked(false);
        break;
568
    case KCalendarCore::Event::Opaque:
569
570
571
572
573
        mUi->mFreeBusyCheck->setChecked(true);
        break;
    }
}

574
void IncidenceDateTime::load(const KCalendarCore::Journal::Ptr &journal, bool isTemplate, bool templateOverridesTimes)
575
576
577
{
    // First en/disable the necessary ui bits and pieces
    mUi->mStartCheck->setVisible(false);
Laurent Montel's avatar
Laurent Montel committed
578
    mUi->mStartCheck->setChecked(true); // Set to checked so we can reuse enableTimeEdits.
579
    mUi->mEndCheck->setVisible(false);
Laurent Montel's avatar
Laurent Montel committed
580
    mUi->mEndCheck->setChecked(true); // Set to checked so we can reuse enableTimeEdits.
581
582
583
584
585
586
587
    mUi->mEndDateEdit->setVisible(false);
    mUi->mEndTimeEdit->setVisible(false);
    mUi->mTimeZoneComboEnd->setVisible(false);
    mUi->mEndLabel->setVisible(false);
    mUi->mFreeBusyCheck->setVisible(false);

    // Start time
Laurent Montel's avatar
Laurent Montel committed
588
589
    connect(mUi->mStartTimeEdit, &KTimeComboBox::timeChanged, this, &IncidenceDateTime::updateStartTime);
    connect(mUi->mStartDateEdit, &KDateComboBox::dateChanged, this, &IncidenceDateTime::updateStartDate);
Laurent Montel's avatar
Laurent Montel committed
590
    connect(mUi->mTimeZoneComboStart,
Laurent Montel's avatar
Laurent Montel committed
591
            static_cast<void (IncidenceEditorNG::KTimeZoneComboBox::*)(int)>(&IncidenceEditorNG::KTimeZoneComboBox::currentIndexChanged),
Laurent Montel's avatar
Laurent Montel committed
592
593
            this,
            &IncidenceDateTime::updateStartSpec);
594
595
596
597
598
599
    mUi->mWholeDayCheck->setChecked(journal->allDay());
    enableTimeEdits();

    if (isTemplate) {
        if (templateOverridesTimes) {
            // We only use the template times if the user didn't override them.
600
            setTimes(journal->dtStart(), QDateTime());
601
602
        }
    } else {
603
        QDateTime startDT = journal->dtStart();
604
605
        // Journals do not have end dates, so pick an arbitrary suitable date.
        setDateTimes(startDT, startDT);
606
607
608
    }
}

609
void IncidenceDateTime::load(const KCalendarCore::Todo::Ptr &todo, bool isTemplate, bool templateOverridesTimes)
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
{
    // First en/disable the necessary ui bits and pieces
    mUi->mStartCheck->setVisible(true);
    mUi->mStartCheck->setChecked(todo->hasStartDate());
    mUi->mStartDateEdit->setEnabled(todo->hasStartDate());
    mUi->mStartTimeEdit->setEnabled(todo->hasStartDate());
    mUi->mTimeZoneComboStart->setEnabled(todo->hasStartDate());

    mUi->mEndLabel->setText(i18nc("@label The due date/time of a to-do", "Due:"));
    mUi->mEndCheck->setVisible(true);
    mUi->mEndCheck->setChecked(todo->hasDueDate());
    mUi->mEndDateEdit->setEnabled(todo->hasDueDate());
    mUi->mEndTimeEdit->setEnabled(todo->hasDueDate());
    mUi->mTimeZoneComboEnd->setEnabled(todo->hasDueDate());

    // These fields where not enabled in the old code either:
    mUi->mFreeBusyCheck->setVisible(false);

    const bool hasDateTimes = mUi->mEndCheck->isChecked() || mUi->mStartCheck->isChecked();
    mUi->mWholeDayCheck->setChecked(hasDateTimes && todo->allDay());
    mUi->mWholeDayCheck->setEnabled(hasDateTimes);

    // Connect to the right logic
    connect(mUi->mStartCheck, &QCheckBox::toggled, this, &IncidenceDateTime::enableStartEdit);
    connect(mUi->mStartCheck, &QCheckBox::toggled, this, &IncidenceDateTime::startDateTimeToggled);
Laurent Montel's avatar
Laurent Montel committed
635
636
637
    connect(mUi->mStartDateEdit, &KDateComboBox::dateChanged, this, &IncidenceDateTime::updateStartDate);
    connect(mUi->mStartTimeEdit, &KTimeComboBox::timeChanged, this, &IncidenceDateTime::updateStartTime);
    connect(mUi->mStartTimeEdit, &KTimeComboBox::timeEdited, this, &IncidenceDateTime::updateStartTime);
Laurent Montel's avatar
Laurent Montel committed
638
    connect(mUi->mTimeZoneComboStart,
Laurent Montel's avatar
Laurent Montel committed
639
            static_cast<void (IncidenceEditorNG::KTimeZoneComboBox::*)(int)>(&IncidenceEditorNG::KTimeZoneComboBox::currentIndexChanged),
Laurent Montel's avatar
Laurent Montel committed
640
            this,
641
            &IncidenceDateTime::updateStartSpec);
642
643
644

    connect(mUi->mEndCheck, &QCheckBox::toggled, this, &IncidenceDateTime::enableEndEdit);
    connect(mUi->mEndCheck, &QCheckBox::toggled, this, &IncidenceDateTime::endDateTimeToggled);
Laurent Montel's avatar
Laurent Montel committed
645
646
647
648
649
650
    connect(mUi->mEndDateEdit, &KDateComboBox::dateChanged, this, &IncidenceDateTime::checkDirtyStatus);
    connect(mUi->mEndTimeEdit, &KTimeComboBox::timeChanged, this, &IncidenceDateTime::checkDirtyStatus);
    connect(mUi->mEndTimeEdit, &KTimeComboBox::timeEdited, this, &IncidenceDateTime::checkDirtyStatus);
    connect(mUi->mEndDateEdit, &KDateComboBox::dateChanged, this, &IncidenceDateTime::endDateChanged);
    connect(mUi->mEndTimeEdit, &KTimeComboBox::timeChanged, this, &IncidenceDateTime::endTimeChanged);
    connect(mUi->mEndTimeEdit, &KTimeComboBox::timeEdited, this, &IncidenceDateTime::endTimeChanged);
Laurent Montel's avatar
Laurent Montel committed
651
    connect(mUi->mTimeZoneComboEnd,
Laurent Montel's avatar
Laurent Montel committed
652
            static_cast<void (IncidenceEditorNG::KTimeZoneComboBox::*)(int)>(&IncidenceEditorNG::KTimeZoneComboBox::currentIndexChanged),
Laurent Montel's avatar
Laurent Montel committed
653
            this,
654
            &IncidenceDateTime::updateEndSpec);
655
    const QDateTime rightNow = QDateTime::currentDateTime();
656
657
658
659

    if (isTemplate) {
        if (templateOverridesTimes) {
            // We only use the template times if the user didn't override them.
660
            setTimes(todo->dtStart(), todo->dateTime(KCalendarCore::Incidence::RoleEnd));
661
662
        }
    } else {
663
        const QDateTime endDT = todo->hasDueDate() ? todo->dtDue(true /** first */) : rightNow;
Laurent Montel's avatar
Laurent Montel committed
664
        const QDateTime startDT = todo->hasStartDate() ? todo->dtStart(true /** first */) : rightNow;
665
666
667
668
        setDateTimes(startDT, endDT);
    }
}

669
void IncidenceDateTime::save(const KCalendarCore::Event::Ptr &event)
670
{
671
672
673
    event->setAllDay(mUi->mWholeDayCheck->isChecked());
    event->setDtStart(currentStartDateTime());
    event->setDtEnd(currentEndDateTime());
674
675
676

    // Free == Event::Transparent
    // Busy == Event::Opaque
Laurent Montel's avatar
Laurent Montel committed
677
    event->setTransparency(mUi->mFreeBusyCheck->isChecked() ? KCalendarCore::Event::Opaque : KCalendarCore::Event::Transparent);
678
679
}

680
void IncidenceDateTime::save(const KCalendarCore::Todo::Ptr &todo)
681
682
{
    if (mUi->mStartCheck->isChecked()) {
683
        todo->setDtStart(currentStartDateTime());
684
685
686
687
        todo->setAllDay(mUi->mWholeDayCheck->isChecked());
        if (currentStartDateTime() != mInitialStartDT) {
            // We don't offer any way to edit the current completed occurrence.
            // So, if the start date changes, reset the dtRecurrence
688
            todo->setDtRecurrence(currentStartDateTime());
689
690
        }
    } else {
691
        todo->setDtStart(QDateTime());
692
693
694
    }

    if (mUi->mEndCheck->isChecked()) {
695
        todo->setDtDue(currentEndDateTime(), true /* first */);
696
697
        todo->setAllDay(mUi->mWholeDayCheck->isChecked());
    } else {
698
        todo->setDtDue(QDateTime());
699
700
701
    }
}

702
void IncidenceDateTime::save(const KCalendarCore::Journal::Ptr &journal)
703
704
{
    journal->setAllDay(mUi->mWholeDayCheck->isChecked());
705
    journal->setDtStart(currentStartDateTime());
706
707
}

708
void IncidenceDateTime::setDateTimes(const QDateTime &start, const QDateTime &end)
709
710
711
712
{
    if (start.isValid()) {
        mUi->mStartDateEdit->setDate(start.date());
        mUi->mStartTimeEdit->setTime(start.time());
713
        mUi->mTimeZoneComboStart->selectTimeZoneFor(start);
714
    } else {
715
        QDateTime dt = QDateTime::currentDateTime();
716
717
        mUi->mStartDateEdit->setDate(dt.date());
        mUi->mStartTimeEdit->setTime(dt.time());
718
        mUi->mTimeZoneComboStart->selectTimeZoneFor(dt);
719
720
721
722
723
    }

    if (end.isValid()) {
        mUi->mEndDateEdit->setDate(end.date());
        mUi->mEndTimeEdit->setTime(end.time());
724
        mUi->mTimeZoneComboEnd->selectTimeZoneFor(end);
725
    } else {
726
        QDateTime dt(QDate::currentDate(), QTime::currentTime().addSecs(60 * 60));
727
728
        mUi->mEndDateEdit->setDate(dt.date());
        mUi->mEndTimeEdit->setTime(dt.time());
729
        mUi->mTimeZoneComboEnd->selectTimeZoneFor(dt);
730
731
    }

732
    mCurrentStartDateTime = currentStartDateTime();
733
734
735
736
737
738
739
740
741
742
743
744
    Q_EMIT startDateChanged(start.date());
    Q_EMIT startTimeChanged(start.time());
    Q_EMIT endDateChanged(end.date());
    Q_EMIT endTimeChanged(end.time());

    updateStartToolTips();
    updateEndToolTips();
}

void IncidenceDateTime::updateStartToolTips()
{
    if (mUi->mStartCheck->isChecked()) {
Laurent Montel's avatar
Laurent Montel committed
745
        QString datetimeStr = KCalUtils::IncidenceFormatter::dateTimeToString(currentStartDateTime(), mUi->mWholeDayCheck->isChecked(), false);
746
747
748
749
750
751
752
753
754
755
756
        mUi->mStartDateEdit->setToolTip(i18n("Starts: %1", datetimeStr));
        mUi->mStartTimeEdit->setToolTip(i18n("Starts: %1", datetimeStr));
    } else {
        mUi->mStartDateEdit->setToolTip(i18n("Starting Date"));
        mUi->mStartTimeEdit->setToolTip(i18n("Starting Time"));
    }
}

void IncidenceDateTime::updateEndToolTips()
{
    if (mUi->mStartCheck->isChecked()) {
Laurent Montel's avatar
Laurent Montel committed
757
        QString datetimeStr = KCalUtils::IncidenceFormatter::dateTimeToString(currentEndDateTime(), mUi->mWholeDayCheck->isChecked(), false);
758
        if (mLoadedIncidence->type() == KCalendarCore::Incidence::TypeTodo) {
759
760
761
762
763
764
765
            mUi->mEndDateEdit->setToolTip(i18n("Due on: %1", datetimeStr));
            mUi->mEndTimeEdit->setToolTip(i18n("Due on: %1", datetimeStr));
        } else {
            mUi->mEndDateEdit->setToolTip(i18n("Ends: %1", datetimeStr));
            mUi->mEndTimeEdit->setToolTip(i18n("Ends: %1", datetimeStr));
        }
    } else {
766
        if (mLoadedIncidence->type() == KCalendarCore::Incidence::TypeTodo) {
767
768
769
770
771
772
773
774
775
            mUi->mEndDateEdit->setToolTip(i18n("Due Date"));
            mUi->mEndTimeEdit->setToolTip(i18n("Due Time"));
        } else {
            mUi->mEndDateEdit->setToolTip(i18n("Ending Date"));
            mUi->mEndTimeEdit->setToolTip(i18n("Ending Time"));
        }
    }
}

776
void IncidenceDateTime::setTimes(const QDateTime &start, const QDateTime &end)
777
778
779
780
781
782
783
784
785
{
    // like setDateTimes(), but it set only the start/end time, not the date
    // it is used while applying a template to an event.
    mUi->mStartTimeEdit->blockSignals(true);
    mUi->mStartTimeEdit->setTime(start.time());
    mUi->mStartTimeEdit->blockSignals(false);

    mUi->mEndTimeEdit->setTime(end.time());

786
787
    mUi->mTimeZoneComboStart->selectTimeZoneFor(start);
    mUi->mTimeZoneComboEnd->selectTimeZoneFor(end);
788

Laurent Montel's avatar
Laurent Montel committed
789
    //   emitDateTimeStr();
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
}

void IncidenceDateTime::setStartDate(const QDate &newDate)
{
    mUi->mStartDateEdit->setDate(newDate);
    updateStartDate(newDate);
}

void IncidenceDateTime::setStartTime(const QTime &newTime)
{
    mUi->mStartTimeEdit->setTime(newTime);
    updateStartTime(newTime);
}

bool IncidenceDateTime::startDateTimeEnabled() const
{
    return mUi->mStartCheck->isChecked();
}

bool IncidenceDateTime::endDateTimeEnabled() const
{
    return mUi->mEndCheck->isChecked();
}

814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
void IncidenceDateTime::focusInvalidField()
{
    if (startDateTimeEnabled()) {
        if (!mUi->mStartDateEdit->isValid()) {
            mUi->mStartDateEdit->setFocus();
            return;
        }
        if (!mUi->mWholeDayCheck->isChecked() && !mUi->mStartTimeEdit->isValid()) {
            mUi->mStartTimeEdit->setFocus();
            return;
        }
    }
    if (endDateTimeEnabled()) {
        if (!mUi->mEndDateEdit->isValid()) {
            mUi->mEndDateEdit->setFocus();
            return;
        }
        if (!mUi->mWholeDayCheck->isChecked() && !mUi->mEndTimeEdit->isValid()) {
            mUi->mEndTimeEdit->setFocus();
            return;
        }
    }
Laurent Montel's avatar
Laurent Montel committed
836
    if (startDateTimeEnabled() && endDateTimeEnabled() && currentStartDateTime() > currentEndDateTime()) {
837
838
839
840
841
842
843
844
        if (mUi->mEndDateEdit->date() < mUi->mStartDateEdit->date()) {
            mUi->mEndDateEdit->setFocus();
        } else {
            mUi->mEndTimeEdit->setFocus();
        }
    }
}

845
846
bool IncidenceDateTime::isValid() const
{
847
848
849
850
851
852
853
854
855
856
857
    if (startDateTimeEnabled()) {
        if (!mUi->mStartDateEdit->isValid()) {
            mLastErrorString = i18nc("@info", "Invalid start date.");
            qCDebug(INCIDENCEEDITOR_LOG) << mLastErrorString;
            return false;
        }
        if (!mUi->mWholeDayCheck->isChecked() && !mUi->mStartTimeEdit->isValid()) {
            mLastErrorString = i18nc("@info", "Invalid start time.");
            qCDebug(INCIDENCEEDITOR_LOG) << mLastErrorString;
            return false;
        }
858
859
    }

860
861
862
863
864
865
866
867
868
869
870
    if (endDateTimeEnabled()) {
        if (!mUi->mEndDateEdit->isValid()) {
            mLastErrorString = i18nc("@info", "Invalid end date.");
            qCDebug(INCIDENCEEDITOR_LOG) << mLastErrorString;
            return false;
        }
        if (!mUi->mWholeDayCheck->isChecked() && !mUi->mEndTimeEdit->isValid()) {
            mLastErrorString = i18nc("@info", "Invalid end time.");
            qCDebug(INCIDENCEEDITOR_LOG) << mLastErrorString;
            return false;
        }
871
872
    }

Laurent Montel's avatar
Laurent Montel committed
873
    if (startDateTimeEnabled() && endDateTimeEnabled() && currentStartDateTime() > currentEndDateTime()) {
874
        if (mLoadedIncidence->type() == KCalendarCore::Incidence::TypeEvent) {
875
876
877
            mLastErrorString = i18nc("@info",
                                     "The event ends before it starts.\n"
                                     "Please correct dates and times.");
878
        } else if (mLoadedIncidence->type() == KCalendarCore::Incidence::TypeTodo) {
879
880
881
            mLastErrorString = i18nc("@info",
                                     "The to-do is due before it starts.\n"
                                     "Please correct dates and times.");
882
        } else if (mLoadedIncidence->type() == KCalendarCore::Incidence::TypeJournal) {
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
            return true;
        }

        qCDebug(INCIDENCEEDITOR_LOG) << mLastErrorString;
        return false;
    } else {
        mLastErrorString.clear();
        return true;
    }
}

void IncidenceDateTime::printDebugInfo() const
{
    qCDebug(INCIDENCEEDITOR_LOG) << "startDateTimeEnabled()          : " << startDateTimeEnabled();
    qCDebug(INCIDENCEEDITOR_LOG) << "endDateTimeEnabled()            : " << endDateTimeEnabled();
Laurent Montel's avatar
Laurent Montel committed
898
899
900
901
902
903
904
905
    qCDebug(INCIDENCEEDITOR_LOG) << "currentStartDateTime().isValid(): " << currentStartDateTime().isValid();
    qCDebug(INCIDENCEEDITOR_LOG) << "currentEndDateTime().isValid()  : " << currentEndDateTime().isValid();
    qCDebug(INCIDENCEEDITOR_LOG) << "currentStartDateTime()          : " << currentStartDateTime().toString();
    qCDebug(INCIDENCEEDITOR_LOG) << "currentEndDateTime()            : " << currentEndDateTime().toString();
    qCDebug(INCIDENCEEDITOR_LOG) << "Incidence type                  : " << mLoadedIncidence->type();
    qCDebug(INCIDENCEEDITOR_LOG) << "allday                          : " << mLoadedIncidence->allDay();
    qCDebug(INCIDENCEEDITOR_LOG) << "mInitialStartDT                 : " << mInitialStartDT.toString();
    qCDebug(INCIDENCEEDITOR_LOG) << "mInitialEndDT                   : " << mInitialEndDT.toString();
Laurent Montel's avatar
Laurent Montel committed
906

907
908
909
910
    qCDebug(INCIDENCEEDITOR_LOG) << "currentStartDateTime().timeZone(): " << currentStartDateTime().timeZone().id();
    qCDebug(INCIDENCEEDITOR_LOG) << "currentEndDateTime().timeZone()  : " << currentEndDateTime().timeZone().id();
    qCDebug(INCIDENCEEDITOR_LOG) << "mInitialStartDT.timeZone()       : " << mInitialStartDT.timeZone().id();
    qCDebug(INCIDENCEEDITOR_LOG) << "mInitialEndDT.timeZone()         : " << mInitialEndDT.timeZone().id();
Laurent Montel's avatar
Laurent Montel committed
911

Laurent Montel's avatar
Laurent Montel committed
912
    qCDebug(INCIDENCEEDITOR_LOG) << "dirty test1: " << (mLoadedIncidence->allDay() != mUi->mWholeDayCheck->isChecked());
913
914
    if (mLoadedIncidence->type() == KCalendarCore::Incidence::TypeEvent) {
        KCalendarCore::Event::Ptr event = mLoadedIncidence.staticCast<KCalendarCore::Event>();
Laurent Montel's avatar
Laurent Montel committed
915
916
        qCDebug(INCIDENCEEDITOR_LOG) << "dirty test2: " << (mUi->mFreeBusyCheck->isChecked() && event->transparency() != KCalendarCore::Event::Opaque);
        qCDebug(INCIDENCEEDITOR_LOG) << "dirty test3: " << (!mUi->mFreeBusyCheck->isChecked() && event->transparency() != KCalendarCore::Event::Transparent);
917
918
919
    }

    if (mLoadedIncidence->allDay()) {
Laurent Montel's avatar
Laurent Montel committed
920
        qCDebug(INCIDENCEEDITOR_LOG) << "dirty test4: "
Laurent Montel's avatar
Laurent Montel committed
921
                                     << (mUi->mStartDateEdit->date() != mInitialStartDT.date() || mUi->mEndDateEdit->date() != mInitialEndDT.date());
922
    } else {
Laurent Montel's avatar
Laurent Montel committed
923
924
925
926
        qCDebug(INCIDENCEEDITOR_LOG) << "dirty test4.1: " << (currentStartDateTime() != mInitialStartDT);
        qCDebug(INCIDENCEEDITOR_LOG) << "dirty test4.2: " << (currentEndDateTime() != mInitialEndDT);
        qCDebug(INCIDENCEEDITOR_LOG) << "dirty test4.3: " << (currentStartDateTime().timeZone() != mInitialStartDT.timeZone());
        qCDebug(INCIDENCEEDITOR_LOG) << "dirty test4.4: " << (currentEndDateTime().timeZone() != mInitialEndDT.timeZone());
927
928
929
930
931
932
933
    }
}

void IncidenceDateTime::setTimeZoneLabelEnabled(bool enable)
{
    mUi->mTimeZoneLabel->setVisible(enable);
}