summary refs log tree commit diff
path: root/src/timeline/widgets/AudioItem.cpp
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/timeline/widgets/AudioItem.cpp
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/timeline/widgets/AudioItem.cpp')
-rw-r--r--src/timeline/widgets/AudioItem.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/timeline/widgets/AudioItem.cpp b/src/timeline/widgets/AudioItem.cpp

index 1e3eb0f0..0c4bf9e4 100644 --- a/src/timeline/widgets/AudioItem.cpp +++ b/src/timeline/widgets/AudioItem.cpp
@@ -55,7 +55,6 @@ AudioItem::init() player_->setVolume(100); player_->setNotifyInterval(1000); - connect(this, &AudioItem::fileDownloadedCb, this, &AudioItem::fileDownloaded); connect(player_, &QMediaPlayer::stateChanged, this, [this](QMediaPlayer::State state) { if (state == QMediaPlayer::StoppedState) { state_ = AudioState::Play; @@ -120,19 +119,22 @@ AudioItem::mousePressEvent(QMouseEvent *event) if (filenameToSave_.isEmpty()) return; + auto proxy = std::make_shared<MediaProxy>(); + connect(proxy.get(), &MediaProxy::fileDownloaded, this, &AudioItem::fileDownloaded); + http::client()->download( url_.toString().toStdString(), - [this](const std::string &data, - const std::string &, - const std::string &, - mtx::http::RequestErr err) { + [proxy = std::move(proxy), url = url_](const std::string &data, + const std::string &, + const std::string &, + mtx::http::RequestErr err) { if (err) { nhlog::net()->info("failed to retrieve m.audio content: {}", - url_.toString().toStdString()); + url.toString().toStdString()); return; } - emit fileDownloadedCb(QByteArray(data.data(), data.size())); + emit proxy->fileDownloaded(QByteArray(data.data(), data.size())); }); } }