Fix crash on exit

This commit is contained in:
Nicolas Werner 2020-10-17 00:57:29 +02:00
parent bc7494473b
commit bd0deb7213
7 changed files with 21 additions and 45 deletions

View file

@ -73,6 +73,8 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
{ {
setObjectName("chatPage"); setObjectName("chatPage");
instance_ = this;
qRegisterMetaType<std::optional<mtx::crypto::EncryptedFile>>(); qRegisterMetaType<std::optional<mtx::crypto::EncryptedFile>>();
qRegisterMetaType<std::optional<RelatedInfo>>(); qRegisterMetaType<std::optional<RelatedInfo>>();
qRegisterMetaType<mtx::presence::PresenceState>(); qRegisterMetaType<mtx::presence::PresenceState>();
@ -124,7 +126,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
contentLayout_->setSpacing(0); contentLayout_->setSpacing(0);
contentLayout_->setMargin(0); contentLayout_->setMargin(0);
view_manager_ = new TimelineViewManager(userSettings_, &callManager_, this); view_manager_ = new TimelineViewManager(&callManager_, this);
contentLayout_->addWidget(view_manager_->getWidget()); contentLayout_->addWidget(view_manager_->getWidget());
@ -590,8 +592,6 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
connectCallMessage<mtx::events::msg::CallCandidates>(); connectCallMessage<mtx::events::msg::CallCandidates>();
connectCallMessage<mtx::events::msg::CallAnswer>(); connectCallMessage<mtx::events::msg::CallAnswer>();
connectCallMessage<mtx::events::msg::CallHangUp>(); connectCallMessage<mtx::events::msg::CallHangUp>();
instance_ = this;
} }
void void

View file

