2016-07-28 17:01:08 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-07-28 17:01:08 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-07-28 17:01:08 +00:00
|
|
|
*/
|
2021-10-18 22:43:50 +00:00
|
|
|
#include "ui/boxes/confirm_phone_box.h"
|
2016-07-28 17:01:08 +00:00
|
|
|
|
2021-10-18 21:36:55 +00:00
|
|
|
#include "ui/boxes/confirm_box.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-16 10:44:06 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
2021-07-26 06:32:16 +00:00
|
|
|
#include "ui/text/format_values.h" // Ui::FormatPhone
|
2019-06-23 13:40:59 +00:00
|
|
|
#include "ui/text/text_utilities.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_layers.h"
|
|
|
|
#include "styles/style_boxes.h"
|
2016-07-28 17:01:08 +00:00
|
|
|
|
2021-10-18 22:43:50 +00:00
|
|
|
namespace Ui {
|
|
|
|
|
2020-06-11 16:09:46 +00:00
|
|
|
ConfirmPhoneBox::ConfirmPhoneBox(
|
|
|
|
QWidget*,
|
|
|
|
const QString &phone,
|
2021-10-18 19:49:42 +00:00
|
|
|
int codeLength,
|
|
|
|
std::optional<int> timeout)
|
|
|
|
: _phone(phone)
|
|
|
|
, _sentCodeLength(codeLength)
|
2018-04-09 17:56:07 +00:00
|
|
|
, _call([this] { sendCall(); }, [this] { update(); }) {
|
2021-10-18 19:49:42 +00:00
|
|
|
if (timeout) {
|
|
|
|
_call.setStatus({ Ui::SentCodeCall::State::Waiting, *timeout });
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
2016-07-28 17:01:08 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 19:49:42 +00:00
|
|
|
void ConfirmPhoneBox::sendCall() {
|
|
|
|
_resendRequests.fire({});
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmPhoneBox::prepare() {
|
2019-06-23 13:40:59 +00:00
|
|
|
_about.create(
|
|
|
|
this,
|
|
|
|
tr::lng_confirm_phone_about(
|
|
|
|
lt_phone,
|
2021-07-26 06:32:16 +00:00
|
|
|
rpl::single(Ui::Text::Bold(Ui::FormatPhone(_phone))),
|
2019-06-23 13:40:59 +00:00
|
|
|
Ui::Text::WithEntities),
|
|
|
|
st::confirmPhoneAboutLabel);
|
2016-07-28 17:01:08 +00:00
|
|
|
|
2019-06-18 14:07:45 +00:00
|
|
|
_code.create(this, st::confirmPhoneCodeField, tr::lng_code_ph());
|
2018-05-31 12:20:28 +00:00
|
|
|
_code->setAutoSubmit(_sentCodeLength, [=] { sendCode(); });
|
|
|
|
_code->setChangedCallback([=] { showError(QString()); });
|
2016-07-28 17:01:08 +00:00
|
|
|
|
2019-06-18 15:00:55 +00:00
|
|
|
setTitle(tr::lng_confirm_phone_title());
|
2016-07-28 17:01:08 +00:00
|
|
|
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(tr::lng_confirm_phone_send(), [=] { sendCode(); });
|
|
|
|
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
2016-07-28 17:01:08 +00:00
|
|
|
|
2021-10-18 19:49:42 +00:00
|
|
|
setDimensions(
|
|
|
|
st::boxWidth,
|
|
|
|
st::usernamePadding.top()
|
|
|
|
+ _code->height()
|
|
|
|
+ st::usernameSkip
|
|
|
|
+ _about->height()
|
|
|
|
+ st::usernameSkip);
|
2016-07-28 17:01:08 +00:00
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
connect(_code, &Ui::InputField::submitted, [=] { sendCode(); });
|
2016-07-28 17:01:08 +00:00
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
showChildren();
|
2016-07-28 17:01:08 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
void ConfirmPhoneBox::sendCode() {
|
2021-10-18 19:49:42 +00:00
|
|
|
if (_isWaitingCheck) {
|
2016-07-28 17:01:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-11-19 12:15:59 +00:00
|
|
|
const auto code = _code->getDigitsOnly();
|
2016-07-28 17:01:08 +00:00
|
|
|
if (code.isEmpty()) {
|
|
|
|
_code->showError();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_code->setDisabled(true);
|
|
|
|
setFocus();
|
|
|
|
|
|
|
|
showError(QString());
|
|
|
|
|
2021-10-18 19:49:42 +00:00
|
|
|
_checkRequests.fire_copy(code);
|
|
|
|
_isWaitingCheck = true;
|
2016-07-28 17:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmPhoneBox::showError(const QString &error) {
|
|
|
|
_error = error;
|
|
|
|
if (!_error.isEmpty()) {
|
|
|
|
_code->showError();
|
|
|
|
}
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmPhoneBox::paintEvent(QPaintEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::paintEvent(e);
|
2016-07-28 17:01:08 +00:00
|
|
|
|
2022-09-16 20:23:27 +00:00
|
|
|
auto p = QPainter(this);
|
2016-07-28 17:01:08 +00:00
|
|
|
|
|
|
|
p.setFont(st::boxTextFont);
|
2021-10-18 19:49:42 +00:00
|
|
|
const auto callText = _call.getText();
|
2016-07-28 17:01:08 +00:00
|
|
|
if (!callText.isEmpty()) {
|
|
|
|
p.setPen(st::usernameDefaultFg);
|
2021-10-18 19:49:42 +00:00
|
|
|
const auto callTextRect = QRect(
|
|
|
|
st::usernamePadding.left(),
|
|
|
|
_about->y() + _about->height(),
|
|
|
|
width() - 2 * st::usernamePadding.left(),
|
|
|
|
st::usernameSkip);
|
2016-07-28 17:01:08 +00:00
|
|
|
p.drawText(callTextRect, callText, style::al_left);
|
|
|
|
}
|
|
|
|
auto errorText = _error;
|
|
|
|
if (errorText.isEmpty()) {
|
|
|
|
p.setPen(st::usernameDefaultFg);
|
2019-06-19 15:09:03 +00:00
|
|
|
errorText = tr::lng_confirm_phone_enter_code(tr::now);
|
2016-07-28 17:01:08 +00:00
|
|
|
} else {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::boxTextFgError);
|
2016-07-28 17:01:08 +00:00
|
|
|
}
|
2021-10-18 19:49:42 +00:00
|
|
|
const auto errorTextRect = QRect(
|
|
|
|
st::usernamePadding.left(),
|
|
|
|
_code->y() + _code->height(),
|
|
|
|
width() - 2 * st::usernamePadding.left(),
|
|
|
|
st::usernameSkip);
|
2016-07-28 17:01:08 +00:00
|
|
|
p.drawText(errorTextRect, errorText, style::al_left);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmPhoneBox::resizeEvent(QResizeEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::resizeEvent(e);
|
|
|
|
|
2021-10-18 19:49:42 +00:00
|
|
|
_code->resize(
|
|
|
|
width() - st::usernamePadding.left() - st::usernamePadding.right(),
|
|
|
|
_code->height());
|
2016-12-13 17:07:56 +00:00
|
|
|
_code->moveToLeft(st::usernamePadding.left(), st::usernamePadding.top());
|
2016-07-28 17:01:08 +00:00
|
|
|
|
2021-10-18 19:49:42 +00:00
|
|
|
_about->moveToLeft(
|
|
|
|
st::usernamePadding.left(),
|
|
|
|
_code->y() + _code->height() + st::usernameSkip);
|
2016-07-28 17:01:08 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void ConfirmPhoneBox::setInnerFocus() {
|
2016-12-20 13:03:51 +00:00
|
|
|
_code->setFocusFast();
|
2016-11-15 11:56:49 +00:00
|
|
|
}
|
2021-10-18 19:49:42 +00:00
|
|
|
|
|
|
|
rpl::producer<QString> ConfirmPhoneBox::checkRequests() const {
|
|
|
|
return _checkRequests.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> ConfirmPhoneBox::resendRequests() const {
|
|
|
|
return _resendRequests.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmPhoneBox::callDone() {
|
|
|
|
_call.callDone();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmPhoneBox::showServerError(const QString &text) {
|
|
|
|
_isWaitingCheck = false;
|
|
|
|
_code->setDisabled(false);
|
|
|
|
_code->setFocus();
|
|
|
|
showError(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ConfirmPhoneBox::getPhone() const {
|
|
|
|
return _phone;
|
|
|
|
}
|
2021-10-18 22:43:50 +00:00
|
|
|
|
|
|
|
} // namespace Ui
|