• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kalarm

  • sources
  • kde-4.14
  • kdepim
  • kalarm
alarmtimewidget.cpp
Go to the documentation of this file.
1 /*
2  * alarmtimewidget.cpp - alarm date/time entry widget
3  * Program: kalarm
4  * Copyright © 2001-2011 by David Jarvie <djarvie@kde.org>
5  *
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.
10  *
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.
15  *
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.
19  */
20 
21 #include "kalarm.h"
22 
23 #include "buttongroup.h"
24 #include "checkbox.h"
25 #include "messagebox.h"
26 #include "preferences.h"
27 #include "pushbutton.h"
28 #include "radiobutton.h"
29 #include "synchtimer.h"
30 #include "timeedit.h"
31 #include "timespinbox.h"
32 #include "timezonecombo.h"
33 #include "alarmtimewidget.h"
34 
35 #include <kalarmcal/datetime.h>
36 
37 #include <kdatecombobox.h>
38 #include <kdialog.h>
39 #include <klocale.h>
40 
41 #include <QGroupBox>
42 #include <QGridLayout>
43 #include <QLabel>
44 
45 static const QTime time_23_59(23, 59);
46 
47 
48 const int AlarmTimeWidget::maxDelayTime = 999*60 + 59; // < 1000 hours
49 
50 QString AlarmTimeWidget::i18n_TimeAfterPeriod()
51 {
52  return i18nc("@info/plain", "Enter the length of time (in hours and minutes) after "
53  "the current time to schedule the alarm.");
54 }
55 
56 
57 /******************************************************************************
58 * Construct a widget with a group box and title.
59 */
60 AlarmTimeWidget::AlarmTimeWidget(const QString& groupBoxTitle, Mode mode, QWidget* parent)
61  : QFrame(parent),
62  mMinDateTimeIsNow(false),
63  mPastMax(false),
64  mMinMaxTimeSet(false)
65 {
66  init(mode, groupBoxTitle);
67 }
68 
69 /******************************************************************************
70 * Construct a widget without a group box or title.
71 */
72 AlarmTimeWidget::AlarmTimeWidget(Mode mode, QWidget* parent)
73  : QFrame(parent),
74  mMinDateTimeIsNow(false),
75  mPastMax(false),
76  mMinMaxTimeSet(false)
77 {
78  init(mode);
79 }
80 
81 void AlarmTimeWidget::init(Mode mode, const QString& title)
82 {
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.");
88 
89  QWidget* topWidget;
90  if (title.isEmpty())
91  topWidget = this;
92  else
93  {
94  QBoxLayout* layout = new QVBoxLayout(this);
95  layout->setMargin(0);
96  layout->setSpacing(0);
97  topWidget = new QGroupBox(title, this);
98  layout->addWidget(topWidget);
99  }
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());
106 
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);
113 
114  // Date edit box
115  mDateEdit = new KDateComboBox(topWidget);
116  mDateEdit->setOptions(KDateComboBox::EditDate | KDateComboBox::SelectDate | KDateComboBox::DatePicker);
117  connect(mDateEdit, SIGNAL(dateEntered(QDate)), SLOT(dateTimeChanged()));
118  mDateEdit->setWhatsThis(i18nc("@info:whatsthis",
119  "<para>Enter the date to schedule the alarm.</para>"
120  "<para>%1</para>", (mDeferring ? tzText : recurText)));
121  mAtTimeRadio->setFocusWidget(mDateEdit);
122 
123  // Time edit box and Any time checkbox
124  KHBox* timeBox = new KHBox(topWidget);
125  timeBox->setSpacing(2*KDialog::spacingHint());
126  mTimeEdit = new TimeEdit(timeBox);
127  mTimeEdit->setFixedSize(mTimeEdit->sizeHint());
128  connect(mTimeEdit, SIGNAL(valueChanged(int)), SLOT(dateTimeChanged()));
129  mTimeEdit->setWhatsThis(i18nc("@info:whatsthis",
130  "<para>Enter the time to schedule the alarm.</para>"
131  "<para>%1</para>"
132  "<para>%2</para>", (mDeferring ? tzText : recurText), TimeSpinBox::shiftWhatsThis()));
133 
134  mAnyTime = -1; // current status is uninitialised
135  if (mode == DEFER_TIME)
136  {
137  mAnyTimeAllowed = false;
138  mAnyTimeCheckBox = 0;
139  }
140  else
141  {
142  mAnyTimeAllowed = true;
143  mAnyTimeCheckBox = new CheckBox(i18nc("@option:check", "Any time"), timeBox);
144  mAnyTimeCheckBox->setFixedSize(mAnyTimeCheckBox->sizeHint());
145  connect(mAnyTimeCheckBox, SIGNAL(toggled(bool)), SLOT(slotAnyTimeToggled(bool)));
146  mAnyTimeCheckBox->setWhatsThis(i18nc("@info:whatsthis",
147  "Check to specify only a date (without a time) for the alarm. The alarm will trigger at the first opportunity on the selected date."));
148  }
149 
150  // 'Time from now' radio button/label
151  mAfterTimeRadio = new RadioButton((mDeferring ? i18nc("@option:radio", "Defer for time interval:") : i18nc("@option:radio", "Time from now:")), topWidget);
152  mAfterTimeRadio->setFixedSize(mAfterTimeRadio->sizeHint());
153  mAfterTimeRadio->setWhatsThis(mDeferring ? i18nc("@info:whatsthis", "Reschedule the alarm for the specified time interval after now.")
154  : i18nc("@info:whatsthis", "Schedule the alarm after the specified time interval from now."));
155  mButtonGroup->addButton(mAfterTimeRadio);
156 
157  // Delay time spin box
158  mDelayTimeEdit = new TimeSpinBox(1, maxDelayTime, topWidget);
159  mDelayTimeEdit->setValue(1439);
160  mDelayTimeEdit->setFixedSize(mDelayTimeEdit->sizeHint());
161  connect(mDelayTimeEdit, SIGNAL(valueChanged(int)), SLOT(delayTimeChanged(int)));
162  mDelayTimeEdit->setWhatsThis(mDeferring ? i18nc("@info:whatsthis", "<para>%1</para><para>%2</para>", i18n_TimeAfterPeriod(), TimeSpinBox::shiftWhatsThis())
163  : i18nc("@info:whatsthis", "<para>%1</para><para>%2</para><para>%3</para>", i18n_TimeAfterPeriod(), recurText, TimeSpinBox::shiftWhatsThis()));
164  mAfterTimeRadio->setFocusWidget(mDelayTimeEdit);
165 
166  // Set up the layout, either narrow or wide
167  QGridLayout* grid = new QGridLayout();
168  grid->setMargin(0);
169  topLayout->addLayout(grid);
170  if (mDeferring)
171  {
172  grid->addWidget(mAtTimeRadio, 0, 0);
173  grid->addWidget(mDateEdit, 0, 1, Qt::AlignLeft);
174  grid->addWidget(timeBox, 1, 1, Qt::AlignLeft);
175  grid->setColumnStretch(2, 1);
176  topLayout->addStretch();
177  QHBoxLayout* layout = new QHBoxLayout();
178  topLayout->addLayout(layout);
179  layout->addWidget(mAfterTimeRadio);
180  layout->addWidget(mDelayTimeEdit);
181  layout->addStretch();
182  }
183  else
184  {
185  grid->addWidget(mAtTimeRadio, 0, 0, Qt::AlignLeft);
186  grid->addWidget(mDateEdit, 0, 1, Qt::AlignLeft);
187  grid->addWidget(timeBox, 0, 2, Qt::AlignLeft);
188  grid->setRowStretch(1, 1);
189  grid->addWidget(mAfterTimeRadio, 2, 0, Qt::AlignLeft);
190  grid->addWidget(mDelayTimeEdit, 2, 1, Qt::AlignLeft);
191 
192  // Time zone selection push button
193  mTimeZoneButton = new PushButton(i18nc("@action:button", "Time Zone..."), topWidget);
194  connect(mTimeZoneButton, SIGNAL(clicked()), SLOT(showTimeZoneSelector()));
195  mTimeZoneButton->setWhatsThis(i18nc("@info:whatsthis",
196  "Choose a time zone for this alarm which is different from the default time zone set in KAlarm's configuration dialog."));
197  grid->addWidget(mTimeZoneButton, 2, 2, 1, 2, Qt::AlignRight);
198 
199  grid->setColumnStretch(2, 1);
200  topLayout->addStretch();
201 
202  QHBoxLayout* layout = new QHBoxLayout();
203  topLayout->addLayout(layout);
204  layout->setSpacing(2*KDialog::spacingHint());
205 
206  // Time zone selector
207  mTimeZoneBox = new KHBox(topWidget); // this is to control the QWhatsThis text display area
208  mTimeZoneBox->setMargin(0);
209  mTimeZoneBox->setSpacing(KDialog::spacingHint());
210  QLabel* label = new QLabel(i18nc("@label:listbox", "Time zone:"), mTimeZoneBox);
211  mTimeZone = new TimeZoneCombo(mTimeZoneBox);
212  mTimeZone->setMaxVisibleItems(15);
213  connect(mTimeZone, SIGNAL(activated(int)), SLOT(slotTimeZoneChanged()));
214  mTimeZoneBox->setWhatsThis(i18nc("@info:whatsthis", "Select the time zone to use for this alarm."));
215  label->setBuddy(mTimeZone);
216  layout->addWidget(mTimeZoneBox);
217 
218  // Time zone checkbox
219  mNoTimeZone = new CheckBox(i18nc("@option:check", "Ignore time zone"), topWidget);
220  connect(mNoTimeZone, SIGNAL(toggled(bool)), SLOT(slotTimeZoneToggled(bool)));
221  mNoTimeZone->setWhatsThis(i18nc("@info:whatsthis",
222  "<para>Check to use the local computer time, ignoring time zones.</para>"
223  "<para>You are recommended not to use this option if the alarm has a "
224  "recurrence specified in hours/minutes. If you do, the alarm may "
225  "occur at unexpected times after daylight saving time shifts.</para>"));
226  layout->addWidget(mNoTimeZone);
227  layout->addStretch();
228 
229  // Initially show only the time zone button, not time zone selector
230  mTimeZoneBox->hide();
231  mNoTimeZone->hide();
232  }
233 
234  // Initialise the radio button statuses
235  mAtTimeRadio->setChecked(true);
236  slotButtonSet(mAtTimeRadio);
237 
238  // Timeout every minute to update alarm time fields.
239  MinuteTimer::connect(this, SLOT(updateTimes()));
240 }
241 
242 /******************************************************************************
243 * Set or clear read-only status for the controls
244 */
245 void AlarmTimeWidget::setReadOnly(bool ro)
246 {
247  mAtTimeRadio->setReadOnly(ro);
248  mDateEdit->setOptions(ro ? KDateComboBox::Options(0) : KDateComboBox::EditDate | KDateComboBox::SelectDate | KDateComboBox::DatePicker);
249  mTimeEdit->setReadOnly(ro);
250  if (mAnyTimeCheckBox)
251  mAnyTimeCheckBox->setReadOnly(ro);
252  mAfterTimeRadio->setReadOnly(ro);
253  if (!mDeferring)
254  {
255  mTimeZone->setReadOnly(ro);
256  mNoTimeZone->setReadOnly(ro);
257  }
258  mDelayTimeEdit->setReadOnly(ro);
259 }
260 
261 /******************************************************************************
262 * Select the "Time from now" radio button.
263 */
264 void AlarmTimeWidget::selectTimeFromNow(int minutes)
265 {
266  mAfterTimeRadio->setChecked(true);
267  if (minutes > 0)
268  mDelayTimeEdit->setValue(minutes);
269 }
270 
271 /******************************************************************************
272 * Fetch the entered date/time.
273 * If 'checkExpired' is true and the entered value <= current time, an error occurs.
274 * If 'minsFromNow' is non-null, it is set to the number of minutes' delay selected,
275 * or to zero if a date/time was entered.
276 * In this case, if 'showErrorMessage' is true, output an error message.
277 * 'errorWidget' if non-null, is set to point to the widget containing the error.
278 * Reply = invalid date/time if error.
279 */
280 KDateTime AlarmTimeWidget::getDateTime(int* minsFromNow, bool checkExpired, bool showErrorMessage, QWidget** errorWidget) const
281 {
282  if (minsFromNow)
283  *minsFromNow = 0;
284  if (errorWidget)
285  *errorWidget = 0;
286  KDateTime now = KDateTime::currentUtcDateTime();
287  now.setTime(QTime(now.time().hour(), now.time().minute(), 0));
288  if (!mAtTimeRadio->isChecked())
289  {
290  if (!mDelayTimeEdit->isValid())
291  {
292  if (showErrorMessage)
293  KAMessageBox::sorry(const_cast<AlarmTimeWidget*>(this), i18nc("@info", "Invalid time"));
294  if (errorWidget)
295  *errorWidget = mDelayTimeEdit;
296  return KDateTime();
297  }
298  int delayMins = mDelayTimeEdit->value();
299  if (minsFromNow)
300  *minsFromNow = delayMins;
301  return now.addSecs(delayMins * 60).toTimeSpec(mTimeSpec);
302  }
303  else
304  {
305  bool dateOnly = mAnyTimeAllowed && mAnyTimeCheckBox && mAnyTimeCheckBox->isChecked();
306  if (!mDateEdit->date().isValid() || !mTimeEdit->isValid())
307  {
308  // The date and/or time is invalid
309  if (!mDateEdit->date().isValid())
310  {
311  if (showErrorMessage)
312  KAMessageBox::sorry(const_cast<AlarmTimeWidget*>(this), i18nc("@info", "Invalid date"));
313  if (errorWidget)
314  *errorWidget = mDateEdit;
315  }
316  else
317  {
318  if (showErrorMessage)
319  KAMessageBox::sorry(const_cast<AlarmTimeWidget*>(this), i18nc("@info", "Invalid time"));
320  if (errorWidget)
321  *errorWidget = mTimeEdit;
322  }
323  return KDateTime();
324  }
325 
326  KDateTime result;
327  if (dateOnly)
328  {
329  result = KDateTime(mDateEdit->date(), mTimeSpec);
330  if (checkExpired && result.date() < now.date())
331  {
332  if (showErrorMessage)
333  KAMessageBox::sorry(const_cast<AlarmTimeWidget*>(this), i18nc("@info", "Alarm date has already expired"));
334  if (errorWidget)
335  *errorWidget = mDateEdit;
336  return KDateTime();
337  }
338  }
339  else
340  {
341  result = KDateTime(mDateEdit->date(), mTimeEdit->time(), mTimeSpec);
342  if (checkExpired && result <= now.addSecs(1))
343  {
344  if (showErrorMessage)
345  KAMessageBox::sorry(const_cast<AlarmTimeWidget*>(this), i18nc("@info", "Alarm time has already expired"));
346  if (errorWidget)
347  *errorWidget = mTimeEdit;
348  return KDateTime();
349  }
350  }
351  return result;
352  }
353 }
354 
355 /******************************************************************************
356 * Set the date/time.
357 */
358 void AlarmTimeWidget::setDateTime(const DateTime& dt)
359 {
360  // Set the time zone first so that the call to dateTimeChanged() works correctly.
361  if (mDeferring)
362  mTimeSpec = dt.timeSpec().isValid() ? dt.timeSpec() : KDateTime::LocalZone;
363  else
364  {
365  KTimeZone tz = dt.timeZone();
366  mNoTimeZone->setChecked(!tz.isValid());
367  mTimeZone->setTimeZone(tz.isValid() ? tz : Preferences::timeZone());
368  slotTimeZoneChanged();
369  }
370 
371  if (dt.date().isValid())
372  {
373  mTimeEdit->setValue(dt.effectiveTime());
374  mDateEdit->setDate(dt.date());
375  dateTimeChanged(); // update the delay time edit box
376  }
377  else
378  {
379  mTimeEdit->setValid(false);
380  mDateEdit->setDate(QDate());
381  mDelayTimeEdit->setValid(false);
382  }
383  if (mAnyTimeCheckBox)
384  {
385  bool dateOnly = dt.isDateOnly();
386  if (dateOnly)
387  mAnyTimeAllowed = true;
388  mAnyTimeCheckBox->setChecked(dateOnly);
389  setAnyTime();
390  }
391 }
392 
393 /******************************************************************************
394 * Set the minimum date/time to track the current time.
395 */
396 void AlarmTimeWidget::setMinDateTimeIsCurrent()
397 {
398  mMinDateTimeIsNow = true;
399  mMinDateTime = KDateTime();
400  KDateTime now = KDateTime::currentDateTime(mTimeSpec);
401  mDateEdit->setMinimumDate(now.date());
402  setMaxMinTimeIf(now);
403 }
404 
405 /******************************************************************************
406 * Set the minimum date/time, adjusting the entered date/time if necessary.
407 * If 'dt' is invalid, any current minimum date/time is cleared.
408 */
409 void AlarmTimeWidget::setMinDateTime(const KDateTime& dt)
410 {
411  mMinDateTimeIsNow = false;
412  mMinDateTime = dt.toTimeSpec(mTimeSpec);
413  mDateEdit->setMinimumDate(mMinDateTime.date());
414  setMaxMinTimeIf(KDateTime::currentDateTime(mTimeSpec));
415 }
416 
417 /******************************************************************************
418 * Set the maximum date/time, adjusting the entered date/time if necessary.
419 * If 'dt' is invalid, any current maximum date/time is cleared.
420 */
421 void AlarmTimeWidget::setMaxDateTime(const DateTime& dt)
422 {
423  mPastMax = false;
424  if (dt.isValid() && dt.isDateOnly())
425  mMaxDateTime = dt.effectiveKDateTime().addSecs(24*3600 - 60).toTimeSpec(mTimeSpec);
426  else
427  mMaxDateTime = dt.kDateTime().toTimeSpec(mTimeSpec);
428  mDateEdit->setMaximumDate(mMaxDateTime.date());
429  KDateTime now = KDateTime::currentDateTime(mTimeSpec);
430  setMaxMinTimeIf(now);
431  setMaxDelayTime(now);
432 }
433 
434 /******************************************************************************
435 * If the minimum and maximum date/times fall on the same date, set the minimum
436 * and maximum times in the time edit box.
437 */
438 void AlarmTimeWidget::setMaxMinTimeIf(const KDateTime& now)
439 {
440  int mint = 0;
441  QTime maxt = time_23_59;
442  mMinMaxTimeSet = false;
443  if (mMaxDateTime.isValid())
444  {
445  bool set = true;
446  KDateTime minDT;
447  if (mMinDateTimeIsNow)
448  minDT = now.addSecs(60);
449  else if (mMinDateTime.isValid())
450  minDT = mMinDateTime;
451  else
452  set = false;
453  if (set && mMaxDateTime.date() == minDT.date())
454  {
455  // The minimum and maximum times are on the same date, so
456  // constrain the time value.
457  mint = minDT.time().hour()*60 + minDT.time().minute();
458  maxt = mMaxDateTime.time();
459  mMinMaxTimeSet = true;
460  }
461  }
462  mTimeEdit->setMinimum(mint);
463  mTimeEdit->setMaximum(maxt);
464  mTimeEdit->setWrapping(!mint && maxt == time_23_59);
465 }
466 
467 /******************************************************************************
468 * Set the maximum value for the delay time edit box, depending on the maximum
469 * value for the date/time.
470 */
471 void AlarmTimeWidget::setMaxDelayTime(const KDateTime& now)
472 {
473  int maxVal = maxDelayTime;
474  if (mMaxDateTime.isValid())
475  {
476  if (now.date().daysTo(mMaxDateTime.date()) < 100) // avoid possible 32-bit overflow on secsTo()
477  {
478  KDateTime dt(now);
479  dt.setTime(QTime(now.time().hour(), now.time().minute(), 0)); // round down to nearest minute
480  maxVal = dt.secsTo(mMaxDateTime) / 60;
481  if (maxVal > maxDelayTime)
482  maxVal = maxDelayTime;
483  }
484  }
485  mDelayTimeEdit->setMaximum(maxVal);
486 }
487 
488 /******************************************************************************
489 * Set the status for whether a time is specified, or just a date.
490 */
491 void AlarmTimeWidget::setAnyTime()
492 {
493  int old = mAnyTime;
494  mAnyTime = (mAtTimeRadio->isChecked() && mAnyTimeAllowed && mAnyTimeCheckBox && mAnyTimeCheckBox->isChecked()) ? 1 : 0;
495  if (mAnyTime != old)
496  emit dateOnlyToggled(mAnyTime);
497 }
498 
499 /******************************************************************************
500 * Enable/disable the "date only" radio button.
501 */
502 void AlarmTimeWidget::enableAnyTime(bool enable)
503 {
504  if (mAnyTimeCheckBox)
505  {
506  mAnyTimeAllowed = enable;
507  bool at = mAtTimeRadio->isChecked();
508  mAnyTimeCheckBox->setEnabled(enable && at);
509  if (at)
510  mTimeEdit->setEnabled(!enable || !mAnyTimeCheckBox->isChecked());
511  setAnyTime();
512  }
513 }
514 
515 /******************************************************************************
516 * Called every minute to update the alarm time data entry fields.
517 * If the maximum date/time has been reached, a 'pastMax()' signal is emitted.
518 */
519 void AlarmTimeWidget::updateTimes()
520 {
521  KDateTime now;
522  if (mMinDateTimeIsNow)
523  {
524  // Make sure that the minimum date is updated when the day changes
525  now = KDateTime::currentDateTime(mTimeSpec);
526  mDateEdit->setMinimumDate(now.date());
527  }
528  if (mMaxDateTime.isValid())
529  {
530  if (!now.isValid())
531  now = KDateTime::currentDateTime(mTimeSpec);
532  if (!mPastMax)
533  {
534  // Check whether the maximum date/time has now been reached
535  if (now.date() >= mMaxDateTime.date())
536  {
537  // The current date has reached or has passed the maximum date
538  if (now.date() > mMaxDateTime.date()
539  || (!mAnyTime && now.time() > mTimeEdit->maxTime()))
540  {
541  mPastMax = true;
542  emit pastMax();
543  }
544  else if (mMinDateTimeIsNow && !mMinMaxTimeSet)
545  {
546  // The minimum date/time tracks the clock, so set the minimum
547  // and maximum times
548  setMaxMinTimeIf(now);
549  }
550  }
551  }
552  setMaxDelayTime(now);
553  }
554 
555  if (mAtTimeRadio->isChecked())
556  dateTimeChanged();
557  else
558  delayTimeChanged(mDelayTimeEdit->value());
559 }
560 
561 
562 /******************************************************************************
563 * Called when the radio button states have been changed.
564 * Updates the appropriate edit box.
565 */
566 void AlarmTimeWidget::slotButtonSet(QAbstractButton*)
567 {
568  bool at = mAtTimeRadio->isChecked();
569  mDateEdit->setEnabled(at);
570  mTimeEdit->setEnabled(at && (!mAnyTimeAllowed || !mAnyTimeCheckBox || !mAnyTimeCheckBox->isChecked()));
571  if (mAnyTimeCheckBox)
572  mAnyTimeCheckBox->setEnabled(at && mAnyTimeAllowed);
573  // Ensure that the value of the delay edit box is > 0.
574  KDateTime att(mDateEdit->date(), mTimeEdit->time(), mTimeSpec);
575  int minutes = (KDateTime::currentUtcDateTime().secsTo(att) + 59) / 60;
576  if (minutes <= 0)
577  mDelayTimeEdit->setValid(true);
578  mDelayTimeEdit->setEnabled(!at);
579  setAnyTime();
580 }
581 
582 /******************************************************************************
583 * Called after the mAnyTimeCheckBox checkbox has been toggled.
584 */
585 void AlarmTimeWidget::slotAnyTimeToggled(bool on)
586 {
587  on = (on && mAnyTimeAllowed);
588  mTimeEdit->setEnabled(!on && mAtTimeRadio->isChecked());
589  setAnyTime();
590  if (on)
591  emit changed(KDateTime(mDateEdit->date(), mTimeSpec));
592  else
593  emit changed(KDateTime(mDateEdit->date(), mTimeEdit->time(), mTimeSpec));
594 }
595 
596 /******************************************************************************
597 * Called after a new selection has been made in the time zone combo box.
598 * Re-evaluates the time specification to use.
599 */
600 void AlarmTimeWidget::slotTimeZoneChanged()
601 {
602  if (mNoTimeZone->isChecked())
603  mTimeSpec = KDateTime::ClockTime;
604  else
605  {
606  KTimeZone tz = mTimeZone->timeZone();
607  mTimeSpec = tz.isValid() ? KDateTime::Spec(tz) : KDateTime::LocalZone;
608  }
609  if (!mTimeZoneBox->isVisible() && mTimeSpec != Preferences::timeZone())
610  {
611  // The current time zone is not the default one, so
612  // show the time zone selection controls
613  showTimeZoneSelector();
614  }
615  mMinDateTime = mMinDateTime.toTimeSpec(mTimeSpec);
616  mMaxDateTime = mMaxDateTime.toTimeSpec(mTimeSpec);
617  updateTimes();
618 }
619 
620 /******************************************************************************
621 * Called after the mNoTimeZone checkbox has been toggled.
622 */
623 void AlarmTimeWidget::slotTimeZoneToggled(bool on)
624 {
625  mTimeZone->setEnabled(!on);
626  slotTimeZoneChanged();
627 }
628 
629 /******************************************************************************
630 * Called after the mTimeZoneButton button has been clicked.
631 * Show the time zone selection controls, and hide the button.
632 */
633 void AlarmTimeWidget::showTimeZoneSelector()
634 {
635  mTimeZoneButton->hide();
636  mTimeZoneBox->show();
637  mNoTimeZone->show();
638 }
639 
640 /******************************************************************************
641 * Show or hide the time zone button.
642 */
643 void AlarmTimeWidget::showMoreOptions(bool more)
644 {
645  if (more)
646  {
647  if (!mTimeZoneBox->isVisible())
648  mTimeZoneButton->show();
649  }
650  else
651  mTimeZoneButton->hide();
652 }
653 
654 /******************************************************************************
655 * Called when the date or time edit box values have changed.
656 * Updates the time delay edit box accordingly.
657 */
658 void AlarmTimeWidget::dateTimeChanged()
659 {
660  KDateTime dt(mDateEdit->date(), mTimeEdit->time(), mTimeSpec);
661  int minutes = (KDateTime::currentUtcDateTime().secsTo(dt) + 59) / 60;
662  bool blocked = mDelayTimeEdit->signalsBlocked();
663  mDelayTimeEdit->blockSignals(true); // prevent infinite recursion between here and delayTimeChanged()
664  if (minutes <= 0 || minutes > mDelayTimeEdit->maximum())
665  mDelayTimeEdit->setValid(false);
666  else
667  mDelayTimeEdit->setValue(minutes);
668  mDelayTimeEdit->blockSignals(blocked);
669  if (mAnyTimeAllowed && mAnyTimeCheckBox && mAnyTimeCheckBox->isChecked())
670  emit changed(KDateTime(dt.date(), mTimeSpec));
671  else
672  emit changed(dt);
673 }
674 
675 /******************************************************************************
676 * Called when the delay time edit box value has changed.
677 * Updates the Date and Time edit boxes accordingly.
678 */
679 void AlarmTimeWidget::delayTimeChanged(int minutes)
680 {
681  if (mDelayTimeEdit->isValid())
682  {
683  QDateTime dt = KDateTime::currentUtcDateTime().addSecs(minutes * 60).toTimeSpec(mTimeSpec).dateTime();
684  bool blockedT = mTimeEdit->signalsBlocked();
685  bool blockedD = mDateEdit->signalsBlocked();
686  mTimeEdit->blockSignals(true); // prevent infinite recursion between here and dateTimeChanged()
687  mDateEdit->blockSignals(true);
688  mTimeEdit->setValue(dt.time());
689  mDateEdit->setDate(dt.date());
690  mTimeEdit->blockSignals(blockedT);
691  mDateEdit->blockSignals(blockedD);
692  emit changed(KDateTime(dt.date(), dt.time(), mTimeSpec));
693  }
694 }
695 #include "moc_alarmtimewidget.cpp"
696 // vim: et sw=4:
QWidget::layout
QLayout * layout() const
CheckBox::setReadOnly
virtual void setReadOnly(bool readOnly)
QWidget
AlarmTimeWidget::Mode
Mode
Definition: alarmtimewidget.h:45
synchtimer.h
SpinBox2::setEnabled
virtual void setEnabled(bool enabled)
AlarmTimeWidget::setMinDateTimeIsCurrent
void setMinDateTimeIsCurrent()
Definition: alarmtimewidget.cpp:396
AlarmTimeWidget::i18n_TimeAfterPeriod
static QString i18n_TimeAfterPeriod()
Definition: alarmtimewidget.cpp:50
buttongroup.h
TimeSpinBox::setValid
void setValid(bool)
alarmtimewidget.h
TimeSpinBox
QGridLayout::addWidget
void addWidget(QWidget *widget, int row, int column, QFlags< Qt::AlignmentFlag > alignment)
TimeEdit::setReadOnly
virtual void setReadOnly(bool readOnly)
RadioButton
AlarmTimeWidget::pastMax
void pastMax()
QCheckBox::sizeHint
virtual QSize sizeHint() const
TimeEdit::isValid
bool isValid() const
QHBoxLayout
AlarmTimeWidget::enableAnyTime
void enableAnyTime(bool enable)
Definition: alarmtimewidget.cpp:502
QDateTime::time
QTime time() const
AlarmTimeWidget::maxDelayTime
static const int maxDelayTime
Definition: alarmtimewidget.h:67
QGridLayout
checkbox.h
AlarmTimeWidget::setMinDateTime
void setMinDateTime(const KDateTime &=KDateTime())
Definition: alarmtimewidget.cpp:409
AlarmTimeWidget::changed
void changed(const KDateTime &)
QTime
AlarmTimeWidget::setDateTime
void setDateTime(const DateTime &)
Definition: alarmtimewidget.cpp:358
TimeZoneCombo::timeZone
KTimeZone timeZone() const
TimeSpinBox::isValid
bool isValid() const
PushButton
AlarmTimeWidget::DEFER_TIME
Definition: alarmtimewidget.h:47
QLabel::setBuddy
void setBuddy(QWidget *buddy)
TimeZoneCombo
TimeEdit::setMinimum
void setMinimum(int minutes)
TimeEdit
pushbutton.h
TimeEdit::maxTime
QTime maxTime() const
QWidget::setEnabled
void setEnabled(bool)
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QGridLayout::setRowStretch
void setRowStretch(int row, int stretch)
TimeSpinBox::sizeHint
virtual QSize sizeHint() const
QGroupBox
AlarmTimeWidget::dateOnlyToggled
void dateOnlyToggled(bool anyTime)
CheckBox
Preferences::timeZone
static KTimeZone timeZone(bool reload=false)
Definition: preferences.cpp:199
SpinBox2::setReadOnly
virtual void setReadOnly(bool readOnly)
QString::isEmpty
bool isEmpty() const
AlarmTimeWidget::AlarmTimeWidget
AlarmTimeWidget(const QString &groupBoxTitle, Mode, QWidget *parent=0)
Definition: alarmtimewidget.cpp:60
QVBoxLayout
QDate
ButtonGroup::addButton
void addButton(QAbstractButton *button)
MinuteTimer::connect
static void connect(QObject *receiver, const char *member)
messagebox.h
QString
QWidget::hide
void hide()
QLayout::setMargin
void setMargin(int margin)
ComboBox::setReadOnly
virtual void setReadOnly(bool readOnly)
QObject::signalsBlocked
bool signalsBlocked() const
SpinBox2::value
int value() const
QObject::blockSignals
bool blockSignals(bool block)
TimeEdit::setWrapping
void setWrapping(bool on)
QWidget::setFixedSize
void setFixedSize(const QSize &s)
preferences.h
RadioButton::setFocusWidget
void setFocusWidget(QWidget *widget, bool enable=true)
QFrame
TimeSpinBox::setValue
virtual void setValue(int minutes)
AlarmTimeWidget::getDateTime
KDateTime getDateTime(int *minsFromNow=0, bool checkExpired=true, bool showErrorMessage=true, QWidget **errorWidget=0) const
Definition: alarmtimewidget.cpp:280
QAbstractButton::setChecked
void setChecked(bool)
AlarmTimeWidget::setMaxDateTime
void setMaxDateTime(const DateTime &=DateTime())
Definition: alarmtimewidget.cpp:421
set
void set(quint32, const QString &, const QString &, const QString &, const QString &, time_t)
QAbstractButton
RadioButton::setReadOnly
virtual void setReadOnly(bool readOnly)
QWidget::setWhatsThis
void setWhatsThis(const QString &)
QDateTime::date
QDate date() const
TimeZoneCombo::setTimeZone
void setTimeZone(const KTimeZone &tz)
QBoxLayout::addStretch
void addStretch(int stretch)
KAMessageBox::sorry
static void sorry(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Options(Notify|WindowModal))
TimeEdit::setValue
virtual void setValue(int minutes)
QGridLayout::setColumnStretch
void setColumnStretch(int column, int stretch)
kalarm.h
QDateTime::toTimeSpec
QDateTime toTimeSpec(Qt::TimeSpec specification) const
SpinBox2::maximum
int maximum() const
TimeEdit::setValid
void setValid(bool valid)
time_23_59
static const QTime time_23_59(23, 59)
KHBox
QWidget::show
void show()
TimeSpinBox::shiftWhatsThis
static QString shiftWhatsThis()
QDateTime::addSecs
QDateTime addSecs(int s) const
QRadioButton::sizeHint
virtual QSize sizeHint() const
TimeSpinBox::setMaximum
virtual void setMaximum(int minutes)
AlarmTimeWidget::setReadOnly
void setReadOnly(bool)
Definition: alarmtimewidget.cpp:245
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QLabel
TimeEdit::time
QTime time() const
timezonecombo.h
QBoxLayout
timeedit.h
timespinbox.h
AlarmTimeWidget::showMoreOptions
void showMoreOptions(bool)
Definition: alarmtimewidget.cpp:643
TimeEdit::setMaximum
void setMaximum(int minutes)
QBoxLayout::setSpacing
void setSpacing(int spacing)
recurText
QString recurText(const KAEvent &event)
Definition: editdlg.cpp:87
radiobutton.h
QDateTime
QBoxLayout::addLayout
void addLayout(QLayout *layout, int stretch)
AlarmTimeWidget::selectTimeFromNow
void selectTimeFromNow(int minutes=0)
Definition: alarmtimewidget.cpp:264
ButtonGroup
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalarm

Skip menu "kalarm"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal