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.
53 lines
1.4 KiB
53 lines
1.4 KiB
#ifndef MEMBERLISTMODEL_H |
|
#define MEMBERLISTMODEL_H |
|
|
|
#include <QAbstractListModel> |
|
#include <QColor> |
|
#include <QMap> |
|
#include <QString> |
|
#include <QIcon> |
|
#include <QPixmap> |
|
#include <QTimer> |
|
#include <stdint.h> |
|
|
|
struct MemberListItem { |
|
quint64 nodeId = 0; |
|
bool online = false; |
|
bool isSelf = false; |
|
QPixmap avatar; |
|
QString name; |
|
int rtt = -1; |
|
int natType = -1; |
|
uint8_t flags = 0; |
|
}; |
|
|
|
class MemberListModel : public QAbstractListModel { |
|
Q_OBJECT |
|
public: |
|
explicit MemberListModel(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, bool isOwner); |
|
void refresh(); |
|
void refreshRtt(); |
|
quint64 nodeIdAt(int row) const; |
|
|
|
/* Called from bridge callbacks (GUI thread) */ |
|
void onMemberList(const QString& chId, int count, const uint8_t* data, int dataLen); |
|
void onMemberUpdated(const QString& chId, const uint8_t* data); |
|
void onMemberRemoved(const QString& chId, uint64_t nodeId); |
|
|
|
private: |
|
void loadBatch(int from, int count); |
|
QPixmap makeAvatar(QColor color, QChar letter) const; |
|
|
|
QString m_channelId; |
|
bool m_isOwner = false; |
|
int m_totalCount = 0; |
|
mutable QMap<int, MemberListItem> m_cache; |
|
QTimer* m_rttTimer; |
|
}; |
|
|
|
#endif
|
|
|