Spectral/src/roomlistmodel.h

80 lines
1.8 KiB
C
Raw Normal View History

2018-02-28 09:10:42 +00:00
#ifndef ROOMLISTMODEL_H
#define ROOMLISTMODEL_H
#include "connection.h"
2018-08-19 06:32:18 +00:00
#include "events/roomevent.h"
#include "matriqueroom.h"
2018-08-19 06:32:18 +00:00
#include "room.h"
#include <QtCore/QAbstractListModel>
2018-02-28 09:10:42 +00:00
2018-07-29 16:04:58 +00:00
using namespace QMatrixClient;
2018-08-17 04:55:57 +00:00
class RoomType : public QObject {
Q_OBJECT
public:
enum Types {
Invited = 1,
Favorite,
Normal,
Direct,
Deprioritized,
};
REGISTER_ENUM(Types)
};
2018-07-09 02:45:26 +00:00
class RoomListModel : public QAbstractListModel {
Q_OBJECT
Q_PROPERTY(Connection* connection READ connection WRITE setConnection)
2018-03-02 11:58:55 +00:00
2018-07-09 02:45:26 +00:00
public:
enum EventRoles {
NameRole = Qt::UserRole + 1,
AvatarRole,
TopicRole,
CategoryRole,
2018-08-17 04:55:57 +00:00
UnreadCountRole,
LastEventRole,
CurrentRoomRole,
};
2018-07-09 02:45:26 +00:00
RoomListModel(QObject* parent = 0);
virtual ~RoomListModel();
2018-02-28 13:11:42 +00:00
Connection* connection() { return m_connection; }
2018-07-29 16:04:58 +00:00
void setConnection(Connection* connection);
void doResetModel();
2018-02-28 09:10:42 +00:00
Q_INVOKABLE MatriqueRoom* roomAt(int row);
2018-07-09 02:45:26 +00:00
QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const override;
Q_INVOKABLE int rowCount(
const QModelIndex& parent = QModelIndex()) const override;
2018-02-28 09:10:42 +00:00
2018-07-09 02:45:26 +00:00
QHash<int, QByteArray> roleNames() const;
2018-02-28 09:10:42 +00:00
2018-07-09 02:45:26 +00:00
private slots:
void namesChanged(MatriqueRoom* room);
void unreadMessagesChanged(MatriqueRoom* room);
2018-07-14 07:35:27 +00:00
2018-07-29 16:04:58 +00:00
void doAddRoom(Room* room);
void updateRoom(Room* room, Room* prev);
void deleteRoom(Room* room);
void refresh(MatriqueRoom* room, const QVector<int>& roles = {});
2018-02-28 09:10:42 +00:00
2018-07-09 02:45:26 +00:00
private:
2018-07-29 16:04:58 +00:00
Connection* m_connection = nullptr;
QList<MatriqueRoom*> m_rooms;
void connectRoomSignals(MatriqueRoom* room);
2018-03-14 09:11:45 +00:00
2018-07-09 02:45:26 +00:00
signals:
void connectionChanged();
void roomAdded(MatriqueRoom* room);
void newMessage(const QString& roomName, const QString& content,
const QIcon& icon);
2018-02-28 09:10:42 +00:00
};
2018-07-09 02:45:26 +00:00
#endif // ROOMLISTMODEL_H