mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-08 08:04:08 +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 "lottie/lottie_animation.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
|
|
||||||
|
#include <QtCore/QBuffer>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
const auto kAnimatedStickerDimensions = QSize(
|
const auto kAnimatedStickerDimensions = QSize(
|
||||||
|
@ -320,21 +322,33 @@ void DocumentOpenClickHandler::Open(
|
||||||
return;
|
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);
|
const auto &location = data->location(true);
|
||||||
if (data->size < App::kImageSizeLimit && location.accessEnable()) {
|
if (!location.isEmpty() && location.accessEnable()) {
|
||||||
const auto guard = gsl::finally([&] {
|
const auto guard = gsl::finally([&] {
|
||||||
location.accessDisable();
|
location.accessDisable();
|
||||||
});
|
});
|
||||||
const auto path = location.name();
|
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);
|
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);
|
const auto &location = data->location(true);
|
||||||
if (data->isTheme() && media->loaded(true)) {
|
if (data->isTheme() && media->loaded(true)) {
|
||||||
Core::App().showDocument(data, context);
|
Core::App().showDocument(data, context);
|
||||||
|
@ -352,12 +366,17 @@ void DocumentOpenClickHandler::Open(
|
||||||
} else {
|
} else {
|
||||||
Core::App().showDocument(data, context);
|
Core::App().showDocument(data, context);
|
||||||
}
|
}
|
||||||
} else if (data->saveFromDataSilent()) {
|
} else {
|
||||||
openFile();
|
data->saveFromDataSilent();
|
||||||
|
if (!openImageInApp()) {
|
||||||
|
if (!data->filepath(true).isEmpty()) {
|
||||||
|
LaunchWithWarning(&data->session(), location.name(), context);
|
||||||
} else if (data->status == FileReady
|
} else if (data->status == FileReady
|
||||||
|| data->status == FileDownloadFailed) {
|
|| data->status == FileDownloadFailed) {
|
||||||
DocumentSaveClickHandler::Save(origin, data);
|
DocumentSaveClickHandler::Save(origin, data);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DocumentOpenClickHandler::onClickImpl() const {
|
void DocumentOpenClickHandler::onClickImpl() const {
|
||||||
|
|
|
@ -197,8 +197,7 @@ void PaintImageProfile(QPainter &p, const QImage &image, QRect rect, QRect fill)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap PrepareStaticImage(const QString &path) {
|
QPixmap PrepareStaticImage(QImage image) {
|
||||||
auto image = App::readImage(path, nullptr, false);
|
|
||||||
#if defined Q_OS_MAC && !defined OS_MAC_OLD
|
#if defined Q_OS_MAC && !defined OS_MAC_OLD
|
||||||
if (image.width() > kMaxDisplayImageSize
|
if (image.width() > kMaxDisplayImageSize
|
||||||
|| image.height() > kMaxDisplayImageSize) {
|
|| image.height() > kMaxDisplayImageSize) {
|
||||||
|
@ -212,6 +211,14 @@ QPixmap PrepareStaticImage(const QString &path) {
|
||||||
return App::pixmapFromImageInPlace(std::move(image));
|
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
|
} // namespace
|
||||||
|
|
||||||
struct OverlayWidget::SharedMedia {
|
struct OverlayWidget::SharedMedia {
|
||||||
|
@ -2304,6 +2311,11 @@ void OverlayWidget::displayDocument(
|
||||||
_staticContent = PrepareStaticImage(path);
|
_staticContent = PrepareStaticImage(path);
|
||||||
_touchbarDisplay.fire(TouchBarItemType::Photo);
|
_touchbarDisplay.fire(TouchBarItemType::Photo);
|
||||||
}
|
}
|
||||||
|
} else if (!_documentMedia->bytes().isEmpty()) {
|
||||||
|
_staticContent = PrepareStaticImage(_documentMedia->bytes());
|
||||||
|
if (!_staticContent.isNull()) {
|
||||||
|
_touchbarDisplay.fire(TouchBarItemType::Photo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
location.accessDisable();
|
location.accessDisable();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue