tdesktop/Telegram/SourceFiles/intro/intro_widget.h

206 lines
4.7 KiB
C
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
2017-05-30 09:31:40 +00:00
#include "mtproto/sender.h"
#include "ui/rp_widget.h"
2019-04-02 09:13:30 +00:00
#include "ui/effects/animations.h"
#include "window/window_lock_widgets.h"
2018-08-03 21:48:00 +00:00
#include "core/core_cloud_password.h"
#include "media/player/media_player_float.h"
2017-05-30 09:31:40 +00:00
2019-07-24 08:46:23 +00:00
namespace Main {
class Account;
} // namespace Main
namespace Ui {
class IconButton;
class RoundButton;
2016-11-24 19:28:23 +00:00
class LinkButton;
class FlatLabel;
template <typename Widget>
class FadeWrap;
} // namespace Ui
2018-05-07 17:44:33 +00:00
namespace Window {
2019-02-10 16:29:55 +00:00
class ConnectionState;
2018-05-07 17:44:33 +00:00
} // namespace Window
2016-11-24 19:28:23 +00:00
namespace Intro {
2019-11-26 11:10:44 +00:00
namespace details {
2016-11-24 19:28:23 +00:00
2019-11-26 11:10:44 +00:00
enum class CallStatus {
Waiting,
Calling,
Called,
Disabled,
};
struct Data {
QString country;
QString phone;
QByteArray phoneHash;
CallStatus callStatus = CallStatus::Disabled;
int callTimeout = 0;
int codeLength = 5;
bool codeByTelegram = false;
Core::CloudPasswordCheckRequest pwdRequest;
bool hasRecovery = false;
QString pwdHint;
bool pwdNotEmptyPassport = false;
2019-11-26 11:10:44 +00:00
Window::TermsLock termsLock;
base::Observable<void> updated;
};
enum class StackAction {
2019-11-26 11:10:44 +00:00
Back,
Forward,
Replace,
};
enum class Animate {
Back,
Forward,
};
2019-11-26 11:10:44 +00:00
class Step;
} // namespace details
enum class EnterPoint : uchar {
Start,
Phone,
Qr,
};
class Widget
: public Ui::RpWidget
, private Media::Player::FloatDelegate
, private Media::Player::FloatSectionDelegate
, private base::Subscriber {
public:
Widget(
QWidget *parent,
not_null<Main::Account*> account,
EnterPoint point);
void showAnimated(const QPixmap &bgAnimCache, bool back = false);
2016-11-24 19:28:23 +00:00
void setInnerFocus();
[[nodiscard]] rpl::producer<> showSettingsRequested() const;
2016-11-24 19:28:23 +00:00
~Widget();
protected:
void paintEvent(QPaintEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
void keyPressEvent(QKeyEvent *e) override;
private:
void refreshLang();
void animationCallback();
2017-05-30 09:31:40 +00:00
void createLanguageLink();
2019-11-26 11:10:44 +00:00
void checkUpdateStatus();
void setupNextButton();
void handleUpdates(const MTPUpdates &updates);
void handleUpdate(const MTPUpdate &update);
void backRequested();
2016-11-24 19:28:23 +00:00
void updateControlsGeometry();
2019-11-26 11:10:44 +00:00
[[nodiscard]] not_null<details::Data*> getData() {
2016-11-24 19:28:23 +00:00
return &_data;
}
2016-11-24 19:28:23 +00:00
void fixOrder();
void showControls();
void hideControls();
2016-11-24 19:28:23 +00:00
void showResetButton();
void resetAccount();
2018-06-01 07:00:18 +00:00
void showTerms();
void acceptTerms(Fn<void()> callback);
2018-05-30 15:08:12 +00:00
void hideAndDestroy(object_ptr<Ui::FadeWrap<Ui::RpWidget>> widget);
2019-11-26 11:10:44 +00:00
[[nodiscard]] details::Step *getStep(int skip = 0) const {
Expects(skip >= 0);
Expects(skip < _stepHistory.size());
return _stepHistory[_stepHistory.size() - skip - 1];
}
void historyMove(details::StackAction action, details::Animate animate);
void moveToStep(
details::Step *step,
details::StackAction action,
details::Animate animate);
2019-11-26 11:10:44 +00:00
void appendStep(details::Step *step);
2017-05-30 09:31:40 +00:00
void getNearestDC();
void showTerms(Fn<void()> callback);
2017-05-30 09:31:40 +00:00
// FloatDelegate
[[nodiscard]] auto floatPlayerDelegate()
-> not_null<Media::Player::FloatDelegate*>;
[[nodiscard]] auto floatPlayerSectionDelegate()
-> not_null<Media::Player::FloatSectionDelegate*>;
not_null<Ui::RpWidget*> floatPlayerWidget() override;
not_null<Media::Player::FloatSectionDelegate*> floatPlayerGetSection(
Window::Column column) override;
void floatPlayerEnumerateSections(Fn<void(
not_null<Media::Player::FloatSectionDelegate*> widget,
Window::Column widgetColumn)> callback) override;
bool floatPlayerIsVisible(not_null<HistoryItem*> item) override;
// FloatSectionDelegate
QRect floatPlayerAvailableRect() override;
bool floatPlayerHandleWheelEvent(QEvent *e) override;
2019-11-27 08:02:56 +00:00
const not_null<Main::Account*> _account;
std::optional<MTP::Sender> _api;
mtpRequestId _nearestDcRequestId = 0;
2019-07-24 08:46:23 +00:00
2019-04-02 09:13:30 +00:00
Ui::Animations::Simple _a_show;
2017-05-30 09:31:40 +00:00
bool _showBack = false;
QPixmap _cacheUnder, _cacheOver;
2019-11-26 11:10:44 +00:00
std::vector<details::Step*> _stepHistory;
rpl::lifetime _stepLifetime;
2016-04-14 19:24:42 +00:00
2019-11-26 11:10:44 +00:00
details::Data _data;
2019-04-02 09:13:30 +00:00
Ui::Animations::Simple _coverShownAnimation;
2016-11-24 19:28:23 +00:00
int _nextTopFrom = 0;
int _controlsTopFrom = 0;
object_ptr<Ui::FadeWrap<Ui::IconButton>> _back;
object_ptr<Ui::FadeWrap<Ui::RoundButton>> _update = { nullptr };
object_ptr<Ui::FadeWrap<Ui::RoundButton>> _settings;
2019-11-26 11:39:54 +00:00
object_ptr<Ui::FadeWrap<Ui::RoundButton>> _next;
object_ptr<Ui::FadeWrap<Ui::LinkButton>> _changeLanguage = { nullptr };
object_ptr<Ui::FadeWrap<Ui::RoundButton>> _resetAccount = { nullptr };
2018-05-30 15:08:12 +00:00
object_ptr<Ui::FadeWrap<Ui::FlatLabel>> _terms = { nullptr };
2019-02-10 16:29:55 +00:00
std::unique_ptr<Window::ConnectionState> _connecting;
2018-05-07 17:44:33 +00:00
2019-11-26 14:27:09 +00:00
bool _nextShown = true;
2019-11-26 11:10:44 +00:00
Ui::Animations::Simple _nextShownAnimation;
2016-11-24 19:28:23 +00:00
mtpRequestId _resetRequest = 0;
};
2016-11-24 19:28:23 +00:00
} // namespace Intro