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 <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
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
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;
00109 }
00110 KMessageBox::sorry(this, text.arg(endTime.formatLocale()));
00111 }
00112 else
00113 accept();
00114 }
00115
00116
00117
00118
00119 void DeferAlarmDlg::setDeferMinutes(int minutes)
00120 {
00121 mTimeWidget->selectTimeFromNow(minutes);
00122 }
00123
00124
00125
00126
00127 void DeferAlarmDlg::slotPastLimit()
00128 {
00129 enableButtonOK(false);
00130 }
00131
00132
00133
00134
00135
00136 void DeferAlarmDlg::setLimit(const DateTime& limit)
00137 {
00138 mLimitEventID = TQString();
00139 mLimitDateTime = limit;
00140 mTimeWidget->setMaxDateTime(mLimitDateTime);
00141 }
00142
00143
00144
00145
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
00164
00165 void DeferAlarmDlg::slotUser1()
00166 {
00167 mAlarmDateTime = DateTime();
00168 accept();
00169 }
00170
00171
00172
00173
00174 void DeferAlarmDlg::slotCancel()
00175 {
00176 reject();
00177 }