@ -203,10 +203,7 @@ RoomInfoListItem::init(QWidget *parent)
}); });
} }
RoomInfoListItem::RoomInfoListItem(QString room_id, RoomInfoListItem::RoomInfoListItem(QString room_id, const RoomInfo &info, QWidget *parent)
const RoomInfo &info,
QSharedPointer<UserSettings> userSettings,
QWidget *parent)
: QWidget(parent) : QWidget(parent)
, roomType_{info.is_invite ? RoomType::Invited : RoomType::Joined} , roomType_{info.is_invite ? RoomType::Invited : RoomType::Joined}
, roomId_(std::move(room_id)) , roomId_(std::move(room_id))
@ -214,7 +211,6 @@ RoomInfoListItem::RoomInfoListItem(QString room_id,
, isPressed_(false) , isPressed_(false)
, unreadMsgCount_(0) , unreadMsgCount_(0)
, unreadHighlightedMsgCount_(0) , unreadHighlightedMsgCount_(0)
, settings(userSettings)
{ {
init(parent); init(parent);
} }
@ -451,7 +447,7 @@ RoomInfoListItem::calculateImportance() const
// returns ImportanceDisabled or Invite // returns ImportanceDisabled or Invite
if (isInvite()) { if (isInvite()) {
return Invite; return Invite;
} else if (!settings->sortByImportance()) { } else if (!ChatPage::instance()->userSettings()->sortByImportance()) {
return ImportanceDisabled; return ImportanceDisabled;
} else if (unreadHighlightedMsgCount_) { } else if (unreadHighlightedMsgCount_) {
return NewMentions; return NewMentions;

View file

@ -64,10 +64,7 @@ class RoomInfoListItem : public QWidget
Q_PROPERTY(QColor btnTextColor READ btnTextColor WRITE setBtnTextColor) Q_PROPERTY(QColor btnTextColor READ btnTextColor WRITE setBtnTextColor)
public: public:
RoomInfoListItem(QString room_id, RoomInfoListItem(QString room_id, const RoomInfo &info, QWidget *parent = nullptr);
const RoomInfo &info,
QSharedPointer<UserSettings> userSettings,
QWidget *parent = nullptr);
void updateUnreadMessageCount(int count, int highlightedCount); void updateUnreadMessageCount(int count, int highlightedCount);
void clearUnreadMessageCount() { updateUnreadMessageCount(0, 0); }; void clearUnreadMessageCount() { updateUnreadMessageCount(0, 0); };
@ -220,6 +217,4 @@ private:
QColor bubbleBgColor_; QColor bubbleBgColor_;
QColor bubbleFgColor_; QColor bubbleFgColor_;
QSharedPointer<UserSettings> settings;
}; };

View file

@ -35,7 +35,6 @@
RoomList::RoomList(QSharedPointer<UserSettings> userSettings, QWidget *parent) RoomList::RoomList(QSharedPointer<UserSettings> userSettings, QWidget *parent)
: QWidget(parent) : QWidget(parent)
, settings(userSettings)
{ {
topLayout_ = new QVBoxLayout(this); topLayout_ = new QVBoxLayout(this);
topLayout_->setSpacing(0); topLayout_->setSpacing(0);
@ -76,7 +75,7 @@ RoomList::RoomList(QSharedPointer<UserSettings> userSettings, QWidget *parent)
void void
RoomList::addRoom(const QString &room_id, const RoomInfo &info) 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))); room_item->setRoomName(QString::fromStdString(std::move(info.name)));
connect(room_item, &RoomInfoListItem::clicked, this, &RoomList::highlightSelectedRoom); 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); MainWindow::instance()->openLeaveRoomDialog(room_id);
}); });
QSharedPointer<RoomInfoListItem> roomWidget(room_item); QSharedPointer<RoomInfoListItem> roomWidget(room_item, &QObject::deleteLater);
rooms_.emplace(room_id, roomWidget); rooms_.emplace(room_id, roomWidget);
rooms_sort_cache_.push_back(roomWidget); rooms_sort_cache_.push_back(roomWidget);
@ -164,11 +163,6 @@ RoomList::initialize(const QMap<QString, RoomInfo> &info)
// prevent flickering and save time sorting over and over again // prevent flickering and save time sorting over and over again
setUpdatesEnabled(false); setUpdatesEnabled(false);
disconnect(settings.data(),
&UserSettings::roomSortingChanged,
this,
&RoomList::sortRoomsByLastMessage);
for (auto it = info.begin(); it != info.end(); it++) { for (auto it = info.begin(); it != info.end(); it++) {
if (it.value().is_invite) if (it.value().is_invite)
addInvitedRoom(it.key(), it.value()); addInvitedRoom(it.key(), it.value());
@ -179,10 +173,6 @@ RoomList::initialize(const QMap<QString, RoomInfo> &info)
for (auto it = info.begin(); it != info.end(); it++) for (auto it = info.begin(); it != info.end(); it++)
updateRoomDescription(it.key(), it.value().msgInfo); updateRoomDescription(it.key(), it.value().msgInfo);
connect(settings.data(),
&UserSettings::roomSortingChanged,
this,
&RoomList::sortRoomsByLastMessage);
setUpdatesEnabled(true); setUpdatesEnabled(true);
if (rooms_.empty()) if (rooms_.empty())
@ -505,7 +495,7 @@ RoomList::updateRoom(const QString &room_id, const RoomInfo &info)
void void
RoomList::addInvitedRoom(const QString &room_id, const RoomInfo &info) 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::acceptInvite, this, &RoomList::acceptInvite);
connect(room_item, &RoomInfoListItem::declineInvite, this, &RoomList::declineInvite); connect(room_item, &RoomInfoListItem::declineInvite, this, &RoomList::declineInvite);

View file

@ -104,5 +104,4 @@ private:
QString selectedRoom_; QString selectedRoom_;
bool isSortPending_ = false; bool isSortPending_ = false;
QSharedPointer<UserSettings> settings;
}; };

View file

