2 * deferdlg.cpp - dialog to defer an alarm
4 * Copyright © 2002-2010 by David Jarvie <djarvie@kde.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include <QVBoxLayout>
27 #include <kmessagebox.h>
30 #include <kcal/event.h>
31 #include <kcal/recurrence.h>
33 #include "alarmcalendar.h"
34 #include "alarmtimewidget.h"
36 #include "functions.h"
38 #include "kalarmapp.h"
39 #include "deferdlg.moc"
42 DeferAlarmDlg::DeferAlarmDlg(const DateTime
& initialDT
, bool anyTimeOption
, bool cancelButton
, QWidget
* parent
)
45 setWindowModality(Qt::WindowModal
);
46 setCaption(i18nc("@title:window", "Defer Alarm"));
47 setButtons(Ok
| Cancel
| User1
);
48 setButtonGuiItem(User1
, KGuiItem(i18nc("@action:button", "Cancel Deferral")));
50 showButton(User1
, false);
51 connect(this, SIGNAL(okClicked()), SLOT(slotOk()));
52 connect(this, SIGNAL(user1Clicked()), SLOT(slotCancelDeferral()));
54 QWidget
* page
= new QWidget(this);
56 QVBoxLayout
* layout
= new QVBoxLayout(page
);
58 layout
->setSpacing(spacingHint());
60 mTimeWidget
= new AlarmTimeWidget((anyTimeOption
? AlarmTimeWidget::DEFER_ANY_TIME
: AlarmTimeWidget::DEFER_TIME
), page
);
61 mTimeWidget
->setDateTime(initialDT
);
62 mTimeWidget
->setMinDateTimeIsCurrent();
63 connect(mTimeWidget
, SIGNAL(pastMax()), SLOT(slotPastLimit()));
64 layout
->addWidget(mTimeWidget
);
65 layout
->addSpacing(spacingHint());
67 setButtonWhatsThis(Ok
, i18nc("@info:whatsthis", "Defer the alarm until the specified time."));
68 setButtonWhatsThis(User1
, i18nc("@info:whatsthis", "Cancel the deferred alarm. This does not affect future recurrences."));
72 /******************************************************************************
73 * Called when the OK button is clicked.
75 void DeferAlarmDlg::slotOk()
77 mAlarmDateTime
= mTimeWidget
->getDateTime(&mDeferMinutes
);
78 if (!mAlarmDateTime
.isValid())
80 KAEvent::DeferLimitType limitType
;
82 if (!mLimitEventID
.isEmpty())
84 // Get the event being deferred
85 const KAEvent
* event
= AlarmCalendar::getEvent(mLimitEventID
);
87 endTime
= event
->deferralLimit(&limitType
);
91 endTime
= mLimitDateTime
;
92 limitType
= mLimitDateTime
.isValid() ? KAEvent::LIMIT_MAIN
: KAEvent::LIMIT_NONE
;
94 if (endTime
.isValid() && mAlarmDateTime
> endTime
)
99 case KAEvent::LIMIT_REPETITION
:
100 text
= i18nc("@info", "Cannot defer past the alarm's next sub-repetition (currently %1)",
101 endTime
.formatLocale());
103 case KAEvent::LIMIT_RECURRENCE
:
104 text
= i18nc("@info", "Cannot defer past the alarm's next recurrence (currently %1)",
105 endTime
.formatLocale());
107 case KAEvent::LIMIT_REMINDER
:
108 text
= i18nc("@info", "Cannot defer past the alarm's next reminder (currently %1)",
109 endTime
.formatLocale());
111 case KAEvent::LIMIT_MAIN
:
112 text
= i18nc("@info", "Cannot defer reminder past the main alarm time (%1)",
113 endTime
.formatLocale());
115 case KAEvent::LIMIT_NONE
:
116 break; // can't happen with a valid endTime
118 KMessageBox::sorry(this, text
);
124 /******************************************************************************
125 * Select the 'Time from now' radio button and preset its value.
127 void DeferAlarmDlg::setDeferMinutes(int minutes
)
129 mTimeWidget
->selectTimeFromNow(minutes
);
132 /******************************************************************************
133 * Called the maximum date/time for the date/time edit widget has been passed.
135 void DeferAlarmDlg::slotPastLimit()
137 enableButtonOk(false);
140 /******************************************************************************
141 * Set the time limit for deferral based on the next occurrence of the alarm
142 * with the specified ID.
144 void DeferAlarmDlg::setLimit(const DateTime
& limit
)
146 mLimitEventID
.clear();
147 mLimitDateTime
= limit
;
148 mTimeWidget
->setMaxDateTime(mLimitDateTime
);
151 /******************************************************************************
152 * Set the time limit for deferral based on the next occurrence of the alarm
153 * with the specified ID.
155 DateTime
DeferAlarmDlg::setLimit(const QString
& eventID
)
157 mLimitEventID
= eventID
;
158 const KAEvent
* event
= AlarmCalendar::getEvent(mLimitEventID
);
159 mLimitDateTime
= event
? event
->deferralLimit() : DateTime();
160 mTimeWidget
->setMaxDateTime(mLimitDateTime
);
161 return mLimitDateTime
;
164 /******************************************************************************
165 * Called when the Cancel Deferral button is clicked.
167 void DeferAlarmDlg::slotCancelDeferral()
169 mAlarmDateTime
= DateTime();