2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Passcode lock button added to DialogsWidget.

This commit is contained in:
John Preston
2016-11-04 22:50:35 +03:00
parent 3a599e0752
commit e693a98bd4
36 changed files with 812 additions and 777 deletions

View File

@@ -74,28 +74,14 @@ introTextSize: size(400px, 93px);
introCallSkip: 15px;
introPwdTextSize: size(400px, 73px);
introNextButton: flatButton {
duration: 200;
cursor: cursor(pointer);
color: #ffffff;
overColor: #ffffff;
downColor: #ffffff;
bgColor: #2fa9e2;
overBgColor: #279ad0;
downBgColor: #279ad0;
textTop: 16px;
overTextTop: 16px;
downTextTop: 17px;
font: font(17px);
overFont: font(17px);
introNextButton: RoundButton(defaultActiveButton) {
width: 300px;
height: 56px;
radius: buttonRadius;
textTop: 16px;
downTextTop: 17px;
font: font(17px);
}
introPhoneTop: 8px;

View File

@@ -25,6 +25,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "application.h"
#include "intro/introsignup.h"
#include "intro/intropwdcheck.h"
#include "ui/buttons/round_button.h"
#include "styles/style_intro.h"
CodeInput::CodeInput(QWidget *parent, const style::flatInput &st, const QString &ph) : FlatInput(parent, st, ph) {
@@ -75,26 +76,28 @@ void CodeInput::correctValue(const QString &was, QString &now) {
IntroCode::IntroCode(IntroWidget *parent) : IntroStep(parent)
, a_errorAlpha(0)
, _a_error(animation(this, &IntroCode::step_error))
, next(this, lang(lng_intro_next), st::introNextButton)
, _next(this, lang(lng_intro_next), st::introNextButton)
, _desc(st::introTextSize.width())
, _noTelegramCode(this, lang(lng_code_no_telegram), st::introLink)
, _noTelegramCodeRequestId(0)
, code(this, st::inpIntroCode, lang(lng_code_ph))
, sentRequest(0)
, callStatus(intro()->getCallStatus()) {
, _code(this, st::inpIntroCode, lang(lng_code_ph))
, _callTimer(this)
, _callStatus(intro()->getCallStatus())
, _checkRequest(this) {
setGeometry(parent->innerRect());
connect(&next, SIGNAL(clicked()), this, SLOT(onSubmitCode()));
connect(&code, SIGNAL(changed()), this, SLOT(onInputChange()));
connect(&callTimer, SIGNAL(timeout()), this, SLOT(onSendCall()));
connect(&checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest()));
connect(&_noTelegramCode, SIGNAL(clicked()), this, SLOT(onNoTelegramCode()));
_next->setTextTransform(Ui::RoundButton::TextTransform::ToUpper);
connect(_next, SIGNAL(clicked()), this, SLOT(onSubmitCode()));
connect(_code, SIGNAL(changed()), this, SLOT(onInputChange()));
connect(_callTimer, SIGNAL(timeout()), this, SLOT(onSendCall()));
connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest()));
connect(_noTelegramCode, SIGNAL(clicked()), this, SLOT(onNoTelegramCode()));
updateDescText();
if (!intro()->codeByTelegram()) {
if (callStatus.type == IntroWidget::CallWaiting) {
callTimer.start(1000);
if (_callStatus.type == IntroWidget::CallWaiting) {
_callTimer->start(1000);
}
}
}
@@ -102,13 +105,13 @@ IntroCode::IntroCode(IntroWidget *parent) : IntroStep(parent)
void IntroCode::updateDescText() {
_desc.setRichText(st::introFont, lang(intro()->codeByTelegram() ? lng_code_telegram : lng_code_desc));
if (intro()->codeByTelegram()) {
_noTelegramCode.show();
callTimer.stop();
_noTelegramCode->show();
_callTimer->stop();
} else {
_noTelegramCode.hide();
callStatus = intro()->getCallStatus();
if (callStatus.type == IntroWidget::CallWaiting && !callTimer.isActive()) {
callTimer.start(1000);
_noTelegramCode->hide();
_callStatus = intro()->getCallStatus();
if (_callStatus.type == IntroWidget::CallWaiting && !_callTimer->isActive()) {
_callTimer->start(1000);
}
}
update();
@@ -122,21 +125,21 @@ void IntroCode::paintEvent(QPaintEvent *e) {
p.setClipRect(e->rect());
}
bool codeByTelegram = intro()->codeByTelegram();
if (trivial || e->rect().intersects(textRect)) {
if (trivial || e->rect().intersects(_textRect)) {
p.setFont(st::introHeaderFont->f);
p.drawText(textRect, intro()->getPhone(), style::al_top);
p.drawText(_textRect, intro()->getPhone(), style::al_top);
p.setFont(st::introFont->f);
_desc.draw(p, textRect.x(), textRect.y() + textRect.height() - 2 * st::introFont->height, textRect.width(), style::al_top);
_desc.draw(p, _textRect.x(), _textRect.y() + _textRect.height() - 2 * st::introFont->height, _textRect.width(), style::al_top);
}
if (codeByTelegram) {
} else {
QString callText;
switch (callStatus.type) {
switch (_callStatus.type) {
case IntroWidget::CallWaiting: {
if (callStatus.timeout >= 3600) {
callText = lng_code_call(lt_minutes, qsl("%1:%2").arg(callStatus.timeout / 3600).arg((callStatus.timeout / 60) % 60, 2, 10, QChar('0')), lt_seconds, qsl("%1").arg(callStatus.timeout % 60, 2, 10, QChar('0')));
if (_callStatus.timeout >= 3600) {
callText = lng_code_call(lt_minutes, qsl("%1:%2").arg(_callStatus.timeout / 3600).arg((_callStatus.timeout / 60) % 60, 2, 10, QChar('0')), lt_seconds, qsl("%1").arg(_callStatus.timeout % 60, 2, 10, QChar('0')));
} else {
callText = lng_code_call(lt_minutes, QString::number(callStatus.timeout / 60), lt_seconds, qsl("%1").arg(callStatus.timeout % 60, 2, 10, QChar('0')));
callText = lng_code_call(lt_minutes, QString::number(_callStatus.timeout / 60), lt_seconds, qsl("%1").arg(_callStatus.timeout % 60, 2, 10, QChar('0')));
}
} break;
@@ -149,32 +152,32 @@ void IntroCode::paintEvent(QPaintEvent *e) {
} break;
}
if (!callText.isEmpty()) {
p.drawText(QRect(textRect.left(), code.y() + code.height() + st::introCallSkip, st::introTextSize.width(), st::introErrorHeight), callText, style::al_center);
p.drawText(QRect(_textRect.left(), _code->y() + _code->height() + st::introCallSkip, st::introTextSize.width(), st::introErrorHeight), callText, style::al_center);
}
}
if (_a_error.animating() || error.length()) {
if (_a_error.animating() || _error.length()) {
p.setOpacity(a_errorAlpha.current());
p.setFont(st::introErrorFont);
p.setPen(st::introErrorFg);
p.drawText(QRect(textRect.left(), next.y() + next.height() + st::introErrorTop, st::introTextSize.width(), st::introErrorHeight), error, style::al_center);
p.drawText(QRect(_textRect.left(), _next->y() + _next->height() + st::introErrorTop, st::introTextSize.width(), st::introErrorHeight), _error, style::al_center);
}
}
void IntroCode::resizeEvent(QResizeEvent *e) {
if (e->oldSize().width() != width()) {
next.move((width() - next.width()) / 2, st::introBtnTop);
code.move((width() - code.width()) / 2, st::introTextTop + st::introTextSize.height() + st::introCountry.top);
_next->move((width() - _next->width()) / 2, st::introBtnTop);
_code->move((width() - _code->width()) / 2, st::introTextTop + st::introTextSize.height() + st::introCountry.top);
}
textRect = QRect((width() - st::introTextSize.width()) / 2, st::introTextTop, st::introTextSize.width(), st::introTextSize.height());
_noTelegramCode.move(textRect.left() + (st::introTextSize.width() - _noTelegramCode.width()) / 2, code.y() + code.height() + st::introCallSkip + (st::introErrorHeight - _noTelegramCode.height()) / 2);
_textRect = QRect((width() - st::introTextSize.width()) / 2, st::introTextTop, st::introTextSize.width(), st::introTextSize.height());
_noTelegramCode->move(_textRect.left() + (st::introTextSize.width() - _noTelegramCode->width()) / 2, _code->y() + _code->height() + st::introCallSkip + (st::introErrorHeight - _noTelegramCode->height()) / 2);
}
void IntroCode::showError(const QString &err) {
if (!err.isEmpty()) code.notaBene();
if (!_a_error.animating() && err == error) return;
void IntroCode::showError(const QString &error) {
if (!error.isEmpty()) _code->notaBene();
if (!_a_error.animating() && error == _error) return;
if (err.length()) {
error = err;
if (error.length()) {
_error = error;
a_errorAlpha.start(1);
} else {
a_errorAlpha.start(0);
@@ -189,7 +192,7 @@ void IntroCode::step_error(float64 ms, bool timer) {
_a_error.stop();
a_errorAlpha.finish();
if (!a_errorAlpha.current()) {
error.clear();
_error.clear();
}
} else {
a_errorAlpha.update(dt, anim::linear);
@@ -199,59 +202,57 @@ void IntroCode::step_error(float64 ms, bool timer) {
void IntroCode::activate() {
IntroStep::activate();
code.setFocus();
_code->setFocus();
}
void IntroCode::finished() {
IntroStep::finished();
error.clear();
_error.clear();
a_errorAlpha = anim::fvalue(0);
sentCode.clear();
code.setDisabled(false);
_sentCode.clear();
_code->setDisabled(false);
callTimer.stop();
code.setText(QString());
_callTimer->stop();
_code->setText(QString());
rpcClear();
}
void IntroCode::cancelled() {
if (sentRequest) {
MTP::cancel(sentRequest);
sentRequest = 0;
if (_sentRequest) {
MTP::cancel(base::take(_sentRequest));
}
MTP::send(MTPauth_CancelCode(MTP_string(intro()->getPhone()), MTP_string(intro()->getPhoneHash())));
}
void IntroCode::stopCheck() {
checkRequest.stop();
_checkRequest->stop();
}
void IntroCode::onCheckRequest() {
int32 status = MTP::state(sentRequest);
int32 status = MTP::state(_sentRequest);
if (status < 0) {
int32 leftms = -status;
if (leftms >= 1000) {
if (sentRequest) {
MTP::cancel(sentRequest);
sentRequest = 0;
sentCode.clear();
if (_sentRequest) {
MTP::cancel(base::take(_sentRequest));
_sentCode.clear();
}
if (!code.isEnabled()) {
code.setDisabled(false);
code.setFocus();
if (!_code->isEnabled()) {
_code->setDisabled(false);
_code->setFocus();
}
}
}
if (!sentRequest && status == MTP::RequestSent) {
if (!_sentRequest && status == MTP::RequestSent) {
stopCheck();
}
}
void IntroCode::codeSubmitDone(const MTPauth_Authorization &result) {
stopCheck();
sentRequest = 0;
code.setDisabled(false);
_sentRequest = 0;
_code->setDisabled(false);
const auto &d(result.c_auth_authorization());
if (d.vuser.type() != mtpc_user || !d.vuser.c_user().is_self()) { // wtf?
showError(lang(lng_server_error));
@@ -264,34 +265,34 @@ void IntroCode::codeSubmitDone(const MTPauth_Authorization &result) {
bool IntroCode::codeSubmitFail(const RPCError &error) {
if (MTP::isFloodError(error)) {
stopCheck();
sentRequest = 0;
_sentRequest = 0;
showError(lang(lng_flood_error));
code.setDisabled(false);
code.setFocus();
_code->setDisabled(false);
_code->setFocus();
return true;
}
if (MTP::isDefaultHandledError(error)) return false;
stopCheck();
sentRequest = 0;
code.setDisabled(false);
_sentRequest = 0;
_code->setDisabled(false);
const QString &err = error.type();
if (err == qstr("PHONE_NUMBER_INVALID") || err == qstr("PHONE_CODE_EXPIRED")) { // show error
intro()->onBack();
return true;
} else if (err == qstr("PHONE_CODE_EMPTY") || err == qstr("PHONE_CODE_INVALID")) {
showError(lang(lng_bad_code));
code.notaBene();
_code->notaBene();
return true;
} else if (err == qstr("PHONE_NUMBER_UNOCCUPIED")) { // success, need to signUp
intro()->setCode(sentCode);
intro()->setCode(_sentCode);
intro()->replaceStep(new IntroSignup(intro()));
return true;
} else if (err == qstr("SESSION_PASSWORD_NEEDED")) {
intro()->setCode(sentCode);
code.setDisabled(false);
checkRequest.start(1000);
sentRequest = MTP::send(MTPaccount_GetPassword(), rpcDone(&IntroCode::gotPassword), rpcFail(&IntroCode::codeSubmitFail));
intro()->setCode(_sentCode);
_code->setDisabled(false);
_checkRequest->start(1000);
_sentRequest = MTP::send(MTPaccount_GetPassword(), rpcDone(&IntroCode::gotPassword), rpcFail(&IntroCode::codeSubmitFail));
return true;
}
if (cDebug()) { // internal server error
@@ -299,43 +300,43 @@ bool IntroCode::codeSubmitFail(const RPCError &error) {
} else {
showError(lang(lng_server_error));
}
code.setFocus();
_code->setFocus();
return false;
}
void IntroCode::onInputChange() {
showError(QString());
if (code.text().length() == 5) onSubmitCode();
if (_code->text().length() == 5) onSubmitCode();
}
void IntroCode::onSendCall() {
if (callStatus.type == IntroWidget::CallWaiting) {
if (--callStatus.timeout <= 0) {
callStatus.type = IntroWidget::CallCalling;
callTimer.stop();
if (_callStatus.type == IntroWidget::CallWaiting) {
if (--_callStatus.timeout <= 0) {
_callStatus.type = IntroWidget::CallCalling;
_callTimer->stop();
MTP::send(MTPauth_ResendCode(MTP_string(intro()->getPhone()), MTP_string(intro()->getPhoneHash())), rpcDone(&IntroCode::callDone));
} else {
intro()->setCallStatus(callStatus);
intro()->setCallStatus(_callStatus);
}
}
update();
}
void IntroCode::callDone(const MTPauth_SentCode &v) {
if (callStatus.type == IntroWidget::CallCalling) {
callStatus.type = IntroWidget::CallCalled;
intro()->setCallStatus(callStatus);
if (_callStatus.type == IntroWidget::CallCalling) {
_callStatus.type = IntroWidget::CallCalled;
intro()->setCallStatus(_callStatus);
update();
}
}
void IntroCode::gotPassword(const MTPaccount_Password &result) {
stopCheck();
sentRequest = 0;
code.setDisabled(false);
_sentRequest = 0;
_code->setDisabled(false);
switch (result.type()) {
case mtpc_account_noPassword: // should not happen
code.setFocus();
_code->setFocus();
break;
case mtpc_account_password: {
@@ -349,20 +350,20 @@ void IntroCode::gotPassword(const MTPaccount_Password &result) {
}
void IntroCode::onSubmitCode() {
if (sentRequest) return;
if (_sentRequest) return;
code.setDisabled(true);
_code->setDisabled(true);
setFocus();
showError(QString());
checkRequest.start(1000);
_checkRequest->start(1000);
sentCode = code.text();
_sentCode = _code->text();
intro()->setPwdSalt(QByteArray());
intro()->setHasRecovery(false);
intro()->setPwdHint(QString());
sentRequest = MTP::send(MTPauth_SignIn(MTP_string(intro()->getPhone()), MTP_string(intro()->getPhoneHash()), MTP_string(sentCode)), rpcDone(&IntroCode::codeSubmitDone), rpcFail(&IntroCode::codeSubmitFail));
_sentRequest = MTP::send(MTPauth_SignIn(MTP_string(intro()->getPhone()), MTP_string(intro()->getPhoneHash()), MTP_string(_sentCode)), rpcDone(&IntroCode::codeSubmitDone), rpcFail(&IntroCode::codeSubmitFail));
}
void IntroCode::onNoTelegramCode() {
@@ -395,7 +396,7 @@ void IntroCode::noTelegramCodeDone(const MTPauth_SentCode &result) {
bool IntroCode::noTelegramCodeFail(const RPCError &error) {
if (MTP::isFloodError(error)) {
showError(lang(lng_flood_error));
code.setFocus();
_code->setFocus();
return true;
}
if (MTP::isDefaultHandledError(error)) return false;
@@ -405,7 +406,7 @@ bool IntroCode::noTelegramCodeFail(const RPCError &error) {
} else {
showError(lang(lng_server_error));
}
code.setFocus();
_code->setFocus();
return false;
}

View File

@@ -25,6 +25,10 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "ui/flatinput.h"
#include "intro/introwidget.h"
namespace Ui {
class RoundButton;
} // namespace Ui
class CodeInput final : public FlatInput {
Q_OBJECT
@@ -43,7 +47,6 @@ class IntroCode final : public IntroStep {
Q_OBJECT
public:
IntroCode(IntroWidget *parent);
void paintEvent(QPaintEvent *e) override;
@@ -65,7 +68,6 @@ public:
void updateDescText();
public slots:
void onSubmitCode();
void onNoTelegramCode();
void onInputChange();
@@ -73,32 +75,32 @@ public slots:
void onCheckRequest();
private:
void showError(const QString &err);
void callDone(const MTPauth_SentCode &v);
void gotPassword(const MTPaccount_Password &result);
void stopCheck();
QString error;
anim::fvalue a_errorAlpha;
Animation _a_error;
FlatButton next;
Text _desc;
LinkButton _noTelegramCode;
mtpRequestId _noTelegramCodeRequestId;
QRect textRect;
void noTelegramCodeDone(const MTPauth_SentCode &result);
bool noTelegramCodeFail(const RPCError &result);
CodeInput code;
QString sentCode;
mtpRequestId sentRequest;
QTimer callTimer;
IntroWidget::CallStatus callStatus;
void stopCheck();
QString _error;
anim::fvalue a_errorAlpha;
Animation _a_error;
ChildWidget<Ui::RoundButton> _next;
Text _desc;
ChildWidget<LinkButton> _noTelegramCode;
mtpRequestId _noTelegramCodeRequestId;
QRect _textRect;
ChildWidget<CodeInput> _code;
QString _sentCode;
mtpRequestId _sentRequest = 0;
ChildObject<QTimer> _callTimer;
IntroWidget::CallStatus _callStatus;
ChildObject<QTimer> _checkRequest;
QTimer checkRequest;
};

View File

@@ -25,6 +25,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "application.h"
#include "intro/introcode.h"
#include "styles/style_intro.h"
#include "ui/buttons/round_button.h"
namespace {
class SignUpClickHandler : public LeftButtonClickHandler {
@@ -46,38 +47,37 @@ namespace {
IntroPhone::IntroPhone(IntroWidget *parent) : IntroStep(parent)
, a_errorAlpha(0)
, _a_error(animation(this, &IntroPhone::step_error))
, changed(false)
, next(this, lang(lng_intro_next), st::introNextButton)
, country(this, st::introCountry)
, phone(this, st::inpIntroPhone)
, code(this, st::inpIntroCountryCode)
, _next(this, lang(lng_intro_next), st::introNextButton)
, _country(this, st::introCountry)
, _phone(this, st::inpIntroPhone)
, _code(this, st::inpIntroCountryCode)
, _signup(this, lng_phone_notreg(lt_signup_start, textcmdStartLink(1), lt_signup_end, textcmdStopLink()), FlatLabel::InitType::Rich, st::introErrorLabel, st::introErrorLabelTextStyle)
, _showSignup(false)
, sentRequest(0) {
, _checkRequest(this) {
setVisible(false);
setGeometry(parent->innerRect());
connect(&next, SIGNAL(clicked()), this, SLOT(onSubmitPhone()));
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()));
_next->setTextTransform(Ui::RoundButton::TextTransform::ToUpper);
connect(_next, SIGNAL(clicked()), this, SLOT(onSubmitPhone()));
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(intro(), SIGNAL(countryChanged()), this, SLOT(countryChanged()));
connect(&checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest()));
connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest()));
_signup.setLink(1, MakeShared<SignUpClickHandler>(this));
_signup.hide();
_signup->setLink(1, MakeShared<SignUpClickHandler>(this));
_signup->hide();
_signupCache = myGrab(&_signup);
_signupCache = myGrab(_signup);
if (!country.onChooseCountry(intro()->currentCountry())) {
country.onChooseCountry(qsl("US"));
if (!_country->onChooseCountry(intro()->currentCountry())) {
_country->onChooseCountry(qsl("US"));
}
changed = false;
_changed = false;
}
void IntroPhone::paintEvent(QPaintEvent *e) {
@@ -87,52 +87,52 @@ void IntroPhone::paintEvent(QPaintEvent *e) {
if (!trivial) {
p.setClipRect(e->rect());
}
if (trivial || e->rect().intersects(textRect)) {
if (trivial || e->rect().intersects(_textRect)) {
p.setFont(st::introHeaderFont->f);
p.drawText(textRect, lang(lng_phone_title), style::al_top);
p.drawText(_textRect, lang(lng_phone_title), style::al_top);
p.setFont(st::introFont->f);
p.drawText(textRect, lang(lng_phone_desc), style::al_bottom);
p.drawText(_textRect, lang(lng_phone_desc), style::al_bottom);
}
if (_a_error.animating() || error.length()) {
int32 errorY = _showSignup ? ((phone.y() + phone.height() + next.y() - st::introErrorFont->height) / 2) : (next.y() + next.height() + st::introErrorTop);
if (_a_error.animating() || _error.length()) {
int32 errorY = _showSignup ? ((_phone->y() + _phone->height() + _next->y() - st::introErrorFont->height) / 2) : (_next->y() + _next->height() + st::introErrorTop);
p.setOpacity(a_errorAlpha.current());
p.setFont(st::introErrorFont);
p.setPen(st::introErrorFg);
p.drawText(QRect(textRect.x(), errorY, textRect.width(), st::introErrorFont->height), error, style::al_top);
p.drawText(QRect(_textRect.x(), errorY, _textRect.width(), st::introErrorFont->height), _error, style::al_top);
if (_signup.isHidden() && _showSignup) {
p.drawPixmap(_signup.x(), _signup.y(), _signupCache);
if (_signup->isHidden() && _showSignup) {
p.drawPixmap(_signup->x(), _signup->y(), _signupCache);
}
}
}
void IntroPhone::resizeEvent(QResizeEvent *e) {
if (e->oldSize().width() != width()) {
next.move((width() - next.width()) / 2, st::introBtnTop);
country.move((width() - country.width()) / 2, st::introTextTop + st::introTextSize.height() + st::introCountry.top);
int phoneTop = country.y() + country.height() + st::introPhoneTop;
phone.move((width() - country.width()) / 2 + country.width() - st::inpIntroPhone.width, phoneTop);
code.move((width() - country.width()) / 2, phoneTop);
_next->move((width() - _next->width()) / 2, st::introBtnTop);
_country->move((width() - _country->width()) / 2, st::introTextTop + st::introTextSize.height() + st::introCountry.top);
int phoneTop = _country->y() + _country->height() + st::introPhoneTop;
_phone->move((width() - _country->width()) / 2 + _country->width() - st::inpIntroPhone.width, phoneTop);
_code->move((width() - _country->width()) / 2, phoneTop);
}
_signup.move((width() - _signup.width()) / 2, next.y() + next.height() + st::introErrorTop - ((st::introErrorLabelTextStyle.lineHeight - st::introErrorFont->height) / 2));
textRect = QRect((width() - st::introTextSize.width()) / 2, st::introTextTop, st::introTextSize.width(), st::introTextSize.height());
_signup->move((width() - _signup->width()) / 2, _next->y() + _next->height() + st::introErrorTop - ((st::introErrorLabelTextStyle.lineHeight - st::introErrorFont->height) / 2));
_textRect = QRect((width() - st::introTextSize.width()) / 2, st::introTextTop, st::introTextSize.width(), st::introTextSize.height());
}
void IntroPhone::showError(const QString &err, bool signUp) {
if (!err.isEmpty()) {
phone.notaBene();
void IntroPhone::showError(const QString &error, bool signUp) {
if (!error.isEmpty()) {
_phone->notaBene();
_showSignup = signUp;
}
if (!_a_error.animating() && err == error) return;
if (!_a_error.animating() && error == _error) return;
if (err.length()) {
error = err;
if (error.length()) {
_error = error;
a_errorAlpha.start(1);
} else {
a_errorAlpha.start(0);
}
_signup.hide();
_signup->hide();
_a_error.start();
}
@@ -143,10 +143,10 @@ void IntroPhone::step_error(float64 ms, bool timer) {
_a_error.stop();
a_errorAlpha.finish();
if (!a_errorAlpha.current()) {
error.clear();
_signup.hide();
} else if (!error.isEmpty() && _showSignup) {
_signup.show();
_error.clear();
_signup->hide();
} else if (!_error.isEmpty() && _showSignup) {
_signup->show();
}
} else {
a_errorAlpha.update(dt, anim::linear);
@@ -155,65 +155,64 @@ void IntroPhone::step_error(float64 ms, bool timer) {
}
void IntroPhone::countryChanged() {
if (!changed) {
if (!_changed) {
selectCountry(intro()->currentCountry());
}
}
void IntroPhone::onInputChange() {
changed = true;
_changed = true;
showError(QString());
}
void IntroPhone::disableAll() {
next.setDisabled(true);
phone.setDisabled(true);
country.setDisabled(true);
code.setDisabled(true);
_next->setDisabled(true);
_phone->setDisabled(true);
_country->setDisabled(true);
_code->setDisabled(true);
setFocus();
}
void IntroPhone::enableAll(bool failed) {
next.setDisabled(false);
phone.setDisabled(false);
country.setDisabled(false);
code.setDisabled(false);
if (failed) phone.setFocus();
_next->setDisabled(false);
_phone->setDisabled(false);
_country->setDisabled(false);
_code->setDisabled(false);
if (failed) _phone->setFocus();
}
void IntroPhone::onSubmitPhone() {
if (sentRequest || isHidden()) return;
if (_sentRequest || isHidden()) return;
if (!App::isValidPhone(fullNumber())) {
showError(lang(lng_bad_phone));
phone.setFocus();
_phone->setFocus();
return;
}
disableAll();
showError(QString());
checkRequest.start(1000);
_checkRequest->start(1000);
sentPhone = fullNumber();
sentRequest = MTP::send(MTPauth_CheckPhone(MTP_string(sentPhone)), rpcDone(&IntroPhone::phoneCheckDone), rpcFail(&IntroPhone::phoneSubmitFail));
_sentPhone = fullNumber();
_sentRequest = MTP::send(MTPauth_CheckPhone(MTP_string(_sentPhone)), rpcDone(&IntroPhone::phoneCheckDone), rpcFail(&IntroPhone::phoneSubmitFail));
}
void IntroPhone::stopCheck() {
checkRequest.stop();
_checkRequest->stop();
}
void IntroPhone::onCheckRequest() {
int32 status = MTP::state(sentRequest);
int32 status = MTP::state(_sentRequest);
if (status < 0) {
int32 leftms = -status;
if (leftms >= 1000) {
MTP::cancel(sentRequest);
sentRequest = 0;
if (!phone.isEnabled()) enableAll(true);
MTP::cancel(base::take(_sentRequest));
if (!_phone->isEnabled()) enableAll(true);
}
}
if (!sentRequest && status == MTP::RequestSent) {
if (!_sentRequest && status == MTP::RequestSent) {
stopCheck();
}
}
@@ -226,20 +225,20 @@ void IntroPhone::phoneCheckDone(const MTPauth_CheckedPhone &result) {
disableAll();
showError(QString());
checkRequest.start(1000);
_checkRequest->start(1000);
MTPauth_SendCode::Flags flags = 0;
sentRequest = MTP::send(MTPauth_SendCode(MTP_flags(flags), MTP_string(sentPhone), MTPBool(), MTP_int(ApiId), MTP_string(ApiHash)), rpcDone(&IntroPhone::phoneSubmitDone), rpcFail(&IntroPhone::phoneSubmitFail));
_sentRequest = MTP::send(MTPauth_SendCode(MTP_flags(flags), MTP_string(_sentPhone), MTPBool(), MTP_int(ApiId), MTP_string(ApiHash)), rpcDone(&IntroPhone::phoneSubmitDone), rpcFail(&IntroPhone::phoneSubmitFail));
} else {
showError(lang(lng_bad_phone_noreg), true);
enableAll(true);
sentRequest = 0;
_sentRequest = 0;
}
}
void IntroPhone::phoneSubmitDone(const MTPauth_SentCode &result) {
stopCheck();
sentRequest = 0;
_sentRequest = 0;
enableAll(true);
if (result.type() != mtpc_auth_sentCode) {
@@ -254,7 +253,7 @@ void IntroPhone::phoneSubmitDone(const MTPauth_SentCode &result) {
case mtpc_auth_sentCodeTypeCall: intro()->setCodeByTelegram(false); break;
case mtpc_auth_sentCodeTypeFlashCall: LOG(("Error: should not be flashcall!")); break;
}
intro()->setPhone(sentPhone, d.vphone_code_hash.c_string().v.c_str(), d.is_phone_registered());
intro()->setPhone(_sentPhone, d.vphone_code_hash.c_string().v.c_str(), d.is_phone_registered());
if (d.has_next_type() && d.vnext_type.type() == mtpc_auth_codeTypeCall) {
intro()->setCallStatus({ IntroWidget::CallWaiting, d.has_timeout() ? d.vtimeout.v : 60 });
} else {
@@ -267,16 +266,16 @@ void IntroPhone::toSignUp() {
disableAll();
showError(QString());
checkRequest.start(1000);
_checkRequest->start(1000);
MTPauth_SendCode::Flags flags = 0;
sentRequest = MTP::send(MTPauth_SendCode(MTP_flags(flags), MTP_string(sentPhone), MTPBool(), MTP_int(ApiId), MTP_string(ApiHash)), rpcDone(&IntroPhone::phoneSubmitDone), rpcFail(&IntroPhone::phoneSubmitFail));
_sentRequest = MTP::send(MTPauth_SendCode(MTP_flags(flags), MTP_string(_sentPhone), MTPBool(), MTP_int(ApiId), MTP_string(ApiHash)), rpcDone(&IntroPhone::phoneSubmitDone), rpcFail(&IntroPhone::phoneSubmitFail));
}
bool IntroPhone::phoneSubmitFail(const RPCError &error) {
if (MTP::isFloodError(error)) {
stopCheck();
sentRequest = 0;
_sentRequest = 0;
showError(lang(lng_flood_error));
enableAll(true);
return true;
@@ -284,7 +283,7 @@ bool IntroPhone::phoneSubmitFail(const RPCError &error) {
if (MTP::isDefaultHandledError(error)) return false;
stopCheck();
sentRequest = 0;
_sentRequest = 0;
const QString &err = error.type();
if (err == qstr("PHONE_NUMBER_INVALID")) { // show error
showError(lang(lng_bad_phone));
@@ -301,32 +300,31 @@ bool IntroPhone::phoneSubmitFail(const RPCError &error) {
}
QString IntroPhone::fullNumber() const {
return code.text() + phone.text();
return _code->text() + _phone->text();
}
void IntroPhone::selectCountry(const QString &c) {
country.onChooseCountry(c);
_country->onChooseCountry(c);
}
void IntroPhone::activate() {
IntroStep::activate();
phone.setFocus();
_phone->setFocus();
}
void IntroPhone::finished() {
IntroStep::finished();
checkRequest.stop();
_checkRequest->stop();
rpcClear();
error.clear();
_error.clear();
a_errorAlpha = anim::fvalue(0);
enableAll(true);
}
void IntroPhone::cancelled() {
if (sentRequest) {
MTP::cancel(sentRequest);
sentRequest = 0;
if (_sentRequest) {
MTP::cancel(base::take(_sentRequest));
}
}

View File

@@ -25,11 +25,14 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "ui/flatlabel.h"
#include "intro/introwidget.h"
namespace Ui {
class RoundButton;
} // namespace Ui
class IntroPhone final : public IntroStep {
Q_OBJECT
public:
IntroPhone(IntroWidget *parent);
void paintEvent(QPaintEvent *e) override;
@@ -51,14 +54,12 @@ public:
void toSignUp();
public slots:
void countryChanged();
void onInputChange();
void onSubmitPhone();
void onCheckRequest();
private:
QString fullNumber() const;
void disableAll();
void enableAll(bool failed);
@@ -66,25 +67,26 @@ private:
void showError(const QString &err, bool signUp = false);
QString error;
QString _error;
anim::fvalue a_errorAlpha;
Animation _a_error;
bool changed;
FlatButton next;
bool _changed = false;
ChildWidget<Ui::RoundButton> _next;
QRect textRect;
QRect _textRect;
CountryInput country;
PhonePartInput phone;
CountryCodeInput code;
ChildWidget<CountryInput> _country;
ChildWidget<PhonePartInput> _phone;
ChildWidget<CountryCodeInput> _code;
FlatLabel _signup;
ChildWidget<FlatLabel> _signup;
QPixmap _signupCache;
bool _showSignup;
bool _showSignup = false;
QString sentPhone;
mtpRequestId sentRequest;
QString _sentPhone;
mtpRequestId _sentRequest = 0;
ChildObject<QTimer> _checkRequest;
QTimer checkRequest;
};

View File

@@ -27,6 +27,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "lang.h"
#include "application.h"
#include "intro/introsignup.h"
#include "ui/buttons/round_button.h"
IntroPwdCheck::IntroPwdCheck(IntroWidget *parent) : IntroStep(parent)
, a_errorAlpha(0)
@@ -40,27 +41,28 @@ IntroPwdCheck::IntroPwdCheck(IntroWidget *parent) : IntroStep(parent)
, _toRecover(this, lang(lng_signin_recover))
, _toPassword(this, lang(lng_signin_try_password))
, _reset(this, lang(lng_signin_reset_account), st::btnRedLink)
, sentRequest(0) {
, _checkRequest(this) {
setVisible(false);
setGeometry(parent->innerRect());
connect(&_next, SIGNAL(clicked()), this, SLOT(onSubmitPwd()));
connect(&checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest()));
connect(&_toRecover, SIGNAL(clicked()), this, SLOT(onToRecover()));
connect(&_toPassword, SIGNAL(clicked()), this, SLOT(onToPassword()));
connect(&_pwdField, SIGNAL(changed()), this, SLOT(onInputChange()));
connect(&_codeField, SIGNAL(changed()), this, SLOT(onInputChange()));
connect(&_reset, SIGNAL(clicked()), this, SLOT(onReset()));
_next->setTextTransform(Ui::RoundButton::TextTransform::ToUpper);
connect(_next, SIGNAL(clicked()), this, SLOT(onSubmitPwd()));
connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest()));
connect(_toRecover, SIGNAL(clicked()), this, SLOT(onToRecover()));
connect(_toPassword, SIGNAL(clicked()), this, SLOT(onToPassword()));
connect(_pwdField, SIGNAL(changed()), this, SLOT(onInputChange()));
connect(_codeField, SIGNAL(changed()), this, SLOT(onInputChange()));
connect(_reset, SIGNAL(clicked()), this, SLOT(onReset()));
_pwdField.setEchoMode(QLineEdit::Password);
_pwdField->setEchoMode(QLineEdit::Password);
if (!_hint.isEmpty()) {
_hintText.setText(st::introFont, lng_signin_hint(lt_password_hint, _hint));
}
_codeField.hide();
_toPassword.hide();
_toRecover.show();
_reset.hide();
_codeField->hide();
_toPassword->hide();
_toRecover->show();
_reset->hide();
setMouseTracking(true);
}
@@ -72,26 +74,26 @@ void IntroPwdCheck::paintEvent(QPaintEvent *e) {
if (!trivial) {
p.setClipRect(e->rect());
}
if (trivial || e->rect().intersects(textRect)) {
if (trivial || e->rect().intersects(_textRect)) {
p.setFont(st::introHeaderFont->f);
p.drawText(textRect, lang(lng_signin_title), style::al_top);
p.drawText(_textRect, lang(lng_signin_title), style::al_top);
p.setFont(st::introFont->f);
p.drawText(textRect, lang(_pwdField.isHidden() ? lng_signin_recover_desc : lng_signin_desc), style::al_bottom);
p.drawText(_textRect, lang(_pwdField->isHidden() ? lng_signin_recover_desc : lng_signin_desc), style::al_bottom);
}
if (_pwdField.isHidden()) {
if (_pwdField->isHidden()) {
if (!_emailPattern.isEmpty()) {
p.drawText(QRect(textRect.x(), _pwdField.y() + _pwdField.height() + st::introFinishSkip, textRect.width(), st::introFont->height), _emailPattern, style::al_top);
p.drawText(QRect(_textRect.x(), _pwdField->y() + _pwdField->height() + st::introFinishSkip, _textRect.width(), st::introFont->height), _emailPattern, style::al_top);
}
} else if (!_hint.isEmpty()) {
_hintText.drawElided(p, _pwdField.x(), _pwdField.y() + _pwdField.height() + st::introFinishSkip, _pwdField.width(), 1, style::al_top);
_hintText.drawElided(p, _pwdField->x(), _pwdField->y() + _pwdField->height() + st::introFinishSkip, _pwdField->width(), 1, style::al_top);
}
if (_a_error.animating() || error.length()) {
if (_a_error.animating() || _error.length()) {
p.setOpacity(a_errorAlpha.current());
QRect errRect((width() - st::introErrorWidth) / 2, (_pwdField.y() + _pwdField.height() + st::introFinishSkip + st::introFont->height + _next.y() - st::introErrorHeight) / 2, st::introErrorWidth, st::introErrorHeight);
QRect errRect((width() - st::introErrorWidth) / 2, (_pwdField->y() + _pwdField->height() + st::introFinishSkip + st::introFont->height + _next->y() - st::introErrorHeight) / 2, st::introErrorWidth, st::introErrorHeight);
p.setFont(st::introErrorFont);
p.setPen(st::introErrorFg);
p.drawText(errRect, error, QTextOption(style::al_center));
p.drawText(errRect, _error, QTextOption(style::al_center));
p.setOpacity(1);
}
@@ -99,21 +101,21 @@ void IntroPwdCheck::paintEvent(QPaintEvent *e) {
void IntroPwdCheck::resizeEvent(QResizeEvent *e) {
if (e->oldSize().width() != width()) {
_next.move((width() - _next.width()) / 2, st::introBtnTop);
_pwdField.move((width() - _pwdField.width()) / 2, st::introTextTop + st::introTextSize.height() + st::introCountry.top);
_codeField.move((width() - _codeField.width()) / 2, st::introTextTop + st::introTextSize.height() + st::introCountry.top);
_toRecover.move(_next.x() + (_pwdField.width() - _toRecover.width()) / 2, _next.y() + _next.height() + st::introFinishSkip);
_toPassword.move(_next.x() + (_pwdField.width() - _toPassword.width()) / 2, _next.y() + _next.height() + st::introFinishSkip);
_reset.move((width() - _reset.width()) / 2, _toRecover.y() + _toRecover.height() + st::introFinishSkip);
_next->move((width() - _next->width()) / 2, st::introBtnTop);
_pwdField->move((width() - _pwdField->width()) / 2, st::introTextTop + st::introTextSize.height() + st::introCountry.top);
_codeField->move((width() - _codeField->width()) / 2, st::introTextTop + st::introTextSize.height() + st::introCountry.top);
_toRecover->move(_next->x() + (_pwdField->width() - _toRecover->width()) / 2, _next->y() + _next->height() + st::introFinishSkip);
_toPassword->move(_next->x() + (_pwdField->width() - _toPassword->width()) / 2, _next->y() + _next->height() + st::introFinishSkip);
_reset->move((width() - _reset->width()) / 2, _toRecover->y() + _toRecover->height() + st::introFinishSkip);
}
textRect = QRect((width() - st::introTextSize.width()) / 2, st::introTextTop, st::introTextSize.width(), st::introTextSize.height());
_textRect = QRect((width() - st::introTextSize.width()) / 2, st::introTextTop, st::introTextSize.width(), st::introTextSize.height());
}
void IntroPwdCheck::showError(const QString &err) {
if (!_a_error.animating() && err == error) return;
void IntroPwdCheck::showError(const QString &error) {
if (!_a_error.animating() && error == _error) return;
if (err.length()) {
error = err;
if (error.length()) {
_error = error;
a_errorAlpha.start(1);
} else {
a_errorAlpha.start(0);
@@ -128,7 +130,7 @@ void IntroPwdCheck::step_error(float64 ms, bool timer) {
_a_error.stop();
a_errorAlpha.finish();
if (!a_errorAlpha.current()) {
error.clear();
_error.clear();
}
} else {
a_errorAlpha.update(dt, anim::linear);
@@ -138,51 +140,49 @@ void IntroPwdCheck::step_error(float64 ms, bool timer) {
void IntroPwdCheck::activate() {
IntroStep::activate();
if (_pwdField.isHidden()) {
_codeField.setFocus();
if (_pwdField->isHidden()) {
_codeField->setFocus();
} else {
_pwdField.setFocus();
_pwdField->setFocus();
}
}
void IntroPwdCheck::cancelled() {
if (sentRequest) {
MTP::cancel(sentRequest);
sentRequest = 0;
if (_sentRequest) {
MTP::cancel(base::take(_sentRequest));
}
}
void IntroPwdCheck::stopCheck() {
checkRequest.stop();
_checkRequest->stop();
}
void IntroPwdCheck::onCheckRequest() {
int32 status = MTP::state(sentRequest);
int32 status = MTP::state(_sentRequest);
if (status < 0) {
int32 leftms = -status;
if (leftms >= 1000) {
MTP::cancel(sentRequest);
sentRequest = 0;
if (!_pwdField.isEnabled()) {
_pwdField.setDisabled(false);
_codeField.setDisabled(false);
MTP::cancel(base::take(_sentRequest));
if (!_pwdField->isEnabled()) {
_pwdField->setDisabled(false);
_codeField->setDisabled(false);
activate();
}
}
}
if (!sentRequest && status == MTP::RequestSent) {
if (!_sentRequest && status == MTP::RequestSent) {
stopCheck();
}
}
void IntroPwdCheck::pwdSubmitDone(bool recover, const MTPauth_Authorization &result) {
sentRequest = 0;
_sentRequest = 0;
stopCheck();
if (recover) {
cSetPasswordRecovered(true);
}
_pwdField.setDisabled(false);
_codeField.setDisabled(false);
_pwdField->setDisabled(false);
_codeField->setDisabled(false);
const auto &d(result.c_auth_authorization());
if (d.vuser.type() != mtpc_user || !d.vuser.c_user().is_self()) { // wtf?
showError(lang(lng_server_error));
@@ -193,25 +193,25 @@ void IntroPwdCheck::pwdSubmitDone(bool recover, const MTPauth_Authorization &res
bool IntroPwdCheck::pwdSubmitFail(const RPCError &error) {
if (MTP::isFloodError(error)) {
sentRequest = 0;
_sentRequest = 0;
stopCheck();
_codeField.setDisabled(false);
_codeField->setDisabled(false);
showError(lang(lng_flood_error));
_pwdField.setDisabled(false);
_pwdField.notaBene();
_pwdField->setDisabled(false);
_pwdField->notaBene();
return true;
}
if (MTP::isDefaultHandledError(error)) return false;
sentRequest = 0;
_sentRequest = 0;
stopCheck();
_pwdField.setDisabled(false);
_codeField.setDisabled(false);
_pwdField->setDisabled(false);
_codeField->setDisabled(false);
const QString &err = error.type();
if (err == qstr("PASSWORD_HASH_INVALID")) {
showError(lang(lng_signin_bad_password));
_pwdField.selectAll();
_pwdField.notaBene();
_pwdField->selectAll();
_pwdField->notaBene();
return true;
} else if (err == qstr("PASSWORD_EMPTY")) {
intro()->onBack();
@@ -221,22 +221,22 @@ bool IntroPwdCheck::pwdSubmitFail(const RPCError &error) {
} else {
showError(lang(lng_server_error));
}
_pwdField.setFocus();
_pwdField->setFocus();
return false;
}
bool IntroPwdCheck::codeSubmitFail(const RPCError &error) {
if (MTP::isFloodError(error)) {
showError(lang(lng_flood_error));
_codeField.notaBene();
_codeField->notaBene();
return true;
}
if (MTP::isDefaultHandledError(error)) return false;
sentRequest = 0;
_sentRequest = 0;
stopCheck();
_pwdField.setDisabled(false);
_codeField.setDisabled(false);
_pwdField->setDisabled(false);
_codeField->setDisabled(false);
const QString &err = error.type();
if (err == qstr("PASSWORD_EMPTY")) {
intro()->onBack();
@@ -250,8 +250,8 @@ bool IntroPwdCheck::codeSubmitFail(const RPCError &error) {
return true;
} else if (err == qstr("CODE_INVALID")) {
showError(lang(lng_signin_wrong_code));
_codeField.selectAll();
_codeField.notaBene();
_codeField->selectAll();
_codeField->notaBene();
return true;
}
if (cDebug()) { // internal server error
@@ -259,22 +259,22 @@ bool IntroPwdCheck::codeSubmitFail(const RPCError &error) {
} else {
showError(lang(lng_server_error));
}
_codeField.setFocus();
_codeField->setFocus();
return false;
}
void IntroPwdCheck::recoverStarted(const MTPauth_PasswordRecovery &result) {
_emailPattern = st::introFont->elided(lng_signin_recover_hint(lt_recover_email, qs(result.c_auth_passwordRecovery().vemail_pattern)), textRect.width());
_emailPattern = st::introFont->elided(lng_signin_recover_hint(lt_recover_email, qs(result.c_auth_passwordRecovery().vemail_pattern)), _textRect.width());
update();
}
bool IntroPwdCheck::recoverStartFail(const RPCError &error) {
stopCheck();
_pwdField.setDisabled(false);
_codeField.setDisabled(false);
_pwdField.show();
_codeField.hide();
_pwdField.setFocus();
_pwdField->setDisabled(false);
_codeField->setDisabled(false);
_pwdField->show();
_codeField->hide();
_pwdField->setFocus();
update();
showError(QString());
return true;
@@ -282,17 +282,16 @@ bool IntroPwdCheck::recoverStartFail(const RPCError &error) {
void IntroPwdCheck::onToRecover() {
if (_hasRecovery) {
if (sentRequest) {
MTP::cancel(sentRequest);
sentRequest = 0;
if (_sentRequest) {
MTP::cancel(base::take(_sentRequest));
}
showError(QString());
_toRecover.hide();
_toPassword.show();
_pwdField.hide();
_pwdField.setText(QString());
_codeField.show();
_codeField.setFocus();
_toRecover->hide();
_toPassword->show();
_pwdField->hide();
_pwdField->setText(QString());
_codeField->show();
_codeField->setFocus();
if (_emailPattern.isEmpty()) {
MTP::send(MTPauth_RequestPasswordRecovery(), rpcDone(&IntroPwdCheck::recoverStarted), rpcFail(&IntroPwdCheck::recoverStartFail));
}
@@ -311,36 +310,35 @@ void IntroPwdCheck::onToPassword() {
}
void IntroPwdCheck::onToReset() {
if (sentRequest) {
MTP::cancel(sentRequest);
sentRequest = 0;
if (_sentRequest) {
MTP::cancel(base::take(_sentRequest));
}
_toRecover.show();
_toPassword.hide();
_pwdField.show();
_codeField.hide();
_codeField.setText(QString());
_pwdField.setFocus();
_reset.show();
_toRecover->show();
_toPassword->hide();
_pwdField->show();
_codeField->hide();
_codeField->setText(QString());
_pwdField->setFocus();
_reset->show();
update();
}
void IntroPwdCheck::onReset() {
if (sentRequest) return;
if (_sentRequest) return;
ConfirmBox *box = new ConfirmBox(lang(lng_signin_sure_reset), lang(lng_signin_reset), st::attentionBoxButton);
connect(box, SIGNAL(confirmed()), this, SLOT(onResetSure()));
Ui::showLayer(box);
}
void IntroPwdCheck::onResetSure() {
if (sentRequest) return;
sentRequest = MTP::send(MTPaccount_DeleteAccount(MTP_string("Forgot password")), rpcDone(&IntroPwdCheck::deleteDone), rpcFail(&IntroPwdCheck::deleteFail));
if (_sentRequest) return;
_sentRequest = MTP::send(MTPaccount_DeleteAccount(MTP_string("Forgot password")), rpcDone(&IntroPwdCheck::deleteDone), rpcFail(&IntroPwdCheck::deleteFail));
}
bool IntroPwdCheck::deleteFail(const RPCError &error) {
if (MTP::isDefaultHandledError(error)) return false;
sentRequest = 0;
_sentRequest = 0;
auto type = error.type();
if (type.startsWith(qstr("2FA_CONFIRM_WAIT_"))) {
@@ -376,27 +374,27 @@ void IntroPwdCheck::onInputChange() {
}
void IntroPwdCheck::onSubmitPwd(bool force) {
if (sentRequest) return;
if (_pwdField.isHidden()) {
if (!force && !_codeField.isEnabled()) return;
QString code = _codeField.text().trimmed();
if (_sentRequest) return;
if (_pwdField->isHidden()) {
if (!force && !_codeField->isEnabled()) return;
QString code = _codeField->text().trimmed();
if (code.isEmpty()) {
_codeField.notaBene();
_codeField->notaBene();
return;
}
sentRequest = MTP::send(MTPauth_RecoverPassword(MTP_string(code)), rpcDone(&IntroPwdCheck::pwdSubmitDone, true), rpcFail(&IntroPwdCheck::codeSubmitFail));
_sentRequest = MTP::send(MTPauth_RecoverPassword(MTP_string(code)), rpcDone(&IntroPwdCheck::pwdSubmitDone, true), rpcFail(&IntroPwdCheck::codeSubmitFail));
} else {
if (!force && !_pwdField.isEnabled()) return;
if (!force && !_pwdField->isEnabled()) return;
_pwdField.setDisabled(true);
_pwdField->setDisabled(true);
setFocus();
showError(QString());
QByteArray pwdData = _salt + _pwdField.text().toUtf8() + _salt, pwdHash(32, Qt::Uninitialized);
QByteArray pwdData = _salt + _pwdField->text().toUtf8() + _salt, pwdHash(32, Qt::Uninitialized);
hashSha256(pwdData.constData(), pwdData.size(), pwdHash.data());
sentRequest = MTP::send(MTPauth_CheckPassword(MTP_bytes(pwdHash)), rpcDone(&IntroPwdCheck::pwdSubmitDone, false), rpcFail(&IntroPwdCheck::pwdSubmitFail));
_sentRequest = MTP::send(MTPauth_CheckPassword(MTP_bytes(pwdHash)), rpcDone(&IntroPwdCheck::pwdSubmitDone, false), rpcFail(&IntroPwdCheck::pwdSubmitFail));
}
}

View File

@@ -20,16 +20,17 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
*/
#pragma once
#include <QtWidgets/QWidget>
#include "ui/flatbutton.h"
#include "ui/flatinput.h"
#include "intro/introwidget.h"
namespace Ui {
class RoundButton;
} // namespace Ui
class IntroPwdCheck final : public IntroStep {
Q_OBJECT
public:
IntroPwdCheck(IntroWidget *parent);
void paintEvent(QPaintEvent *e) override;
@@ -49,7 +50,6 @@ public:
void recoverStarted(const MTPauth_PasswordRecovery &result);
public slots:
void onSubmitPwd(bool force = false);
void onToRecover();
void onToPassword();
@@ -60,32 +60,35 @@ public slots:
void onResetSure();
private:
void showError(const QString &err);
void showError(const QString &error);
void stopCheck();
void deleteDone(const MTPBool &result);
bool deleteFail(const RPCError &error);
QString error;
QString _error;
anim::fvalue a_errorAlpha;
Animation _a_error;
FlatButton _next;
ChildWidget<Ui::RoundButton> _next;
QRect textRect;
QRect _textRect;
QByteArray _salt;
bool _hasRecovery;
QString _hint, _emailPattern;
FlatInput _pwdField, _codeField;
LinkButton _toRecover, _toPassword, _reset;
mtpRequestId sentRequest;
ChildWidget<FlatInput> _pwdField;
ChildWidget<FlatInput> _codeField;
ChildWidget<LinkButton> _toRecover;
ChildWidget<LinkButton> _toPassword;
ChildWidget<LinkButton> _reset;
mtpRequestId _sentRequest = 0;
Text _hintText;
QByteArray _pwdSalt;
QTimer checkRequest;
ChildObject<QTimer> _checkRequest;
};

View File

@@ -27,25 +27,27 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "boxes/photocropbox.h"
#include "lang.h"
#include "application.h"
#include "ui/buttons/round_button.h"
IntroSignup::IntroSignup(IntroWidget *parent) : IntroStep(parent)
, a_errorAlpha(0)
, a_photoOver(0)
, _a_error(animation(this, &IntroSignup::step_error))
, _a_photo(animation(this, &IntroSignup::step_photo))
, next(this, lang(lng_intro_finish), st::introNextButton)
, first(this, st::inpIntroName, lang(lng_signup_firstname))
, last(this, st::inpIntroName, lang(lng_signup_lastname))
, sentRequest(0)
, _invertOrder(langFirstNameGoesSecond()) {
, _next(this, lang(lng_intro_finish), st::introNextButton)
, _first(this, st::inpIntroName, lang(lng_signup_firstname))
, _last(this, st::inpIntroName, lang(lng_signup_lastname))
, _invertOrder(langFirstNameGoesSecond())
, _checkRequest(this) {
setVisible(false);
setGeometry(parent->innerRect());
connect(&next, SIGNAL(clicked()), this, SLOT(onSubmitName()));
connect(&checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest()));
_next->setTextTransform(Ui::RoundButton::TextTransform::ToUpper);
connect(_next, SIGNAL(clicked()), this, SLOT(onSubmitName()));
connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest()));
if (_invertOrder) {
setTabOrder(&last, &first);
setTabOrder(_last, _first);
}
setMouseTracking(true);
@@ -102,20 +104,20 @@ void IntroSignup::paintEvent(QPaintEvent *e) {
if (!trivial) {
p.setClipRect(e->rect());
}
if (trivial || e->rect().intersects(textRect)) {
if (trivial || e->rect().intersects(_textRect)) {
p.setFont(st::introHeaderFont->f);
p.drawText(textRect, lang(lng_signup_title), style::al_top);
p.drawText(_textRect, lang(lng_signup_title), style::al_top);
p.setFont(st::introFont->f);
p.drawText(textRect, lang(lng_signup_desc), style::al_bottom);
p.drawText(_textRect, lang(lng_signup_desc), style::al_bottom);
}
if (_a_error.animating() || error.length()) {
p.setOpacity(a_errorAlpha.current());
QRect errRect;
if (_invertOrder) {
errRect = QRect((width() - st::introErrorWidth) / 2, (first.y() + first.height() + next.y() - st::introErrorHeight) / 2, st::introErrorWidth, st::introErrorHeight);
errRect = QRect((width() - st::introErrorWidth) / 2, (_first->y() + _first->height() + _next->y() - st::introErrorHeight) / 2, st::introErrorWidth, st::introErrorHeight);
} else {
errRect = QRect((width() - st::introErrorWidth) / 2, (last.y() + last.height() + next.y() - st::introErrorHeight) / 2, st::introErrorWidth, st::introErrorHeight);
errRect = QRect((width() - st::introErrorWidth) / 2, (_last->y() + _last->height() + _next->y() - st::introErrorHeight) / 2, st::introErrorWidth, st::introErrorHeight);
}
p.setFont(st::introErrorFont);
p.setPen(st::introErrorFg);
@@ -147,19 +149,19 @@ void IntroSignup::paintEvent(QPaintEvent *e) {
}
void IntroSignup::resizeEvent(QResizeEvent *e) {
_phLeft = (width() - next.width()) / 2;
_phLeft = (width() - _next->width()) / 2;
_phTop = st::introTextTop + st::introTextSize.height() + st::introCountry.top;
if (e->oldSize().width() != width()) {
next.move((width() - next.width()) / 2, st::introBtnTop);
_next->move((width() - _next->width()) / 2, st::introBtnTop);
if (_invertOrder) {
last.move((width() - next.width()) / 2 + next.width() - last.width(), _phTop);
first.move((width() - next.width()) / 2 + next.width() - first.width(), last.y() + st::introCountry.height + st::introCountry.ptrSize.height() + st::introPhoneTop);
_last->move((width() - _next->width()) / 2 + _next->width() - _last->width(), _phTop);
_first->move((width() - _next->width()) / 2 + _next->width() - _first->width(), _last->y() + st::introCountry.height + st::introCountry.ptrSize.height() + st::introPhoneTop);
} else {
first.move((width() - next.width()) / 2 + next.width() - first.width(), _phTop);
last.move((width() - next.width()) / 2 + next.width() - last.width(), first.y() + st::introCountry.height + st::introCountry.ptrSize.height() + st::introPhoneTop);
_first->move((width() - _next->width()) / 2 + _next->width() - _first->width(), _phTop);
_last->move((width() - _next->width()) / 2 + _next->width() - _last->width(), _first->y() + st::introCountry.height + st::introCountry.ptrSize.height() + st::introPhoneTop);
}
}
textRect = QRect((width() - st::introTextSize.width()) / 2, st::introTextTop, st::introTextSize.width(), st::introTextSize.height());
_textRect = QRect((width() - st::introTextSize.width()) / 2, st::introTextTop, st::introTextSize.width(), st::introTextSize.height());
}
void IntroSignup::showError(const QString &err) {
@@ -204,42 +206,40 @@ void IntroSignup::step_photo(float64 ms, bool timer) {
void IntroSignup::activate() {
IntroStep::activate();
if (_invertOrder) {
last.setFocus();
_last->setFocus();
} else {
first.setFocus();
_first->setFocus();
}
}
void IntroSignup::cancelled() {
if (sentRequest) {
MTP::cancel(sentRequest);
sentRequest = 0;
if (_sentRequest) {
MTP::cancel(base::take(_sentRequest));
}
}
void IntroSignup::stopCheck() {
checkRequest.stop();
_checkRequest->stop();
}
void IntroSignup::onCheckRequest() {
int32 status = MTP::state(sentRequest);
int32 status = MTP::state(_sentRequest);
if (status < 0) {
int32 leftms = -status;
if (leftms >= 1000) {
MTP::cancel(sentRequest);
sentRequest = 0;
if (!first.isEnabled()) {
first.setDisabled(false);
last.setDisabled(false);
MTP::cancel(base::take(_sentRequest));
if (!_first->isEnabled()) {
_first->setDisabled(false);
_last->setDisabled(false);
if (_invertOrder) {
first.setFocus();
_first->setFocus();
} else {
last.setFocus();
_last->setFocus();
}
}
}
}
if (!sentRequest && status == MTP::RequestSent) {
if (!_sentRequest && status == MTP::RequestSent) {
stopCheck();
}
}
@@ -252,8 +252,8 @@ void IntroSignup::onPhotoReady(const QImage &img) {
void IntroSignup::nameSubmitDone(const MTPauth_Authorization &result) {
stopCheck();
first.setDisabled(false);
last.setDisabled(false);
_first->setDisabled(false);
_last->setDisabled(false);
const auto &d(result.c_auth_authorization());
if (d.vuser.type() != mtpc_user || !d.vuser.c_user().is_self()) { // wtf?
showError(lang(lng_server_error));
@@ -265,21 +265,21 @@ void IntroSignup::nameSubmitDone(const MTPauth_Authorization &result) {
bool IntroSignup::nameSubmitFail(const RPCError &error) {
if (MTP::isFloodError(error)) {
stopCheck();
first.setDisabled(false);
last.setDisabled(false);
_first->setDisabled(false);
_last->setDisabled(false);
showError(lang(lng_flood_error));
if (_invertOrder) {
first.setFocus();
_first->setFocus();
} else {
last.setFocus();
_last->setFocus();
}
return true;
}
if (MTP::isDefaultHandledError(error)) return false;
stopCheck();
first.setDisabled(false);
last.setDisabled(false);
_first->setDisabled(false);
_last->setDisabled(false);
const QString &err = error.type();
if (err == qstr("PHONE_NUMBER_INVALID") || err == qstr("PHONE_CODE_EXPIRED") ||
err == qstr("PHONE_CODE_EMPTY") || err == qstr("PHONE_CODE_INVALID") ||
@@ -288,11 +288,11 @@ bool IntroSignup::nameSubmitFail(const RPCError &error) {
return true;
} else if (err == "FIRSTNAME_INVALID") {
showError(lang(lng_bad_name));
first.setFocus();
_first->setFocus();
return true;
} else if (err == "LASTNAME_INVALID") {
showError(lang(lng_bad_name));
last.setFocus();
_last->setFocus();
return true;
}
if (cDebug()) { // internal server error
@@ -301,9 +301,9 @@ bool IntroSignup::nameSubmitFail(const RPCError &error) {
showError(lang(lng_server_error));
}
if (_invertOrder) {
last.setFocus();
_last->setFocus();
} else {
first.setFocus();
_first->setFocus();
}
return false;
}
@@ -314,33 +314,33 @@ void IntroSignup::onInputChange() {
void IntroSignup::onSubmitName(bool force) {
if (_invertOrder) {
if ((last.hasFocus() || last.text().trimmed().length()) && !first.text().trimmed().length()) {
first.setFocus();
if ((_last->hasFocus() || _last->text().trimmed().length()) && !_first->text().trimmed().length()) {
_first->setFocus();
return;
} else if (!last.text().trimmed().length()) {
last.setFocus();
} else if (!_last->text().trimmed().length()) {
_last->setFocus();
return;
}
} else {
if ((first.hasFocus() || first.text().trimmed().length()) && !last.text().trimmed().length()) {
last.setFocus();
if ((_first->hasFocus() || _first->text().trimmed().length()) && !_last->text().trimmed().length()) {
_last->setFocus();
return;
} else if (!first.text().trimmed().length()) {
first.setFocus();
} else if (!_first->text().trimmed().length()) {
_first->setFocus();
return;
}
}
if (!force && !first.isEnabled()) return;
if (!force && !_first->isEnabled()) return;
first.setDisabled(true);
last.setDisabled(true);
_first->setDisabled(true);
_last->setDisabled(true);
setFocus();
showError(QString());
firstName = first.text().trimmed();
lastName = last.text().trimmed();
sentRequest = MTP::send(MTPauth_SignUp(MTP_string(intro()->getPhone()), MTP_string(intro()->getPhoneHash()), MTP_string(intro()->getCode()), MTP_string(firstName), MTP_string(lastName)), rpcDone(&IntroSignup::nameSubmitDone), rpcFail(&IntroSignup::nameSubmitFail));
_firstName = _first->text().trimmed();
_lastName = _last->text().trimmed();
_sentRequest = MTP::send(MTPauth_SignUp(MTP_string(intro()->getPhone()), MTP_string(intro()->getPhoneHash()), MTP_string(intro()->getCode()), MTP_string(_firstName), MTP_string(_lastName)), rpcDone(&IntroSignup::nameSubmitDone), rpcFail(&IntroSignup::nameSubmitFail));
}
void IntroSignup::onSubmit() {

View File

@@ -20,16 +20,18 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
*/
#pragma once
#include <QtWidgets/QWidget>
#include "ui/flatbutton.h"
#include "ui/flatinput.h"
#include "intro/introwidget.h"
namespace Ui {
class RoundButton;
} // namespace Ui
class IntroSignup final : public IntroStep {
Q_OBJECT
public:
IntroSignup(IntroWidget *parent);
void paintEvent(QPaintEvent *e) override;
@@ -48,14 +50,12 @@ public:
bool nameSubmitFail(const RPCError &error);
public slots:
void onSubmitName(bool force = false);
void onInputChange();
void onCheckRequest();
void onPhotoReady(const QImage &img);
private:
void showError(const QString &err);
void stopCheck();
@@ -64,20 +64,22 @@ private:
Animation _a_error;
Animation _a_photo;
FlatButton next;
ChildWidget<Ui::RoundButton> _next;
QRect textRect;
QRect _textRect;
bool _photoOver;
bool _photoOver = false;
QImage _photoBig;
QPixmap _photoSmall;
int32 _phLeft, _phTop;
FlatInput first, last;
QString firstName, lastName;
mtpRequestId sentRequest;
ChildWidget<FlatInput> _first;
ChildWidget<FlatInput> _last;
QString _firstName, _lastName;
mtpRequestId _sentRequest = 0;
bool _invertOrder;
bool _invertOrder = false;
ChildObject<QTimer> _checkRequest;
QTimer checkRequest;
};

View File

@@ -25,36 +25,38 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "application.h"
#include "intro/introphone.h"
#include "langloaderplain.h"
#include "ui/buttons/round_button.h"
IntroStart::IntroStart(IntroWidget *parent) : IntroStep(parent)
, _intro(this, lang(lng_intro), FlatLabel::InitType::Rich, st::introLabel, st::introLabelTextStyle)
, _changeLang(this, QString())
, _next(this, lang(lng_start_msgs), st::introNextButton) {
_changeLang.hide();
_changeLang->hide();
if (cLang() == languageDefault) {
int32 l = Sandbox::LangSystem();
if (l != languageDefault) {
LangLoaderPlain loader(qsl(":/langs/lang_") + LanguageCodes[l].c_str() + qsl(".strings"), langLoaderRequest(lng_switch_to_this));
QString text = loader.found().value(lng_switch_to_this);
if (!text.isEmpty()) {
_changeLang.setText(text);
_changeLang->setText(text);
parent->langChangeTo(l);
_changeLang.show();
_changeLang->show();
}
}
} else {
_changeLang.setText(langOriginal(lng_switch_to_this));
_changeLang->setText(langOriginal(lng_switch_to_this));
parent->langChangeTo(languageDefault);
_changeLang.show();
_changeLang->show();
}
_headerWidth = st::introHeaderFont->width(qsl("Telegram Desktop"));
setGeometry(parent->innerRect());
connect(&_next, SIGNAL(clicked()), parent, SLOT(onStepSubmit()));
_next->setTextTransform(Ui::RoundButton::TextTransform::ToUpper);
connect(_next, SIGNAL(clicked()), parent, SLOT(onStepSubmit()));
connect(&_changeLang, SIGNAL(clicked()), parent, SLOT(onChangeLang()));
connect(_changeLang, SIGNAL(clicked()), parent, SLOT(onChangeLang()));
setMouseTracking(true);
}
@@ -66,7 +68,7 @@ void IntroStart::paintEvent(QPaintEvent *e) {
if (!trivial) {
p.setClipRect(e->rect());
}
int32 hy = _intro.y() - st::introHeaderFont->height - st::introHeaderSkip + st::introHeaderFont->ascent;
int32 hy = _intro->y() - st::introHeaderFont->height - st::introHeaderSkip + st::introHeaderFont->ascent;
p.setFont(st::introHeaderFont);
p.setPen(st::introHeaderFg);
@@ -77,9 +79,9 @@ void IntroStart::paintEvent(QPaintEvent *e) {
void IntroStart::resizeEvent(QResizeEvent *e) {
if (e->oldSize().width() != width()) {
_next.move((width() - _next.width()) / 2, st::introBtnTop);
_intro.move((width() - _intro.width()) / 2, _next.y() - _intro.height() - st::introSkip);
_changeLang.move((width() - _changeLang.width()) / 2, _next.y() + _next.height() + _changeLang.height());
_next->move((width() - _next->width()) / 2, st::introBtnTop);
_intro->move((width() - _intro->width()) / 2, _next->y() - _intro->height() - st::introSkip);
_changeLang->move((width() - _changeLang->width()) / 2, _next->y() + _next->height() + _changeLang->height());
}
}

View File

@@ -23,9 +23,12 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "intro/introwidget.h"
#include "ui/flatlabel.h"
namespace Ui {
class RoundButton;
} // namespace Ui
class IntroStart final : public IntroStep {
public:
IntroStart(IntroWidget *parent);
void paintEvent(QPaintEvent *e) override;
@@ -34,11 +37,12 @@ public:
void onSubmit() override;
private:
ChildWidget<FlatLabel> _intro;
FlatLabel _intro;
ChildWidget<LinkButton> _changeLang;
LinkButton _changeLang;
ChildWidget<Ui::RoundButton> _next;
int32 _headerWidth = 0;
FlatButton _next;
int32 _headerWidth;
};

View File

@@ -338,7 +338,7 @@ void IntroWidget::resizeEvent(QResizeEvent *e) {
}
void IntroWidget::finish(const MTPUser &user, const QImage &photo) {
App::wnd()->setupMain(true, &user);
App::wnd()->setupMain(&user);
if (!photo.isNull()) {
App::app()->uploadProfilePhoto(photo, MTP::authedId());
}