mirror of
https://github.com/telegramdesktop/tdesktop
synced 2024-12-25 16:02:52 +00:00
Use photo as video thumbnail in WebPageData.
This commit is contained in:
parent
550b67236e
commit
4837117719
@ -552,11 +552,15 @@ void DocumentData::validateGoodThumbnail() {
|
||||
|
||||
void DocumentData::refreshGoodThumbnail() {
|
||||
if (_goodThumbnail && hasRemoteLocation()) {
|
||||
_goodThumbnail->replaceSource(
|
||||
std::make_unique<Data::GoodThumbSource>(this));
|
||||
replaceGoodThumbnail(std::make_unique<Data::GoodThumbSource>(this));
|
||||
}
|
||||
}
|
||||
|
||||
void DocumentData::replaceGoodThumbnail(
|
||||
std::unique_ptr<Images::Source> &&source) {
|
||||
_goodThumbnail->replaceSource(std::move(source));
|
||||
}
|
||||
|
||||
void DocumentData::setGoodThumbnail(QImage &&image, QByteArray &&bytes) {
|
||||
Expects(uploadingData != nullptr);
|
||||
|
||||
|
@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
|
||||
#include "data/data_types.h"
|
||||
|
||||
namespace Images {
|
||||
class Source;
|
||||
} // namespace Images
|
||||
|
||||
namespace Storage {
|
||||
namespace Cache {
|
||||
struct Key;
|
||||
@ -158,6 +162,7 @@ public:
|
||||
Storage::Cache::Key goodThumbnailCacheKey() const;
|
||||
void setGoodThumbnail(QImage &&image, QByteArray &&bytes);
|
||||
void refreshGoodThumbnail();
|
||||
void replaceGoodThumbnail(std::unique_ptr<Images::Source> &&source);
|
||||
|
||||
void setRemoteLocation(
|
||||
int32 dc,
|
||||
|
@ -52,9 +52,11 @@ void GoodThumbSource::generate(base::binary_guard &&guard) {
|
||||
if (!filepath.isEmpty()) {
|
||||
location->accessDisable();
|
||||
}
|
||||
const auto bytesSize = bytes.size();
|
||||
ready(
|
||||
std::move(guard),
|
||||
std::move(result.thumbnail),
|
||||
bytesSize,
|
||||
std::move(bytes));
|
||||
});
|
||||
}
|
||||
@ -63,12 +65,13 @@ void GoodThumbSource::generate(base::binary_guard &&guard) {
|
||||
void GoodThumbSource::ready(
|
||||
base::binary_guard &&guard,
|
||||
QImage &&image,
|
||||
QByteArray &&bytes) {
|
||||
int bytesSize,
|
||||
QByteArray &&bytesForCache) {
|
||||
crl::on_main([
|
||||
=,
|
||||
guard = std::move(guard),
|
||||
image = std::move(image),
|
||||
bytes = std::move(bytes)
|
||||
bytes = std::move(bytesForCache)
|
||||
]() mutable {
|
||||
if (!guard.alive()) {
|
||||
return;
|
||||
@ -80,6 +83,7 @@ void GoodThumbSource::ready(
|
||||
_loaded = std::move(image);
|
||||
_width = _loaded.width();
|
||||
_height = _loaded.height();
|
||||
_bytesSize = bytesSize;
|
||||
if (!bytes.isEmpty()) {
|
||||
Auth().data().cache().put(
|
||||
_document->goodThumbnailCacheKey(),
|
||||
@ -114,7 +118,7 @@ void GoodThumbSource::load(
|
||||
guard = std::move(guard),
|
||||
value = std::move(value)
|
||||
]() mutable {
|
||||
ready(std::move(guard), App::readImage(value));
|
||||
ready(std::move(guard), App::readImage(value), value.size());
|
||||
});
|
||||
};
|
||||
|
||||
@ -194,6 +198,9 @@ void GoodThumbSource::setImageBytes(const QByteArray &bytes) {
|
||||
if (!bytes.isEmpty()) {
|
||||
cancel();
|
||||
_loaded = App::readImage(bytes);
|
||||
_width = _loaded.width();
|
||||
_height = _loaded.height();
|
||||
_bytesSize = bytes.size();
|
||||
}
|
||||
}
|
||||
|
||||
@ -205,9 +212,14 @@ 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() {
|
||||
|
@ -50,6 +50,7 @@ public:
|
||||
|
||||
int width() override;
|
||||
int height() override;
|
||||
int bytesSize() override;
|
||||
void setInformation(int size, int width, int height) override;
|
||||
|
||||
QByteArray bytesForCache() override;
|
||||
@ -61,13 +62,15 @@ private:
|
||||
void ready(
|
||||
base::binary_guard &&guard,
|
||||
QImage &&image,
|
||||
QByteArray &&bytes = {});
|
||||
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;
|
||||
|
||||
};
|
||||
|
@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "data/data_photo.h"
|
||||
#include "data/data_document.h"
|
||||
#include "ui/image/image.h"
|
||||
#include "ui/image/image_source.h"
|
||||
#include "ui/text/text_entity.h"
|
||||
|
||||
namespace {
|
||||
@ -196,5 +197,22 @@ bool WebPageData::applyChanges(
|
||||
author = resultAuthor;
|
||||
pendingTill = newPendingTill;
|
||||
++version;
|
||||
|
||||
replaceDocumentGoodThumbnail();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void WebPageData::replaceDocumentGoodThumbnail() {
|
||||
if (!document || !photo || !document->goodThumbnail()) {
|
||||
return;
|
||||
}
|
||||
const auto &location = photo->full->location();
|
||||
if (!location.isNull()) {
|
||||
document->replaceGoodThumbnail(
|
||||
std::make_unique<Images::StorageSource>(
|
||||
location,
|
||||
photo->full->bytesSize()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -95,4 +95,7 @@ struct WebPageData {
|
||||
int pendingTill = 0;
|
||||
int version = 0;
|
||||
|
||||
private:
|
||||
void replaceDocumentGoodThumbnail();
|
||||
|
||||
};
|
||||
|
@ -78,6 +78,7 @@ public:
|
||||
|
||||
virtual int width() = 0;
|
||||
virtual int height() = 0;
|
||||
virtual int bytesSize() = 0;
|
||||
virtual void setInformation(int size, int width, int height) = 0;
|
||||
|
||||
virtual QByteArray bytesForCache() = 0;
|
||||
@ -194,6 +195,9 @@ public:
|
||||
int height() const {
|
||||
return _source->height();
|
||||
}
|
||||
int bytesSize() const {
|
||||
return _source->bytesSize();
|
||||
}
|
||||
void setInformation(int size, int width, int height) {
|
||||
_source->setInformation(size, width, height);
|
||||
}
|
||||
|
@ -113,6 +113,10 @@ int ImageSource::height() {
|
||||
return _data.height();
|
||||
}
|
||||
|
||||
int ImageSource::bytesSize() {
|
||||
return _bytes.size();
|
||||
}
|
||||
|
||||
void ImageSource::setInformation(int size, int width, int height) {
|
||||
}
|
||||
|
||||
@ -242,6 +246,11 @@ int LocalFileSource::height() {
|
||||
return _height;
|
||||
}
|
||||
|
||||
int LocalFileSource::bytesSize() {
|
||||
ensureDimensionsKnown();
|
||||
return _bytes.size();
|
||||
}
|
||||
|
||||
void LocalFileSource::setInformation(int size, int width, int height) {
|
||||
ensureDimensionsKnown(); // First load _bytes.
|
||||
if (width && height) {
|
||||
@ -456,6 +465,10 @@ int StorageSource::height() {
|
||||
return _location.height();
|
||||
}
|
||||
|
||||
int StorageSource::bytesSize() {
|
||||
return _size;
|
||||
}
|
||||
|
||||
void StorageSource::setInformation(int size, int width, int height) {
|
||||
if (size) {
|
||||
_size = size;
|
||||
@ -519,6 +532,10 @@ int WebCachedSource::height() {
|
||||
return _height;
|
||||
}
|
||||
|
||||
int WebCachedSource::bytesSize() {
|
||||
return _size;
|
||||
}
|
||||
|
||||
void WebCachedSource::setInformation(int size, int width, int height) {
|
||||
if (size) {
|
||||
_size = size;
|
||||
@ -563,6 +580,10 @@ int GeoPointSource::height() {
|
||||
return _location.height * _location.scale;
|
||||
}
|
||||
|
||||
int GeoPointSource::bytesSize() {
|
||||
return _size;
|
||||
}
|
||||
|
||||
void GeoPointSource::setInformation(int size, int width, int height) {
|
||||
Expects(_location.scale != 0);
|
||||
|
||||
@ -705,6 +726,10 @@ int WebUrlSource::height() {
|
||||
return _height;
|
||||
}
|
||||
|
||||
int WebUrlSource::bytesSize() {
|
||||
return _size;
|
||||
}
|
||||
|
||||
void WebUrlSource::setInformation(int size, int width, int height) {
|
||||
if (size) {
|
||||
_size = size;
|
||||
|
@ -48,6 +48,7 @@ public:
|
||||
|
||||
int width() override;
|
||||
int height() override;
|
||||
int bytesSize() override;
|
||||
void setInformation(int size, int width, int height) override;
|
||||
|
||||
QByteArray bytesForCache() override;
|
||||
@ -100,6 +101,7 @@ public:
|
||||
|
||||
int width() override;
|
||||
int height() override;
|
||||
int bytesSize() override;
|
||||
void setInformation(int size, int width, int height) override;
|
||||
|
||||
QByteArray bytesForCache() override;
|
||||
@ -184,6 +186,7 @@ public:
|
||||
|
||||
int width() override;
|
||||
int height() override;
|
||||
int bytesSize() override;
|
||||
void setInformation(int size, int width, int height) override;
|
||||
|
||||
protected:
|
||||
@ -211,6 +214,7 @@ public:
|
||||
|
||||
int width() override;
|
||||
int height() override;
|
||||
int bytesSize() override;
|
||||
void setInformation(int size, int width, int height) override;
|
||||
|
||||
protected:
|
||||
@ -236,6 +240,7 @@ public:
|
||||
|
||||
int width() override;
|
||||
int height() override;
|
||||
int bytesSize() override;
|
||||
void setInformation(int size, int width, int height) override;
|
||||
|
||||
protected:
|
||||
@ -298,6 +303,7 @@ public:
|
||||
|
||||
int width() override;
|
||||
int height() override;
|
||||
int bytesSize() override;
|
||||
void setInformation(int size, int width, int height) override;
|
||||
|
||||
protected:
|
||||
|
Loading…
Reference in New Issue
Block a user