kalarm

latecancel.cpp

00001 /*
00002  *  latecancel.cpp  -  widget to specify cancellation if late
00003  *  Program:  kalarm
00004  *  Copyright (C) 2004, 2005 by David Jarvie <software@astrojar.org.uk>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 // Collect these widget labels together to ensure consistent wording and
00034 // translations across different modules.
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 *  Set the read-only status.
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())      // don't change when it's not visible
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 *  Called when either of the checkboxes is toggled.
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 }
KDE Home | KDE Accessibility Home | Description of Access Keys