Remove Image::toDelayedStorageImage downcaster.

This commit is contained in:
John Preston 2018-10-11 19:07:08 +03:00
parent 113f665295
commit 5a50248055
5 changed files with 23 additions and 30 deletions

View File

@ -129,9 +129,9 @@ ImagePtr PhotoData::makeReplyPreview(Data::FileOrigin origin) {
: image->pix(origin, st::msgReplyBarSize.height())), : image->pix(origin, st::msgReplyBarSize.height())),
"PNG"); "PNG");
}; };
if (thumb->toDelayedStorageImage() if (thumb->isDelayedStorageImage()
&& !full->isNull() && !full->isNull()
&& !full->toDelayedStorageImage()) { && !full->isDelayedStorageImage()) {
replyPreview = previewFromImage(full); replyPreview = previewFromImage(full);
} else { } else {
replyPreview = previewFromImage(thumb); replyPreview = previewFromImage(thumb);

View File

@ -57,10 +57,10 @@ void UpdateImage(ImagePtr &old, ImagePtr now) {
} }
if (old->isNull()) { if (old->isNull()) {
old = now; old = now;
} else if (const auto delayed = old->toDelayedStorageImage()) { } else if (old->isDelayedStorageImage()) {
const auto location = now->location(); const auto location = now->location();
if (!location.isNull()) { if (!location.isNull()) {
delayed->setStorageLocation(Data::FileOrigin(), location); old->setDelayedStorageLocation(Data::FileOrigin(), location);
} }
} }
} }

View File

@ -460,8 +460,7 @@ void HistoryPhoto::draw(Painter &p, const QRect &r, TextSelection selection, Tim
p.setOpacity(radialOpacity); p.setOpacity(radialOpacity);
auto icon = ([radial, this, selected]() -> const style::icon* { auto icon = ([radial, this, selected]() -> const style::icon* {
if (radial || _data->loading()) { if (radial || _data->loading()) {
auto delayed = _data->full->toDelayedStorageImage(); if (!_data->full->location().isNull()) {
if (!delayed || !delayed->location().isNull()) {
return &(selected ? st::historyFileThumbCancelSelected : st::historyFileThumbCancel); return &(selected ? st::historyFileThumbCancelSelected : st::historyFileThumbCancel);
} }
return nullptr; return nullptr;
@ -529,8 +528,7 @@ TextState HistoryPhoto::textState(QPoint point, StateRequest request) const {
} else if (_data->loaded()) { } else if (_data->loaded()) {
result.link = _openl; result.link = _openl;
} else if (_data->loading()) { } else if (_data->loading()) {
auto delayed = _data->full->toDelayedStorageImage(); if (!_data->full->location().isNull()) {
if (!delayed || !delayed->location().isNull()) {
result.link = _cancell; result.link = _cancell;
} }
} else { } else {
@ -631,8 +629,7 @@ void HistoryPhoto::drawGrouped(
if (_data->waitingForAlbum()) { if (_data->waitingForAlbum()) {
return &(selected ? st::historyFileThumbWaitingSelected : st::historyFileThumbWaiting); return &(selected ? st::historyFileThumbWaitingSelected : st::historyFileThumbWaiting);
} else if (radial || _data->loading()) { } else if (radial || _data->loading()) {
auto delayed = _data->full->toDelayedStorageImage(); if (!_data->full->location().isNull()) {
if (!delayed || !delayed->location().isNull()) {
return &(selected ? st::historyFileThumbCancelSelected : st::historyFileThumbCancel); return &(selected ? st::historyFileThumbCancelSelected : st::historyFileThumbCancel);
} }
return nullptr; return nullptr;
@ -661,15 +658,14 @@ TextState HistoryPhoto::getStateGrouped(
if (!geometry.contains(point)) { if (!geometry.contains(point)) {
return {}; return {};
} }
const auto delayed = _data->full->toDelayedStorageImage();
return TextState(_parent, _data->uploading() return TextState(_parent, _data->uploading()
? _cancell ? _cancell
: _data->loaded() : _data->loaded()
? _openl ? _openl
: _data->loading() : _data->loading()
? ((!delayed || !delayed->location().isNull()) ? (_data->full->location().isNull()
? _cancell ? ClickHandlerPtr()
: ClickHandlerPtr()) : _cancell)
: _savel); : _savel);
} }

View File

@ -898,7 +898,8 @@ FileLoader *GeoPointImage::createLoader(
Data::kImageCacheTag); Data::kImageCacheTag);
} }
DelayedStorageImage::DelayedStorageImage() : StorageImage(StorageImageLocation()) DelayedStorageImage::DelayedStorageImage()
: StorageImage(StorageImageLocation())
, _loadRequested(false) , _loadRequested(false)
, _loadCancelled(false) , _loadCancelled(false)
, _loadFromCloud(false) { , _loadFromCloud(false) {
@ -918,7 +919,7 @@ DelayedStorageImage::DelayedStorageImage(int32 w, int32 h)
//, _loadFromCloud(false) { //, _loadFromCloud(false) {
//} //}
void DelayedStorageImage::setStorageLocation( void DelayedStorageImage::setDelayedStorageLocation(
Data::FileOrigin origin, Data::FileOrigin origin,
const StorageImageLocation location) { const StorageImageLocation location) {
_location = location; _location = location;

View File

@ -15,7 +15,6 @@ void CheckCacheSize();
} // namespace Images } // namespace Images
class DelayedStorageImage;
class HistoryItem; class HistoryItem;
class Image { class Image {
@ -157,11 +156,12 @@ public:
return _saved; return _saved;
} }
virtual DelayedStorageImage *toDelayedStorageImage() { virtual void setDelayedStorageLocation(
return 0; Data::FileOrigin origin,
} const StorageImageLocation location) {
virtual const DelayedStorageImage *toDelayedStorageImage() const { };
return 0; virtual bool isDelayedStorageImage() const {
return false;
} }
virtual ~Image(); virtual ~Image();
@ -340,15 +340,11 @@ public:
DelayedStorageImage(int32 w, int32 h); DelayedStorageImage(int32 w, int32 h);
//DelayedStorageImage(QByteArray &bytes); //DelayedStorageImage(QByteArray &bytes);
void setStorageLocation( void setDelayedStorageLocation(
Data::FileOrigin origin, Data::FileOrigin origin,
const StorageImageLocation location); const StorageImageLocation location) override;
bool isDelayedStorageImage() const override {
virtual DelayedStorageImage *toDelayedStorageImage() override { return true;
return this;
}
virtual const DelayedStorageImage *toDelayedStorageImage() const override {
return this;
} }
void automaticLoad( void automaticLoad(