|
|
@ -1,6 +1,8 @@ |
|
|
|
#include "TimelineViewManager.h" |
|
|
|
#include "TimelineViewManager.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <QFileDialog> |
|
|
|
#include <QMetaType> |
|
|
|
#include <QMetaType> |
|
|
|
|
|
|
|
#include <QMimeDatabase> |
|
|
|
#include <QQmlContext> |
|
|
|
#include <QQmlContext> |
|
|
|
|
|
|
|
|
|
|
|
#include "Logging.h" |
|
|
|
#include "Logging.h" |
|
|
@ -55,11 +57,17 @@ TimelineViewManager::setHistoryView(const QString &room_id) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void |
|
|
|
TimelineViewManager::openImageOverlay(QString url) const |
|
|
|
TimelineViewManager::openImageOverlay(QString mxcUrl, |
|
|
|
|
|
|
|
QString originalFilename, |
|
|
|
|
|
|
|
QString mimeType, |
|
|
|
|
|
|
|
qml_mtx_events::EventType eventType) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
QQuickImageResponse *imgResponse = |
|
|
|
QQuickImageResponse *imgResponse = |
|
|
|
imgProvider->requestImageResponse(url.remove("image://mxcimage/"), QSize()); |
|
|
|
imgProvider->requestImageResponse(mxcUrl.remove("mxc://"), QSize()); |
|
|
|
connect(imgResponse, &QQuickImageResponse::finished, this, [imgResponse]() { |
|
|
|
connect(imgResponse, |
|
|
|
|
|
|
|
&QQuickImageResponse::finished, |
|
|
|
|
|
|
|
this, |
|
|
|
|
|
|
|
[this, mxcUrl, originalFilename, mimeType, eventType, imgResponse]() { |
|
|
|
if (!imgResponse->errorString().isEmpty()) { |
|
|
|
if (!imgResponse->errorString().isEmpty()) { |
|
|
|
nhlog::ui()->error("Error when retrieving image for overlay: {}", |
|
|
|
nhlog::ui()->error("Error when retrieving image for overlay: {}", |
|
|
|
imgResponse->errorString().toStdString()); |
|
|
|
imgResponse->errorString().toStdString()); |
|
|
@ -69,9 +77,67 @@ TimelineViewManager::openImageOverlay(QString url) const |
|
|
|
|
|
|
|
|
|
|
|
auto imgDialog = new dialogs::ImageOverlay(pixmap); |
|
|
|
auto imgDialog = new dialogs::ImageOverlay(pixmap); |
|
|
|
imgDialog->show(); |
|
|
|
imgDialog->show(); |
|
|
|
// connect(imgDialog, &dialogs::ImageOverlay::saving, this,
|
|
|
|
connect(imgDialog, |
|
|
|
// &ImageItem::saveAs);
|
|
|
|
&dialogs::ImageOverlay::saving, |
|
|
|
Q_UNUSED(imgDialog); |
|
|
|
this, |
|
|
|
|
|
|
|
[this, mxcUrl, originalFilename, mimeType, eventType]() { |
|
|
|
|
|
|
|
saveMedia(mxcUrl, originalFilename, mimeType, eventType); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
|
|
|
TimelineViewManager::saveMedia(QString mxcUrl, |
|
|
|
|
|
|
|
QString originalFilename, |
|
|
|
|
|
|
|
QString mimeType, |
|
|
|
|
|
|
|
qml_mtx_events::EventType eventType) const |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QString dialogTitle; |
|
|
|
|
|
|
|
if (eventType == qml_mtx_events::EventType::ImageMessage) { |
|
|
|
|
|
|
|
dialogTitle = tr("Save image"); |
|
|
|
|
|
|
|
} else if (eventType == qml_mtx_events::EventType::VideoMessage) { |
|
|
|
|
|
|
|
dialogTitle = tr("Save video"); |
|
|
|
|
|
|
|
} else if (eventType == qml_mtx_events::EventType::AudioMessage) { |
|
|
|
|
|
|
|
dialogTitle = tr("Save audio"); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
dialogTitle = tr("Save file"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString filterString = QMimeDatabase().mimeTypeForName(mimeType).filterString(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto filename = |
|
|
|
|
|
|
|
QFileDialog::getSaveFileName(container, dialogTitle, originalFilename, filterString); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (filename.isEmpty()) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(), data.size())); |
|
|
|
|
|
|
|
file.close(); |
|
|
|
|
|
|
|
} catch (const std::exception &e) { |
|
|
|
|
|
|
|
nhlog::ui()->warn("Error while saving file to: {}", e.what()); |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|