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

Move photo data to Data::PhotoMedia.

This commit is contained in:
John Preston
2020-05-25 18:16:04 +04:00
parent 24fed8105c
commit e27d2bc2d5
51 changed files with 1628 additions and 922 deletions

View File

@@ -946,14 +946,6 @@ QImage Image::original() const {
return _data;
}
void Image::automaticLoad(
Data::FileOrigin origin,
const HistoryItem *item) {
if (!loaded()) {
_source->automaticLoad(origin, item);
}
}
void Image::load(Data::FileOrigin origin) {
if (!loaded()) {
_source->load(origin);

View File

@@ -67,11 +67,6 @@ public:
virtual QImage takeLoaded() = 0;
virtual void unload() = 0;
virtual void automaticLoad(
Data::FileOrigin origin,
const HistoryItem *item) = 0;
virtual void automaticLoadSettingsChanged() = 0;
virtual bool loading() = 0;
virtual bool displayLoading() = 0;
virtual void cancel() = 0;
@@ -178,10 +173,6 @@ public:
int32 w,
int32 h = 0) const;
void automaticLoad(Data::FileOrigin origin, const HistoryItem *item);
void automaticLoadSettingsChanged() {
_source->automaticLoadSettingsChanged();
}
bool loading() const {
return _source->loading();
}

View File

@@ -14,6 +14,65 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Images {
ImageWithLocation FromPhotoSize(
not_null<Main::Session*> session,
const MTPDphoto &photo,
const MTPPhotoSize &size) {
return size.match([&](const MTPDphotoSize &data) {
return ImageWithLocation{
.location = ImageLocation(
DownloadLocation{ StorageFileLocation(
photo.vdc_id().v,
session->userId(),
MTP_inputPhotoFileLocation(
photo.vid(),
photo.vaccess_hash(),
photo.vfile_reference(),
data.vtype())) },
data.vw().v,
data.vh().v),
.bytesCount = data.vsize().v
};
}, [&](const MTPDphotoCachedSize &data) {
const auto bytes = qba(data.vbytes());
return ImageWithLocation{
.location = ImageLocation(
DownloadLocation{ StorageFileLocation(
photo.vdc_id().v,
session->userId(),
MTP_inputPhotoFileLocation(
photo.vid(),
photo.vaccess_hash(),
photo.vfile_reference(),
data.vtype())) },
data.vw().v,
data.vh().v),
.bytesCount = bytes.size(),
.bytes = bytes
};
}, [&](const MTPDphotoStrippedSize &data) {
return ImageWithLocation();
//const auto bytes = ExpandInlineBytes(qba(data.vbytes()));
//return ImageWithLocation{
// .location = ImageLocation(
// DownloadLocation{ StorageFileLocation(
// photo.vdc_id().v,
// session->userId(),
// MTP_inputPhotoFileLocation(
// photo.vid(),
// photo.vaccess_hash(),
// photo.vfile_reference(),
// data.vtype())) },
// width, // ???
// height), // ???
// .bytesCount = bytes.size(),
// .bytes = bytes
//};
}, [&](const MTPDphotoSizeEmpty &) {
return ImageWithLocation();
});
}
ImageWithLocation FromPhotoSize(
not_null<Main::Session*> session,
const MTPDdocument &document,

View File

@@ -15,6 +15,10 @@ class Session;
namespace Images {
[[nodiscard]] ImageWithLocation FromPhotoSize(
not_null<Main::Session*> session,
const MTPDphoto &photo,
const MTPPhotoSize &size);
[[nodiscard]] ImageWithLocation FromPhotoSize(
not_null<Main::Session*> session,
const MTPDdocument &document,

View File

@@ -57,14 +57,6 @@ void ImageSource::unload() {
_data = QImage();
}
void ImageSource::automaticLoad(
Data::FileOrigin origin,
const HistoryItem *item) {
}
void ImageSource::automaticLoadSettingsChanged() {
}
bool ImageSource::loading() {
return false;
}
@@ -186,14 +178,6 @@ void LocalFileSource::unload() {
_data = QImage();
}
void LocalFileSource::automaticLoad(
Data::FileOrigin origin,
const HistoryItem *item) {
}
void LocalFileSource::automaticLoadSettingsChanged() {
}
bool LocalFileSource::loading() {
return false;
}
@@ -344,36 +328,6 @@ bool RemoteSource::loading() {
return (_loader != nullptr);
}
void RemoteSource::automaticLoad(
Data::FileOrigin origin,
const HistoryItem *item) {
if (!item || cancelled()) {
return;
}
const auto loadFromCloud = Data::AutoDownload::Should(
Auth().settings().autoDownload(),
item->history()->peer,
this);
if (_loader) {
if (loadFromCloud) {
_loader->permitLoadFromCloud();
}
} else {
_loader = createLoader(
origin,
loadFromCloud ? LoadFromCloudOrLocal : LoadFromLocalOnly,
true);
}
if (_loader) {
_loader->start();
}
}
void RemoteSource::automaticLoadSettingsChanged() {
_cancelled = false;
}
void RemoteSource::load(Data::FileOrigin origin) {
if (!_loader) {
_loader = createLoader(origin, LoadFromCloudOrLocal, false);
@@ -645,33 +599,33 @@ void DelayedStorageSource::performDelayedLoad(Data::FileOrigin origin) {
loadLocal();
}
}
void DelayedStorageSource::automaticLoad(
Data::FileOrigin origin,
const HistoryItem *item) {
if (_location.valid()) {
StorageSource::automaticLoad(origin, item);
return;
} else if (_loadCancelled || !item) {
return;
}
const auto loadFromCloud = Data::AutoDownload::Should(
Auth().settings().autoDownload(),
item->history()->peer,
this);
if (_loadRequested) {
if (loadFromCloud) _loadFromCloud = loadFromCloud;
} else {
_loadFromCloud = loadFromCloud;
_loadRequested = true;
}
}
void DelayedStorageSource::automaticLoadSettingsChanged() {
if (_loadCancelled) _loadCancelled = false;
StorageSource::automaticLoadSettingsChanged();
}
//
//void DelayedStorageSource::automaticLoad(
// Data::FileOrigin origin,
// const HistoryItem *item) {
// if (_location.valid()) {
// StorageSource::automaticLoad(origin, item);
// return;
// } else if (_loadCancelled || !item) {
// return;
// }
// const auto loadFromCloud = Data::AutoDownload::Should(
// Auth().settings().autoDownload(),
// item->history()->peer,
// this);
//
// if (_loadRequested) {
// if (loadFromCloud) _loadFromCloud = loadFromCloud;
// } else {
// _loadFromCloud = loadFromCloud;
// _loadRequested = true;
// }
//}
//
//void DelayedStorageSource::automaticLoadSettingsChanged() {
// if (_loadCancelled) _loadCancelled = false;
// StorageSource::automaticLoadSettingsChanged();
//}
void DelayedStorageSource::load(Data::FileOrigin origin) {
if (_location.valid()) {

View File

@@ -20,11 +20,6 @@ public:
QImage takeLoaded() override;
void unload() override;
void automaticLoad(
Data::FileOrigin origin,
const HistoryItem *item) override;
void automaticLoadSettingsChanged() override;
bool loading() override;
bool displayLoading() override;
void cancel() override;
@@ -69,11 +64,6 @@ public:
QImage takeLoaded() override;
void unload() override;
void automaticLoad(
Data::FileOrigin origin,
const HistoryItem *item) override;
void automaticLoadSettingsChanged() override;
bool loading() override;
bool displayLoading() override;
void cancel() override;
@@ -115,11 +105,6 @@ public:
QImage takeLoaded() override;
void unload() override;
void automaticLoad(
Data::FileOrigin origin,
const HistoryItem *item) override;
void automaticLoadSettingsChanged() override;
bool loading() override;
bool displayLoading() override;
void cancel() override;
@@ -256,11 +241,6 @@ public:
bool isDelayedStorageImage() const override;
void performDelayedLoad(Data::FileOrigin origin) override;
void automaticLoad(
Data::FileOrigin origin,
const HistoryItem *item) override; // auto load photo
void automaticLoadSettingsChanged() override;
bool loading() override {
return _location.valid()
? StorageSource::loading()