sent_code_field.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 "base/timer.h"
  9. #include "ui/widgets/fields/input_field.h"
  10. namespace Ui {
  11. class SentCodeField final : public Ui::InputField {
  12. public:
  13. SentCodeField(
  14. QWidget *parent,
  15. const style::InputField &st,
  16. rpl::producer<QString> placeholder = nullptr,
  17. const QString &val = QString());
  18. void setAutoSubmit(int length, Fn<void()> submitCallback);
  19. void setChangedCallback(Fn<void()> changedCallback);
  20. [[nodiscard]] QString getDigitsOnly() const;
  21. private:
  22. void fix();
  23. // Flag for not calling onTextChanged() recursively.
  24. bool _fixing = false;
  25. int _autoSubmitLength = 0;
  26. Fn<void()> _submitCallback;
  27. Fn<void()> _changedCallback;
  28. };
  29. class SentCodeCall final {
  30. public:
  31. SentCodeCall(
  32. FnMut<void()> callCallback,
  33. Fn<void()> updateCallback);
  34. enum class State {
  35. Waiting,
  36. Calling,
  37. Called,
  38. Disabled,
  39. };
  40. struct Status {
  41. Status() {
  42. }
  43. Status(State state, int timeout) : state(state), timeout(timeout) {
  44. }
  45. State state = State::Disabled;
  46. int timeout = 0;
  47. };
  48. void setStatus(const Status &status);
  49. void callDone();
  50. [[nodiscard]] QString getText() const;
  51. private:
  52. Status _status;
  53. base::Timer _timer;
  54. FnMut<void()> _call;
  55. Fn<void()> _update;
  56. };
  57. } // namespace Ui