diff options
Diffstat (limited to 'src')
-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 |
8 files changed, 94 insertions, 33 deletions
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 |