Remove Q_OBJECTs from Intro.

This commit is contained in:
John Preston 2019-11-27 11:33:18 +03:00
parent e943264823
commit 55f83129b7
9 changed files with 81 additions and 148 deletions

View file

@ -22,7 +22,7 @@ class FlatLabel;
namespace Intro {
namespace details {
class QrWidget : public Step {
class QrWidget final : public Step {
public:
QrWidget(
QWidget *parent,

View file

@ -82,17 +82,15 @@ CodeWidget::CodeWidget(
: Step(parent, account, data)
, _noTelegramCode(this, tr::lng_code_no_telegram(tr::now), st::introLink)
, _code(this, st::introCode, tr::lng_code_ph())
, _callTimer(this)
, _callTimer([=] { sendCall(); })
, _callStatus(getData()->callStatus)
, _callTimeout(getData()->callTimeout)
, _callLabel(this, st::introDescription)
, _checkRequest(this) {
, _checkRequestTimer([=] { checkRequest(); }) {
subscribe(Lang::Current().updated(), [this] { refreshLang(); });
connect(_code, SIGNAL(changed()), this, SLOT(onInputChange()));
connect(_callTimer, SIGNAL(timeout()), this, SLOT(onSendCall()));
connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest()));
_noTelegramCode->addClickHandler([=] { onNoTelegramCode(); });
connect(_code, &CodeInput::changed, [=] { codeChanged(); });
_noTelegramCode->addClickHandler([=] { noTelegramCode(); });
_code->setDigitsCountMax(getData()->codeLength);
@ -101,7 +99,9 @@ CodeWidget::CodeWidget(
}
void CodeWidget::refreshLang() {
if (_noTelegramCode) _noTelegramCode->setText(tr::lng_code_no_telegram(tr::now));
if (_noTelegramCode) {
_noTelegramCode->setText(tr::lng_code_no_telegram(tr::now));
}
updateDescText();
updateControlsGeometry();
}
@ -117,13 +117,13 @@ void CodeWidget::updateDescText() {
Ui::Text::RichLangValue));
if (getData()->codeByTelegram) {
_noTelegramCode->show();
_callTimer->stop();
_callTimer.cancel();
} else {
_noTelegramCode->hide();
_callStatus = getData()->callStatus;
_callTimeout = getData()->callTimeout;
if (_callStatus == CallStatus::Waiting && !_callTimer->isActive()) {
_callTimer->start(1000);
if (_callStatus == CallStatus::Waiting && !_callTimer.isActive()) {
_callTimer.callEach(1000);
}
}
updateCallText();
@ -199,8 +199,8 @@ void CodeWidget::activate() {
void CodeWidget::finished() {
Step::finished();
_checkRequest->stop();
_callTimer->stop();
_checkRequestTimer.cancel();
_callTimer.cancel();
rpcInvalidate();
cancelled();
@ -215,10 +215,10 @@ void CodeWidget::cancelled() {
}
void CodeWidget::stopCheck() {
_checkRequest->stop();
_checkRequestTimer.cancel();
}
void CodeWidget::onCheckRequest() {
void CodeWidget::checkRequest() {
auto status = MTP::state(_sentRequest);
if (status < 0) {
auto leftms = -status;
@ -278,7 +278,7 @@ bool CodeWidget::codeSubmitFail(const RPCError &error) {
showCodeError(tr::lng_bad_code());
return true;
} else if (err == qstr("SESSION_PASSWORD_NEEDED")) {
_checkRequest->start(1000);
_checkRequestTimer.callEach(1000);
_sentRequest = MTP::send(
MTPaccount_GetPassword(),
rpcDone(&CodeWidget::gotPassword),
@ -293,17 +293,21 @@ bool CodeWidget::codeSubmitFail(const RPCError &error) {
return false;
}
void CodeWidget::onInputChange() {
void CodeWidget::codeChanged() {
hideError();
submit();
}
void CodeWidget::onSendCall() {
void CodeWidget::sendCall() {
if (_callStatus == CallStatus::Waiting) {
if (--_callTimeout <= 0) {
_callStatus = CallStatus::Calling;
_callTimer->stop();
_callRequestId = MTP::send(MTPauth_ResendCode(MTP_string(getData()->phone), MTP_bytes(getData()->phoneHash)), rpcDone(&CodeWidget::callDone));
_callTimer.cancel();
_callRequestId = MTP::send(
MTPauth_ResendCode(
MTP_string(getData()->phone),
MTP_bytes(getData()->phoneHash)),
rpcDone(&CodeWidget::callDone));
} else {
getData()->callStatus = _callStatus;
getData()->callTimeout = _callTimeout;
@ -369,7 +373,7 @@ void CodeWidget::submit() {
hideError();
_checkRequest->start(1000);
_checkRequestTimer.callEach(1000);
_sentCode = text;
getData()->pwdRequest = Core::CloudPasswordCheckRequest();
@ -385,7 +389,7 @@ void CodeWidget::submit() {
rpcFail(&CodeWidget::codeSubmitFail));
}
void CodeWidget::onNoTelegramCode() {
void CodeWidget::noTelegramCode() {
if (_noTelegramCodeRequestId) {
return;
}

View file

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "intro/intro_step.h"
#include "ui/widgets/input_fields.h"
#include "intro/introwidget.h"
#include "base/timer.h"
namespace Ui {
class RoundButton;
@ -39,9 +40,7 @@ private:
};
class CodeWidget : public Step {
Q_OBJECT
class CodeWidget final : public Step {
public:
CodeWidget(
QWidget *parent,
@ -62,13 +61,12 @@ public:
protected:
void resizeEvent(QResizeEvent *e) override;
private slots:
void onNoTelegramCode();
void onInputChange();
void onSendCall();
void onCheckRequest();
private:
void noTelegramCode();
void codeChanged();
void sendCall();
void checkRequest();
int errorTop() const override;
void updateCallText();
@ -94,13 +92,13 @@ private:
QString _sentCode;
mtpRequestId _sentRequest = 0;
object_ptr<QTimer> _callTimer;
base::Timer _callTimer;
CallStatus _callStatus = CallStatus();
int _callTimeout;
mtpRequestId _callRequestId = 0;
object_ptr<Ui::FlatLabel> _callLabel;
object_ptr<QTimer> _checkRequest;
base::Timer _checkRequestTimer;
};

View file

@ -40,16 +40,15 @@ PhoneWidget::PhoneWidget(
, _country(this, st::introCountry)
, _code(this, st::introCountryCode)
, _phone(this, st::introPhone)
, _checkRequest(this) {
, _checkRequestTimer([=] { checkRequest(); }) {
connect(_phone, SIGNAL(voidBackspace(QKeyEvent*)), _code, SLOT(startErasing(QKeyEvent*)));
connect(_country, SIGNAL(codeChanged(const QString &)), _code, SLOT(codeSelected(const QString &)));
connect(_code, SIGNAL(codeChanged(const QString &)), _country, SLOT(onChooseCode(const QString &)));
connect(_code, SIGNAL(codeChanged(const QString &)), _phone, SLOT(onChooseCode(const QString &)));
connect(_country, SIGNAL(codeChanged(const QString &)), _phone, SLOT(onChooseCode(const QString &)));
connect(_code, SIGNAL(addedToNumber(const QString &)), _phone, SLOT(addedToNumber(const QString &)));
connect(_phone, SIGNAL(changed()), this, SLOT(onInputChange()));
connect(_code, SIGNAL(changed()), this, SLOT(onInputChange()));
connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest()));
connect(_phone, &Ui::PhonePartInput::changed, [=] { phoneChanged(); });
connect(_code, &Ui::CountryCodeInput::changed, [=] { phoneChanged(); });
setTitleText(tr::lng_phone_title());
setDescriptionText(tr::lng_phone_desc());
@ -85,7 +84,7 @@ void PhoneWidget::countryChanged() {
}
}
void PhoneWidget::onInputChange() {
void PhoneWidget::phoneChanged() {
_changed = true;
hidePhoneError();
}
@ -102,7 +101,7 @@ void PhoneWidget::submit() {
hidePhoneError();
_checkRequest->start(1000);
_checkRequestTimer.callEach(1000);
_sentPhone = phone;
account().mtp()->setUserPhone(_sentPhone);
@ -117,10 +116,10 @@ void PhoneWidget::submit() {
}
void PhoneWidget::stopCheck() {
_checkRequest->stop();
_checkRequestTimer.cancel();
}
void PhoneWidget::onCheckRequest() {
void PhoneWidget::checkRequest() {
auto status = MTP::state(_sentRequest);
if (status < 0) {
auto leftms = -status;
@ -209,7 +208,7 @@ void PhoneWidget::activate() {
void PhoneWidget::finished() {
Step::finished();
_checkRequest->stop();
_checkRequestTimer.cancel();
rpcInvalidate();
cancelled();

View file

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/countryinput.h"
#include "intro/intro_step.h"
#include "base/timer.h"
namespace Ui {
class PhonePartInput;
@ -20,9 +21,7 @@ class FlatLabel;
namespace Intro {
namespace details {
class PhoneWidget : public Step {
Q_OBJECT
class PhoneWidget final : public Step {
public:
PhoneWidget(
QWidget *parent,
@ -44,11 +43,9 @@ public:
protected:
void resizeEvent(QResizeEvent *e) override;
private slots:
void onInputChange();
void onCheckRequest();
private:
void phoneChanged();
void checkRequest();
void countryChanged();
void phoneSubmitDone(const MTPauth_SentCode &result);
@ -69,7 +66,7 @@ private:
QString _sentPhone;
mtpRequestId _sentRequest = 0;
object_ptr<QTimer> _checkRequest;
base::Timer _checkRequestTimer;
};

View file

@ -38,17 +38,15 @@ PwdCheckWidget::PwdCheckWidget(
, _pwdHint(this, st::introPasswordHint)
, _codeField(this, st::introPassword, tr::lng_signin_code())
, _toRecover(this, tr::lng_signin_recover(tr::now))
, _toPassword(this, tr::lng_signin_try_password(tr::now))
, _checkRequest(this) {
, _toPassword(this, tr::lng_signin_try_password(tr::now)) {
Expects(!!_request);
subscribe(Lang::Current().updated(), [this] { refreshLang(); });
subscribe(Lang::Current().updated(), [=] { refreshLang(); });
connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest()));
_toRecover->addClickHandler([=] { onToRecover(); });
_toPassword->addClickHandler([=] { onToPassword(); });
connect(_pwdField, SIGNAL(changed()), this, SLOT(onInputChange()));
connect(_codeField, SIGNAL(changed()), this, SLOT(onInputChange()));
_toRecover->addClickHandler([=] { toRecover(); });
_toPassword->addClickHandler([=] { toPassword(); });
connect(_pwdField, &Ui::PasswordInput::changed, [=] { hideError(); });
connect(_codeField, &Ui::InputField::changed, [=] { hideError(); });
setTitleText(tr::lng_signin_title());
updateDescriptionText();
@ -120,26 +118,8 @@ void PwdCheckWidget::cancelled() {
_api.request(base::take(_sentRequest)).cancel();
}
void PwdCheckWidget::stopCheck() {
_checkRequest->stop();
}
void PwdCheckWidget::onCheckRequest() {
auto status = MTP::state(_sentRequest);
if (status < 0) {
auto leftms = -status;
if (leftms >= 1000) {
_api.request(base::take(_sentRequest)).cancel();
}
}
if (!_sentRequest && status == MTP::RequestSent) {
stopCheck();
}
}
void PwdCheckWidget::pwdSubmitDone(bool recover, const MTPauth_Authorization &result) {
_sentRequest = 0;
stopCheck();
if (recover) {
cSetPasswordRecovered(true);
}
@ -154,14 +134,12 @@ void PwdCheckWidget::pwdSubmitDone(bool recover, const MTPauth_Authorization &re
void PwdCheckWidget::pwdSubmitFail(const RPCError &error) {
if (MTP::isFloodError(error)) {
_sentRequest = 0;
stopCheck();
showError(tr::lng_flood_error());
_pwdField->showError();
return;
}
_sentRequest = 0;
stopCheck();
const auto &type = error.type();
if (type == qstr("PASSWORD_HASH_INVALID")
|| type == qstr("SRP_PASSWORD_CHANGED")) {
@ -248,7 +226,6 @@ void PwdCheckWidget::codeSubmitFail(const RPCError &error) {
}
_sentRequest = 0;
stopCheck();
const auto &type = error.type();
if (type == qstr("PASSWORD_EMPTY")
|| type == qstr("AUTH_KEY_UNREGISTERED")) {
@ -257,7 +234,7 @@ void PwdCheckWidget::codeSubmitFail(const RPCError &error) {
recoverStartFail(error);
} else if (type == qstr("PASSWORD_RECOVERY_EXPIRED")) {
_emailPattern = QString();
onToPassword();
toPassword();
} else if (type == qstr("CODE_INVALID")) {
showError(tr::lng_signin_wrong_code());
_codeField->selectAll();
@ -278,7 +255,6 @@ void PwdCheckWidget::recoverStarted(const MTPauth_PasswordRecovery &result) {
}
void PwdCheckWidget::recoverStartFail(const RPCError &error) {
stopCheck();
_pwdField->show();
_pwdHint->show();
_codeField->hide();
@ -288,7 +264,7 @@ void PwdCheckWidget::recoverStartFail(const RPCError &error) {
hideError();
}
void PwdCheckWidget::onToRecover() {
void PwdCheckWidget::toRecover() {
if (_hasRecovery) {
if (_sentRequest) {
_api.request(base::take(_sentRequest)).cancel();
@ -312,12 +288,16 @@ void PwdCheckWidget::onToRecover() {
}).send();
}
} else {
Ui::show(Box<InformBox>(tr::lng_signin_no_email_forgot(tr::now), [this] { showReset(); }));
Ui::show(Box<InformBox>(
tr::lng_signin_no_email_forgot(tr::now),
[=] { showReset(); }));
}
}
void PwdCheckWidget::onToPassword() {
Ui::show(Box<InformBox>(tr::lng_signin_cant_email_forgot(tr::now), [this] { showReset(); }));
void PwdCheckWidget::toPassword() {
Ui::show(Box<InformBox>(
tr::lng_signin_cant_email_forgot(tr::now),
[=] { showReset(); }));
}
void PwdCheckWidget::showReset() {
@ -344,12 +324,10 @@ void PwdCheckWidget::updateDescriptionText() {
: tr::lng_signin_desc());
}
void PwdCheckWidget::onInputChange() {
hideError();
}
void PwdCheckWidget::submit() {
if (_sentRequest) return;
if (_sentRequest) {
return;
}
if (_pwdField->isHidden()) {
auto code = _codeField->getLastText().trimmed();
if (code.isEmpty()) {

View file

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "intro/intro_step.h"
#include "core/core_cloud_password.h"
#include "mtproto/sender.h"
#include "base/timer.h"
namespace Ui {
class InputField;
@ -21,9 +22,7 @@ class LinkButton;
namespace Intro {
namespace details {
class PwdCheckWidget : public Step {
Q_OBJECT
class PwdCheckWidget final : public Step {
public:
PwdCheckWidget(
QWidget *parent,
@ -39,13 +38,10 @@ public:
protected:
void resizeEvent(QResizeEvent *e) override;
private slots:
void onToRecover();
void onToPassword();
void onInputChange();
void onCheckRequest();
private:
void toRecover();
void toPassword();
int errorTop() const override;
void showReset();
@ -60,7 +56,6 @@ private:
void recoverStarted(const MTPauth_PasswordRecovery &result);
void updateDescriptionText();
void stopCheck();
void handleSrpIdInvalid();
void requestPasswordData();
void checkPasswordHash();
@ -82,8 +77,6 @@ private:
object_ptr<Ui::LinkButton> _toPassword;
mtpRequestId _sentRequest = 0;
object_ptr<QTimer> _checkRequest;
};
} // namespace details

View file

@ -26,16 +26,15 @@ SignupWidget::SignupWidget(
QWidget *parent,
not_null<Main::Account*> account,
not_null<Data*> data)
: Step(parent, account, data)
, _photo(
this,
tr::lng_settings_crop_profile(tr::now),
Ui::UserpicButton::Role::ChangePhoto,
st::defaultUserpicButton)
, _first(this, st::introName, tr::lng_signup_firstname())
, _last(this, st::introName, tr::lng_signup_lastname())
, _invertOrder(langFirstNameGoesSecond())
, _checkRequest(this) {
: Step(parent, account, data)
, _photo(
this,
tr::lng_settings_crop_profile(tr::now),
Ui::UserpicButton::Role::ChangePhoto,
st::defaultUserpicButton)
, _first(this, st::introName, tr::lng_signup_firstname())
, _last(this, st::introName, tr::lng_signup_lastname())
, _invertOrder(langFirstNameGoesSecond()) {
subscribe(Lang::Current().updated(), [this] { refreshLang(); });
if (_invertOrder) {
setTabOrder(_last, _first);
@ -43,8 +42,6 @@ SignupWidget::SignupWidget(
setTabOrder(_first, _last);
}
connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest()));
setErrorCentered(true);
setTitleText(tr::lng_signup_title());
@ -107,25 +104,7 @@ void SignupWidget::cancelled() {
MTP::cancel(base::take(_sentRequest));
}
void SignupWidget::stopCheck() {
_checkRequest->stop();
}
void SignupWidget::onCheckRequest() {
auto status = MTP::state(_sentRequest);
if (status < 0) {
auto leftms = -status;
if (leftms >= 1000) {
MTP::cancel(base::take(_sentRequest));
}
}
if (!_sentRequest && status == MTP::RequestSent) {
stopCheck();
}
}
void SignupWidget::nameSubmitDone(const MTPauth_Authorization &result) {
stopCheck();
auto &d = result.c_auth_authorization();
if (d.vuser().type() != mtpc_user || !d.vuser().c_user().is_self()) { // wtf?
showError(rpl::single(Lang::Hard::ServerError()));
@ -136,7 +115,6 @@ void SignupWidget::nameSubmitDone(const MTPauth_Authorization &result) {
bool SignupWidget::nameSubmitFail(const RPCError &error) {
if (MTP::isFloodError(error)) {
stopCheck();
showError(tr::lng_flood_error());
if (_invertOrder) {
_first->setFocus();
@ -147,7 +125,6 @@ bool SignupWidget::nameSubmitFail(const RPCError &error) {
}
if (MTP::isDefaultHandledError(error)) return false;
stopCheck();
auto &err = error.type();
if (err == qstr("PHONE_NUMBER_FLOOD")) {
Ui::show(Box<InformBox>(tr::lng_error_phone_flood(tr::now)));
@ -182,10 +159,6 @@ bool SignupWidget::nameSubmitFail(const RPCError &error) {
return false;
}
void SignupWidget::onInputChange() {
hideError();
}
void SignupWidget::submit() {
if (_sentRequest) {
return;

View file

@ -18,9 +18,7 @@ class UserpicButton;
namespace Intro {
namespace details {
class SignupWidget : public Step {
Q_OBJECT
class SignupWidget final : public Step {
public:
SignupWidget(
QWidget *parent,
@ -37,10 +35,6 @@ public:
protected:
void resizeEvent(QResizeEvent *e) override;
private slots:
void onInputChange();
void onCheckRequest();
private:
void refreshLang();
void updateControlsGeometry();
@ -48,8 +42,6 @@ private:
void nameSubmitDone(const MTPauth_Authorization &result);
bool nameSubmitFail(const RPCError &error);
void stopCheck();
object_ptr<Ui::UserpicButton> _photo;
object_ptr<Ui::InputField> _first;
object_ptr<Ui::InputField> _last;
@ -59,7 +51,6 @@ private:
bool _invertOrder = false;
bool _termsAccepted = false;
object_ptr<QTimer> _checkRequest;
};