diff options
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | resources/qml/RoomSettings.qml | 2 | ||||
-rw-r--r-- | resources/qml/TimelineView.qml | 4 | ||||
-rw-r--r-- | resources/qml/ToggleButton.qml | 10 | ||||
-rw-r--r-- | src/MainWindow.cpp | 4 | ||||
-rw-r--r-- | src/MainWindow.h | 2 | ||||
-rw-r--r-- | src/dialogs/RoomSettingsOld.cpp (renamed from src/dialogs/RoomSettings.cpp) | 50 | ||||
-rw-r--r-- | src/dialogs/RoomSettingsOld.h (renamed from src/dialogs/RoomSettings.h) | 4 | ||||
-rw-r--r-- | src/timeline/TimelineViewManager.cpp | 4 | ||||
-rw-r--r-- | src/timeline/TimelineViewManager.h | 5 | ||||
-rw-r--r-- | src/ui/RoomSettings.cpp | 33 | ||||
-rw-r--r-- | src/ui/RoomSettings.h | 25 |
12 files changed, 112 insertions, 37 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c9e29998..505a59f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -257,7 +257,7 @@ set(SRC_FILES src/dialogs/PreviewUploadOverlay.cpp src/dialogs/ReCaptcha.cpp src/dialogs/ReadReceipts.cpp - src/dialogs/RoomSettings.cpp + src/dialogs/RoomSettingsOld.cpp # Emoji src/emoji/EmojiModel.cpp @@ -294,6 +294,7 @@ set(SRC_FILES src/ui/ThemeManager.cpp src/ui/ToggleButton.cpp src/ui/UserProfile.cpp + src/ui/RoomSettings.cpp src/AvatarProvider.cpp src/BlurhashProvider.cpp @@ -471,7 +472,7 @@ qt5_wrap_cpp(MOC_HEADERS src/dialogs/RawMessage.h src/dialogs/ReCaptcha.h src/dialogs/ReadReceipts.h - src/dialogs/RoomSettings.h + src/dialogs/RoomSettingsOld.h # Emoji src/emoji/EmojiModel.h @@ -506,6 +507,7 @@ qt5_wrap_cpp(MOC_HEADERS src/ui/Theme.h src/ui/ThemeManager.h src/ui/UserProfile.h + src/ui/RoomSettings.h src/notifications/Manager.h diff --git a/resources/qml/RoomSettings.qml b/resources/qml/RoomSettings.qml index 106c9119..d6f3fe7b 100644 --- a/resources/qml/RoomSettings.qml +++ b/resources/qml/RoomSettings.qml @@ -16,7 +16,7 @@ ApplicationWindow { minimumHeight: 420 palette: colors color: colors.window - title: "Room Settings" + title: roomSettings.roomName modality: Qt.Modal Shortcut { diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml index c6c1e2b2..6b34f2ab 100644 --- a/resources/qml/TimelineView.qml +++ b/resources/qml/TimelineView.qml @@ -177,7 +177,9 @@ Page { Connections { target: TimelineManager onOpenRoomSettingsDialog: { - var roomSettings = roomSettingsComponent.createObject(timelineRoot); + var roomSettings = roomSettingsComponent.createObject(timelineRoot, { + "roomSettings": roomSettings + }); roomSettings.show(); } } diff --git a/resources/qml/ToggleButton.qml b/resources/qml/ToggleButton.qml new file mode 100644 index 00000000..584fc693 --- /dev/null +++ b/resources/qml/ToggleButton.qml @@ -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 +}
\ No newline at end of file diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index ab3c2cf2..b1635c94 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -51,7 +51,7 @@ #include "dialogs/Logout.h" #include "dialogs/MemberList.h" #include "dialogs/ReadReceipts.h" -#include "dialogs/RoomSettings.h" +#include "dialogs/RoomSettingsOld.h" MainWindow *MainWindow::instance_ = nullptr; @@ -366,7 +366,7 @@ MainWindow::hasActiveUser() void MainWindow::openRoomSettings(const QString &room_id) { - auto dialog = new dialogs::RoomSettings(room_id, this); + auto dialog = new dialogs::RoomSettingsOld(room_id, this); showDialog(dialog); } diff --git a/src/MainWindow.h b/src/MainWindow.h index bb219813..b3983d72 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -54,7 +54,7 @@ class LeaveRoom; class Logout; class MemberList; class ReCaptcha; -class RoomSettings; +class RoomSettingsOld; } class MainWindow : public QMainWindow diff --git a/src/dialogs/RoomSettings.cpp b/src/dialogs/RoomSettingsOld.cpp index bd3cc26f..7eb34c20 100644 --- a/src/dialogs/RoomSettings.cpp +++ b/src/dialogs/RoomSettingsOld.cpp @@ -1,4 +1,4 @@ -#include "dialogs/RoomSettings.h" +#include "dialogs/RoomSettingsOld.h" #include <QApplication> #include <QComboBox> #include <QEvent> @@ -195,7 +195,7 @@ EditModal::setFields(const QString &roomName, const QString &roomTopic) topicInput_->setText(roomTopic); } -RoomSettings::RoomSettings(const QString &room_id, QWidget *parent) +RoomSettingsOld::RoomSettingsOld(const QString &room_id, QWidget *parent) : QFrame(parent) , 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("All messages")); // delete rule - connect(this, &RoomSettings::notifChanged, notifCombo, &QComboBox::setCurrentIndex); + connect(this, &RoomSettingsOld::notifChanged, notifCombo, &QComboBox::setCurrentIndex); http::client()->get_pushrules( "global", "override", @@ -487,7 +487,7 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent) auto filter = new ClickableFilter(this); avatar_->installEventFilter(filter); 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); @@ -542,7 +542,7 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent) layout->addLayout(spinnerLayout); layout->addStretch(1); - connect(this, &RoomSettings::enableEncryptionError, this, [this](const QString &msg) { + connect(this, &RoomSettingsOld::enableEncryptionError, this, [this](const QString &msg) { encryptionToggle_->setState(false); keyRequestsToggle_->setState(false); keyRequestsToggle_->setEnabled(false); @@ -551,7 +551,7 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent) 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_) return; @@ -561,18 +561,18 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent) errorLabel_->setText(msg); }); - connect(this, &RoomSettings::accessRulesUpdated, this, [this]() { + connect(this, &RoomSettingsOld::accessRulesUpdated, this, [this]() { stopLoadingSpinner(); resetErrorLabel(); }); auto closeShortcut = new QShortcut(QKeySequence(QKeySequence::Cancel), this); - connect(closeShortcut, &QShortcut::activated, this, &RoomSettings::close); - connect(okBtn, &QPushButton::clicked, this, &RoomSettings::close); + connect(closeShortcut, &QShortcut::activated, this, &RoomSettingsOld::close); + connect(okBtn, &QPushButton::clicked, this, &RoomSettingsOld::close); } void -RoomSettings::setupEditButton() +RoomSettingsOld::setupEditButton() { btnLayout_ = new QHBoxLayout; btnLayout_->setSpacing(BUTTON_SPACING); @@ -610,7 +610,7 @@ RoomSettings::setupEditButton() } void -RoomSettings::retrieveRoomInfo() +RoomSettingsOld::retrieveRoomInfo() { try { usesEncryption_ = cache::isRoomEncrypted(room_id_.toStdString()); @@ -623,7 +623,7 @@ RoomSettings::retrieveRoomInfo() } void -RoomSettings::enableEncryption() +RoomSettingsOld::enableEncryption() { const auto room_id = room_id_.toStdString(); http::client()->enable_encryption( @@ -645,7 +645,7 @@ RoomSettings::enableEncryption() } void -RoomSettings::showEvent(QShowEvent *event) +RoomSettingsOld::showEvent(QShowEvent *event) { resetErrorLabel(); stopLoadingSpinner(); @@ -654,7 +654,7 @@ RoomSettings::showEvent(QShowEvent *event) } 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 { return cache::hasEnoughPowerLevel({EventType::RoomJoinRules}, room_id, user_id); @@ -666,7 +666,7 @@ RoomSettings::canChangeJoinRules(const std::string &room_id, const std::string & } 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 { return cache::hasEnoughPowerLevel( @@ -679,7 +679,7 @@ RoomSettings::canChangeNameAndTopic(const std::string &room_id, const std::strin } 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 { 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 -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::GuestAccess &guest_access) { @@ -732,7 +732,7 @@ RoomSettings::updateAccessRules(const std::string &room_id, } void -RoomSettings::stopLoadingSpinner() +RoomSettingsOld::stopLoadingSpinner() { if (spinner_) { spinner_->stop(); @@ -741,7 +741,7 @@ RoomSettings::stopLoadingSpinner() } void -RoomSettings::startLoadingSpinner() +RoomSettingsOld::startLoadingSpinner() { if (spinner_) { spinner_->start(); @@ -750,7 +750,7 @@ RoomSettings::startLoadingSpinner() } void -RoomSettings::displayErrorMessage(const QString &msg) +RoomSettingsOld::displayErrorMessage(const QString &msg) { stopLoadingSpinner(); @@ -759,7 +759,7 @@ RoomSettings::displayErrorMessage(const QString &msg) } void -RoomSettings::setAvatar() +RoomSettingsOld::setAvatar() { stopLoadingSpinner(); @@ -768,7 +768,7 @@ RoomSettings::setAvatar() } void -RoomSettings::resetErrorLabel() +RoomSettingsOld::resetErrorLabel() { if (errorLabel_) { errorLabel_->hide(); @@ -777,7 +777,7 @@ RoomSettings::resetErrorLabel() } void -RoomSettings::updateAvatar() +RoomSettingsOld::updateAvatar() { const QString picturesFolder = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation); @@ -811,8 +811,8 @@ RoomSettings::updateAvatar() // Events emitted from the http callbacks (different threads) will // be queued back into the UI thread through this proxy object. auto proxy = std::make_shared<ThreadProxy>(); - connect(proxy.get(), &ThreadProxy::error, this, &RoomSettings::displayErrorMessage); - connect(proxy.get(), &ThreadProxy::avatarChanged, this, &RoomSettings::setAvatar); + connect(proxy.get(), &ThreadProxy::error, this, &RoomSettingsOld::displayErrorMessage); + connect(proxy.get(), &ThreadProxy::avatarChanged, this, &RoomSettingsOld::setAvatar); const auto bin = file.peek(file.size()); const auto payload = std::string(bin.data(), bin.size()); diff --git a/src/dialogs/RoomSettings.h b/src/dialogs/RoomSettingsOld.h index e0918afd..e517676a 100644 --- a/src/dialogs/RoomSettings.h +++ b/src/dialogs/RoomSettingsOld.h @@ -86,11 +86,11 @@ private: namespace dialogs { -class RoomSettings : public QFrame +class RoomSettingsOld : public QFrame { Q_OBJECT public: - RoomSettings(const QString &room_id, QWidget *parent = nullptr); + RoomSettingsOld(const QString &room_id, QWidget *parent = nullptr); signals: void enableEncryptionError(const QString &msg); diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index d7d06386..7c1922d7 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -393,7 +393,9 @@ void TimelineViewManager::openRoomSettings() { MainWindow::instance()->openRoomSettings(timeline_->roomId()); - emit openRoomSettingsDialog(); + + RoomSettings *roomSettings = new RoomSettings(timeline_->roomId(), this); + emit openRoomSettingsDialog(roomSettings); } void diff --git a/src/timeline/TimelineViewManager.h b/src/timeline/TimelineViewManager.h index 841e0bcb..dca133ce 100644 --- a/src/timeline/TimelineViewManager.h +++ b/src/timeline/TimelineViewManager.h @@ -18,7 +18,8 @@ #include "WebRTCSession.h" #include "emoji/EmojiModel.h" #include "emoji/Provider.h" -#include "dialogs/RoomSettings.h" +#include "dialogs/RoomSettingsOld.h" +#include "ui/RoomSettings.h" class MxcImageProvider; class BlurhashProvider; @@ -88,7 +89,7 @@ signals: void showRoomList(); void narrowViewChanged(); void focusChanged(); - void openRoomSettingsDialog(); + void openRoomSettingsDialog(RoomSettings *roomSettings); public slots: void updateReadReceipts(const QString &room_id, const std::vector<QString> &event_ids); diff --git a/src/ui/RoomSettings.cpp b/src/ui/RoomSettings.cpp new file mode 100644 index 00000000..e8317024 --- /dev/null +++ b/src/ui/RoomSettings.cpp @@ -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()); + } +}
\ No newline at end of file diff --git a/src/ui/RoomSettings.h b/src/ui/RoomSettings.h new file mode 100644 index 00000000..98e64b74 --- /dev/null +++ b/src/ui/RoomSettings.h @@ -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_; +};
\ No newline at end of file |