diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp
index 6195c24a..7234caa9 100644
--- a/src/timeline/TimelineViewManager.cpp
+++ b/src/timeline/TimelineViewManager.cpp
@@ -6,10 +6,12 @@
#include "TimelineViewManager.h"
#include <QDropEvent>
+#include <QFileDialog>
#include <QMetaType>
#include <QPalette>
#include <QQmlContext>
#include <QQmlEngine>
+#include <QStandardPaths>
#include <QString>
#include "BlurhashProvider.h"
@@ -32,7 +34,6 @@
#include "SingleImagePackModel.h"
#include "UserSettingsPage.h"
#include "UsersModel.h"
-#include "dialogs/ImageOverlay.h"
#include "emoji/EmojiModel.h"
#include "emoji/Provider.h"
#include "encryption/DeviceVerificationFlow.h"
@@ -331,11 +332,6 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
isInitialSync_ = true;
emit initialSyncChanged(true);
});
-
- connect(this,
- &TimelineViewManager::openImageOverlayInternalCb,
- this,
- &TimelineViewManager::openImageOverlayInternal);
}
void
@@ -416,23 +412,13 @@ TimelineViewManager::escapeEmoji(QString str) const
}
void
-TimelineViewManager::openImageOverlay(QString mxcUrl, QString eventId)
+TimelineViewManager::openImageOverlay(TimelineModel *room, QString mxcUrl, QString eventId)
{
if (mxcUrl.isEmpty()) {
return;
}
- MxcImageProvider::download(mxcUrl.remove(QStringLiteral("mxc://")),
- QSize(),
- [this, eventId](QString, QSize, QImage img, QString) {
- if (img.isNull()) {
- nhlog::ui()->error(
- "Error when retrieving image for overlay.");
- return;
- }
-
- emit openImageOverlayInternalCb(eventId, std::move(img));
- });
+ emit showImageOverlay(room, eventId, mxcUrl);
}
void
@@ -443,25 +429,46 @@ TimelineViewManager::openImagePackSettings(QString roomid)
}
void
-TimelineViewManager::openImageOverlayInternal(QString eventId, QImage img)
+TimelineViewManager::saveMedia(QString mxcUrl)
{
- auto pixmap = QPixmap::fromImage(img);
+ const QString downloadsFolder =
+ QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
+ const QString openLocation = downloadsFolder + "/" + mxcUrl.splitRef(u'/').constLast();
- auto imgDialog = new dialogs::ImageOverlay(pixmap);
- imgDialog->showFullScreen();
+ const QString filename = QFileDialog::getSaveFileName(getWidget(), {}, openLocation);
- auto room = rooms_->currentRoom();
- connect(imgDialog, &dialogs::ImageOverlay::saving, room, [eventId, imgDialog, room]() {
- // hide the overlay while presenting the save dialog for better
- // cross platform support.
- imgDialog->hide();
+ if (filename.isEmpty())
+ return;
- if (!room->saveMedia(eventId)) {
- imgDialog->show();
- } else {
- imgDialog->close();
- }
- });
+ const auto url = mxcUrl.toStdString();
+
+ http::client()->download(url,
+ [filename, url](const std::string &data,
+ const std::string &,
+ const std::string &,
+ mtx::http::RequestErr err) {
+ if (err) {
+ nhlog::net()->warn("failed to retrieve image {}: {} {}",
+ url,
+ err->matrix_error.error,
+ static_cast<int>(err->status_code));
+ return;
+ }
+
+ try {
+ QFile file(filename);
+
+ if (!file.open(QIODevice::WriteOnly))
+ return;
+
+ file.write(QByteArray(data.data(), (int)data.size()));
+ file.close();
+
+ return;
+ } catch (const std::exception &e) {
+ nhlog::ui()->warn("Error while saving file to: {}", e.what());
+ }
+ });
}
void
diff --git a/src/timeline/TimelineViewManager.h b/src/timeline/TimelineViewManager.h
index 47a72412..455702f4 100644
--- a/src/timeline/TimelineViewManager.h
+++ b/src/timeline/TimelineViewManager.h
@@ -60,8 +60,9 @@ public:
Q_INVOKABLE bool isInitialSync() const { return isInitialSync_; }
bool isWindowFocused() const { return isWindowFocused_; }
- Q_INVOKABLE void openImageOverlay(QString mxcUrl, QString eventId);
+ Q_INVOKABLE void openImageOverlay(TimelineModel *room, QString mxcUrl, QString eventId);
Q_INVOKABLE void openImagePackSettings(QString roomid);
+ Q_INVOKABLE void saveMedia(QString mxcUrl);
Q_INVOKABLE QColor userColor(QString id, QColor background);
Q_INVOKABLE QString escapeEmoji(QString str) const;
Q_INVOKABLE QString htmlEscape(QString str) const { return str.toHtmlEscaped(); }
@@ -85,13 +86,13 @@ signals:
void narrowViewChanged();
void focusChanged();
void focusInput();
- void openImageOverlayInternalCb(QString eventId, QImage img);
void openRoomMembersDialog(MemberList *members, TimelineModel *room);
void openRoomSettingsDialog(RoomSettings *settings);
void openInviteUsersDialog(InviteesModel *invitees);
void openProfile(UserProfile *profile);
void showImagePackSettings(TimelineModel *room, ImagePackListModel *packlist);
void openLeaveRoomDialog(QString roomid);
+ void showImageOverlay(TimelineModel *room, QString eventId, QString url);
public slots:
void updateReadReceipts(const QString &room_id, const std::vector<QString> &event_ids);
@@ -120,9 +121,6 @@ public slots:
RoomlistModel *rooms() { return rooms_; }
-private slots:
- void openImageOverlayInternal(QString eventId, QImage img);
-
private:
#ifdef USE_QUICK_VIEW
QQuickView *view;
|