57 lines
1.4 KiB
C++
57 lines
1.4 KiB
C++
#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;
|
|
QPixmap avatar;
|
|
QString name;
|
|
QString localNick;
|
|
int rtt = -1; // ms (min из node_addresses, -1 если нет)
|
|
int natType = -1; // addr_type: 0=NET, 1=DIR, 2=EIM, 3=STR
|
|
};
|
|
|
|
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
|