mirror of https://github.com/procxx/kepka.git
Remove data_document_good_thumbnail module.
This commit is contained in:
parent
70c79eb6bd
commit
888e42df34
|
@ -358,8 +358,6 @@ PRIVATE
|
|||
data/data_countries.h
|
||||
data/data_document.cpp
|
||||
data/data_document.h
|
||||
data/data_document_good_thumbnail.cpp
|
||||
data/data_document_good_thumbnail.h
|
||||
data/data_document_media.cpp
|
||||
data/data_document_media.h
|
||||
data/data_drafts.cpp
|
||||
|
|
|
@ -9,7 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_streaming.h"
|
||||
#include "data/data_document_good_thumbnail.h"
|
||||
#include "data/data_document_media.h"
|
||||
#include "data/data_reply_preview.h"
|
||||
#include "lang/lang_keys.h"
|
||||
|
|
|
@ -1,285 +0,0 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "data/data_document_good_thumbnail.h"
|
||||
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_file_origin.h"
|
||||
#include "data/data_cloud_themes.h"
|
||||
#include "media/clip/media_clip_reader.h"
|
||||
#include "lottie/lottie_animation.h"
|
||||
#include "window/themes/window_theme_preview.h"
|
||||
#include "main/main_session.h"
|
||||
#include "app.h"
|
||||
|
||||
#include <QtCore/QBuffer>
|
||||
#include <QtGui/QImageReader>
|
||||
|
||||
namespace Data {
|
||||
namespace {
|
||||
|
||||
constexpr auto kGoodThumbQuality = 87;
|
||||
constexpr auto kWallPaperSize = 960;
|
||||
|
||||
enum class FileType {
|
||||
Video,
|
||||
AnimatedSticker,
|
||||
WallPaper,
|
||||
Theme,
|
||||
};
|
||||
|
||||
QImage Prepare(
|
||||
const QString &path,
|
||||
QByteArray data,
|
||||
FileType type) {
|
||||
if (type == FileType::Video) {
|
||||
return ::Media::Clip::PrepareForSending(path, data).thumbnail;
|
||||
} else if (type == FileType::AnimatedSticker) {
|
||||
return Lottie::ReadThumbnail(Lottie::ReadContent(data, path));
|
||||
} else if (type == FileType::Theme) {
|
||||
return Window::Theme::GeneratePreview(data, path);
|
||||
}
|
||||
const auto validateSize = [](QSize size) {
|
||||
return (size.width() + size.height()) < 10'000;
|
||||
};
|
||||
auto buffer = QBuffer(&data);
|
||||
auto file = QFile(path);
|
||||
auto device = data.isEmpty() ? static_cast<QIODevice*>(&file) : &buffer;
|
||||
auto reader = QImageReader(device);
|
||||
#ifndef OS_MAC_OLD
|
||||
reader.setAutoTransform(true);
|
||||
#endif // OS_MAC_OLD
|
||||
if (!reader.canRead() || !validateSize(reader.size())) {
|
||||
return QImage();
|
||||
}
|
||||
auto result = reader.read();
|
||||
if (!result.width() || !result.height()) {
|
||||
return QImage();
|
||||
}
|
||||
return (result.width() > kWallPaperSize
|
||||
|| result.height() > kWallPaperSize)
|
||||
? result.scaled(
|
||||
kWallPaperSize,
|
||||
kWallPaperSize,
|
||||
Qt::KeepAspectRatio,
|
||||
Qt::SmoothTransformation)
|
||||
: result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
GoodThumbSource::GoodThumbSource(not_null<DocumentData*> document)
|
||||
: _document(document) {
|
||||
}
|
||||
|
||||
void GoodThumbSource::generate(base::binary_guard &&guard) {
|
||||
if (!guard) {
|
||||
return;
|
||||
}
|
||||
const auto data = _document->data();
|
||||
const auto type = _document->isWallPaper()
|
||||
? FileType::WallPaper
|
||||
: _document->isTheme()
|
||||
? FileType::Theme
|
||||
: _document->sticker()
|
||||
? FileType::AnimatedSticker
|
||||
: FileType::Video;
|
||||
auto location = _document->location().isEmpty()
|
||||
? nullptr
|
||||
: std::make_unique<FileLocation>(_document->location());
|
||||
if (data.isEmpty() && !location) {
|
||||
_empty = true;
|
||||
return;
|
||||
}
|
||||
crl::async([
|
||||
=,
|
||||
guard = std::move(guard),
|
||||
location = std::move(location)
|
||||
]() mutable {
|
||||
const auto filepath = (location && location->accessEnable())
|
||||
? location->name()
|
||||
: QString();
|
||||
auto result = Prepare(filepath, data, type);
|
||||
auto bytes = QByteArray();
|
||||
if (!result.isNull()) {
|
||||
auto buffer = QBuffer(&bytes);
|
||||
const auto format = (type == FileType::AnimatedSticker)
|
||||
? "WEBP"
|
||||
: (type == FileType::WallPaper && result.hasAlphaChannel())
|
||||
? "PNG"
|
||||
: "JPG";
|
||||
result.save(&buffer, format, kGoodThumbQuality);
|
||||
}
|
||||
if (!filepath.isEmpty()) {
|
||||
location->accessDisable();
|
||||
}
|
||||
const auto bytesSize = bytes.size();
|
||||
ready(
|
||||
std::move(guard),
|
||||
std::move(result),
|
||||
bytesSize,
|
||||
std::move(bytes));
|
||||
});
|
||||
}
|
||||
|
||||
// NB: This method is called from crl::async(), 'this' is unreliable.
|
||||
void GoodThumbSource::ready(
|
||||
base::binary_guard &&guard,
|
||||
QImage &&image,
|
||||
int bytesSize,
|
||||
QByteArray &&bytesForCache) {
|
||||
crl::on_main(std::move(guard), [
|
||||
=,
|
||||
image = std::move(image),
|
||||
bytes = std::move(bytesForCache)
|
||||
]() mutable {
|
||||
if (image.isNull()) {
|
||||
_empty = true;
|
||||
return;
|
||||
}
|
||||
_loaded = std::move(image);
|
||||
_width = _loaded.width();
|
||||
_height = _loaded.height();
|
||||
_bytesSize = bytesSize;
|
||||
if (!bytes.isEmpty()) {
|
||||
Auth().data().cache().put(
|
||||
_document->goodThumbnailCacheKey(),
|
||||
Storage::Cache::Database::TaggedValue{
|
||||
std::move(bytes),
|
||||
kImageCacheTag });
|
||||
}
|
||||
Auth().downloaderTaskFinished().notify();
|
||||
});
|
||||
}
|
||||
|
||||
void GoodThumbSource::load(FileOrigin origin) {
|
||||
if (loading() || _empty) {
|
||||
return;
|
||||
}
|
||||
auto callback = [=, guard = _loading.make_guard()](
|
||||
QByteArray &&value) mutable {
|
||||
if (value.isEmpty()) {
|
||||
crl::on_main([=, guard = std::move(guard)]() mutable {
|
||||
generate(std::move(guard));
|
||||
});
|
||||
return;
|
||||
}
|
||||
crl::async([
|
||||
=,
|
||||
guard = std::move(guard),
|
||||
value = std::move(value)
|
||||
]() mutable {
|
||||
ready(
|
||||
std::move(guard),
|
||||
App::readImage(value, nullptr, false),
|
||||
value.size());
|
||||
});
|
||||
};
|
||||
|
||||
Auth().data().cache().get(
|
||||
_document->goodThumbnailCacheKey(),
|
||||
std::move(callback));
|
||||
}
|
||||
|
||||
void GoodThumbSource::loadEvenCancelled(FileOrigin origin) {
|
||||
_empty = false;
|
||||
load(origin);
|
||||
}
|
||||
|
||||
QImage GoodThumbSource::takeLoaded() {
|
||||
return std::move(_loaded);
|
||||
}
|
||||
|
||||
void GoodThumbSource::unload() {
|
||||
_loaded = QImage();
|
||||
cancel();
|
||||
}
|
||||
|
||||
void GoodThumbSource::automaticLoad(
|
||||
FileOrigin origin,
|
||||
const HistoryItem *item) {
|
||||
}
|
||||
|
||||
void GoodThumbSource::automaticLoadSettingsChanged() {
|
||||
}
|
||||
|
||||
bool GoodThumbSource::loading() {
|
||||
return _loading.alive();
|
||||
}
|
||||
|
||||
bool GoodThumbSource::displayLoading() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void GoodThumbSource::cancel() {
|
||||
_loading = nullptr;
|
||||
}
|
||||
|
||||
float64 GoodThumbSource::progress() {
|
||||
return 1.;
|
||||
}
|
||||
|
||||
int GoodThumbSource::loadOffset() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const StorageImageLocation &GoodThumbSource::location() {
|
||||
return StorageImageLocation::Invalid();
|
||||
}
|
||||
|
||||
void GoodThumbSource::refreshFileReference(const QByteArray &data) {
|
||||
}
|
||||
|
||||
std::optional<Storage::Cache::Key> GoodThumbSource::cacheKey() {
|
||||
return _document->goodThumbnailCacheKey();
|
||||
}
|
||||
|
||||
void GoodThumbSource::setDelayedStorageLocation(
|
||||
const StorageImageLocation &location) {
|
||||
}
|
||||
|
||||
void GoodThumbSource::performDelayedLoad(FileOrigin origin) {
|
||||
}
|
||||
|
||||
bool GoodThumbSource::isDelayedStorageImage() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void GoodThumbSource::setImageBytes(const QByteArray &bytes) {
|
||||
if (!bytes.isEmpty()) {
|
||||
cancel();
|
||||
_loaded = App::readImage(bytes);
|
||||
_width = _loaded.width();
|
||||
_height = _loaded.height();
|
||||
_bytesSize = bytes.size();
|
||||
}
|
||||
}
|
||||
|
||||
int GoodThumbSource::width() {
|
||||
return _width;
|
||||
}
|
||||
|
||||
int GoodThumbSource::height() {
|
||||
return _height;
|
||||
}
|
||||
|
||||
int GoodThumbSource::bytesSize() {
|
||||
return _bytesSize;
|
||||
}
|
||||
|
||||
void GoodThumbSource::setInformation(int size, int width, int height) {
|
||||
_width = width;
|
||||
_height = height;
|
||||
_bytesSize = size;
|
||||
}
|
||||
|
||||
QByteArray GoodThumbSource::bytesForCache() {
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
} // namespace Data
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "ui/image/image.h"
|
||||
#include "base/binary_guard.h"
|
||||
|
||||
class DocumentData;
|
||||
|
||||
namespace Data {
|
||||
|
||||
class GoodThumbSource : public Images::Source {
|
||||
public:
|
||||
explicit GoodThumbSource(not_null<DocumentData*> document);
|
||||
|
||||
void load(FileOrigin origin) override;
|
||||
void loadEvenCancelled(FileOrigin origin) override;
|
||||
QImage takeLoaded() override;
|
||||
void unload() override;
|
||||
|
||||
void automaticLoad(
|
||||
FileOrigin origin,
|
||||
const HistoryItem *item) override;
|
||||
void automaticLoadSettingsChanged() override;
|
||||
|
||||
bool loading() override;
|
||||
bool displayLoading() override;
|
||||
void cancel() override;
|
||||
float64 progress() override;
|
||||
int loadOffset() override;
|
||||
|
||||
const StorageImageLocation &location() override;
|
||||
void refreshFileReference(const QByteArray &data) override;
|
||||
std::optional<Storage::Cache::Key> cacheKey() override;
|
||||
void setDelayedStorageLocation(
|
||||
const StorageImageLocation &location) override;
|
||||
void performDelayedLoad(FileOrigin origin) override;
|
||||
bool isDelayedStorageImage() const override;
|
||||
void setImageBytes(const QByteArray &bytes) override;
|
||||
|
||||
int width() override;
|
||||
int height() override;
|
||||
int bytesSize() override;
|
||||
void setInformation(int size, int width, int height) override;
|
||||
|
||||
QByteArray bytesForCache() override;
|
||||
|
||||
private:
|
||||
void generate(base::binary_guard &&guard);
|
||||
|
||||
// NB: This method is called from crl::async(), 'this' is unreliable.
|
||||
void ready(
|
||||
base::binary_guard &&guard,
|
||||
QImage &&image,
|
||||
int bytesSize,
|
||||
QByteArray &&bytesForCache = {});
|
||||
|
||||
not_null<DocumentData*> _document;
|
||||
QImage _loaded;
|
||||
base::binary_guard _loading;
|
||||
int _width = 0;
|
||||
int _height = 0;
|
||||
int _bytesSize = 0;
|
||||
bool _empty = false;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Data
|
|
@ -8,7 +8,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_document_media.h"
|
||||
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_document_good_thumbnail.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_cloud_themes.h"
|
||||
#include "data/data_file_origin.h"
|
||||
|
|
Loading…
Reference in New Issue