1 /*
2 This file is part of Telegram Desktop,
3 the official desktop application for the Telegram messaging service.
4 
5 For license and copyright information please follow this link:
6 https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
7 */
8 #pragma once
9 
10 #include "data/data_file_origin.h"
11 #include "ui/basic_click_handlers.h"
12 
13 class DocumentData;
14 class HistoryItem;
15 class PhotoData;
16 
17 class FileClickHandler : public LeftButtonClickHandler {
18 public:
19 	FileClickHandler(FullMsgId context);
20 
21 	void setMessageId(FullMsgId context);
22 
23 	[[nodiscard]] FullMsgId context() const;
24 
25 private:
26 	FullMsgId _context;
27 
28 };
29 
30 class DocumentClickHandler : public FileClickHandler {
31 public:
32 	DocumentClickHandler(
33 		not_null<DocumentData*> document,
34 		FullMsgId context = FullMsgId());
35 
36 	[[nodiscard]] not_null<DocumentData*> document() const;
37 
38 private:
39 	const not_null<DocumentData*> _document;
40 
41 };
42 
43 class DocumentSaveClickHandler : public DocumentClickHandler {
44 public:
45 	enum class Mode {
46 		ToCacheOrFile,
47 		ToFile,
48 		ToNewFile,
49 	};
50 	using DocumentClickHandler::DocumentClickHandler;
51 	static void Save(
52 		Data::FileOrigin origin,
53 		not_null<DocumentData*> document,
54 		Mode mode = Mode::ToCacheOrFile);
55 
56 protected:
57 	void onClickImpl() const override;
58 
59 };
60 
61 class DocumentOpenClickHandler : public DocumentClickHandler {
62 public:
63 	DocumentOpenClickHandler(
64 		not_null<DocumentData*> document,
65 		Fn<void(FullMsgId)> &&callback,
66 		FullMsgId context = FullMsgId());
67 
68 protected:
69 	void onClickImpl() const override;
70 
71 private:
72 	const Fn<void(FullMsgId)> _handler;
73 
74 };
75 
76 class DocumentCancelClickHandler : public DocumentClickHandler {
77 public:
78 	DocumentCancelClickHandler(
79 		not_null<DocumentData*> document,
80 		Fn<void(FullMsgId)> &&callback,
81 		FullMsgId context = FullMsgId());
82 
83 protected:
84 	void onClickImpl() const override;
85 
86 private:
87 	const Fn<void(FullMsgId)> _handler;
88 
89 };
90 
91 class DocumentOpenWithClickHandler : public DocumentClickHandler {
92 public:
93 	using DocumentClickHandler::DocumentClickHandler;
94 	static void Open(
95 		Data::FileOrigin origin,
96 		not_null<DocumentData*> document);
97 
98 protected:
99 	void onClickImpl() const override;
100 
101 };
102 
103 class VoiceSeekClickHandler : public DocumentOpenClickHandler {
104 public:
105 	using DocumentOpenClickHandler::DocumentOpenClickHandler;
106 
107 protected:
onClickImpl()108 	void onClickImpl() const override {
109 	}
110 
111 };
112 
113 class DocumentWrappedClickHandler : public DocumentClickHandler {
114 public:
115 	DocumentWrappedClickHandler(
116 		ClickHandlerPtr wrapped,
117 		not_null<DocumentData*> document,
118 		FullMsgId context = FullMsgId());
119 
120 protected:
121 	void onClickImpl() const override;
122 
123 private:
124 	ClickHandlerPtr _wrapped;
125 
126 };
127 
128 class PhotoClickHandler : public FileClickHandler {
129 public:
130 	PhotoClickHandler(
131 		not_null<PhotoData*> photo,
132 		FullMsgId context = FullMsgId(),
133 		PeerData *peer = nullptr);
134 
135 	[[nodiscard]] not_null<PhotoData*> photo() const;
136 	[[nodiscard]] PeerData *peer() const;
137 
138 private:
139 	const not_null<PhotoData*> _photo;
140 	PeerData * const _peer = nullptr;
141 
142 };
143 
144 class PhotoOpenClickHandler : public PhotoClickHandler {
145 public:
146 	PhotoOpenClickHandler(
147 		not_null<PhotoData*> photo,
148 		Fn<void(FullMsgId)> &&callback,
149 		FullMsgId context = FullMsgId());
150 
151 protected:
152 	void onClickImpl() const override;
153 
154 private:
155 	const Fn<void(FullMsgId)> _handler;
156 
157 };
158 
159 class PhotoSaveClickHandler : public PhotoClickHandler {
160 public:
161 	using PhotoClickHandler::PhotoClickHandler;
162 
163 protected:
164 	void onClickImpl() const override;
165 
166 };
167 
168 class PhotoCancelClickHandler : public PhotoClickHandler {
169 public:
170 	PhotoCancelClickHandler(
171 		not_null<PhotoData*> photo,
172 		Fn<void(FullMsgId)> &&callback,
173 		FullMsgId context = FullMsgId());
174 
175 protected:
176 	void onClickImpl() const override;
177 
178 private:
179 	const Fn<void(FullMsgId)> _handler;
180 
181 };
182