2020-05-26 11:59:45 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "base/flags.h"
|
2020-05-29 15:10:25 +00:00
|
|
|
#include "ui/image/image.h"
|
2020-05-26 11:59:45 +00:00
|
|
|
#include "ui/image/image_location.h"
|
|
|
|
|
|
|
|
class FileLoader;
|
|
|
|
|
|
|
|
namespace Storage {
|
|
|
|
namespace Cache {
|
|
|
|
class Database;
|
|
|
|
} // namespace Cache
|
|
|
|
} // namespace Storage
|
|
|
|
|
2020-05-27 14:31:39 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
2020-05-26 11:59:45 +00:00
|
|
|
namespace Data {
|
|
|
|
|
|
|
|
struct FileOrigin;
|
|
|
|
|
|
|
|
struct CloudFile final {
|
|
|
|
enum class Flag : uchar {
|
|
|
|
Cancelled = 0x01,
|
|
|
|
Failed = 0x02,
|
2021-12-06 11:00:17 +00:00
|
|
|
Loaded = 0x04,
|
2020-05-26 11:59:45 +00:00
|
|
|
};
|
|
|
|
friend inline constexpr bool is_flag_type(Flag) { return true; };
|
|
|
|
|
2020-06-03 09:48:11 +00:00
|
|
|
~CloudFile();
|
|
|
|
|
2024-04-15 07:18:57 +00:00
|
|
|
void clear();
|
|
|
|
|
2020-05-26 11:59:45 +00:00
|
|
|
ImageLocation location;
|
|
|
|
std::unique_ptr<FileLoader> loader;
|
|
|
|
int byteSize = 0;
|
2020-08-25 18:03:41 +00:00
|
|
|
int progressivePartSize = 0;
|
2020-05-26 11:59:45 +00:00
|
|
|
base::flags<Flag> flags;
|
|
|
|
};
|
|
|
|
|
2020-05-27 14:31:39 +00:00
|
|
|
class CloudImage final {
|
|
|
|
public:
|
2020-05-28 13:51:18 +00:00
|
|
|
CloudImage();
|
|
|
|
CloudImage(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const ImageWithLocation &data);
|
2020-05-27 14:31:39 +00:00
|
|
|
|
2020-05-28 14:32:10 +00:00
|
|
|
// This method will replace the location and zero the _view pointer.
|
|
|
|
void set(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const ImageWithLocation &data);
|
|
|
|
|
2020-05-28 13:51:18 +00:00
|
|
|
void update(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const ImageWithLocation &data);
|
2020-05-27 14:31:39 +00:00
|
|
|
|
|
|
|
[[nodiscard]] bool empty() const;
|
|
|
|
[[nodiscard]] bool loading() const;
|
|
|
|
[[nodiscard]] bool failed() const;
|
2021-12-06 11:00:17 +00:00
|
|
|
[[nodiscard]] bool loadedOnce() const;
|
2020-05-28 13:51:18 +00:00
|
|
|
void load(not_null<Main::Session*> session, FileOrigin origin);
|
2020-05-27 14:31:39 +00:00
|
|
|
[[nodiscard]] const ImageLocation &location() const;
|
|
|
|
[[nodiscard]] int byteSize() const;
|
|
|
|
|
2022-12-05 12:18:10 +00:00
|
|
|
[[nodiscard]] std::shared_ptr<QImage> createView();
|
|
|
|
[[nodiscard]] std::shared_ptr<QImage> activeView() const;
|
2020-05-28 14:32:10 +00:00
|
|
|
[[nodiscard]] bool isCurrentView(
|
2022-12-05 12:18:10 +00:00
|
|
|
const std::shared_ptr<QImage> &view) const;
|
2020-05-27 14:31:39 +00:00
|
|
|
|
|
|
|
private:
|
2022-12-05 12:18:10 +00:00
|
|
|
void setToActive(not_null<Main::Session*> session, QImage image);
|
|
|
|
|
2020-05-27 14:31:39 +00:00
|
|
|
CloudFile _file;
|
2022-12-05 12:18:10 +00:00
|
|
|
std::weak_ptr<QImage> _view;
|
2020-05-27 14:31:39 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-05-26 11:59:45 +00:00
|
|
|
void UpdateCloudFile(
|
|
|
|
CloudFile &file,
|
|
|
|
const ImageWithLocation &data,
|
|
|
|
Storage::Cache::Database &cache,
|
2020-05-27 09:01:25 +00:00
|
|
|
uint8 cacheTag,
|
2020-05-26 11:59:45 +00:00
|
|
|
Fn<void(FileOrigin)> restartLoader,
|
2022-02-21 14:23:49 +00:00
|
|
|
Fn<void(QImage, QByteArray)> usePreloaded = nullptr);
|
2020-05-26 11:59:45 +00:00
|
|
|
|
2020-05-27 09:01:25 +00:00
|
|
|
void LoadCloudFile(
|
2020-06-08 15:17:33 +00:00
|
|
|
not_null<Main::Session*> session,
|
2020-05-27 09:01:25 +00:00
|
|
|
CloudFile &file,
|
|
|
|
FileOrigin origin,
|
|
|
|
LoadFromCloudSetting fromCloud,
|
|
|
|
bool autoLoading,
|
|
|
|
uint8 cacheTag,
|
|
|
|
Fn<bool()> finalCheck,
|
2022-02-21 14:23:49 +00:00
|
|
|
Fn<void(QImage, QByteArray)> done,
|
2020-05-27 09:01:25 +00:00
|
|
|
Fn<void(bool)> fail = nullptr,
|
2020-08-25 18:03:41 +00:00
|
|
|
Fn<void()> progress = nullptr,
|
|
|
|
int downloadFrontPartSize = 0);
|
2020-05-27 09:01:25 +00:00
|
|
|
|
|
|
|
void LoadCloudFile(
|
2020-06-08 15:17:33 +00:00
|
|
|
not_null<Main::Session*> session,
|
2020-05-27 09:01:25 +00:00
|
|
|
CloudFile &file,
|
|
|
|
FileOrigin origin,
|
|
|
|
LoadFromCloudSetting fromCloud,
|
|
|
|
bool autoLoading,
|
|
|
|
uint8 cacheTag,
|
|
|
|
Fn<bool()> finalCheck,
|
|
|
|
Fn<void(QByteArray)> done,
|
|
|
|
Fn<void(bool)> fail = nullptr,
|
|
|
|
Fn<void()> progress = nullptr);
|
|
|
|
|
2020-05-26 11:59:45 +00:00
|
|
|
} // namespace Data
|