matrixion/src/dialogs/RoomSettings.h

150 lines
3.8 KiB
C
Raw Normal View History

2018-04-30 21:41:47 +03:00
#pragma once
#include <QEvent>
2018-04-30 21:41:47 +03:00
#include <QFrame>
#include <QImage>
#include "Cache.h"
class Avatar;
2018-04-30 21:41:47 +03:00
class FlatButton;
class QComboBox;
class QHBoxLayout;
class QShowEvent;
class LoadingIndicator;
2018-04-30 21:41:47 +03:00
class QLabel;
class QLabel;
class QLayout;
class QPixmap;
class TextField;
class TextField;
class Toggle;
2018-04-30 21:41:47 +03:00
class ClickableFilter : public QObject
{
Q_OBJECT
public:
explicit ClickableFilter(QWidget *parent)
: QObject(parent)
{}
signals:
void clicked();
protected:
bool eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::MouseButtonRelease) {
emit clicked();
return true;
}
return QObject::eventFilter(obj, event);
}
};
/// 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 avatarChanged(const QImage &img);
void nameEventSent(const QString &);
void topicEventSent();
};
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);
private:
QString roomId_;
QString initialName_;
QString initialTopic_;
QLabel *errorField_;
TextField *nameInput_;
TextField *topicInput_;
FlatButton *applyBtn_;
FlatButton *cancelBtn_;
};
2018-04-30 21:41:47 +03:00
namespace dialogs {
class RoomSettings : public QFrame
{
Q_OBJECT
public:
2018-05-08 20:30:09 +03:00
RoomSettings(const QString &room_id, QWidget *parent = nullptr);
2018-04-30 21:41:47 +03:00
signals:
void closing();
void enableEncryptionError(const QString &msg);
void showErrorMessage(const QString &msg);
void accessRulesUpdated();
2018-04-30 21:41:47 +03:00
protected:
void paintEvent(QPaintEvent *event) override;
void showEvent(QShowEvent *event) override;
private slots:
//! The file dialog opens so the user can select and upload a new room avatar.
void updateAvatar();
2018-04-30 21:41:47 +03:00
private:
//! Whether the user has enough power level to send m.room.join_rules events.
bool canChangeJoinRules(const std::string &room_id, const std::string &user_id) const;
//! Whether the user has enough power level to send m.room.name & m.room.topic events.
bool canChangeNameAndTopic(const std::string &room_id, const std::string &user_id) const;
//! Whether the user has enough power level to send m.room.avatar event.
bool canChangeAvatar(const std::string &room_id, const std::string &user_id) const;
void updateAccessRules(const std::string &room_id,
const mtx::events::state::JoinRules &,
const mtx::events::state::GuestAccess &);
void stopLoadingSpinner();
void startLoadingSpinner();
void resetErrorLabel();
void displayErrorMessage(const QString &msg);
2018-04-30 21:41:47 +03:00
void setAvatar(const QImage &img);
void setupEditButton();
//! Retrieve the current room information from cache.
void retrieveRoomInfo();
void enableEncryption();
Avatar *avatar_ = nullptr;
bool usesEncryption_ = false;
QHBoxLayout *btnLayout_;
2018-04-30 21:41:47 +03:00
FlatButton *editFieldsBtn_ = nullptr;
2018-04-30 21:41:47 +03:00
RoomInfo info_;
QString room_id_;
QImage avatarImg_;
QLabel *roomNameLabel_ = nullptr;
QLabel *errorLabel_ = nullptr;
LoadingIndicator *spinner_ = nullptr;
QComboBox *accessCombo = nullptr;
Toggle *encryptionToggle_ = nullptr;
Toggle *keyRequestsToggle_ = nullptr;
2018-04-30 21:41:47 +03:00
};
} // dialogs