mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 23:53:58 +02:00
parent
2a1096d83c
commit
5feb381cb2
2 changed files with 44 additions and 13 deletions
|
@ -47,6 +47,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "lottie/lottie_animation.h"
|
||||
#include "app.h"
|
||||
|
||||
#include <QtCore/QBuffer>
|
||||
|
||||
namespace {
|
||||
|
||||
const auto kAnimatedStickerDimensions = QSize(
|
||||
|
@ -320,21 +322,33 @@ void DocumentOpenClickHandler::Open(
|
|||
return;
|
||||
}
|
||||
|
||||
const auto openFile = [&] {
|
||||
const auto media = data->createMediaView();
|
||||
const auto openImageInApp = [&] {
|
||||
if (data->size >= App::kImageSizeLimit) {
|
||||
return false;
|
||||
}
|
||||
const auto &location = data->location(true);
|
||||
if (data->size < App::kImageSizeLimit && location.accessEnable()) {
|
||||
if (!location.isEmpty() && location.accessEnable()) {
|
||||
const auto guard = gsl::finally([&] {
|
||||
location.accessDisable();
|
||||
});
|
||||
const auto path = location.name();
|
||||
if (Core::MimeTypeForFile(path).name().startsWith("image/") && QImageReader(path).canRead()) {
|
||||
if (Core::MimeTypeForFile(path).name().startsWith("image/")
|
||||
&& QImageReader(path).canRead()) {
|
||||
Core::App().showDocument(data, context);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
} else if (data->mimeString().startsWith("image/")
|
||||
&& !media->bytes().isEmpty()) {
|
||||
auto bytes = media->bytes();
|
||||
auto buffer = QBuffer(&bytes);
|
||||
if (QImageReader(&buffer).canRead()) {
|
||||
Core::App().showDocument(data, context);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
LaunchWithWarning(&data->session(), location.name(), context);
|
||||
return false;
|
||||
};
|
||||
const auto media = data->createMediaView();
|
||||
const auto &location = data->location(true);
|
||||
if (data->isTheme() && media->loaded(true)) {
|
||||
Core::App().showDocument(data, context);
|
||||
|
@ -352,11 +366,16 @@ void DocumentOpenClickHandler::Open(
|
|||
} else {
|
||||
Core::App().showDocument(data, context);
|
||||
}
|
||||
} else if (data->saveFromDataSilent()) {
|
||||
openFile();
|
||||
} else if (data->status == FileReady
|
||||
|| data->status == FileDownloadFailed) {
|
||||
DocumentSaveClickHandler::Save(origin, data);
|
||||
} else {
|
||||
data->saveFromDataSilent();
|
||||
if (!openImageInApp()) {
|
||||
if (!data->filepath(true).isEmpty()) {
|
||||
LaunchWithWarning(&data->session(), location.name(), context);
|
||||
} else if (data->status == FileReady
|
||||
|| data->status == FileDownloadFailed) {
|
||||
DocumentSaveClickHandler::Save(origin, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -197,8 +197,7 @@ void PaintImageProfile(QPainter &p, const QImage &image, QRect rect, QRect fill)
|
|||
});
|
||||
}
|
||||
|
||||
QPixmap PrepareStaticImage(const QString &path) {
|
||||
auto image = App::readImage(path, nullptr, false);
|
||||
QPixmap PrepareStaticImage(QImage image) {
|
||||
#if defined Q_OS_MAC && !defined OS_MAC_OLD
|
||||
if (image.width() > kMaxDisplayImageSize
|
||||
|| image.height() > kMaxDisplayImageSize) {
|
||||
|
@ -212,6 +211,14 @@ QPixmap PrepareStaticImage(const QString &path) {
|
|||
return App::pixmapFromImageInPlace(std::move(image));
|
||||
}
|
||||
|
||||
QPixmap PrepareStaticImage(const QString &path) {
|
||||
return PrepareStaticImage(App::readImage(path, nullptr, false));
|
||||
}
|
||||
|
||||
QPixmap PrepareStaticImage(const QByteArray &bytes) {
|
||||
return PrepareStaticImage(App::readImage(bytes, nullptr, false));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
struct OverlayWidget::SharedMedia {
|
||||
|
@ -2304,6 +2311,11 @@ void OverlayWidget::displayDocument(
|
|||
_staticContent = PrepareStaticImage(path);
|
||||
_touchbarDisplay.fire(TouchBarItemType::Photo);
|
||||
}
|
||||
} else if (!_documentMedia->bytes().isEmpty()) {
|
||||
_staticContent = PrepareStaticImage(_documentMedia->bytes());
|
||||
if (!_staticContent.isNull()) {
|
||||
_touchbarDisplay.fire(TouchBarItemType::Photo);
|
||||
}
|
||||
}
|
||||
location.accessDisable();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue