edit_privacy_box.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "ui/layers/box_content.h"
  9. #include "mtproto/sender.h"
  10. #include "api/api_user_privacy.h"
  11. namespace Ui {
  12. class GenericBox;
  13. class VerticalLayout;
  14. class FlatLabel;
  15. class LinkButton;
  16. template <typename Enum>
  17. class RadioenumGroup;
  18. template <typename Enum>
  19. class Radioenum;
  20. template <typename Widget>
  21. class SlideWrap;
  22. } // namespace Ui
  23. namespace Window {
  24. class SessionController;
  25. } // namespace Window
  26. class EditPrivacyBox;
  27. class EditPrivacyController {
  28. public:
  29. using Key = Api::UserPrivacy::Key;
  30. using Option = Api::UserPrivacy::Option;
  31. enum class Exception {
  32. Always,
  33. Never,
  34. };
  35. [[nodiscard]] virtual Key key() const = 0;
  36. [[nodiscard]] virtual rpl::producer<QString> title() const = 0;
  37. [[nodiscard]] virtual bool hasOption(Option option) const;
  38. [[nodiscard]] virtual rpl::producer<QString> optionsTitleKey() const = 0;
  39. [[nodiscard]] virtual QString optionLabel(Option option) const;
  40. [[nodiscard]] virtual rpl::producer<TextWithEntities> warning() const {
  41. return nullptr;
  42. }
  43. virtual void prepareWarningLabel(
  44. not_null<Ui::FlatLabel*> warning) const {
  45. }
  46. [[nodiscard]] virtual rpl::producer<QString> exceptionButtonTextKey(
  47. Exception exception) const = 0;
  48. [[nodiscard]] virtual rpl::producer<QString> exceptionBoxTitle(
  49. Exception exception) const = 0;
  50. [[nodiscard]] virtual auto exceptionsDescription()
  51. const -> rpl::producer<QString> = 0;
  52. [[nodiscard]] virtual bool allowPremiumsToggle(
  53. Exception exception) const {
  54. return false;
  55. }
  56. [[nodiscard]] virtual bool allowMiniAppsToggle(
  57. Exception exception) const {
  58. return false;
  59. }
  60. virtual void handleExceptionsChange(
  61. Exception exception,
  62. rpl::producer<int> value) {
  63. }
  64. [[nodiscard]] virtual object_ptr<Ui::RpWidget> setupAboveWidget(
  65. not_null<Window::SessionController*> controller,
  66. not_null<QWidget*> parent,
  67. rpl::producer<Option> option,
  68. not_null<QWidget*> outerContainer) {
  69. return { nullptr };
  70. }
  71. [[nodiscard]] virtual object_ptr<Ui::RpWidget> setupMiddleWidget(
  72. not_null<Window::SessionController*> controller,
  73. not_null<QWidget*> parent,
  74. rpl::producer<Option> option) {
  75. return { nullptr };
  76. }
  77. [[nodiscard]] virtual object_ptr<Ui::RpWidget> setupBelowWidget(
  78. not_null<Window::SessionController*> controller,
  79. not_null<QWidget*> parent,
  80. rpl::producer<Option> option) {
  81. return { nullptr };
  82. }
  83. virtual void confirmSave(
  84. bool someAreDisallowed,
  85. Fn<void()> saveCallback) {
  86. saveCallback();
  87. }
  88. virtual void saveAdditional() {
  89. }
  90. [[nodiscard]] virtual Fn<void()> premiumClickedCallback(
  91. Option option,
  92. not_null<Window::SessionController*> controller) {
  93. return nullptr;
  94. }
  95. virtual ~EditPrivacyController() = default;
  96. protected:
  97. [[nodiscard]] EditPrivacyBox *view() const {
  98. return _view;
  99. }
  100. private:
  101. void setView(EditPrivacyBox *box) {
  102. _view = box;
  103. }
  104. EditPrivacyBox *_view = nullptr;
  105. friend class EditPrivacyBox;
  106. };
  107. class EditPrivacyBox final : public Ui::BoxContent {
  108. public:
  109. using Value = Api::UserPrivacy::Rule;
  110. using Option = Api::UserPrivacy::Option;
  111. using Exceptions = Api::UserPrivacy::Exceptions;
  112. using Exception = EditPrivacyController::Exception;
  113. EditPrivacyBox(
  114. QWidget*,
  115. not_null<Window::SessionController*> window,
  116. std::unique_ptr<EditPrivacyController> controller,
  117. const Value &value);
  118. static Ui::Radioenum<Option> *AddOption(
  119. not_null<Ui::VerticalLayout*> container,
  120. not_null<EditPrivacyController*> controller,
  121. const std::shared_ptr<Ui::RadioenumGroup<Option>> &group,
  122. Option option);
  123. protected:
  124. void prepare() override;
  125. private:
  126. bool showExceptionLink(Exception exception) const;
  127. void setupContent();
  128. Ui::FlatLabel *addLabel(
  129. not_null<Ui::VerticalLayout*> container,
  130. rpl::producer<TextWithEntities> text,
  131. int topSkip);
  132. Ui::FlatLabel *addLabelOrDivider(
  133. not_null<Ui::VerticalLayout*> container,
  134. rpl::producer<TextWithEntities> text,
  135. int topSkip);
  136. void editExceptions(Exception exception, Fn<void()> done);
  137. Exceptions &exceptions(Exception exception);
  138. const not_null<Window::SessionController*> _window;
  139. std::unique_ptr<EditPrivacyController> _controller;
  140. Value _value;
  141. };
  142. void EditMessagesPrivacyBox(
  143. not_null<Ui::GenericBox*> box,
  144. not_null<Window::SessionController*> controller);
  145. [[nodiscard]] rpl::producer<int> SetupChargeSlider(
  146. not_null<Ui::VerticalLayout*> container,
  147. not_null<PeerData*> peer,
  148. int savedValue);