Added button for opening custom url to Ui::ConfirmPhoneBox.
This commit is contained in:
parent
44f79b8331
commit
613d4932ca
|
@ -58,6 +58,10 @@ void ConfirmPhone::resolve(
|
||||||
}, [&](const MTPDauth_sentCodeTypeSetUpEmailRequired &) {
|
}, [&](const MTPDauth_sentCodeTypeSetUpEmailRequired &) {
|
||||||
return bad("SetUpEmailRequired");
|
return bad("SetUpEmailRequired");
|
||||||
});
|
});
|
||||||
|
const auto fragmentUrl = data.vtype().match([](
|
||||||
|
const MTPDauth_sentCodeTypeFragmentSms &data) {
|
||||||
|
return qs(data.vurl());
|
||||||
|
}, [](const auto &) { return QString(); });
|
||||||
const auto phoneHash = qs(data.vphone_code_hash());
|
const auto phoneHash = qs(data.vphone_code_hash());
|
||||||
const auto timeout = [&]() -> std::optional<int> {
|
const auto timeout = [&]() -> std::optional<int> {
|
||||||
if (const auto nextType = data.vnext_type()) {
|
if (const auto nextType = data.vnext_type()) {
|
||||||
|
@ -70,6 +74,7 @@ void ConfirmPhone::resolve(
|
||||||
auto box = Box<Ui::ConfirmPhoneBox>(
|
auto box = Box<Ui::ConfirmPhoneBox>(
|
||||||
phone,
|
phone,
|
||||||
sentCodeLength,
|
sentCodeLength,
|
||||||
|
fragmentUrl,
|
||||||
timeout);
|
timeout);
|
||||||
const auto boxWeak = Ui::MakeWeak(box.data());
|
const auto boxWeak = Ui::MakeWeak(box.data());
|
||||||
box->resendRequests(
|
box->resendRequests(
|
||||||
|
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "ui/boxes/confirm_phone_box.h"
|
#include "ui/boxes/confirm_phone_box.h"
|
||||||
|
|
||||||
|
#include "core/file_utilities.h"
|
||||||
#include "ui/boxes/confirm_box.h"
|
#include "ui/boxes/confirm_box.h"
|
||||||
#include "ui/widgets/buttons.h"
|
#include "ui/widgets/buttons.h"
|
||||||
#include "ui/widgets/labels.h"
|
#include "ui/widgets/labels.h"
|
||||||
|
@ -22,10 +23,20 @@ ConfirmPhoneBox::ConfirmPhoneBox(
|
||||||
QWidget*,
|
QWidget*,
|
||||||
const QString &phone,
|
const QString &phone,
|
||||||
int codeLength,
|
int codeLength,
|
||||||
|
const QString &openUrl,
|
||||||
std::optional<int> timeout)
|
std::optional<int> timeout)
|
||||||
: _phone(phone)
|
: _phone(phone)
|
||||||
, _sentCodeLength(codeLength)
|
, _sentCodeLength(codeLength)
|
||||||
, _call([this] { sendCall(); }, [this] { update(); }) {
|
, _call([=] { sendCall(); }, [=] { update(); }) {
|
||||||
|
if (!openUrl.isEmpty()) {
|
||||||
|
_fragment.create(
|
||||||
|
this,
|
||||||
|
tr::lng_intro_fragment_button(),
|
||||||
|
st::fragmentBoxButton);
|
||||||
|
_fragment->setClickedCallback([=] { File::OpenUrl(openUrl); });
|
||||||
|
_fragment->setTextTransform(
|
||||||
|
Ui::RoundButton::TextTransform::NoTransform);
|
||||||
|
}
|
||||||
if (timeout) {
|
if (timeout) {
|
||||||
_call.setStatus({ Ui::SentCodeCall::State::Waiting, *timeout });
|
_call.setStatus({ Ui::SentCodeCall::State::Waiting, *timeout });
|
||||||
}
|
}
|
||||||
|
@ -59,7 +70,8 @@ void ConfirmPhoneBox::prepare() {
|
||||||
+ _code->height()
|
+ _code->height()
|
||||||
+ st::usernameSkip
|
+ st::usernameSkip
|
||||||
+ _about->height()
|
+ _about->height()
|
||||||
+ st::usernameSkip);
|
+ st::usernameSkip
|
||||||
|
+ (_fragment ? (_fragment->height() + fragmentSkip()) : 0));
|
||||||
|
|
||||||
connect(_code, &Ui::InputField::submitted, [=] { sendCode(); });
|
connect(_code, &Ui::InputField::submitted, [=] { sendCode(); });
|
||||||
|
|
||||||
|
@ -132,15 +144,27 @@ void ConfirmPhoneBox::resizeEvent(QResizeEvent *e) {
|
||||||
_code->height());
|
_code->height());
|
||||||
_code->moveToLeft(st::usernamePadding.left(), st::usernamePadding.top());
|
_code->moveToLeft(st::usernamePadding.left(), st::usernamePadding.top());
|
||||||
|
|
||||||
_about->moveToLeft(
|
if (_fragment) {
|
||||||
st::usernamePadding.left(),
|
_fragment->setFullWidth(_code->width());
|
||||||
_code->y() + _code->height() + st::usernameSkip);
|
_fragment->moveToLeft(
|
||||||
|
(width() - _fragment->width()) / 2,
|
||||||
|
_code->y() + _code->height() + st::usernameSkip);
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto aboutTop = _fragment
|
||||||
|
? (_fragment->y() + _fragment->height() + fragmentSkip())
|
||||||
|
: (_code->y() + _code->height() + st::usernameSkip);
|
||||||
|
_about->moveToLeft(st::usernamePadding.left(), aboutTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfirmPhoneBox::setInnerFocus() {
|
void ConfirmPhoneBox::setInnerFocus() {
|
||||||
_code->setFocusFast();
|
_code->setFocusFast();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ConfirmPhoneBox::fragmentSkip() const {
|
||||||
|
return st::usernamePadding.bottom();
|
||||||
|
}
|
||||||
|
|
||||||
rpl::producer<QString> ConfirmPhoneBox::checkRequests() const {
|
rpl::producer<QString> ConfirmPhoneBox::checkRequests() const {
|
||||||
return _checkRequests.events();
|
return _checkRequests.events();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
||||||
class FlatLabel;
|
class FlatLabel;
|
||||||
|
class RoundButton;
|
||||||
|
|
||||||
class ConfirmPhoneBox final : public Ui::BoxContent {
|
class ConfirmPhoneBox final : public Ui::BoxContent {
|
||||||
public:
|
public:
|
||||||
|
@ -20,6 +21,7 @@ public:
|
||||||
QWidget*,
|
QWidget*,
|
||||||
const QString &phone,
|
const QString &phone,
|
||||||
int codeLength,
|
int codeLength,
|
||||||
|
const QString &openUrl,
|
||||||
std::optional<int> timeout);
|
std::optional<int> timeout);
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<QString> checkRequests() const;
|
[[nodiscard]] rpl::producer<QString> checkRequests() const;
|
||||||
|
@ -40,6 +42,8 @@ private:
|
||||||
void sendCall();
|
void sendCall();
|
||||||
void checkPhoneAndHash();
|
void checkPhoneAndHash();
|
||||||
|
|
||||||
|
[[nodiscard]] int fragmentSkip() const;
|
||||||
|
|
||||||
QString getPhone() const;
|
QString getPhone() const;
|
||||||
void showError(const QString &error);
|
void showError(const QString &error);
|
||||||
|
|
||||||
|
@ -54,6 +58,7 @@ private:
|
||||||
|
|
||||||
object_ptr<Ui::FlatLabel> _about = { nullptr };
|
object_ptr<Ui::FlatLabel> _about = { nullptr };
|
||||||
object_ptr<Ui::SentCodeField> _code = { nullptr };
|
object_ptr<Ui::SentCodeField> _code = { nullptr };
|
||||||
|
object_ptr<Ui::RoundButton> _fragment = { nullptr };
|
||||||
|
|
||||||
QString _error;
|
QString _error;
|
||||||
Ui::SentCodeCall _call;
|
Ui::SentCodeCall _call;
|
||||||
|
|
Loading…
Reference in New Issue