1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

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.
This commit is contained in:
Anthony Bilinski 2019-10-10 02:52:29 -07:00
parent 82a4f1b412
commit 24e4ec3751
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
6 changed files with 18 additions and 17 deletions

View File

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

View File

@ -28,17 +28,17 @@ AboutFriend::AboutFriend(const Friend* f, IFriendSettings* const s)
: f{f}
, settings{s}
{
s->connectTo_contactNoteChanged([=](const ToxPk& pk, const QString& note) {
s->connectTo_contactNoteChanged(this, [=](const ToxPk& pk, const QString& note) {
emit noteChanged(note);
});
s->connectTo_autoAcceptCallChanged(
s->connectTo_autoAcceptCallChanged(this,
[=](const ToxPk& pk, IFriendSettings::AutoAcceptCallFlags 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);
});
s->connectTo_autoGroupInviteChanged([=](const ToxPk& pk, bool enable) {
s->connectTo_autoGroupInviteChanged(this, [=](const ToxPk& pk, bool enable) {
emit autoGroupInviteChanged(enable);
});
}

View File

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

View File

@ -41,7 +41,7 @@ AboutFriendForm::AboutFriendForm(std::unique_ptr<IAboutFriend> _about, QWidget*
connect(ui->autogroupinvite, &QCheckBox::clicked, this, &AboutFriendForm::onAutoGroupInvite);
connect(ui->selectSaveDir, &QPushButton::clicked, this, &AboutFriendForm::onSelectDirClicked);
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();
ui->autoacceptfile->setChecked(!dir.isEmpty());

View File

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

View File

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