/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright (C) 2019 Michael Zanetti * * * * This file is part of nymea. * * * * nymea is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, version 2 of the License. * * * * nymea is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with nymea. If not, see . * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #ifndef SCRIPTALARM_H #define SCRIPTALARM_H #include #include #include class ScriptAlarm : public QObject { Q_OBJECT Q_PROPERTY(QTime time READ time WRITE setTime NOTIFY timeChanged) Q_PROPERTY(QTime endTime READ endTime WRITE setEndTime NOTIFY endTimeChanged) Q_PROPERTY(WeekDays weekDays READ weekDays WRITE setWeekDays NOTIFY weekDaysChanged) Q_PROPERTY(bool active READ active NOTIFY activeChanged) public: enum WeekDay { Monday = 0x01, Tuesday = 0x02, Wednesday = 0x04, Thursday = 0x08, Friday = 0x10, Saturday = 0x20, Sunday = 0x40, AllDays = 0xFF }; Q_ENUM(WeekDay) Q_DECLARE_FLAGS(WeekDays, WeekDay) Q_FLAG(WeekDays) explicit ScriptAlarm(QObject *parent = nullptr); QTime time() const; void setTime(const QTime &time); QTime endTime() const; void setEndTime(const QTime &endTime); WeekDays weekDays() const; void setWeekDays(const WeekDays &weekDays); bool active() const; signals: void timeChanged(); void endTimeChanged(); void weekDaysChanged(); void triggered(); void activeChanged(); protected: void timerEvent(QTimerEvent *event) override; private: WeekDay today() const; void updateActive(); private: QTime m_time; QTime m_endTime; WeekDays m_weekDays = AllDays; bool m_active = false; int m_timerId = 0; }; #endif // SCRIPTALARM_H