00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kalarm.h"
00022
00023 #include <qwidgetstack.h>
00024 #include <qlayout.h>
00025 #include <qwhatsthis.h>
00026 #include <klocale.h>
00027 #include <kdialog.h>
00028
00029 #include "checkbox.h"
00030 #include "latecancel.moc"
00031
00032
00033
00034
00035 QString LateCancelSelector::i18n_CancelIfLate() { return i18n("Cancel if late"); }
00036 QString LateCancelSelector::i18n_n_CancelIfLate() { return i18n("Ca&ncel if late"); }
00037 QString LateCancelSelector::i18n_AutoCloseWin() { return i18n("Auto-close window after this time"); }
00038 QString LateCancelSelector::i18n_AutoCloseWinLC() { return i18n("Auto-close window after late-cancelation time"); }
00039 QString LateCancelSelector::i18n_i_AutoCloseWinLC() { return i18n("Auto-close w&indow after late-cancelation time"); }
00040
00041
00042 LateCancelSelector::LateCancelSelector(bool allowHourMinute, QWidget* parent, const char* name)
00043 : QFrame(parent, name),
00044 mDateOnly(false),
00045 mReadOnly(false),
00046 mAutoCloseShown(false)
00047 {
00048 QString whatsThis = i18n("If checked, the alarm will be canceled if it cannot be triggered within the "
00049 "specified period after its scheduled time. Possible reasons for not triggering "
00050 "include your being logged off, X not running, or the alarm daemon not running.\n\n"
00051 "If unchecked, the alarm will be triggered at the first opportunity after "
00052 "its scheduled time, regardless of how late it is.");
00053
00054 setFrameStyle(QFrame::NoFrame);
00055 mLayout = new QVBoxLayout(this, 0, KDialog::spacingHint());
00056
00057 mStack = new QWidgetStack(this);
00058 mCheckboxFrame = new QFrame(mStack);
00059 mCheckboxFrame->setFrameStyle(QFrame::NoFrame);
00060 mStack->addWidget(mCheckboxFrame, 1);
00061 QBoxLayout* layout = new QVBoxLayout(mCheckboxFrame, 0, 0);
00062 mCheckbox = new CheckBox(i18n_n_CancelIfLate(), mCheckboxFrame);
00063 mCheckbox->setFixedSize(mCheckbox->sizeHint());
00064 connect(mCheckbox, SIGNAL(toggled(bool)), SLOT(slotToggled(bool)));
00065 QWhatsThis::add(mCheckbox, whatsThis);
00066 layout->addWidget(mCheckbox, 0, Qt::AlignAuto);
00067
00068 mTimeSelectorFrame = new QFrame(mStack);
00069 mTimeSelectorFrame->setFrameStyle(QFrame::NoFrame);
00070 mStack->addWidget(mTimeSelectorFrame, 2);
00071 layout = new QVBoxLayout(mTimeSelectorFrame, 0, 0);
00072 mTimeSelector = new TimeSelector(i18n("Cancel if late by 10 minutes", "Ca&ncel if late by"), QString::null,
00073 whatsThis, i18n("Enter how late will cause the alarm to be canceled"),
00074 allowHourMinute, mTimeSelectorFrame);
00075 connect(mTimeSelector, SIGNAL(toggled(bool)), SLOT(slotToggled(bool)));
00076 layout->addWidget(mTimeSelector);
00077 mLayout->addWidget(mStack);
00078
00079 layout = new QHBoxLayout(mLayout, KDialog::spacingHint());
00080 layout->addSpacing(3*KDialog::spacingHint());
00081 mAutoClose = new CheckBox(i18n_AutoCloseWin(), this);
00082 mAutoClose->setFixedSize(mAutoClose->sizeHint());
00083 QWhatsThis::add(mAutoClose, i18n("Automatically close the alarm window after the expiry of the late-cancelation period"));
00084 layout->addWidget(mAutoClose);
00085 layout->addStretch();
00086
00087 mAutoClose->hide();
00088 mAutoClose->setEnabled(false);
00089 }
00090
00091
00092
00093
00094 void LateCancelSelector::setReadOnly(bool ro)
00095 {
00096 if ((int)ro != (int)mReadOnly)
00097 {
00098 mReadOnly = ro;
00099 mCheckbox->setReadOnly(mReadOnly);
00100 mTimeSelector->setReadOnly(mReadOnly);
00101 mAutoClose->setReadOnly(mReadOnly);
00102 }
00103 }
00104
00105 int LateCancelSelector::minutes() const
00106 {
00107 return mTimeSelector->minutes();
00108 }
00109
00110 void LateCancelSelector::setMinutes(int minutes, bool dateOnly, TimePeriod::Units defaultUnits)
00111 {
00112 slotToggled(minutes);
00113 mTimeSelector->setMinutes(minutes, dateOnly, defaultUnits);
00114 }
00115
00116 void LateCancelSelector::setDateOnly(bool dateOnly)
00117 {
00118 if (dateOnly != mDateOnly)
00119 {
00120 mDateOnly = dateOnly;
00121 if (mTimeSelector->isChecked())
00122 mTimeSelector->setDateOnly(dateOnly);
00123 }
00124 }
00125
00126 void LateCancelSelector::showAutoClose(bool show)
00127 {
00128 if (show)
00129 mAutoClose->show();
00130 else
00131 mAutoClose->hide();
00132 mAutoCloseShown = show;
00133 mLayout->activate();
00134 }
00135
00136 bool LateCancelSelector::isAutoClose() const
00137 {
00138 return mAutoCloseShown && mAutoClose->isEnabled() && mAutoClose->isChecked();
00139 }
00140
00141 void LateCancelSelector::setAutoClose(bool autoClose)
00142 {
00143 mAutoClose->setChecked(autoClose);
00144 }
00145
00146
00147
00148
00149 void LateCancelSelector::slotToggled(bool on)
00150 {
00151 mCheckbox->setChecked(on);
00152 mTimeSelector->setChecked(on);
00153 if (on)
00154 {
00155 mTimeSelector->setDateOnly(mDateOnly);
00156 mStack->raiseWidget(mTimeSelectorFrame);
00157 }
00158 else
00159 mStack->raiseWidget(mCheckboxFrame);
00160 mAutoClose->setEnabled(on);
00161 }