intro_widget.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 "mtproto/sender.h"
  9. #include "ui/rp_widget.h"
  10. #include "ui/effects/animations.h"
  11. #include "window/window_lock_widgets.h"
  12. #include "core/core_cloud_password.h"
  13. #include "media/player/media_player_float.h"
  14. namespace Main {
  15. class Account;
  16. } // namespace Main
  17. namespace Ui {
  18. class IconButton;
  19. class RoundButton;
  20. class LinkButton;
  21. class FlatLabel;
  22. template <typename Widget>
  23. class FadeWrap;
  24. } // namespace Ui
  25. namespace Window {
  26. class ConnectionState;
  27. class Controller;
  28. class SlideAnimation;
  29. } // namespace Window
  30. namespace Intro {
  31. namespace details {
  32. enum class CallStatus {
  33. Waiting,
  34. Calling,
  35. Called,
  36. Disabled,
  37. };
  38. struct Data {
  39. // Required for the UserpicButton.
  40. const not_null<Window::Controller*> controller;
  41. QString country;
  42. QString phone;
  43. QByteArray phoneHash;
  44. CallStatus callStatus = CallStatus::Disabled;
  45. int callTimeout = 0;
  46. int codeLength = 5;
  47. bool codeByTelegram = false;
  48. QString codeByFragmentUrl;
  49. Core::CloudPasswordState pwdState;
  50. Window::TermsLock termsLock;
  51. rpl::event_stream<> updated;
  52. };
  53. enum class StackAction {
  54. Back,
  55. Forward,
  56. Replace,
  57. };
  58. enum class Animate {
  59. Back,
  60. Forward,
  61. };
  62. class Step;
  63. } // namespace details
  64. enum class EnterPoint : uchar {
  65. Start,
  66. Phone,
  67. Qr,
  68. };
  69. class Widget
  70. : public Ui::RpWidget
  71. , private Media::Player::FloatDelegate
  72. , private Media::Player::FloatSectionDelegate {
  73. public:
  74. Widget(
  75. QWidget *parent,
  76. not_null<Window::Controller*> controller,
  77. not_null<Main::Account*> account,
  78. EnterPoint point);
  79. ~Widget();
  80. void showAnimated(QPixmap oldContentCache, bool back = false);
  81. void setInnerFocus();
  82. [[nodiscard]] rpl::producer<> showSettingsRequested() const;
  83. protected:
  84. void paintEvent(QPaintEvent *e) override;
  85. void resizeEvent(QResizeEvent *e) override;
  86. void keyPressEvent(QKeyEvent *e) override;
  87. private:
  88. void refreshLang();
  89. void showFinished();
  90. void createLanguageLink();
  91. void checkUpdateStatus();
  92. void setupNextButton();
  93. void handleUpdates(const MTPUpdates &updates);
  94. void handleUpdate(const MTPUpdate &update);
  95. void backRequested();
  96. void updateControlsGeometry();
  97. [[nodiscard]] not_null<details::Data*> getData() {
  98. return &_data;
  99. }
  100. void fixOrder();
  101. void showControls();
  102. void hideControls();
  103. void showResetButton();
  104. void resetAccount();
  105. void showTerms();
  106. void acceptTerms(Fn<void()> callback);
  107. void hideAndDestroy(object_ptr<Ui::FadeWrap<Ui::RpWidget>> widget);
  108. [[nodiscard]] details::Step *getStep(int skip = 0) const {
  109. Expects(skip >= 0);
  110. Expects(skip < _stepHistory.size());
  111. return _stepHistory[_stepHistory.size() - skip - 1];
  112. }
  113. void historyMove(details::StackAction action, details::Animate animate);
  114. void moveToStep(
  115. details::Step *step,
  116. details::StackAction action,
  117. details::Animate animate);
  118. void appendStep(details::Step *step);
  119. void getNearestDC();
  120. void showTerms(Fn<void()> callback);
  121. // FloatDelegate
  122. [[nodiscard]] auto floatPlayerDelegate()
  123. -> not_null<Media::Player::FloatDelegate*>;
  124. [[nodiscard]] auto floatPlayerSectionDelegate()
  125. -> not_null<Media::Player::FloatSectionDelegate*>;
  126. not_null<Ui::RpWidget*> floatPlayerWidget() override;
  127. void floatPlayerToggleGifsPaused(bool paused) override;
  128. not_null<Media::Player::FloatSectionDelegate*> floatPlayerGetSection(
  129. Window::Column column) override;
  130. void floatPlayerEnumerateSections(Fn<void(
  131. not_null<Media::Player::FloatSectionDelegate*> widget,
  132. Window::Column widgetColumn)> callback) override;
  133. bool floatPlayerIsVisible(not_null<HistoryItem*> item) override;
  134. void floatPlayerDoubleClickEvent(
  135. not_null<const HistoryItem*> item) override;
  136. // FloatSectionDelegate
  137. QRect floatPlayerAvailableRect() override;
  138. bool floatPlayerHandleWheelEvent(QEvent *e) override;
  139. const not_null<Main::Account*> _account;
  140. std::optional<MTP::Sender> _api;
  141. mtpRequestId _nearestDcRequestId = 0;
  142. std::unique_ptr<Window::SlideAnimation> _showAnimation;
  143. std::vector<details::Step*> _stepHistory;
  144. rpl::lifetime _stepLifetime;
  145. details::Data _data;
  146. Ui::Animations::Simple _coverShownAnimation;
  147. int _nextTopFrom = 0;
  148. int _controlsTopFrom = 0;
  149. const style::RoundButton *_nextStyle = nullptr;
  150. object_ptr<Ui::FadeWrap<Ui::IconButton>> _back;
  151. object_ptr<Ui::FadeWrap<Ui::RoundButton>> _update = { nullptr };
  152. object_ptr<Ui::FadeWrap<Ui::RoundButton>> _settings;
  153. object_ptr<Ui::FadeWrap<Ui::RoundButton>> _next;
  154. object_ptr<Ui::FadeWrap<Ui::LinkButton>> _changeLanguage = { nullptr };
  155. object_ptr<Ui::FadeWrap<Ui::RoundButton>> _resetAccount = { nullptr };
  156. object_ptr<Ui::FadeWrap<Ui::FlatLabel>> _terms = { nullptr };
  157. std::unique_ptr<Window::ConnectionState> _connecting;
  158. bool _nextShown = true;
  159. Ui::Animations::Simple _nextShownAnimation;
  160. mtpRequestId _resetRequest = 0;
  161. };
  162. } // namespace Intro