Build with clang.
[kdepim.git] / kalarm / alarmtimewidget.cpp
blobb619190ebf28a6406e8d98b4f6a771f2101b4177
1 /*
2 * alarmtimewidget.cpp - alarm date/time entry widget
3 * Program: kalarm
4 * Copyright © 2001-2011 by David Jarvie <djarvie@kde.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "kalarm.h"
23 #include "buttongroup.h"
24 #include "checkbox.h"
25 #include "datetime.h"
26 #include "messagebox.h"
27 #include "preferences.h"
28 #include "pushbutton.h"
29 #include "radiobutton.h"
30 #include "synchtimer.h"
31 #include "timeedit.h"
32 #include "timespinbox.h"
33 #include "timezonecombo.h"
34 #include "alarmtimewidget.moc"
36 #include <libkdepim/kdateedit.h>
38 #include <kdialog.h>
39 #include <klocale.h>
41 #include <QGroupBox>
42 #include <QGridLayout>
43 #include <QLabel>
45 static const QTime time_23_59(23, 59);
48 const int AlarmTimeWidget::maxDelayTime = 999*60 + 59; // < 1000 hours
50 QString AlarmTimeWidget::i18n_TimeAfterPeriod()
52 return i18nc("@info/plain", "Enter the length of time (in hours and minutes) after "
53 "the current time to schedule the alarm.");
57 /******************************************************************************
58 * Construct a widget with a group box and title.
60 AlarmTimeWidget::AlarmTimeWidget(const QString& groupBoxTitle, Mode mode, QWidget* parent)
61 : QFrame(parent),
62 mMinDateTimeIsNow(false),
63 mPastMax(false),
64 mMinMaxTimeSet(false)
66 init(mode, groupBoxTitle);
69 /******************************************************************************
70 * Construct a widget without a group box or title.
72 AlarmTimeWidget::AlarmTimeWidget(Mode mode, QWidget* parent)
73 : QFrame(parent),
74 mMinDateTimeIsNow(false),
75 mPastMax(false),
76 mMinMaxTimeSet(false)
78 init(mode);
81 void AlarmTimeWidget::init(Mode mode, const QString& title)
83 static const QString recurText = i18nc("@info/plain",
84 "If a recurrence is configured, the start date/time will be adjusted "
85 "to the first recurrence on or after the entered date/time.");
86 static const QString tzText = i18nc("@info/plain",
87 "This uses KAlarm's default time zone, set in the Configuration dialog.");
89 QWidget* topWidget;
90 if (title.isEmpty())
91 topWidget = this;
92 else
94 QBoxLayout* layout = new QVBoxLayout(this);
95 layout->setMargin(0);
96 layout->setSpacing(0);
97 topWidget = new QGroupBox(title, this);
98 layout->addWidget(topWidget);
100 mDeferring = mode & DEFER_TIME;
101 mButtonGroup = new ButtonGroup(this);
102 connect(mButtonGroup, SIGNAL(buttonSet(QAbstractButton*)), SLOT(slotButtonSet(QAbstractButton*)));
103 QVBoxLayout* topLayout = new QVBoxLayout(topWidget);
104 topLayout->setSpacing(KDialog::spacingHint());
105 topLayout->setMargin(title.isEmpty() ? 0 : KDialog::marginHint());
107 // At time radio button/label
108 mAtTimeRadio = new RadioButton((mDeferring ? i18nc("@option:radio", "Defer to date/time:") : i18nc("@option:radio", "At date/time:")), topWidget);
109 mAtTimeRadio->setFixedSize(mAtTimeRadio->sizeHint());
110 mAtTimeRadio->setWhatsThis(mDeferring ? i18nc("@info:whatsthis", "Reschedule the alarm to the specified date and time.")
111 : i18nc("@info:whatsthis", "Specify the date, or date and time, to schedule the alarm."));
112 mButtonGroup->addButton(mAtTimeRadio);
114 // Date edit box
115 mDateEdit = new KPIM::KDateEdit(topWidget);
116 connect(mDateEdit, SIGNAL(dateEntered(QDate)), SLOT(dateTimeChanged()));
117 mDateEdit->setWhatsThis(i18nc("@info:whatsthis",
118 "<para>Enter the date to schedule the alarm.</para>"
119 "<para>%1</para>", (mDeferring ? tzText : recurText)));
120 mAtTimeRadio->setFocusWidget(mDateEdit);
122 // Time edit box and Any time checkbox
123 KHBox* timeBox = new KHBox(topWidget);
124 timeBox->setSpacing(2*KDialog::spacingHint());
125 mTimeEdit = new TimeEdit(timeBox);
126 mTimeEdit->setFixedSize(mTimeEdit->sizeHint());
127 connect(mTimeEdit, SIGNAL(valueChanged(int)), SLOT(dateTimeChanged()));
128 mTimeEdit->setWhatsThis(i18nc("@info:whatsthis",
129 "<para>Enter the time to schedule the alarm.</para>"
130 "<para>%1</para>"
131 "<para>%2</para>", (mDeferring ? tzText : recurText), TimeSpinBox::shiftWhatsThis()));
133 mAnyTime = -1; // current status is uninitialised
134 if (mode == DEFER_TIME)
136 mAnyTimeAllowed = false;
137 mAnyTimeCheckBox = 0;
139 else
141 mAnyTimeAllowed = true;
142 mAnyTimeCheckBox = new CheckBox(i18nc("@option:check", "Any time"), timeBox);
143 mAnyTimeCheckBox->setFixedSize(mAnyTimeCheckBox->sizeHint());
144 connect(mAnyTimeCheckBox, SIGNAL(toggled(bool)), SLOT(slotAnyTimeToggled(bool)));
145 mAnyTimeCheckBox->setWhatsThis(i18nc("@info:whatsthis",
146 "Check to specify only a date (without a time) for the alarm. The alarm will trigger at the first opportunity on the selected date."));
149 // 'Time from now' radio button/label
150 mAfterTimeRadio = new RadioButton((mDeferring ? i18nc("@option:radio", "Defer for time interval:") : i18nc("@option:radio", "Time from now:")), topWidget);
151 mAfterTimeRadio->setFixedSize(mAfterTimeRadio->sizeHint());
152 mAfterTimeRadio->setWhatsThis(mDeferring ? i18nc("@info:whatsthis", "Reschedule the alarm for the specified time interval after now.")
153 : i18nc("@info:whatsthis", "Schedule the alarm after the specified time interval from now."));
154 mButtonGroup->addButton(mAfterTimeRadio);
156 // Delay time spin box
157 mDelayTimeEdit = new TimeSpinBox(1, maxDelayTime, topWidget);
158 mDelayTimeEdit->setValue(1439);
159 mDelayTimeEdit->setFixedSize(mDelayTimeEdit->sizeHint());
160 connect(mDelayTimeEdit, SIGNAL(valueChanged(int)), SLOT(delayTimeChanged(int)));
161 mDelayTimeEdit->setWhatsThis(mDeferring ? i18nc("@info:whatsthis", "<para>%1</para><para>%2</para>", i18n_TimeAfterPeriod(), TimeSpinBox::shiftWhatsThis())
162 : i18nc("@info:whatsthis", "<para>%1</para><para>%2</para><para>%3</para>", i18n_TimeAfterPeriod(), recurText, TimeSpinBox::shiftWhatsThis()));
163 mAfterTimeRadio->setFocusWidget(mDelayTimeEdit);
165 // Set up the layout, either narrow or wide
166 QGridLayout* grid = new QGridLayout();
167 grid->setMargin(0);
168 topLayout->addLayout(grid);
169 if (mDeferring)
171 grid->addWidget(mAtTimeRadio, 0, 0);
172 grid->addWidget(mDateEdit, 0, 1, Qt::AlignLeft);
173 grid->addWidget(timeBox, 1, 1, Qt::AlignLeft);
174 grid->setColumnStretch(2, 1);
175 topLayout->addStretch();
176 QHBoxLayout* layout = new QHBoxLayout();
177 topLayout->addLayout(layout);
178 layout->addWidget(mAfterTimeRadio);
179 layout->addWidget(mDelayTimeEdit);
180 layout->addStretch();
182 else
184 grid->addWidget(mAtTimeRadio, 0, 0, Qt::AlignLeft);
185 grid->addWidget(mDateEdit, 0, 1, Qt::AlignLeft);
186 grid->addWidget(timeBox, 0, 2, Qt::AlignLeft);
187 grid->setRowStretch(1, 1);
188 grid->addWidget(mAfterTimeRadio, 2, 0, Qt::AlignLeft);
189 grid->addWidget(mDelayTimeEdit, 2, 1, Qt::AlignLeft);
191 // Time zone selection push button
192 mTimeZoneButton = new PushButton(i18nc("@action:button", "Time Zone..."), topWidget);
193 connect(mTimeZoneButton, SIGNAL(clicked()), SLOT(showTimeZoneSelector()));
194 mTimeZoneButton->setWhatsThis(i18nc("@info:whatsthis",
195 "Choose a time zone for this alarm which is different from the default time zone set in KAlarm's configuration dialog."));
196 grid->addWidget(mTimeZoneButton, 2, 2, 1, 2, Qt::AlignRight);
198 grid->setColumnStretch(2, 1);
199 topLayout->addStretch();
201 QHBoxLayout* layout = new QHBoxLayout();
202 topLayout->addLayout(layout);
203 layout->setSpacing(2*KDialog::spacingHint());
205 // Time zone selector
206 mTimeZoneBox = new KHBox(topWidget); // this is to control the QWhatsThis text display area
207 mTimeZoneBox->setMargin(0);
208 mTimeZoneBox->setSpacing(KDialog::spacingHint());
209 QLabel* label = new QLabel(i18nc("@label:listbox", "Time zone:"), mTimeZoneBox);
210 mTimeZone = new TimeZoneCombo(mTimeZoneBox);
211 mTimeZone->setMaxVisibleItems(15);
212 connect(mTimeZone, SIGNAL(activated(int)), SLOT(slotTimeZoneChanged()));
213 mTimeZoneBox->setWhatsThis(i18nc("@info:whatsthis", "Select the time zone to use for this alarm."));
214 label->setBuddy(mTimeZone);
215 layout->addWidget(mTimeZoneBox);
217 // Time zone checkbox
218 mNoTimeZone = new CheckBox(i18nc("@option:check", "Ignore time zone"), topWidget);
219 connect(mNoTimeZone, SIGNAL(toggled(bool)), SLOT(slotTimeZoneToggled(bool)));
220 mNoTimeZone->setWhatsThis(i18nc("@info:whatsthis",
221 "<para>Check to use the local computer time, ignoring time zones.</para>"
222 "<para>You are recommended not to use this option if the alarm has a "
223 "recurrence specified in hours/minutes. If you do, the alarm may "
224 "occur at unexpected times after daylight saving time shifts.</para>"));
225 layout->addWidget(mNoTimeZone);
226 layout->addStretch();
228 // Initially show only the time zone button, not time zone selector
229 mTimeZoneBox->hide();
230 mNoTimeZone->hide();
233 // Initialise the radio button statuses
234 mAtTimeRadio->setChecked(true);
235 slotButtonSet(mAtTimeRadio);
237 // Timeout every minute to update alarm time fields.
238 MinuteTimer::connect(this, SLOT(updateTimes()));
241 /******************************************************************************
242 * Set or clear read-only status for the controls
244 void AlarmTimeWidget::setReadOnly(bool ro)
246 mAtTimeRadio->setReadOnly(ro);
247 mDateEdit->setReadOnly(ro);
248 mTimeEdit->setReadOnly(ro);
249 if (mAnyTimeCheckBox)
250 mAnyTimeCheckBox->setReadOnly(ro);
251 mAfterTimeRadio->setReadOnly(ro);
252 if (!mDeferring)
254 mTimeZone->setReadOnly(ro);
255 mNoTimeZone->setReadOnly(ro);
257 mDelayTimeEdit->setReadOnly(ro);
260 /******************************************************************************
261 * Select the "Time from now" radio button.
263 void AlarmTimeWidget::selectTimeFromNow(int minutes)
265 mAfterTimeRadio->setChecked(true);
266 if (minutes > 0)
267 mDelayTimeEdit->setValue(minutes);
270 /******************************************************************************
271 * Fetch the entered date/time.
272 * If 'checkExpired' is true and the entered value <= current time, an error occurs.
273 * If 'minsFromNow' is non-null, it is set to the number of minutes' delay selected,
274 * or to zero if a date/time was entered.
275 * In this case, if 'showErrorMessage' is true, output an error message.
276 * 'errorWidget' if non-null, is set to point to the widget containing the error.
277 * Reply = invalid date/time if error.
279 KDateTime AlarmTimeWidget::getDateTime(int* minsFromNow, bool checkExpired, bool showErrorMessage, QWidget** errorWidget) const
281 if (minsFromNow)
282 *minsFromNow = 0;
283 if (errorWidget)
284 *errorWidget = 0;
285 KDateTime now = KDateTime::currentUtcDateTime();
286 now.setTime(QTime(now.time().hour(), now.time().minute(), 0));
287 if (!mAtTimeRadio->isChecked())
289 if (!mDelayTimeEdit->isValid())
291 if (showErrorMessage)
292 KAMessageBox::sorry(const_cast<AlarmTimeWidget*>(this), i18nc("@info", "Invalid time"));
293 if (errorWidget)
294 *errorWidget = mDelayTimeEdit;
295 return KDateTime();
297 int delayMins = mDelayTimeEdit->value();
298 if (minsFromNow)
299 *minsFromNow = delayMins;
300 return now.addSecs(delayMins * 60).toTimeSpec(mTimeSpec);
302 else
304 bool dateOnly = mAnyTimeAllowed && mAnyTimeCheckBox && mAnyTimeCheckBox->isChecked();
305 if (!mDateEdit->date().isValid() || !mTimeEdit->isValid())
307 // The date and/or time is invalid
308 if (!mDateEdit->date().isValid())
310 if (showErrorMessage)
311 KAMessageBox::sorry(const_cast<AlarmTimeWidget*>(this), i18nc("@info", "Invalid date"));
312 if (errorWidget)
313 *errorWidget = mDateEdit;
315 else
317 if (showErrorMessage)
318 KAMessageBox::sorry(const_cast<AlarmTimeWidget*>(this), i18nc("@info", "Invalid time"));
319 if (errorWidget)
320 *errorWidget = mTimeEdit;
322 return KDateTime();
325 KDateTime result;
326 if (dateOnly)
328 result = KDateTime(mDateEdit->date(), mTimeSpec);
329 if (checkExpired && result.date() < now.date())
331 if (showErrorMessage)
332 KAMessageBox::sorry(const_cast<AlarmTimeWidget*>(this), i18nc("@info", "Alarm date has already expired"));
333 if (errorWidget)
334 *errorWidget = mDateEdit;
335 return KDateTime();
338 else
340 result = KDateTime(mDateEdit->date(), mTimeEdit->time(), mTimeSpec);
341 if (checkExpired && result <= now.addSecs(1))
343 if (showErrorMessage)
344 KAMessageBox::sorry(const_cast<AlarmTimeWidget*>(this), i18nc("@info", "Alarm time has already expired"));
345 if (errorWidget)
346 *errorWidget = mTimeEdit;
347 return KDateTime();
350 return result;
354 /******************************************************************************
355 * Set the date/time.
357 void AlarmTimeWidget::setDateTime(const DateTime& dt)
359 // Set the time zone first so that the call to dateTimeChanged() works correctly.
360 if (mDeferring)
361 mTimeSpec = dt.timeSpec().isValid() ? dt.timeSpec() : KDateTime::LocalZone;
362 else
364 KTimeZone tz = dt.timeZone();
365 mNoTimeZone->setChecked(!tz.isValid());
366 mTimeZone->setTimeZone(tz.isValid() ? tz : Preferences::timeZone());
367 slotTimeZoneChanged();
370 if (dt.date().isValid())
372 mTimeEdit->setValue(dt.effectiveTime());
373 mDateEdit->setDate(dt.date());
374 dateTimeChanged(); // update the delay time edit box
376 else
378 mTimeEdit->setValid(false);
379 mDateEdit->setDate(QDate());
380 mDelayTimeEdit->setValid(false);
382 if (mAnyTimeCheckBox)
384 bool dateOnly = dt.isDateOnly();
385 if (dateOnly)
386 mAnyTimeAllowed = true;
387 mAnyTimeCheckBox->setChecked(dateOnly);
388 setAnyTime();
392 /******************************************************************************
393 * Set the minimum date/time to track the current time.
395 void AlarmTimeWidget::setMinDateTimeIsCurrent()
397 mMinDateTimeIsNow = true;
398 mMinDateTime = KDateTime();
399 KDateTime now = KDateTime::currentDateTime(mTimeSpec);
400 mDateEdit->setMinimumDate(now.date());
401 setMaxMinTimeIf(now);
404 /******************************************************************************
405 * Set the minimum date/time, adjusting the entered date/time if necessary.
406 * If 'dt' is invalid, any current minimum date/time is cleared.
408 void AlarmTimeWidget::setMinDateTime(const KDateTime& dt)
410 mMinDateTimeIsNow = false;
411 mMinDateTime = dt.toTimeSpec(mTimeSpec);
412 mDateEdit->setMinimumDate(mMinDateTime.date());
413 setMaxMinTimeIf(KDateTime::currentDateTime(mTimeSpec));
416 /******************************************************************************
417 * Set the maximum date/time, adjusting the entered date/time if necessary.
418 * If 'dt' is invalid, any current maximum date/time is cleared.
420 void AlarmTimeWidget::setMaxDateTime(const DateTime& dt)
422 mPastMax = false;
423 if (dt.isValid() && dt.isDateOnly())
424 mMaxDateTime = dt.effectiveKDateTime().addSecs(24*3600 - 60).toTimeSpec(mTimeSpec);
425 else
426 mMaxDateTime = dt.kDateTime().toTimeSpec(mTimeSpec);
427 mDateEdit->setMaximumDate(mMaxDateTime.date());
428 KDateTime now = KDateTime::currentDateTime(mTimeSpec);
429 setMaxMinTimeIf(now);
430 setMaxDelayTime(now);
433 /******************************************************************************
434 * If the minimum and maximum date/times fall on the same date, set the minimum
435 * and maximum times in the time edit box.
437 void AlarmTimeWidget::setMaxMinTimeIf(const KDateTime& now)
439 int mint = 0;
440 QTime maxt = time_23_59;
441 mMinMaxTimeSet = false;
442 if (mMaxDateTime.isValid())
444 bool set = true;
445 KDateTime minDT;
446 if (mMinDateTimeIsNow)
447 minDT = now.addSecs(60);
448 else if (mMinDateTime.isValid())
449 minDT = mMinDateTime;
450 else
451 set = false;
452 if (set && mMaxDateTime.date() == minDT.date())
454 // The minimum and maximum times are on the same date, so
455 // constrain the time value.
456 mint = minDT.time().hour()*60 + minDT.time().minute();
457 maxt = mMaxDateTime.time();
458 mMinMaxTimeSet = true;
461 mTimeEdit->setMinimum(mint);
462 mTimeEdit->setMaximum(maxt);
463 mTimeEdit->setWrapping(!mint && maxt == time_23_59);
466 /******************************************************************************
467 * Set the maximum value for the delay time edit box, depending on the maximum
468 * value for the date/time.
470 void AlarmTimeWidget::setMaxDelayTime(const KDateTime& now)
472 int maxVal = maxDelayTime;
473 if (mMaxDateTime.isValid())
475 if (now.date().daysTo(mMaxDateTime.date()) < 100) // avoid possible 32-bit overflow on secsTo()
477 KDateTime dt(now);
478 dt.setTime(QTime(now.time().hour(), now.time().minute(), 0)); // round down to nearest minute
479 maxVal = dt.secsTo(mMaxDateTime) / 60;
480 if (maxVal > maxDelayTime)
481 maxVal = maxDelayTime;
484 mDelayTimeEdit->setMaximum(maxVal);
487 /******************************************************************************
488 * Set the status for whether a time is specified, or just a date.
490 void AlarmTimeWidget::setAnyTime()
492 int old = mAnyTime;
493 mAnyTime = (mAtTimeRadio->isChecked() && mAnyTimeAllowed && mAnyTimeCheckBox && mAnyTimeCheckBox->isChecked()) ? 1 : 0;
494 if (mAnyTime != old)
495 emit dateOnlyToggled(mAnyTime);
498 /******************************************************************************
499 * Enable/disable the "date only" radio button.
501 void AlarmTimeWidget::enableAnyTime(bool enable)
503 if (mAnyTimeCheckBox)
505 mAnyTimeAllowed = enable;
506 bool at = mAtTimeRadio->isChecked();
507 mAnyTimeCheckBox->setEnabled(enable && at);
508 if (at)
509 mTimeEdit->setEnabled(!enable || !mAnyTimeCheckBox->isChecked());
510 setAnyTime();
514 /******************************************************************************
515 * Called every minute to update the alarm time data entry fields.
516 * If the maximum date/time has been reached, a 'pastMax()' signal is emitted.
518 void AlarmTimeWidget::updateTimes()
520 KDateTime now;
521 if (mMinDateTimeIsNow)
523 // Make sure that the minimum date is updated when the day changes
524 now = KDateTime::currentDateTime(mTimeSpec);
525 mDateEdit->setMinimumDate(now.date());
527 if (mMaxDateTime.isValid())
529 if (!now.isValid())
530 now = KDateTime::currentDateTime(mTimeSpec);
531 if (!mPastMax)
533 // Check whether the maximum date/time has now been reached
534 if (now.date() >= mMaxDateTime.date())
536 // The current date has reached or has passed the maximum date
537 if (now.date() > mMaxDateTime.date()
538 || (!mAnyTime && now.time() > mTimeEdit->maxTime()))
540 mPastMax = true;
541 emit pastMax();
543 else if (mMinDateTimeIsNow && !mMinMaxTimeSet)
545 // The minimum date/time tracks the clock, so set the minimum
546 // and maximum times
547 setMaxMinTimeIf(now);
551 setMaxDelayTime(now);
554 if (mAtTimeRadio->isChecked())
555 dateTimeChanged();
556 else
557 delayTimeChanged(mDelayTimeEdit->value());
561 /******************************************************************************
562 * Called when the radio button states have been changed.
563 * Updates the appropriate edit box.
565 void AlarmTimeWidget::slotButtonSet(QAbstractButton*)
567 bool at = mAtTimeRadio->isChecked();
568 mDateEdit->setEnabled(at);
569 mTimeEdit->setEnabled(at && (!mAnyTimeAllowed || !mAnyTimeCheckBox || !mAnyTimeCheckBox->isChecked()));
570 if (mAnyTimeCheckBox)
571 mAnyTimeCheckBox->setEnabled(at && mAnyTimeAllowed);
572 // Ensure that the value of the delay edit box is > 0.
573 KDateTime att(mDateEdit->date(), mTimeEdit->time(), mTimeSpec);
574 int minutes = (KDateTime::currentUtcDateTime().secsTo(att) + 59) / 60;
575 if (minutes <= 0)
576 mDelayTimeEdit->setValid(true);
577 mDelayTimeEdit->setEnabled(!at);
578 setAnyTime();
581 /******************************************************************************
582 * Called after the mAnyTimeCheckBox checkbox has been toggled.
584 void AlarmTimeWidget::slotAnyTimeToggled(bool on)
586 on = (on && mAnyTimeAllowed);
587 mTimeEdit->setEnabled(!on && mAtTimeRadio->isChecked());
588 setAnyTime();
589 if (on)
590 emit changed(KDateTime(mDateEdit->date(), mTimeSpec));
591 else
592 emit changed(KDateTime(mDateEdit->date(), mTimeEdit->time(), mTimeSpec));
595 /******************************************************************************
596 * Called after a new selection has been made in the time zone combo box.
597 * Re-evaluates the time specification to use.
599 void AlarmTimeWidget::slotTimeZoneChanged()
601 if (mNoTimeZone->isChecked())
602 mTimeSpec = KDateTime::ClockTime;
603 else
605 KTimeZone tz = mTimeZone->timeZone();
606 mTimeSpec = tz.isValid() ? KDateTime::Spec(tz) : KDateTime::LocalZone;
608 if (!mTimeZoneBox->isVisible() && mTimeSpec != Preferences::timeZone())
610 // The current time zone is not the default one, so
611 // show the time zone selection controls
612 showTimeZoneSelector();
614 mMinDateTime = mMinDateTime.toTimeSpec(mTimeSpec);
615 mMaxDateTime = mMaxDateTime.toTimeSpec(mTimeSpec);
616 updateTimes();
619 /******************************************************************************
620 * Called after the mNoTimeZone checkbox has been toggled.
622 void AlarmTimeWidget::slotTimeZoneToggled(bool on)
624 mTimeZone->setEnabled(!on);
625 slotTimeZoneChanged();
628 /******************************************************************************
629 * Called after the mTimeZoneButton button has been clicked.
630 * Show the time zone selection controls, and hide the button.
632 void AlarmTimeWidget::showTimeZoneSelector()
634 mTimeZoneButton->hide();
635 mTimeZoneBox->show();
636 mNoTimeZone->show();
639 /******************************************************************************
640 * Show or hide the time zone button.
642 void AlarmTimeWidget::showMoreOptions(bool more)
644 if (more)
646 if (!mTimeZoneBox->isVisible())
647 mTimeZoneButton->show();
649 else
650 mTimeZoneButton->hide();
653 /******************************************************************************
654 * Called when the date or time edit box values have changed.
655 * Updates the time delay edit box accordingly.
657 void AlarmTimeWidget::dateTimeChanged()
659 KDateTime dt(mDateEdit->date(), mTimeEdit->time(), mTimeSpec);
660 int minutes = (KDateTime::currentUtcDateTime().secsTo(dt) + 59) / 60;
661 bool blocked = mDelayTimeEdit->signalsBlocked();
662 mDelayTimeEdit->blockSignals(true); // prevent infinite recursion between here and delayTimeChanged()
663 if (minutes <= 0 || minutes > mDelayTimeEdit->maximum())
664 mDelayTimeEdit->setValid(false);
665 else
666 mDelayTimeEdit->setValue(minutes);
667 mDelayTimeEdit->blockSignals(blocked);
668 if (mAnyTimeAllowed && mAnyTimeCheckBox && mAnyTimeCheckBox->isChecked())
669 emit changed(KDateTime(dt.date(), mTimeSpec));
670 else
671 emit changed(dt);
674 /******************************************************************************
675 * Called when the delay time edit box value has changed.
676 * Updates the Date and Time edit boxes accordingly.
678 void AlarmTimeWidget::delayTimeChanged(int minutes)
680 if (mDelayTimeEdit->isValid())
682 QDateTime dt = KDateTime::currentUtcDateTime().addSecs(minutes * 60).toTimeSpec(mTimeSpec).dateTime();
683 bool blockedT = mTimeEdit->signalsBlocked();
684 bool blockedD = mDateEdit->signalsBlocked();
685 mTimeEdit->blockSignals(true); // prevent infinite recursion between here and dateTimeChanged()
686 mDateEdit->blockSignals(true);
687 mTimeEdit->setValue(dt.time());
688 mDateEdit->setDate(dt.date());
689 mTimeEdit->blockSignals(blockedT);
690 mDateEdit->blockSignals(blockedD);
691 emit changed(KDateTime(dt.date(), dt.time(), mTimeSpec));
695 // vim: et sw=4: