22 #include "editdlg.moc"
23 #include "editdlg_p.moc"
30 #include "alarmresources.h"
60 #include <kfiledialog.h>
61 #include <kpushbutton.h>
64 #include <kwindowsystem.h>
71 #include <QPushButton>
72 #include <QGridLayout>
73 #include <QHBoxLayout>
74 #include <QVBoxLayout>
75 #include <QDragEnterEvent>
76 #include <QResizeEvent>
78 #include <QStackedWidget>
83 using namespace KAlarmCal;
94 if (event.repetition())
95 r = QString::fromLatin1(
"%1 / %2").arg(event.recurrenceText()).arg(event.repetitionText());
97 r =
event.recurrenceText();
98 return i18nc(
"@title:tab",
"Recurrence - [%1]", r);
123 switch (event->actionTypes())
125 case KAEvent::ACT_COMMAND:
return new EditCommandAlarmDlg(Template, event, newAlarm, parent, getResource, readOnly);
126 case KAEvent::ACT_DISPLAY_COMMAND:
127 case KAEvent::ACT_DISPLAY:
return new EditDisplayAlarmDlg(Template, event, newAlarm, parent, getResource, readOnly);
128 case KAEvent::ACT_EMAIL:
return new EditEmailAlarmDlg(Template, event, newAlarm, parent, getResource, readOnly);
129 case KAEvent::ACT_AUDIO:
return new EditAudioAlarmDlg(Template, event, newAlarm, parent, getResource, readOnly);
147 mMainPageShown(false),
148 mRecurPageShown(false),
149 mRecurSetDefaultEndDate(true),
152 mDeferChangeButton(0),
154 mShowInKorganizer(0),
158 mDeferGroupHeight(0),
161 mDesiredReadOnly(false),
166 init(0, getResource);
172 mAlarmType(event->actionSubType()),
173 mMainPageShown(false),
174 mRecurPageShown(false),
175 mRecurSetDefaultEndDate(true),
178 mDeferChangeButton(0),
180 mShowInKorganizer(0),
184 mDeferGroupHeight(0),
185 mEventId(newAlarm ? QString() : event->id()),
188 mDesiredReadOnly(readOnly),
193 init(event, getResource);
204 mCollectionItemId =
event->itemId();
209 mCollectionItemId = -1;
213 mCollectionItemId = -2;
219 mResourceEventId =
event->id();
224 mResourceEventId = QString(
"");
228 mResourceEventId.clear();
236 setObjectName(mTemplate ? QLatin1String(
"TemplEditDlg") : QLatin1String(
"EditDlg"));
239 caption = mTemplate ? i18nc(
"@title:window",
"Alarm Template [read-only]")
240 :
event->expired() ? i18nc(
"@title:window",
"Archived Alarm [read-only]")
241 : i18nc(
"@title:window",
"Alarm [read-only]");
245 setButtons((mReadOnly ? Cancel|Try|Default : mTemplate ? Ok|Cancel|Try|Default : Ok|Cancel|Try|Help|Default));
246 setDefaultButton(mReadOnly ? Cancel : Ok);
247 setButtonText(Help, i18nc(
"@action:button",
"Load Template..."));
248 setButtonIcon(Help, KIcon());
249 setButtonIcon(Default, KIcon());
250 connect(
this, SIGNAL(tryClicked()), SLOT(
slotTry()));
251 connect(
this, SIGNAL(defaultClicked()), SLOT(
slotDefault()));
252 connect(
this, SIGNAL(helpClicked()), SLOT(
slotHelp()));
254 mainWidget->setMargin(0);
255 setMainWidget(mainWidget);
260 box->setSpacing(spacingHint());
261 QLabel* label =
new QLabel(i18nc(
"@label:textbox",
"Template name:"), box);
262 label->setFixedSize(label->sizeHint());
264 mTemplateName->setReadOnly(mReadOnly);
265 connect(mTemplateName, SIGNAL(userTextChanged(QString)), SLOT(
contentsChanged()));
266 label->setBuddy(mTemplateName);
267 box->setWhatsThis(i18nc(
"@info:whatsthis",
"Enter the name of the alarm template"));
268 box->setFixedHeight(box->sizeHint().height());
270 mTabs =
new KTabWidget(mainWidget);
274 mTabs->addTab(mainScroll, i18nc(
"@title:tab",
"Alarm"));
277 mainScroll->setWidget(mainPage);
278 connect(mainPage, SIGNAL(shown()), SLOT(slotShowMainPage()));
279 QVBoxLayout* topLayout =
new QVBoxLayout(mainPage);
280 topLayout->setMargin(marginHint());
281 topLayout->setSpacing(spacingHint());
285 mTabs->addTab(recurScroll, QString());
288 recurTab->setMargin(marginHint());
289 recurScroll->setWidget(recurTab);
291 connect(mRecurrenceEdit, SIGNAL(shown()), SLOT(slotShowRecurrenceEdit()));
292 connect(mRecurrenceEdit, SIGNAL(typeChanged(
int)), SLOT(slotRecurTypeChange(
int)));
293 connect(mRecurrenceEdit, SIGNAL(frequencyChanged()), SLOT(slotRecurFrequencyChange()));
294 connect(mRecurrenceEdit, SIGNAL(repeatNeedsInitialisation()), SLOT(slotSetSubRepetition()));
299 topLayout->addWidget(actionBox, 1);
300 QVBoxLayout* layout =
new QVBoxLayout(actionBox);
301 layout->setMargin(marginHint());
302 layout->setSpacing(spacingHint());
309 mDeferGroup =
new QGroupBox(i18nc(
"@title:group",
"Deferred Alarm"), mainPage);
310 topLayout->addWidget(mDeferGroup);
311 QHBoxLayout* hlayout =
new QHBoxLayout(mDeferGroup);
312 hlayout->setMargin(marginHint());
313 hlayout->setSpacing(spacingHint());
314 QLabel* label =
new QLabel(i18nc(
"@label",
"Deferred to:"), mDeferGroup);
315 label->setFixedSize(label->sizeHint());
316 hlayout->addWidget(label);
317 mDeferTimeLabel =
new QLabel(mDeferGroup);
318 hlayout->addWidget(mDeferTimeLabel);
320 mDeferChangeButton =
new QPushButton(i18nc(
"@action:button",
"Change..."), mDeferGroup);
321 mDeferChangeButton->setFixedSize(mDeferChangeButton->sizeHint());
322 connect(mDeferChangeButton, SIGNAL(clicked()), SLOT(slotEditDeferral()));
323 mDeferChangeButton->setWhatsThis(i18nc(
"@info:whatsthis",
"Change the alarm's deferred time, or cancel the deferral"));
324 hlayout->addWidget(mDeferChangeButton);
328 QHBoxLayout* hlayout =
new QHBoxLayout();
329 hlayout->setMargin(0);
330 topLayout->addLayout(hlayout);
336 hlayout->addWidget(templateTimeBox);
337 QGridLayout* grid =
new QGridLayout(templateTimeBox);
338 grid->setMargin(marginHint());
339 grid->setSpacing(spacingHint());
340 mTemplateTimeGroup =
new ButtonGroup(templateTimeBox);
341 connect(mTemplateTimeGroup, SIGNAL(buttonSet(QAbstractButton*)), SLOT(slotTemplateTimeType(QAbstractButton*)));
342 connect(mTemplateTimeGroup, SIGNAL(buttonSet(QAbstractButton*)), SLOT(
contentsChanged()));
344 mTemplateDefaultTime =
new RadioButton(i18nc(
"@option:radio",
"Default time"), templateTimeBox);
345 mTemplateDefaultTime->setFixedSize(mTemplateDefaultTime->sizeHint());
347 mTemplateDefaultTime->setWhatsThis(i18nc(
"@info:whatsthis",
"Do not specify a start time for alarms based on this template. "
348 "The normal default start time will be used."));
349 mTemplateTimeGroup->
addButton(mTemplateDefaultTime);
350 grid->addWidget(mTemplateDefaultTime, 0, 0, Qt::AlignLeft);
354 box->setSpacing(spacingHint());
355 mTemplateUseTime =
new RadioButton(i18nc(
"@option:radio",
"Time:"), box);
356 mTemplateUseTime->setFixedSize(mTemplateUseTime->sizeHint());
358 mTemplateUseTime->setWhatsThis(i18nc(
"@info:whatsthis",
"Specify a start time for alarms based on this template."));
359 mTemplateTimeGroup->
addButton(mTemplateUseTime);
361 mTemplateTime->setFixedSize(mTemplateTime->sizeHint());
363 mTemplateTime->setWhatsThis(i18nc(
"@info:whatsthis",
364 "<para>Enter the start time for alarms based on this template.</para><para>%1</para>",
366 connect(mTemplateTime, SIGNAL(valueChanged(
int)), SLOT(
contentsChanged()));
367 box->setStretchFactor(
new QWidget(box), 1);
368 box->setFixedHeight(box->sizeHint().height());
369 grid->addWidget(box, 0, 1, Qt::AlignLeft);
371 mTemplateAnyTime =
new RadioButton(i18nc(
"@option:radio",
"Date only"), templateTimeBox);
372 mTemplateAnyTime->setFixedSize(mTemplateAnyTime->sizeHint());
374 mTemplateAnyTime->setWhatsThis(i18nc(
"@info:whatsthis",
"Set the <interface>Any time</interface> option for alarms based on this template."));
375 mTemplateTimeGroup->
addButton(mTemplateAnyTime);
376 grid->addWidget(mTemplateAnyTime, 1, 0, Qt::AlignLeft);
378 box =
new KHBox(templateTimeBox);
380 box->setSpacing(spacingHint());
381 mTemplateUseTimeAfter =
new RadioButton(i18nc(
"@option:radio",
"Time from now:"), box);
382 mTemplateUseTimeAfter->setFixedSize(mTemplateUseTimeAfter->sizeHint());
384 mTemplateUseTimeAfter->setWhatsThis(i18nc(
"@info:whatsthis",
385 "Set alarms based on this template to start after the specified time "
386 "interval from when the alarm is created."));
387 mTemplateTimeGroup->
addButton(mTemplateUseTimeAfter);
390 mTemplateTimeAfter->setFixedSize(mTemplateTimeAfter->
sizeHint());
392 connect(mTemplateTimeAfter, SIGNAL(valueChanged(
int)), SLOT(
contentsChanged()));
393 mTemplateTimeAfter->setWhatsThis(i18nc(
"@info:whatsthis",
"<para>%1</para><para>%2</para>",
395 box->setFixedHeight(box->sizeHint().height());
396 grid->addWidget(box, 1, 1, Qt::AlignLeft);
398 hlayout->addStretch();
403 connect(mTimeWidget, SIGNAL(dateOnlyToggled(
bool)), SLOT(slotAnyTimeToggled(
bool)));
404 connect(mTimeWidget, SIGNAL(changed(KDateTime)), SLOT(
contentsChanged()));
405 topLayout->addWidget(mTimeWidget);
409 mMoreOptions =
new QFrame(mainPage);
410 mMoreOptions->setFrameStyle(QFrame::NoFrame);
411 topLayout->addWidget(mMoreOptions);
412 QVBoxLayout* moreLayout =
new QVBoxLayout(mMoreOptions);
413 moreLayout->setMargin(0);
414 moreLayout->setSpacing(spacingHint());
420 mReminder->setFixedSize(mReminder->sizeHint());
422 moreLayout->addWidget(mReminder, 0, Qt::AlignLeft);
424 connect(mTimeWidget, SIGNAL(changed(KDateTime)), mReminder, SLOT(setDefaultUnits(KDateTime)));
430 moreLayout->addWidget(mLateCancel, 0, Qt::AlignLeft);
433 playout->setSpacing(2*spacingHint());
434 moreLayout->addLayout(playout);
440 confirmAck->setFixedSize(confirmAck->sizeHint());
442 playout->addWidget(confirmAck);
445 if (
theApp()->korganizerEnabled())
449 mShowInKorganizer->setFixedSize(mShowInKorganizer->sizeHint());
450 connect(mShowInKorganizer, SIGNAL(toggled(
bool)), SLOT(
contentsChanged()));
451 mShowInKorganizer->setWhatsThis(i18nc(
"@info:whatsthis",
"Check to copy the alarm into KOrganizer's calendar"));
452 playout->addWidget(mShowInKorganizer);
455 setButtonWhatsThis(Ok, i18nc(
"@info:whatsthis",
"Schedule the alarm at the specified time."));
464 mTemplateName->setFocus();
469 saveState((event && (mTemplate || !event->isTemplate())) ?
event : 0);
477 mDesktop = KWindowSystem::currentDesktop();
488 void EditAlarmDlg::initValues(
const KAEvent* event)
493 mOnlyDeferred =
false;
494 mExpiredRecurrence =
false;
496 bool deferGroupVisible =
false;
501 mTemplateName->setText(event->templateName());
502 bool recurs =
event->recurs();
503 if ((recurs || event->repetition()) && !mTemplate && event->deferred())
505 deferGroupVisible =
true;
506 mDeferDateTime =
event->deferDateTime();
507 mDeferTimeLabel->setText(mDeferDateTime.formatLocale());
513 int afterTime =
event->isTemplate() ?
event->templateAfterTime() : -1;
514 bool noTime = !afterTime;
515 bool useTime = !
event->mainDateTime().isDateOnly();
516 RadioButton* button = noTime ? mTemplateDefaultTime :
517 (afterTime > 0) ? mTemplateUseTimeAfter :
518 useTime ? mTemplateUseTime : mTemplateAnyTime;
519 button->setChecked(
true);
520 mTemplateTimeAfter->
setValue(afterTime > 0 ? afterTime : 1);
521 if (!noTime && useTime)
522 mTemplateTime->
setValue(event->mainDateTime().kDateTime().time());
528 if (event->isTemplate())
532 int afterTime =
event->templateAfterTime();
535 mTimeWidget->
setDateTime(now.addSecs(afterTime * 60));
540 KDateTime dt =
event->startDateTime().kDateTime();
542 QDate d = now.date();
543 if (!dt.isDateOnly() && now.time() >= dt.time())
551 mExpiredRecurrence = recurs &&
event->mainExpired();
552 mTimeWidget->
setDateTime(recurs || event->category() == CalEvent::ARCHIVED ?
event->startDateTime()
553 :
event->mainExpired() ?
event->deferDateTime() :
event->mainDateTime());
557 KAEvent::SubAction action =
event->actionSubType();
559 if (event->commandScript())
560 altext.setScript(event->cleanText());
562 altext.setText(event->cleanText());
565 mLateCancel->
setMinutes(event->lateCancel(),
event->startDateTime().isDateOnly(),
567 if (mShowInKorganizer)
568 mShowInKorganizer->setChecked(event->copyToKOrganizer());
570 mRecurrenceEdit->
set(*event);
571 mTabs->setTabText(mRecurPageIndex,
recurText(*event));
576 KDateTime defaultTime = KDateTime::currentUtcDateTime().addSecs(60).toTimeSpec(
Preferences::timeZone());
579 mTemplateDefaultTime->setChecked(
true);
586 if (mShowInKorganizer)
590 slotRecurFrequencyChange();
592 if (mReminder && mTimeWidget)
595 if (!deferGroupVisible && mDeferGroup)
599 enableButton(Help, !empty);
612 event.setTime(mTimeWidget->
getDateTime(0,
false,
false));
613 event.setRecurrence(recur);
614 event.setRepetition(Repetition(subRepeatInterval, subRepeatCount - 1));
615 mRecurrenceEdit->
set(event);
628 mShowInKorganizer->setChecked(show);
636 mReadOnly = readOnly;
641 if (mDeferChangeButton)
644 mDeferChangeButton->hide();
646 mDeferChangeButton->show();
648 if (mShowInKorganizer)
660 mSavedEvent =
new KAEvent(*event);
663 mSavedTemplateName = mTemplateName->text();
664 mSavedTemplateTimeType = mTemplateTimeGroup->checkedButton();
665 mSavedTemplateTime = mTemplateTime->
time();
666 mSavedTemplateAfterTime = mTemplateTimeAfter->
value();
668 checkText(mSavedTextFileCommandMessage,
false);
670 mSavedDateTime = mTimeWidget->
getDateTime(0,
false,
false);
671 mSavedLateCancel = mLateCancel->
minutes();
672 if (mShowInKorganizer)
673 mSavedShowInKorganizer = mShowInKorganizer->isChecked();
674 mSavedRecurrenceType = mRecurrenceEdit->
repeatType();
675 mSavedDeferTime = mDeferDateTime.kDateTime();
685 bool EditAlarmDlg::stateChanged()
const
688 mOnlyDeferred =
false;
691 QString textFileCommandMessage;
692 checkText(textFileCommandMessage,
false);
695 if (mSavedTemplateName != mTemplateName->text()
696 || mSavedTemplateTimeType != mTemplateTimeGroup->checkedButton()
697 || (mTemplateUseTime->isChecked() && mSavedTemplateTime != mTemplateTime->
time())
698 || (mTemplateUseTimeAfter->isChecked() && mSavedTemplateAfterTime != mTemplateTimeAfter->
value()))
703 KDateTime dt = mTimeWidget->
getDateTime(0,
false,
false);
704 if (mSavedDateTime.timeSpec() != dt.timeSpec() || mSavedDateTime != dt)
707 if (mSavedLateCancel != mLateCancel->
minutes()
708 || (mShowInKorganizer && mSavedShowInKorganizer != mShowInKorganizer->isChecked())
709 || textFileCommandMessage != mSavedTextFileCommandMessage
710 || mSavedRecurrenceType != mRecurrenceEdit->
repeatType())
716 if (mSavedEvent && mSavedEvent->deferred())
717 mOnlyDeferred =
true;
731 if (mSavedEvent && button(Ok))
732 button(Ok)->setEnabled(stateChanged() || mDeferDateTime.kDateTime() != mSavedDeferTime);
747 collection = mCollection;
749 resource = mResource;
754 setEvent(event, mAlarmMessage,
false);
759 event = *mSavedEvent;
764 if (mDeferDateTime.isValid())
765 event.defer(mDeferDateTime, event.reminderDeferral(),
false);
777 void EditAlarmDlg::setEvent(KAEvent& event,
const QString&
text,
bool trial)
783 dt = mAlarmDateTime.effectiveKDateTime();
784 else if (mTemplateUseTime->isChecked())
785 dt = KDateTime(QDate(2000,1,1), mTemplateTime->
time());
788 int lateCancel = (trial || !mLateCancel->isEnabled()) ? 0 : mLateCancel->
minutes();
796 KDateTime now = KDateTime::currentDateTime(mAlarmDateTime.timeSpec());
797 bool dateOnly = mAlarmDateTime.isDateOnly();
798 if ((dateOnly && mAlarmDateTime.date() < now.date())
799 || (!dateOnly && mAlarmDateTime.kDateTime() < now))
803 event.setNextOccurrence(now);
805 mAlarmDateTime =
event.startDateTime();
806 if (mDeferDateTime.isValid() && mDeferDateTime < mAlarmDateTime)
808 bool deferral =
true;
809 bool deferReminder =
false;
813 DateTime remindTime = mAlarmDateTime.addMins(-reminder);
814 if (mDeferDateTime >= remindTime)
816 if (remindTime > KDateTime::currentUtcDateTime())
818 else if (mDeferDateTime > remindTime)
819 deferReminder =
true;
823 event.defer(mDeferDateTime, deferReminder,
false);
828 int afterTime = mTemplateDefaultTime->isChecked() ? 0
829 : mTemplateUseTimeAfter->isChecked() ? mTemplateTimeAfter->
value() : -1;
830 event.setTemplate(mTemplateName->text(), afterTime);
840 KAEvent::Flags flags(0);
841 if (mShowInKorganizer && mShowInKorganizer->isEnabled() && mShowInKorganizer->isChecked())
842 flags |= KAEvent::COPY_KORGANIZER;
844 flags |= KAEvent::REPEAT_AT_LOGIN;
845 if (mTemplate ? mTemplateAnyTime->isChecked() : mAlarmDateTime.isDateOnly())
846 flags |= KAEvent::ANY_TIME;
857 KDialog::showEvent(se);
858 if (!mDeferGroupHeight)
861 mDeferGroupHeight = mDeferGroup->height() + spacingHint();
865 bool defer = mDeferGroup && !mDeferGroup->isHidden();
866 s.setHeight(s.height() + (defer ? mDeferGroupHeight : 0));
873 KWindowSystem::setOnDesktop(winId(), mDesktop);
882 KDialog::closeEvent(ce);
891 void EditAlarmDlg::slotResize()
894 s = minimumSizeHint();
895 if (height() > s.height())
900 resize(s.width(), s.height() + 2);
911 if (isVisible() && mDeferGroupHeight)
913 QSize s = re->size();
914 s.setHeight(s.height() - (!mDeferGroup || mDeferGroup->isHidden() ? 0 : mDeferGroupHeight));
917 KDialog::resizeEvent(re);
931 KDialog::slotButtonClicked(button);
938 bool EditAlarmDlg::validate()
945 return mOnlyDeferred;
956 QString name = mTemplateName->text();
958 errmsg = i18nc(
"@info",
"You must enter a name for the alarm template");
959 else if (name != mSavedTemplateName)
962 errmsg = i18nc(
"@info",
"Template name is already in use");
964 if (!errmsg.isEmpty())
966 mTemplateName->setFocus();
971 else if (mTimeWidget)
974 mAlarmDateTime = mTimeWidget->
getDateTime(0, !timedRecurrence,
false, &errWidget);
978 mTabs->setCurrentIndex(mMainPageIndex);
979 errWidget->setFocus();
993 DateTime dt = mAlarmDateTime;
995 setEvent(event, mAlarmMessage,
false);
997 KDateTime pre = dt.effectiveKDateTime();
998 bool dateOnly = dt.isDateOnly();
1000 pre = pre.addDays(-1);
1002 pre = pre.addSecs(-1);
1004 event.nextOccurrence(pre, next, KAEvent::IGNORE_REPETITION);
1007 QString prompt = dateOnly ? i18nc(
"@info The parameter is a date value",
1008 "The start date does not match the alarm's recurrence pattern, "
1009 "so it will be adjusted to the date of the next recurrence (%1).",
1010 KGlobal::locale()->formatDate(next.date(), KLocale::ShortDate))
1011 : i18nc(
"@info The parameter is a date/time value",
1012 "The start date/time does not match the alarm's recurrence pattern, "
1013 "so it will be adjusted to the date/time of the next recurrence (%1).",
1014 KGlobal::locale()->formatDateTime(next.kDateTime(), KLocale::ShortDate));
1020 if (timedRecurrence)
1024 Akonadi::Collection c;
1030 KDateTime now = KDateTime::currentDateTime(mAlarmDateTime.timeSpec());
1031 bool dateOnly = mAlarmDateTime.isDateOnly();
1032 if ((dateOnly && mAlarmDateTime.date() < now.date())
1033 || (!dateOnly && mAlarmDateTime.kDateTime() < now))
1037 if (event.nextOccurrence(now, mAlarmDateTime, KAEvent::ALLOW_FOR_REPETITION) == KAEvent::NO_OCCURRENCE)
1042 if (event.workTimeOnly() && !
event.nextTrigger(KAEvent::DISPLAY_TRIGGER).isValid())
1045 != KMessageBox::Continue)
1051 QWidget* errWidget = mRecurrenceEdit->
checkData(mAlarmDateTime.effectiveKDateTime(), errmsg);
1054 mTabs->setCurrentIndex(mRecurPageIndex);
1055 errWidget->setFocus();
1063 int longestRecurMinutes = -1;
1064 int reminder = mReminder ? mReminder->
minutes() : 0;
1068 longestRecurMinutes = recurEvent.longestRecurrenceInterval().asSeconds() / 60;
1069 if (longestRecurMinutes && reminder >= longestRecurMinutes)
1071 mTabs->setCurrentIndex(mMainPageIndex);
1073 KAMessageBox::sorry(
this, i18nc(
"@info",
"Reminder period must be less than the recurrence interval, unless <interface>%1</interface> is checked.",
1080 if (longestRecurMinutes < 0)
1083 longestRecurMinutes = recurEvent.longestRecurrenceInterval().asSeconds() / 60;
1085 if (longestRecurMinutes > 0
1086 && recurEvent.repetition().intervalMinutes() * recurEvent.repetition().count() >= longestRecurMinutes -
reminder)
1088 KAMessageBox::sorry(
this, i18nc(
"@info",
"The duration of a repetition within the recurrence must be less than the recurrence interval minus any reminder period"));
1092 if (!recurEvent.repetition().isDaily()
1093 && ((mTemplate && mTemplateAnyTime->isChecked()) || (!mTemplate && mAlarmDateTime.isDateOnly())))
1095 KAMessageBox::sorry(
this, i18nc(
"@info",
"For a repetition within the recurrence, its period must be in units of days or weeks for a date-only alarm"));
1105 mCollection = Akonadi::Collection();
1108 if (mCollectionItemId >= -1)
1110 if (mCollectionItemId >= 0)
1113 if (mCollection.isValid())
1115 CalEvent::Type type = mTemplate ? CalEvent::TEMPLATE : CalEvent::ACTIVE;
1117 mCollection = Akonadi::Collection();
1120 bool cancelled =
false;
1121 CalEvent::Type type = mTemplate ? CalEvent::TEMPLATE : CalEvent::ACTIVE;
1124 if (!mCollection.isValid())
1127 KAMessageBox::sorry(
this, i18nc(
"@info",
"You must select a calendar to save the alarm in"));
1135 if (!mResourceEventId.isNull())
1137 if (!mResourceEventId.isEmpty())
1142 CalEvent::Type type = mTemplate ? CalEvent::TEMPLATE : CalEvent::ACTIVE;
1143 if (mResource->alarmType() != type)
1147 bool cancelled =
false;
1148 if (!mResource || !mResource->writable())
1150 CalEvent::Type type = mTemplate ? CalEvent::TEMPLATE : CalEvent::ACTIVE;
1151 mResource = AlarmResources::instance()->destination(type,
this,
false, &cancelled);
1156 KAMessageBox::sorry(
this, i18nc(
"@info",
"You must select a calendar to save the alarm in"));
1176 setEvent(event, text,
true);
1177 if (!mNewAlarm && !stateChanged())
1181 event.setEventId(mEventId);
1184 void* result =
theApp()->
execAlarm(event, event.firstAlarm(),
false,
false);
1195 KAEvent::Actions type;
1199 case KAEvent::MESSAGE: type = KAEvent::ACT_DISPLAY;
break;
1200 case KAEvent::COMMAND: type = KAEvent::ACT_COMMAND;
break;
1201 case KAEvent::EMAIL: type = KAEvent::ACT_EMAIL;
break;
1202 case KAEvent::AUDIO: type = KAEvent::ACT_AUDIO;
break;
1210 if (dlg->exec() == QDialog::Accepted)
1213 KAEvent
event = dlg->selectedTemplate();
1217 initValues(dlg->selectedTemplate());
1228 showOptions(!mShowingMore);
1236 void EditAlarmDlg::showOptions(
bool more)
1238 kDebug() << (more ?
"More" :
"Less");
1241 mMoreOptions->show();
1242 setButtonText(Default, i18nc(
"@action:button",
"Less Options <<"));
1246 mMoreOptions->hide();
1247 setButtonText(Default, i18nc(
"@action:button",
"More Options >>"));
1253 mShowingMore = more;
1254 QTimer::singleShot(0,
this, SLOT(slotResize()));
1260 void EditAlarmDlg::slotEditDeferral()
1266 DateTime start = mSavedEvent->recurs() ? (mExpiredRecurrence ? DateTime() : mSavedEvent->mainDateTime())
1267 : mTimeWidget->getDateTime(0, !repetition, !mExpiredRecurrence);
1268 if (!start.isValid())
1270 if (!mExpiredRecurrence)
1274 KDateTime now = KDateTime::currentUtcDateTime();
1277 if (repetition && start < now)
1280 int repeatNum = repetition.isDaily()
1281 ? (start.daysTo(now) + repetition.intervalDays() - 1) / repetition.intervalDays()
1282 : (start.secsTo(now) + repetition.intervalSeconds() - 1) / repetition.intervalSeconds();
1283 if (repeatNum > repetition.count())
1288 start = repetition.duration(repeatNum).end(start.kDateTime());
1292 bool deferred = mDeferDateTime.isValid();
1297 start.isDateOnly(), deferred,
this);
1298 deferDlg->setObjectName(QLatin1String(
"EditDeferDlg"));
1302 int reminder = mReminder ? mReminder->
minutes() : 0;
1305 DateTime remindTime = start.addMins(-reminder);
1306 if (KDateTime::currentUtcDateTime() < remindTime)
1309 deferDlg->setLimit(start.addSecs(-60));
1311 if (deferDlg->exec() == QDialog::Accepted)
1313 mDeferDateTime = deferDlg->getDateTime();
1314 mDeferTimeLabel->setText(mDeferDateTime.isValid() ? mDeferDateTime.formatLocale() : QString());
1323 void EditAlarmDlg::slotShowMainPage()
1325 if (!mMainPageShown)
1328 mTemplateName->setFocus();
1329 mMainPageShown =
true;
1335 main->verticalScrollBar()->setValue(0);
1354 void EditAlarmDlg::slotShowRecurrenceEdit()
1356 mRecurPageIndex = mTabs->currentIndex();
1357 if (!mReadOnly && !mTemplate)
1359 mAlarmDateTime = mTimeWidget->
getDateTime(0,
false,
false);
1360 KDateTime now = KDateTime::currentDateTime(mAlarmDateTime.timeSpec());
1361 bool expired = (mAlarmDateTime.effectiveKDateTime() < now);
1362 if (mRecurSetDefaultEndDate)
1364 mRecurrenceEdit->
setDefaultEndDate(expired ? now.date() : mAlarmDateTime.date());
1365 mRecurSetDefaultEndDate =
false;
1367 mRecurrenceEdit->
setStartDate(mAlarmDateTime.date(), now.date());
1369 mRecurrenceEdit->
setEndDateTime(expired ? now : mAlarmDateTime.kDateTime());
1371 mRecurPageShown =
true;
1379 void EditAlarmDlg::slotRecurTypeChange(
int repeatType)
1386 mDeferGroup->setEnabled(recurs);
1390 mAlarmDateTime = mTimeWidget->
getDateTime(0,
false,
false);
1398 mLateCancel->setEnabled(!atLogin);
1399 if (mShowInKorganizer)
1400 mShowInKorganizer->setEnabled(!atLogin);
1401 slotRecurFrequencyChange();
1409 void EditAlarmDlg::slotRecurFrequencyChange()
1411 slotSetSubRepetition();
1414 mTabs->setTabText(mRecurPageIndex,
recurText(event));
1425 void EditAlarmDlg::slotSetSubRepetition()
1427 bool dateOnly = mTemplate ? mTemplateAnyTime->isChecked() : mTimeWidget->
anyTime();
1435 void EditAlarmDlg::slotTemplateTimeType(QAbstractButton*)
1437 mTemplateTime->setEnabled(mTemplateUseTime->isChecked());
1438 mTemplateTimeAfter->
setEnabled(mTemplateUseTimeAfter->isChecked());
1445 void EditAlarmDlg::slotAnyTimeToggled(
bool anyTime)
1454 return mTimeWidget ? mTimeWidget->
anyTime() : mTemplateAnyTime->isChecked();
1464 mTabs->setCurrentIndex(mMainPageIndex);
virtual void closeEvent(QCloseEvent *)
virtual void setReadOnly(bool readOnly)
KAEvent::SubAction mAlarmType
virtual void setEnabled(bool enabled)
static bool defaultCopyToKOrganizer()
Get Show in KOrganizer.
static const char EDIT_MORE_KEY[]
void setAfterOnly(bool after)
LateCancelSelector * lateCancel() const
void setTime(const DateTime &)
static int isWritableEnabled(const Akonadi::Collection &, CalEvent::Type)
Return whether a collection is both enabled and fully writable for a given alarm type, i.e.
virtual void showEvent(QShowEvent *)
virtual void setReadOnly(bool readOnly)
virtual CheckBox * type_createConfirmAckCheckbox(QWidget *parent)
static QString i18n_chk_FirstRecurrenceOnly()
void updateEvent(KAEvent &, bool adjustStart)
Write recurrence settings into an event.
virtual QByteArray text(quint32 serialNumber) const =0
virtual bool checkText(QString &result, bool showErrorMessage=true) const =0
void setLateCancel(int minutes)
void setStartDate(const QDate &, const QDate &today)
static AlarmCalendar * resources()
void showAutoClose(bool show)
AlarmResource * resourceForEvent(const QString &eventID) const
KAEvent * templateEvent(const QString &templateName)
KDateTime endDateTime() const
void setDateOnly(bool dateOnly)
virtual void type_executedTry(const QString &text, void *obj)
the KAlarm application object
EditAlarmDlg(bool Template, KAEvent::SubAction, QWidget *parent=0, GetResourceType=RES_PROMPT)
virtual QSize sizeHint() const
void showMoreOptions(bool)
virtual void slotButtonClicked(int button)
static KTimeZone timeZone(bool reload=false)
virtual void setReadOnly(bool readOnly)
static Akonadi::Collection destination(CalEvent::Type, QWidget *promptParent=0, bool noPrompt=false, bool *cancelled=0)
Find the collection to be used to store an event of a given type.
void setDefaultUnits(const KDateTime &)
virtual KAEvent::Flags getAlarmFlags() const
RepeatType repeatType() const
static AkonadiModel * instance()
virtual void setAction(KAEvent::SubAction, const AlarmText &=AlarmText())=0
Repetition subRepetition() const
virtual void type_aboutToTry()
void setShowInKOrganizer(bool)
static EditAlarmDlg * create(bool Template, Type, QWidget *parent=0, GetResourceType=RES_PROMPT)
bool getEvent(KAEvent &, AlarmResource *&)
bool isTimedRepeatType() const
bool stateChanged() const
static const int maxDelayTime
virtual bool type_stateChanged() const =0
virtual void setValue(int minutes)
virtual void setReadOnly(bool readOnly)=0
static int defaultLateCancel()
Get Cancel if late (minutes)
void setDateOnly(bool dateOnly)
bool isTimedRecurrence() const
void init(const KAEvent *event)
static int warningContinueCancel(QWidget *parent, ButtonCode defaultButton, const QString &text, const QString &caption=QString(), const KGuiItem &buttonContinue=KStandardGuiItem::cont(), const QString &dontAskAgainName=QString())
virtual void type_showOptions(bool more)=0
void setDefaults(const KDateTime &from)
Set widgets to default values.
void activateSubRepetition()
void setRecurrence(const KARecurrence &, int subRepeatInterval, int subRepeatCount)
virtual void slotDefault()
static void sorry(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Options(Notify|WindowModal))
virtual void setValue(int minutes)
virtual QString type_caption() const =0
void setRepeatAtLogin()
Initialise with repeat-at-login selected, instead of calling set().
virtual void type_initValues(const KAEvent *)=0
Reminder * reminder() const
virtual void type_setEvent(KAEvent &, const KDateTime &, const QString &text, int lateCancel, bool trial)=0
void * execAlarm(KAEvent &, const KAAlarm &, bool reschedule, bool allowDefer=true, bool noPreAction=false)
KAEvent::List events(CalEvent::Types s=CalEvent::EMPTY) const
QWidget * checkData(const KDateTime &startDateTime, QString &errorMessage) const
void enableOnceOnly(bool enable)
virtual void type_init(QWidget *parent, QVBoxLayout *frameLayout)=0
virtual void resizeEvent(QResizeEvent *)
virtual void saveState(const KAEvent *)=0
static QString i18n_chk_ShowInKOrganizer()
void setDefaultEndDate(const QDate &)
static QString shiftWhatsThis()
void setMinutes(int Minutes, bool dateOnly, TimePeriod::Units defaultUnits)
int main(int argc, char *argv[])
static const char EDIT_MORE_GROUP[]
static const char EDIT_DIALOG_NAME[]
QString recurText(const KAEvent &event)
virtual bool type_validate(bool trial)=0
void set(const KAEvent &)
Initialise according to a specified event.
virtual Reminder * createReminder(QWidget *parent)
void setSubRepetition(int reminderMinutes, bool dateOnly)
void setEndDateTime(const KDateTime &)
static const char TEMPLATE_DIALOG_NAME[]