deferdlg.cpp
00001 /* 00002 * deferdlg.cpp - dialogue to defer an alarm 00003 * Program: kalarm 00004 * Copyright © 2002-2006,2008 by David Jarvie <djarvie@kde.org> 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 <tqlayout.h> 00024 00025 #include <tdeglobal.h> 00026 #include <tdelocale.h> 00027 #include <tdemessagebox.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 TQString& caption, const DateTime& initialDT, 00043 bool cancelButton, TQWidget* 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 TQWidget* page = new TQWidget(this); 00050 setMainWidget(page); 00051 TQVBoxLayout* layout = new TQVBoxLayout(page, 0, spacingHint()); 00052 00053 mTimeWidget = new AlarmTimeWidget(AlarmTimeWidget::DEFER_TIME, page, "timeGroup"); 00054 mTimeWidget->setDateTime(initialDT); 00055 mTimeWidget->setMinDateTimeIsCurrent(); 00056 connect(mTimeWidget, TQT_SIGNAL(pastMax()), TQT_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 TQString text; 00093 switch (limitType) 00094 { 00095 case KAEvent::LIMIT_REPETITION: 00096 text = i18n("Cannot defer past the alarm's next sub-repetition (currently %1)"); 00097 break; 00098 case KAEvent::LIMIT_RECURRENCE: 00099 text = i18n("Cannot defer past the alarm's next recurrence (currently %1)"); 00100 break; 00101 case KAEvent::LIMIT_REMINDER: 00102 text = i18n("Cannot defer past the alarm's next reminder (currently %1)"); 00103 break; 00104 case KAEvent::LIMIT_MAIN: 00105 text = i18n("Cannot defer reminder past the main alarm time (%1)"); 00106 break; 00107 case KAEvent::LIMIT_NONE: 00108 break; // can't happen with a valid endTime 00109 } 00110 KMessageBox::sorry(this, text.arg(endTime.formatLocale())); 00111 } 00112 else 00113 accept(); 00114 } 00115 00116 /****************************************************************************** 00117 * Select the 'Time from now' radio button and preset its value. 00118 */ 00119 void DeferAlarmDlg::setDeferMinutes(int minutes) 00120 { 00121 mTimeWidget->selectTimeFromNow(minutes); 00122 } 00123 00124 /****************************************************************************** 00125 * Called the maximum date/time for the date/time edit widget has been passed. 00126 */ 00127 void DeferAlarmDlg::slotPastLimit() 00128 { 00129 enableButtonOK(false); 00130 } 00131 00132 /****************************************************************************** 00133 * Set the time limit for deferral based on the next occurrence of the alarm 00134 * with the specified ID. 00135 */ 00136 void DeferAlarmDlg::setLimit(const DateTime& limit) 00137 { 00138 mLimitEventID = TQString(); 00139 mLimitDateTime = limit; 00140 mTimeWidget->setMaxDateTime(mLimitDateTime); 00141 } 00142 00143 /****************************************************************************** 00144 * Set the time limit for deferral based on the next occurrence of the alarm 00145 * with the specified ID. 00146 */ 00147 DateTime DeferAlarmDlg::setLimit(const TQString& eventID) 00148 { 00149 mLimitEventID = eventID; 00150 const KCal::Event* kcalEvent = AlarmCalendar::getEvent(mLimitEventID); 00151 if (kcalEvent) 00152 { 00153 KAEvent event(*kcalEvent); 00154 mLimitDateTime = event.deferralLimit(); 00155 } 00156 else 00157 mLimitDateTime = DateTime(); 00158 mTimeWidget->setMaxDateTime(mLimitDateTime); 00159 return mLimitDateTime; 00160 } 00161 00162 /****************************************************************************** 00163 * Called when the Cancel Deferral button is clicked. 00164 */ 00165 void DeferAlarmDlg::slotUser1() 00166 { 00167 mAlarmDateTime = DateTime(); 00168 accept(); 00169 } 00170 00171 /****************************************************************************** 00172 * Called when the Cancel button is clicked. 00173 */ 00174 void DeferAlarmDlg::slotCancel() 00175 { 00176 reject(); 00177 }