summary refs log tree commit diff
path: root/src/dialogs
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-09-07 12:24:09 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-09-07 12:24:09 +0300
commit896fe069b6e1f0406ba483dd82480e32ffe2a5df (patch)
tree53aa546185b39970093b180344d75b775ca5b7f3 /src/dialogs
parentPut back removed links (diff)
downloadnheko-896fe069b6e1f0406ba483dd82480e32ffe2a5df.tar.xz
Use proxy objects on lambdas instead of raw pointers
When the object is destroyed the connections will be removed
automatically by Qt.

fixes #433
Diffstat (limited to 'src/dialogs')
-rw-r--r--src/dialogs/RoomSettings.cpp56
-rw-r--r--src/dialogs/RoomSettings.h6
2 files changed, 32 insertions, 30 deletions
diff --git a/src/dialogs/RoomSettings.cpp b/src/dialogs/RoomSettings.cpp

index 0a1c93e6..4e56b130 100644 --- a/src/dialogs/RoomSettings.cpp +++ b/src/dialogs/RoomSettings.cpp
@@ -90,20 +90,6 @@ EditModal::EditModal(const QString &roomId, QWidget *parent) labelLayout->addWidget(errorField_); layout->addLayout(labelLayout); - connect(this, &EditModal::stateEventErrorCb, this, [this](const QString &msg) { - errorField_->setText(msg); - errorField_->show(); - }); - connect(this, &EditModal::nameEventSentCb, this, [this](const QString &newName) { - errorField_->hide(); - emit nameChanged(newName); - close(); - }); - connect(this, &EditModal::topicEventSentCb, this, [this]() { - errorField_->hide(); - close(); - }); - connect(applyBtn_, &QPushButton::clicked, [this]() { // Check if the values are changed from the originals. auto newName = nameInput_->text().trimmed(); @@ -117,6 +103,21 @@ EditModal::EditModal(const QString &roomId, QWidget *parent) } using namespace mtx::events; + auto proxy = std::make_shared<ThreadProxy>(); + connect(proxy.get(), &ThreadProxy::topicEventSent, this, [this]() { + errorField_->hide(); + close(); + }); + connect( + proxy.get(), &ThreadProxy::nameEventSent, this, [this](const QString &newName) { + errorField_->hide(); + emit nameChanged(newName); + close(); + }); + connect(proxy.get(), &ThreadProxy::error, this, [this](const QString &msg) { + errorField_->setText(msg); + errorField_->show(); + }); if (newName != initialName_ && !newName.isEmpty()) { state::Name body; @@ -125,15 +126,15 @@ EditModal::EditModal(const QString &roomId, QWidget *parent) http::client()->send_state_event<state::Name, EventType::RoomName>( roomId_.toStdString(), body, - [this, newName](const mtx::responses::EventId &, - mtx::http::RequestErr err) { + [proxy, newName](const mtx::responses::EventId &, + mtx::http::RequestErr err) { if (err) { - emit stateEventErrorCb( + emit proxy->error( QString::fromStdString(err->matrix_error.error)); return; } - emit nameEventSentCb(newName); + emit proxy->nameEventSent(newName); }); } @@ -144,14 +145,14 @@ EditModal::EditModal(const QString &roomId, QWidget *parent) http::client()->send_state_event<state::Topic, EventType::RoomTopic>( roomId_.toStdString(), body, - [this](const mtx::responses::EventId &, mtx::http::RequestErr err) { + [proxy](const mtx::responses::EventId &, mtx::http::RequestErr err) { if (err) { - emit stateEventErrorCb( + emit proxy->error( QString::fromStdString(err->matrix_error.error)); return; } - emit topicEventSentCb(); + emit proxy->topicEventSent(); }); } }); @@ -366,15 +367,15 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent) connect(filter, &ClickableFilter::clicked, this, &RoomSettings::updateAvatar); } - auto roomNameLabel = new QLabel(QString::fromStdString(info_.name), this); - roomNameLabel->setFont(doubleFont); + roomNameLabel_ = new QLabel(QString::fromStdString(info_.name), this); + roomNameLabel_->setFont(doubleFont); auto membersLabel = new QLabel(tr("%n member(s)", "", info_.member_count), this); auto textLayout = new QVBoxLayout; - textLayout->addWidget(roomNameLabel); + textLayout->addWidget(roomNameLabel_); textLayout->addWidget(membersLabel); - textLayout->setAlignment(roomNameLabel, Qt::AlignCenter | Qt::AlignTop); + textLayout->setAlignment(roomNameLabel_, Qt::AlignCenter | Qt::AlignTop); textLayout->setAlignment(membersLabel, Qt::AlignCenter | Qt::AlignTop); textLayout->setSpacing(TEXT_SPACING); textLayout->setMargin(0); @@ -458,8 +459,9 @@ RoomSettings::setupEditButton() modal->setFields(QString::fromStdString(info_.name), QString::fromStdString(info_.topic)); modal->show(); - connect(modal, &EditModal::nameChanged, this, [](const QString &newName) { - Q_UNUSED(newName); + connect(modal, &EditModal::nameChanged, this, [this](const QString &newName) { + if (roomNameLabel_) + roomNameLabel_->setText(newName); }); }); diff --git a/src/dialogs/RoomSettings.h b/src/dialogs/RoomSettings.h
index ac9097dd..dd729250 100644 --- a/src/dialogs/RoomSettings.h +++ b/src/dialogs/RoomSettings.h
@@ -53,6 +53,8 @@ class ThreadProxy : public QObject signals: void error(const QString &msg); void avatarChanged(const QImage &img); + void nameEventSent(const QString &); + void topicEventSent(); }; class EditModal : public QWidget @@ -66,9 +68,6 @@ public: signals: void nameChanged(const QString &roomName); - void nameEventSentCb(const QString &newName); - void topicEventSentCb(); - void stateEventErrorCb(const QString &msg); private: QString roomId_; @@ -138,6 +137,7 @@ private: QString room_id_; QImage avatarImg_; + QLabel *roomNameLabel_ = nullptr; QLabel *errorLabel_ = nullptr; LoadingIndicator *spinner_ = nullptr;