8#include "alarmdialog.h"
9#include "editorconfig.h"
10#include "ui_alarmdialog.h"
12#include <KLocalizedString>
13#include <QDialogButtonBox>
17using namespace IncidenceEditorNG;
21 , mUi(new Ui::AlarmDialog)
22 , mIncidenceType(incidenceType)
24 setWindowTitle(
i18nc(
"@title:window",
"Create a new reminder"));
33 auto mainWidget =
new QWidget(
this);
34 mUi->setupUi(mainWidget);
35 mainLayout->addWidget(mainWidget);
36 mainLayout->addWidget(buttonBox);
38 const int defaultReminderTime = IncidenceEditorNG::EditorConfig::instance()->reminderTime();
39 mUi->mAlarmOffset->setValue(defaultReminderTime);
41 int defaultReminderUnits = IncidenceEditorNG::EditorConfig::instance()->reminderTimeUnits();
42 if (defaultReminderUnits < 0 || defaultReminderUnits > 2) {
43 defaultReminderUnits = 0;
46 mUi->mOffsetUnit->setCurrentIndex(defaultReminderUnits);
47 mUi->mSoundFile->setMimeTypeFilters({QStringLiteral(
"audio/x-wav"), QStringLiteral(
"audio/x-mp3"), QStringLiteral(
"application/ogg")});
49 if (IncidenceEditorNG::EditorConfig::instance()->defaultAudioFileReminders()) {
50 mUi->mSoundFile->setUrl(IncidenceEditorNG::EditorConfig::instance()->audioFilePath());
56AlarmDialog::~AlarmDialog()
71 int beforeafterpos = 0;
73 if (alarm->hasEndOffset()) {
75 offset = alarm->endOffset().asSeconds();
78 offset = alarm->startOffset().asSeconds();
86 mUi->mBeforeAfter->setCurrentIndex(beforeafterpos);
89 int useoffset = offset;
91 if (offset % (24 * 60) == 0 && offset > 0) {
92 useoffset = offset / (24 * 60);
93 mUi->mOffsetUnit->setCurrentIndex(2);
94 }
else if (offset % 60 == 0 && offset > 0) {
95 useoffset = offset / 60;
96 mUi->mOffsetUnit->setCurrentIndex(1);
99 mUi->mOffsetUnit->setCurrentIndex(0);
101 mUi->mAlarmOffset->setValue(useoffset);
104 mUi->mRepeats->setChecked(alarm->repeatCount() > 0);
105 if (alarm->repeatCount() > 0) {
106 mUi->mRepeatCount->setValue(alarm->repeatCount());
107 mUi->mRepeatInterval->setValue(alarm->snoozeTime().asSeconds() / 60);
111 switch (alarm->type()) {
113 mUi->mTypeCombo->setCurrentIndex(1);
122 mUi->mTypeCombo->setCurrentIndex(0);
123 mUi->mDisplayText->setPlainText(alarm->text());
127 mUi->mTypeStack->setCurrentIndex(
id);
128 if (alarm->audioFile().isEmpty() && IncidenceEditorNG::EditorConfig::instance()->defaultAudioFileReminders()) {
129 mUi->mSoundFile->setUrl(IncidenceEditorNG::EditorConfig::instance()->audioFilePath());
136 int offset = mUi->mAlarmOffset->value() * 60;
137 int offsetunit = mUi->mOffsetUnit->currentIndex();
138 if (offsetunit >= 1) {
141 if (offsetunit >= 2) {
144 if (offsetunit >= 3) {
148 const int beforeafterpos = mUi->mBeforeAfter->currentIndex();
149 if (beforeafterpos % 2 == 0) {
155 Q_ASSERT(mAllowBeginReminders || mAllowEndReminders);
161 if (!mAllowBeginReminders) {
163 }
else if (beforeafterpos == 0 || beforeafterpos == 1) {
165 }
else if (beforeafterpos == 2 || beforeafterpos == 3) {
170 if (mUi->mRepeats->isChecked()) {
171 alarm->setRepeatCount(mUi->mRepeatCount->value());
172 alarm->setSnoozeTime(mUi->mRepeatInterval->value() * 60);
174 alarm->setRepeatCount(0);
177 if (mUi->mTypeCombo->currentIndex() == 1) {
178 alarm->setAudioAlarm(mUi->mSoundFile->url().toLocalFile());
180 alarm->setDisplayAlarm(mUi->mDisplayText->toPlainText());
184void AlarmDialog::fillCombo()
189 mUi->mBeforeAfter->clear();
191 if (mAllowBeginReminders) {
192 items <<
i18n(
"Before the to-do starts") <<
i18n(
"After the to-do starts");
195 if (mAllowEndReminders) {
196 items <<
i18n(
"Before the to-do is due") <<
i18n(
"After the to-do is due");
199 if (mAllowBeginReminders) {
200 items <<
i18n(
"Before the event starts") <<
i18n(
"After the event starts");
202 if (mAllowEndReminders) {
203 items <<
i18n(
"Before the event ends") <<
i18n(
"After the event ends");
207 mUi->mBeforeAfter->clear();
208 mUi->mBeforeAfter->addItems(items);
211void AlarmDialog::setAllowBeginReminders(
bool allow)
213 mAllowBeginReminders = allow;
217void AlarmDialog::setAllowEndReminders(
bool allow)
219 mAllowEndReminders = allow;
223void AlarmDialog::setOffset(
int offset)
225 Q_ASSERT(offset > 0);
226 mUi->mAlarmOffset->setValue(offset);
229void AlarmDialog::setUnit(Unit unit)
231 mUi->mOffsetUnit->setCurrentIndex(unit);
234void AlarmDialog::setWhen(When when)
236 Q_ASSERT(when <= mUi->mBeforeAfter->count());
237 mUi->mBeforeAfter->setCurrentIndex(when);
240#include "moc_alarmdialog.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QUrl fromLocalFile(const QString &localFile)