matrixion/src/ui/RoomSettings.h

136 lines
4.2 KiB
C
Raw Normal View History

2021-03-05 02:35:15 +03:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <QLabel>
#include <QObject>
#include <QPushButton>
#include <QString>
#include <mtx/events/guest_access.hpp>
#include "CacheStructs.h"
class TextField;
2021-02-11 21:09:11 +03:00
/// Convenience class which connects events emmited from threads
/// outside of main with the UI code.
class ThreadProxy : public QObject
{
Q_OBJECT
signals:
void error(const QString &msg);
void nameEventSent(const QString &);
2021-02-13 16:38:52 +03:00
void topicEventSent(const QString &);
2021-02-11 21:09:11 +03:00
void stopLoading();
};
class EditModal : public QWidget
{
Q_OBJECT
public:
EditModal(const QString &roomId, QWidget *parent = nullptr);
void setFields(const QString &roomName, const QString &roomTopic);
signals:
void nameChanged(const QString &roomName);
2021-02-13 16:38:52 +03:00
void topicChanged(const QString &topic);
private slots:
2021-02-13 16:38:52 +03:00
void topicEventSent(const QString &topic);
void nameEventSent(const QString &name);
void error(const QString &msg);
void applyClicked();
private:
QString roomId_;
QString initialName_;
QString initialTopic_;
QLabel *errorField_;
TextField *nameInput_;
TextField *topicInput_;
QPushButton *applyBtn_;
QPushButton *cancelBtn_;
};
class RoomSettings : public QObject
{
2021-02-11 21:09:11 +03:00
Q_OBJECT
2021-02-11 18:53:33 +03:00
Q_PROPERTY(QString roomId READ roomId CONSTANT)
Q_PROPERTY(QString roomVersion READ roomVersion CONSTANT)
2021-02-13 16:38:52 +03:00
Q_PROPERTY(QString roomName READ roomName NOTIFY roomNameChanged)
Q_PROPERTY(QString roomTopic READ roomTopic NOTIFY roomTopicChanged)
2021-02-11 21:09:11 +03:00
Q_PROPERTY(QString roomAvatarUrl READ roomAvatarUrl NOTIFY avatarUrlChanged)
2021-02-11 18:53:33 +03:00
Q_PROPERTY(int memberCount READ memberCount CONSTANT)
Q_PROPERTY(int notifications READ notifications NOTIFY notificationsChanged)
Q_PROPERTY(int accessJoinRules READ accessJoinRules NOTIFY accessJoinRulesChanged)
2021-02-11 21:09:11 +03:00
Q_PROPERTY(bool isLoading READ isLoading NOTIFY loadingChanged)
2021-02-13 16:38:52 +03:00
Q_PROPERTY(bool canChangeAvatar READ canChangeAvatar CONSTANT)
Q_PROPERTY(bool canChangeJoinRules READ canChangeJoinRules CONSTANT)
2021-02-11 21:09:11 +03:00
Q_PROPERTY(bool canChangeNameAndTopic READ canChangeNameAndTopic CONSTANT)
Q_PROPERTY(bool isEncryptionEnabled READ isEncryptionEnabled NOTIFY encryptionChanged)
public:
RoomSettings(QString roomid, QObject *parent = nullptr);
2021-02-11 18:53:33 +03:00
QString roomId() const;
2021-02-13 16:38:52 +03:00
QString roomName() const;
QString roomTopic() const;
2021-02-11 18:53:33 +03:00
QString roomVersion() const;
2021-02-11 21:09:11 +03:00
QString roomAvatarUrl();
2021-02-11 18:53:33 +03:00
int memberCount() const;
int notifications();
int accessJoinRules();
2021-02-11 21:09:11 +03:00
bool isLoading() const;
//! Whether the user has enough power level to send m.room.join_rules events.
bool canChangeJoinRules() const;
2021-02-11 21:09:11 +03:00
//! Whether the user has enough power level to send m.room.name & m.room.topic events.
bool canChangeNameAndTopic() const;
//! Whether the user has enough power level to send m.room.avatar event.
bool canChangeAvatar() const;
bool isEncryptionEnabled() const;
Q_INVOKABLE void enableEncryption();
2021-02-11 21:09:11 +03:00
Q_INVOKABLE void updateAvatar();
Q_INVOKABLE void openEditModal();
2021-02-13 16:38:52 +03:00
Q_INVOKABLE void changeAccessRules(int index);
Q_INVOKABLE void changeNotifications(int currentIndex);
signals:
2021-02-13 16:38:52 +03:00
void loadingChanged();
void roomNameChanged();
void roomTopicChanged();
void avatarUrlChanged();
void encryptionChanged();
void notificationsChanged();
void accessJoinRulesChanged();
2021-02-11 21:09:11 +03:00
void displayError(const QString &errorMessage);
public slots:
void stopLoading();
2021-02-13 16:38:52 +03:00
void avatarChanged();
private:
void retrieveRoomInfo();
void updateAccessRules(const std::string &room_id,
const mtx::events::state::JoinRules &,
const mtx::events::state::GuestAccess &);
private:
QString roomid_;
bool usesEncryption_ = false;
2021-02-11 21:09:11 +03:00
bool isLoading_ = false;
RoomInfo info_;
int notifications_ = 0;
int accessRules_ = 0;
};