File indexing completed on 2024-04-21 04:59:52

0001 /*
0002    SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "attachments/file.h"
0010 #include "attachments/fileattachments.h"
0011 #include "libruqolacore_export.h"
0012 #include <QAbstractListModel>
0013 class RocketChatAccount;
0014 class LIBRUQOLACORE_EXPORT FilesForRoomModel : public QAbstractListModel
0015 {
0016     Q_OBJECT
0017 public:
0018     enum UserRoles {
0019         FileName = Qt::UserRole + 1,
0020         FilePointer,
0021         UserId,
0022         Description,
0023         Url,
0024         MimeType,
0025         CanBeDeleted,
0026         FileId,
0027         TimeStamp,
0028         UserName,
0029         SortByTimeStamp,
0030         Complete,
0031         TypeGroup,
0032     };
0033     Q_ENUM(UserRoles)
0034 
0035     explicit FilesForRoomModel(RocketChatAccount *account = nullptr, QObject *parent = nullptr);
0036     ~FilesForRoomModel() override;
0037 
0038     [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0039     [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
0040 
0041     void setFiles(const QVector<File> &files);
0042 
0043     FileAttachments *fileAttachments() const;
0044 
0045     [[nodiscard]] QString roomId() const;
0046     void setRoomId(const QString &roomId);
0047 
0048     void parseFileAttachments(const QJsonObject &fileAttachmentsObj, const QString &roomId);
0049     void addMoreFileAttachments(const QJsonObject &fileAttachmentsObj);
0050     void initialize();
0051     [[nodiscard]] int total() const;
0052 
0053     [[nodiscard]] bool hasFullList() const;
0054     void setHasFullList(bool state);
0055 
0056     [[nodiscard]] bool loadMoreFilesInProgress() const;
0057     void setLoadMoreFilesInProgress(bool loadMoreFilesInProgress);
0058 
0059     void clear();
0060 
0061 Q_SIGNALS:
0062     void hasFullListChanged();
0063     void totalChanged();
0064     void loadingInProgressChanged();
0065 
0066 private:
0067     LIBRUQOLACORE_NO_EXPORT void checkFullList();
0068     QString mRoomId;
0069     bool mHasFullList = false;
0070     bool mLoadMoreFilesInProgress = false;
0071     FileAttachments *const mFileAttachments;
0072     RocketChatAccount *const mRochetChantAccount;
0073 };