passport_panel.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #include "passport/passport_panel.h"
  8. #include "passport/passport_panel_controller.h"
  9. #include "passport/passport_panel_form.h"
  10. #include "passport/passport_panel_password.h"
  11. #include "ui/widgets/separate_panel.h"
  12. #include "ui/widgets/labels.h"
  13. #include "ui/wrap/padding_wrap.h"
  14. #include "lang/lang_keys.h"
  15. #include "styles/style_passport.h"
  16. #include "styles/style_widgets.h"
  17. #include "styles/style_calls.h"
  18. namespace Passport {
  19. Panel::Panel(not_null<PanelController*> controller)
  20. : _controller(controller)
  21. , _widget(std::make_unique<Ui::SeparatePanel>(Ui::SeparatePanelArgs{
  22. .onAllSpaces = true,
  23. })) {
  24. _widget->setTitle(tr::lng_passport_title());
  25. _widget->setInnerSize(st::passportPanelSize);
  26. _widget->closeRequests(
  27. ) | rpl::start_with_next([=] {
  28. _controller->cancelAuth();
  29. }, _widget->lifetime());
  30. _widget->closeEvents(
  31. ) | rpl::start_with_next([=] {
  32. _controller->cancelAuthSure();
  33. }, _widget->lifetime());
  34. }
  35. rpl::producer<> Panel::backRequests() const {
  36. return _widget->backRequests();
  37. }
  38. void Panel::setBackAllowed(bool allowed) {
  39. _widget->setBackAllowed(allowed);
  40. }
  41. not_null<Ui::RpWidget*> Panel::widget() const {
  42. return _widget.get();
  43. }
  44. int Panel::hideAndDestroyGetDuration() {
  45. return _widget->hideGetDuration();
  46. }
  47. void Panel::showAskPassword() {
  48. _widget->showInner(
  49. base::make_unique_q<PanelAskPassword>(_widget.get(), _controller));
  50. setBackAllowed(false);
  51. }
  52. void Panel::showNoPassword() {
  53. _widget->showInner(
  54. base::make_unique_q<PanelNoPassword>(_widget.get(), _controller));
  55. setBackAllowed(false);
  56. }
  57. void Panel::showCriticalError(const QString &error) {
  58. auto container = base::make_unique_q<Ui::PaddingWrap<Ui::FlatLabel>>(
  59. _widget.get(),
  60. object_ptr<Ui::FlatLabel>(
  61. _widget.get(),
  62. error,
  63. st::passportErrorLabel),
  64. style::margins(0, st::passportPanelSize.height() / 3, 0, 0));
  65. container->widthValue(
  66. ) | rpl::start_with_next([label = container->entity()](int width) {
  67. label->resize(width, label->height());
  68. }, container->lifetime());
  69. _widget->showInner(std::move(container));
  70. setBackAllowed(false);
  71. }
  72. void Panel::showForm() {
  73. _widget->showInner(
  74. base::make_unique_q<PanelForm>(_widget.get(), _controller));
  75. setBackAllowed(false);
  76. }
  77. void Panel::showEditValue(object_ptr<Ui::RpWidget> from) {
  78. _widget->showInner(base::unique_qptr<Ui::RpWidget>(from.data()));
  79. }
  80. void Panel::showBox(
  81. object_ptr<Ui::BoxContent> box,
  82. Ui::LayerOptions options,
  83. anim::type animated) {
  84. _widget->showBox(std::move(box), options, animated);
  85. _widget->showAndActivate();
  86. }
  87. void Panel::showToast(const QString &text) {
  88. _widget->showToast({ text });
  89. }
  90. Panel::~Panel() = default;
  91. } // namespace Passport