You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.3 KiB
57 lines
1.3 KiB
#ifndef MEMBERLISTMODEL_H |
|
#define MEMBERLISTMODEL_H |
|
|
|
#include <QAbstractListModel> |
|
#include <QColor> |
|
#include <QMap> |
|
#include <QString> |
|
#include <QIcon> |
|
#include <QPixmap> |
|
|
|
class DbManager; |
|
|
|
struct MemberListItem { |
|
quint64 nodeId = 0; |
|
bool online = false; |
|
bool isSelf = false; |
|
QPixmap avatar; |
|
QString name; |
|
QString localNick; |
|
int rtt = -1; |
|
int natType = -1; |
|
}; |
|
|
|
class MemberListModel : public QAbstractListModel { |
|
Q_OBJECT |
|
public: |
|
static const int BATCH = 40; |
|
static const int MAX_CACHE = 120; |
|
|
|
explicit MemberListModel(DbManager* db, QObject* parent = nullptr); |
|
|
|
int rowCount(const QModelIndex& parent = QModelIndex()) const override; |
|
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; |
|
|
|
void setChannel(const QString& channelId); |
|
void refresh(); |
|
void refreshRtt(); |
|
quint64 nodeIdAt(int row) const; |
|
|
|
private slots: |
|
void loadPendingBatch(); |
|
|
|
private: |
|
void scheduleBatch(int centerRow) const; |
|
void loadBatch(int from, int count); |
|
void evictDistant(int centerRow); |
|
QPixmap makeAvatar(QColor color, QChar letter) const; |
|
|
|
DbManager* m_db; |
|
QString m_channelId; |
|
int m_totalCount = 0; |
|
mutable QMap<int, MemberListItem> m_cache; |
|
mutable int m_pendingFrom = -1; |
|
mutable int m_pendingCount = 0; |
|
}; |
|
|
|
#endif
|
|
|