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

@ -33,9 +33,6 @@ imageBg: #000000;
imageBgTransparent: #ffffff;
// widgets
cancelIconFg: #a2a2a2;
cancelIconFgOver: #808080;
activeButtonBg: windowActiveFill;
activeButtonBgOver: #46b4eb | activeButtonBg;
activeButtonFg: #ffffff;
@ -48,7 +45,9 @@ lightButtonBgOver: #f2f7fa | lightButtonBg;
lightButtonFg: #2b99d5;
lightButtonFgOver: lightButtonFg;
menuIconFg: #808080 | windowSubTextFg;
menuIconFg: windowSubTextFg;
dialogsMenuIconFg: menuIconFg;
// custom title bar for Windows
titleBg: windowOverBg;
@ -69,6 +68,9 @@ trayCounterFgMacInvert: #ffffff01;
// layers
layerBg: #0000007f;
cancelIconFg: #a2a2a2;
cancelIconFgOver: #808080;
// boxes
boxBg: windowBg;
boxTextFg: windowTextFg;

Binary file not shown.

After

Width:  |  Height:  |  Size: 285 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 408 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 430 B

View File

@ -31,8 +31,6 @@ windowActiveTextFg: #1485c2;
windowShadowFg: #000000;
imageBg: #000000;
imageBgTransparent: #ffffff;
cancelIconFg: #a2a2a2;
cancelIconFgOver: #808080;
activeButtonBg: windowActiveFill;
activeButtonBgOver: #46b4eb; // activeButtonBg;
activeButtonFg: #ffffff;
@ -43,7 +41,8 @@ lightButtonBg: windowBg;
lightButtonBgOver: #f2f7fa; // lightButtonBg;
lightButtonFg: #2b99d5;
lightButtonFgOver: lightButtonFg;
menuIconFg: #808080; // windowSubTextFg;
menuIconFg: windowSubTextFg;
dialogsMenuIconFg: menuIconFg;
titleBg: windowOverBg;
titleShadow: #00000003;
titleButtonFg: #ababab;
@ -57,6 +56,8 @@ trayCounterFg: #ffffff;
trayCounterBgMacInvert: #ffffff;
trayCounterFgMacInvert: #ffffff01;
layerBg: #0000007f;
cancelIconFg: #a2a2a2;
cancelIconFgOver: #808080;
boxBg: windowBg;
boxTextFg: windowTextFg;
boxTextFgGood: #4ab44a;

View File

