Browse Source

fix(model): take QObject receiver argument to interface signal connection macro

receiver QObject is used by Qt to automatically deregister the connection when
the receiver is destroyed. Forward it on to Qt's connect.
reviewable/pr5545/r2
Anthony Bilinski 6 years ago
parent
commit
24e4ec3751
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 6
      src/core/toxcall.cpp
  2. 8
      src/model/about/aboutfriend.cpp
  3. 8
      src/model/interface.h
  4. 2
      src/widget/about/aboutfriendform.cpp
  5. 8
      src/widget/form/profileform.cpp
  6. 3
      src/widget/widget.cpp

6
src/core/toxcall.cpp

@ -139,7 +139,7 @@ ToxFriendCall::ToxFriendCall(uint32_t FriendNum, bool VideoEnabled, CoreAV& av,
qDebug() << "Audio input connection not working"; qDebug() << "Audio input connection not working";
} }
audioSinkInvalid = sink->connectTo_invalidated([this]() { this->onAudioSinkInvalidated(); }); audioSinkInvalid = sink->connectTo_invalidated(this, [this]() { this->onAudioSinkInvalidated(); });
// register video // register video
if (videoEnabled) { if (videoEnabled) {
@ -183,7 +183,7 @@ void ToxFriendCall::onAudioSinkInvalidated()
{ {
auto newSink = audio.makeSink(); auto newSink = audio.makeSink();
audioSinkInvalid = newSink->connectTo_invalidated([this]() { this->onAudioSinkInvalidated(); }); audioSinkInvalid = newSink->connectTo_invalidated(this, [this]() { this->onAudioSinkInvalidated(); });
sink = std::move(newSink); sink = std::move(newSink);
} }
@ -269,7 +269,7 @@ void ToxGroupCall::removePeer(ToxPk peerId)
void ToxGroupCall::addPeer(ToxPk peerId) void ToxGroupCall::addPeer(ToxPk peerId)
{ {
std::unique_ptr<IAudioSink> newSink = audio.makeSink(); std::unique_ptr<IAudioSink> newSink = audio.makeSink();
QMetaObject::Connection con = newSink->connectTo_invalidated([this, peerId]() { this->onAudioSinkInvalidated(peerId); }); QMetaObject::Connection con = newSink->connectTo_invalidated(this, [this, peerId]() { this->onAudioSinkInvalidated(peerId); });
peers.emplace(peerId, std::move(newSink)); peers.emplace(peerId, std::move(newSink));
sinkInvalid.insert({peerId, con}); sinkInvalid.insert({peerId, con});

8
src/model/about/aboutfriend.cpp

@ -28,17 +28,17 @@ AboutFriend::AboutFriend(const Friend* f, IFriendSettings* const s)
: f{f} : f{f}
, settings{s} , settings{s}
{ {
s->connectTo_contactNoteChanged([=](const ToxPk& pk, const QString& note) { s->connectTo_contactNoteChanged(this, [=](const ToxPk& pk, const QString& note) {
emit noteChanged(note); emit noteChanged(note);
}); });
s->connectTo_autoAcceptCallChanged( s->connectTo_autoAcceptCallChanged(this,
[=](const ToxPk& pk, IFriendSettings::AutoAcceptCallFlags flag) { [=](const ToxPk& pk, IFriendSettings::AutoAcceptCallFlags flag) {
emit autoAcceptCallChanged(flag); emit autoAcceptCallChanged(flag);
}); });
s->connectTo_autoAcceptDirChanged([=](const ToxPk& pk, const QString& dir) { s->connectTo_autoAcceptDirChanged(this, [=](const ToxPk& pk, const QString& dir) {
emit autoAcceptDirChanged(dir); emit autoAcceptDirChanged(dir);
}); });
s->connectTo_autoGroupInviteChanged([=](const ToxPk& pk, bool enable) { s->connectTo_autoGroupInviteChanged(this, [=](const ToxPk& pk, bool enable) {
emit autoGroupInviteChanged(enable); emit autoGroupInviteChanged(enable);
}); });
} }

8
src/model/interface.h

@ -50,7 +50,7 @@
*/ */
#define DECLARE_SIGNAL(name, ...) \ #define DECLARE_SIGNAL(name, ...) \
using Slot_##name = std::function<void (__VA_ARGS__)>; \ using Slot_##name = std::function<void (__VA_ARGS__)>; \
virtual QMetaObject::Connection connectTo_##name(Slot_##name slot) const = 0 virtual QMetaObject::Connection connectTo_##name(QObject *receiver, Slot_##name slot) const = 0
/** /**
* @def DECLARE_SIGNAL * @def DECLARE_SIGNAL
@ -58,7 +58,7 @@
*/ */
#define DECLARE_SIGNAL(name, ...) \ #define DECLARE_SIGNAL(name, ...) \
using Slot_##name = std::function<void (__VA_ARGS__)>; \ using Slot_##name = std::function<void (__VA_ARGS__)>; \
virtual QMetaObject::Connection connectTo_##name(Slot_##name slot) const = 0 virtual QMetaObject::Connection connectTo_##name(QObject *receiver, Slot_##name slot) const = 0
/** /**
* @def SIGNAL_IMPL * @def SIGNAL_IMPL
@ -67,8 +67,8 @@
#define SIGNAL_IMPL(classname, name, ...) \ #define SIGNAL_IMPL(classname, name, ...) \
using Slot_##name = std::function<void (__VA_ARGS__)>; \ using Slot_##name = std::function<void (__VA_ARGS__)>; \
Q_SIGNAL void name(__VA_ARGS__); \ Q_SIGNAL void name(__VA_ARGS__); \
QMetaObject::Connection connectTo_##name(Slot_##name slot) const override { \ QMetaObject::Connection connectTo_##name(QObject *receiver, Slot_##name slot) const override { \
connect(this, &classname::name, slot); \ return connect(this, &classname::name, receiver, slot); \
} }
#endif // INTERFACE_H #endif // INTERFACE_H

2
src/widget/about/aboutfriendform.cpp

@ -41,7 +41,7 @@ AboutFriendForm::AboutFriendForm(std::unique_ptr<IAboutFriend> _about, QWidget*
connect(ui->autogroupinvite, &QCheckBox::clicked, this, &AboutFriendForm::onAutoGroupInvite); connect(ui->autogroupinvite, &QCheckBox::clicked, this, &AboutFriendForm::onAutoGroupInvite);
connect(ui->selectSaveDir, &QPushButton::clicked, this, &AboutFriendForm::onSelectDirClicked); connect(ui->selectSaveDir, &QPushButton::clicked, this, &AboutFriendForm::onSelectDirClicked);
connect(ui->removeHistory, &QPushButton::clicked, this, &AboutFriendForm::onRemoveHistoryClicked); connect(ui->removeHistory, &QPushButton::clicked, this, &AboutFriendForm::onRemoveHistoryClicked);
about->connectTo_autoAcceptDirChanged([=](const QString& dir){ onAutoAcceptDirChanged(dir); }); about->connectTo_autoAcceptDirChanged(this, [=](const QString& dir){ onAutoAcceptDirChanged(dir); });
const QString dir = about->getAutoAcceptDir(); const QString dir = about->getAutoAcceptDir();
ui->autoacceptfile->setChecked(!dir.isEmpty()); ui->autoacceptfile->setChecked(!dir.isEmpty());

8
src/widget/form/profileform.cpp

@ -147,7 +147,7 @@ ProfileForm::ProfileForm(IProfileInfo* profileInfo, QWidget* parent)
connect(bodyUI->toxIdLabel, &CroppingLabel::clicked, this, &ProfileForm::copyIdClicked); connect(bodyUI->toxIdLabel, &CroppingLabel::clicked, this, &ProfileForm::copyIdClicked);
connect(toxId, &ClickableTE::clicked, this, &ProfileForm::copyIdClicked); connect(toxId, &ClickableTE::clicked, this, &ProfileForm::copyIdClicked);
connect(profileInfo, &IProfileInfo::idChanged, this, &ProfileForm::setToxId); profileInfo->connectTo_idChanged(this, [=](const ToxId& id) { setToxId(id); });
connect(bodyUI->userName, &QLineEdit::editingFinished, this, &ProfileForm::onUserNameEdited); connect(bodyUI->userName, &QLineEdit::editingFinished, this, &ProfileForm::onUserNameEdited);
connect(bodyUI->statusMessage, &QLineEdit::editingFinished, connect(bodyUI->statusMessage, &QLineEdit::editingFinished,
this, &ProfileForm::onStatusMessageEdited); this, &ProfileForm::onStatusMessageEdited);
@ -166,9 +166,11 @@ ProfileForm::ProfileForm(IProfileInfo* profileInfo, QWidget* parent)
connect(bodyUI->saveQr, &QPushButton::clicked, this, &ProfileForm::onSaveQrClicked); connect(bodyUI->saveQr, &QPushButton::clicked, this, &ProfileForm::onSaveQrClicked);
connect(bodyUI->copyQr, &QPushButton::clicked, this, &ProfileForm::onCopyQrClicked); connect(bodyUI->copyQr, &QPushButton::clicked, this, &ProfileForm::onCopyQrClicked);
connect(profileInfo, &IProfileInfo::usernameChanged, this, profileInfo->connectTo_usernameChanged(
this,
[=](const QString& val) { bodyUI->userName->setText(val); }); [=](const QString& val) { bodyUI->userName->setText(val); });
connect(profileInfo, &IProfileInfo::statusMessageChanged, this, profileInfo->connectTo_statusMessageChanged(
this,
[=](const QString& val) { bodyUI->statusMessage->setText(val); }); [=](const QString& val) { bodyUI->statusMessage->setText(val); });
for (QComboBox* cb : findChildren<QComboBox*>()) { for (QComboBox* cb : findChildren<QComboBox*>()) {

3
src/widget/widget.cpp

@ -1021,8 +1021,7 @@ void Widget::playNotificationSound(IAudioSink::Sound sound, bool loop)
} }
} }
connect(audioNotification.get(), &IAudioSink::finishedPlaying, this, audioNotification->connectTo_finishedPlaying(this, [this](){ cleanupNotificationSound(); });
&Widget::cleanupNotificationSound);
audioNotification->playMono16Sound(sound); audioNotification->playMono16Sound(sound);

Loading…
Cancel
Save