2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-05-30 09:31:40 +00:00
|
|
|
#include "mtproto/sender.h"
|
2018-04-26 16:14:21 +00:00
|
|
|
#include "ui/rp_widget.h"
|
2017-05-30 09:31:40 +00:00
|
|
|
|
2016-10-26 10:06:00 +00:00
|
|
|
namespace Ui {
|
|
|
|
class IconButton;
|
2016-11-11 13:46:04 +00:00
|
|
|
class RoundButton;
|
2016-11-24 19:28:23 +00:00
|
|
|
class LinkButton;
|
|
|
|
class SlideAnimation;
|
|
|
|
class CrossFadeAnimation;
|
|
|
|
class FlatLabel;
|
2016-10-26 10:06:00 +00:00
|
|
|
template <typename Widget>
|
2017-09-30 18:26:45 +00:00
|
|
|
class FadeWrap;
|
2016-10-26 10:06:00 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|
2018-05-07 17:44:33 +00:00
|
|
|
namespace Window {
|
|
|
|
class ConnectingWidget;
|
|
|
|
} // namespace Window
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
namespace Intro {
|
|
|
|
|
2018-04-26 16:14:21 +00:00
|
|
|
class Widget : public Ui::RpWidget, private MTP::Sender, private base::Subscriber {
|
2014-05-30 08:53:19 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2016-11-24 19:28:23 +00:00
|
|
|
Widget(QWidget *parent);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void showAnimated(const QPixmap &bgAnimCache, bool back = false);
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void setInnerFocus();
|
2016-03-14 16:59:18 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
~Widget();
|
2016-11-05 08:36:24 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
void keyPressEvent(QKeyEvent *e) override;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void countryChanged();
|
|
|
|
|
2016-11-05 08:36:24 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
|
|
|
|
private slots:
|
|
|
|
void onCheckUpdateStatus();
|
|
|
|
#endif // TDESKTOP_DISABLE_AUTOUPDATE
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
// Internal interface.
|
|
|
|
public:
|
|
|
|
struct Data {
|
|
|
|
QString country;
|
|
|
|
QString phone;
|
2017-03-10 19:46:28 +00:00
|
|
|
QByteArray phoneHash;
|
2016-11-24 19:28:23 +00:00
|
|
|
bool phoneIsRegistered = false;
|
|
|
|
|
|
|
|
enum class CallStatus {
|
|
|
|
Waiting,
|
|
|
|
Calling,
|
|
|
|
Called,
|
|
|
|
Disabled,
|
|
|
|
};
|
|
|
|
CallStatus callStatus = CallStatus::Disabled;
|
|
|
|
int callTimeout = 0;
|
|
|
|
|
|
|
|
QString code;
|
|
|
|
int codeLength = 5;
|
|
|
|
bool codeByTelegram = false;
|
|
|
|
|
|
|
|
QByteArray pwdSalt;
|
|
|
|
bool hasRecovery = false;
|
|
|
|
QString pwdHint;
|
|
|
|
|
|
|
|
base::Observable<void> updated;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class Direction {
|
|
|
|
Back,
|
|
|
|
Forward,
|
|
|
|
Replace,
|
|
|
|
};
|
2017-02-18 11:29:19 +00:00
|
|
|
class Step : public TWidget, public RPCSender, protected base::Subscriber {
|
2016-11-24 19:28:23 +00:00
|
|
|
public:
|
|
|
|
Step(QWidget *parent, Data *data, bool hasCover = false);
|
|
|
|
|
|
|
|
virtual void setInnerFocus() {
|
|
|
|
setFocus();
|
|
|
|
}
|
|
|
|
|
2017-02-26 11:32:13 +00:00
|
|
|
void setGoCallback(base::lambda<void(Step *step, Direction direction)> callback);
|
|
|
|
void setShowResetCallback(base::lambda<void()> callback);
|
2016-11-24 19:28:23 +00:00
|
|
|
|
|
|
|
void prepareShowAnimated(Step *after);
|
|
|
|
void showAnimated(Direction direction);
|
|
|
|
void showFast();
|
|
|
|
bool animating() const;
|
|
|
|
|
|
|
|
bool hasCover() const;
|
|
|
|
virtual bool hasBack() const;
|
|
|
|
virtual void activate();
|
|
|
|
virtual void cancelled();
|
|
|
|
virtual void finished();
|
|
|
|
|
|
|
|
virtual void submit() = 0;
|
|
|
|
virtual QString nextButtonText() const;
|
|
|
|
|
|
|
|
int contentLeft() const;
|
|
|
|
int contentTop() const;
|
|
|
|
|
|
|
|
void setErrorCentered(bool centered);
|
|
|
|
void setErrorBelowLink(bool below);
|
2017-05-30 13:54:05 +00:00
|
|
|
void showError(base::lambda<QString()> textFactory);
|
2016-11-24 19:28:23 +00:00
|
|
|
void hideError() {
|
2017-05-30 13:54:05 +00:00
|
|
|
showError(base::lambda<QString()>());
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 13:42:37 +00:00
|
|
|
~Step();
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
|
2017-05-30 13:54:05 +00:00
|
|
|
void setTitleText(base::lambda<QString()> richTitleTextFactory);
|
|
|
|
void setDescriptionText(base::lambda<QString()> richDescriptionTextFactory);
|
2016-11-24 19:28:23 +00:00
|
|
|
bool paintAnimated(Painter &p, QRect clip);
|
|
|
|
|
|
|
|
void fillSentCodeData(const MTPauth_SentCodeType &type);
|
|
|
|
|
|
|
|
void showDescription();
|
|
|
|
void hideDescription();
|
|
|
|
|
|
|
|
Data *getData() const {
|
|
|
|
return _data;
|
|
|
|
}
|
2017-11-13 12:02:53 +00:00
|
|
|
void finish(const MTPUser &user, QImage &&photo = QImage());
|
2016-11-24 19:28:23 +00:00
|
|
|
|
|
|
|
void goBack() {
|
|
|
|
if (_goCallback) _goCallback(nullptr, Direction::Back);
|
|
|
|
}
|
|
|
|
void goNext(Step *step) {
|
|
|
|
if (_goCallback) _goCallback(step, Direction::Forward);
|
|
|
|
}
|
|
|
|
void goReplace(Step *step) {
|
|
|
|
if (_goCallback) _goCallback(step, Direction::Replace);
|
|
|
|
}
|
|
|
|
void showResetButton() {
|
|
|
|
if (_showResetCallback) _showResetCallback();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct CoverAnimation {
|
2016-11-28 13:42:37 +00:00
|
|
|
CoverAnimation() = default;
|
|
|
|
CoverAnimation(CoverAnimation &&other) = default;
|
|
|
|
CoverAnimation &operator=(CoverAnimation &&other) = default;
|
|
|
|
~CoverAnimation();
|
|
|
|
|
2017-02-21 13:45:56 +00:00
|
|
|
std::unique_ptr<Ui::CrossFadeAnimation> title;
|
|
|
|
std::unique_ptr<Ui::CrossFadeAnimation> description;
|
2016-11-24 19:28:23 +00:00
|
|
|
|
|
|
|
// From content top till the next button top.
|
|
|
|
QPixmap contentSnapshotWas;
|
|
|
|
QPixmap contentSnapshotNow;
|
|
|
|
};
|
|
|
|
void updateLabelsPosition();
|
|
|
|
void paintContentSnapshot(Painter &p, const QPixmap &snapshot, float64 alpha, float64 howMuchHidden);
|
2017-05-30 13:54:05 +00:00
|
|
|
void refreshError();
|
|
|
|
void refreshTitle();
|
|
|
|
void refreshDescription();
|
|
|
|
void refreshLang();
|
2016-11-24 19:28:23 +00:00
|
|
|
|
|
|
|
CoverAnimation prepareCoverAnimation(Step *step);
|
|
|
|
QPixmap prepareContentSnapshot();
|
|
|
|
QPixmap prepareSlideAnimation();
|
|
|
|
void showFinished();
|
|
|
|
|
|
|
|
void prepareCoverMask();
|
|
|
|
void paintCover(Painter &p, int top);
|
|
|
|
|
|
|
|
Data *_data = nullptr;
|
|
|
|
bool _hasCover = false;
|
|
|
|
base::lambda<void(Step *step, Direction direction)> _goCallback;
|
|
|
|
base::lambda<void()> _showResetCallback;
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<Ui::FlatLabel> _title;
|
2017-05-30 13:54:05 +00:00
|
|
|
base::lambda<QString()> _titleTextFactory;
|
2017-09-30 18:26:45 +00:00
|
|
|
object_ptr<Ui::FadeWrap<Ui::FlatLabel>> _description;
|
2017-05-30 13:54:05 +00:00
|
|
|
base::lambda<QString()> _descriptionTextFactory;
|
2016-11-24 19:28:23 +00:00
|
|
|
|
|
|
|
bool _errorCentered = false;
|
|
|
|
bool _errorBelowLink = false;
|
2017-05-30 13:54:05 +00:00
|
|
|
base::lambda<QString()> _errorTextFactory;
|
2017-09-30 18:26:45 +00:00
|
|
|
object_ptr<Ui::FadeWrap<Ui::FlatLabel>> _error = { nullptr };
|
2016-11-24 19:28:23 +00:00
|
|
|
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation _a_show;
|
2016-11-24 19:28:23 +00:00
|
|
|
CoverAnimation _coverAnimation;
|
2017-02-21 13:45:56 +00:00
|
|
|
std::unique_ptr<Ui::SlideAnimation> _slideAnimation;
|
2016-11-24 19:28:23 +00:00
|
|
|
QPixmap _coverMask;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
private:
|
2018-05-07 17:44:33 +00:00
|
|
|
void setupConnectingWidget();
|
2017-05-30 13:54:05 +00:00
|
|
|
void refreshLang();
|
2016-12-05 11:01:08 +00:00
|
|
|
void animationCallback();
|
2017-05-30 09:31:40 +00:00
|
|
|
void createLanguageLink();
|
2016-11-24 19:28:23 +00:00
|
|
|
|
2016-11-05 08:36:24 +00:00
|
|
|
void updateControlsGeometry();
|
2016-11-24 19:28:23 +00:00
|
|
|
Data *getData() {
|
|
|
|
return &_data;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void fixOrder();
|
|
|
|
void showControls();
|
|
|
|
void hideControls();
|
|
|
|
QRect calculateStepRect() const;
|
2014-12-19 21:20:30 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void showResetButton();
|
|
|
|
void resetAccount();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
Step *getStep(int skip = 0) {
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(_stepHistory.size() + skip > 0);
|
2016-03-14 16:59:18 +00:00
|
|
|
return _stepHistory.at(_stepHistory.size() - skip - 1);
|
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
void historyMove(Direction direction);
|
|
|
|
void moveToStep(Step *step, Direction direction);
|
|
|
|
void appendStep(Step *step);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-05-30 09:31:40 +00:00
|
|
|
void getNearestDC();
|
|
|
|
|
|
|
|
Animation _a_show;
|
|
|
|
bool _showBack = false;
|
|
|
|
QPixmap _cacheUnder, _cacheOver;
|
|
|
|
|
|
|
|
QVector<Step*> _stepHistory;
|
2016-04-14 19:24:42 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
Data _data;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation _coverShownAnimation;
|
2016-11-24 19:28:23 +00:00
|
|
|
int _nextTopFrom = 0;
|
|
|
|
int _controlsTopFrom = 0;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
object_ptr<Ui::FadeWrap<Ui::IconButton>> _back;
|
|
|
|
object_ptr<Ui::FadeWrap<Ui::RoundButton>> _update = { nullptr };
|
|
|
|
object_ptr<Ui::FadeWrap<Ui::RoundButton>> _settings;
|
2014-11-26 16:45:52 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<Ui::RoundButton> _next;
|
2017-09-30 18:26:45 +00:00
|
|
|
object_ptr<Ui::FadeWrap<Ui::LinkButton>> _changeLanguage = { nullptr };
|
|
|
|
object_ptr<Ui::FadeWrap<Ui::RoundButton>> _resetAccount = { nullptr };
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-05-07 17:44:33 +00:00
|
|
|
base::unique_qptr<Window::ConnectingWidget> _connecting;
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
mtpRequestId _resetRequest = 0;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
};
|
2016-11-24 19:28:23 +00:00
|
|
|
|
|
|
|
} // namespace Intro
|