Commit 3e901bc2 authored by Boris Petrov's avatar Boris Petrov 💾
Browse files

Simplification of the command at timeout feature

The command is now set during the creation
of a timer and can't be changed after that.
parent 338d3ba8
/*
* Copyright 2021 Devin Lin <espidev@gmail.com>
* Copyright 2021 Boris Petrov <boris.v.petrov@protonmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -14,6 +15,7 @@ Kirigami.FormLayout {
id: form
property alias name: label.text
property alias commandTimeout: commandTimeoutField.text
function setDuration(duration) {
hours = duration / 60 / 60;
......@@ -138,6 +140,13 @@ Kirigami.FormLayout {
text: i18n("New Timer") // default
focus: true
}
TextField {
id: commandTimeoutField
Kirigami.FormData.label: i18n("<b>Command at timeout:</b>")
font.family: "Monospace"
focus: true
placeholderText: i18n("Optional")
}
RowLayout {
Layout.alignment: Qt.AlignHCenter
spacing: Kirigami.Units.smallSpacing
......@@ -175,7 +184,7 @@ Kirigami.FormLayout {
Button {
text: showDelete ? "Delete" : preset.presetName
onClicked: showDelete ? TimerPresetModel.deletePreset(index) : loader.createTimer(timerForm.getDuration(), timerForm.name) & close();
onClicked: showDelete ? TimerPresetModel.deletePreset(index) : loader.createTimer(timerForm.getDuration(), timerForm.name, timerForm.commandTimeout) & close();
}
}
......
/*
* Copyright 2021 Devin Lin <espidev@gmail.com>
* Copyright 2021 Boris Petrov <boris.v.petrov@protonmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -14,8 +15,8 @@ Loader {
id: loader
sourceComponent: Kirigami.Settings.isMobile ? mobileTimerForm : desktopTimerForm
function createTimer(duration, label) {
timerModel.addNew(duration, label);
function createTimer(duration, label, commandTimeout) {
timerModel.addNew(duration, label, commandTimeout);
}
property bool showPresets: false
......@@ -81,7 +82,7 @@ Loader {
icon.name: "dialog-ok"
text: i18n("Done")
onClicked: {
loader.createTimer(timerForm.getDuration(), timerForm.name);
loader.createTimer(timerForm.getDuration(), timerForm.name, timerForm.commandTimeout);
close();
}
}
......@@ -139,7 +140,7 @@ Loader {
icon.name: "dialog-ok"
text: i18n("Done")
onClicked: {
loader.createTimer(timerForm.getDuration(), timerForm.name);
loader.createTimer(timerForm.getDuration(), timerForm.name, timerForm.commandTimeout);
close();
}
}
......
/*
* Copyright 2020 Devin Lin <espidev@gmail.com>
* Copyright 2021 Boris Petrov <boris.v.petrov@protonmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -185,25 +186,17 @@ Kirigami.ScrollablePage {
RowLayout {
anchors.left: parent.left
anchors.right: parent.right
ToolButton {
icon.name: "dialog-scripts"
display: AbstractButton.IconOnly
text: i18n("Command")
checked: timerDelegate && timerDelegate.isCommandTimeout
onClicked: timerDelegate.toggleIsCommandTimeout()
ToolTip.visible: hovered && text.length > 0
ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
ToolTip.text: text
Layout.alignment: Qt.AlignLeft
Kirigami.Icon {
source: "dialog-scripts"
visible: timerDelegate && timerDelegate.commandTimeout.length > 0
}
TextField {
Layout.fillWidth: true
enabled: timerDelegate && timerDelegate.isCommandTimeout
focus: true
Label {
visible: timerDelegate && timerDelegate.commandTimeout.length > 0
font.family: "Monospace"
onEditingFinished: timerDelegate.saveCommandTimeout(text)
Layout.fillWidth: true
text: timerDelegate.commandTimeout
placeholderText: "Command to execute at timeout…"
color: timerDelegate && Kirigami.Theme.disabledTextColor
}
}
}
......
/*
* Copyright 2020 Devin Lin <espidev@gmail.com>
* Copyright 2019 Nick Reitemeyer <nick.reitemeyer@web.de>
* Copyright 2021 Boris Petrov <boris.v.petrov@protonmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -24,7 +25,7 @@ Kirigami.Page {
property int elapsed: timer == null ? 0 : timer.elapsed
property int duration: timer == null ? 0 : timer.length
property bool running: timer == null ? 0 : timer.running
property bool isCommandTimeout: timer == null ? 0 : timer.isCommandTimeout
property bool isCommandTimeout: timer == null ? 0 : timer.commandTimeout.length > 0
// keyboard controls
Keys.onSpacePressed: timer.toggleRunning();
......@@ -51,13 +52,6 @@ Kirigami.Page {
pageStack.pop();
timerModel.remove(timerIndex);
}
},
Kirigami.Action {
icon.name: "dialog-scripts"
text: i18n("Command")
checkable: true
checked: isCommandTimeout
onTriggered: timer.toggleIsCommandTimeout();
}
]
}
......@@ -67,4 +61,18 @@ Kirigami.Page {
timerElapsed: elapsed
timerRunning: running
}
RowLayout {
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
Kirigami.Icon {
source: "dialog-scripts"
visible: isCommandTimeout
}
Kirigami.Label {
visible: isCommandTimeout
font.family: "Monospace"
text: timerDelegate.commandTimeout
color: timerDelegate && Kirigami.Theme.disabledTextColor
}
}
}
/*
* Copyright 2020 Han Young <hanyoung@protonmail.com>
* Copyright 2020 Devin Lin <espidev@gmail.com>
* Copyright 2021 Boris Petrov <boris.v.petrov@protonmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -24,13 +25,11 @@ Timer::Timer(QString uuid, bool justCreated)
m_length = m_interface->length();
m_running = m_interface->running();
m_elapsed = m_interface->elapsed();
m_isCommandTimeout = m_interface->isCommandTimeout();
m_commandTimeout = m_interface->commandTimeout();
connect(m_interface, &OrgKdeKclockTimerInterface::lengthChanged, this, &Timer::updateLength);
connect(m_interface, &OrgKdeKclockTimerInterface::labelChanged, this, &Timer::updateLabel);
connect(m_interface, &OrgKdeKclockTimerInterface::runningChanged, this, &Timer::updateRunning);
connect(m_interface, &OrgKdeKclockTimerInterface::isCommandTimeoutChanged, this, &Timer::updateIsCommandTimeout);
connect(m_interface, &OrgKdeKclockTimerInterface::commandTimeoutChanged, this, &Timer::updateCommandTimeout);
connect(m_interface, &OrgKdeKclockTimerInterface::runningChanged, this, &Timer::updateRunning);
updateRunning(); // start animation
}
......@@ -41,16 +40,6 @@ void Timer::toggleRunning()
m_interface->toggleRunning();
}
void Timer::toggleIsCommandTimeout()
{
m_interface->toggleIsCommandTimeout();
}
void Timer::saveCommandTimeout(QString command)
{
m_interface->saveCommandTimeout(command);
}
void Timer::reset()
{
m_interface->reset();
......@@ -89,12 +78,6 @@ void Timer::updateRunning()
Q_EMIT elapsedChanged();
}
void Timer::updateIsCommandTimeout()
{
m_isCommandTimeout = m_interface->isCommandTimeout();
Q_EMIT propertyChanged();
}
void Timer::updateCommandTimeout()
{
m_commandTimeout = m_interface->commandTimeout();
......
/*
* Copyright 2020 Han Young <hanyoung@protonmail.com>
* Copyright 2020 Devin Lin <espidev@gmail.com>
* Copyright 2021 Boris Petrov <boris.v.petrov@protonmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -22,10 +23,9 @@ class Timer : public QObject
Q_PROPERTY(QString lengthPretty READ lengthPretty NOTIFY propertyChanged)
Q_PROPERTY(QString elapsedPretty READ elapsedPretty NOTIFY elapsedChanged)
Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY propertyChanged)
Q_PROPERTY(QString commandTimeout READ commandTimeout WRITE setCommandTimeout NOTIFY propertyChanged)
Q_PROPERTY(bool running READ running NOTIFY propertyChanged)
Q_PROPERTY(bool justCreated MEMBER m_justCreated NOTIFY propertyChanged)
Q_PROPERTY(bool isCommandTimeout READ isCommandTimeout NOTIFY propertyChanged)
Q_PROPERTY(QString commandTimeout READ commandTimeout NOTIFY propertyChanged)
public:
Timer();
......@@ -35,8 +35,6 @@ public:
return m_uuid;
};
Q_INVOKABLE void toggleRunning();
Q_INVOKABLE void toggleIsCommandTimeout();
Q_INVOKABLE void saveCommandTimeout(QString);
Q_INVOKABLE void reset();
Q_INVOKABLE void addMinute();
......@@ -70,17 +68,17 @@ public:
{
m_interface->setLabel(label);
}
const bool &running() const
const QString &commandTimeout() const
{
return m_running;
return m_commandTimeout;
}
const bool &isCommandTimeout() const
void setCommandTimeout(QString commandTimeout)
{
return m_isCommandTimeout;
m_interface->setCommandTimeout(commandTimeout);
}
const QString &commandTimeout() const
const bool &running() const
{
return m_commandTimeout;
return m_running;
}
signals:
......@@ -89,18 +87,16 @@ signals:
private slots:
void updateLength();
void updateLabel();
void updateRunning();
void updateIsCommandTimeout();
void updateCommandTimeout();
void updateRunning();
private:
void animation(bool start);
int m_length, m_elapsed; // seconds
QString m_label;
bool m_running;
bool m_isCommandTimeout;
QString m_commandTimeout;
bool m_running;
bool m_justCreated;
QUuid m_uuid;
......
/*
* Copyright 2020 Han Young <hanyoung@protonmail.com>
* Copyright 2020 Devin Lin <espidev@gmail.com>
* Copyright 2021 Boris Petrov <boris.v.petrov@protonmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -74,9 +75,9 @@ QVariant TimerModel::data(const QModelIndex &index, int role) const
return QVariant();
}
void TimerModel::addTimer(int length, QString label, bool running)
void TimerModel::addTimer(int length, QString label, QString commandTimeout, bool running)
{
m_interface->addTimer(length, label, running);
m_interface->addTimer(length, label, commandTimeout, running);
}
void TimerModel::remove(int index)
......
/*
* Copyright 2020 Han Young <hanyoung@protonmail.com>
* Copyright 2020 Devin Lin <espidev@gmail.com>
* Copyright 2021 Boris Petrov <boris.v.petrov@protonmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -31,9 +32,9 @@ public:
return singleton;
}
Q_INVOKABLE void addNew(int length, QString label)
Q_INVOKABLE void addNew(int length, QString label, QString commandTimeout)
{
this->addTimer(length, label, false);
this->addTimer(length, label, commandTimeout, false);
};
Q_INVOKABLE void remove(int index);
Q_INVOKABLE int count();
......@@ -46,7 +47,7 @@ Q_SIGNALS:
private Q_SLOTS:
void addTimer(QString uuid); // remote add, always justCreated
void addTimer(int length = 300, QString label = i18n("New timer"), bool running = false);
void addTimer(int length = 300, QString label = i18n("New timer"), QString commandTimeout = "", bool running = false);
void removeTimer(QString uuid);
private:
......
/*
* Copyright 2020 Han Young <hanyoung@protonmail.com>
* Copyright 2021 Boris Petrov <boris.v.petrov@protonmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -18,10 +19,11 @@
/* ~ Timer ~ */
Timer::Timer(int length, QString label, bool running)
Timer::Timer(int length, QString label, QString commandTimeout, bool running)
: m_uuid(QUuid::createUuid())
, m_length(length)
, m_label(label)
, m_commandTimeout(commandTimeout)
{
connect(&Utilities::instance(), &Utilities::wakeup, this, &Timer::timeUp);
connect(&Utilities::instance(), &Utilities::needsReschedule, this, &Timer::reschedule);
......@@ -40,7 +42,6 @@ Timer::Timer(const QJsonObject &obj)
m_length = obj[QStringLiteral("length")].toInt();
m_label = obj[QStringLiteral("label")].toString();
m_uuid = QUuid(obj[QStringLiteral("uuid")].toString());
m_isCommandTimeout = obj[QStringLiteral("isCommandTimeout")].toBool();
m_commandTimeout = obj[QStringLiteral("commandTimeout")].toString();
connect(&Utilities::instance(), &Utilities::wakeup, this, &Timer::timeUp);
......@@ -65,7 +66,6 @@ QJsonObject Timer::serialize()
obj[QStringLiteral("length")] = m_length;
obj[QStringLiteral("label")] = m_label;
obj[QStringLiteral("uuid")] = m_uuid.toString();
obj[QStringLiteral("isCommandTimeout")] = m_isCommandTimeout;
obj[QStringLiteral("commandTimeout")] = m_commandTimeout;
return obj;
}
......@@ -75,24 +75,6 @@ void Timer::toggleRunning()
setRunning(!m_running);
}
void Timer::toggleIsCommandTimeout()
{
m_isCommandTimeout = !m_isCommandTimeout;
Q_EMIT isCommandTimeoutChanged();
TimerModel::instance()->save();
}
void Timer::saveCommandTimeout(QString command)
{
m_commandTimeout = command;
Q_EMIT commandTimeoutChanged();
TimerModel::instance()->save();
}
void Timer::reset()
{
setRunning(false);
......@@ -106,7 +88,7 @@ void Timer::timeUp(int cookie)
if (cookie == m_cookie) {
this->sendNotification();
this->m_cookie = -1;
if (m_isCommandTimeout) {
if (m_commandTimeout != "") {
QProcess *process = new QProcess;
process->start(m_commandTimeout);
}
......
/*
* Copyright 2020 Han Young <hanyoung@protonmail.com>
* Copyright 2021 Boris Petrov <boris.v.petrov@protonmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -19,20 +20,17 @@ class Timer : public QObject
Q_CLASSINFO("D-Bus Interface", "org.kde.kclock.Timer")
Q_PROPERTY(int length READ length WRITE setLength NOTIFY lengthChanged)
Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged)
Q_PROPERTY(QString commandTimeout READ commandTimeout WRITE setCommandTimeout NOTIFY commandTimeoutChanged)
Q_PROPERTY(bool running READ running NOTIFY runningChanged)
Q_PROPERTY(bool isCommandTimeout READ isCommandTimeout NOTIFY isCommandTimeoutChanged)
Q_PROPERTY(QString commandTimeout READ commandTimeout NOTIFY commandTimeoutChanged)
public:
explicit Timer(int length = 0, QString label = QStringLiteral(), bool running = false);
explicit Timer(int length = 0, QString label = QStringLiteral(), QString commandTimeout = QStringLiteral(), bool running = false);
explicit Timer(const QJsonObject &obj);
~Timer();
QJsonObject serialize();
Q_SCRIPTABLE void toggleRunning();
Q_SCRIPTABLE void toggleIsCommandTimeout();
Q_SCRIPTABLE void saveCommandTimeout(QString);
Q_SCRIPTABLE void reset();
Q_SCRIPTABLE int elapsed() const
{
......@@ -69,24 +67,25 @@ public:
Q_EMIT labelChanged();
TimerModel::instance()->save();
}
const bool &running() const
const QString &commandTimeout() const
{
return m_running;
return m_commandTimeout;
}
const bool &isCommandTimeout() const
void setCommandTimeout(QString commandTiemout)
{
return m_isCommandTimeout;
m_commandTimeout = commandTiemout;
Q_EMIT commandTimeoutChanged();
TimerModel::instance()->save();
}
const QString &commandTimeout() const
const bool &running() const
{
return m_commandTimeout;
return m_running;
}
Q_SIGNALS:
Q_SCRIPTABLE void lengthChanged();
Q_SCRIPTABLE void labelChanged();
Q_SCRIPTABLE void runningChanged();
Q_SCRIPTABLE void isCommandTimeoutChanged();
Q_SCRIPTABLE void commandTimeoutChanged();
private Q_SLOTS:
void timeUp(int cookie);
......@@ -101,9 +100,8 @@ private:
int m_hasElapsed = 0; // time has elapsed till stop, only be updated if stopped or finished
int m_cookie = -1;
QString m_label;
QString m_commandTimeout;
bool m_running = false;
bool m_isCommandTimeout = false;
QString m_commandTimeout = "";
};
#endif // KCLOCKD_TIMER_H
/*
* Copyright 2020 Devin Lin <espidev@gmail.com>
* Copyright 2021 Boris Petrov <boris.v.petrov@protonmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -54,9 +55,9 @@ void TimerModel::save()
group.sync();
}
void TimerModel::addTimer(int length, QString label, bool running)
void TimerModel::addTimer(int length, QString label, QString commandTimeout, bool running)
{
auto *timer = new Timer(length, label, running);
auto *timer = new Timer(length, label, commandTimeout, running);
m_timerList.append(timer);
save();
......
/*
* Copyright 2020 Devin Lin <espidev@gmail.com>
* Copyright 2021 Boris Petrov <boris.v.petrov@protonmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -25,7 +26,7 @@ public:
void load();
void save();
Q_SCRIPTABLE void addTimer(int length, QString label, bool running);
Q_SCRIPTABLE void addTimer(int length, QString label, QString commandTimeout, bool running);
Q_SCRIPTABLE void removeTimer(QString uuid);
Q_SIGNALS:
Q_SCRIPTABLE void timerAdded(QString);
......
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