kalarm

deferdlg.cpp

00001 /*
00002  *  deferdlg.cpp  -  dialogue to defer an alarm
00003  *  Program:  kalarm
00004  *  Copyright © 2002-2006 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 <qlayout.h>
00024 
00025 #include <kglobal.h>
00026 #include <klocale.h>
00027 #include <kmessagebox.h>
00028 #include <kdebug.h>
00029 
00030 #include <libkcal/event.h>
00031 #include <libkcal/recurrence.h>
00032 
00033 #include "alarmcalendar.h"
00034 #include "alarmevent.h"
00035 #include "alarmtimewidget.h"
00036 #include "datetime.h"
00037 #include "functions.h"
00038 #include "kalarmapp.h"
00039 #include "deferdlg.moc"
00040 
00041 
00042 DeferAlarmDlg::DeferAlarmDlg(const QString& caption, const DateTime& initialDT,
00043                              bool cancelButton, QWidget* parent, const char* name)
00044     : KDialogBase(parent, name, true, caption, Ok|Cancel|User1, Ok, false, i18n("Cancel &Deferral"))
00045 {
00046     if (!cancelButton)
00047         showButton(User1, false);
00048 
00049     QWidget* page = new QWidget(this);
00050     setMainWidget(page);
00051     QVBoxLayout* layout = new QVBoxLayout(page, 0, spacingHint());
00052 
00053     mTimeWidget = new AlarmTimeWidget(AlarmTimeWidget::DEFER_TIME, page, "timeGroup");
00054     mTimeWidget->setDateTime(initialDT);
00055     mTimeWidget->setMinDateTimeIsCurrent();
00056     connect(mTimeWidget, SIGNAL(pastMax()), SLOT(slotPastLimit()));
00057     layout->addWidget(mTimeWidget);
00058     layout->addSpacing(spacingHint());
00059 
00060     setButtonWhatsThis(Ok, i18n("Defer the alarm until the specified time."));
00061     setButtonWhatsThis(User1, i18n("Cancel the deferred alarm. This does not affect future recurrences."));
00062 }
00063 
00064 
00065 /******************************************************************************
00066 * Called when the OK button is clicked.
00067 */
00068 void DeferAlarmDlg::slotOk()
00069 {
00070     mAlarmDateTime = mTimeWidget->getDateTime(&mDeferMinutes);
00071     if (!mAlarmDateTime.isValid())
00072         return;
00073     KAEvent::DeferLimitType limitType;
00074     DateTime endTime;
00075     if (!mLimitEventID.isEmpty())
00076     {
00077         // Get the event being deferred
00078         const KCal::Event* kcalEvent = AlarmCalendar::getEvent(mLimitEventID);
00079         if (kcalEvent)
00080         {
00081             KAEvent event(*kcalEvent);
00082             endTime = event.deferralLimit(&limitType);
00083         }
00084     }
00085     else
00086     {
00087         endTime = mLimitDateTime;
00088         limitType = mLimitDateTime.isValid() ? KAEvent::LIMIT_MAIN : KAEvent::LIMIT_NONE;
00089     }
00090     if (endTime.isValid()  &&  mAlarmDateTime > endTime)
00091     {
00092         QString text;
00093         switch (limitType)
00094         {
00095             case KAEvent::LIMIT_REPETITION:
00096                 text = i18n("This refers to simple repetitions set up using the Simple Repetition dialog",
00097                             "Cannot defer past the alarm's next repetition (currently %1)");
00098                 break;
00099             case KAEvent::LIMIT_RECURRENCE:
00100                 text = i18n("This refers to recurrences set up using the Recurrence tab",
00101                             "Cannot defer past the alarm's next recurrence (currently %1)");
00102                 break;
00103             case KAEvent::LIMIT_REMINDER:
00104                 text = i18n("Cannot defer past the alarm's next reminder (currently %1)");
00105                 break;
00106             case KAEvent::LIMIT_MAIN:
00107                 text = i18n("Cannot defer reminder past the main alarm time (%1)");
00108                 break;
00109             case KAEvent::LIMIT_NONE:
00110                 break;   // can't happen with a valid endTime
00111         }
00112         KMessageBox::sorry(this, text.arg(endTime.formatLocale()));
00113     }
00114     else
00115         accept();
00116 }
00117 
00118 /******************************************************************************
00119 * Select the 'Time from now' radio button and preset its value.
00120 */
00121 void DeferAlarmDlg::setDeferMinutes(int minutes)
00122 {
00123     mTimeWidget->selectTimeFromNow(minutes);
00124 }
00125 
00126 /******************************************************************************
00127 * Called the maximum date/time for the date/time edit widget has been passed.
00128 */
00129 void DeferAlarmDlg::slotPastLimit()
00130 {
00131     enableButtonOK(false);
00132 }
00133 
00134 /******************************************************************************
00135 * Set the time limit for deferral based on the next occurrence of the alarm
00136 * with the specified ID.
00137 */
00138 void DeferAlarmDlg::setLimit(const DateTime& limit)
00139 {
00140     mLimitEventID  = QString::null;
00141     mLimitDateTime = limit;
00142     mTimeWidget->setMaxDateTime(mLimitDateTime);
00143 }
00144 
00145 /******************************************************************************
00146 * Set the time limit for deferral based on the next occurrence of the alarm
00147 * with the specified ID.
00148 */
00149 DateTime DeferAlarmDlg::setLimit(const QString& eventID)
00150 {
00151     mLimitEventID = eventID;
00152     const KCal::Event* kcalEvent = AlarmCalendar::getEvent(mLimitEventID);
00153     if (kcalEvent)
00154     {
00155         KAEvent event(*kcalEvent);
00156         mLimitDateTime = event.deferralLimit();
00157     }
00158     else
00159         mLimitDateTime = DateTime();
00160     mTimeWidget->setMaxDateTime(mLimitDateTime);
00161     return mLimitDateTime;
00162 }
00163 
00164 /******************************************************************************
00165 * Called when the Cancel Deferral button is clicked.
00166 */
00167 void DeferAlarmDlg::slotUser1()
00168 {
00169     mAlarmDateTime = DateTime();
00170     accept();
00171 }
00172 
00173 /******************************************************************************
00174 * Called when the Cancel button is clicked.
00175 */
00176 void DeferAlarmDlg::slotCancel()
00177 {
00178     reject();
00179 }
KDE Home | KDE Accessibility Home | Description of Access Keys