Load cloud image without active view only once.

This commit is contained in:
John Preston 2021-12-06 15:00:17 +04:00
parent 01c2be3f01
commit d199e16a6e
2 changed files with 10 additions and 1 deletions

View File

@ -99,13 +99,19 @@ bool CloudImage::failed() const {
return (_file.flags & CloudFile::Flag::Failed);
}
bool CloudImage::loadedOnce() const {
return (_file.flags & CloudFile::Flag::Loaded);
}
void CloudImage::load(not_null<Main::Session*> session, FileOrigin origin) {
const auto autoLoading = false;
const auto finalCheck = [=] {
if (const auto active = activeView()) {
return !active->image();
} else if (_file.flags & CloudFile::Flag::Loaded) {
return false;
}
return true;
return !(_file.flags & CloudFile::Flag::Loaded);
};
const auto done = [=](QImage result) {
if (const auto active = activeView()) {
@ -247,6 +253,7 @@ void LoadCloudFile(
if (!file.loader || file.loader->cancelled()) {
file.flags |= CloudFile::Flag::Cancelled;
} else {
file.flags |= CloudFile::Flag::Loaded;
done(file);
}
// NB! file.loader may be in ~FileLoader() already.

View File

@ -31,6 +31,7 @@ struct CloudFile final {
enum class Flag : uchar {
Cancelled = 0x01,
Failed = 0x02,
Loaded = 0x04,
};
friend inline constexpr bool is_flag_type(Flag) { return true; };
@ -73,6 +74,7 @@ public:
[[nodiscard]] bool empty() const;
[[nodiscard]] bool loading() const;
[[nodiscard]] bool failed() const;
[[nodiscard]] bool loadedOnce() const;
void load(not_null<Main::Session*> session, FileOrigin origin);
[[nodiscard]] const ImageLocation &location() const;
[[nodiscard]] int byteSize() const;