Added button for opening custom url to ChangePhone::EnterCode box.
This commit is contained in:
parent
aa1117a714
commit
44f79b8331
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "boxes/change_phone_box.h"
|
#include "boxes/change_phone_box.h"
|
||||||
|
|
||||||
|
#include "core/file_utilities.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "ui/widgets/labels.h"
|
#include "ui/widgets/labels.h"
|
||||||
#include "ui/widgets/sent_code_field.h"
|
#include "ui/widgets/sent_code_field.h"
|
||||||
|
@ -67,6 +68,10 @@ void CreateErrorLabel(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] int ErrorSkip() {
|
||||||
|
return st::boxLittleSkip + st::changePhoneError.style.font->height;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace Settings {
|
namespace Settings {
|
||||||
|
@ -109,6 +114,7 @@ public:
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
const QString &phone,
|
const QString &phone,
|
||||||
const QString &hash,
|
const QString &hash,
|
||||||
|
const QString &openUrl,
|
||||||
int codeLength,
|
int codeLength,
|
||||||
int callTimeout);
|
int callTimeout);
|
||||||
|
|
||||||
|
@ -128,18 +134,20 @@ private:
|
||||||
void hideError() {
|
void hideError() {
|
||||||
showError(QString());
|
showError(QString());
|
||||||
}
|
}
|
||||||
int countHeight();
|
[[nodiscard]] int countHeight() const;
|
||||||
|
|
||||||
const not_null<Window::SessionController*> _controller;
|
const not_null<Window::SessionController*> _controller;
|
||||||
MTP::Sender _api;
|
MTP::Sender _api;
|
||||||
|
|
||||||
QString _phone;
|
QString _phone;
|
||||||
QString _hash;
|
QString _hash;
|
||||||
|
QString _openUrl;
|
||||||
int _codeLength = 0;
|
int _codeLength = 0;
|
||||||
int _callTimeout = 0;
|
int _callTimeout = 0;
|
||||||
object_ptr<Ui::SentCodeField> _code = { nullptr };
|
object_ptr<Ui::SentCodeField> _code = { nullptr };
|
||||||
object_ptr<Ui::FadeWrap<Ui::FlatLabel>> _error = { nullptr };
|
object_ptr<Ui::FadeWrap<Ui::FlatLabel>> _error = { nullptr };
|
||||||
object_ptr<Ui::FlatLabel> _callLabel = { nullptr };
|
object_ptr<Ui::FlatLabel> _callLabel = { nullptr };
|
||||||
|
object_ptr<Ui::RoundButton> _fragment = { nullptr };
|
||||||
mtpRequestId _requestId = 0;
|
mtpRequestId _requestId = 0;
|
||||||
Ui::SentCodeCall _call;
|
Ui::SentCodeCall _call;
|
||||||
|
|
||||||
|
@ -174,11 +182,9 @@ void ChangePhone::EnterPhone::prepare() {
|
||||||
this,
|
this,
|
||||||
tr::lng_change_phone_new_description(tr::now),
|
tr::lng_change_phone_new_description(tr::now),
|
||||||
st::changePhoneLabel);
|
st::changePhoneLabel);
|
||||||
const auto errorSkip = st::boxLittleSkip
|
|
||||||
+ st::changePhoneError.style.font->height;
|
|
||||||
description->moveToLeft(
|
description->moveToLeft(
|
||||||
st::boxPadding.left(),
|
st::boxPadding.left(),
|
||||||
_phone->y() + _phone->height() + errorSkip + st::boxLittleSkip);
|
_phone->y() + _phone->height() + ErrorSkip() + st::boxLittleSkip);
|
||||||
|
|
||||||
setDimensions(
|
setDimensions(
|
||||||
st::boxWidth,
|
st::boxWidth,
|
||||||
|
@ -221,6 +227,7 @@ void ChangePhone::EnterPhone::sendPhoneDone(
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
auto codeLength = 0;
|
auto codeLength = 0;
|
||||||
|
auto codeByFragmentUrl = QString();
|
||||||
const auto hasLength = data.vtype().match([&](
|
const auto hasLength = data.vtype().match([&](
|
||||||
const MTPDauth_sentCodeTypeApp &typeData) {
|
const MTPDauth_sentCodeTypeApp &typeData) {
|
||||||
LOG(("Error: should not be in-app code!"));
|
LOG(("Error: should not be in-app code!"));
|
||||||
|
@ -231,6 +238,7 @@ void ChangePhone::EnterPhone::sendPhoneDone(
|
||||||
return true;
|
return true;
|
||||||
}, [&](const MTPDauth_sentCodeTypeFragmentSms &typeData) {
|
}, [&](const MTPDauth_sentCodeTypeFragmentSms &typeData) {
|
||||||
codeLength = typeData.vlength().v;
|
codeLength = typeData.vlength().v;
|
||||||
|
codeByFragmentUrl = qs(typeData.vurl());
|
||||||
return true;
|
return true;
|
||||||
}, [&](const MTPDauth_sentCodeTypeCall &typeData) {
|
}, [&](const MTPDauth_sentCodeTypeCall &typeData) {
|
||||||
codeLength = typeData.vlength().v;
|
codeLength = typeData.vlength().v;
|
||||||
|
@ -263,6 +271,7 @@ void ChangePhone::EnterPhone::sendPhoneDone(
|
||||||
_controller,
|
_controller,
|
||||||
phoneNumber,
|
phoneNumber,
|
||||||
phoneCodeHash,
|
phoneCodeHash,
|
||||||
|
codeByFragmentUrl,
|
||||||
codeLength,
|
codeLength,
|
||||||
callTimeout),
|
callTimeout),
|
||||||
Ui::LayerOption::KeepOther);
|
Ui::LayerOption::KeepOther);
|
||||||
|
@ -307,18 +316,21 @@ ChangePhone::EnterCode::EnterCode(
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
const QString &phone,
|
const QString &phone,
|
||||||
const QString &hash,
|
const QString &hash,
|
||||||
|
const QString &openUrl,
|
||||||
int codeLength,
|
int codeLength,
|
||||||
int callTimeout)
|
int callTimeout)
|
||||||
: _controller(controller)
|
: _controller(controller)
|
||||||
, _api(&controller->session().mtp())
|
, _api(&controller->session().mtp())
|
||||||
, _phone(phone)
|
, _phone(phone)
|
||||||
, _hash(hash)
|
, _hash(hash)
|
||||||
|
, _openUrl(openUrl)
|
||||||
, _codeLength(codeLength)
|
, _codeLength(codeLength)
|
||||||
, _callTimeout(callTimeout)
|
, _callTimeout(callTimeout)
|
||||||
, _call([this] { sendCall(); }, [this] { updateCall(); }) {
|
, _call([this] { sendCall(); }, [this] { updateCall(); }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChangePhone::EnterCode::prepare() {
|
void ChangePhone::EnterCode::prepare() {
|
||||||
|
const auto width = st::boxWidth;
|
||||||
setTitle(tr::lng_change_phone_title());
|
setTitle(tr::lng_change_phone_title());
|
||||||
|
|
||||||
const auto descriptionText = tr::lng_change_phone_code_description(
|
const auto descriptionText = tr::lng_change_phone_code_description(
|
||||||
|
@ -341,11 +353,26 @@ void ChangePhone::EnterCode::prepare() {
|
||||||
_code->setAutoSubmit(_codeLength, [=] { submit(); });
|
_code->setAutoSubmit(_codeLength, [=] { submit(); });
|
||||||
_code->setChangedCallback([=] { hideError(); });
|
_code->setChangedCallback([=] { hideError(); });
|
||||||
|
|
||||||
_code->resize(st::boxWidth - 2 * st::boxPadding.left(), _code->height());
|
_code->resize(width - 2 * st::boxPadding.left(), _code->height());
|
||||||
_code->moveToLeft(st::boxPadding.left(), description->bottomNoMargins());
|
_code->moveToLeft(st::boxPadding.left(), description->bottomNoMargins());
|
||||||
connect(_code, &Ui::InputField::submitted, [=] { submit(); });
|
connect(_code, &Ui::InputField::submitted, [=] { submit(); });
|
||||||
|
|
||||||
setDimensions(st::boxWidth, countHeight());
|
if (!_openUrl.isEmpty()) {
|
||||||
|
_fragment.create(
|
||||||
|
this,
|
||||||
|
tr::lng_intro_fragment_button(),
|
||||||
|
st::fragmentBoxButton);
|
||||||
|
_fragment->setClickedCallback([=] { File::OpenUrl(_openUrl); });
|
||||||
|
_fragment->setTextTransform(
|
||||||
|
Ui::RoundButton::TextTransform::NoTransform);
|
||||||
|
const auto codeBottom = _code->y() + _code->height();
|
||||||
|
_fragment->setFullWidth(_code->width());
|
||||||
|
_fragment->moveToLeft(
|
||||||
|
(width - _fragment->width()) / 2,
|
||||||
|
codeBottom + ErrorSkip() + st::boxLittleSkip);
|
||||||
|
}
|
||||||
|
|
||||||
|
setDimensions(width, countHeight());
|
||||||
|
|
||||||
if (_callTimeout > 0) {
|
if (_callTimeout > 0) {
|
||||||
_call.setStatus({ Ui::SentCodeCall::State::Waiting, _callTimeout });
|
_call.setStatus({ Ui::SentCodeCall::State::Waiting, _callTimeout });
|
||||||
|
@ -356,10 +383,11 @@ void ChangePhone::EnterCode::prepare() {
|
||||||
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
int ChangePhone::EnterCode::countHeight() {
|
int ChangePhone::EnterCode::countHeight() const {
|
||||||
const auto errorSkip = st::boxLittleSkip
|
return _code->bottomNoMargins()
|
||||||
+ st::changePhoneError.style.font->height;
|
+ ErrorSkip()
|
||||||
return _code->bottomNoMargins() + errorSkip + 3 * st::boxLittleSkip;
|
+ 3 * st::boxLittleSkip
|
||||||
|
+ (_fragment ? _fragment->height() : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChangePhone::EnterCode::submit() {
|
void ChangePhone::EnterCode::submit() {
|
||||||
|
|
Loading…
Reference in New Issue