File indexing completed on 2024-05-12 05:13:15

0001 /*
0002   SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
0003     Author: Stephen Kelly <stephen@kdab.com>
0004 
0005   SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #pragma once
0009 
0010 #include <Akonadi/Attribute>
0011 #include <Akonadi/Item>
0012 
0013 #include <KCalendarCore/Incidence>
0014 
0015 #include <QAbstractListModel>
0016 
0017 #include <memory>
0018 
0019 namespace Akonadi
0020 {
0021 }
0022 
0023 namespace CalendarSupport
0024 {
0025 class IncidenceAttachmentModelPrivate;
0026 
0027 class IncidenceAttachmentModel : public QAbstractListModel
0028 {
0029     Q_OBJECT
0030     Q_PROPERTY(int attachmentCount READ rowCount NOTIFY rowCountChanged)
0031 
0032 public:
0033     enum Roles {
0034         AttachmentDataRole = Qt::UserRole,
0035         MimeTypeRole,
0036         AttachmentCountRole,
0037 
0038         UserRole = Qt::UserRole + 100
0039     };
0040 
0041     explicit IncidenceAttachmentModel(const QPersistentModelIndex &modelIndex, QObject *parent = nullptr);
0042 
0043     explicit IncidenceAttachmentModel(const Akonadi::Item &item, QObject *parent = nullptr);
0044 
0045     explicit IncidenceAttachmentModel(QObject *parent = nullptr);
0046 
0047     ~IncidenceAttachmentModel() override;
0048 
0049     KCalendarCore::Incidence::Ptr incidence() const;
0050 
0051     void setItem(const Akonadi::Item &item);
0052     void setIndex(const QPersistentModelIndex &modelIndex);
0053 
0054     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0055 
0056     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0057 
0058     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0059     QHash<int, QByteArray> roleNames() const override;
0060 
0061 Q_SIGNALS:
0062     void rowCountChanged();
0063 
0064 private:
0065     Q_DECLARE_PRIVATE(IncidenceAttachmentModel)
0066     std::unique_ptr<IncidenceAttachmentModelPrivate> const d_ptr;
0067 
0068     Q_PRIVATE_SLOT(d_func(), void resetModel())
0069     Q_PRIVATE_SLOT(d_func(), void itemFetched(Akonadi::Item::List))
0070 };
0071 }