File: data_cloud_file.h

package info (click to toggle)
telegram-desktop 4.6.5%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 53,300 kB
  • sloc: cpp: 605,857; python: 3,978; ansic: 1,636; sh: 965; makefile: 841; objc: 652; javascript: 187; xml: 165
file content (117 lines) | stat: -rw-r--r-- 2,722 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
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"
#include "ui/image/image.h"
#include "ui/image/image_location.h"

class FileLoader;

namespace Storage {
namespace Cache {
class Database;
} // namespace Cache
} // namespace Storage

namespace Main {
class Session;
} // namespace Main

namespace Data {

struct FileOrigin;

struct CloudFile final {
	enum class Flag : uchar {
		Cancelled = 0x01,
		Failed = 0x02,
		Loaded = 0x04,
	};
	friend inline constexpr bool is_flag_type(Flag) { return true; };

	~CloudFile();

	ImageLocation location;
	std::unique_ptr<FileLoader> loader;
	int byteSize = 0;
	int progressivePartSize = 0;
	base::flags<Flag> flags;
};

class CloudImage final {
public:
	CloudImage();
	CloudImage(
		not_null<Main::Session*> session,
		const ImageWithLocation &data);

	// This method will replace the location and zero the _view pointer.
	void set(
		not_null<Main::Session*> session,
		const ImageWithLocation &data);

	void update(
		not_null<Main::Session*> session,
		const ImageWithLocation &data);

	[[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;

	[[nodiscard]] std::shared_ptr<QImage> createView();
	[[nodiscard]] std::shared_ptr<QImage> activeView() const;
	[[nodiscard]] bool isCurrentView(
		const std::shared_ptr<QImage> &view) const;

private:
	void setToActive(not_null<Main::Session*> session, QImage image);

	CloudFile _file;
	std::weak_ptr<QImage> _view;

};

void UpdateCloudFile(
	CloudFile &file,
	const ImageWithLocation &data,
	Storage::Cache::Database &cache,
	uint8 cacheTag,
	Fn<void(FileOrigin)> restartLoader,
	Fn<void(QImage, QByteArray)> usePreloaded = nullptr);

void LoadCloudFile(
	not_null<Main::Session*> session,
	CloudFile &file,
	FileOrigin origin,
	LoadFromCloudSetting fromCloud,
	bool autoLoading,
	uint8 cacheTag,
	Fn<bool()> finalCheck,
	Fn<void(QImage, QByteArray)> done,
	Fn<void(bool)> fail = nullptr,
	Fn<void()> progress = nullptr,
	int downloadFrontPartSize = 0);

void LoadCloudFile(
	not_null<Main::Session*> session,
	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);

} // namespace Data