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