settings_common_session.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 "settings/settings_common.h"
  9. #include "ui/rp_widget.h"
  10. #include "base/object_ptr.h"
  11. #include "settings/settings_type.h"
  12. namespace Ui {
  13. class ScrollArea;
  14. } // namespace Ui
  15. namespace Ui::Menu {
  16. struct MenuCallback;
  17. } // namespace Ui::Menu
  18. namespace Window {
  19. class SessionController;
  20. } // namespace Window
  21. namespace Settings {
  22. enum class Container {
  23. Section,
  24. Layer,
  25. };
  26. class AbstractSection;
  27. struct AbstractSectionFactory {
  28. [[nodiscard]] virtual object_ptr<AbstractSection> create(
  29. not_null<QWidget*> parent,
  30. not_null<Window::SessionController*> controller,
  31. not_null<Ui::ScrollArea*> scroll,
  32. rpl::producer<Container> containerValue) const = 0;
  33. [[nodiscard]] virtual bool hasCustomTopBar() const {
  34. return false;
  35. }
  36. virtual ~AbstractSectionFactory() = default;
  37. };
  38. template <typename SectionType>
  39. struct SectionFactory : AbstractSectionFactory {
  40. object_ptr<AbstractSection> create(
  41. not_null<QWidget*> parent,
  42. not_null<Window::SessionController*> controller,
  43. not_null<Ui::ScrollArea*> scroll,
  44. rpl::producer<Container> containerValue
  45. ) const final override {
  46. return object_ptr<SectionType>(parent, controller);
  47. }
  48. [[nodiscard]] static const std::shared_ptr<SectionFactory> &Instance() {
  49. static const auto result = std::make_shared<SectionFactory>();
  50. return result;
  51. }
  52. };
  53. template <typename SectionType>
  54. class Section : public AbstractSection {
  55. public:
  56. using AbstractSection::AbstractSection;
  57. [[nodiscard]] static Type Id() {
  58. return SectionFactory<SectionType>::Instance();
  59. }
  60. [[nodiscard]] Type id() const final override {
  61. return Id();
  62. }
  63. [[nodiscard]] rpl::producer<Type> sectionShowOther() final override {
  64. return _showOtherRequests.events();
  65. }
  66. void showOther(Type type) {
  67. _showOtherRequests.fire_copy(type);
  68. }
  69. [[nodiscard]] Fn<void(Type)> showOtherMethod() {
  70. return crl::guard(this, [=](Type type) {
  71. showOther(type);
  72. });
  73. }
  74. private:
  75. rpl::event_stream<Type> _showOtherRequests;
  76. };
  77. bool HasMenu(Type type);
  78. } // namespace Settings