window_controller.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 "mainwindow.h"
  9. #include "window/window_adaptive.h"
  10. #include "window/window_separate_id.h"
  11. namespace Main {
  12. class Account;
  13. class Session;
  14. } // namespace Main
  15. namespace Ui {
  16. class Show;
  17. } // namespace Ui
  18. namespace Ui::Toast {
  19. struct Config;
  20. } // namespace Ui::Toast
  21. namespace Media::View {
  22. struct OpenRequest;
  23. } // namespace Media::View
  24. namespace Media::Player {
  25. class FloatDelegate;
  26. } // namespace Media::Player
  27. namespace Window {
  28. class Controller final : public base::has_weak_ptr {
  29. public:
  30. Controller();
  31. Controller(SeparateId id, MsgId showAtMsgId);
  32. ~Controller();
  33. Controller(const Controller &other) = delete;
  34. Controller &operator=(const Controller &other) = delete;
  35. void showAccount(not_null<Main::Account*> account);
  36. [[nodiscard]] SeparateId id() const;
  37. [[nodiscard]] bool isPrimary() const;
  38. [[nodiscard]] not_null<::MainWindow*> widget() {
  39. return &_widget;
  40. }
  41. [[nodiscard]] Main::Account &account() const;
  42. [[nodiscard]] Main::Session *maybeSession() const;
  43. [[nodiscard]] SessionController *sessionController() const {
  44. return _sessionController.get();
  45. }
  46. [[nodiscard]] auto sessionControllerValue() const
  47. -> rpl::producer<SessionController*>;
  48. [[nodiscard]] auto sessionControllerChanges() const
  49. -> rpl::producer<SessionController*>;
  50. [[nodiscard]] bool locked() const;
  51. [[nodiscard]] Adaptive &adaptive() const;
  52. void firstShow();
  53. void finishFirstShow();
  54. void setupPasscodeLock();
  55. void clearPasscodeLock();
  56. void showLogoutConfirmation();
  57. void showSettings();
  58. [[nodiscard]] int verticalShadowTop() const;
  59. void showToast(Ui::Toast::Config &&config);
  60. void showToast(TextWithEntities &&text, crl::time duration = 0);
  61. void showToast(const QString &text, crl::time duration = 0);
  62. void showRightColumn(object_ptr<TWidget> widget);
  63. void showBox(
  64. object_ptr<Ui::BoxContent> content,
  65. Ui::LayerOptions options,
  66. anim::type animated);
  67. void showLayer(
  68. std::unique_ptr<Ui::LayerWidget> &&layer,
  69. Ui::LayerOptions options,
  70. anim::type animated = anim::type::normal);
  71. void hideLayer(anim::type animated = anim::type::normal);
  72. void hideSettingsAndLayer(anim::type animated = anim::type::normal);
  73. [[nodiscard]] bool isLayerShown() const;
  74. template <
  75. typename BoxType,
  76. typename = std::enable_if_t<
  77. std::is_base_of_v<Ui::BoxContent, BoxType>>>
  78. QPointer<BoxType> show(
  79. object_ptr<BoxType> content,
  80. Ui::LayerOptions options = Ui::LayerOption::KeepOther,
  81. anim::type animated = anim::type()) {
  82. auto result = QPointer<BoxType>(content.data());
  83. showBox(std::move(content), options, animated);
  84. return result;
  85. }
  86. void activate();
  87. void updateIsActiveFocus();
  88. void updateIsActiveBlur();
  89. void updateIsActive();
  90. void minimize();
  91. void close();
  92. void preventOrInvoke(Fn<void()> &&callback);
  93. void invokeForSessionController(
  94. not_null<Main::Account*> account,
  95. PeerData *singlePeer,
  96. Fn<void(not_null<SessionController*>)> &&callback);
  97. void openInMediaView(Media::View::OpenRequest &&request);
  98. [[nodiscard]] auto openInMediaViewRequests() const
  99. -> rpl::producer<Media::View::OpenRequest>;
  100. [[nodiscard]] QPoint getPointForCallPanelCenter() const;
  101. using FloatDelegate = Media::Player::FloatDelegate;
  102. void setDefaultFloatPlayerDelegate(
  103. not_null<Media::Player::FloatDelegate*> delegate);
  104. void replaceFloatPlayerDelegate(
  105. not_null<Media::Player::FloatDelegate*> replacement);
  106. void restoreFloatPlayerDelegate(
  107. not_null<Media::Player::FloatDelegate*> replacement);
  108. [[nodiscard]] FloatDelegate *floatPlayerDelegate() const;
  109. [[nodiscard]] auto floatPlayerDelegateValue() const
  110. -> rpl::producer<FloatDelegate*>;
  111. [[nodiscard]] std::shared_ptr<Ui::Show> uiShow();
  112. [[nodiscard]] rpl::lifetime &lifetime();
  113. private:
  114. struct CreateArgs {
  115. SeparateId id;
  116. };
  117. explicit Controller(CreateArgs &&args);
  118. void setupIntro(QPixmap oldContentCache);
  119. void setupMain(MsgId singlePeerShowAtMsgId, QPixmap oldContentCache);
  120. void showAccount(
  121. not_null<Main::Account*> account,
  122. MsgId singlePeerShowAtMsgId);
  123. void setupSideBar();
  124. void sideBarChanged();
  125. void checkThemeEditor();
  126. void checkLockByTerms();
  127. void showTermsDecline();
  128. void showTermsDelete();
  129. SeparateId _id;
  130. base::Timer _isActiveTimer;
  131. ::MainWindow _widget;
  132. const std::unique_ptr<Adaptive> _adaptive;
  133. std::unique_ptr<SessionController> _sessionController;
  134. rpl::variable<SessionController*> _sessionControllerValue;
  135. QPointer<Ui::BoxContent> _termsBox;
  136. rpl::event_stream<Media::View::OpenRequest> _openInMediaViewRequests;
  137. FloatDelegate *_defaultFloatPlayerDelegate = nullptr;
  138. FloatDelegate *_replacementFloatPlayerDelegate = nullptr;
  139. rpl::variable<FloatDelegate*> _floatPlayerDelegate = nullptr;
  140. rpl::lifetime _accountLifetime;
  141. rpl::lifetime _lifetime;
  142. };
  143. } // namespace Window