window_lock_widgets.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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/rp_widget.h"
  9. #include "ui/effects/animations.h"
  10. #include "ui/layers/box_content.h"
  11. #include "base/bytes.h"
  12. #include "base/timer.h"
  13. namespace base {
  14. enum class SystemUnlockResult;
  15. } // namespace base
  16. namespace Ui {
  17. class PasswordInput;
  18. class LinkButton;
  19. class RoundButton;
  20. class CheckView;
  21. } // namespace Ui
  22. namespace Main {
  23. class Session;
  24. } // namespace Main
  25. namespace Window {
  26. class Controller;
  27. class SlideAnimation;
  28. class LockWidget : public Ui::RpWidget {
  29. public:
  30. LockWidget(QWidget *parent, not_null<Controller*> window);
  31. ~LockWidget();
  32. [[nodiscard]] not_null<Controller*> window() const;
  33. virtual void setInnerFocus();
  34. void showAnimated(QPixmap oldContentCache);
  35. void showFinished();
  36. protected:
  37. void paintEvent(QPaintEvent *e) override;
  38. virtual void paintContent(QPainter &p);
  39. private:
  40. const not_null<Controller*> _window;
  41. std::unique_ptr<SlideAnimation> _showAnimation;
  42. };
  43. class PasscodeLockWidget : public LockWidget {
  44. public:
  45. PasscodeLockWidget(QWidget *parent, not_null<Controller*> window);
  46. void setInnerFocus() override;
  47. protected:
  48. void resizeEvent(QResizeEvent *e) override;
  49. private:
  50. enum class SystemUnlockType : uchar {
  51. None,
  52. Default,
  53. Biometrics,
  54. Companion,
  55. };
  56. void paintContent(QPainter &p) override;
  57. void setupSystemUnlockInfo();
  58. void setupSystemUnlock();
  59. void suggestSystemUnlock();
  60. void systemUnlockDone(base::SystemUnlockResult result);
  61. void changed();
  62. void submit();
  63. void error();
  64. rpl::variable<SystemUnlockType> _systemUnlockAvailable;
  65. rpl::variable<SystemUnlockType> _systemUnlockAllowed;
  66. object_ptr<Ui::PasswordInput> _passcode;
  67. object_ptr<Ui::RoundButton> _submit;
  68. object_ptr<Ui::LinkButton> _logout;
  69. QString _error;
  70. rpl::lifetime _systemUnlockSuggested;
  71. base::Timer _systemUnlockCooldown;
  72. };
  73. struct TermsLock {
  74. bytes::vector id;
  75. TextWithEntities text;
  76. std::optional<int> minAge;
  77. bool popup = false;
  78. inline bool operator==(const TermsLock &other) const {
  79. return (id == other.id);
  80. }
  81. inline bool operator!=(const TermsLock &other) const {
  82. return !(*this == other);
  83. }
  84. static TermsLock FromMTP(
  85. Main::Session *session,
  86. const MTPDhelp_termsOfService &data);
  87. };
  88. class TermsBox : public Ui::BoxContent {
  89. public:
  90. TermsBox(
  91. QWidget*,
  92. const TermsLock &data,
  93. rpl::producer<QString> agree,
  94. rpl::producer<QString> cancel);
  95. TermsBox(
  96. QWidget*,
  97. const TextWithEntities &text,
  98. rpl::producer<QString> agree,
  99. rpl::producer<QString> cancel,
  100. bool attentionAgree = false);
  101. rpl::producer<> agreeClicks() const;
  102. rpl::producer<> cancelClicks() const;
  103. QString lastClickedMention() const;
  104. protected:
  105. void prepare() override;
  106. void keyPressEvent(QKeyEvent *e) override;
  107. private:
  108. TermsLock _data;
  109. rpl::producer<QString> _agree;
  110. rpl::producer<QString> _cancel;
  111. rpl::event_stream<> _agreeClicks;
  112. rpl::event_stream<> _cancelClicks;
  113. QString _lastClickedMention;
  114. bool _attentionAgree = false;
  115. bool _ageErrorShown = false;
  116. Ui::Animations::Simple _ageErrorAnimation;
  117. };
  118. } // namespace Window