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
|
|
|
*/
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/confirm_phone_box.h"
|
2016-07-28 17:01:08 +00:00
|
|
|
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-15 11:56:49 +00:00
|
|
|
#include "ui/widgets/input_fields.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"
|
2019-06-05 17:43:21 +00:00
|
|
|
#include "core/click_handler_types.h" // UrlClickHandler
|
|
|
|
#include "base/qthelp_url.h" // qthelp::url_encode
|
2019-09-17 16:13:12 +00:00
|
|
|
#include "base/platform/base_platform_info.h"
|
2020-06-11 16:09:46 +00:00
|
|
|
#include "main/main_session.h"
|
2016-07-28 17:01:08 +00:00
|
|
|
#include "mainwidget.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2019-11-13 08:31:12 +00:00
|
|
|
#include "mtproto/facade.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
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<ConfirmPhoneBox> CurrentConfirmPhoneBox = { nullptr };
|
2016-07-28 17:01:08 +00:00
|
|
|
|
2019-06-05 17:43:21 +00:00
|
|
|
void SendToBannedHelp(const QString &phone) {
|
|
|
|
const auto version = QString::fromLatin1(AppVersionStr)
|
|
|
|
+ (cAlphaVersion()
|
|
|
|
? qsl(" alpha %1").arg(cAlphaVersion())
|
|
|
|
: (AppBetaVersion ? " beta" : ""));
|
|
|
|
|
|
|
|
const auto subject = qsl("Banned phone number: ") + phone;
|
|
|
|
|
|
|
|
const auto body = qsl("\
|
|
|
|
I'm trying to use my mobile phone number: ") + phone + qsl("\n\
|
|
|
|
But Telegram says it's banned. Please help.\n\
|
|
|
|
\n\
|
|
|
|
App version: ") + version + qsl("\n\
|
|
|
|
OS version: ") + Platform::SystemVersionPretty() + qsl("\n\
|
|
|
|
Locale: ") + Platform::SystemLanguage();
|
|
|
|
|
|
|
|
const auto url = "mailto:?to="
|
|
|
|
+ qthelp::url_encode("login@stel.com")
|
|
|
|
+ "&subject="
|
|
|
|
+ qthelp::url_encode(subject)
|
|
|
|
+ "&body="
|
|
|
|
+ qthelp::url_encode(body);
|
|
|
|
|
|
|
|
UrlClickHandler::Open(url);
|
|
|
|
}
|
|
|
|
|
2016-07-28 17:01:08 +00:00
|
|
|
} // namespace
|
|
|
|
|
2019-06-05 17:43:21 +00:00
|
|
|
void ShowPhoneBannedError(const QString &phone) {
|
2019-09-18 11:19:05 +00:00
|
|
|
const auto box = std::make_shared<QPointer<Ui::BoxContent>>();
|
2019-06-05 17:43:21 +00:00
|
|
|
const auto close = [=] {
|
|
|
|
if (*box) {
|
|
|
|
(*box)->closeBox();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
*box = Ui::show(Box<ConfirmBox>(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_signin_banned_text(tr::now),
|
|
|
|
tr::lng_box_ok(tr::now),
|
|
|
|
tr::lng_signin_banned_help(tr::now),
|
2019-06-05 17:43:21 +00:00
|
|
|
close,
|
|
|
|
[=] { SendToBannedHelp(phone); close(); }));
|
2019-08-06 16:40:08 +00:00
|
|
|
}
|
2019-06-05 17:43:21 +00:00
|
|
|
|
2018-11-19 12:15:59 +00:00
|
|
|
SentCodeField::SentCodeField(
|
|
|
|
QWidget *parent,
|
|
|
|
const style::InputField &st,
|
2019-06-18 14:07:45 +00:00
|
|
|
rpl::producer<QString> placeholder,
|
2018-11-19 12:15:59 +00:00
|
|
|
const QString &val)
|
2019-06-18 14:07:45 +00:00
|
|
|
: Ui::InputField(parent, st, std::move(placeholder), val) {
|
2018-11-19 12:15:59 +00:00
|
|
|
connect(this, &Ui::InputField::changed, [this] { fix(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void SentCodeField::setAutoSubmit(int length, Fn<void()> submitCallback) {
|
|
|
|
_autoSubmitLength = length;
|
|
|
|
_submitCallback = std::move(submitCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SentCodeField::setChangedCallback(Fn<void()> changedCallback) {
|
|
|
|
_changedCallback = std::move(changedCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString SentCodeField::getDigitsOnly() const {
|
|
|
|
return QString(
|
|
|
|
getLastText()
|
|
|
|
).remove(
|
|
|
|
QRegularExpression("[^\\d]")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-03-21 11:42:04 +00:00
|
|
|
void SentCodeField::fix() {
|
|
|
|
if (_fixing) return;
|
|
|
|
|
|
|
|
_fixing = true;
|
|
|
|
auto newText = QString();
|
2018-11-19 12:15:59 +00:00
|
|
|
const auto now = getLastText();
|
2017-03-21 11:42:04 +00:00
|
|
|
auto oldPos = textCursor().position();
|
|
|
|
auto newPos = -1;
|
|
|
|
auto oldLen = now.size();
|
|
|
|
auto digitCount = 0;
|
2021-09-08 10:53:54 +00:00
|
|
|
for (const auto &ch : now) {
|
2017-03-21 11:42:04 +00:00
|
|
|
if (ch.isDigit()) {
|
|
|
|
++digitCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_autoSubmitLength > 0 && digitCount > _autoSubmitLength) {
|
|
|
|
digitCount = _autoSubmitLength;
|
|
|
|
}
|
2018-11-19 12:15:59 +00:00
|
|
|
auto strict = (_autoSubmitLength > 0)
|
|
|
|
&& (digitCount == _autoSubmitLength);
|
2017-03-21 11:42:04 +00:00
|
|
|
|
|
|
|
newText.reserve(oldLen);
|
|
|
|
int i = 0;
|
2021-09-08 10:53:54 +00:00
|
|
|
for (const auto &ch : now) {
|
2017-03-21 11:42:04 +00:00
|
|
|
if (i++ == oldPos) {
|
|
|
|
newPos = newText.length();
|
|
|
|
}
|
|
|
|
if (ch.isDigit()) {
|
|
|
|
if (!digitCount--) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
newText += ch;
|
|
|
|
if (strict && !digitCount) {
|
|
|
|
break;
|
|
|
|
}
|
2018-11-19 12:15:59 +00:00
|
|
|
} else if (ch == '-') {
|
|
|
|
newText += ch;
|
2017-03-21 11:42:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (newPos < 0) {
|
|
|
|
newPos = newText.length();
|
|
|
|
}
|
|
|
|
if (newText != now) {
|
2018-11-19 12:15:59 +00:00
|
|
|
setText(newText);
|
2017-03-21 11:42:04 +00:00
|
|
|
setCursorPosition(newPos);
|
|
|
|
}
|
|
|
|
_fixing = false;
|
|
|
|
|
|
|
|
if (_changedCallback) {
|
|
|
|
_changedCallback();
|
|
|
|
}
|
|
|
|
if (strict && _submitCallback) {
|
|
|
|
_submitCallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-19 12:15:59 +00:00
|
|
|
SentCodeCall::SentCodeCall(
|
|
|
|
FnMut<void()> callCallback,
|
|
|
|
Fn<void()> updateCallback)
|
2018-04-09 17:56:07 +00:00
|
|
|
: _call(std::move(callCallback))
|
2017-03-21 11:42:04 +00:00
|
|
|
, _update(std::move(updateCallback)) {
|
2018-04-09 17:56:07 +00:00
|
|
|
_timer.setCallback([=] {
|
2017-03-21 11:42:04 +00:00
|
|
|
if (_status.state == State::Waiting) {
|
|
|
|
if (--_status.timeout <= 0) {
|
|
|
|
_status.state = State::Calling;
|
2018-04-09 17:56:07 +00:00
|
|
|
_timer.cancel();
|
2017-03-21 11:42:04 +00:00
|
|
|
if (_call) {
|
|
|
|
_call();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_update) {
|
|
|
|
_update();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void SentCodeCall::setStatus(const Status &status) {
|
|
|
|
_status = status;
|
|
|
|
if (_status.state == State::Waiting) {
|
2018-04-09 17:56:07 +00:00
|
|
|
_timer.callEach(1000);
|
2017-03-21 11:42:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString SentCodeCall::getText() const {
|
|
|
|
switch (_status.state) {
|
|
|
|
case State::Waiting: {
|
|
|
|
if (_status.timeout >= 3600) {
|
2019-06-19 16:39:25 +00:00
|
|
|
return tr::lng_code_call(tr::now, lt_minutes, qsl("%1:%2").arg(_status.timeout / 3600).arg((_status.timeout / 60) % 60, 2, 10, QChar('0')), lt_seconds, qsl("%1").arg(_status.timeout % 60, 2, 10, QChar('0')));
|
2017-03-21 11:42:04 +00:00
|
|
|
}
|
2019-06-19 16:39:25 +00:00
|
|
|
return tr::lng_code_call(tr::now, lt_minutes, QString::number(_status.timeout / 60), lt_seconds, qsl("%1").arg(_status.timeout % 60, 2, 10, QChar('0')));
|
2017-03-21 11:42:04 +00:00
|
|
|
} break;
|
2019-06-19 15:09:03 +00:00
|
|
|
case State::Calling: return tr::lng_code_calling(tr::now);
|
|
|
|
case State::Called: return tr::lng_code_called(tr::now);
|
2017-03-21 11:42:04 +00:00
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2020-06-11 16:09:46 +00:00
|
|
|
void ConfirmPhoneBox::Start(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const QString &phone,
|
|
|
|
const QString &hash) {
|
|
|
|
if (CurrentConfirmPhoneBox
|
|
|
|
&& (CurrentConfirmPhoneBox->getPhone() != phone
|
|
|
|
|| &CurrentConfirmPhoneBox->session() != session)) {
|
2016-12-13 17:07:56 +00:00
|
|
|
CurrentConfirmPhoneBox.destroyDelayed();
|
2016-07-28 17:01:08 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
if (!CurrentConfirmPhoneBox) {
|
2020-06-11 16:09:46 +00:00
|
|
|
CurrentConfirmPhoneBox = Box<ConfirmPhoneBox>(session, phone, hash);
|
2016-07-28 17:01:08 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
CurrentConfirmPhoneBox->checkPhoneAndHash();
|
2016-07-28 17:01:08 +00:00
|
|
|
}
|
|
|
|
|
2020-06-11 16:09:46 +00:00
|
|
|
ConfirmPhoneBox::ConfirmPhoneBox(
|
|
|
|
QWidget*,
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const QString &phone,
|
|
|
|
const QString &hash)
|
|
|
|
: _session(session)
|
2020-06-17 09:36:25 +00:00
|
|
|
, _api(&session->mtp())
|
2020-06-11 16:09:46 +00:00
|
|
|
, _phone(phone)
|
2016-12-13 17:07:56 +00:00
|
|
|
, _hash(hash)
|
2018-04-09 17:56:07 +00:00
|
|
|
, _call([this] { sendCall(); }, [this] { update(); }) {
|
2017-03-21 11:42:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmPhoneBox::sendCall() {
|
2020-06-11 16:09:46 +00:00
|
|
|
_api.request(MTPauth_ResendCode(
|
|
|
|
MTP_string(_phone),
|
|
|
|
MTP_string(_phoneHash)
|
|
|
|
)).done([=](const MTPauth_SentCode &result) {
|
|
|
|
callDone(result);
|
|
|
|
}).send();
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmPhoneBox::checkPhoneAndHash() {
|
|
|
|
if (_sendCodeRequestId) {
|
|
|
|
return;
|
|
|
|
}
|
2020-06-11 16:09:46 +00:00
|
|
|
_sendCodeRequestId = _api.request(MTPaccount_SendConfirmPhoneCode(
|
|
|
|
MTP_string(_hash),
|
|
|
|
MTP_codeSettings(MTP_flags(0))
|
|
|
|
)).done([=](const MTPauth_SentCode &result) {
|
|
|
|
sendCodeDone(result);
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2020-06-11 16:09:46 +00:00
|
|
|
sendCodeFail(error);
|
|
|
|
}).handleFloodErrors().send();
|
2016-07-28 17:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmPhoneBox::sendCodeDone(const MTPauth_SentCode &result) {
|
2019-07-05 13:38:38 +00:00
|
|
|
result.match([&](const MTPDauth_sentCode &data) {
|
|
|
|
_sendCodeRequestId = 0;
|
|
|
|
_sentCodeLength = data.vtype().match([&](const MTPDauth_sentCodeTypeApp &data) {
|
|
|
|
LOG(("Error: should not be in-app code!"));
|
|
|
|
return 0;
|
|
|
|
}, [&](const MTPDauth_sentCodeTypeSms &data) {
|
|
|
|
return data.vlength().v;
|
|
|
|
}, [&](const MTPDauth_sentCodeTypeCall &data) {
|
|
|
|
return data.vlength().v;
|
|
|
|
}, [&](const MTPDauth_sentCodeTypeFlashCall &data) {
|
|
|
|
LOG(("Error: should not be flashcall!"));
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
_phoneHash = qs(data.vphone_code_hash());
|
|
|
|
if (const auto nextType = data.vnext_type()) {
|
|
|
|
if (nextType->type() == mtpc_auth_codeTypeCall) {
|
|
|
|
_call.setStatus({ SentCodeCall::State::Waiting, data.vtimeout().value_or(60) });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
launch();
|
|
|
|
});
|
2016-07-28 17:01:08 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
void ConfirmPhoneBox::sendCodeFail(const MTP::Error &error) {
|
2017-09-28 20:11:10 +00:00
|
|
|
auto errorText = Lang::Hard::ServerError();
|
2021-03-12 12:48:00 +00:00
|
|
|
if (MTP::IsFloodError(error)) {
|
2019-06-19 15:09:03 +00:00
|
|
|
errorText = tr::lng_flood_error(tr::now);
|
2016-07-28 17:01:08 +00:00
|
|
|
} else if (error.code() == 400) {
|
2019-06-19 15:09:03 +00:00
|
|
|
errorText = tr::lng_confirm_phone_link_invalid(tr::now);
|
2016-07-28 17:01:08 +00:00
|
|
|
}
|
|
|
|
_sendCodeRequestId = 0;
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<InformBox>(errorText));
|
|
|
|
if (this == CurrentConfirmPhoneBox) {
|
|
|
|
CurrentConfirmPhoneBox.destroyDelayed();
|
|
|
|
} else {
|
|
|
|
deleteLater();
|
|
|
|
}
|
2016-07-28 17:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmPhoneBox::launch() {
|
2016-12-13 17:07:56 +00:00
|
|
|
if (!CurrentConfirmPhoneBox) return;
|
2017-02-21 13:45:56 +00:00
|
|
|
Ui::show(std::move(CurrentConfirmPhoneBox));
|
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
|
|
|
|
2016-12-13 17:07:56 +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
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmPhoneBox::callDone(const MTPauth_SentCode &result) {
|
2017-03-21 11:42:04 +00:00
|
|
|
_call.callDone();
|
2016-07-28 17:01:08 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
void ConfirmPhoneBox::sendCode() {
|
2016-07-28 17:01:08 +00:00
|
|
|
if (_sendCodeRequestId) {
|
|
|
|
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());
|
|
|
|
|
2020-06-11 16:09:46 +00:00
|
|
|
_sendCodeRequestId = _api.request(MTPaccount_ConfirmPhone(
|
|
|
|
MTP_string(_phoneHash),
|
|
|
|
MTP_string(code)
|
|
|
|
)).done([=](const MTPBool &result) {
|
|
|
|
confirmDone(result);
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2020-06-11 16:09:46 +00:00
|
|
|
confirmFail(error);
|
|
|
|
}).handleFloodErrors().send();
|
2016-07-28 17:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmPhoneBox::confirmDone(const MTPBool &result) {
|
|
|
|
_sendCodeRequestId = 0;
|
2021-07-26 06:32:16 +00:00
|
|
|
Ui::show(Box<InformBox>(tr::lng_confirm_phone_success(tr::now, lt_phone, Ui::FormatPhone(_phone))));
|
2016-07-28 17:01:08 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
void ConfirmPhoneBox::confirmFail(const MTP::Error &error) {
|
2017-09-28 20:11:10 +00:00
|
|
|
auto errorText = Lang::Hard::ServerError();
|
2021-03-12 12:48:00 +00:00
|
|
|
if (MTP::IsFloodError(error)) {
|
2019-06-19 15:09:03 +00:00
|
|
|
errorText = tr::lng_flood_error(tr::now);
|
2016-07-28 17:01:08 +00:00
|
|
|
} else {
|
|
|
|
auto &errorType = error.type();
|
|
|
|
if (errorType == qstr("PHONE_CODE_EMPTY") || errorType == qstr("PHONE_CODE_INVALID")) {
|
2019-06-19 15:09:03 +00:00
|
|
|
errorText = tr::lng_bad_code(tr::now);
|
2016-07-28 17:01:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_sendCodeRequestId = 0;
|
|
|
|
_code->setDisabled(false);
|
|
|
|
_code->setFocus();
|
|
|
|
showError(errorText);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-11-19 14:47:28 +00:00
|
|
|
Painter p(this);
|
2016-07-28 17:01:08 +00:00
|
|
|
|
|
|
|
p.setFont(st::boxTextFont);
|
2017-03-21 11:42:04 +00:00
|
|
|
auto callText = _call.getText();
|
2016-07-28 17:01:08 +00:00
|
|
|
if (!callText.isEmpty()) {
|
|
|
|
p.setPen(st::usernameDefaultFg);
|
|
|
|
auto callTextRectLeft = st::usernamePadding.left();
|
|
|
|
auto callTextRectTop = _about->y() + _about->height();
|
|
|
|
auto callTextRectWidth = width() - 2 * st::usernamePadding.left();
|
|
|
|
auto callTextRect = QRect(callTextRectLeft, callTextRectTop, callTextRectWidth, st::usernameSkip);
|
|
|
|
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
|
|
|
}
|
|
|
|
auto errorTextRectLeft = st::usernamePadding.left();
|
|
|
|
auto errorTextRectTop = _code->y() + _code->height();
|
|
|
|
auto errorTextRectWidth = width() - 2 * st::usernamePadding.left();
|
|
|
|
auto errorTextRect = QRect(errorTextRectLeft, errorTextRectTop, errorTextRectWidth, st::usernameSkip);
|
|
|
|
p.drawText(errorTextRect, errorText, style::al_left);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmPhoneBox::resizeEvent(QResizeEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::resizeEvent(e);
|
|
|
|
|
2016-07-28 17:01:08 +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
|
|
|
|
|
|
|
_about->moveToLeft(st::usernamePadding.left(), _code->y() + _code->height() + st::usernameSkip);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|