File indexing completed on 2024-11-24 04:50:36
0001 // SPDX-FileCopyrightText: 2021 Claudio Cambra <claudio.cambra@gmail.com> 0002 // SPDX-License-Identifier: LGPL-2.1-or-later 0003 0004 #pragma once 0005 0006 #include <KCalendarCore/Calendar> 0007 #include <QAbstractListModel> 0008 /** 0009 * 0010 */ 0011 class AttendeeStatusModel : public QAbstractListModel 0012 { 0013 Q_OBJECT 0014 0015 public: 0016 enum Roles { 0017 DisplayNameRole = Qt::UserRole + 1, 0018 ValueRole, 0019 }; 0020 Q_ENUM(Roles) 0021 0022 explicit AttendeeStatusModel(QObject *parent = nullptr); 0023 ~AttendeeStatusModel() override = default; 0024 0025 QVariant data(const QModelIndex &idx, int role) const override; 0026 QHash<int, QByteArray> roleNames() const override; 0027 int rowCount(const QModelIndex &parent = {}) const override; 0028 0029 private: 0030 QHash<int, QString> m_status; 0031 }; 0032 0033 class AttendeesModel : public QAbstractListModel 0034 { 0035 Q_OBJECT 0036 Q_PROPERTY(KCalendarCore::Incidence::Ptr incidencePtr READ incidencePtr WRITE setIncidencePtr NOTIFY incidencePtrChanged) 0037 Q_PROPERTY(KCalendarCore::Attendee::List attendees READ attendees NOTIFY attendeesChanged) 0038 Q_PROPERTY(AttendeeStatusModel *attendeeStatusModel READ attendeeStatusModel NOTIFY attendeeStatusModelChanged) 0039 Q_PROPERTY(QList<qint64> attendeesAkonadiIds READ attendeesAkonadiIds NOTIFY attendeesAkonadiIdsChanged) 0040 0041 public: 0042 enum Roles { 0043 CuTypeRole = Qt::UserRole + 1, 0044 DelegateRole, 0045 DelegatorRole, 0046 EmailRole, 0047 FullNameRole, 0048 IsNullRole, 0049 NameRole, 0050 RoleRole, 0051 RSVPRole, 0052 StatusRole, 0053 UidRole 0054 }; 0055 Q_ENUM(Roles) 0056 0057 explicit AttendeesModel(QObject *parent = nullptr, KCalendarCore::Incidence::Ptr incidencePtr = nullptr); 0058 ~AttendeesModel() override = default; 0059 0060 KCalendarCore::Incidence::Ptr incidencePtr() const; 0061 void setIncidencePtr(const KCalendarCore::Incidence::Ptr incidence); 0062 KCalendarCore::Attendee::List attendees() const; 0063 void updateAkonadiContactIds(); 0064 AttendeeStatusModel *attendeeStatusModel(); 0065 QList<qint64> attendeesAkonadiIds() const; 0066 0067 QVariant data(const QModelIndex &idx, int role) const override; 0068 bool setData(const QModelIndex &idx, const QVariant &value, int role) override; 0069 QHash<int, QByteArray> roleNames() const override; 0070 int rowCount(const QModelIndex &parent = {}) const override; 0071 0072 Q_INVOKABLE void addAttendee(qint64 itemId = qint64(), const QString &email = QString()); 0073 Q_INVOKABLE void deleteAttendee(int row); 0074 Q_INVOKABLE void deleteAttendeeFromAkonadiId(qint64 itemId); 0075 0076 Q_SIGNALS: 0077 void incidencePtrChanged(); 0078 void attendeesChanged(); 0079 void attendeeStatusModelChanged(); 0080 void attendeesAkonadiIdsChanged(); 0081 0082 private: 0083 KCalendarCore::Incidence::Ptr m_incidence; 0084 AttendeeStatusModel m_attendeeStatusModel; 0085 QList<qint64> m_attendeesAkonadiIds; 0086 QVariantMap m_dataRoles; 0087 };