Commit 9aec20bf authored by David Jarvie's avatar David Jarvie
Browse files

Add functions to initialise the date in the new alarm dialog

parent 197e44a4
Pipeline #49654 failed with stage
in 12 minutes and 39 seconds
/*
* alarmtimewidget.cpp - alarm date/time entry widget
* Program: kalarm
* SPDX-FileCopyrightText: 2001-2020 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2001-2021 David Jarvie <djarvie@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -234,13 +234,19 @@ void AlarmTimeWidget::setReadOnly(bool ro)
}
/******************************************************************************
* Select the "Time from now" radio button.
* Select the "Time from now" radio button, or if minutes < 0, select
* 'At date/time'.
*/
void AlarmTimeWidget::selectTimeFromNow(int minutes)
{
mAfterTimeRadio->setChecked(true);
if (minutes > 0)
mDelayTimeEdit->setValue(minutes);
if (minutes >= 0)
{
mAfterTimeRadio->setChecked(true);
if (minutes > 0)
mDelayTimeEdit->setValue(minutes);
}
else
mAtTimeRadio->setChecked(true);
}
/******************************************************************************
......
/*
* alarmtimewidget.h - alarm date/time entry widget
* Program: kalarm
* SPDX-FileCopyrightText: 2001-2019 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2001-2021 David Jarvie <djarvie@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -47,6 +47,10 @@ class AlarmTimeWidget : public QFrame
void setReadOnly(bool);
bool anyTime() const { return mAnyTime; }
void enableAnyTime(bool enable);
/** Select/deselect 'Time from now' option.
* @param minutes Value to set in 'Time from now', or
* if < 0, select 'At date/time' option.
*/
void selectTimeFromNow(int minutes = 0);
void showMoreOptions(bool);
QSize sizeHint() const override { return minimumSizeHint(); }
......
......@@ -597,6 +597,11 @@ void EditAlarmDlg::setName(const QString& name)
void EditAlarmDlg::setTime(const DateTime& start)
{
mTimeWidget->setDateTime(start);
mTimeWidget->selectTimeFromNow(-1); // select 'At date/time' option
}
KADateTime EditAlarmDlg::time() const
{
return mTimeWidget->getDateTime(nullptr, false, false);
}
void EditAlarmDlg::setRecurrence(const KARecurrence& recur, const KCalendarCore::Duration& subRepeatInterval, int subRepeatCount)
{
......
......@@ -62,9 +62,16 @@ public:
// Methods to initialise values in the New Alarm dialogue.
void setName(const QString&);
// N.B. setTime() must be called first to set the date-only characteristic,
// followed by setRecurrence() if applicable.
/** Set the start date/time for the alarm.
* N.B. setTime() must be called first to set the date-only characteristic,
* followed by setRecurrence() if applicable.
*/
void setTime(const DateTime&); // must be called first to set date-only value
/** Return the start date/time for the alarm. */
KADateTime time() const;
void setRecurrence(const KARecurrence&, const KCalendarCore::Duration& subRepeatInterval, int subRepeatCount);
void setRepeatAtLogin();
virtual void setAction(KAEvent::SubAction, const AlarmText& = AlarmText()) = 0;
......
......@@ -1047,10 +1047,14 @@ void displayKOrgUpdateError(QWidget* parent, UpdateError code, const UpdateResul
* Execute a New Alarm dialog for the specified alarm type.
*/
void editNewAlarm(EditAlarmDlg::Type type, QWidget* parent)
{
editNewAlarm(type, QDate(), parent);
}
void editNewAlarm(EditAlarmDlg::Type type, const QDate& startDate, QWidget* parent)
{
EditAlarmDlg* editDlg = EditAlarmDlg::create(false, type, parent);
if (editDlg)
execNewAlarmDlg(editDlg);
execNewAlarmDlg(editDlg, startDate);
}
/******************************************************************************
......@@ -1092,17 +1096,28 @@ void editNewAlarm(KAEvent::SubAction action, QWidget* parent, const AlarmText* t
* event, or setting the action and text.
*/
void editNewAlarm(const KAEvent& preset, QWidget* parent)
{
editNewAlarm(preset, QDate(), parent);
}
void editNewAlarm(const KAEvent& preset, const QDate& startDate, QWidget* parent)
{
EditAlarmDlg* editDlg = EditAlarmDlg::create(false, preset, true, parent);
if (editDlg)
execNewAlarmDlg(editDlg);
execNewAlarmDlg(editDlg, startDate);
}
/******************************************************************************
* Common code for editNewAlarm() variants.
*/
void execNewAlarmDlg(EditAlarmDlg* editDlg)
void execNewAlarmDlg(EditAlarmDlg* editDlg, const QDate& startDate)
{
if (startDate.isValid())
{
KADateTime defaultTime = editDlg->time();
defaultTime.setDate(startDate);
editDlg->setTime(defaultTime);
}
// Create a PrivateNewAlarmDlg parented by editDlg.
// It will be deleted when editDlg is closed.
new PrivateNewAlarmDlg(editDlg);
......
......@@ -70,8 +70,10 @@ MainWindow* displayMainWindowSelected(const QString& eventId);
bool editNewAlarm(const QString& templateName, QWidget* parent = nullptr);
void editNewAlarm(EditAlarmDlg::Type, QWidget* parent = nullptr);
void editNewAlarm(EditAlarmDlg::Type, const QDate& startDate, QWidget* parent = nullptr);
void editNewAlarm(KAEvent::SubAction, QWidget* parent = nullptr, const AlarmText* = nullptr);
void editNewAlarm(const KAEvent& preset, QWidget* parent = nullptr);
void editNewAlarm(const KAEvent& preset, const QDate& startDate, QWidget* parent = nullptr);
void editAlarm(KAEvent&, QWidget* parent = nullptr);
bool editAlarmById(const EventId& eventID, QWidget* parent = nullptr);
void updateEditedAlarm(EditAlarmDlg*, KAEvent&, Resource&);
......@@ -79,7 +81,7 @@ void viewAlarm(const KAEvent&, QWidget* parent = nullptr);
void editNewTemplate(EditAlarmDlg::Type, QWidget* parent = nullptr);
void editNewTemplate(const KAEvent& preset, QWidget* parent = nullptr);
void editTemplate(KAEvent&, QWidget* parent = nullptr);
void execNewAlarmDlg(EditAlarmDlg*);
void execNewAlarmDlg(EditAlarmDlg*, const QDate& startDate = QDate());
/** Create a "New From Template" QAction */
KToggleAction* createAlarmEnableAction(QObject* parent);
QAction* createStopPlayAction(QObject* parent);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment