Fix crash on exit

master
Nicolas Werner 4 years ago
parent bc7494473b
commit bd0deb7213
  1. 6
      src/ChatPage.cpp
  2. 8
      src/RoomInfoListItem.cpp
  3. 7
      src/RoomInfoListItem.h
  4. 16
      src/RoomList.cpp
  5. 1
      src/RoomList.h
  6. 23
      src/timeline/TimelineViewManager.cpp
  7. 5
      src/timeline/TimelineViewManager.h

@ -73,6 +73,8 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
{
setObjectName("chatPage");
instance_ = this;
qRegisterMetaType<std::optional<mtx::crypto::EncryptedFile>>();
qRegisterMetaType<std::optional<RelatedInfo>>();
qRegisterMetaType<mtx::presence::PresenceState>();
@ -124,7 +126,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> 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> userSettings, QWidget *parent)
connectCallMessage<mtx::events::msg::CallCandidates>();
connectCallMessage<mtx::events::msg::CallAnswer>();
connectCallMessage<mtx::events::msg::CallHangUp>();
instance_ = this;
}
void

@ -203,10 +203,7 @@ RoomInfoListItem::init(QWidget *parent)
});
}
RoomInfoListItem::RoomInfoListItem(QString room_id,
const RoomInfo &info,
QSharedPointer<UserSettings> 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;

@ -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> 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<UserSettings> settings;
};

@ -35,7 +35,6 @@
RoomList::RoomList(QSharedPointer<UserSettings> userSettings, QWidget *parent)
: QWidget(parent)
, settings(userSettings)
{
topLayout_ = new QVBoxLayout(this);
topLayout_->setSpacing(0);
@ -76,7 +75,7 @@ RoomList::RoomList(QSharedPointer<UserSettings> 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<RoomInfoListItem> roomWidget(room_item);
QSharedPointer<RoomInfoListItem> roomWidget(room_item, &QObject::deleteLater);
rooms_.emplace(room_id, 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
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<QString, RoomInfo> &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);

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

@ -30,7 +30,7 @@ namespace msgs = mtx::events::msg;
void
TimelineViewManager::updateEncryptedDescriptions()
{
auto decrypt = settings->decryptSidebar();
auto decrypt = ChatPage::instance()->userSettings()->decryptSidebar();
QHash<QString, QSharedPointer<TimelineModel>>::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> 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<mtx::events::msg::KeyVerificationAccept>();
qRegisterMetaType<mtx::events::msg::KeyVerificationCancel>();
@ -133,7 +130,7 @@ TimelineViewManager::TimelineViewManager(QSharedPointer<UserSettings> userSettin
});
qmlRegisterSingletonType<UserSettings>(
"im.nheko", 1, 0, "Settings", [](QQmlEngine *, QJSEngine *) -> QObject * {
return self->settings.data();
return ChatPage::instance()->userSettings().data();
});
qRegisterMetaType<mtx::events::collections::TimelineEvents>();
@ -284,7 +281,8 @@ TimelineViewManager::addRoom(const QString &room_id)
{
if (!models.contains(room_id)) {
QSharedPointer<TimelineModel> 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";
}

@ -41,9 +41,7 @@ class TimelineViewManager : public QObject
Q_PROPERTY(bool isMicMuted READ isMicMuted NOTIFY micMuteChanged)
public:
TimelineViewManager(QSharedPointer<UserSettings> 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<UserSettings> settings;
QHash<QString, QColor> userColors;
QHash<QString, QSharedPointer<DeviceVerificationFlow>> dvList;

Loading…
Cancel
Save