26 #include <tqtooltip.h>
29 #include <tqwidgetstack.h>
30 #include <tqlistbox.h>
33 #include <tqpushbutton.h>
34 #include <tqlineedit.h>
35 #include <tqwhatsthis.h>
37 #include <tdeglobal.h>
38 #include <tdelocale.h>
39 #include <kcalendarsystem.h>
40 #include <kiconloader.h>
42 #include <tdemessagebox.h>
45 #include <libkcal/event.h>
48 #include "alarmtimewidget.h"
54 #include "karecurrence.h"
55 #include "preferences.h"
56 #include "radiobutton.h"
57 #include "repetition.h"
60 #include "timespinbox.h"
61 #include "buttongroup.h"
64 #include "recurrenceedit.moc"
65 #include "recurrenceeditprivate.moc"
69 TQString RecurrenceEdit::i18n_Norecur() {
return i18n(
"No recurrence"); }
70 TQString RecurrenceEdit::i18n_NoRecur() {
return i18n(
"No Recurrence"); }
71 TQString RecurrenceEdit::i18n_AtLogin() {
return i18n(
"At Login"); }
72 TQString RecurrenceEdit::i18n_l_Atlogin() {
return i18n(
"At &login"); }
73 TQString RecurrenceEdit::i18n_HourlyMinutely() {
return i18n(
"Hourly/Minutely"); }
74 TQString RecurrenceEdit::i18n_u_HourlyMinutely() {
return i18n(
"Ho&urly/Minutely"); }
75 TQString RecurrenceEdit::i18n_Daily() {
return i18n(
"Daily"); }
76 TQString RecurrenceEdit::i18n_d_Daily() {
return i18n(
"&Daily"); }
77 TQString RecurrenceEdit::i18n_Weekly() {
return i18n(
"Weekly"); }
78 TQString RecurrenceEdit::i18n_w_Weekly() {
return i18n(
"&Weekly"); }
79 TQString RecurrenceEdit::i18n_Monthly() {
return i18n(
"Monthly"); }
80 TQString RecurrenceEdit::i18n_m_Monthly() {
return i18n(
"&Monthly"); }
81 TQString RecurrenceEdit::i18n_Yearly() {
return i18n(
"Yearly"); }
82 TQString RecurrenceEdit::i18n_y_Yearly() {
return i18n(
"&Yearly"); }
85 RecurrenceEdit::RecurrenceEdit(
bool readOnly, TQWidget* parent,
const char* name)
86 : TQFrame(parent, name),
88 mRuleButtonType(INVALID_RECUR),
93 mNoEmitTypeChanged(true),
97 TQVBoxLayout* topLayout =
new TQVBoxLayout(
this, 0, KDialog::spacingHint());
106 TQGroupBox* recurGroup =
new TQGroupBox(1, TQt::Vertical, i18n(
"Recurrence Rule"),
this,
"recurGroup");
107 topLayout->addWidget(recurGroup);
108 TQFrame* ruleFrame =
new TQFrame(recurGroup,
"ruleFrame");
109 layout =
new TQVBoxLayout(ruleFrame, 0);
110 layout->addSpacing(KDialog::spacingHint()/2);
112 layout =
new TQHBoxLayout(layout, 0);
113 TQBoxLayout* lay =
new TQVBoxLayout(layout, 0);
114 mRuleButtonGroup =
new ButtonGroup(1, TQt::Horizontal, ruleFrame);
115 mRuleButtonGroup->setInsideMargin(0);
116 mRuleButtonGroup->setFrameStyle(TQFrame::NoFrame);
117 lay->addWidget(mRuleButtonGroup);
119 connect(mRuleButtonGroup, TQ_SIGNAL(buttonSet(
int)), TQ_SLOT(periodClicked(
int)));
121 mNoneButton =
new RadioButton(i18n_Norecur(), mRuleButtonGroup);
122 mNoneButton->setFixedSize(mNoneButton->sizeHint());
123 mNoneButton->setReadOnly(mReadOnly);
124 TQWhatsThis::add(mNoneButton, i18n(
"Do not repeat the alarm"));
126 mAtLoginButton =
new RadioButton(i18n_l_Atlogin(), mRuleButtonGroup);
127 mAtLoginButton->setFixedSize(mAtLoginButton->sizeHint());
128 mAtLoginButton->setReadOnly(mReadOnly);
129 TQWhatsThis::add(mAtLoginButton,
130 i18n(
"Trigger the alarm at the specified date/time and at every login until then.\n"
131 "Note that it will also be triggered any time the alarm daemon is restarted."));
133 mSubDailyButton =
new RadioButton(i18n_u_HourlyMinutely(), mRuleButtonGroup);
134 mSubDailyButton->setFixedSize(mSubDailyButton->sizeHint());
135 mSubDailyButton->setReadOnly(mReadOnly);
136 TQWhatsThis::add(mSubDailyButton,
137 i18n(
"Repeat the alarm at hourly/minutely intervals"));
139 mDailyButton =
new RadioButton(i18n_d_Daily(), mRuleButtonGroup);
140 mDailyButton->setFixedSize(mDailyButton->sizeHint());
141 mDailyButton->setReadOnly(mReadOnly);
142 TQWhatsThis::add(mDailyButton,
143 i18n(
"Repeat the alarm at daily intervals"));
145 mWeeklyButton =
new RadioButton(i18n_w_Weekly(), mRuleButtonGroup);
146 mWeeklyButton->setFixedSize(mWeeklyButton->sizeHint());
147 mWeeklyButton->setReadOnly(mReadOnly);
148 TQWhatsThis::add(mWeeklyButton,
149 i18n(
"Repeat the alarm at weekly intervals"));
151 mMonthlyButton =
new RadioButton(i18n_m_Monthly(), mRuleButtonGroup);
152 mMonthlyButton->setFixedSize(mMonthlyButton->sizeHint());
153 mMonthlyButton->setReadOnly(mReadOnly);
154 TQWhatsThis::add(mMonthlyButton,
155 i18n(
"Repeat the alarm at monthly intervals"));
157 mYearlyButton =
new RadioButton(i18n_y_Yearly(), mRuleButtonGroup);
158 mYearlyButton->setFixedSize(mYearlyButton->sizeHint());
159 mYearlyButton->setReadOnly(mReadOnly);
160 TQWhatsThis::add(mYearlyButton,
161 i18n(
"Repeat the alarm at annual intervals"));
163 mNoneButtonId = mRuleButtonGroup->id(mNoneButton);
164 mAtLoginButtonId = mRuleButtonGroup->id(mAtLoginButton);
165 mSubDailyButtonId = mRuleButtonGroup->id(mSubDailyButton);
166 mDailyButtonId = mRuleButtonGroup->id(mDailyButton);
167 mWeeklyButtonId = mRuleButtonGroup->id(mWeeklyButton);
168 mMonthlyButtonId = mRuleButtonGroup->id(mMonthlyButton);
169 mYearlyButtonId = mRuleButtonGroup->id(mYearlyButton);
172 mSubRepetition =
new RepetitionButton(i18n(
"Sub-Repetition"),
true, ruleFrame);
173 mSubRepetition->setFixedSize(mSubRepetition->sizeHint());
174 mSubRepetition->setReadOnly(mReadOnly);
175 connect(mSubRepetition, TQ_SIGNAL(needsInitialisation()), TQ_SIGNAL(repeatNeedsInitialisation()));
176 connect(mSubRepetition, TQ_SIGNAL(changed()), TQ_SIGNAL(frequencyChanged()));
177 TQWhatsThis::add(mSubRepetition, i18n(
"Set up a repetition within the recurrence, to trigger the alarm multiple times each time the recurrence is due."));
178 lay->addSpacing(KDialog::spacingHint());
179 lay->addWidget(mSubRepetition);
181 lay =
new TQVBoxLayout(layout);
184 layout =
new TQHBoxLayout(lay);
186 layout->addSpacing(KDialog::marginHint());
187 TQFrame* divider =
new TQFrame(ruleFrame);
188 divider->setFrameStyle(TQFrame::VLine | TQFrame::Sunken);
189 layout->addWidget(divider);
190 layout->addSpacing(KDialog::marginHint());
192 mNoRule =
new NoRule(ruleFrame,
"noFrame");
193 mSubDailyRule =
new SubDailyRule(mReadOnly, ruleFrame,
"subdayFrame");
194 mDailyRule =
new DailyRule(mReadOnly, ruleFrame,
"dayFrame");
195 mWeeklyRule =
new WeeklyRule(mReadOnly, ruleFrame,
"weekFrame");
196 mMonthlyRule =
new MonthlyRule(mReadOnly, ruleFrame,
"monthFrame");
197 mYearlyRule =
new YearlyRule(mReadOnly, ruleFrame,
"yearFrame");
199 connect(mSubDailyRule, TQ_SIGNAL(frequencyChanged()),
this, TQ_SIGNAL(frequencyChanged()));
200 connect(mDailyRule, TQ_SIGNAL(frequencyChanged()),
this, TQ_SIGNAL(frequencyChanged()));
201 connect(mWeeklyRule, TQ_SIGNAL(frequencyChanged()),
this, TQ_SIGNAL(frequencyChanged()));
202 connect(mMonthlyRule, TQ_SIGNAL(frequencyChanged()),
this, TQ_SIGNAL(frequencyChanged()));
203 connect(mYearlyRule, TQ_SIGNAL(frequencyChanged()),
this, TQ_SIGNAL(frequencyChanged()));
205 mRuleStack =
new TQWidgetStack(ruleFrame);
206 layout->addWidget(mRuleStack);
207 layout->addStretch(1);
208 mRuleStack->addWidget(mNoRule, 0);
209 mRuleStack->addWidget(mSubDailyRule, 1);
210 mRuleStack->addWidget(mDailyRule, 2);
211 mRuleStack->addWidget(mWeeklyRule, 3);
212 mRuleStack->addWidget(mMonthlyRule, 4);
213 mRuleStack->addWidget(mYearlyRule, 5);
214 layout->addSpacing(KDialog::marginHint());
219 mRangeButtonGroup =
new ButtonGroup(i18n(
"Recurrence End"),
this,
"mRangeButtonGroup");
220 connect(mRangeButtonGroup, TQ_SIGNAL(buttonSet(
int)), TQ_SLOT(rangeTypeClicked()));
221 topLayout->addWidget(mRangeButtonGroup);
223 TQVBoxLayout* vlayout =
new TQVBoxLayout(mRangeButtonGroup, KDialog::marginHint(), KDialog::spacingHint());
224 vlayout->addSpacing(fontMetrics().lineSpacing()/2);
225 mNoEndDateButton =
new RadioButton(i18n(
"No &end"), mRangeButtonGroup);
226 mNoEndDateButton->setFixedSize(mNoEndDateButton->sizeHint());
227 mNoEndDateButton->setReadOnly(mReadOnly);
228 TQWhatsThis::add(mNoEndDateButton, i18n(
"Repeat the alarm indefinitely"));
229 vlayout->addWidget(mNoEndDateButton, 1, TQt::AlignAuto);
230 TQSize size = mNoEndDateButton->size();
232 layout =
new TQHBoxLayout(vlayout, KDialog::spacingHint());
233 mRepeatCountButton =
new RadioButton(i18n(
"End a&fter:"), mRangeButtonGroup);
234 mRepeatCountButton->setReadOnly(mReadOnly);
235 TQWhatsThis::add(mRepeatCountButton,
236 i18n(
"Repeat the alarm for the number of times specified"));
237 mRepeatCountEntry =
new SpinBox(1, 9999, 1, mRangeButtonGroup);
238 mRepeatCountEntry->setFixedSize(mRepeatCountEntry->sizeHint());
239 mRepeatCountEntry->setLineShiftStep(10);
240 mRepeatCountEntry->setSelectOnStep(
false);
241 mRepeatCountEntry->setReadOnly(mReadOnly);
242 connect(mRepeatCountEntry, TQ_SIGNAL(valueChanged(
int)), TQ_SLOT(repeatCountChanged(
int)));
243 TQWhatsThis::add(mRepeatCountEntry,
244 i18n(
"Enter the total number of times to trigger the alarm"));
245 mRepeatCountButton->setFocusWidget(mRepeatCountEntry);
246 mRepeatCountLabel =
new TQLabel(i18n(
"occurrence(s)"), mRangeButtonGroup);
247 mRepeatCountLabel->setFixedSize(mRepeatCountLabel->sizeHint());
248 layout->addWidget(mRepeatCountButton);
249 layout->addSpacing(KDialog::spacingHint());
250 layout->addWidget(mRepeatCountEntry);
251 layout->addWidget(mRepeatCountLabel);
252 layout->addStretch();
253 size = size.expandedTo(mRepeatCountButton->sizeHint());
255 layout =
new TQHBoxLayout(vlayout, KDialog::spacingHint());
256 mEndDateButton =
new RadioButton(i18n(
"End &by:"), mRangeButtonGroup);
257 mEndDateButton->setReadOnly(mReadOnly);
258 TQWhatsThis::add(mEndDateButton,
259 i18n(
"Repeat the alarm until the date/time specified.\n\n"
260 "Note: This applies to the main recurrence only. It does not limit any sub-repetition which will occur regardless after the last main recurrence."));
261 mEndDateEdit =
new DateEdit(mRangeButtonGroup);
262 mEndDateEdit->setFixedSize(mEndDateEdit->sizeHint());
263 mEndDateEdit->setReadOnly(mReadOnly);
264 TQWhatsThis::add(mEndDateEdit,
265 i18n(
"Enter the last date to repeat the alarm"));
266 mEndDateButton->setFocusWidget(mEndDateEdit);
267 mEndTimeEdit =
new TimeEdit(mRangeButtonGroup);
268 mEndTimeEdit->setFixedSize(mEndTimeEdit->sizeHint());
269 mEndTimeEdit->setReadOnly(mReadOnly);
270 static const TQString lastTimeText = i18n(
"Enter the last time to repeat the alarm.");
271 TQWhatsThis::add(mEndTimeEdit, TQString(
"%1\n\n%2").arg(lastTimeText).arg(TimeSpinBox::shiftWhatsThis()));
272 mEndAnyTimeCheckBox =
new CheckBox(i18n(
"Any time"), mRangeButtonGroup);
273 mEndAnyTimeCheckBox->setFixedSize(mEndAnyTimeCheckBox->sizeHint());
274 mEndAnyTimeCheckBox->setReadOnly(mReadOnly);
275 connect(mEndAnyTimeCheckBox, TQ_SIGNAL(toggled(
bool)), TQ_SLOT(slotAnyTimeToggled(
bool)));
276 TQWhatsThis::add(mEndAnyTimeCheckBox,
277 i18n(
"Stop repeating the alarm after your first login on or after the specified end date"));
278 layout->addWidget(mEndDateButton);
279 layout->addSpacing(KDialog::spacingHint());
280 layout->addWidget(mEndDateEdit);
281 layout->addWidget(mEndTimeEdit);
282 layout->addWidget(mEndAnyTimeCheckBox);
283 layout->addStretch();
284 size = size.expandedTo(mEndDateButton->sizeHint());
287 mRepeatCountButton->setFixedSize(size);
288 mEndDateButton->setFixedSize(size);
293 mExceptionGroup =
new TQGroupBox(i18n(
"E&xceptions"),
this,
"mExceptionGroup");
294 topLayout->addWidget(mExceptionGroup);
295 topLayout->setStretchFactor(mExceptionGroup, 2);
296 vlayout =
new TQVBoxLayout(mExceptionGroup, KDialog::marginHint(), KDialog::spacingHint());
297 vlayout->addSpacing(fontMetrics().lineSpacing()/2);
298 layout =
new TQHBoxLayout(vlayout, KDialog::spacingHint());
299 vlayout =
new TQVBoxLayout(layout);
301 mExceptionDateList =
new TQListBox(mExceptionGroup);
302 mExceptionDateList->setSizePolicy(TQSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Expanding));
303 connect(mExceptionDateList, TQ_SIGNAL(selectionChanged()), TQ_SLOT(enableExceptionButtons()));
304 TQWhatsThis::add(mExceptionDateList,
305 i18n(
"The list of exceptions, i.e. dates/times excluded from the recurrence"));
306 vlayout->addWidget(mExceptionDateList);
310 mExceptionDateEdit = 0;
311 mChangeExceptionButton = 0;
312 mDeleteExceptionButton = 0;
316 vlayout =
new TQVBoxLayout(layout);
317 mExceptionDateEdit =
new DateEdit(mExceptionGroup);
318 mExceptionDateEdit->setFixedSize(mExceptionDateEdit->sizeHint());
319 mExceptionDateEdit->setDate(TQDate::currentDate());
320 TQWhatsThis::add(mExceptionDateEdit,
321 i18n(
"Enter a date to insert in the exceptions list. "
322 "Use in conjunction with the Add or Change button below."));
323 vlayout->addWidget(mExceptionDateEdit);
325 layout =
new TQHBoxLayout(vlayout, KDialog::spacingHint());
326 TQPushButton* button =
new TQPushButton(i18n(
"Add"), mExceptionGroup);
327 button->setFixedSize(button->sizeHint());
328 connect(button, TQ_SIGNAL(clicked()), TQ_SLOT(addException()));
329 TQWhatsThis::add(button,
330 i18n(
"Add the date entered above to the exceptions list"));
331 layout->addWidget(button);
333 mChangeExceptionButton =
new TQPushButton(i18n(
"Change"), mExceptionGroup);
334 mChangeExceptionButton->setFixedSize(mChangeExceptionButton->sizeHint());
335 connect(mChangeExceptionButton, TQ_SIGNAL(clicked()), TQ_SLOT(changeException()));
336 TQWhatsThis::add(mChangeExceptionButton,
337 i18n(
"Replace the currently highlighted item in the exceptions list with the date entered above"));
338 layout->addWidget(mChangeExceptionButton);
340 mDeleteExceptionButton =
new TQPushButton(i18n(
"Delete"), mExceptionGroup);
341 mDeleteExceptionButton->setFixedSize(mDeleteExceptionButton->sizeHint());
342 connect(mDeleteExceptionButton, TQ_SIGNAL(clicked()), TQ_SLOT(deleteException()));
343 TQWhatsThis::add(mDeleteExceptionButton,
344 i18n(
"Remove the currently highlighted item from the exceptions list"));
345 layout->addWidget(mDeleteExceptionButton);
348 mNoEmitTypeChanged =
false;
355 TQWidget* RecurrenceEdit::checkData(
const TQDateTime& startDateTime, TQString& errorMessage)
const
357 if (mAtLoginButton->isOn())
359 const_cast<RecurrenceEdit*
>(
this)->mCurrStartDateTime = startDateTime;
360 if (mEndDateButton->isChecked())
362 TQWidget* errWidget = 0;
363 bool noTime = !mEndTimeEdit->isEnabled();
364 TQDate endDate = mEndDateEdit->date();
365 if (endDate < startDateTime.date())
366 errWidget = mEndDateEdit;
367 else if (!noTime && TQDateTime(endDate, mEndTimeEdit->time()) < startDateTime)
368 errWidget = mEndTimeEdit;
371 errorMessage = noTime
372 ? i18n(
"End date is earlier than start date")
373 : i18n(
"End date/time is earlier than start date/time");
379 return mRule->validate(errorMessage);
385 void RecurrenceEdit::periodClicked(
int id)
387 RepeatType oldType = mRuleButtonType;
388 bool none = (
id == mNoneButtonId);
389 bool atLogin = (
id == mAtLoginButtonId);
390 bool subdaily = (
id == mSubDailyButtonId);
394 mRuleButtonType = NO_RECUR;
399 mRuleButtonType = AT_LOGIN;
400 mRangeButtonGroup->setButton(mRangeButtonGroup->id(mEndDateButton));
404 mRule = mSubDailyRule;
405 mRuleButtonType = SUBDAILY;
407 else if (
id == mDailyButtonId)
410 mRuleButtonType = DAILY;
413 else if (
id == mWeeklyButtonId)
416 mRuleButtonType = WEEKLY;
419 else if (
id == mMonthlyButtonId)
421 mRule = mMonthlyRule;
422 mRuleButtonType = MONTHLY;
423 mMonthlyShown =
true;
425 else if (
id == mYearlyButtonId)
428 mRuleButtonType = ANNUAL;
434 if (mRuleButtonType != oldType)
436 mRuleStack->raiseWidget(mRule ? mRule : mNoRule);
437 if (oldType == NO_RECUR || none)
438 mRangeButtonGroup->setEnabled(!none);
439 mExceptionGroup->setEnabled(!(none || atLogin));
440 mEndAnyTimeCheckBox->setEnabled(atLogin);
443 mNoEndDateButton->setEnabled(!atLogin);
444 mRepeatCountButton->setEnabled(!atLogin);
447 mSubRepetition->setEnabled(!(none || atLogin));
448 if (!mNoEmitTypeChanged)
449 emit typeChanged(mRuleButtonType);
453 void RecurrenceEdit::slotAnyTimeToggled(
bool on)
455 TQButton* button = mRuleButtonGroup->selected();
456 mEndTimeEdit->setEnabled((button == mAtLoginButton && !on)
457 || (button == mSubDailyButton && mEndDateButton->isChecked()));
463 void RecurrenceEdit::rangeTypeClicked()
465 bool endDate = mEndDateButton->isOn();
466 mEndDateEdit->setEnabled(endDate);
467 mEndTimeEdit->setEnabled(endDate
468 && ((mAtLoginButton->isOn() && !mEndAnyTimeCheckBox->isChecked())
469 || mSubDailyButton->isOn()));
470 bool repeatCount = mRepeatCountButton->isOn();
471 mRepeatCountEntry->setEnabled(repeatCount);
472 mRepeatCountLabel->setEnabled(repeatCount);
475 void RecurrenceEdit::showEvent(TQShowEvent*)
478 mRule->setFrequencyFocus();
480 mRuleButtonGroup->selected()->setFocus();
488 int RecurrenceEdit::subRepeatCount(
int* subRepeatInterval)
const
490 int count = (mRuleButtonType >= SUBDAILY) ? mSubRepetition->count() : 0;
491 if (subRepeatInterval)
492 *subRepeatInterval = count ? mSubRepetition->interval() : 0;
504 void RecurrenceEdit::setSubRepetition(
int reminderMinutes,
bool dateOnly)
507 switch (mRuleButtonType)
509 case RecurrenceEdit::NO_RECUR:
510 case RecurrenceEdit::AT_LOGIN:
516 updateEvent(event,
false);
517 maxDuration =
event.longestRecurrenceInterval() - reminderMinutes - 1;
521 mSubRepetition->initialise(mSubRepetition->interval(), mSubRepetition->count(), dateOnly, maxDuration);
522 mSubRepetition->setEnabled(mRuleButtonType >= SUBDAILY && maxDuration);
528 void RecurrenceEdit::activateSubRepetition()
530 mSubRepetition->activate();
537 bool RecurrenceEdit::validateDate(
const DateTime &date)
const
539 if (mRuleButtonType == RecurrenceEdit::DAILY)
541 TQBitArray selectedDays = mDailyRule->days();
542 if (!selectedDays[date.date().dayOfWeek()-1])
545 else if (mRuleButtonType == RecurrenceEdit::WEEKLY)
547 TQBitArray selectedDays = mWeeklyRule->days();
548 if (!selectedDays[date.date().dayOfWeek()-1])
551 else if (mRuleButtonType == RecurrenceEdit::MONTHLY)
553 if (mMonthlyRule->type() == MonthYearRule::DATE)
556 int comboDate = mMonthlyRule->date();
557 if ((comboDate > 0 && date.date().day() != comboDate) ||
558 (comboDate <=0 && date.date().day() != date.date().daysInMonth()))
564 if (date.date().dayOfWeek() != mMonthlyRule->dayOfWeek())
567 int monthDay = date.date().day();
568 int weekNum = mMonthlyRule->week();
569 int minDay = 0, maxDay = 0;
572 minDay = (weekNum-1) * 7;
573 maxDay = weekNum * 7;
575 else if (weekNum < 0)
577 int dim = date.date().daysInMonth();
578 minDay = dim + weekNum * 7;
579 maxDay = dim + (weekNum+1) * 7;
581 if (monthDay <= minDay || monthDay > maxDay)
585 else if (mRuleButtonType == RecurrenceEdit::ANNUAL)
587 TQValueList<int> months = mYearlyRule->months();
588 if (!months.contains(date.date().month()))
591 if (mYearlyRule->type() == MonthYearRule::DATE)
594 int comboDate = mYearlyRule->date();
595 if ((comboDate > 0 && date.date().day() != comboDate) ||
596 (comboDate <=0 && date.date().day() != date.date().daysInMonth()))
602 if (date.date().dayOfWeek() != mYearlyRule->dayOfWeek())
605 int monthDay = date.date().day();
606 int weekNum = mYearlyRule->week();
607 int minDay = 0, maxDay = 0;
610 minDay = (weekNum-1) * 7;
611 maxDay = weekNum * 7;
613 else if (weekNum < 0)
615 int dim = date.date().daysInMonth();
616 minDay = dim + weekNum * 7;
617 maxDay = dim + (weekNum+1) * 7;
619 if (monthDay <= minDay || monthDay > maxDay)
630 void RecurrenceEdit::repeatCountChanged(
int value)
632 if (value > 0 && mRepeatCountEntry->minValue() == 0)
633 mRepeatCountEntry->setMinValue(1);
640 void RecurrenceEdit::addException()
642 if (!mExceptionDateEdit || !mExceptionDateEdit->isValid())
644 TQDate date = mExceptionDateEdit->date();
645 TQValueList<TQDate>::Iterator it;
648 for (it = mExceptionDates.begin(); it != mExceptionDates.end(); ++index, ++it)
652 insert = (date != *it);
658 mExceptionDates.insert(it, date);
659 mExceptionDateList->insertItem(TDEGlobal::locale()->formatDate(date), index);
661 mExceptionDateList->setCurrentItem(index);
662 enableExceptionButtons();
669 void RecurrenceEdit::changeException()
671 if (!mExceptionDateEdit || !mExceptionDateEdit->isValid())
673 int index = mExceptionDateList->currentItem();
674 if (index >= 0 && mExceptionDateList->isSelected(index))
676 TQDate olddate = mExceptionDates[index];
677 TQDate newdate = mExceptionDateEdit->date();
678 if (newdate != olddate)
680 mExceptionDates.remove(mExceptionDates.at(index));
681 mExceptionDateList->removeItem(index);
690 void RecurrenceEdit::deleteException()
692 int index = mExceptionDateList->currentItem();
693 if (index >= 0 && mExceptionDateList->isSelected(index))
695 mExceptionDates.remove(mExceptionDates.at(index));
696 mExceptionDateList->removeItem(index);
697 enableExceptionButtons();
705 void RecurrenceEdit::enableExceptionButtons()
707 int index = mExceptionDateList->currentItem();
708 bool enable = (index >= 0 && mExceptionDateList->isSelected(index));
709 if (mDeleteExceptionButton)
710 mDeleteExceptionButton->setEnabled(enable);
711 if (mChangeExceptionButton)
712 mChangeExceptionButton->setEnabled(enable);
715 mExceptionDateList->setFocusPolicy(mExceptionDateList->count() ? TQWidget::WheelFocus : TQWidget::NoFocus);
721 void RecurrenceEdit::setStartDate(
const TQDate& start,
const TQDate& today)
725 setRuleDefaults(start);
728 mEndDateEdit->setMinDate(today);
729 if (mExceptionDateEdit)
730 mExceptionDateEdit->setMinDate(today);
734 const TQString startString = i18n(
"Date cannot be earlier than start date",
"start date");
735 mEndDateEdit->setMinDate(start, startString);
736 if (mExceptionDateEdit)
737 mExceptionDateEdit->setMinDate(start, startString);
745 void RecurrenceEdit::setDefaultEndDate(
const TQDate& end)
747 if (!mEndDateButton->isOn())
748 mEndDateEdit->setDate(end);
751 void RecurrenceEdit::setEndDateTime(
const DateTime& end)
753 mEndDateEdit->setDate(end.date());
754 mEndTimeEdit->setValue(end.time());
755 mEndTimeEdit->setEnabled(!end.isDateOnly());
756 mEndAnyTimeCheckBox->setChecked(end.isDateOnly());
759 DateTime RecurrenceEdit::endDateTime()
const
761 if (mRuleButtonGroup->selected() == mAtLoginButton && mEndAnyTimeCheckBox->isChecked())
762 return DateTime(mEndDateEdit->date());
763 return DateTime(mEndDateEdit->date(), mEndTimeEdit->time());
769 void RecurrenceEdit::setDefaults(
const TQDateTime& from)
771 mCurrStartDateTime = from;
772 TQDate fromDate = from.date();
773 mNoEndDateButton->setChecked(
true);
775 mSubDailyRule->setFrequency(1);
776 mDailyRule->setFrequency(1);
777 mWeeklyRule->setFrequency(1);
778 mMonthlyRule->setFrequency(1);
779 mYearlyRule->setFrequency(1);
781 setRuleDefaults(fromDate);
782 mMonthlyRule->setType(MonthYearRule::DATE);
783 mYearlyRule->setType(MonthYearRule::DATE);
785 mEndDateEdit->setDate(fromDate);
787 mNoEmitTypeChanged =
true;
789 switch (Preferences::defaultRecurPeriod())
791 case AT_LOGIN: button = mAtLoginButtonId;
break;
792 case ANNUAL: button = mYearlyButtonId;
break;
793 case MONTHLY: button = mMonthlyButtonId;
break;
794 case WEEKLY: button = mWeeklyButtonId;
break;
795 case DAILY: button = mDailyButtonId;
break;
796 case SUBDAILY: button = mSubDailyButtonId;
break;
798 default: button = mNoneButtonId;
break;
800 mRuleButtonGroup->setButton(button);
801 mNoEmitTypeChanged =
false;
803 enableExceptionButtons();
812 void RecurrenceEdit::setRuleDefaults(
const TQDate& fromDate)
814 int day = fromDate.day();
815 int dayOfWeek = fromDate.dayOfWeek();
816 int month = fromDate.month();
818 mDailyRule->setDays(
true);
820 mWeeklyRule->setDay(dayOfWeek);
822 mMonthlyRule->setDefaultValues(day, dayOfWeek);
824 mYearlyRule->setDefaultValues(day, dayOfWeek, month);
832 void RecurrenceEdit::set(
const KAEvent& event,
bool keepDuration)
834 setDefaults(event.mainDateTime().dateTime());
835 if (event.repeatAtLogin())
837 mRuleButtonGroup->setButton(mAtLoginButtonId);
838 mEndDateButton->setChecked(
true);
841 mRuleButtonGroup->setButton(mNoneButtonId);
842 KARecurrence* recurrence =
event.recurrence();
845 KARecurrence::Type rtype = recurrence->type();
848 case KARecurrence::MINUTELY:
849 mRuleButtonGroup->setButton(mSubDailyButtonId);
852 case KARecurrence::DAILY:
854 mRuleButtonGroup->setButton(mDailyButtonId);
855 TQBitArray rDays = recurrence->days();
857 for (
int i = 0; i < 7 && !set; ++i)
858 set = rDays.testBit(i);
860 mDailyRule->setDays(rDays);
862 mDailyRule->setDays(
true);
865 case KARecurrence::WEEKLY:
867 mRuleButtonGroup->setButton(mWeeklyButtonId);
868 TQBitArray rDays = recurrence->days();
869 mWeeklyRule->setDays(rDays);
872 case KARecurrence::MONTHLY_POS:
874 TQValueList<RecurrenceRule::WDayPos> posns = recurrence->monthPositions();
875 int i = posns.first().pos();
880 mRuleButtonGroup->setButton(mWeeklyButtonId);
881 mWeeklyRule->setFrequency(recurrence->frequency());
883 for (TQValueList<RecurrenceRule::WDayPos>::ConstIterator it = posns.begin(); it != posns.end(); ++it)
886 rDays.setBit((*it).day() - 1, 1);
888 mWeeklyRule->setDays(rDays);
891 mRuleButtonGroup->setButton(mMonthlyButtonId);
892 mMonthlyRule->setPosition(i, posns.first().day());
895 case KARecurrence::MONTHLY_DAY:
897 mRuleButtonGroup->setButton(mMonthlyButtonId);
898 TQValueList<int> rmd = recurrence->monthDays();
899 int day = (rmd.isEmpty()) ? event.mainDate().day() : rmd.first();
900 mMonthlyRule->setDate(day);
903 case KARecurrence::ANNUAL_DATE:
904 case KARecurrence::ANNUAL_POS:
906 if (rtype == KARecurrence::ANNUAL_DATE)
908 mRuleButtonGroup->setButton(mYearlyButtonId);
909 const TQValueList<int> rmd = recurrence->monthDays();
910 int day = (rmd.isEmpty()) ? event.mainDate().day() : rmd.first();
911 mYearlyRule->setDate(day);
912 mYearlyRule->setFeb29Type(recurrence->feb29Type());
914 else if (rtype == KARecurrence::ANNUAL_POS)
916 mRuleButtonGroup->setButton(mYearlyButtonId);
917 TQValueList<RecurrenceRule::WDayPos> posns = recurrence->yearPositions();
918 mYearlyRule->setPosition(posns.first().pos(), posns.first().day());
920 mYearlyRule->setMonths(recurrence->yearMonths());
927 mRule->setFrequency(recurrence->frequency());
930 TQDateTime endtime = mCurrStartDateTime;
931 int duration = recurrence->duration();
933 mNoEndDateButton->setChecked(
true);
936 mRepeatCountButton->setChecked(
true);
937 mRepeatCountEntry->setValue(duration);
941 mEndDateButton->setChecked(
true);
942 endtime = recurrence->endDateTime();
943 mEndTimeEdit->setValue(endtime.time());
945 mEndDateEdit->setDate(endtime.date());
948 mExceptionDates =
event.recurrence()->exDates();
949 qHeapSort(mExceptionDates);
950 mExceptionDateList->clear();
951 for (DateList::ConstIterator it = mExceptionDates.begin(); it != mExceptionDates.end(); ++it)
952 mExceptionDateList->insertItem(TDEGlobal::locale()->formatDate(*it));
953 enableExceptionButtons();
956 mSubRepetition->set(event.repeatInterval(), event.repeatCount());
968 void RecurrenceEdit::updateEvent(
KAEvent& event,
bool adjustStart)
974 if (mNoEndDateButton->isChecked())
976 else if (mRepeatCountButton->isChecked())
977 repeatCount = mRepeatCountEntry->value();
981 endDate = mEndDateEdit->date();
982 endTime = mEndTimeEdit->time();
986 TQButton* button = mRuleButtonGroup->selected();
987 event.setRepeatAtLogin(button == mAtLoginButton);
988 int frequency = mRule ? mRule->frequency() : 0;
989 if (button == mSubDailyButton)
991 TQDateTime endDateTime(endDate, endTime);
992 event.setRecurMinutely(frequency, repeatCount, endDateTime);
994 else if (button == mDailyButton)
996 event.setRecurDaily(frequency, mDailyRule->days(), repeatCount, endDate);
998 else if (button == mWeeklyButton)
1000 event.setRecurWeekly(frequency, mWeeklyRule->days(), repeatCount, endDate);
1002 else if (button == mMonthlyButton)
1004 if (mMonthlyRule->type() == MonthlyRule::POS)
1007 KAEvent::MonthPos pos;
1008 pos.days.fill(
false);
1009 pos.days.setBit(mMonthlyRule->dayOfWeek() - 1);
1010 pos.weeknum = mMonthlyRule->week();
1011 TQValueList<KAEvent::MonthPos> poses;
1013 event.setRecurMonthlyByPos(frequency, poses, repeatCount, endDate);
1018 int daynum = mMonthlyRule->date();
1019 TQValueList<int> daynums;
1020 daynums.append(daynum);
1021 event.setRecurMonthlyByDate(frequency, daynums, repeatCount, endDate);
1024 else if (button == mYearlyButton)
1026 TQValueList<int> months = mYearlyRule->months();
1027 if (mYearlyRule->type() == YearlyRule::POS)
1030 KAEvent::MonthPos pos;
1031 pos.days.fill(
false);
1032 pos.days.setBit(mYearlyRule->dayOfWeek() - 1);
1033 pos.weeknum = mYearlyRule->week();
1034 TQValueList<KAEvent::MonthPos> poses;
1036 event.setRecurAnnualByPos(frequency, poses, months, repeatCount, endDate);
1041 event.setRecurAnnualByDate(frequency, months, mYearlyRule->date(),
1042 mYearlyRule->feb29Type(), repeatCount, endDate);
1050 if (!event.recurs())
1053 event.setFirstRecurrence();
1057 int count = mSubRepetition->count();
1058 if (mRuleButtonType < SUBDAILY)
1060 event.setRepetition(mSubRepetition->interval(), count);
1063 event.recurrence()->setExDates(mExceptionDates);
1071 void RecurrenceEdit::saveState()
1073 mSavedRuleButton = mRuleButtonGroup->selected();
1076 mSavedRangeButton = mRangeButtonGroup->selected();
1077 if (mSavedRangeButton == mRepeatCountButton)
1078 mSavedRecurCount = mRepeatCountEntry->value();
1079 else if (mSavedRangeButton == mEndDateButton)
1080 mSavedEndDateTime.set(TQDateTime(mEndDateEdit->date(), mEndTimeEdit->time()), mEndAnyTimeCheckBox->isChecked());
1081 mSavedExceptionDates = mExceptionDates;
1082 mSavedRepeatInterval = mSubRepetition->interval();
1083 mSavedRepeatCount = mSubRepetition->count();
1089 bool RecurrenceEdit::stateChanged()
const
1091 if (mSavedRuleButton != mRuleButtonGroup->selected()
1092 || mSavedRangeButton != mRangeButtonGroup->selected()
1093 || (mRule && mRule->stateChanged()))
1095 if (mSavedRangeButton == mRepeatCountButton
1096 && mSavedRecurCount != mRepeatCountEntry->value())
1098 if (mSavedRangeButton == mEndDateButton
1099 && mSavedEndDateTime != DateTime(TQDateTime(mEndDateEdit->date(), mEndTimeEdit->time()), mEndAnyTimeCheckBox->isChecked()))
1101 if (mSavedExceptionDates != mExceptionDates
1102 || mSavedRepeatInterval != mSubRepetition->interval()
1103 || mSavedRepeatCount != mSubRepetition->count())
1115 Rule::Rule(
const TQString& freqText,
const TQString& freqWhatsThis,
bool time,
bool readOnly, TQWidget* parent,
const char* name)
1116 : NoRule(parent, name)
1118 mLayout =
new TQVBoxLayout(
this, 0, KDialog::spacingHint());
1119 TQHBox* freqBox =
new TQHBox(
this);
1120 mLayout->addWidget(freqBox);
1121 TQHBox* box =
new TQHBox(freqBox);
1122 box->setSpacing(KDialog::spacingHint());
1124 TQLabel* label =
new TQLabel(i18n(
"Recur e&very"), box);
1125 label->setFixedSize(label->sizeHint());
1129 mSpinBox = mTimeSpinBox =
new TimeSpinBox(1, 5999, box);
1130 mTimeSpinBox->setFixedSize(mTimeSpinBox->sizeHint());
1131 mTimeSpinBox->setReadOnly(readOnly);
1136 mSpinBox = mIntSpinBox =
new SpinBox(1, 999, 1, box);
1137 mIntSpinBox->setFixedSize(mIntSpinBox->sizeHint());
1138 mIntSpinBox->setReadOnly(readOnly);
1140 connect(mSpinBox, TQ_SIGNAL(valueChanged(
int)), TQ_SIGNAL(frequencyChanged()));
1141 label->setBuddy(mSpinBox);
1142 label =
new TQLabel(freqText, box);
1143 label->setFixedSize(label->sizeHint());
1144 box->setFixedSize(sizeHint());
1145 TQWhatsThis::add(box, freqWhatsThis);
1147 new TQWidget(freqBox);
1148 freqBox->setFixedHeight(freqBox->sizeHint().height());
1149 freqBox->setFocusProxy(mSpinBox);
1152 int Rule::frequency()
const
1155 return mIntSpinBox->value();
1157 return mTimeSpinBox->value();
1161 void Rule::setFrequency(
int n)
1164 mIntSpinBox->setValue(n);
1166 mTimeSpinBox->setValue(n);
1172 void Rule::saveState()
1174 mSavedFrequency = frequency();
1180 bool Rule::stateChanged()
const
1182 return (mSavedFrequency != frequency());
1191 SubDailyRule::SubDailyRule(
bool readOnly, TQWidget* parent,
const char* name)
1192 : Rule(i18n(
"hours:minutes"),
1193 i18n(
"Enter the number of hours and minutes between repetitions of the alarm"),
1194 true, readOnly, parent, name)
1203 DayWeekRule::DayWeekRule(
const TQString& freqText,
const TQString& freqWhatsThis,
const TQString& daysWhatsThis,
1204 bool readOnly, TQWidget* parent,
const char* name)
1205 : Rule(freqText, freqWhatsThis, false, readOnly, parent, name),
1208 TQGridLayout* grid =
new TQGridLayout(layout(), 1, 4, KDialog::spacingHint());
1209 grid->setRowStretch(0, 1);
1211 TQLabel* label =
new TQLabel(i18n(
"On: Tuesday",
"O&n:"),
this);
1212 label->setFixedSize(label->sizeHint());
1213 grid->addWidget(label, 0, 0, TQt::AlignRight | TQt::AlignTop);
1214 grid->addColSpacing(1, KDialog::spacingHint());
1218 TQWidget* box =
new TQWidget(
this);
1219 TQGridLayout* dgrid =
new TQGridLayout(box, 4, 2, 0, KDialog::spacingHint());
1220 const KCalendarSystem* calendar = TDEGlobal::locale()->calendar();
1221 for (
int i = 0; i < 7; ++i)
1223 int day = KAlarm::localeDayInWeek_to_weekDay(i);
1224 mDayBox[i] =
new CheckBox(calendar->weekDayName(day), box);
1225 mDayBox[i]->setFixedSize(mDayBox[i]->sizeHint());
1226 mDayBox[i]->setReadOnly(readOnly);
1227 dgrid->addWidget(mDayBox[i], i%4, i/4, TQt::AlignAuto);
1229 box->setFixedSize(box->sizeHint());
1230 TQWhatsThis::add(box, daysWhatsThis);
1231 grid->addWidget(box, 0, 2, TQt::AlignAuto);
1232 label->setBuddy(mDayBox[0]);
1233 grid->setColStretch(3, 1);
1239 TQBitArray DayWeekRule::days()
const
1243 for (
int i = 0; i < 7; ++i)
1244 if (mDayBox[i]->isChecked())
1245 ds.setBit(KAlarm::localeDayInWeek_to_weekDay(i) - 1, 1);
1252 void DayWeekRule::setDays(
bool tick)
1254 for (
int i = 0; i < 7; ++i)
1255 mDayBox[i]->setChecked(tick);
1261 void DayWeekRule::setDays(
const TQBitArray& days)
1263 for (
int i = 0; i < 7; ++i)
1265 bool x = days.testBit(KAlarm::localeDayInWeek_to_weekDay(i) - 1);
1266 mDayBox[i]->setChecked(x);
1273 void DayWeekRule::setDay(
int dayOfWeek)
1275 for (
int i = 0; i < 7; ++i)
1276 mDayBox[i]->setChecked(
false);
1277 if (dayOfWeek > 0 && dayOfWeek <= 7)
1278 mDayBox[KAlarm::weekDay_to_localeDayInWeek(dayOfWeek)]->setChecked(
true);
1284 TQWidget* DayWeekRule::validate(TQString& errorMessage)
1286 for (
int i = 0; i < 7; ++i)
1287 if (mDayBox[i]->isChecked())
1289 errorMessage = i18n(
"No day selected");
1296 void DayWeekRule::saveState()
1299 mSavedDays = days();
1305 bool DayWeekRule::stateChanged()
const
1307 return (Rule::stateChanged()
1308 || mSavedDays != days());
1317 DailyRule::DailyRule(
bool readOnly, TQWidget* parent,
const char* name)
1318 : DayWeekRule(i18n(
"day(s)"),
1319 i18n(
"Enter the number of days between repetitions of the alarm"),
1320 i18n(
"Select the days of the week on which the alarm is allowed to occur"),
1321 readOnly, parent, name)
1330 WeeklyRule::WeeklyRule(
bool readOnly, TQWidget* parent,
const char* name)
1331 : DayWeekRule(i18n(
"week(s)"),
1332 i18n(
"Enter the number of weeks between repetitions of the alarm"),
1333 i18n(
"Select the days of the week on which to repeat the alarm"),
1334 readOnly, parent, name)
1343 MonthYearRule::MonthYearRule(
const TQString& freqText,
const TQString& freqWhatsThis,
bool allowEveryWeek,
1344 bool readOnly, TQWidget* parent,
const char* name)
1345 : Rule(freqText, freqWhatsThis, false, readOnly, parent, name),
1346 mEveryWeek(allowEveryWeek)
1348 mButtonGroup =
new ButtonGroup(
this);
1349 mButtonGroup->hide();
1352 TQHBox* box =
new TQHBox(
this);
1353 box->setSpacing(KDialog::spacingHint());
1354 layout()->addWidget(box);
1356 mDayButton =
new RadioButton(i18n(
"On day number in the month",
"O&n day"), box);
1357 mDayButton->setFixedSize(mDayButton->sizeHint());
1358 mDayButton->setReadOnly(readOnly);
1359 mDayButtonId = mButtonGroup->insert(mDayButton);
1360 TQWhatsThis::add(mDayButton, i18n(
"Repeat the alarm on the selected day of the month"));
1362 mDayCombo =
new ComboBox(
false, box);
1363 mDayCombo->setSizeLimit(11);
1364 for (
int i = 0; i < 31; ++i)
1365 mDayCombo->insertItem(TQString::number(i + 1));
1366 mDayCombo->insertItem(i18n(
"Last day of month",
"Last"));
1367 mDayCombo->setFixedSize(mDayCombo->sizeHint());
1368 mDayCombo->setReadOnly(readOnly);
1369 TQWhatsThis::add(mDayCombo, i18n(
"Select the day of the month on which to repeat the alarm"));
1370 mDayButton->setFocusWidget(mDayCombo);
1371 connect(mDayCombo, TQ_SIGNAL(activated(
int)), TQ_SLOT(slotDaySelected(
int)));
1373 box->setStretchFactor(
new TQWidget(box), 1);
1374 box->setFixedHeight(box->sizeHint().height());
1377 box =
new TQHBox(
this);
1378 box->setSpacing(KDialog::spacingHint());
1379 layout()->addWidget(box);
1381 mPosButton =
new RadioButton(i18n(
"On the 1st Tuesday",
"On t&he"), box);
1382 mPosButton->setFixedSize(mPosButton->sizeHint());
1383 mPosButton->setReadOnly(readOnly);
1384 mPosButtonId = mButtonGroup->insert(mPosButton);
1385 TQWhatsThis::add(mPosButton,
1386 i18n(
"Repeat the alarm on one day of the week, in the selected week of the month"));
1388 mWeekCombo =
new ComboBox(
false, box);
1389 mWeekCombo->insertItem(i18n(
"1st"));
1390 mWeekCombo->insertItem(i18n(
"2nd"));
1391 mWeekCombo->insertItem(i18n(
"3rd"));
1392 mWeekCombo->insertItem(i18n(
"4th"));
1393 mWeekCombo->insertItem(i18n(
"5th"));
1394 mWeekCombo->insertItem(i18n(
"Last Monday in March",
"Last"));
1395 mWeekCombo->insertItem(i18n(
"2nd Last"));
1396 mWeekCombo->insertItem(i18n(
"3rd Last"));
1397 mWeekCombo->insertItem(i18n(
"4th Last"));
1398 mWeekCombo->insertItem(i18n(
"5th Last"));
1401 mWeekCombo->insertItem(i18n(
"Every (Monday...) in month",
"Every"));
1402 mWeekCombo->setSizeLimit(11);
1404 TQWhatsThis::add(mWeekCombo, i18n(
"Select the week of the month in which to repeat the alarm"));
1405 mWeekCombo->setFixedSize(mWeekCombo->sizeHint());
1406 mWeekCombo->setReadOnly(readOnly);
1407 mPosButton->setFocusWidget(mWeekCombo);
1409 mDayOfWeekCombo =
new ComboBox(
false, box);
1410 const KCalendarSystem* calendar = TDEGlobal::locale()->calendar();
1411 for (
int i = 0; i < 7; ++i)
1413 int day = KAlarm::localeDayInWeek_to_weekDay(i);
1414 mDayOfWeekCombo->insertItem(calendar->weekDayName(day));
1416 mDayOfWeekCombo->setReadOnly(readOnly);
1417 TQWhatsThis::add(mDayOfWeekCombo, i18n(
"Select the day of the week on which to repeat the alarm"));
1419 box->setStretchFactor(
new TQWidget(box), 1);
1420 box->setFixedHeight(box->sizeHint().height());
1421 connect(mButtonGroup, TQ_SIGNAL(buttonSet(
int)), TQ_SLOT(clicked(
int)));
1424 MonthYearRule::DayPosType MonthYearRule::type()
const
1426 return (mButtonGroup->selectedId() == mDayButtonId) ? DATE : POS;
1429 void MonthYearRule::setType(MonthYearRule::DayPosType type)
1431 mButtonGroup->setButton(type == DATE ? mDayButtonId : mPosButtonId);
1434 void MonthYearRule::setDefaultValues(
int dayOfMonth,
int dayOfWeek)
1437 mDayCombo->setCurrentItem(dayOfMonth);
1438 mWeekCombo->setCurrentItem(dayOfMonth / 7);
1439 mDayOfWeekCombo->setCurrentItem(KAlarm::weekDay_to_localeDayInWeek(dayOfWeek));
1442 int MonthYearRule::date()
const
1444 int daynum = mDayCombo->currentItem() + 1;
1445 return (daynum <= 31) ? daynum : 31 - daynum;
1448 int MonthYearRule::week()
const
1450 int weeknum = mWeekCombo->currentItem() + 1;
1451 return (weeknum <= 5) ? weeknum : (weeknum == 11) ? 0 : 5 - weeknum;
1454 int MonthYearRule::dayOfWeek()
const
1456 return KAlarm::localeDayInWeek_to_weekDay(mDayOfWeekCombo->currentItem());
1459 void MonthYearRule::setDate(
int dayOfMonth)
1461 mButtonGroup->setButton(mDayButtonId);
1462 mDayCombo->setCurrentItem(dayOfMonth > 0 ? dayOfMonth - 1 : dayOfMonth < 0 ? 30 - dayOfMonth : 0);
1465 void MonthYearRule::setPosition(
int week,
int dayOfWeek)
1467 mButtonGroup->setButton(mPosButtonId);
1468 mWeekCombo->setCurrentItem((week > 0) ? week - 1 : (week < 0) ? 4 - week : mEveryWeek ? 10 : 0);
1469 mDayOfWeekCombo->setCurrentItem(KAlarm::weekDay_to_localeDayInWeek(dayOfWeek));
1472 void MonthYearRule::enableSelection(DayPosType type)
1474 bool date = (type == DATE);
1475 mDayCombo->setEnabled(date);
1476 mWeekCombo->setEnabled(!date);
1477 mDayOfWeekCombo->setEnabled(!date);
1480 void MonthYearRule::clicked(
int id)
1482 enableSelection(
id == mDayButtonId ? DATE : POS);
1485 void MonthYearRule::slotDaySelected(
int index)
1487 daySelected(index <= 30 ? index + 1 : 30 - index);
1493 void MonthYearRule::saveState()
1496 mSavedType = type();
1497 if (mSavedType == DATE)
1501 mSavedWeek = week();
1502 mSavedWeekDay = dayOfWeek();
1509 bool MonthYearRule::stateChanged()
const
1511 if (Rule::stateChanged()
1512 || mSavedType != type())
1514 if (mSavedType == DATE)
1516 if (mSavedDay != date())
1521 if (mSavedWeek != week()
1522 || mSavedWeekDay != dayOfWeek())
1534 MonthlyRule::MonthlyRule(
bool readOnly, TQWidget* parent,
const char* name)
1535 : MonthYearRule(i18n(
"month(s)"),
1536 i18n(
"Enter the number of months between repetitions of the alarm"),
1537 false, readOnly, parent, name)
1546 YearlyRule::YearlyRule(
bool readOnly, TQWidget* parent,
const char* name)
1547 : MonthYearRule(i18n(
"year(s)"),
1548 i18n(
"Enter the number of years between repetitions of the alarm"),
1549 true, readOnly, parent, name)
1552 TQBoxLayout* hlayout =
new TQHBoxLayout(layout(), KDialog::spacingHint());
1553 TQLabel* label =
new TQLabel(i18n(
"List of months to select",
"Months:"),
this);
1554 label->setFixedSize(label->sizeHint());
1555 hlayout->addWidget(label, 0, TQt::AlignAuto | TQt::AlignTop);
1558 TQWidget* w =
new TQWidget(
this);
1559 hlayout->addWidget(w, 1, TQt::AlignAuto);
1560 TQGridLayout* grid =
new TQGridLayout(w, 4, 3, 0, KDialog::spacingHint());
1561 const KCalendarSystem* calendar = TDEGlobal::locale()->calendar();
1562 int year = TQDate::currentDate().year();
1563 for (
int i = 0; i < 12; ++i)
1565 mMonthBox[i] =
new CheckBox(calendar->monthName(i + 1, year,
true), w);
1566 mMonthBox[i]->setFixedSize(mMonthBox[i]->sizeHint());
1567 mMonthBox[i]->setReadOnly(readOnly);
1568 grid->addWidget(mMonthBox[i], i%3, i/3, TQt::AlignAuto);
1570 connect(mMonthBox[1], TQ_SIGNAL(toggled(
bool)), TQ_SLOT(enableFeb29()));
1571 w->setFixedHeight(w->sizeHint().height());
1572 TQWhatsThis::add(w, i18n(
"Select the months of the year in which to repeat the alarm"));
1575 TQHBox* f29box =
new TQHBox(
this);
1576 layout()->addWidget(f29box);
1577 TQHBox* box =
new TQHBox(f29box);
1578 box->setSpacing(KDialog::spacingHint());
1579 mFeb29Label =
new TQLabel(i18n(
"February 2&9th alarm in non-leap years:"), box);
1580 mFeb29Label->setFixedSize(mFeb29Label->sizeHint());
1581 mFeb29Combo =
new ComboBox(
false, box);
1582 mFeb29Combo->insertItem(i18n(
"No date",
"None"));
1583 mFeb29Combo->insertItem(i18n(
"1st March (short form)",
"1 Mar"));
1584 mFeb29Combo->insertItem(i18n(
"28th February (short form)",
"28 Feb"));
1585 mFeb29Combo->setFixedSize(mFeb29Combo->sizeHint());
1586 mFeb29Combo->setReadOnly(readOnly);
1587 mFeb29Label->setBuddy(mFeb29Combo);
1588 box->setFixedSize(box->sizeHint());
1589 TQWhatsThis::add(box,
1590 i18n(
"Select which date, if any, the February 29th alarm should trigger in non-leap years"));
1591 new TQWidget(f29box);
1592 f29box->setFixedHeight(f29box->sizeHint().height());
1595 void YearlyRule::setDefaultValues(
int dayOfMonth,
int dayOfWeek,
int month)
1597 MonthYearRule::setDefaultValues(dayOfMonth, dayOfWeek);
1599 for (
int i = 0; i < 12; ++i)
1600 mMonthBox[i]->setChecked(i == month);
1601 setFeb29Type(Preferences::defaultFeb29Type());
1602 daySelected(dayOfMonth);
1609 TQValueList<int> YearlyRule::months()
const
1611 TQValueList<int> mnths;
1612 for (
int i = 0; i < 12; ++i)
1613 if (mMonthBox[i]->isChecked() && mMonthBox[i]->isEnabled())
1614 mnths.append(i + 1);
1621 void YearlyRule::setMonths(
const TQValueList<int>& mnths)
1624 for (
int i = 0; i < 12; ++i)
1626 for (TQValueListConstIterator<int> it = mnths.begin(); it != mnths.end(); ++it)
1627 checked[(*it) - 1] =
true;
1628 for (
int i = 0; i < 12; ++i)
1629 mMonthBox[i]->setChecked(checked[i]);
1636 KARecurrence::Feb29Type YearlyRule::feb29Type()
const
1638 if (mFeb29Combo->isEnabled())
1640 switch (mFeb29Combo->currentItem())
1642 case 1:
return KARecurrence::FEB29_MAR1;
1643 case 2:
return KARecurrence::FEB29_FEB28;
1647 return KARecurrence::FEB29_FEB29;
1653 void YearlyRule::setFeb29Type(KARecurrence::Feb29Type type)
1659 case KARecurrence::FEB29_FEB29: index = 0;
break;
1660 case KARecurrence::FEB29_MAR1: index = 1;
break;
1661 case KARecurrence::FEB29_FEB28: index = 2;
break;
1663 mFeb29Combo->setCurrentItem(index);
1669 TQWidget* YearlyRule::validate(TQString& errorMessage)
1671 for (
int i = 0; i < 12; ++i)
1672 if (mMonthBox[i]->isChecked() && mMonthBox[i]->isEnabled())
1674 errorMessage = i18n(
"No month selected");
1675 return mMonthBox[0];
1682 void YearlyRule::clicked(
int id)
1684 MonthYearRule::clicked(
id);
1685 daySelected(buttonType(
id) == DATE ? date() : 1);
1692 void YearlyRule::daySelected(
int day)
1694 mMonthBox[1]->setEnabled(day <= 29);
1695 bool enable = (day != 31);
1696 mMonthBox[3]->setEnabled(enable);
1697 mMonthBox[5]->setEnabled(enable);
1698 mMonthBox[8]->setEnabled(enable);
1699 mMonthBox[10]->setEnabled(enable);
1707 void YearlyRule::enableFeb29()
1709 bool enable = (type() == DATE && date() == 29 && mMonthBox[1]->isChecked() && mMonthBox[1]->isEnabled());
1710 mFeb29Label->setEnabled(enable);
1711 mFeb29Combo->setEnabled(enable);
1717 void YearlyRule::saveState()
1719 MonthYearRule::saveState();
1720 mSavedMonths = months();
1721 mSavedFeb29Type = feb29Type();
1727 bool YearlyRule::stateChanged()
const
1729 return (MonthYearRule::stateChanged()
1730 || mSavedMonths != months()
1731 || mSavedFeb29Type != feb29Type());
represents calendar alarms and events
KAEvent corresponds to a KCal::Event instance.
the KAlarm application object