2018-02-28 09:10:42 +00:00
|
|
|
#ifndef ROOMLISTMODEL_H
|
|
|
|
#define ROOMLISTMODEL_H
|
|
|
|
|
2018-07-07 09:38:20 +00:00
|
|
|
#include "connection.h"
|
2018-08-19 06:32:18 +00:00
|
|
|
#include "events/roomevent.h"
|
|
|
|
#include "room.h"
|
2018-09-18 12:57:38 +00:00
|
|
|
#include "spectralroom.h"
|
2018-08-18 08:02:47 +00:00
|
|
|
|
|
|
|
#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
|
2018-08-18 08:02:47 +00:00
|
|
|
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:
|
2018-07-13 04:06:27 +00:00
|
|
|
enum EventRoles {
|
|
|
|
NameRole = Qt::UserRole + 1,
|
|
|
|
AvatarRole,
|
|
|
|
TopicRole,
|
|
|
|
CategoryRole,
|
2018-08-17 04:55:57 +00:00
|
|
|
UnreadCountRole,
|
2018-09-06 04:34:15 +00:00
|
|
|
HighlightCountRole,
|
2018-08-24 05:25:41 +00:00
|
|
|
LastEventRole,
|
2018-09-18 12:57:38 +00:00
|
|
|
LastActiveTimeRole,
|
2018-08-24 05:25:41 +00:00
|
|
|
CurrentRoomRole,
|
2018-07-13 04:06:27 +00:00
|
|
|
};
|
|
|
|
|
2018-07-09 02:45:26 +00:00
|
|
|
RoomListModel(QObject* parent = 0);
|
|
|
|
virtual ~RoomListModel();
|
2018-02-28 13:11:42 +00:00
|
|
|
|
2018-08-18 08:02:47 +00:00
|
|
|
Connection* connection() { return m_connection; }
|
2018-07-29 16:04:58 +00:00
|
|
|
void setConnection(Connection* connection);
|
2018-07-18 14:16:03 +00:00
|
|
|
void doResetModel();
|
2018-02-28 09:10:42 +00:00
|
|
|
|
2018-09-17 13:01:02 +00:00
|
|
|
Q_INVOKABLE SpectralRoom* roomAt(int row);
|
2018-07-07 09:38:20 +00:00
|
|
|
|
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:
|
2018-09-17 13:01:02 +00:00
|
|
|
void namesChanged(SpectralRoom* room);
|
|
|
|
void unreadMessagesChanged(SpectralRoom* 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);
|
2018-09-17 13:01:02 +00:00
|
|
|
void refresh(SpectralRoom* 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;
|
2018-09-17 13:01:02 +00:00
|
|
|
QList<SpectralRoom*> m_rooms;
|
|
|
|
void connectRoomSignals(SpectralRoom* room);
|
2018-03-14 09:11:45 +00:00
|
|
|
|
2018-07-09 02:45:26 +00:00
|
|
|
signals:
|
|
|
|
void connectionChanged();
|
2018-09-17 13:01:02 +00:00
|
|
|
void roomAdded(SpectralRoom* room);
|
2018-08-22 15:21:39 +00:00
|
|
|
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
|