ui almost looks the same, midway between transition from old room settings to new room settings

This commit is contained in:
Jedi18 2021-02-10 21:22:42 +05:30
parent 37679ac57e
commit b70f37194f
12 changed files with 112 additions and 37 deletions

View file

@ -257,7 +257,7 @@ set(SRC_FILES
src/dialogs/PreviewUploadOverlay.cpp src/dialogs/PreviewUploadOverlay.cpp
src/dialogs/ReCaptcha.cpp src/dialogs/ReCaptcha.cpp
src/dialogs/ReadReceipts.cpp src/dialogs/ReadReceipts.cpp
src/dialogs/RoomSettings.cpp src/dialogs/RoomSettingsOld.cpp
# Emoji # Emoji
src/emoji/EmojiModel.cpp src/emoji/EmojiModel.cpp
@ -294,6 +294,7 @@ set(SRC_FILES
src/ui/ThemeManager.cpp src/ui/ThemeManager.cpp
src/ui/ToggleButton.cpp src/ui/ToggleButton.cpp
src/ui/UserProfile.cpp src/ui/UserProfile.cpp
src/ui/RoomSettings.cpp
src/AvatarProvider.cpp src/AvatarProvider.cpp
src/BlurhashProvider.cpp src/BlurhashProvider.cpp
@ -471,7 +472,7 @@ qt5_wrap_cpp(MOC_HEADERS
src/dialogs/RawMessage.h src/dialogs/RawMessage.h
src/dialogs/ReCaptcha.h src/dialogs/ReCaptcha.h
src/dialogs/ReadReceipts.h src/dialogs/ReadReceipts.h
src/dialogs/RoomSettings.h src/dialogs/RoomSettingsOld.h
# Emoji # Emoji
src/emoji/EmojiModel.h src/emoji/EmojiModel.h
@ -506,6 +507,7 @@ qt5_wrap_cpp(MOC_HEADERS
src/ui/Theme.h src/ui/Theme.h
src/ui/ThemeManager.h src/ui/ThemeManager.h
src/ui/UserProfile.h src/ui/UserProfile.h
src/ui/RoomSettings.h
src/notifications/Manager.h src/notifications/Manager.h

View file

@ -16,7 +16,7 @@ ApplicationWindow {
minimumHeight: 420 minimumHeight: 420
palette: colors palette: colors
color: colors.window color: colors.window
title: "Room Settings" title: roomSettings.roomName
modality: Qt.Modal modality: Qt.Modal
Shortcut { Shortcut {

View file

@ -177,7 +177,9 @@ Page {
Connections { Connections {
target: TimelineManager target: TimelineManager
onOpenRoomSettingsDialog: { onOpenRoomSettingsDialog: {
var roomSettings = roomSettingsComponent.createObject(timelineRoot); var roomSettings = roomSettingsComponent.createObject(timelineRoot, {
"roomSettings": roomSettings
});
roomSettings.show(); roomSettings.show();
} }
} }

View file

@ -0,0 +1,10 @@
import QtQuick 2.5
import QtQuick.Controls 2.3
import im.nheko 1.0
Switch {
property color activeColor
property color disabledColor
property color inactiveColor
property color trackColor
}

View file

@ -51,7 +51,7 @@
#include "dialogs/Logout.h" #include "dialogs/Logout.h"
#include "dialogs/MemberList.h" #include "dialogs/MemberList.h"
#include "dialogs/ReadReceipts.h" #include "dialogs/ReadReceipts.h"
#include "dialogs/RoomSettings.h" #include "dialogs/RoomSettingsOld.h"
MainWindow *MainWindow::instance_ = nullptr; MainWindow *MainWindow::instance_ = nullptr;
@ -366,7 +366,7 @@ MainWindow::hasActiveUser()
void void
MainWindow::openRoomSettings(const QString &room_id) MainWindow::openRoomSettings(const QString &room_id)
{ {
auto dialog = new dialogs::RoomSettings(room_id, this); auto dialog = new dialogs::RoomSettingsOld(room_id, this);
showDialog(dialog); showDialog(dialog);
} }

View file

@ -54,7 +54,7 @@ class LeaveRoom;
class Logout; class Logout;
class MemberList; class MemberList;
class ReCaptcha; class ReCaptcha;
class RoomSettings; class RoomSettingsOld;
} }
class MainWindow : public QMainWindow class MainWindow : public QMainWindow

View file

@ -1,4 +1,4 @@
#include "dialogs/RoomSettings.h" #include "dialogs/RoomSettingsOld.h"
#include <QApplication> #include <QApplication>
#include <QComboBox> #include <QComboBox>
#include <QEvent> #include <QEvent>
@ -195,7 +195,7 @@ EditModal::setFields(const QString &roomName, const QString &roomTopic)
topicInput_->setText(roomTopic); topicInput_->setText(roomTopic);
} }
RoomSettings::RoomSettings(const QString &room_id, QWidget *parent) RoomSettingsOld::RoomSettingsOld(const QString &room_id, QWidget *parent)
: QFrame(parent) : QFrame(parent)
, room_id_{std::move(room_id)} , room_id_{std::move(room_id)}
{ {
@ -253,7 +253,7 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent)
notifCombo->addItem(tr("Mentions only")); // {"actions":["dont_notify"]} notifCombo->addItem(tr("Mentions only")); // {"actions":["dont_notify"]}
notifCombo->addItem(tr("All messages")); // delete rule notifCombo->addItem(tr("All messages")); // delete rule
connect(this, &RoomSettings::notifChanged, notifCombo, &QComboBox::setCurrentIndex); connect(this, &RoomSettingsOld::notifChanged, notifCombo, &QComboBox::setCurrentIndex);
http::client()->get_pushrules( http::client()->get_pushrules(
"global", "global",
"override", "override",
@ -487,7 +487,7 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent)
auto filter = new ClickableFilter(this); auto filter = new ClickableFilter(this);
avatar_->installEventFilter(filter); avatar_->installEventFilter(filter);
avatar_->setCursor(Qt::PointingHandCursor); avatar_->setCursor(Qt::PointingHandCursor);
connect(filter, &ClickableFilter::clicked, this, &RoomSettings::updateAvatar); connect(filter, &ClickableFilter::clicked, this, &RoomSettingsOld::updateAvatar);
} }
roomNameLabel_ = new QLabel(QString::fromStdString(info_.name), this); roomNameLabel_ = new QLabel(QString::fromStdString(info_.name), this);
@ -542,7 +542,7 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent)
layout->addLayout(spinnerLayout); layout->addLayout(spinnerLayout);
layout->addStretch(1); layout->addStretch(1);
connect(this, &RoomSettings::enableEncryptionError, this, [this](const QString &msg) { connect(this, &RoomSettingsOld::enableEncryptionError, this, [this](const QString &msg) {
encryptionToggle_->setState(false); encryptionToggle_->setState(false);
keyRequestsToggle_->setState(false); keyRequestsToggle_->setState(false);
keyRequestsToggle_->setEnabled(false); keyRequestsToggle_->setEnabled(false);
@ -551,7 +551,7 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent)
emit ChatPage::instance()->showNotification(msg); emit ChatPage::instance()->showNotification(msg);
}); });
connect(this, &RoomSettings::showErrorMessage, this, [this](const QString &msg) { connect(this, &RoomSettingsOld::showErrorMessage, this, [this](const QString &msg) {
if (!errorLabel_) if (!errorLabel_)
return; return;
@ -561,18 +561,18 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent)
errorLabel_->setText(msg); errorLabel_->setText(msg);
}); });
connect(this, &RoomSettings::accessRulesUpdated, this, [this]() { connect(this, &RoomSettingsOld::accessRulesUpdated, this, [this]() {
stopLoadingSpinner(); stopLoadingSpinner();
resetErrorLabel(); resetErrorLabel();
}); });
auto closeShortcut = new QShortcut(QKeySequence(QKeySequence::Cancel), this); auto closeShortcut = new QShortcut(QKeySequence(QKeySequence::Cancel), this);
connect(closeShortcut, &QShortcut::activated, this, &RoomSettings::close); connect(closeShortcut, &QShortcut::activated, this, &RoomSettingsOld::close);
connect(okBtn, &QPushButton::clicked, this, &RoomSettings::close); connect(okBtn, &QPushButton::clicked, this, &RoomSettingsOld::close);
} }
void void
RoomSettings::setupEditButton() RoomSettingsOld::setupEditButton()
{ {
btnLayout_ = new QHBoxLayout; btnLayout_ = new QHBoxLayout;
btnLayout_->setSpacing(BUTTON_SPACING); btnLayout_->setSpacing(BUTTON_SPACING);
@ -610,7 +610,7 @@ RoomSettings::setupEditButton()
} }
void void
RoomSettings::retrieveRoomInfo() RoomSettingsOld::retrieveRoomInfo()
{ {
try { try {
usesEncryption_ = cache::isRoomEncrypted(room_id_.toStdString()); usesEncryption_ = cache::isRoomEncrypted(room_id_.toStdString());
@ -623,7 +623,7 @@ RoomSettings::retrieveRoomInfo()
} }
void void
RoomSettings::enableEncryption() RoomSettingsOld::enableEncryption()
{ {
const auto room_id = room_id_.toStdString(); const auto room_id = room_id_.toStdString();
http::client()->enable_encryption( http::client()->enable_encryption(
@ -645,7 +645,7 @@ RoomSettings::enableEncryption()
} }
void void
RoomSettings::showEvent(QShowEvent *event) RoomSettingsOld::showEvent(QShowEvent *event)
{ {
resetErrorLabel(); resetErrorLabel();
stopLoadingSpinner(); stopLoadingSpinner();
@ -654,7 +654,7 @@ RoomSettings::showEvent(QShowEvent *event)
} }
bool bool
RoomSettings::canChangeJoinRules(const std::string &room_id, const std::string &user_id) const RoomSettingsOld::canChangeJoinRules(const std::string &room_id, const std::string &user_id) const
{ {
try { try {
return cache::hasEnoughPowerLevel({EventType::RoomJoinRules}, room_id, user_id); return cache::hasEnoughPowerLevel({EventType::RoomJoinRules}, room_id, user_id);
@ -666,7 +666,7 @@ RoomSettings::canChangeJoinRules(const std::string &room_id, const std::string &
} }
bool bool
RoomSettings::canChangeNameAndTopic(const std::string &room_id, const std::string &user_id) const RoomSettingsOld::canChangeNameAndTopic(const std::string &room_id, const std::string &user_id) const
{ {
try { try {
return cache::hasEnoughPowerLevel( return cache::hasEnoughPowerLevel(
@ -679,7 +679,7 @@ RoomSettings::canChangeNameAndTopic(const std::string &room_id, const std::strin
} }
bool bool
RoomSettings::canChangeAvatar(const std::string &room_id, const std::string &user_id) const RoomSettingsOld::canChangeAvatar(const std::string &room_id, const std::string &user_id) const
{ {
try { try {
return cache::hasEnoughPowerLevel({EventType::RoomAvatar}, room_id, user_id); return cache::hasEnoughPowerLevel({EventType::RoomAvatar}, room_id, user_id);
@ -691,7 +691,7 @@ RoomSettings::canChangeAvatar(const std::string &room_id, const std::string &use
} }
void void
RoomSettings::updateAccessRules(const std::string &room_id, RoomSettingsOld::updateAccessRules(const std::string &room_id,
const mtx::events::state::JoinRules &join_rule, const mtx::events::state::JoinRules &join_rule,
const mtx::events::state::GuestAccess &guest_access) const mtx::events::state::GuestAccess &guest_access)
{ {
@ -732,7 +732,7 @@ RoomSettings::updateAccessRules(const std::string &room_id,
} }
void void
RoomSettings::stopLoadingSpinner() RoomSettingsOld::stopLoadingSpinner()
{ {
if (spinner_) { if (spinner_) {
spinner_->stop(); spinner_->stop();
@ -741,7 +741,7 @@ RoomSettings::stopLoadingSpinner()
} }
void void
RoomSettings::startLoadingSpinner() RoomSettingsOld::startLoadingSpinner()
{ {
if (spinner_) { if (spinner_) {
spinner_->start(); spinner_->start();
@ -750,7 +750,7 @@ RoomSettings::startLoadingSpinner()
} }
void void
RoomSettings::displayErrorMessage(const QString &msg) RoomSettingsOld::displayErrorMessage(const QString &msg)
{ {
stopLoadingSpinner(); stopLoadingSpinner();
@ -759,7 +759,7 @@ RoomSettings::displayErrorMessage(const QString &msg)
} }
void void
RoomSettings::setAvatar() RoomSettingsOld::setAvatar()
{ {
stopLoadingSpinner(); stopLoadingSpinner();
@ -768,7 +768,7 @@ RoomSettings::setAvatar()
} }
void void
RoomSettings::resetErrorLabel() RoomSettingsOld::resetErrorLabel()
{ {
if (errorLabel_) { if (errorLabel_) {
errorLabel_->hide(); errorLabel_->hide();
@ -777,7 +777,7 @@ RoomSettings::resetErrorLabel()
} }
void void
RoomSettings::updateAvatar() RoomSettingsOld::updateAvatar()
{ {
const QString picturesFolder = const QString picturesFolder =
QStandardPaths::writableLocation(QStandardPaths::PicturesLocation); QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
@ -811,8 +811,8 @@ RoomSettings::updateAvatar()
// Events emitted from the http callbacks (different threads) will // Events emitted from the http callbacks (different threads) will
// be queued back into the UI thread through this proxy object. // be queued back into the UI thread through this proxy object.
auto proxy = std::make_shared<ThreadProxy>(); auto proxy = std::make_shared<ThreadProxy>();
connect(proxy.get(), &ThreadProxy::error, this, &RoomSettings::displayErrorMessage); connect(proxy.get(), &ThreadProxy::error, this, &RoomSettingsOld::displayErrorMessage);
connect(proxy.get(), &ThreadProxy::avatarChanged, this, &RoomSettings::setAvatar); connect(proxy.get(), &ThreadProxy::avatarChanged, this, &RoomSettingsOld::setAvatar);
const auto bin = file.peek(file.size()); const auto bin = file.peek(file.size());
const auto payload = std::string(bin.data(), bin.size()); const auto payload = std::string(bin.data(), bin.size());

View file

@ -86,11 +86,11 @@ private:
namespace dialogs { namespace dialogs {
class RoomSettings : public QFrame class RoomSettingsOld : public QFrame
{ {
Q_OBJECT Q_OBJECT
public: public:
RoomSettings(const QString &room_id, QWidget *parent = nullptr); RoomSettingsOld(const QString &room_id, QWidget *parent = nullptr);
signals: signals:
void enableEncryptionError(const QString &msg); void enableEncryptionError(const QString &msg);

View file

@ -393,7 +393,9 @@ void
TimelineViewManager::openRoomSettings() TimelineViewManager::openRoomSettings()
{ {
MainWindow::instance()->openRoomSettings(timeline_->roomId()); MainWindow::instance()->openRoomSettings(timeline_->roomId());
emit openRoomSettingsDialog();
RoomSettings *roomSettings = new RoomSettings(timeline_->roomId(), this);
emit openRoomSettingsDialog(roomSettings);
} }
void void

View file

@ -18,7 +18,8 @@
#include "WebRTCSession.h" #include "WebRTCSession.h"
#include "emoji/EmojiModel.h" #include "emoji/EmojiModel.h"
#include "emoji/Provider.h" #include "emoji/Provider.h"
#include "dialogs/RoomSettings.h" #include "dialogs/RoomSettingsOld.h"
#include "ui/RoomSettings.h"
class MxcImageProvider; class MxcImageProvider;
class BlurhashProvider; class BlurhashProvider;
@ -88,7 +89,7 @@ signals:
void showRoomList(); void showRoomList();
void narrowViewChanged(); void narrowViewChanged();
void focusChanged(); void focusChanged();
void openRoomSettingsDialog(); void openRoomSettingsDialog(RoomSettings *roomSettings);
public slots: public slots:
void updateReadReceipts(const QString &room_id, const std::vector<QString> &event_ids); void updateReadReceipts(const QString &room_id, const std::vector<QString> &event_ids);

33
src/ui/RoomSettings.cpp Normal file
View file

@ -0,0 +1,33 @@
#include "RoomSettings.h"
#include <mtx/responses/common.hpp>
#include <mtx/responses/media.hpp>
#include "Cache.h"
#include "Logging.h"
RoomSettings::RoomSettings(QString roomid, QObject *parent)
: roomid_{std::move(roomid)}
, QObject(parent)
{
retrieveRoomInfo();
}
QString
RoomSettings::roomName() const
{
return QString(info_.name.c_str());
}
void
RoomSettings::retrieveRoomInfo()
{
try {
usesEncryption_ = cache::isRoomEncrypted(roomid_.toStdString());
info_ = cache::singleRoomInfo(roomid_.toStdString());
//setAvatar();
} catch (const lmdb::error &) {
nhlog::db()->warn("failed to retrieve room info from cache: {}",
roomid_.toStdString());
}
}

25
src/ui/RoomSettings.h Normal file
View file

@ -0,0 +1,25 @@
#pragma once
#include <QObject>
#include <QString>
#include "CacheStructs.h"
class RoomSettings : public QObject
{
Q_OBJECT
Q_PROPERTY(QString roomName READ roomName CONSTANT)
public:
RoomSettings(QString roomid, QObject *parent = nullptr);
QString roomName() const;
private:
void retrieveRoomInfo();
private:
QString roomid_;
bool usesEncryption_ = false;
RoomInfo info_;
};