summary refs log tree commit diff
path: root/src/timeline/TimelineViewManager.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-04-05 13:58:00 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2021-04-05 13:58:00 +0200
commitec6f0f92964614588ea88e13a1030952bec904e7 (patch)
tree9dd0f306d1334eee0794cb6fc09398e596a240fc /src/timeline/TimelineViewManager.cpp
parentFix download button (diff)
downloadnheko-ec6f0f92964614588ea88e13a1030952bec904e7.tar.xz
Don't use direct image response objects anymore
Diffstat (limited to 'src/timeline/TimelineViewManager.cpp')
-rw-r--r--src/timeline/TimelineViewManager.cpp60
1 files changed, 34 insertions, 26 deletions
diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp

index 3ed1c21c..45abff98 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp
@@ -256,6 +256,11 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par isInitialSync_ = true; emit initialSyncChanged(true); }); + + connect(this, + &TimelineViewManager::openImageOverlayInternalCb, + this, + &TimelineViewManager::openImageOverlayInternal); } void @@ -350,37 +355,40 @@ TimelineViewManager::escapeEmoji(QString str) const } void -TimelineViewManager::openImageOverlay(QString mxcUrl, QString eventId) const +TimelineViewManager::openImageOverlay(QString mxcUrl, QString eventId) { if (mxcUrl.isEmpty()) { return; } - QQuickImageResponse *imgResponse = - imgProvider->requestImageResponse(mxcUrl.remove("mxc://"), QSize()); - connect(imgResponse, &QQuickImageResponse::finished, this, [this, eventId, imgResponse]() { - if (!imgResponse->errorString().isEmpty()) { - nhlog::ui()->error("Error when retrieving image for overlay: {}", - imgResponse->errorString().toStdString()); - return; - } - auto pixmap = QPixmap::fromImage(imgResponse->textureFactory()->image()); - auto imgDialog = new dialogs::ImageOverlay(pixmap); - imgDialog->showFullScreen(); - connect(imgDialog, - &dialogs::ImageOverlay::saving, - timeline_, - [this, eventId, imgDialog]() { - // hide the overlay while presenting the save dialog for better - // cross platform support. - imgDialog->hide(); + MxcImageProvider::download( + mxcUrl.remove("mxc://"), QSize(), [this, eventId](QString, QSize, QImage img, QString) { + if (img.isNull()) { + nhlog::ui()->error("Error when retrieving image for overlay."); + return; + } - if (!timeline_->saveMedia(eventId)) { - imgDialog->show(); - } else { - imgDialog->close(); - } - }); + emit openImageOverlayInternalCb(eventId, std::move(img)); + }); +} + +void +TimelineViewManager::openImageOverlayInternal(QString eventId, QImage img) +{ + auto pixmap = QPixmap::fromImage(img); + + auto imgDialog = new dialogs::ImageOverlay(pixmap); + imgDialog->showFullScreen(); + connect(imgDialog, &dialogs::ImageOverlay::saving, timeline_, [this, eventId, imgDialog]() { + // hide the overlay while presenting the save dialog for better + // cross platform support. + imgDialog->hide(); + + if (!timeline_->saveMedia(eventId)) { + imgDialog->show(); + } else { + imgDialog->close(); + } }); } @@ -597,4 +605,4 @@ void TimelineViewManager::focusTimeline() { getWidget()->setFocus(); -} \ No newline at end of file +}