Spectral/matrix/roomlistmodel.h

57 lines
1.6 KiB
C
Raw Normal View History

2018-02-28 09:10:42 +00:00
#ifndef ROOMLISTMODEL_H
#define ROOMLISTMODEL_H
2018-02-28 13:11:42 +00:00
#include <QtCore/QAbstractListModel>
2018-02-28 09:10:42 +00:00
#include "matriqueroom.h"
2018-03-14 09:11:45 +00:00
namespace QMatrixClient
{
2018-02-28 09:10:42 +00:00
class Connection;
class Room;
}
2018-03-14 09:11:45 +00:00
class RoomListModel: public QAbstractListModel
2018-02-28 13:11:42 +00:00
{
Q_OBJECT
2018-03-14 09:11:45 +00:00
Q_PROPERTY(QMatrixClient::Connection *connection READ getConnection WRITE setConnection)
2018-03-02 11:58:55 +00:00
2018-03-06 11:11:39 +00:00
public:
2018-03-14 09:11:45 +00:00
enum Roles {
HasUnreadRole = Qt::UserRole + 1,
HighlightCountRole, JoinStateRole
2018-03-06 11:11:39 +00:00
};
2018-02-28 13:11:42 +00:00
2018-03-14 09:11:45 +00:00
explicit RoomListModel(QObject* parent = nullptr);
2018-02-28 13:11:42 +00:00
2018-03-14 09:11:45 +00:00
QMatrixClient::Connection* getConnection() { return m_connection; }
void setConnection(QMatrixClient::Connection* connection);
void deleteConnection(QMatrixClient::Connection* connection);
2018-02-28 09:10:42 +00:00
2018-03-14 09:11:45 +00:00
MatriqueRoom* roomAt(QModelIndex index) const;
QModelIndex indexOf(MatriqueRoom* room) const;
2018-02-28 09:10:42 +00:00
2018-03-14 09:11:45 +00:00
QVariant data(const QModelIndex& index, int role) const override;
QHash<int, QByteArray> roleNames() const;
int rowCount(const QModelIndex& parent) const override;
2018-02-28 09:10:42 +00:00
2018-03-06 11:11:39 +00:00
private slots:
2018-03-14 09:11:45 +00:00
void displaynameChanged(MatriqueRoom* room);
void unreadMessagesChanged(MatriqueRoom* room);
2018-03-14 09:11:45 +00:00
void refresh(MatriqueRoom* room, const QVector<int>& roles = {});
void updateRoom(QMatrixClient::Room* room,
QMatrixClient::Room* prev);
void deleteRoom(QMatrixClient::Room* room);
2018-02-28 09:10:42 +00:00
2018-03-06 11:11:39 +00:00
private:
2018-03-14 09:11:45 +00:00
QMatrixClient::Connection* m_connection;
QList<MatriqueRoom*> m_rooms;
2018-03-14 09:11:45 +00:00
void doAddRoom(QMatrixClient::Room* r);
void connectRoomSignals(MatriqueRoom* room);
2018-02-28 09:10:42 +00:00
};
#endif // ROOMLISTMODEL_H