2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 14:45:14 +00:00

WebDocument wrap to HistoryPhoto supported.

Only WebDocument with a valid 'size' field value and with a valid
'documentAttributeImageSize' attribute works wrapped as a photo.
This commit is contained in:
John Preston
2017-03-05 20:33:32 +03:00
parent 7b5985445c
commit 31e3c6a2c6
6 changed files with 255 additions and 72 deletions

View File

@@ -364,6 +364,9 @@ Image *blank() {
using StorageImages = QMap<StorageKey, StorageImage*>;
StorageImages storageImages;
using WebFileImages = QMap<StorageKey, WebFileImage*>;
WebFileImages webFileImages;
int64 globalAcquiredSize = 0;
uint64 PixKey(int width, int height, Images::Options options) {
@@ -377,6 +380,7 @@ uint64 SinglePixKey(Images::Options options) {
} // namespace
StorageImageLocation StorageImageLocation::Null;
WebFileImageLocation WebFileImageLocation::Null;
bool Image::isNull() const {
return (this == blank());
@@ -809,6 +813,9 @@ void clearStorageImages() {
for (auto image : base::take(webImages)) {
delete image;
}
for (auto image : base::take(webFileImages)) {
delete image;
}
}
void clearAllImages() {
@@ -995,6 +1002,29 @@ FileLoader *StorageImage::createLoader(LoadFromCloudSetting fromCloud, bool auto
return new mtpFileLoader(&_location, _size, fromCloud, autoLoading);
}
WebFileImage::WebFileImage(const WebFileImageLocation &location, int32 size)
: _location(location)
, _size(size) {
}
int32 WebFileImage::countWidth() const {
return _location.width();
}
int32 WebFileImage::countHeight() const {
return _location.height();
}
void WebFileImage::setInformation(int32 size, int32 width, int32 height) {
_size = size;
_location.setSize(width, height);
}
FileLoader *WebFileImage::createLoader(LoadFromCloudSetting fromCloud, bool autoLoading) {
if (_location.isNull()) return 0;
return new mtpFileLoader(&_location, _size, fromCloud, autoLoading);
}
DelayedStorageImage::DelayedStorageImage() : StorageImage(StorageImageLocation())
, _loadRequested(false)
, _loadCancelled(false)
@@ -1188,6 +1218,15 @@ StorageImage *getImage(const StorageImageLocation &location, const QByteArray &b
return i.value();
}
WebFileImage *getImage(const WebFileImageLocation &location, int32 size) {
auto key = storageKey(location);
auto i = webFileImages.constFind(key);
if (i == webFileImages.cend()) {
i = webFileImages.insert(key, new WebFileImage(location, size));
}
return i.value();
}
} // namespace internal
ReadAccessEnabler::ReadAccessEnabler(const PsFileBookmark *bookmark) : _bookmark(bookmark), _failed(_bookmark ? !_bookmark->enable() : false) {