@ -34,9 +34,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
ApiWrap::ApiWrap(QObject *parent) : QObject(parent)
, _messageDataResolveDelayed(new SingleDelayedCall(this, "resolveMessageDatas")) {
if (!Local::readBackground()) {
Window::Theme::Background()->start();
}
Window::Theme::Background()->start();
connect(&_webPagesTimer, SIGNAL(timeout()), this, SLOT(resolveWebPages()));
connect(&_draftsSaveTimer, SIGNAL(timeout()), this, SLOT(saveDraftsToCloud()));

View File

@ -199,7 +199,7 @@ namespace {
if (auto w = wnd()) {
w->tempDirDelete(Local::ClearManagerAll);
w->notifyClearFast();
w->setupIntro(true);
w->setupIntro();
}
MTP::setAuthedId(0);
Local::reset();

View File

@ -750,12 +750,12 @@ AppClass::AppClass() : QObject() {
DEBUG_LOG(("Application Info: showing."));
if (state == Local::ReadMapPassNeeded) {
_window->setupPasscode(false);
_window->setupPasscode();
} else {
if (MTP::authedId()) {
_window->setupMain(false);
_window->setupMain();
} else {
_window->setupIntro(false);
_window->setupIntro();
}
}
_window->firstShow();

View File

@ -246,13 +246,8 @@ passcodeHeaderFont: font(19px);
passcodeHeaderHeight: 80px;
passcodeInput: flatInput(inpIntroPhone) {
}
passcodeSubmit: flatButton(introNextButton) {
textTop: 15px;
overTextTop: 15px;
downTextTop: 16px;
passcodeSubmit: RoundButton(introNextButton) {
width: 225px;
font: font(19px);
overFont: font(19px);
}
passcodeSubmitSkip: 40px;
passcodePadding: margins(0px, 22px, 0px, 3px);

View File

@ -35,8 +35,8 @@ struct Draft {
, previewCancelled(previewCancelled)
, saveRequestId(saveRequestId) {
}
Draft(const FlatTextarea &field, MsgId msgId, bool previewCancelled, mtpRequestId saveRequestId = 0)
: textWithTags(field.getTextWithTags())
Draft(const FlatTextarea *field, MsgId msgId, bool previewCancelled, mtpRequestId saveRequestId = 0)
: textWithTags(field->getTextWithTags())
, msgId(msgId)
, cursor(field)
, previewCancelled(previewCancelled) {

View File

@ -87,10 +87,15 @@ dialogsMenuToggle: IconButton {
width: 32px;
height: 32px;
icon: icon {{ "dialogs_menu", #999999 }};
icon: icon {{ "dialogs_menu", dialogsMenuIconFg }};
iconPosition: point(6px, 6px);
iconPositionDown: point(6px, 6px);
}
dialogsLock: IconButton(dialogsMenuToggle) {
icon: icon {{ "dialogs_lock", dialogsMenuIconFg }};
}
dialogsUnlockIcon: icon {{ "dialogs_unlock", dialogsMenuIconFg }};
dialogsFilter: flatInput(inpDefGray) {
font: font(fsize);
bgColor: #f2f2f2;

View File

@ -1028,10 +1028,6 @@ void DialogsInner::dialogsReceived(const QVector<MTPDialog> &added) {
}
}
Notify::unreadCounterUpdated();
if (!_sel && !shownDialogs()->isEmpty()) {
_sel = *shownDialogs()->cbegin();
_importantSwitchSel = false;
}
refresh();
}
@ -1776,6 +1772,7 @@ DialogsWidget::DialogsWidget(QWidget *parent) : TWidget(parent)
, _mainMenuToggle(this, st::dialogsMenuToggle)
, _filter(this, st::dialogsFilter, lang(lng_dlg_filter))
, _cancelSearch(this, st::dialogsCancelSearch)
, _lockUnlock(this, st::dialogsLock)
, _scroll(this, st::dialogsScroll)
, _inner(&_scroll, parent)
, _a_show(animation(this, &DialogsWidget::step_show)) {
@ -1793,8 +1790,15 @@ DialogsWidget::DialogsWidget(QWidget *parent) : TWidget(parent)
connect(_filter, SIGNAL(cancelled()), this, SLOT(onCancel()));
connect(_filter, SIGNAL(changed()), this, SLOT(onFilterUpdate()));
connect(_filter, SIGNAL(cursorPositionChanged(int,int)), this, SLOT(onFilterCursorMoved(int,int)));
connect(_cancelSearch, SIGNAL(clicked()), this, SLOT(onCancelSearch()));
_cancelSearch->setClickedCallback([this] { onCancelSearch(); });
_lockUnlock->setVisible(Global::LocalPasscode());
subscribe(Global::RefLocalPasscodeChanged(), [this] { updateLockUnlockVisibility(); });
_lockUnlock->setClickedCallback([this] {
_lockUnlock->setIcon(&st::dialogsUnlockIcon);
App::wnd()->setupPasscode();
_lockUnlock->setIcon(nullptr);
});
_mainMenuToggle->setClickedCallback([this] { showMainMenu(); });
_chooseByDragTimer.setSingleShot(true);
@ -1851,8 +1855,10 @@ void DialogsWidget::showAnimated(Window::SlideDirection direction, const Window:
_a_show.stop();
_scroll.hide();
_mainMenuToggle->hide();
_filter->hide();
_cancelSearch->hide();
_lockUnlock->hide();
int delta = st::slideShift;
if (direction == Window::SlideDirection::FromLeft) {
@ -1880,7 +1886,9 @@ void DialogsWidget::step_show(float64 ms, bool timer) {
_cacheUnder = _cacheOver = QPixmap();
_scroll.show();
_mainMenuToggle->show();
_filter->show();
updateLockUnlockVisibility();
_a_show.stop();
onFilterUpdate();
@ -2440,17 +2448,15 @@ void DialogsWidget::onCompleteHashtag(QString tag) {
}
void DialogsWidget::resizeEvent(QResizeEvent *e) {
int32 w = width();
_filter->setGeometryToLeft(st::dialogsFilterPadding.x() * 2 + _mainMenuToggle->width(), st::dialogsFilterPadding.y(), w - 3 * st::dialogsFilterPadding.x() - _mainMenuToggle->width(), _filter->height());
_mainMenuToggle->moveToLeft(st::dialogsFilterPadding.x(), _filter->y());
_cancelSearch->moveToRight(st::dialogsFilterPadding.x(), _filter->y());
updateControlsGeometry();
_scroll.move(0, _filter->height() + 2 * st::dialogsFilterPadding.y());
updateMainMenuGeometry();
int32 addToY = App::main() ? App::main()->contentScrollAddToY() : 0;
int32 newScrollY = _scroll.scrollTop() + addToY;
_scroll.resize(w, height() - _filter->y() - _filter->height() - st::dialogsFilterPadding.y() - st::dialogsPadding.y());
_scroll.resize(width(), height() - _filter->y() - _filter->height() - st::dialogsFilterPadding.y() - st::dialogsPadding.y());
if (addToY) {
_scroll.scrollToY(newScrollY);
} else {
@ -2458,6 +2464,26 @@ void DialogsWidget::resizeEvent(QResizeEvent *e) {
}
}
void DialogsWidget::updateLockUnlockVisibility() {
if (!_a_show.animating()) {
_lockUnlock->setVisible(Global::LocalPasscode());
}
updateControlsGeometry();
}
void DialogsWidget::updateControlsGeometry() {
auto filterLeft = st::dialogsFilterPadding.x() * 2 + _mainMenuToggle->width();
auto filterWidth = width() - 2 * st::dialogsFilterPadding.x();
filterWidth -= st::dialogsFilterPadding.x() + _mainMenuToggle->width();
if (Global::LocalPasscode()) {
filterWidth -= st::dialogsFilterPadding.x() + _lockUnlock->width();
}
_filter->setGeometryToLeft(filterLeft, st::dialogsFilterPadding.y(), filterWidth, _filter->height());
_mainMenuToggle->moveToLeft(st::dialogsFilterPadding.x(), _filter->y());
_lockUnlock->moveToRight(st::dialogsFilterPadding.x(), _filter->y());
_cancelSearch->moveToLeft(filterLeft + filterWidth - _cancelSearch->width(), _filter->y());
}
void DialogsWidget::updateMainMenuGeometry() {
if (!_mainMenu) return;

View File

@ -233,7 +233,7 @@ private:
};
class DialogsWidget : public TWidget, public RPCSender {
class DialogsWidget : public TWidget, public RPCSender, private base::Subscriber {
Q_OBJECT
public:
@ -315,6 +315,8 @@ public slots:
private:
void showMainMenu();
void updateLockUnlockVisibility();
void updateControlsGeometry();
void updateMainMenuGeometry();
bool _dragInScroll = false;
@ -338,6 +340,7 @@ private:
ChildWidget<Ui::DropdownMenu> _mainMenu = { nullptr };
ChildWidget<FlatInput> _filter;
ChildWidget<Ui::IconButton> _cancelSearch;
ChildWidget<Ui::IconButton> _lockUnlock;
ScrollArea _scroll;
DialogsInner _inner;

File diff suppressed because it is too large Load Diff

View File

@ -351,8 +351,9 @@ protected:
void paintEvent(QPaintEvent *e) override;
private:
FlatButton _report, _hide;
LinkButton _clear;
ChildWidget<FlatButton> _report;
ChildWidget<FlatButton> _hide;
ChildWidget<LinkButton> _clear;
};
@ -489,7 +490,8 @@ private:
QString _shareUrl, _shareText;
QString _botAndQuery;
BoxButton _send, _cancel;
ChildWidget<BoxButton> _send;
ChildWidget<BoxButton> _cancel;
PeerData *_offered = nullptr;
anim::fvalue a_opacity;
@ -1098,7 +1100,11 @@ private:
ReportSpamPanel _reportSpamPanel;
FlatButton _send, _unblock, _botStart, _joinChannel, _muteUnmute;
ChildWidget<FlatButton> _send;
ChildWidget<FlatButton> _unblock;
ChildWidget<FlatButton> _botStart;
ChildWidget<FlatButton> _joinChannel;
ChildWidget<FlatButton> _muteUnmute;
mtpRequestId _unblockRequest = 0;
mtpRequestId _reportSpamRequest = 0;
ChildWidget<Ui::IconButton> _attachDocument;
@ -1109,7 +1115,7 @@ private:
ChildWidget<Ui::IconButton> _botCommandStart;
ChildWidget<SilentToggle> _silent;
bool _cmdStartShown = false;
MessageField _field;
ChildWidget<MessageField> _field;
Animation _a_record, _a_recording;
bool _recording = false;
bool _inRecord = false;

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());
}

View File

@ -255,9 +255,9 @@ void MainWindow::clearPasscode() {
}
}
void MainWindow::setupPasscode(bool anim) {
auto bg = grabInner();
void MainWindow::setupPasscode() {
auto animated = (_main || _intro);
auto bg = animated ? grabInner() : QPixmap();
if (_passcode) {
_passcode->stop_show();
_passcode.destroyDelayed();
@ -270,7 +270,7 @@ void MainWindow::setupPasscode(bool anim) {
_settings.destroyDelayed();
}
if (_intro) _intro->hide();
if (anim) {
if (animated) {
_passcode->animShow(bg);
} else {
setInnerFocus();
@ -294,14 +294,14 @@ void MainWindow::checkAutoLock() {
App::app()->checkLocalTime();
uint64 ms = getms(true), idle = psIdleTime(), should = Global::AutoLock() * 1000ULL;
if (idle >= should || (_shouldLockAt > 0 && ms > _shouldLockAt + 3000ULL)) {
setupPasscode(true);
setupPasscode();
} else {
_shouldLockAt = ms + (should - idle);
_autoLockTimer.start(should - idle);
}
}
void MainWindow::setupIntro(bool anim) {
void MainWindow::setupIntro() {
cSetContactsReceived(false);
cSetDialogsReceived(false);
if (_intro && !_intro->isHidden() && !_main) return;
@ -311,14 +311,17 @@ void MainWindow::setupIntro(bool anim) {
}
Ui::hideSettingsAndLayer(true);
QPixmap bg = anim ? grabInner() : QPixmap();
auto animated = (_main || _passcode);
auto bg = animated ? grabInner() : QPixmap();
clearWidgets();
_intro.create(bodyWidget());
updateControlsGeometry();
if (anim) {
if (animated) {
_intro->animShow(bg);
} else {
setInnerFocus();
}
fixOrder();
@ -361,13 +364,15 @@ void MainWindow::sendServiceHistoryRequest() {
_serviceHistoryRequest = MTP::send(MTPmessages_GetHistory(user->input, MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(1), MTP_int(0), MTP_int(0)), _main->rpcDone(&MainWidget::serviceHistoryDone), _main->rpcFail(&MainWidget::serviceHistoryFail));
}
void MainWindow::setupMain(bool anim, const MTPUser *self) {
QPixmap bg = anim ? grabInner() : QPixmap();
void MainWindow::setupMain(const MTPUser *self) {
auto animated = (_intro || _passcode);
auto bg = animated ? grabInner() : QPixmap();
clearWidgets();
_main.create(bodyWidget());
updateControlsGeometry();
if (anim) {
if (animated) {
_main->animShow(bg);
} else {
_main->activate();

View File

@ -85,11 +85,11 @@ public:
void inactivePress(bool inactive);
bool inactivePress() const;
void setupPasscode(bool anim);
void setupPasscode();
void clearPasscode();
void checkAutoLockIn(int msec);
void setupIntro(bool anim);
void setupMain(bool anim, const MTPUser *user = 0);
void setupIntro();
void setupMain(const MTPUser *user = 0);
void serviceNotification(const QString &msg, const MTPMessageMedia &media = MTP_messageMediaEmpty(), bool force = false);
void sendServiceHistoryRequest();
void showDelayedServiceMsgs();

View File

@ -26,6 +26,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "mainwindow.h"
#include "application.h"
#include "ui/text/text.h"
#include "ui/buttons/round_button.h"
#include "styles/style_boxes.h"
PasscodeWidget::PasscodeWidget(QWidget *parent) : TWidget(parent)
@ -33,32 +34,32 @@ PasscodeWidget::PasscodeWidget(QWidget *parent) : TWidget(parent)
, _passcode(this, st::passcodeInput)
, _submit(this, lang(lng_passcode_submit), st::passcodeSubmit)
, _logout(this, lang(lng_passcode_logout)) {
_passcode.setEchoMode(QLineEdit::Password);
connect(&_submit, SIGNAL(clicked()), this, SLOT(onSubmit()));
_passcode->setEchoMode(QLineEdit::Password);
connect(_passcode, SIGNAL(changed()), this, SLOT(onChanged()));
connect(_passcode, SIGNAL(submitted(bool)), this, SLOT(onSubmit()));
connect(&_passcode, SIGNAL(changed()), this, SLOT(onChanged()));
connect(&_passcode, SIGNAL(submitted(bool)), this, SLOT(onSubmit()));
connect(&_logout, SIGNAL(clicked()), App::wnd(), SLOT(onLogout()));
_submit->setTextTransform(Ui::RoundButton::TextTransform::ToUpper);
_submit->setClickedCallback([this] { onSubmit(); });
_logout->setClickedCallback([] { App::wnd()->onLogout(); });
show();
_passcode.setFocus();
_passcode->setFocus();
}
void PasscodeWidget::onSubmit() {
if (_passcode.text().isEmpty()) {
_passcode.notaBene();
if (_passcode->text().isEmpty()) {
_passcode->notaBene();
return;
}
if (!passcodeCanTry()) {
_error = lang(lng_flood_error);
_passcode.notaBene();
_passcode->notaBene();
update();
return;
}
if (App::main()) {
if (Local::checkPasscode(_passcode.text().toUtf8())) {
if (Local::checkPasscode(_passcode->text().toUtf8())) {
cSetPasscodeBadTries(0);
App::wnd()->clearPasscode();
} else {
@ -68,14 +69,14 @@ void PasscodeWidget::onSubmit() {
return;
}
} else {
if (Local::readMap(_passcode.text().toUtf8()) != Local::ReadMapPassNeeded) {
if (Local::readMap(_passcode->text().toUtf8()) != Local::ReadMapPassNeeded) {
cSetPasscodeBadTries(0);
MTP::start();
if (MTP::authedId()) {
App::wnd()->setupMain(true);
App::wnd()->setupMain();
} else {
App::wnd()->setupIntro(true);
App::wnd()->setupIntro();
}
App::app()->checkMapVersion();
@ -90,8 +91,8 @@ void PasscodeWidget::onSubmit() {
void PasscodeWidget::onError() {
_error = lang(lng_passcode_wrong);
_passcode.selectAll();
_passcode.notaBene();
_passcode->selectAll();
_passcode->notaBene();
update();
}
@ -151,15 +152,15 @@ void PasscodeWidget::stop_show() {
}
void PasscodeWidget::showAll() {
_passcode.show();
_submit.show();
_logout.show();
_passcode->show();
_submit->show();
_logout->show();
}
void PasscodeWidget::hideAll() {
_passcode.hide();
_submit.hide();
_logout.hide();
_passcode->hide();
_submit->hide();
_logout->hide();
}
void PasscodeWidget::paintEvent(QPaintEvent *e) {
@ -186,32 +187,22 @@ void PasscodeWidget::paintEvent(QPaintEvent *e) {
p.setFont(st::passcodeHeaderFont);
p.setPen(st::windowTextFg);
p.drawText(QRect(0, _passcode.y() - st::passcodeHeaderHeight, width(), st::passcodeHeaderHeight), lang(lng_passcode_enter), style::al_center);
p.drawText(QRect(0, _passcode->y() - st::passcodeHeaderHeight, width(), st::passcodeHeaderHeight), lang(lng_passcode_enter), style::al_center);
if (!_error.isEmpty()) {
p.setFont(st::boxTextFont);
p.setPen(st::boxTextFgError);
p.drawText(QRect(0, _passcode.y() + _passcode.height(), width(), st::passcodeSubmitSkip), _error, style::al_center);
p.drawText(QRect(0, _passcode->y() + _passcode->height(), width(), st::passcodeSubmitSkip), _error, style::al_center);
}
}
}
void PasscodeWidget::resizeEvent(QResizeEvent *e) {
_passcode.move((width() - _passcode.width()) / 2, (height() / 3));
_submit.move(_passcode.x(), _passcode.y() + _passcode.height() + st::passcodeSubmitSkip);
_logout.move(_passcode.x() + (_passcode.width() - _logout.width()) / 2, _submit.y() + _submit.height() + st::linkFont->ascent);
}
void PasscodeWidget::mousePressEvent(QMouseEvent *e) {
}
void PasscodeWidget::keyPressEvent(QKeyEvent *e) {
_passcode->move((width() - _passcode->width()) / 2, (height() / 3));
_submit->move(_passcode->x(), _passcode->y() + _passcode->height() + st::passcodeSubmitSkip);
_logout->move(_passcode->x() + (_passcode->width() - _logout->width()) / 2, _submit->y() + _submit->height() + st::linkFont->ascent);
}
void PasscodeWidget::setInnerFocus() {
_passcode.setFocus();
}
PasscodeWidget::~PasscodeWidget() {
_passcode->setFocus();
}

View File

@ -20,6 +20,10 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
*/
#pragma once
namespace Ui {
class RoundButton;
} // namespace Ui
class PasscodeWidget : public TWidget {
Q_OBJECT
@ -32,13 +36,9 @@ public:
void step_show(float64 ms, bool timer);
void stop_show();
~PasscodeWidget();
protected:
void paintEvent(QPaintEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void keyPressEvent(QKeyEvent *e) override;
public slots:
void onError();
@ -54,9 +54,9 @@ private:
anim::ivalue a_coordUnder, a_coordOver;
anim::fvalue a_shadow;
FlatInput _passcode;
FlatButton _submit;
LinkButton _logout;
ChildWidget<FlatInput> _passcode;
ChildWidget<Ui::RoundButton> _submit;
ChildWidget<LinkButton> _logout;
QString _error;
};

View File

@ -38,7 +38,7 @@ bool lock_telegram() {
w->passcodeWidget()->onSubmit();
return true;
} else if (Global::LocalPasscode()) {
w->setupPasscode(true);
w->setupPasscode();
return true;
}
}

View File

@ -1394,29 +1394,32 @@ QString saveFileName(const QString &title, const QString &filter, const QString
MsgId clientMsgId();
struct MessageCursor {
MessageCursor() : position(0), anchor(0), scroll(QFIXED_MAX) {
}
MessageCursor() = default;
MessageCursor(int position, int anchor, int scroll) : position(position), anchor(anchor), scroll(scroll) {
}
MessageCursor(const QTextEdit &edit) {
MessageCursor(const QTextEdit *edit) {
fillFrom(edit);
}
void fillFrom(const QTextEdit &edit) {
QTextCursor c = edit.textCursor();
void fillFrom(const QTextEdit *edit) {
QTextCursor c = edit->textCursor();
position = c.position();
anchor = c.anchor();
QScrollBar *s = edit.verticalScrollBar();
QScrollBar *s = edit->verticalScrollBar();
scroll = (s && (s->value() != s->maximum())) ? s->value() : QFIXED_MAX;
}
void applyTo(QTextEdit &edit) {
QTextCursor c = edit.textCursor();
c.setPosition(anchor, QTextCursor::MoveAnchor);
c.setPosition(position, QTextCursor::KeepAnchor);
edit.setTextCursor(c);
QScrollBar *s = edit.verticalScrollBar();
if (s) s->setValue(scroll);
void applyTo(QTextEdit *edit) {
auto cursor = edit->textCursor();
cursor.setPosition(anchor, QTextCursor::MoveAnchor);
cursor.setPosition(position, QTextCursor::KeepAnchor);
edit->setTextCursor(cursor);
if (auto scrollbar = edit->verticalScrollBar()) {
scrollbar->setValue(scroll);
}
}
int position, anchor, scroll;
int position = 0;
int anchor = 0;
int scroll = QFIXED_MAX;
};
inline bool operator==(const MessageCursor &a, const MessageCursor &b) {

View File

@ -126,12 +126,12 @@ void MainWindow::savePosition(Qt::WindowState state) {
if (state == Qt::WindowActive) state = windowHandle()->windowState();
if (state == Qt::WindowMinimized || !positionInited()) return;
TWindowPos pos(cWindowPos()), curPos = pos;
auto pos = cWindowPos(), curPos = pos;
if (state == Qt::WindowMaximized) {
curPos.maximized = 1;
} else {
QRect r(geometry());
auto r = geometry();
curPos.x = r.x();
curPos.y = r.y();
curPos.w = r.width();

View File

@ -419,7 +419,9 @@ void ChatBackground::setThemeData(QImage &&themeImage, bool themeTile) {
void ChatBackground::start() {
if (_id == internal::kUninitializedBackground) {
setImage(kThemeBackground);
if (!Local::readBackground()) {
setImage(kThemeBackground);
}
}
}