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 "boxes/abstract_box.h"
11 #include "api/api_common.h"
12 #include "data/data_poll.h"
13 #include "base/flags.h"
14 
15 struct PollData;
16 
17 namespace Ui {
18 class VerticalLayout;
19 } // namespace Ui
20 
21 namespace Window {
22 class SessionController;
23 } // namespace Window
24 
25 namespace SendMenu {
26 enum class Type;
27 } // namespace SendMenu
28 
29 class CreatePollBox : public Ui::BoxContent {
30 public:
31 	struct Result {
32 		PollData poll;
33 		Api::SendOptions options;
34 	};
35 
36 	CreatePollBox(
37 		QWidget*,
38 		not_null<Window::SessionController*> controller,
39 		PollData::Flags chosen,
40 		PollData::Flags disabled,
41 		Api::SendType sendType,
42 		SendMenu::Type sendMenuType);
43 
44 	[[nodiscard]] rpl::producer<Result> submitRequests() const;
45 	void submitFailed(const QString &error);
46 
47 	void setInnerFocus() override;
48 
49 protected:
50 	void prepare() override;
51 
52 private:
53 	enum class Error {
54 		Question = 0x01,
55 		Options  = 0x02,
56 		Correct  = 0x04,
57 		Other    = 0x08,
58 		Solution = 0x10,
59 	};
is_flag_type(Error)60 	friend constexpr inline bool is_flag_type(Error) { return true; }
61 	using Errors = base::flags<Error>;
62 
63 	[[nodiscard]] object_ptr<Ui::RpWidget> setupContent();
64 	[[nodiscard]] not_null<Ui::InputField*> setupQuestion(
65 		not_null<Ui::VerticalLayout*> container);
66 	[[nodiscard]] not_null<Ui::InputField*> setupSolution(
67 		not_null<Ui::VerticalLayout*> container,
68 		rpl::producer<bool> shown);
69 
70 	const not_null<Window::SessionController*> _controller;
71 	const PollData::Flags _chosen = PollData::Flags();
72 	const PollData::Flags _disabled = PollData::Flags();
73 	const Api::SendType _sendType = Api::SendType();
74 	const SendMenu::Type _sendMenuType;
75 	Fn<void()> _setInnerFocus;
76 	Fn<rpl::producer<bool>()> _dataIsValidValue;
77 	rpl::event_stream<Result> _submitRequests;
78 
79 };
80