File indexing completed on 2025-01-05 04:47:40

0001 /*
0002   SPDX-FileCopyrightText: 2010 Casey Link <unnamedrambler@gmail.com>
0003   SPDX-FileCopyrightText: 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
0004 
0005   SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #pragma once
0009 
0010 #include "calendarsupport_export.h"
0011 
0012 #include "freebusyitem.h"
0013 
0014 #include <QAbstractItemModel>
0015 #include <QTimer>
0016 
0017 #include <memory>
0018 
0019 class ItemPrivateData;
0020 
0021 namespace CalendarSupport
0022 {
0023 /**
0024  * The FreeBusyItemModel is a 2-level tree structure.
0025  *
0026  * The top level parent nodes represent the freebusy items, and
0027  * the 2nd-level child nodes represent the FreeBusyPeriods of the parent
0028  * freebusy item.
0029  */
0030 class FreeBusyItemModelPrivate;
0031 class CALENDARSUPPORT_EXPORT FreeBusyItemModel : public QAbstractItemModel
0032 {
0033     Q_OBJECT
0034 public:
0035     enum Roles { AttendeeRole = Qt::UserRole, FreeBusyRole, FreeBusyPeriodRole };
0036 
0037     explicit FreeBusyItemModel(QObject *parent = nullptr);
0038     ~FreeBusyItemModel() override;
0039 
0040     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0041     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0042     int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0043     QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override;
0044     QModelIndex parent(const QModelIndex &child) const override;
0045     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0046 
0047     void addItem(const FreeBusyItem::Ptr &freebusy);
0048 
0049     void clear();
0050     void removeAttendee(const KCalendarCore::Attendee &attendee);
0051     void removeItem(const FreeBusyItem::Ptr &freebusy);
0052     void removeRow(int row);
0053 
0054     [[nodiscard]] bool containsAttendee(const KCalendarCore::Attendee &attendee);
0055 
0056     /**
0057      * Queues a reload of free/busy data.
0058      * All current attendees will have their free/busy data
0059      * redownloaded from Akonadi.
0060      */
0061     void triggerReload();
0062 
0063     /**
0064      * cancel reloading
0065      */
0066     void cancelReload();
0067 
0068     /**
0069      * Reload FB items
0070      */
0071     void reload();
0072 
0073 public Q_SLOTS:
0074     void slotInsertFreeBusy(const KCalendarCore::FreeBusy::Ptr &fb, const QString &email);
0075 
0076 protected:
0077     void timerEvent(QTimerEvent *) override;
0078 
0079 private:
0080     // Only download FB if the auto-download option is set in config
0081     CALENDARSUPPORT_NO_EXPORT void autoReload();
0082 
0083     CALENDARSUPPORT_NO_EXPORT void setFreeBusyPeriods(const QModelIndex &parent, const KCalendarCore::FreeBusyPeriod::List &list);
0084     CALENDARSUPPORT_NO_EXPORT void updateFreeBusyData(const FreeBusyItem::Ptr &);
0085 
0086     std::unique_ptr<FreeBusyItemModelPrivate> const d;
0087 };
0088 }