Files
wino-mail-dtkqt/src/ui/models/EmailListModel.h
T

75 lines
2.3 KiB
C++
Raw Normal View History

#ifndef EMAILLISTMODEL_H
#define EMAILLISTMODEL_H
#include <QAbstractTableModel>
#include <QHash>
#include <QByteArray>
#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<int, QByteArray> 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();
2026-08-23 14:49:58 +02:00
// 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<MailItem>& 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<MailItem> m_emails;
int m_folderId{-1}; // -1 means all folders
2026-08-23 14:49:58 +02:00
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