| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <QAbstractListModel> |
| 8 |
#include <QObject> |
| 9 |
#include <QQmlEngine> |
| 10 |
#include <QSet> |
| 11 |
#include <QString> |
| 12 |
|
| 13 |
#include <unordered_set> |
| 14 |
|
| 15 |
#include <mtx/events/event_type.hpp> |
| 16 |
#include <mtx/events/guest_access.hpp> |
| 17 |
#include <mtx/events/history_visibility.hpp> |
| 18 |
|
| 19 |
#include "CacheStructs.h" |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
class ThreadProxy final : public QObject |
| 24 |
{ |
| 25 |
Q_OBJECT |
| 26 |
|
| 27 |
signals: |
| 28 |
void error(const QString &msg); |
| 29 |
void nameEventSent(const QString &); |
| 30 |
void topicEventSent(const QString &); |
| 31 |
void eventSent(); |
| 32 |
void stopLoading(); |
| 33 |
}; |
| 34 |
|
| 35 |
class RoomSettings; |
| 36 |
|
| 37 |
class RoomSettingsAllowedRoomsModel final : public QAbstractListModel |
| 38 |
{ |
| 39 |
Q_OBJECT |
| 40 |
|
| 41 |
public: |
| 42 |
enum Roles |
| 43 |
{ |
| 44 |
Name, |
| 45 |
IsAllowed, |
| 46 |
IsSpaceParent, |
| 47 |
}; |
| 48 |
|
| 49 |
explicit RoomSettingsAllowedRoomsModel(RoomSettings *parent); |
| 50 |
|
| 51 |
QHash<int, QByteArray> roleNames() const override; |
| 52 |
int rowCount(const QModelIndex &) const override; |
| 53 |
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
| 54 |
bool |
| 55 |
setData(const QModelIndex &index, const QVariant &value, int role = Qt::DisplayRole) override; |
| 56 |
Q_INVOKABLE void addRoom(QString room); |
| 57 |
|
| 58 |
Qt::ItemFlags flags(const QModelIndex &) const override |
| 59 |
{ |
| 60 |
return Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | |
| 61 |
Qt::ItemNeverHasChildren; |
| 62 |
} |
| 63 |
|
| 64 |
QStringList allowedRoomIds; |
| 65 |
|
| 66 |
private: |
| 67 |
QStringList listedRoomIds; |
| 68 |
std::unordered_set<QString> parentSpaces; |
| 69 |
RoomSettings *settings; |
| 70 |
}; |
| 71 |
|
| 72 |
class RoomSettings final : public QObject |
| 73 |
{ |
| 74 |
Q_OBJECT |
| 75 |
QML_ELEMENT |
| 76 |
QML_UNCREATABLE("") |
| 77 |
|
| 78 |
Q_PROPERTY(QString roomId READ roomId CONSTANT) |
| 79 |
Q_PROPERTY(QString roomVersion READ roomVersion CONSTANT) |
| 80 |
Q_PROPERTY(QString roomName READ roomName NOTIFY roomNameChanged) |
| 81 |
Q_PROPERTY(QString roomTopic READ roomTopic NOTIFY roomTopicChanged) |
| 82 |
Q_PROPERTY(QString plainRoomName READ plainRoomName NOTIFY roomNameChanged) |
| 83 |
Q_PROPERTY(QString plainRoomTopic READ plainRoomTopic NOTIFY roomTopicChanged) |
| 84 |
Q_PROPERTY(QString roomAvatarUrl READ roomAvatarUrl NOTIFY avatarUrlChanged) |
| 85 |
Q_PROPERTY(int memberCount READ memberCount CONSTANT) |
| 86 |
Q_PROPERTY(int notifications READ notifications NOTIFY notificationsChanged) |
| 87 |
Q_PROPERTY(Visibility historyVisibility READ historyVisibility WRITE changeHistoryVisibility |
| 88 |
NOTIFY historyVisibilityChanged) |
| 89 |
Q_PROPERTY(bool privateAccess READ privateAccess NOTIFY accessJoinRulesChanged) |
| 90 |
Q_PROPERTY(bool guestAccess READ guestAccess NOTIFY accessJoinRulesChanged) |
| 91 |
Q_PROPERTY(bool knockingEnabled READ knockingEnabled NOTIFY accessJoinRulesChanged) |
| 92 |
Q_PROPERTY(bool restrictedEnabled READ restrictedEnabled NOTIFY accessJoinRulesChanged) |
| 93 |
Q_PROPERTY(bool isLoading READ isLoading NOTIFY loadingChanged) |
| 94 |
Q_PROPERTY(bool canChangeAvatar READ canChangeAvatar CONSTANT) |
| 95 |
Q_PROPERTY(bool canChangeJoinRules READ canChangeJoinRules CONSTANT) |
| 96 |
Q_PROPERTY(bool canChangeName READ canChangeName CONSTANT) |
| 97 |
Q_PROPERTY(bool canChangeTopic READ canChangeTopic CONSTANT) |
| 98 |
Q_PROPERTY(bool canChangeHistoryVisibility READ canChangeHistoryVisibility CONSTANT) |
| 99 |
Q_PROPERTY(bool isEncryptionEnabled READ isEncryptionEnabled NOTIFY encryptionChanged) |
| 100 |
Q_PROPERTY(bool supportsKnocking READ supportsKnocking CONSTANT) |
| 101 |
Q_PROPERTY(bool supportsRestricted READ supportsRestricted CONSTANT) |
| 102 |
Q_PROPERTY(bool supportsKnockRestricted READ supportsKnockRestricted CONSTANT) |
| 103 |
Q_PROPERTY(bool isRoomNameSet READ isRoomNameSet NOTIFY roomNameChanged) |
| 104 |
Q_PROPERTY( |
| 105 |
QStringList allowedRooms READ allowedRooms WRITE setAllowedRooms NOTIFY allowedRoomsChanged) |
| 106 |
Q_PROPERTY(RoomSettingsAllowedRoomsModel *allowedRoomsModel MEMBER allowedRoomsModel CONSTANT) |
| 107 |
Q_PROPERTY( |
| 108 |
bool allowedRoomsModified READ allowedRoomsModified NOTIFY allowedRoomsModifiedChanged) |
| 109 |
|
| 110 |
public: |
| 111 |
|
| 112 |
enum Visibility |
| 113 |
{ |
| 114 |
WorldReadable, |
| 115 |
Shared, |
| 116 |
Invited, |
| 117 |
Joined, |
| 118 |
}; |
| 119 |
Q_ENUM(Visibility) |
| 120 |
|
| 121 |
RoomSettings(QString roomid, QObject *parent = nullptr); |
| 122 |
|
| 123 |
QString roomId() const; |
| 124 |
QString roomName() const; |
| 125 |
QString roomTopic() const; |
| 126 |
QString plainRoomName() const; |
| 127 |
QString plainRoomTopic() const; |
| 128 |
QString roomVersion() const; |
| 129 |
QString roomAvatarUrl(); |
| 130 |
int memberCount() const; |
| 131 |
int notifications(); |
| 132 |
bool isRoomNameSet() const; |
| 133 |
bool privateAccess() const; |
| 134 |
bool guestAccess() const; |
| 135 |
bool knockingEnabled() const; |
| 136 |
bool restrictedEnabled() const; |
| 137 |
bool isLoading() const; |
| 138 |
|
| 139 |
bool canChangeJoinRules() const; |
| 140 |
|
| 141 |
bool canChangeName() const; |
| 142 |
|
| 143 |
bool canChangeTopic() const; |
| 144 |
|
| 145 |
bool canChangeAvatar() const; |
| 146 |
bool canChangeHistoryVisibility() const; |
| 147 |
bool isEncryptionEnabled() const; |
| 148 |
bool supportsKnocking() const; |
| 149 |
bool supportsRestricted() const; |
| 150 |
bool supportsKnockRestricted() const; |
| 151 |
QStringList allowedRooms() const; |
| 152 |
void setAllowedRooms(QStringList rooms); |
| 153 |
bool allowedRoomsModified() const { return allowedRoomsModified_; } |
| 154 |
|
| 155 |
Visibility historyVisibility() const; |
| 156 |
Q_INVOKABLE void changeHistoryVisibility(Visibility visibility); |
| 157 |
|
| 158 |
Q_INVOKABLE void enableEncryption(); |
| 159 |
Q_INVOKABLE void updateAvatar(); |
| 160 |
Q_INVOKABLE void changeAccessRules(bool private_, |
| 161 |
bool guestsAllowed, |
| 162 |
bool knockingAllowed, |
| 163 |
bool restrictedAllowed); |
| 164 |
Q_INVOKABLE void changeNotifications(int currentIndex); |
| 165 |
Q_INVOKABLE void changeTopic(const QString &topic); |
| 166 |
Q_INVOKABLE void changeName(const QString &name); |
| 167 |
|
| 168 |
Q_INVOKABLE void applyAllowedFromModel(); |
| 169 |
|
| 170 |
signals: |
| 171 |
void loadingChanged(); |
| 172 |
void roomNameChanged(); |
| 173 |
void roomTopicChanged(); |
| 174 |
void avatarUrlChanged(); |
| 175 |
void encryptionChanged(); |
| 176 |
void notificationsChanged(); |
| 177 |
void accessJoinRulesChanged(); |
| 178 |
void allowedRoomsChanged(); |
| 179 |
void displayError(const QString &errorMessage); |
| 180 |
void allowedRoomsModifiedChanged(); |
| 181 |
void historyVisibilityChanged(); |
| 182 |
|
| 183 |
public slots: |
| 184 |
void stopLoading(); |
| 185 |
void avatarChanged(); |
| 186 |
|
| 187 |
private: |
| 188 |
void retrieveRoomInfo(); |
| 189 |
void updateAccessRules(const std::string &room_id, |
| 190 |
const mtx::events::state::JoinRules &, |
| 191 |
const mtx::events::state::GuestAccess &); |
| 192 |
|
| 193 |
private: |
| 194 |
QString roomid_; |
| 195 |
bool usesEncryption_ = false; |
| 196 |
bool isLoading_ = false; |
| 197 |
bool allowedRoomsModified_ = false; |
| 198 |
RoomInfo info_; |
| 199 |
int notifications_ = 0; |
| 200 |
|
| 201 |
mtx::events::state::JoinRules accessRules_; |
| 202 |
mtx::events::state::Visibility historyVisibility_ = mtx::events::state::Visibility::Shared; |
| 203 |
mtx::events::state::AccessState guestRules_ = mtx::events::state::AccessState::Forbidden; |
| 204 |
|
| 205 |
RoomSettingsAllowedRoomsModel *allowedRoomsModel; |
| 206 |
}; |