Files
wino-mail-dtkqt/src/ui/models/FolderListModel.cpp
T

46 lines
1.2 KiB
C++
Raw Normal View History

#include "FolderListModel.h"
#include <QDebug>
FolderListModel::FolderListModel(QObject *parent)
: QAbstractListModel(parent),
m_folderDao(FolderDao::instance())
{
refresh();
}
int FolderListModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid())
return 0;
return m_folderNames.size();
}
QVariant FolderListModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() >= m_folderNames.size())
return QVariant();
if (role == FolderNameRole)
return m_folderNames.at(index.row());
else if (role == UnreadCountRole)
return m_unreadCounts.at(index.row());
return QVariant();
}
QHash<int, QByteArray> FolderListModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[FolderNameRole] = "folderName";
roles[UnreadCountRole] = "unreadCount";
return roles;
}
void FolderListModel::refresh()
{
beginResetModel();
// For now, we'll just use hardcoded folders until we implement the DAO properly
m_folderNames = {"Inbox", "Sent", "Drafts", "Trash", "Spam"};
m_unreadCounts = {5, 0, 0, 0, 0};
endResetModel();
qDebug() << "FolderListModel refreshed with" << m_folderNames.size() << "folders";
}