File indexing completed on 2024-05-26 05:53:22
0001 /* 0002 * Copyright 2020 Han Young <hanyoung@protonmail.com> 0003 * Copyright 2020-2021 Devin Lin <devin@kde.org> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include "alarm.h" 0011 0012 #include <KStatusNotifierItem> 0013 #include <QObject> 0014 0015 class Alarm; 0016 0017 class AlarmModel : public QObject 0018 { 0019 Q_OBJECT 0020 Q_CLASSINFO("D-Bus Interface", "org.kde.kclock.AlarmModel") 0021 0022 public: 0023 static AlarmModel *instance(); 0024 0025 void load(); 0026 void save(); 0027 void configureWakeups(); // needs to be called to start worker thread, or configure powerdevil (called in main) 0028 0029 Q_SCRIPTABLE void removeAlarm(const QString &uuid); 0030 Q_SCRIPTABLE void addAlarm(const QString &name, int hours, int minutes, int daysOfWeek, const QString &audioPath, int ringDuration, int snoozeDuration); 0031 0032 Q_SIGNALS: 0033 Q_SCRIPTABLE void alarmAdded(const QString &uuid); 0034 Q_SCRIPTABLE void alarmRemoved(const QString &uuid); 0035 Q_SCRIPTABLE void nextAlarm(quint64 nextAlarmTimeStamp); // next alarm wakeup timestamp, or 0 if there are none 0036 0037 public Q_SLOTS: 0038 Q_SCRIPTABLE quint64 getNextAlarm(); 0039 void scheduleAlarm(); 0040 void wakeupCallback(int cookie); 0041 0042 private Q_SLOTS: 0043 void updateNotifierItem(quint64 time); // update notify icon in systemtray 0044 0045 private: 0046 explicit AlarmModel(QObject *parent = nullptr); 0047 0048 void removeAlarm(int index); 0049 void initNotifierItem(); 0050 0051 // next scheduled system wakeup for ringing alarms, in unix time 0052 quint64 m_nextAlarmTime = 0; 0053 0054 // token for system wakeup call authentication 0055 int m_cookie = -1; 0056 0057 // list of alarms that will ring on the next scheduled system wakeup 0058 QList<Alarm *> alarmsToRing; 0059 0060 // list of alarms in the model 0061 QList<Alarm *> m_alarmsList; 0062 0063 // system tray notifier item 0064 KStatusNotifierItem *m_item{nullptr}; 0065 };