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 #include <QMimeDatabase> 0009 0010 class AttachmentsModel : public QAbstractListModel 0011 { 0012 Q_OBJECT 0013 Q_PROPERTY(KCalendarCore::Incidence::Ptr incidencePtr READ incidencePtr WRITE setIncidencePtr NOTIFY incidencePtrChanged) 0014 Q_PROPERTY(KCalendarCore::Attachment::List attachments READ attachments NOTIFY attachmentsChanged) 0015 Q_PROPERTY(QVariantMap dataroles READ dataroles CONSTANT) 0016 0017 public: 0018 enum Roles { 0019 AttachmentRole = Qt::UserRole + 1, 0020 LabelRole, 0021 MimeTypeRole, 0022 IconNameRole, 0023 DataRole, 0024 SizeRole, 0025 URIRole, 0026 }; 0027 Q_ENUM(Roles) 0028 0029 explicit AttachmentsModel(QObject *parent = nullptr, KCalendarCore::Incidence::Ptr incidencePtr = nullptr); 0030 ~AttachmentsModel() override = default; 0031 0032 KCalendarCore::Incidence::Ptr incidencePtr(); 0033 void setIncidencePtr(KCalendarCore::Incidence::Ptr incidence); 0034 KCalendarCore::Attachment::List attachments(); 0035 QVariantMap dataroles(); 0036 0037 QVariant data(const QModelIndex &idx, int role) const override; 0038 QHash<int, QByteArray> roleNames() const override; 0039 int rowCount(const QModelIndex &parent = {}) const override; 0040 0041 Q_INVOKABLE void addAttachment(const QString &uri); 0042 Q_INVOKABLE void deleteAttachment(const QString &uri); 0043 0044 Q_SIGNALS: 0045 void incidencePtrChanged(); 0046 void attachmentsChanged(); 0047 0048 private: 0049 KCalendarCore::Incidence::Ptr m_incidence; 0050 QVariantMap m_dataRoles; 0051 QMimeDatabase m_mimeDb; 0052 };