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
|
|
|
*/
|
2019-11-27 09:45:23 +00:00
|
|
|
#include "intro/intro_widget.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2019-11-27 09:45:23 +00:00
|
|
|
#include "intro/intro_start.h"
|
|
|
|
#include "intro/intro_phone.h"
|
2020-06-23 14:55:08 +00:00
|
|
|
#include "intro/intro_qr.h"
|
2019-11-27 09:45:23 +00:00
|
|
|
#include "intro/intro_code.h"
|
|
|
|
#include "intro/intro_signup.h"
|
|
|
|
#include "intro/intro_password_check.h"
|
2019-11-26 11:10:44 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2020-09-30 09:11:44 +00:00
|
|
|
#include "lang/lang_instance.h"
|
2019-11-26 11:10:44 +00:00
|
|
|
#include "lang/lang_cloud_manager.h"
|
|
|
|
#include "storage/localstorage.h"
|
2019-07-24 08:46:23 +00:00
|
|
|
#include "main/main_account.h"
|
2020-06-23 14:55:08 +00:00
|
|
|
#include "main/main_domain.h"
|
2020-06-29 18:14:16 +00:00
|
|
|
#include "main/main_session.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwindow.h"
|
2021-06-15 23:06:22 +00:00
|
|
|
#include "history/history.h"
|
|
|
|
#include "history/history_item.h"
|
2020-06-29 18:14:16 +00:00
|
|
|
#include "data/data_user.h"
|
2021-08-26 14:46:24 +00:00
|
|
|
#include "countries/countries_instance.h"
|
2021-10-18 21:36:55 +00:00
|
|
|
#include "ui/boxes/confirm_box.h"
|
2021-07-26 06:32:16 +00:00
|
|
|
#include "ui/text/format_values.h" // Ui::FormatPhone
|
2019-06-12 20:11:41 +00:00
|
|
|
#include "ui/text/text_utilities.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-24 19:28:23 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "ui/wrap/fade_wrap.h"
|
2018-04-26 16:14:21 +00:00
|
|
|
#include "core/update_checker.h"
|
2020-03-29 10:06:10 +00:00
|
|
|
#include "core/application.h"
|
2020-06-17 09:36:25 +00:00
|
|
|
#include "mtproto/mtproto_dc_options.h"
|
2016-11-24 19:28:23 +00:00
|
|
|
#include "window/window_slide_animation.h"
|
2018-05-07 17:44:33 +00:00
|
|
|
#include "window/window_connecting_widget.h"
|
2021-06-15 23:06:22 +00:00
|
|
|
#include "window/window_controller.h"
|
|
|
|
#include "window/window_session_controller.h"
|
2020-06-25 14:17:37 +00:00
|
|
|
#include "window/section_widget.h"
|
2019-09-17 16:13:12 +00:00
|
|
|
#include "base/platform/base_platform_info.h"
|
2020-03-29 10:06:10 +00:00
|
|
|
#include "api/api_text_entities.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_layers.h"
|
2019-02-07 16:36:30 +00:00
|
|
|
#include "styles/style_intro.h"
|
2022-01-24 16:33:30 +00:00
|
|
|
#include "base/qt/qt_common_adapters.h"
|
2016-11-24 19:28:23 +00:00
|
|
|
|
|
|
|
namespace Intro {
|
2017-04-13 17:59:05 +00:00
|
|
|
namespace {
|
|
|
|
|
2019-11-26 11:10:44 +00:00
|
|
|
using namespace ::Intro::details;
|
2018-10-07 09:02:10 +00:00
|
|
|
|
2020-06-29 18:14:16 +00:00
|
|
|
[[nodiscard]] QString ComputeNewAccountCountry() {
|
|
|
|
if (const auto parent
|
|
|
|
= Core::App().domain().maybeLastOrSomeAuthedAccount()) {
|
|
|
|
if (const auto session = parent->maybeSession()) {
|
2021-08-26 15:15:49 +00:00
|
|
|
const auto iso = Countries::Instance().countryISO2ByPhone(
|
2020-06-29 18:14:16 +00:00
|
|
|
session->user()->phone());
|
|
|
|
if (!iso.isEmpty()) {
|
|
|
|
return iso;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Platform::SystemCountry();
|
|
|
|
}
|
|
|
|
|
2017-04-13 17:59:05 +00:00
|
|
|
} // namespace
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2020-06-23 14:55:08 +00:00
|
|
|
Widget::Widget(
|
|
|
|
QWidget *parent,
|
2021-02-21 03:51:30 +00:00
|
|
|
not_null<Window::Controller*> controller,
|
2020-06-23 14:55:08 +00:00
|
|
|
not_null<Main::Account*> account,
|
|
|
|
EnterPoint point)
|
2019-07-24 08:46:23 +00:00
|
|
|
: RpWidget(parent)
|
|
|
|
, _account(account)
|
2021-02-21 03:51:30 +00:00
|
|
|
, _data(details::Data{ .controller = controller })
|
2017-09-30 18:26:45 +00:00
|
|
|
, _back(this, object_ptr<Ui::IconButton>(this, st::introBackButton))
|
|
|
|
, _settings(
|
|
|
|
this,
|
|
|
|
object_ptr<Ui::RoundButton>(
|
|
|
|
this,
|
2019-06-18 16:53:27 +00:00
|
|
|
tr::lng_menu_settings(),
|
2017-09-30 18:26:45 +00:00
|
|
|
st::defaultBoxButton))
|
2019-11-26 11:39:54 +00:00
|
|
|
, _next(
|
|
|
|
this,
|
2019-11-27 08:02:56 +00:00
|
|
|
object_ptr<Ui::RoundButton>(this, nullptr, st::introNextButton))
|
|
|
|
, _connecting(std::make_unique<Window::ConnectionState>(
|
2019-11-26 11:39:54 +00:00
|
|
|
this,
|
2020-06-10 14:52:44 +00:00
|
|
|
account,
|
2019-11-27 08:02:56 +00:00
|
|
|
rpl::single(true))) {
|
2020-06-25 14:17:37 +00:00
|
|
|
Core::App().setDefaultFloatPlayerDelegate(floatPlayerDelegate());
|
|
|
|
|
2020-06-29 18:14:16 +00:00
|
|
|
getData()->country = ComputeNewAccountCountry();
|
2020-06-26 11:28:06 +00:00
|
|
|
|
2020-06-29 18:16:48 +00:00
|
|
|
_account->mtpValue(
|
|
|
|
) | rpl::start_with_next([=](not_null<MTP::Instance*> instance) {
|
|
|
|
_api.emplace(instance);
|
|
|
|
crl::on_main(this, [=] { createLanguageLink(); });
|
|
|
|
}, lifetime());
|
|
|
|
|
2020-06-23 14:55:08 +00:00
|
|
|
switch (point) {
|
|
|
|
case EnterPoint::Start:
|
2020-06-29 18:14:16 +00:00
|
|
|
getNearestDC();
|
2020-06-23 14:55:08 +00:00
|
|
|
appendStep(new StartWidget(this, _account, getData()));
|
|
|
|
break;
|
|
|
|
case EnterPoint::Phone:
|
|
|
|
appendStep(new PhoneWidget(this, _account, getData()));
|
|
|
|
break;
|
|
|
|
case EnterPoint::Qr:
|
|
|
|
appendStep(new QrWidget(this, _account, getData()));
|
|
|
|
break;
|
|
|
|
default: Unexpected("Enter point in Intro::Widget::Widget.");
|
|
|
|
}
|
|
|
|
|
2019-11-27 08:02:56 +00:00
|
|
|
fixOrder();
|
|
|
|
|
2021-05-25 14:12:10 +00:00
|
|
|
Lang::CurrentCloudManager().firstLanguageSuggestion(
|
|
|
|
) | rpl::start_with_next([=] {
|
2019-11-27 08:02:56 +00:00
|
|
|
createLanguageLink();
|
2021-05-25 14:12:10 +00:00
|
|
|
}, lifetime());
|
2019-11-27 08:02:56 +00:00
|
|
|
|
2020-03-29 10:06:10 +00:00
|
|
|
_account->mtpUpdates(
|
|
|
|
) | rpl::start_with_next([=](const MTPUpdates &updates) {
|
|
|
|
handleUpdates(updates);
|
|
|
|
}, lifetime());
|
|
|
|
|
2020-06-23 14:55:08 +00:00
|
|
|
_back->entity()->setClickedCallback([=] { backRequested(); });
|
2017-09-30 19:20:40 +00:00
|
|
|
_back->hide(anim::type::instant);
|
2014-11-26 16:45:52 +00:00
|
|
|
|
2019-11-27 08:02:56 +00:00
|
|
|
_next->entity()->setClickedCallback([=] { getStep()->submit(); });
|
2016-11-24 19:28:23 +00:00
|
|
|
|
2019-11-27 08:02:56 +00:00
|
|
|
if (_changeLanguage) {
|
|
|
|
_changeLanguage->finishAnimating();
|
|
|
|
}
|
2017-05-30 13:54:05 +00:00
|
|
|
|
2020-09-30 09:11:44 +00:00
|
|
|
Lang::Updated(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
refreshLang();
|
|
|
|
}, lifetime());
|
2017-05-30 13:54:05 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
show();
|
2016-11-24 19:28:23 +00:00
|
|
|
showControls();
|
|
|
|
getStep()->showFast();
|
2019-03-12 09:55:56 +00:00
|
|
|
setInnerFocus();
|
2014-11-26 16:45:52 +00:00
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
cSetPasswordRecovered(false);
|
|
|
|
|
2018-07-11 22:14:44 +00:00
|
|
|
if (!Core::UpdaterDisabled()) {
|
|
|
|
Core::UpdateChecker checker;
|
|
|
|
checker.start();
|
2019-11-26 11:10:44 +00:00
|
|
|
rpl::merge(
|
2022-03-11 05:55:21 +00:00
|
|
|
rpl::single(rpl::empty),
|
2019-11-26 11:10:44 +00:00
|
|
|
checker.isLatest(),
|
|
|
|
checker.failed(),
|
|
|
|
checker.ready()
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
checkUpdateStatus();
|
|
|
|
}, lifetime());
|
2018-07-11 22:14:44 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2021-02-03 01:58:27 +00:00
|
|
|
rpl::producer<> Widget::showSettingsRequested() const {
|
|
|
|
return _settings->entity()->clicks() | rpl::to_empty;
|
|
|
|
}
|
|
|
|
|
2020-06-25 14:17:37 +00:00
|
|
|
not_null<Media::Player::FloatDelegate*> Widget::floatPlayerDelegate() {
|
|
|
|
return static_cast<Media::Player::FloatDelegate*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Widget::floatPlayerSectionDelegate()
|
|
|
|
-> not_null<Media::Player::FloatSectionDelegate*> {
|
|
|
|
return static_cast<Media::Player::FloatSectionDelegate*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
not_null<Ui::RpWidget*> Widget::floatPlayerWidget() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Widget::floatPlayerGetSection(Window::Column column)
|
|
|
|
-> not_null<Media::Player::FloatSectionDelegate*> {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::floatPlayerEnumerateSections(Fn<void(
|
|
|
|
not_null<Media::Player::FloatSectionDelegate*> widget,
|
|
|
|
Window::Column widgetColumn)> callback) {
|
|
|
|
callback(this, Window::Column::Second);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Widget::floatPlayerIsVisible(not_null<HistoryItem*> item) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-06-15 23:06:22 +00:00
|
|
|
void Widget::floatPlayerDoubleClickEvent(not_null<const HistoryItem*> item) {
|
|
|
|
getData()->controller->invokeForSessionController(
|
|
|
|
&item->history()->peer->session().account(),
|
2022-06-10 10:59:19 +00:00
|
|
|
item->history()->peer,
|
|
|
|
[&](not_null<Window::SessionController*> controller) {
|
2021-06-15 23:06:22 +00:00
|
|
|
controller->showPeerHistoryAtItem(item);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-06-25 14:17:37 +00:00
|
|
|
QRect Widget::floatPlayerAvailableRect() {
|
|
|
|
return mapToGlobal(rect());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Widget::floatPlayerHandleWheelEvent(QEvent *e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-30 13:54:05 +00:00
|
|
|
void Widget::refreshLang() {
|
2017-05-30 16:58:13 +00:00
|
|
|
_changeLanguage.destroy();
|
|
|
|
createLanguageLink();
|
2017-05-30 15:21:05 +00:00
|
|
|
InvokeQueued(this, [this] { updateControlsGeometry(); });
|
2017-05-30 13:54:05 +00:00
|
|
|
}
|
|
|
|
|
2020-03-29 10:06:10 +00:00
|
|
|
void Widget::handleUpdates(const MTPUpdates &updates) {
|
|
|
|
updates.match([&](const MTPDupdateShort &data) {
|
|
|
|
handleUpdate(data.vupdate());
|
|
|
|
}, [&](const MTPDupdates &data) {
|
|
|
|
for (const auto &update : data.vupdates().v) {
|
|
|
|
handleUpdate(update);
|
|
|
|
}
|
|
|
|
}, [&](const MTPDupdatesCombined &data) {
|
|
|
|
for (const auto &update : data.vupdates().v) {
|
|
|
|
handleUpdate(update);
|
|
|
|
}
|
|
|
|
}, [](const auto &) {});
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::handleUpdate(const MTPUpdate &update) {
|
|
|
|
update.match([&](const MTPDupdateDcOptions &data) {
|
2020-06-17 09:36:25 +00:00
|
|
|
_account->mtp().dcOptions().addFromList(data.vdc_options());
|
2020-03-29 10:06:10 +00:00
|
|
|
}, [&](const MTPDupdateConfig &data) {
|
2020-06-17 09:36:25 +00:00
|
|
|
_account->mtp().requestConfig();
|
2020-03-29 10:06:10 +00:00
|
|
|
}, [&](const MTPDupdateServiceNotification &data) {
|
|
|
|
const auto text = TextWithEntities{
|
|
|
|
qs(data.vmessage()),
|
2020-06-08 08:03:45 +00:00
|
|
|
Api::EntitiesFromMTP(nullptr, data.ventities().v)
|
2020-03-29 10:06:10 +00:00
|
|
|
};
|
2022-02-27 08:23:20 +00:00
|
|
|
Ui::show(Ui::MakeInformBox(text));
|
2020-03-29 10:06:10 +00:00
|
|
|
}, [](const auto &) {});
|
|
|
|
}
|
|
|
|
|
2017-05-30 09:31:40 +00:00
|
|
|
void Widget::createLanguageLink() {
|
2020-06-29 18:17:47 +00:00
|
|
|
if (_changeLanguage
|
|
|
|
|| Core::App().domain().maybeLastOrSomeAuthedAccount()) {
|
2019-11-27 08:02:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-05-30 09:31:40 +00:00
|
|
|
|
2019-11-27 08:02:56 +00:00
|
|
|
const auto createLink = [=](
|
|
|
|
const QString &text,
|
|
|
|
const QString &languageId) {
|
2017-09-30 18:26:45 +00:00
|
|
|
_changeLanguage.create(
|
|
|
|
this,
|
|
|
|
object_ptr<Ui::LinkButton>(this, text));
|
2017-09-30 19:20:40 +00:00
|
|
|
_changeLanguage->hide(anim::type::instant);
|
2018-04-07 08:47:08 +00:00
|
|
|
_changeLanguage->entity()->setClickedCallback([=] {
|
2017-05-30 09:31:40 +00:00
|
|
|
Lang::CurrentCloudManager().switchToLanguage(languageId);
|
|
|
|
});
|
2018-05-30 15:08:12 +00:00
|
|
|
_changeLanguage->toggle(
|
2019-11-26 14:27:09 +00:00
|
|
|
!_resetAccount && !_terms && _nextShown,
|
2018-05-30 15:08:12 +00:00
|
|
|
anim::type::normal);
|
2017-05-30 13:54:05 +00:00
|
|
|
updateControlsGeometry();
|
2017-05-30 09:31:40 +00:00
|
|
|
};
|
|
|
|
|
2020-09-30 09:11:44 +00:00
|
|
|
const auto currentId = Lang::LanguageIdOrDefault(Lang::Id());
|
2018-10-22 11:13:48 +00:00
|
|
|
const auto defaultId = Lang::DefaultLanguageId();
|
|
|
|
const auto suggested = Lang::CurrentCloudManager().suggestedLanguage();
|
|
|
|
if (currentId != defaultId) {
|
2019-06-19 15:42:16 +00:00
|
|
|
createLink(
|
|
|
|
Lang::GetOriginalValue(tr::lng_switch_to_this.base),
|
|
|
|
defaultId);
|
2019-11-27 08:02:56 +00:00
|
|
|
} else if (!suggested.isEmpty() && suggested != currentId && _api) {
|
|
|
|
_api->request(MTPlangpack_GetStrings(
|
2018-08-20 11:31:40 +00:00
|
|
|
MTP_string(Lang::CloudLangPackName()),
|
2018-10-22 11:13:48 +00:00
|
|
|
MTP_string(suggested),
|
2018-04-07 08:47:08 +00:00
|
|
|
MTP_vector<MTPstring>(1, MTP_string("lng_switch_to_this"))
|
|
|
|
)).done([=](const MTPVector<MTPLangPackString> &result) {
|
2019-06-19 15:42:16 +00:00
|
|
|
const auto strings = Lang::Instance::ParseStrings(result);
|
|
|
|
const auto i = strings.find(tr::lng_switch_to_this.base);
|
|
|
|
if (i != strings.end()) {
|
|
|
|
createLink(i->second, suggested);
|
2017-05-30 09:31:40 +00:00
|
|
|
}
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-26 11:10:44 +00:00
|
|
|
void Widget::checkUpdateStatus() {
|
2018-07-11 22:14:44 +00:00
|
|
|
Expects(!Core::UpdaterDisabled());
|
|
|
|
|
2018-04-26 16:14:21 +00:00
|
|
|
if (Core::UpdateChecker().state() == Core::UpdateChecker::State::Ready) {
|
2016-11-05 08:36:24 +00:00
|
|
|
if (_update) return;
|
2017-09-30 18:26:45 +00:00
|
|
|
_update.create(
|
|
|
|
this,
|
|
|
|
object_ptr<Ui::RoundButton>(
|
|
|
|
this,
|
2019-06-18 16:53:27 +00:00
|
|
|
tr::lng_menu_update(),
|
2017-09-30 18:26:45 +00:00
|
|
|
st::defaultBoxButton));
|
2017-09-30 19:20:40 +00:00
|
|
|
if (!_a_show.animating()) {
|
|
|
|
_update->setVisible(true);
|
|
|
|
}
|
2018-05-29 18:12:23 +00:00
|
|
|
const auto stepHasCover = getStep()->hasCover();
|
|
|
|
_update->toggle(!stepHasCover, anim::type::instant);
|
2016-11-24 19:28:23 +00:00
|
|
|
_update->entity()->setClickedCallback([] {
|
2018-04-26 16:14:21 +00:00
|
|
|
Core::checkReadyUpdate();
|
2022-01-27 12:48:51 +00:00
|
|
|
Core::Restart();
|
2016-11-05 08:36:24 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if (!_update) return;
|
|
|
|
_update.destroy();
|
|
|
|
}
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::setInnerFocus() {
|
|
|
|
if (getStep()->animating()) {
|
|
|
|
setFocus();
|
|
|
|
} else {
|
|
|
|
getStep()->setInnerFocus();
|
|
|
|
}
|
2016-03-14 16:59:18 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 14:55:08 +00:00
|
|
|
void Widget::historyMove(StackAction action, Animate animate) {
|
2019-11-26 11:10:44 +00:00
|
|
|
Expects(_stepHistory.size() > 1);
|
2016-03-14 16:59:18 +00:00
|
|
|
|
2019-11-26 11:10:44 +00:00
|
|
|
if (getStep()->animating()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-03-14 16:59:18 +00:00
|
|
|
|
2020-06-23 14:55:08 +00:00
|
|
|
auto wasStep = getStep((action == StackAction::Back) ? 0 : 1);
|
|
|
|
if (action == StackAction::Back) {
|
2016-03-14 16:59:18 +00:00
|
|
|
_stepHistory.pop_back();
|
2016-11-24 19:28:23 +00:00
|
|
|
wasStep->cancelled();
|
2020-06-23 14:55:08 +00:00
|
|
|
} else if (action == StackAction::Replace) {
|
2019-11-26 11:10:44 +00:00
|
|
|
_stepHistory.erase(_stepHistory.end() - 2);
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
2018-06-01 07:00:18 +00:00
|
|
|
|
|
|
|
if (_resetAccount) {
|
|
|
|
hideAndDestroy(std::exchange(_resetAccount, { nullptr }));
|
|
|
|
}
|
|
|
|
if (_terms) {
|
|
|
|
hideAndDestroy(std::exchange(_terms, { nullptr }));
|
|
|
|
}
|
|
|
|
|
|
|
|
getStep()->finishInit();
|
2016-11-24 19:28:23 +00:00
|
|
|
getStep()->prepareShowAnimated(wasStep);
|
|
|
|
if (wasStep->hasCover() != getStep()->hasCover()) {
|
2019-11-26 11:10:44 +00:00
|
|
|
_nextTopFrom = wasStep->contentTop() + st::introNextTop;
|
2016-11-24 19:28:23 +00:00
|
|
|
_controlsTopFrom = wasStep->hasCover() ? st::introCoverHeight : 0;
|
2016-12-05 11:01:08 +00:00
|
|
|
_coverShownAnimation.start([this] { updateControlsGeometry(); }, 0., 1., st::introCoverDuration, wasStep->hasCover() ? anim::linear : anim::easeOutCirc);
|
2016-03-14 16:59:18 +00:00
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2019-12-31 08:56:41 +00:00
|
|
|
_stepLifetime.destroy();
|
2020-06-23 14:55:08 +00:00
|
|
|
if (action == StackAction::Forward || action == StackAction::Replace) {
|
2016-11-24 19:28:23 +00:00
|
|
|
wasStep->finished();
|
|
|
|
}
|
2020-06-23 14:55:08 +00:00
|
|
|
if (action == StackAction::Back || action == StackAction::Replace) {
|
2016-11-24 19:28:23 +00:00
|
|
|
delete base::take(wasStep);
|
|
|
|
}
|
2017-09-30 19:20:40 +00:00
|
|
|
_back->toggle(getStep()->hasBack(), anim::type::normal);
|
2017-04-14 12:12:40 +00:00
|
|
|
|
|
|
|
auto stepHasCover = getStep()->hasCover();
|
2017-09-30 19:20:40 +00:00
|
|
|
_settings->toggle(!stepHasCover, anim::type::normal);
|
2018-05-30 15:08:12 +00:00
|
|
|
if (_update) {
|
|
|
|
_update->toggle(!stepHasCover, anim::type::normal);
|
|
|
|
}
|
2019-11-26 11:10:44 +00:00
|
|
|
setupNextButton();
|
2018-06-01 07:00:18 +00:00
|
|
|
if (_resetAccount) _resetAccount->show(anim::type::normal);
|
|
|
|
if (_terms) _terms->show(anim::type::normal);
|
2020-06-23 14:55:08 +00:00
|
|
|
getStep()->showAnimated(animate);
|
2016-11-24 19:28:23 +00:00
|
|
|
fixOrder();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2018-05-30 15:08:12 +00:00
|
|
|
void Widget::hideAndDestroy(object_ptr<Ui::FadeWrap<Ui::RpWidget>> widget) {
|
2019-09-13 12:22:54 +00:00
|
|
|
const auto weak = Ui::MakeWeak(widget.data());
|
2018-05-30 15:08:12 +00:00
|
|
|
widget->hide(anim::type::normal);
|
|
|
|
widget->shownValue(
|
|
|
|
) | rpl::start_with_next([=](bool shown) {
|
|
|
|
if (!shown && weak) {
|
|
|
|
weak->deleteLater();
|
|
|
|
}
|
|
|
|
}, widget->lifetime());
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::fixOrder() {
|
|
|
|
_next->raise();
|
|
|
|
if (_update) _update->raise();
|
2019-11-26 14:27:09 +00:00
|
|
|
if (_changeLanguage) _changeLanguage->raise();
|
2016-11-24 19:28:23 +00:00
|
|
|
_settings->raise();
|
|
|
|
_back->raise();
|
2020-06-25 14:17:37 +00:00
|
|
|
floatPlayerRaiseAll();
|
2018-05-07 17:44:33 +00:00
|
|
|
_connecting->raise();
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 14:55:08 +00:00
|
|
|
void Widget::moveToStep(Step *step, StackAction action, Animate animate) {
|
2016-11-24 19:28:23 +00:00
|
|
|
appendStep(step);
|
2016-10-26 10:06:00 +00:00
|
|
|
_back->raise();
|
2016-11-05 08:36:24 +00:00
|
|
|
_settings->raise();
|
|
|
|
if (_update) {
|
|
|
|
_update->raise();
|
|
|
|
}
|
2018-05-07 17:44:33 +00:00
|
|
|
_connecting->raise();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2020-06-23 14:55:08 +00:00
|
|
|
historyMove(action, animate);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::appendStep(Step *step) {
|
|
|
|
_stepHistory.push_back(step);
|
2019-11-26 11:10:44 +00:00
|
|
|
step->setGeometry(rect());
|
2020-06-23 14:55:08 +00:00
|
|
|
step->setGoCallback([=](Step *step, StackAction action, Animate animate) {
|
|
|
|
if (action == StackAction::Back) {
|
2021-08-25 12:31:51 +00:00
|
|
|
backRequested();
|
2016-11-24 19:28:23 +00:00
|
|
|
} else {
|
2020-06-23 14:55:08 +00:00
|
|
|
moveToStep(step, action, animate);
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
});
|
2018-05-30 15:08:12 +00:00
|
|
|
step->setShowResetCallback([=] {
|
2016-11-24 19:28:23 +00:00
|
|
|
showResetButton();
|
|
|
|
});
|
2020-06-26 11:28:06 +00:00
|
|
|
step->setShowTermsCallback([=] {
|
2018-06-01 07:00:18 +00:00
|
|
|
showTerms();
|
2018-05-30 15:08:12 +00:00
|
|
|
});
|
2020-06-26 11:28:06 +00:00
|
|
|
step->setCancelNearestDcCallback([=] {
|
|
|
|
if (_api) {
|
|
|
|
_api->request(base::take(_nearestDcRequestId)).cancel();
|
|
|
|
}
|
|
|
|
});
|
2018-06-04 15:35:11 +00:00
|
|
|
step->setAcceptTermsCallback([=](Fn<void()> callback) {
|
2018-06-01 07:00:18 +00:00
|
|
|
acceptTerms(callback);
|
2018-05-30 15:08:12 +00:00
|
|
|
});
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::showResetButton() {
|
|
|
|
if (!_resetAccount) {
|
2019-06-18 16:53:27 +00:00
|
|
|
auto entity = object_ptr<Ui::RoundButton>(
|
|
|
|
this,
|
|
|
|
tr::lng_signin_reset_account(),
|
|
|
|
st::introResetButton);
|
2018-05-30 15:08:12 +00:00
|
|
|
_resetAccount.create(this, std::move(entity));
|
2017-09-30 19:20:40 +00:00
|
|
|
_resetAccount->hide(anim::type::instant);
|
2016-11-24 19:28:23 +00:00
|
|
|
_resetAccount->entity()->setClickedCallback([this] { resetAccount(); });
|
|
|
|
updateControlsGeometry();
|
2016-04-14 19:24:42 +00:00
|
|
|
}
|
2017-09-30 19:20:40 +00:00
|
|
|
_resetAccount->show(anim::type::normal);
|
2018-05-30 15:08:12 +00:00
|
|
|
if (_changeLanguage) {
|
|
|
|
_changeLanguage->hide(anim::type::normal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-01 07:00:18 +00:00
|
|
|
void Widget::showTerms() {
|
2018-06-03 13:30:40 +00:00
|
|
|
if (getData()->termsLock.text.text.isEmpty()) {
|
2018-06-01 07:00:18 +00:00
|
|
|
_terms.destroy();
|
|
|
|
} else if (!_terms) {
|
|
|
|
auto entity = object_ptr<Ui::FlatLabel>(
|
|
|
|
this,
|
2019-06-18 16:53:27 +00:00
|
|
|
tr::lng_terms_signup(
|
2018-06-01 07:00:18 +00:00
|
|
|
lt_link,
|
2019-06-18 16:53:27 +00:00
|
|
|
tr::lng_terms_signup_link() | Ui::Text::ToLink(),
|
|
|
|
Ui::Text::WithEntities),
|
2018-06-01 07:00:18 +00:00
|
|
|
st::introTermsLabel);
|
|
|
|
_terms.create(this, std::move(entity));
|
2019-06-12 20:11:41 +00:00
|
|
|
_terms->entity()->setClickHandlerFilter([=](
|
|
|
|
const ClickHandlerPtr &handler,
|
|
|
|
Qt::MouseButton button) {
|
|
|
|
if (button == Qt::LeftButton) {
|
2018-06-01 07:00:18 +00:00
|
|
|
showTerms(nullptr);
|
2019-06-12 20:11:41 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
2018-06-01 07:00:18 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
_terms->hide(anim::type::instant);
|
2018-05-30 15:08:12 +00:00
|
|
|
}
|
|
|
|
if (_changeLanguage) {
|
|
|
|
_changeLanguage->toggle(
|
2019-11-26 14:27:09 +00:00
|
|
|
!_terms && !_resetAccount && _nextShown,
|
2018-05-30 15:08:12 +00:00
|
|
|
anim::type::normal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
void Widget::acceptTerms(Fn<void()> callback) {
|
2018-05-30 15:08:12 +00:00
|
|
|
showTerms(callback);
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::resetAccount() {
|
2019-11-27 08:02:56 +00:00
|
|
|
if (_resetRequest || !_api) {
|
|
|
|
return;
|
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
|
2021-10-18 22:28:08 +00:00
|
|
|
const auto callback = crl::guard(this, [this] {
|
2019-11-27 08:02:56 +00:00
|
|
|
if (_resetRequest) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_resetRequest = _api->request(MTPaccount_DeleteAccount(
|
2022-07-01 09:04:21 +00:00
|
|
|
MTP_flags(0),
|
|
|
|
MTP_string("Forgot password"),
|
|
|
|
MTPInputCheckPasswordSRP()
|
2021-11-26 20:54:46 +00:00
|
|
|
)).done([=] {
|
2017-05-30 09:31:40 +00:00
|
|
|
_resetRequest = 0;
|
|
|
|
|
|
|
|
Ui::hideLayer();
|
2021-01-22 14:19:27 +00:00
|
|
|
if (getData()->phone.isEmpty()) {
|
|
|
|
moveToStep(
|
|
|
|
new QrWidget(this, _account, getData()),
|
|
|
|
StackAction::Replace,
|
|
|
|
Animate::Back);
|
|
|
|
} else {
|
|
|
|
moveToStep(
|
|
|
|
new SignupWidget(this, _account, getData()),
|
|
|
|
StackAction::Replace,
|
|
|
|
Animate::Forward);
|
|
|
|
}
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2017-05-30 09:31:40 +00:00
|
|
|
_resetRequest = 0;
|
|
|
|
|
2019-07-24 08:46:23 +00:00
|
|
|
const auto &type = error.type();
|
2017-05-30 09:31:40 +00:00
|
|
|
if (type.startsWith(qstr("2FA_CONFIRM_WAIT_"))) {
|
2021-10-19 13:00:21 +00:00
|
|
|
const auto seconds = base::StringViewMid(
|
|
|
|
type,
|
2021-10-18 22:28:08 +00:00
|
|
|
qstr("2FA_CONFIRM_WAIT_").size()).toInt();
|
2019-06-19 16:39:25 +00:00
|
|
|
const auto days = (seconds + 59) / 86400;
|
|
|
|
const auto hours = ((seconds + 59) % 86400) / 3600;
|
|
|
|
const auto minutes = ((seconds + 59) % 3600) / 60;
|
2022-03-31 16:45:11 +00:00
|
|
|
auto when = tr::lng_minutes(tr::now, lt_count, minutes);
|
2017-05-30 09:31:40 +00:00
|
|
|
if (days > 0) {
|
2022-03-31 16:45:11 +00:00
|
|
|
const auto daysCount = tr::lng_days(
|
2019-06-19 16:39:25 +00:00
|
|
|
tr::now,
|
|
|
|
lt_count,
|
|
|
|
days);
|
2022-03-31 16:45:11 +00:00
|
|
|
const auto hoursCount = tr::lng_hours(
|
2019-06-19 16:39:25 +00:00
|
|
|
tr::now,
|
|
|
|
lt_count,
|
|
|
|
hours);
|
|
|
|
when = tr::lng_signin_reset_in_days(
|
|
|
|
tr::now,
|
|
|
|
lt_days_count,
|
|
|
|
daysCount,
|
|
|
|
lt_hours_count,
|
|
|
|
hoursCount,
|
|
|
|
lt_minutes_count,
|
|
|
|
when);
|
2017-05-30 09:31:40 +00:00
|
|
|
} else if (hours > 0) {
|
2022-03-31 16:45:11 +00:00
|
|
|
const auto hoursCount = tr::lng_hours(
|
2019-06-19 16:39:25 +00:00
|
|
|
tr::now,
|
|
|
|
lt_count,
|
|
|
|
hours);
|
|
|
|
when = tr::lng_signin_reset_in_hours(
|
|
|
|
tr::now,
|
|
|
|
lt_hours_count,
|
|
|
|
hoursCount,
|
|
|
|
lt_minutes_count,
|
|
|
|
when);
|
2017-05-30 09:31:40 +00:00
|
|
|
}
|
2022-02-27 08:23:20 +00:00
|
|
|
Ui::show(Ui::MakeInformBox(tr::lng_signin_reset_wait(
|
2019-06-19 16:39:25 +00:00
|
|
|
tr::now,
|
|
|
|
lt_phone_number,
|
2021-07-26 06:32:16 +00:00
|
|
|
Ui::FormatPhone(getData()->phone),
|
2019-06-19 16:39:25 +00:00
|
|
|
lt_when,
|
|
|
|
when)));
|
2017-05-30 09:31:40 +00:00
|
|
|
} else if (type == qstr("2FA_RECENT_CONFIRM")) {
|
2022-02-27 08:23:20 +00:00
|
|
|
Ui::show(Ui::MakeInformBox(
|
|
|
|
tr::lng_signin_reset_cancelled()));
|
2017-05-30 09:31:40 +00:00
|
|
|
} else {
|
|
|
|
Ui::hideLayer();
|
2019-06-18 16:53:27 +00:00
|
|
|
getStep()->showError(rpl::single(Lang::Hard::ServerError()));
|
2017-05-30 09:31:40 +00:00
|
|
|
}
|
|
|
|
}).send();
|
2021-10-18 22:28:08 +00:00
|
|
|
});
|
|
|
|
|
2022-02-27 08:23:20 +00:00
|
|
|
Ui::show(Ui::MakeConfirmBox({
|
|
|
|
.text = tr::lng_signin_sure_reset(),
|
|
|
|
.confirmed = callback,
|
|
|
|
.confirmText = tr::lng_signin_reset(),
|
|
|
|
.confirmStyle = &st::attentionBoxButton,
|
|
|
|
}));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 09:31:40 +00:00
|
|
|
void Widget::getNearestDC() {
|
2019-11-27 08:02:56 +00:00
|
|
|
if (!_api) {
|
|
|
|
return;
|
|
|
|
}
|
2020-06-26 11:28:06 +00:00
|
|
|
_nearestDcRequestId = _api->request(MTPhelp_GetNearestDc(
|
2019-11-27 08:02:56 +00:00
|
|
|
)).done([=](const MTPNearestDc &result) {
|
2020-06-26 11:28:06 +00:00
|
|
|
_nearestDcRequestId = 0;
|
2019-11-27 08:02:56 +00:00
|
|
|
const auto &nearest = result.c_nearestDc();
|
2018-05-30 15:08:12 +00:00
|
|
|
DEBUG_LOG(("Got nearest dc, country: %1, nearest: %2, this: %3"
|
2019-07-05 13:38:38 +00:00
|
|
|
).arg(qs(nearest.vcountry())
|
|
|
|
).arg(nearest.vnearest_dc().v
|
|
|
|
).arg(nearest.vthis_dc().v));
|
2019-07-24 08:46:23 +00:00
|
|
|
_account->suggestMainDcId(nearest.vnearest_dc().v);
|
2019-08-09 10:06:27 +00:00
|
|
|
const auto nearestCountry = qs(nearest.vcountry());
|
2017-05-30 09:31:40 +00:00
|
|
|
if (getData()->country != nearestCountry) {
|
|
|
|
getData()->country = nearestCountry;
|
2021-05-25 13:27:23 +00:00
|
|
|
getData()->updated.fire({});
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
2017-05-30 09:31:40 +00:00
|
|
|
}).send();
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
void Widget::showTerms(Fn<void()> callback) {
|
2018-06-03 13:30:40 +00:00
|
|
|
if (getData()->termsLock.text.text.isEmpty()) {
|
2018-05-30 15:08:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-09-13 12:22:54 +00:00
|
|
|
const auto weak = Ui::MakeWeak(this);
|
2018-06-03 13:30:40 +00:00
|
|
|
const auto box = Ui::show(callback
|
|
|
|
? Box<Window::TermsBox>(
|
|
|
|
getData()->termsLock,
|
2019-06-18 16:53:27 +00:00
|
|
|
tr::lng_terms_agree(),
|
|
|
|
tr::lng_terms_decline())
|
2018-06-03 13:30:40 +00:00
|
|
|
: Box<Window::TermsBox>(
|
|
|
|
getData()->termsLock.text,
|
2019-06-18 16:53:27 +00:00
|
|
|
tr::lng_box_ok(),
|
2018-06-03 13:30:40 +00:00
|
|
|
nullptr));
|
|
|
|
|
|
|
|
box->setCloseByEscape(false);
|
|
|
|
box->setCloseByOutsideClick(false);
|
2018-06-01 07:00:18 +00:00
|
|
|
|
|
|
|
box->agreeClicks(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
if (box) {
|
|
|
|
box->closeBox();
|
|
|
|
}
|
|
|
|
}, box->lifetime());
|
|
|
|
|
|
|
|
box->cancelClicks(
|
|
|
|
) | rpl::start_with_next([=] {
|
2018-06-03 13:30:40 +00:00
|
|
|
const auto box = Ui::show(Box<Window::TermsBox>(
|
2019-06-19 15:09:03 +00:00
|
|
|
TextWithEntities{ tr::lng_terms_signup_sorry(tr::now) },
|
2019-06-18 16:53:27 +00:00
|
|
|
tr::lng_intro_finish(),
|
|
|
|
tr::lng_terms_decline()));
|
2018-05-30 15:08:12 +00:00
|
|
|
box->agreeClicks(
|
|
|
|
) | rpl::start_with_next([=] {
|
2018-06-01 07:00:18 +00:00
|
|
|
if (weak) {
|
|
|
|
showTerms(callback);
|
2018-05-30 15:08:12 +00:00
|
|
|
}
|
2018-06-01 07:00:18 +00:00
|
|
|
}, box->lifetime());
|
|
|
|
box->cancelClicks(
|
|
|
|
) | rpl::start_with_next([=] {
|
2018-05-30 15:08:12 +00:00
|
|
|
if (box) {
|
|
|
|
box->closeBox();
|
|
|
|
}
|
|
|
|
}, box->lifetime());
|
2018-06-01 07:00:18 +00:00
|
|
|
}, box->lifetime());
|
2018-05-30 15:08:12 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::showControls() {
|
|
|
|
getStep()->show();
|
2019-11-26 11:10:44 +00:00
|
|
|
setupNextButton();
|
2020-06-25 15:01:10 +00:00
|
|
|
_next->toggle(_nextShown, anim::type::instant);
|
2019-11-26 11:10:44 +00:00
|
|
|
_nextShownAnimation.stop();
|
2018-05-07 17:44:33 +00:00
|
|
|
_connecting->setForceHidden(false);
|
2017-03-15 15:10:18 +00:00
|
|
|
auto hasCover = getStep()->hasCover();
|
2017-09-30 19:20:40 +00:00
|
|
|
_settings->toggle(!hasCover, anim::type::instant);
|
2018-05-30 15:08:12 +00:00
|
|
|
if (_update) {
|
|
|
|
_update->toggle(!hasCover, anim::type::instant);
|
|
|
|
}
|
|
|
|
if (_changeLanguage) {
|
|
|
|
_changeLanguage->toggle(
|
2019-11-26 14:27:09 +00:00
|
|
|
!_resetAccount && !_terms && _nextShown,
|
2018-05-30 15:08:12 +00:00
|
|
|
anim::type::instant);
|
|
|
|
}
|
2018-06-01 07:00:18 +00:00
|
|
|
if (_terms) {
|
|
|
|
_terms->show(anim::type::instant);
|
|
|
|
}
|
2017-09-30 19:20:40 +00:00
|
|
|
_back->toggle(getStep()->hasBack(), anim::type::instant);
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2019-11-26 11:10:44 +00:00
|
|
|
void Widget::setupNextButton() {
|
2019-11-26 11:39:54 +00:00
|
|
|
_next->entity()->setText(getStep()->nextButtonText(
|
2019-11-26 11:10:44 +00:00
|
|
|
) | rpl::filter([](const QString &text) {
|
|
|
|
return !text.isEmpty();
|
|
|
|
}));
|
2019-12-31 08:56:41 +00:00
|
|
|
getStep()->nextButtonText(
|
2019-11-26 11:10:44 +00:00
|
|
|
) | rpl::map([](const QString &text) {
|
|
|
|
return !text.isEmpty();
|
2019-12-31 08:56:41 +00:00
|
|
|
}) | rpl::filter([=](bool visible) {
|
2019-11-26 14:27:09 +00:00
|
|
|
return visible != _nextShown;
|
|
|
|
}) | rpl::start_with_next([=](bool visible) {
|
2019-11-26 11:39:54 +00:00
|
|
|
_next->toggle(visible, anim::type::normal);
|
2019-11-26 11:10:44 +00:00
|
|
|
_nextShown = visible;
|
2019-11-26 14:27:09 +00:00
|
|
|
if (_changeLanguage) {
|
|
|
|
_changeLanguage->toggle(
|
|
|
|
!_resetAccount && !_terms && _nextShown,
|
|
|
|
anim::type::normal);
|
|
|
|
}
|
2019-11-26 11:10:44 +00:00
|
|
|
_nextShownAnimation.start(
|
|
|
|
[=] { updateControlsGeometry(); },
|
|
|
|
_nextShown ? 0. : 1.,
|
|
|
|
_nextShown ? 1. : 0.,
|
|
|
|
st::slideDuration);
|
2019-12-31 08:56:41 +00:00
|
|
|
}, _stepLifetime);
|
2019-11-26 11:10:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::hideControls() {
|
|
|
|
getStep()->hide();
|
2019-11-26 11:39:54 +00:00
|
|
|
_next->hide(anim::type::instant);
|
2018-05-07 17:44:33 +00:00
|
|
|
_connecting->setForceHidden(true);
|
2017-09-30 19:20:40 +00:00
|
|
|
_settings->hide(anim::type::instant);
|
|
|
|
if (_update) _update->hide(anim::type::instant);
|
|
|
|
if (_changeLanguage) _changeLanguage->hide(anim::type::instant);
|
2018-06-01 07:00:18 +00:00
|
|
|
if (_terms) _terms->hide(anim::type::instant);
|
2017-09-30 19:20:40 +00:00
|
|
|
_back->hide(anim::type::instant);
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void Widget::showAnimated(const QPixmap &bgAnimCache, bool back) {
|
|
|
|
_showBack = back;
|
2016-11-24 19:28:23 +00:00
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
(_showBack ? _cacheOver : _cacheUnder) = bgAnimCache;
|
2016-11-24 19:28:23 +00:00
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
_a_show.stop();
|
2016-11-24 19:28:23 +00:00
|
|
|
showControls();
|
2020-06-25 14:17:37 +00:00
|
|
|
floatPlayerHideAll();
|
2017-12-26 12:41:48 +00:00
|
|
|
(_showBack ? _cacheUnder : _cacheOver) = Ui::GrabWidget(this);
|
2016-11-24 19:28:23 +00:00
|
|
|
hideControls();
|
2020-06-25 14:17:37 +00:00
|
|
|
floatPlayerShowVisible();
|
2015-10-17 14:52:26 +00:00
|
|
|
|
2019-11-26 11:10:44 +00:00
|
|
|
_a_show.start(
|
|
|
|
[=] { animationCallback(); },
|
|
|
|
0.,
|
|
|
|
1.,
|
|
|
|
st::slideDuration,
|
|
|
|
Window::SlideAnimation::transition());
|
2015-10-17 14:52:26 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
show();
|
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void Widget::animationCallback() {
|
|
|
|
update();
|
|
|
|
if (!_a_show.animating()) {
|
2015-10-17 14:52:26 +00:00
|
|
|
_cacheUnder = _cacheOver = QPixmap();
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
showControls();
|
|
|
|
getStep()->activate();
|
2015-10-17 14:52:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::paintEvent(QPaintEvent *e) {
|
2014-05-30 08:53:19 +00:00
|
|
|
bool trivial = (rect() == e->rect());
|
|
|
|
setMouseTracking(true);
|
|
|
|
|
|
|
|
QPainter p(this);
|
|
|
|
if (!trivial) {
|
|
|
|
p.setClipRect(e->rect());
|
|
|
|
}
|
2016-10-31 12:29:26 +00:00
|
|
|
p.fillRect(e->rect(), st::windowBg);
|
2019-04-02 09:13:30 +00:00
|
|
|
auto progress = _a_show.value(1.);
|
2015-10-17 14:52:26 +00:00
|
|
|
if (_a_show.animating()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto coordUnder = _showBack ? anim::interpolate(-st::slideShift, 0, progress) : anim::interpolate(0, -st::slideShift, progress);
|
|
|
|
auto coordOver = _showBack ? anim::interpolate(0, width(), progress) : anim::interpolate(width(), 0, progress);
|
|
|
|
auto shadow = _showBack ? (1. - progress) : progress;
|
|
|
|
if (coordOver > 0) {
|
|
|
|
p.drawPixmap(QRect(0, 0, coordOver, height()), _cacheUnder, QRect(-coordUnder * cRetinaFactor(), 0, coordOver * cRetinaFactor(), height() * cRetinaFactor()));
|
|
|
|
p.setOpacity(shadow);
|
|
|
|
p.fillRect(0, 0, coordOver, height(), st::slideFadeOutBg);
|
2015-10-17 14:52:26 +00:00
|
|
|
p.setOpacity(1);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
p.drawPixmap(coordOver, 0, _cacheOver);
|
|
|
|
p.setOpacity(shadow);
|
|
|
|
st::slideShadow.fill(p, QRect(coordOver - st::slideShadow.width(), 0, st::slideShadow.width(), height()));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::resizeEvent(QResizeEvent *e) {
|
2020-07-02 06:42:09 +00:00
|
|
|
if (_stepHistory.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-11-26 11:10:44 +00:00
|
|
|
for (const auto step : _stepHistory) {
|
|
|
|
step->setGeometry(rect());
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
updateControlsGeometry();
|
2020-06-25 14:17:37 +00:00
|
|
|
floatPlayerAreaUpdated();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
void Widget::updateControlsGeometry() {
|
2019-04-02 09:13:30 +00:00
|
|
|
auto shown = _coverShownAnimation.value(1.);
|
2016-11-24 19:28:23 +00:00
|
|
|
|
|
|
|
auto controlsTopTo = getStep()->hasCover() ? st::introCoverHeight : 0;
|
|
|
|
auto controlsTop = anim::interpolate(_controlsTopFrom, controlsTopTo, shown);
|
|
|
|
_settings->moveToRight(st::introSettingsSkip, controlsTop + st::introSettingsSkip);
|
|
|
|
if (_update) {
|
|
|
|
_update->moveToRight(st::introSettingsSkip + _settings->width() + st::introSettingsSkip, _settings->y());
|
|
|
|
}
|
|
|
|
_back->moveToLeft(0, controlsTop);
|
|
|
|
|
2019-11-26 11:10:44 +00:00
|
|
|
auto nextTopTo = getStep()->contentTop() + st::introNextTop;
|
2016-11-24 19:28:23 +00:00
|
|
|
auto nextTop = anim::interpolate(_nextTopFrom, nextTopTo, shown);
|
2019-11-26 11:10:44 +00:00
|
|
|
const auto shownAmount = _nextShownAnimation.value(_nextShown ? 1. : 0.);
|
2019-11-26 11:39:54 +00:00
|
|
|
const auto realNextTop = anim::interpolate(
|
|
|
|
nextTop + st::introNextSlide,
|
|
|
|
nextTop,
|
|
|
|
shownAmount);
|
2019-11-26 11:10:44 +00:00
|
|
|
_next->moveToLeft((width() - _next->width()) / 2, realNextTop);
|
2019-11-29 13:42:42 +00:00
|
|
|
getStep()->setShowAnimationClipping(shownAmount > 0
|
|
|
|
? QRect(0, 0, width(), realNextTop)
|
|
|
|
: QRect());
|
2016-11-24 19:28:23 +00:00
|
|
|
if (_changeLanguage) {
|
|
|
|
_changeLanguage->moveToLeft((width() - _changeLanguage->width()) / 2, _next->y() + _next->height() + _changeLanguage->height());
|
|
|
|
}
|
|
|
|
if (_resetAccount) {
|
|
|
|
_resetAccount->moveToLeft((width() - _resetAccount->width()) / 2, height() - st::introResetBottom - _resetAccount->height());
|
|
|
|
}
|
2018-05-30 15:08:12 +00:00
|
|
|
if (_terms) {
|
|
|
|
_terms->moveToLeft((width() - _terms->width()) / 2, height() - st::introTermsBottom - _terms->height());
|
|
|
|
}
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::keyPressEvent(QKeyEvent *e) {
|
|
|
|
if (_a_show.animating() || getStep()->animating()) return;
|
|
|
|
|
2018-09-27 14:28:57 +00:00
|
|
|
if (e->key() == Qt::Key_Escape || e->key() == Qt::Key_Back) {
|
2016-11-24 19:28:23 +00:00
|
|
|
if (getStep()->hasBack()) {
|
2020-06-23 14:55:08 +00:00
|
|
|
backRequested();
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
2018-09-27 14:28:57 +00:00
|
|
|
} else if (e->key() == Qt::Key_Enter
|
|
|
|
|| e->key() == Qt::Key_Return
|
|
|
|
|| e->key() == Qt::Key_Space) {
|
2016-11-24 19:28:23 +00:00
|
|
|
getStep()->submit();
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 14:55:08 +00:00
|
|
|
void Widget::backRequested() {
|
|
|
|
if (_stepHistory.size() > 1) {
|
|
|
|
historyMove(StackAction::Back, Animate::Back);
|
|
|
|
} else if (const auto parent
|
|
|
|
= Core::App().domain().maybeLastOrSomeAuthedAccount()) {
|
|
|
|
Core::App().domain().activate(parent);
|
|
|
|
} else {
|
|
|
|
moveToStep(
|
|
|
|
new StartWidget(this, _account, getData()),
|
|
|
|
StackAction::Replace,
|
|
|
|
Animate::Back);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
Widget::~Widget() {
|
|
|
|
for (auto step : base::take(_stepHistory)) {
|
|
|
|
delete step;
|
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
} // namespace Intro
|