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

index f8d3272d..850941ae 100644 --- a/src/timeline/widgets/FileItem.cpp +++ b/src/timeline/widgets/FileItem.cpp
@@ -50,8 +50,6 @@ FileItem::init() icon_.addFile(":/icons/icons/ui/arrow-pointing-down.png"); setFixedHeight(Height); - - connect(this, &FileItem::fileDownloadedCb, this, &FileItem::fileDownloaded); } FileItem::FileItem(const mtx::events::RoomEvent<mtx::events::msg::File> &event, QWidget *parent) @@ -110,19 +108,22 @@ FileItem::mousePressEvent(QMouseEvent *event) if (filenameToSave_.isEmpty()) return; + auto proxy = std::make_shared<MediaProxy>(); + connect(proxy.get(), &MediaProxy::fileDownloaded, this, &FileItem::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::ui()->warn("failed to retrieve m.file content: {}", - url_.toString().toStdString()); + url.toString().toStdString()); return; } - emit fileDownloadedCb(QByteArray(data.data(), data.size())); + emit proxy->fileDownloaded(QByteArray(data.data(), data.size())); }); } else { openUrl();