File indexing completed on 2024-04-14 15:05:45

0001 // SPDX-FileCopyrightText: 2021 kaniini <https://git.pleroma.social/kaniini>
0002 // SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu>
0003 // SPDX-License-Identifier: GPL-3.0-only
0004 
0005 #pragma once
0006 
0007 #include <QAbstractListModel>
0008 #include <memory>
0009 
0010 #include "timeline/post.h"
0011 #include "posteditorbackend.h"
0012 
0013 class QTimer;
0014 class AbstractAccount;
0015 
0016 class AttachmentEditorModel : public QAbstractListModel
0017 {
0018     Q_OBJECT
0019     Q_PROPERTY(int count READ count NOTIFY countChanged)
0020 public:
0021     explicit AttachmentEditorModel(QObject *parent, AbstractAccount *account);
0022 
0023     enum ExtraRole {
0024         PreviewRole = Qt::UserRole + 1,
0025         DescriptionRole,
0026     };
0027 
0028     int count() const;
0029 
0030     Q_INVOKABLE int rowCount(const QModelIndex &parent = {}) const override;
0031     QVariant data(const QModelIndex &index, int role) const override;
0032     QHash<int, QByteArray> roleNames() const override;
0033     const QVector<Attachment *> &attachments() const;
0034 
0035 public Q_SLOTS:
0036     QNetworkReply *append(const QUrl &fileName);
0037     void appendExisting(Attachment *attachment);
0038     void removeAttachment(int row);
0039     void setDescription(int row, const QString &description);
0040 
0041 Q_SIGNALS:
0042     void postChanged();
0043     void countChanged();
0044 
0045 private:
0046     QVector<Attachment *> m_attachments;
0047     QHash<QString, QTimer *> m_updateTimers;
0048     AbstractAccount *m_account;
0049 };