File indexing completed on 2024-05-05 05:28:18

0001 /*
0002  * SPDX-FileCopyrightText: 2019 Dimitris Kardarakos <dimkard@posteo.net>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 #ifndef CALALARMCLIENT_H
0008 #define CALALARMCLIENT_H
0009 
0010 #include <QTimer>
0011 #include <QDateTime>
0012 
0013 class WakeupBackend;
0014 class AlarmsModel;
0015 class NotificationHandler;
0016 class WakeupManager;
0017 /**
0018  * @brief Client that orchestrates the parsing of calendars and the display of notifications for event alarms. It exposes a D-Bus Interface containing a set of callable methods.
0019  *
0020  */
0021 class CalAlarmClient : public QObject
0022 {
0023     Q_OBJECT
0024     Q_CLASSINFO("D-Bus Interface", "org.kde.calindac")
0025 
0026 public:
0027     explicit CalAlarmClient(QObject *parent = nullptr);
0028     ~CalAlarmClient() override;
0029 
0030     // DBUS interface
0031     /**
0032      * @brief Quits the application
0033      *
0034      */
0035     Q_SCRIPTABLE void quit();
0036 
0037     /**
0038      * @brief Checks the calendars for event alarms
0039      *
0040      */
0041     Q_SCRIPTABLE void forceAlarmCheck();
0042 
0043     /**
0044      * @return The date time of the last check done for event alarms
0045      */
0046     Q_SCRIPTABLE QString dumpLastCheck() const;
0047 
0048     /**
0049      * @return The list of today's event alarms
0050      */
0051     Q_SCRIPTABLE QStringList dumpAlarms() const;
0052 
0053     /**
0054      * @return Schedule alarm check
0055      */
0056     Q_SCRIPTABLE void scheduleAlarmCheck();
0057 
0058     /**
0059      * @return The method that should be triggered by the wakeup backend
0060      */
0061     void wakeupCallback();
0062 private Q_SLOTS:
0063     void setupShceduler(const bool wakeupManagerActive);
0064 private:
0065     QString alarmText(const QString &uid) const;
0066     void checkAlarms();
0067     void saveLastCheckTime();
0068     void saveCheckInterval();
0069     void saveSuspendSeconds();
0070     void restoreSuspendedFromConfig();
0071     void flushSuspendedToConfig();
0072     QStringList calendarFileList() const;
0073 
0074     AlarmsModel *m_alarms_model;
0075     QDateTime m_last_check;
0076     QTimer m_check_timer;
0077     NotificationHandler *m_notification_handler;
0078     int m_check_interval;
0079     int m_suspend_seconds;
0080     WakeupManager *m_wakeup_manager;
0081 };
0082 #endif