diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 8e93c0f4..e61df263 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -73,6 +73,8 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) { setObjectName("chatPage"); + instance_ = this; + qRegisterMetaType>(); qRegisterMetaType>(); qRegisterMetaType(); @@ -124,7 +126,7 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) contentLayout_->setSpacing(0); contentLayout_->setMargin(0); - view_manager_ = new TimelineViewManager(userSettings_, &callManager_, this); + view_manager_ = new TimelineViewManager(&callManager_, this); contentLayout_->addWidget(view_manager_->getWidget()); @@ -590,8 +592,6 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) connectCallMessage(); connectCallMessage(); connectCallMessage(); - - instance_ = this; } void diff --git a/src/RoomInfoListItem.cpp b/src/RoomInfoListItem.cpp index f234b59b..985ab1b9 100644 --- a/src/RoomInfoListItem.cpp +++ b/src/RoomInfoListItem.cpp @@ -203,10 +203,7 @@ RoomInfoListItem::init(QWidget *parent) }); } -RoomInfoListItem::RoomInfoListItem(QString room_id, - const RoomInfo &info, - QSharedPointer userSettings, - QWidget *parent) +RoomInfoListItem::RoomInfoListItem(QString room_id, const RoomInfo &info, QWidget *parent) : QWidget(parent) , roomType_{info.is_invite ? RoomType::Invited : RoomType::Joined} , roomId_(std::move(room_id)) @@ -214,7 +211,6 @@ RoomInfoListItem::RoomInfoListItem(QString room_id, , isPressed_(false) , unreadMsgCount_(0) , unreadHighlightedMsgCount_(0) - , settings(userSettings) { init(parent); } @@ -451,7 +447,7 @@ RoomInfoListItem::calculateImportance() const // returns ImportanceDisabled or Invite if (isInvite()) { return Invite; - } else if (!settings->sortByImportance()) { + } else if (!ChatPage::instance()->userSettings()->sortByImportance()) { return ImportanceDisabled; } else if (unreadHighlightedMsgCount_) { return NewMentions; diff --git a/src/RoomInfoListItem.h b/src/RoomInfoListItem.h index e609f4d8..da5a1bc4 100644 --- a/src/RoomInfoListItem.h +++ b/src/RoomInfoListItem.h @@ -64,10 +64,7 @@ class RoomInfoListItem : public QWidget Q_PROPERTY(QColor btnTextColor READ btnTextColor WRITE setBtnTextColor) public: - RoomInfoListItem(QString room_id, - const RoomInfo &info, - QSharedPointer userSettings, - QWidget *parent = nullptr); + RoomInfoListItem(QString room_id, const RoomInfo &info, QWidget *parent = nullptr); void updateUnreadMessageCount(int count, int highlightedCount); void clearUnreadMessageCount() { updateUnreadMessageCount(0, 0); }; @@ -220,6 +217,4 @@ private: QColor bubbleBgColor_; QColor bubbleFgColor_; - - QSharedPointer settings; }; diff --git a/src/RoomList.cpp b/src/RoomList.cpp index b4c507b5..8c9e296f 100644 --- a/src/RoomList.cpp +++ b/src/RoomList.cpp @@ -35,7 +35,6 @@ RoomList::RoomList(QSharedPointer userSettings, QWidget *parent) : QWidget(parent) - , settings(userSettings) { topLayout_ = new QVBoxLayout(this); topLayout_->setSpacing(0); @@ -76,7 +75,7 @@ RoomList::RoomList(QSharedPointer userSettings, QWidget *parent) void RoomList::addRoom(const QString &room_id, const RoomInfo &info) { - auto room_item = new RoomInfoListItem(room_id, info, settings, scrollArea_); + auto room_item = new RoomInfoListItem(room_id, info, scrollArea_); room_item->setRoomName(QString::fromStdString(std::move(info.name))); connect(room_item, &RoomInfoListItem::clicked, this, &RoomList::highlightSelectedRoom); @@ -84,7 +83,7 @@ RoomList::addRoom(const QString &room_id, const RoomInfo &info) MainWindow::instance()->openLeaveRoomDialog(room_id); }); - QSharedPointer roomWidget(room_item); + QSharedPointer roomWidget(room_item, &QObject::deleteLater); rooms_.emplace(room_id, roomWidget); rooms_sort_cache_.push_back(roomWidget); @@ -164,11 +163,6 @@ RoomList::initialize(const QMap &info) // prevent flickering and save time sorting over and over again setUpdatesEnabled(false); - disconnect(settings.data(), - &UserSettings::roomSortingChanged, - this, - &RoomList::sortRoomsByLastMessage); - for (auto it = info.begin(); it != info.end(); it++) { if (it.value().is_invite) addInvitedRoom(it.key(), it.value()); @@ -179,10 +173,6 @@ RoomList::initialize(const QMap &info) for (auto it = info.begin(); it != info.end(); it++) updateRoomDescription(it.key(), it.value().msgInfo); - connect(settings.data(), - &UserSettings::roomSortingChanged, - this, - &RoomList::sortRoomsByLastMessage); setUpdatesEnabled(true); if (rooms_.empty()) @@ -505,7 +495,7 @@ RoomList::updateRoom(const QString &room_id, const RoomInfo &info) void RoomList::addInvitedRoom(const QString &room_id, const RoomInfo &info) { - auto room_item = new RoomInfoListItem(room_id, info, settings, scrollArea_); + auto room_item = new RoomInfoListItem(room_id, info, scrollArea_); connect(room_item, &RoomInfoListItem::acceptInvite, this, &RoomList::acceptInvite); connect(room_item, &RoomInfoListItem::declineInvite, this, &RoomList::declineInvite); diff --git a/src/RoomList.h b/src/RoomList.h index d3470666..d50c7de1 100644 --- a/src/RoomList.h +++ b/src/RoomList.h @@ -104,5 +104,4 @@ private: QString selectedRoom_; bool isSortPending_ = false; - QSharedPointer settings; }; diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index 7c81ca8f..783584c9 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -30,7 +30,7 @@ namespace msgs = mtx::events::msg; void TimelineViewManager::updateEncryptedDescriptions() { - auto decrypt = settings->decryptSidebar(); + auto decrypt = ChatPage::instance()->userSettings()->decryptSidebar(); QHash>::iterator i; for (i = models.begin(); i != models.end(); ++i) { auto ptr = i.value(); @@ -47,10 +47,10 @@ TimelineViewManager::updateColorPalette() { userColors.clear(); - if (settings->theme() == "light") { + if (ChatPage::instance()->userSettings()->theme() == "light") { view->rootContext()->setContextProperty("currentActivePalette", QPalette()); view->rootContext()->setContextProperty("currentInactivePalette", QPalette()); - } else if (settings->theme() == "dark") { + } else if (ChatPage::instance()->userSettings()->theme() == "dark") { view->rootContext()->setContextProperty("currentActivePalette", QPalette()); view->rootContext()->setContextProperty("currentInactivePalette", QPalette()); } else { @@ -84,14 +84,11 @@ TimelineViewManager::userStatus(QString id) const return QString::fromStdString(cache::statusMessage(id.toStdString())); } -TimelineViewManager::TimelineViewManager(QSharedPointer userSettings, - CallManager *callManager, - ChatPage *parent) +TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *parent) : imgProvider(new MxcImageProvider()) , colorImgProvider(new ColorImageProvider()) , blurhashProvider(new BlurhashProvider()) , callManager_(callManager) - , settings(userSettings) { qRegisterMetaType(); qRegisterMetaType(); @@ -133,7 +130,7 @@ TimelineViewManager::TimelineViewManager(QSharedPointer userSettin }); qmlRegisterSingletonType( "im.nheko", 1, 0, "Settings", [](QQmlEngine *, QJSEngine *) -> QObject * { - return self->settings.data(); + return ChatPage::instance()->userSettings().data(); }); qRegisterMetaType(); @@ -284,7 +281,8 @@ TimelineViewManager::addRoom(const QString &room_id) { if (!models.contains(room_id)) { QSharedPointer newRoom(new TimelineModel(this, room_id)); - newRoom->setDecryptDescription(settings->decryptSidebar()); + newRoom->setDecryptDescription( + ChatPage::instance()->userSettings()->decryptSidebar()); connect(newRoom.data(), &TimelineModel::newEncryptedImage, @@ -461,7 +459,7 @@ TimelineViewManager::queueTextMessage(const QString &msg) mtx::events::msg::Text text = {}; text.body = msg.trimmed().toStdString(); - if (settings->markdown()) { + if (ChatPage::instance()->userSettings()->markdown()) { text.formatted_body = utils::markdownToHtml(msg).toStdString(); // Don't send formatted_body, when we don't need to @@ -489,7 +487,7 @@ TimelineViewManager::queueTextMessage(const QString &msg) // NOTE(Nico): rich replies always need a formatted_body! text.format = "org.matrix.custom.html"; - if (settings->markdown()) + if (ChatPage::instance()->userSettings()->markdown()) text.formatted_body = utils::getFormattedQuoteBody(related, utils::markdownToHtml(msg)) .toStdString(); @@ -512,7 +510,8 @@ TimelineViewManager::queueEmoteMessage(const QString &msg) mtx::events::msg::Emote emote; emote.body = msg.trimmed().toStdString(); - if (html != msg.trimmed().toHtmlEscaped() && settings->markdown()) { + if (html != msg.trimmed().toHtmlEscaped() && + ChatPage::instance()->userSettings()->markdown()) { emote.formatted_body = html.toStdString(); emote.format = "org.matrix.custom.html"; } diff --git a/src/timeline/TimelineViewManager.h b/src/timeline/TimelineViewManager.h index 9a2a6467..5e441562 100644 --- a/src/timeline/TimelineViewManager.h +++ b/src/timeline/TimelineViewManager.h @@ -41,9 +41,7 @@ class TimelineViewManager : public QObject Q_PROPERTY(bool isMicMuted READ isMicMuted NOTIFY micMuteChanged) public: - TimelineViewManager(QSharedPointer userSettings, - CallManager *callManager, - ChatPage *parent = nullptr); + TimelineViewManager(CallManager *callManager, ChatPage *parent = nullptr); QWidget *getWidget() const { return container; } void sync(const mtx::responses::Rooms &rooms); @@ -176,7 +174,6 @@ private: bool isInitialSync_ = true; bool isNarrowView_ = false; - QSharedPointer settings; QHash userColors; QHash> dvList;