From 44f79b83312e2ad26de9fbcb5622f468c3c04866 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 28 Dec 2022 23:49:31 +0300 Subject: [PATCH] Added button for opening custom url to ChangePhone::EnterCode box. --- .../SourceFiles/boxes/change_phone_box.cpp | 48 +++++++++++++++---- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/Telegram/SourceFiles/boxes/change_phone_box.cpp b/Telegram/SourceFiles/boxes/change_phone_box.cpp index 5d044293bb..1a329b306f 100644 --- a/Telegram/SourceFiles/boxes/change_phone_box.cpp +++ b/Telegram/SourceFiles/boxes/change_phone_box.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "boxes/change_phone_box.h" +#include "core/file_utilities.h" #include "lang/lang_keys.h" #include "ui/widgets/labels.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 Settings { @@ -109,6 +114,7 @@ public: not_null controller, const QString &phone, const QString &hash, + const QString &openUrl, int codeLength, int callTimeout); @@ -128,18 +134,20 @@ private: void hideError() { showError(QString()); } - int countHeight(); + [[nodiscard]] int countHeight() const; const not_null _controller; MTP::Sender _api; QString _phone; QString _hash; + QString _openUrl; int _codeLength = 0; int _callTimeout = 0; object_ptr _code = { nullptr }; object_ptr> _error = { nullptr }; object_ptr _callLabel = { nullptr }; + object_ptr _fragment = { nullptr }; mtpRequestId _requestId = 0; Ui::SentCodeCall _call; @@ -174,11 +182,9 @@ void ChangePhone::EnterPhone::prepare() { this, tr::lng_change_phone_new_description(tr::now), st::changePhoneLabel); - const auto errorSkip = st::boxLittleSkip - + st::changePhoneError.style.font->height; description->moveToLeft( st::boxPadding.left(), - _phone->y() + _phone->height() + errorSkip + st::boxLittleSkip); + _phone->y() + _phone->height() + ErrorSkip() + st::boxLittleSkip); setDimensions( st::boxWidth, @@ -221,6 +227,7 @@ void ChangePhone::EnterPhone::sendPhoneDone( return false; }; auto codeLength = 0; + auto codeByFragmentUrl = QString(); const auto hasLength = data.vtype().match([&]( const MTPDauth_sentCodeTypeApp &typeData) { LOG(("Error: should not be in-app code!")); @@ -231,6 +238,7 @@ void ChangePhone::EnterPhone::sendPhoneDone( return true; }, [&](const MTPDauth_sentCodeTypeFragmentSms &typeData) { codeLength = typeData.vlength().v; + codeByFragmentUrl = qs(typeData.vurl()); return true; }, [&](const MTPDauth_sentCodeTypeCall &typeData) { codeLength = typeData.vlength().v; @@ -263,6 +271,7 @@ void ChangePhone::EnterPhone::sendPhoneDone( _controller, phoneNumber, phoneCodeHash, + codeByFragmentUrl, codeLength, callTimeout), Ui::LayerOption::KeepOther); @@ -307,18 +316,21 @@ ChangePhone::EnterCode::EnterCode( not_null controller, const QString &phone, const QString &hash, + const QString &openUrl, int codeLength, int callTimeout) : _controller(controller) , _api(&controller->session().mtp()) , _phone(phone) , _hash(hash) +, _openUrl(openUrl) , _codeLength(codeLength) , _callTimeout(callTimeout) , _call([this] { sendCall(); }, [this] { updateCall(); }) { } void ChangePhone::EnterCode::prepare() { + const auto width = st::boxWidth; setTitle(tr::lng_change_phone_title()); const auto descriptionText = tr::lng_change_phone_code_description( @@ -341,11 +353,26 @@ void ChangePhone::EnterCode::prepare() { _code->setAutoSubmit(_codeLength, [=] { submit(); }); _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()); 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) { _call.setStatus({ Ui::SentCodeCall::State::Waiting, _callTimeout }); @@ -356,10 +383,11 @@ void ChangePhone::EnterCode::prepare() { addButton(tr::lng_cancel(), [=] { closeBox(); }); } -int ChangePhone::EnterCode::countHeight() { - const auto errorSkip = st::boxLittleSkip - + st::changePhoneError.style.font->height; - return _code->bottomNoMargins() + errorSkip + 3 * st::boxLittleSkip; +int ChangePhone::EnterCode::countHeight() const { + return _code->bottomNoMargins() + + ErrorSkip() + + 3 * st::boxLittleSkip + + (_fragment ? _fragment->height() : 0); } void ChangePhone::EnterCode::submit() {