@ -30,7 +30,7 @@ namespace msgs = mtx::events::msg;
void void
TimelineViewManager::updateEncryptedDescriptions() TimelineViewManager::updateEncryptedDescriptions()
{ {
auto decrypt = settings->decryptSidebar(); auto decrypt = ChatPage::instance()->userSettings()->decryptSidebar();
QHash<QString, QSharedPointer<TimelineModel>>::iterator i; QHash<QString, QSharedPointer<TimelineModel>>::iterator i;
for (i = models.begin(); i != models.end(); ++i) { for (i = models.begin(); i != models.end(); ++i) {
auto ptr = i.value(); auto ptr = i.value();
@ -47,10 +47,10 @@ TimelineViewManager::updateColorPalette()
{ {
userColors.clear(); userColors.clear();
if (settings->theme() == "light") { if (ChatPage::instance()->userSettings()->theme() == "light") {
view->rootContext()->setContextProperty("currentActivePalette", QPalette()); view->rootContext()->setContextProperty("currentActivePalette", QPalette());
view->rootContext()->setContextProperty("currentInactivePalette", 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("currentActivePalette", QPalette());
view->rootContext()->setContextProperty("currentInactivePalette", QPalette()); view->rootContext()->setContextProperty("currentInactivePalette", QPalette());
} else { } else {
@ -84,14 +84,11 @@ TimelineViewManager::userStatus(QString id) const
return QString::fromStdString(cache::statusMessage(id.toStdString())); return QString::fromStdString(cache::statusMessage(id.toStdString()));
} }
TimelineViewManager::TimelineViewManager(QSharedPointer<UserSettings> userSettings, TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *parent)
CallManager *callManager,
ChatPage *parent)
: imgProvider(new MxcImageProvider()) : imgProvider(new MxcImageProvider())
, colorImgProvider(new ColorImageProvider()) , colorImgProvider(new ColorImageProvider())
, blurhashProvider(new BlurhashProvider()) , blurhashProvider(new BlurhashProvider())
, callManager_(callManager) , callManager_(callManager)
, settings(userSettings)
{ {
qRegisterMetaType<mtx::events::msg::KeyVerificationAccept>(); qRegisterMetaType<mtx::events::msg::KeyVerificationAccept>();
qRegisterMetaType<mtx::events::msg::KeyVerificationCancel>(); qRegisterMetaType<mtx::events::msg::KeyVerificationCancel>();
@ -133,7 +130,7 @@ TimelineViewManager::TimelineViewManager(QSharedPointer<UserSettings> userSettin
}); });
qmlRegisterSingletonType<UserSettings>( qmlRegisterSingletonType<UserSettings>(
"im.nheko", 1, 0, "Settings", [](QQmlEngine *, QJSEngine *) -> QObject * { "im.nheko", 1, 0, "Settings", [](QQmlEngine *, QJSEngine *) -> QObject * {
return self->settings.data(); return ChatPage::instance()->userSettings().data();
}); });
qRegisterMetaType<mtx::events::collections::TimelineEvents>(); qRegisterMetaType<mtx::events::collections::TimelineEvents>();
@ -284,7 +281,8 @@ TimelineViewManager::addRoom(const QString &room_id)
{ {
if (!models.contains(room_id)) { if (!models.contains(room_id)) {
QSharedPointer<TimelineModel> newRoom(new TimelineModel(this, room_id)); QSharedPointer<TimelineModel> newRoom(new TimelineModel(this, room_id));
newRoom->setDecryptDescription(settings->decryptSidebar()); newRoom->setDecryptDescription(
ChatPage::instance()->userSettings()->decryptSidebar());
connect(newRoom.data(), connect(newRoom.data(),
&TimelineModel::newEncryptedImage, &TimelineModel::newEncryptedImage,
@ -461,7 +459,7 @@ TimelineViewManager::queueTextMessage(const QString &msg)
mtx::events::msg::Text text = {}; mtx::events::msg::Text text = {};
text.body = msg.trimmed().toStdString(); text.body = msg.trimmed().toStdString();
if (settings->markdown()) { if (ChatPage::instance()->userSettings()->markdown()) {
text.formatted_body = utils::markdownToHtml(msg).toStdString(); text.formatted_body = utils::markdownToHtml(msg).toStdString();
// Don't send formatted_body, when we don't need to // 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! // NOTE(Nico): rich replies always need a formatted_body!
text.format = "org.matrix.custom.html"; text.format = "org.matrix.custom.html";
if (settings->markdown()) if (ChatPage::instance()->userSettings()->markdown())
text.formatted_body = text.formatted_body =
utils::getFormattedQuoteBody(related, utils::markdownToHtml(msg)) utils::getFormattedQuoteBody(related, utils::markdownToHtml(msg))
.toStdString(); .toStdString();
@ -512,7 +510,8 @@ TimelineViewManager::queueEmoteMessage(const QString &msg)
mtx::events::msg::Emote emote; mtx::events::msg::Emote emote;
emote.body = msg.trimmed().toStdString(); 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.formatted_body = html.toStdString();
emote.format = "org.matrix.custom.html"; emote.format = "org.matrix.custom.html";
} }

View file

@ -41,9 +41,7 @@ class TimelineViewManager : public QObject
Q_PROPERTY(bool isMicMuted READ isMicMuted NOTIFY micMuteChanged) Q_PROPERTY(bool isMicMuted READ isMicMuted NOTIFY micMuteChanged)
public: public:
TimelineViewManager(QSharedPointer<UserSettings> userSettings, TimelineViewManager(CallManager *callManager, ChatPage *parent = nullptr);
CallManager *callManager,
ChatPage *parent = nullptr);
QWidget *getWidget() const { return container; } QWidget *getWidget() const { return container; }
void sync(const mtx::responses::Rooms &rooms); void sync(const mtx::responses::Rooms &rooms);
@ -176,7 +174,6 @@ private:
bool isInitialSync_ = true; bool isInitialSync_ = true;
bool isNarrowView_ = false; bool isNarrowView_ = false;
QSharedPointer<UserSettings> settings;
QHash<QString, QColor> userColors; QHash<QString, QColor> userColors;
QHash<QString, QSharedPointer<DeviceVerificationFlow>> dvList; QHash<QString, QSharedPointer<DeviceVerificationFlow>> dvList;