#ifndef EMAILLISTMODEL_H #define EMAILLISTMODEL_H #include #include #include #include "../db/dao/mailitemdao.h" class EmailListModel : public QAbstractListModel { Q_OBJECT public: explicit EmailListModel(QObject *parent = nullptr); ~EmailListModel() override = default; enum EmailRoles { IdRole = Qt::UserRole + 1, SubjectRole, SenderRole, RecipientRole, DateRole, ReadRole, FlaggedRole, AttachmentsRole, FileIdRole, SizeRole, MessageIdRole, SenderInitialRole, // computed from sender ThreadIdRole, InReplyToRole, ReferencesRole, IsPinnedRole }; // QAbstractListModel interface int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QHash roleNames() const override; bool canFetchMore(const QModelIndex &parent) const override; void fetchMore(const QModelIndex &parent) override; // Set the folderId to filter emails; -1 means all folders void setFolderId(int folderId); // Refresh the model from the database based on current folderId void refresh(); // Set search filter on the model void setSearchFilter(const QString &filter); // Set filter flags void setShowUnreadOnly(bool show); void setShowFlaggedOnly(bool show); void setShowHasAttachments(bool show); // Set batch size for pagination void setBatchSize(int size) { m_batchSize = size; } // Get all emails currently in the model (after filtering) const QVector& emails() const { return m_emails; } // Total count of emails matching filters (including unloaded) int totalCount() const { return m_totalCount; } signals: void totalCountChanged(int count); private: QVector m_emails; int m_folderId{-1}; // -1 means all folders QString m_searchFilter; bool m_unreadOnly{false}; bool m_flaggedOnly{false}; bool m_hasAttachments{false}; int m_batchSize{50}; // emails per fetch int m_loadedCount{0}; // how many emails currently loaded int m_totalCount{0}; // total matching emails in DB }; #endif // EMAILLISTMODEL_H