2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2014-12-01 10:47:38 +00:00
|
|
|
Copyright (c) 2014 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "lang.h"
|
|
|
|
#include "style.h"
|
|
|
|
|
2015-03-02 12:34:16 +00:00
|
|
|
#include "localstorage.h"
|
2014-12-19 21:20:30 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "intro/intro.h"
|
|
|
|
#include "intro/introsteps.h"
|
|
|
|
#include "intro/introphone.h"
|
|
|
|
#include "intro/introcode.h"
|
|
|
|
#include "intro/introsignup.h"
|
2015-04-02 10:33:19 +00:00
|
|
|
#include "intro/intropwdcheck.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "mainwidget.h"
|
|
|
|
#include "window.h"
|
|
|
|
#include "application.h"
|
|
|
|
#include "gui/text.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
IntroWidget *signalEmitOn = 0;
|
|
|
|
QString countryForReg;
|
|
|
|
void gotNearestDC(const MTPNearestDc &result) {
|
|
|
|
const MTPDnearestDc &nearest(result.c_nearestDc());
|
|
|
|
DEBUG_LOG(("Got nearest dc, country: %1, nearest: %2, this: %3").arg(nearest.vcountry.c_string().v.c_str()).arg(nearest.vnearest_dc.v).arg(nearest.vthis_dc.v));
|
|
|
|
MTP::setdc(result.c_nearestDc().vnearest_dc.v, true);
|
|
|
|
if (countryForReg != nearest.vcountry.c_string().v.c_str()) {
|
|
|
|
countryForReg = nearest.vcountry.c_string().v.c_str();
|
|
|
|
emit signalEmitOn->countryChanged();
|
|
|
|
}
|
|
|
|
if (App::app()) App::app()->startUpdateCheck();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IntroWidget::IntroWidget(Window *window) : QWidget(window),
|
2014-12-19 21:20:30 +00:00
|
|
|
_langChangeTo(0),
|
2014-11-26 16:45:52 +00:00
|
|
|
cacheForHideInd(0),
|
|
|
|
cacheForShowInd(0),
|
|
|
|
wnd(window),
|
|
|
|
steps(new IntroSteps(this)),
|
|
|
|
phone(0),
|
|
|
|
code(0),
|
|
|
|
signup(0),
|
2015-04-02 10:33:19 +00:00
|
|
|
pwdcheck(0),
|
2014-11-26 16:45:52 +00:00
|
|
|
current(0),
|
|
|
|
moving(0),
|
|
|
|
visibilityChanging(0),
|
|
|
|
_callTimeout(60),
|
2015-04-02 10:33:19 +00:00
|
|
|
_registered(false),
|
|
|
|
_hasRecovery(false),
|
2014-11-26 16:45:52 +00:00
|
|
|
_back(this, st::setClose),
|
|
|
|
_backFrom(0), _backTo(0) {
|
2014-05-30 08:53:19 +00:00
|
|
|
setGeometry(QRect(0, st::titleHeight, wnd->width(), wnd->height() - st::titleHeight));
|
|
|
|
|
2014-11-26 16:45:52 +00:00
|
|
|
connect(&_back, SIGNAL(clicked()), this, SLOT(onIntroBack()));
|
|
|
|
_back.hide();
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
countryForReg = psCurrentCountry();
|
|
|
|
|
|
|
|
MTP::send(MTPhelp_GetNearestDc(), rpcDone(gotNearestDC));
|
|
|
|
signalEmitOn = this;
|
|
|
|
|
|
|
|
stages[0] = steps;
|
|
|
|
memset(stages + 1, 0, sizeof(QWidget*) * 3);
|
2014-11-26 16:45:52 +00:00
|
|
|
_back.raise();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
connect(window, SIGNAL(resized(const QSize &)), this, SLOT(onParentResize(const QSize &)));
|
|
|
|
|
|
|
|
show();
|
|
|
|
setFocus();
|
2014-11-26 16:45:52 +00:00
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
cSetPasswordRecovered(false);
|
|
|
|
|
2014-11-26 16:45:52 +00:00
|
|
|
_back.move(st::setClosePos.x(), st::setClosePos.y());
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2014-12-19 21:20:30 +00:00
|
|
|
void IntroWidget::langChangeTo(int32 langId) {
|
|
|
|
_langChangeTo = langId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntroWidget::onChangeLang() {
|
|
|
|
cSetLang(_langChangeTo);
|
2015-03-02 12:34:16 +00:00
|
|
|
Local::writeSettings();
|
2014-12-19 21:20:30 +00:00
|
|
|
cSetRestarting(true);
|
|
|
|
cSetRestartingToSettings(false);
|
|
|
|
App::quit();
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void IntroWidget::onParentResize(const QSize &newSize) {
|
|
|
|
resize(newSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntroWidget::onIntroBack() {
|
|
|
|
if (!current) return;
|
2015-04-04 20:01:34 +00:00
|
|
|
moving = (current == 4) ? -2 : -1;
|
2014-05-30 08:53:19 +00:00
|
|
|
prepareMove();
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntroWidget::onIntroNext() {
|
|
|
|
if (!createNext()) return;
|
|
|
|
moving = 1;
|
|
|
|
prepareMove();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IntroWidget::createNext() {
|
|
|
|
if (current == sizeof(stages) / sizeof(stages[0]) - 1) return false;
|
|
|
|
if (!stages[current + 1]) {
|
|
|
|
switch (current) {
|
|
|
|
case 0: stages[current + 1] = phone = new IntroPhone(this); break;
|
|
|
|
case 1: stages[current + 1] = code = new IntroCode(this); break;
|
2015-04-02 10:33:19 +00:00
|
|
|
case 2:
|
|
|
|
if (_pwdSalt.isEmpty()) {
|
2015-04-04 20:01:34 +00:00
|
|
|
if (signup) delete signup;
|
2015-04-02 10:33:19 +00:00
|
|
|
stages[current + 1] = signup = new IntroSignup(this);
|
|
|
|
} else {
|
|
|
|
stages[current + 1] = pwdcheck = new IntroPwdCheck(this);
|
|
|
|
}
|
|
|
|
break;
|
2015-04-04 20:01:34 +00:00
|
|
|
case 3: stages[current + 1] = signup = new IntroSignup(this); break;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
2014-11-26 16:45:52 +00:00
|
|
|
_back.raise();
|
2014-05-30 08:53:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntroWidget::prepareMove() {
|
|
|
|
if (cacheForHide.isNull() || cacheForHideInd != current) makeHideCache();
|
2015-04-04 20:01:34 +00:00
|
|
|
|
|
|
|
stages[current + moving]->prepareShow();
|
2014-05-30 08:53:19 +00:00
|
|
|
if (cacheForShow.isNull() || cacheForShowInd != current + moving) makeShowCache();
|
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
int32 m = (moving > 0) ? 1 : -1;
|
|
|
|
xCoordHide = anim::ivalue(0, -m * st::introSlideShift);
|
2014-05-30 08:53:19 +00:00
|
|
|
cAlphaHide = anim::fvalue(1, 0);
|
2015-04-04 20:01:34 +00:00
|
|
|
xCoordShow = anim::ivalue(m * st::introSlideShift, 0);
|
2014-05-30 08:53:19 +00:00
|
|
|
cAlphaShow = anim::fvalue(0, 1);
|
|
|
|
anim::start(this);
|
|
|
|
|
2014-11-26 16:45:52 +00:00
|
|
|
_backTo = stages[current + moving]->hasBack() ? 1 : 0;
|
|
|
|
_backFrom = stages[current]->hasBack() ? 1 : 0;
|
|
|
|
animStep(0);
|
|
|
|
if (_backFrom > 0 || _backTo > 0) {
|
|
|
|
_back.show();
|
|
|
|
} else {
|
|
|
|
_back.hide();
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
stages[current]->deactivate();
|
|
|
|
stages[current + moving]->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntroWidget::onDoneStateChanged(int oldState, ButtonStateChangeSource source) {
|
|
|
|
if (animating()) return;
|
|
|
|
if (source == ButtonByPress) {
|
|
|
|
if (oldState & Button::StateDown) {
|
|
|
|
cacheForHide = QPixmap();
|
|
|
|
} else {
|
|
|
|
makeHideCache();
|
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
} else if (source == ButtonByHover && current != 2) {
|
2014-05-30 08:53:19 +00:00
|
|
|
if (!createNext()) return;
|
|
|
|
if (!cacheForShow) makeShowCache(current + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntroWidget::makeHideCache(int stage) {
|
|
|
|
if (stage < 0) stage = current;
|
|
|
|
int w = st::introSize.width(), h = st::introSize.height();
|
2014-06-14 19:32:11 +00:00
|
|
|
cacheForHide = myGrab(stages[stage], QRect(st::introSlideShift, 0, w, h));
|
2014-05-30 08:53:19 +00:00
|
|
|
cacheForHideInd = stage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntroWidget::makeShowCache(int stage) {
|
|
|
|
if (stage < 0) stage = current + moving;
|
|
|
|
int w = st::introSize.width(), h = st::introSize.height();
|
2014-06-14 19:32:11 +00:00
|
|
|
cacheForShow = myGrab(stages[stage], QRect(st::introSlideShift, 0, w, h));
|
2014-05-30 08:53:19 +00:00
|
|
|
cacheForShowInd = stage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntroWidget::animShow(const QPixmap &bgAnimCache, bool back) {
|
|
|
|
_bgAnimCache = bgAnimCache;
|
|
|
|
|
|
|
|
anim::stop(this);
|
|
|
|
stages[current]->show();
|
2014-11-26 16:45:52 +00:00
|
|
|
if (stages[current]->hasBack()) {
|
|
|
|
_back.setOpacity(1);
|
|
|
|
_back.show();
|
|
|
|
} else {
|
|
|
|
_back.hide();
|
|
|
|
}
|
2014-06-14 19:32:11 +00:00
|
|
|
_animCache = myGrab(this, rect());
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
visibilityChanging = 1;
|
|
|
|
a_coord = back ? anim::ivalue(-st::introSlideShift, 0) : anim::ivalue(st::introSlideShift, 0);
|
|
|
|
a_alpha = anim::fvalue(0, 1);
|
|
|
|
a_bgCoord = back ? anim::ivalue(0, st::introSlideShift) : anim::ivalue(0, -st::introSlideShift);
|
|
|
|
a_bgAlpha = anim::fvalue(1, 0);
|
|
|
|
|
|
|
|
stages[current]->deactivate();
|
|
|
|
stages[current]->hide();
|
2014-11-26 16:45:52 +00:00
|
|
|
_back.hide();
|
2014-05-30 08:53:19 +00:00
|
|
|
anim::start(this);
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IntroWidget::animStep(float64 ms) {
|
|
|
|
float64 fullDuration = st::introSlideDelta + st::introSlideDuration, dt = ms / fullDuration;
|
|
|
|
float64 dt1 = (ms > st::introSlideDuration) ? 1 : (ms / st::introSlideDuration), dt2 = (ms > st::introSlideDelta) ? (ms - st::introSlideDelta) / (st::introSlideDuration) : 0;
|
|
|
|
bool res = true;
|
|
|
|
if (visibilityChanging) {
|
|
|
|
if (dt2 >= 1) {
|
|
|
|
res = false;
|
|
|
|
a_bgCoord.finish();
|
|
|
|
a_bgAlpha.finish();
|
|
|
|
a_coord.finish();
|
|
|
|
a_alpha.finish();
|
|
|
|
|
|
|
|
_animCache = _bgAnimCache = QPixmap();
|
|
|
|
|
|
|
|
visibilityChanging = 0;
|
|
|
|
setFocus();
|
|
|
|
stages[current]->show();
|
|
|
|
stages[current]->activate();
|
2014-11-26 16:45:52 +00:00
|
|
|
if (stages[current]->hasBack()) {
|
|
|
|
_back.setOpacity(1);
|
|
|
|
_back.show();
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
|
|
|
a_bgCoord.update(dt1, st::introHideFunc);
|
|
|
|
a_bgAlpha.update(dt1, st::introAlphaHideFunc);
|
|
|
|
a_coord.update(dt2, st::introShowFunc);
|
|
|
|
a_alpha.update(dt2, st::introAlphaShowFunc);
|
|
|
|
}
|
|
|
|
} else if (dt >= 1) {
|
|
|
|
res = false;
|
|
|
|
xCoordShow.finish();
|
|
|
|
cAlphaShow.finish();
|
|
|
|
|
|
|
|
cacheForHide = cacheForShow = QPixmap();
|
|
|
|
|
|
|
|
current += moving;
|
|
|
|
moving = 0;
|
|
|
|
setFocus();
|
|
|
|
stages[current]->activate();
|
2014-11-26 16:45:52 +00:00
|
|
|
if (!stages[current]->hasBack()) {
|
|
|
|
_back.hide();
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
|
|
|
xCoordShow.update(dt2, st::introShowFunc);
|
|
|
|
cAlphaShow.update(dt2, st::introAlphaShowFunc);
|
|
|
|
xCoordHide.update(dt1, st::introHideFunc);
|
|
|
|
cAlphaHide.update(dt1, st::introAlphaHideFunc);
|
2014-11-26 16:45:52 +00:00
|
|
|
if (_backFrom != _backTo) {
|
|
|
|
_back.setOpacity((_backFrom > _backTo) ? cAlphaHide.current() : cAlphaShow.current());
|
|
|
|
} else {
|
|
|
|
_back.setOpacity(1);
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
update();
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntroWidget::paintEvent(QPaintEvent *e) {
|
|
|
|
bool trivial = (rect() == e->rect());
|
|
|
|
setMouseTracking(true);
|
|
|
|
|
|
|
|
QPainter p(this);
|
|
|
|
if (!trivial) {
|
|
|
|
p.setClipRect(e->rect());
|
|
|
|
}
|
|
|
|
if (animating()) {
|
|
|
|
if (visibilityChanging) {
|
|
|
|
p.setOpacity(a_bgAlpha.current());
|
|
|
|
p.drawPixmap(a_bgCoord.current(), 0, _bgAnimCache);
|
|
|
|
p.setOpacity(a_alpha.current());
|
|
|
|
p.drawPixmap(a_coord.current(), 0, _animCache);
|
|
|
|
} else {
|
|
|
|
p.setOpacity(cAlphaHide.current());
|
2014-06-14 19:32:11 +00:00
|
|
|
p.drawPixmap(stages[current]->x() + st::introSlideShift + xCoordHide.current(), stages[current]->y(), cacheForHide);
|
2014-05-30 08:53:19 +00:00
|
|
|
p.setOpacity(cAlphaShow.current());
|
2014-06-14 19:32:11 +00:00
|
|
|
p.drawPixmap(stages[current + moving]->x() + st::introSlideShift + xCoordShow.current(), stages[current + moving]->y(), cacheForShow);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect IntroWidget::innerRect() const {
|
|
|
|
int innerWidth = st::introSize.width() + 2 * st::introSlideShift, innerHeight = st::introSize.height();
|
|
|
|
return QRect((width() - innerWidth) / 2, (height() - innerHeight) / 2, innerWidth, (height() + innerHeight) / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString IntroWidget::currentCountry() const {
|
|
|
|
return countryForReg;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntroWidget::setPhone(const QString &phone, const QString &phone_hash, bool registered) {
|
|
|
|
_phone = phone;
|
|
|
|
_phone_hash = phone_hash;
|
|
|
|
_registered = registered;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntroWidget::setCode(const QString &code) {
|
|
|
|
_code = code;
|
|
|
|
}
|
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
void IntroWidget::setPwdSalt(const QByteArray &salt) {
|
|
|
|
_pwdSalt = salt;
|
|
|
|
delete signup;
|
|
|
|
delete pwdcheck;
|
2015-04-04 20:01:34 +00:00
|
|
|
stages[3] = stages[4] = 0;
|
2015-04-02 10:33:19 +00:00
|
|
|
signup = 0;
|
|
|
|
pwdcheck = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntroWidget::setHasRecovery(bool has) {
|
|
|
|
_hasRecovery = has;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntroWidget::setPwdHint(const QString &hint) {
|
|
|
|
_pwdHint = hint;
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void IntroWidget::setCallTimeout(int32 callTimeout) {
|
|
|
|
_callTimeout = callTimeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &IntroWidget::getPhone() const {
|
|
|
|
return _phone;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &IntroWidget::getPhoneHash() const {
|
|
|
|
return _phone_hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &IntroWidget::getCode() const {
|
|
|
|
return _code;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 IntroWidget::getCallTimeout() const {
|
|
|
|
return _callTimeout;
|
|
|
|
}
|
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
const QByteArray &IntroWidget::getPwdSalt() const {
|
|
|
|
return _pwdSalt;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IntroWidget::getHasRecovery() const {
|
|
|
|
return _hasRecovery;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &IntroWidget::getPwdHint() const {
|
|
|
|
return _pwdHint;
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void IntroWidget::resizeEvent(QResizeEvent *e) {
|
|
|
|
QRect r(innerRect());
|
|
|
|
if (steps) steps->setGeometry(r);
|
|
|
|
if (phone) phone->setGeometry(r);
|
|
|
|
if (code) code->setGeometry(r);
|
|
|
|
if (signup) signup->setGeometry(r);
|
2015-04-02 10:33:19 +00:00
|
|
|
if (pwdcheck) pwdcheck->setGeometry(r);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IntroWidget::mousePressEvent(QMouseEvent *e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntroWidget::finish(const MTPUser &user, const QImage &photo) {
|
2015-03-02 12:34:16 +00:00
|
|
|
wnd->setupMain(true, &user);
|
2014-05-30 08:53:19 +00:00
|
|
|
if (!photo.isNull()) {
|
|
|
|
App::app()->uploadProfilePhoto(photo, MTP::authedId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntroWidget::keyPressEvent(QKeyEvent *e) {
|
|
|
|
if (animating()) return;
|
|
|
|
if (e->key() == Qt::Key_Escape) {
|
|
|
|
stages[current]->onBack();
|
|
|
|
} else if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return || e->key() == Qt::Key_Space) {
|
|
|
|
stages[current]->onNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-12 16:27:03 +00:00
|
|
|
void IntroWidget::updateWideMode() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-08-01 11:09:46 +00:00
|
|
|
void IntroWidget::rpcInvalidate() {
|
|
|
|
if (phone) phone->rpcInvalidate();
|
|
|
|
if (code) code->rpcInvalidate();
|
|
|
|
if (signup) signup->rpcInvalidate();
|
2015-04-02 10:33:19 +00:00
|
|
|
if (pwdcheck) pwdcheck->rpcInvalidate();
|
2014-08-01 11:09:46 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
IntroWidget::~IntroWidget() {
|
|
|
|
delete steps;
|
|
|
|
delete phone;
|
|
|
|
delete code;
|
|
|
|
delete signup;
|
2015-04-02 10:33:19 +00:00
|
|
|
delete pwdcheck;
|
2014-05-30 08:53:19 +00:00
|
|
|
if (App::wnd()) App::wnd()->noIntro(this);
|
|
|
|
}
|