File indexing completed on 2024-04-14 05:43:43

0001 /*
0002  * SPDX-FileCopyrightText: 2020 Dimitris Kardarakos <dimkard@posteo.net>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 #ifndef ALARMSMODEL_H
0008 #define ALARMSMODEL_H
0009 
0010 #include <KCalendarCore/Alarm>
0011 #include <KCalendarCore/FileStorage>
0012 #include <QDateTime>
0013 
0014 struct FilterPeriod {
0015     QDateTime from;
0016     QDateTime to;
0017 };
0018 
0019 /**
0020  * @brief Model that serves the alarms found in a set of calendar files for a specific time period
0021  *
0022  */
0023 class AlarmsModel : public QObject
0024 {
0025     Q_OBJECT
0026 
0027 public:
0028     explicit AlarmsModel(QObject *parent = nullptr);
0029 
0030     /**
0031      * @return The start/end date time to use to look for alarms
0032      */
0033     FilterPeriod period() const;
0034 
0035     /**
0036      * @brief Set the start/end date time to look for alarms
0037      */
0038     void setPeriod(const FilterPeriod &filterPeriod);
0039 
0040     /**
0041      * @brief The list of calendar files to look for alarms into
0042      */
0043     QStringList calendarFiles() const;
0044 
0045     /**
0046      * @brief Set the list of calendar files to look for alarms into
0047      */
0048     void setCalendarFiles(const QStringList &fileList);
0049 
0050     /**
0051      * @brief List of alarms scheduled into the interval specified
0052      */
0053     KCalendarCore::Alarm::List alarms() const;
0054 
0055     /**
0056      * @brief The date time of the first alarm scheduled into the interval specified
0057      */
0058     QDateTime firstAlarmTime() const;
0059 
0060 Q_SIGNALS:
0061     void uidsChanged();
0062     void calendarsChanged();
0063     void periodChanged();
0064 
0065 private:
0066     void loadAlarms();
0067     void setCalendars();
0068     void openLoadStorages();
0069     void closeStorages();
0070     QDateTime parentStartDt(const int idx) const;
0071 
0072     QVector<KCalendarCore::Calendar::Ptr> m_calendars;
0073     QVector<KCalendarCore::FileStorage::Ptr> m_file_storages;
0074     KCalendarCore::Alarm::List m_alarms;
0075     QStringList m_calendar_files;
0076     FilterPeriod m_period;
0077 };
0078 #endif