From 7e3c54f8d0e63a986ce823de167433596d10e15d Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 5 May 2022 21:45:49 +0300 Subject: [PATCH] Added common initial helpers for steps of cloud password settings. --- Telegram/CMakeLists.txt | 2 + Telegram/Resources/langs/lang.strings | 21 ++ .../settings_cloud_password_common.cpp | 182 ++++++++++++++++++ .../settings_cloud_password_common.h | 97 ++++++++++ Telegram/SourceFiles/settings/settings.style | 1 + 5 files changed, 303 insertions(+) create mode 100644 Telegram/SourceFiles/settings/cloud_password/settings_cloud_password_common.cpp create mode 100644 Telegram/SourceFiles/settings/cloud_password/settings_cloud_password_common.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 5b11282a3..3ec7f0064 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -1072,6 +1072,8 @@ PRIVATE profile/profile_block_widget.h profile/profile_cover_drop_area.cpp profile/profile_cover_drop_area.h + settings/cloud_password/settings_cloud_password_common.cpp + settings/cloud_password/settings_cloud_password_common.h settings/settings_advanced.cpp settings/settings_advanced.h settings/settings_blocked_peers.cpp diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index f8920317a..bdd301827 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -541,6 +541,27 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_security_bots" = "Bots and websites"; "lng_settings_clear_payment_info" = "Clear Payment and Shipping Info"; +"lng_settings_cloud_password_on" = "On"; +"lng_settings_cloud_password_off" = "Off"; +"lng_settings_cloud_password_start_title" = "Two-Step Verification"; +"lng_settings_cloud_password_password_title" = "Password"; +"lng_settings_cloud_password_hint_title" = "Password Hint"; +"lng_settings_cloud_password_email_title" = "Recovery Email"; +"lng_settings_cloud_password_start_about" = "Protect your Telegram account with an additional password."; +"lng_settings_cloud_password_hint_about" = "You can create a hint for your password."; +"lng_settings_cloud_password_email_about" = "Please enter your new recovery email. It is the only way to recover a forgotten password."; +"lng_settings_cloud_password_password_subtitle" = "Create Password"; +"lng_settings_cloud_password_check_subtitle" = "Your Password"; +"lng_settings_cloud_password_hint_subtitle" = "Add Password Hint"; +"lng_settings_cloud_password_email_subtitle" = "Add Recovery Email"; +"lng_settings_cloud_password_email_recovery_subtitle" = "Password Recovery"; +"lng_settings_cloud_password_manage_about1" = "You have Two-Step Verification enabled, so your account is protected with an additional password."; +"lng_settings_cloud_password_manage_about2" = "This email is the only way to recover a forgotten password."; +"lng_settings_cloud_password_manage_disable_sure" = "Are you sure you want to disable your password?"; +"lng_settings_cloud_password_manage_email_new" = "Set Recovery Email"; +"lng_settings_cloud_password_manage_email_change" = "Change Recovery Email"; +"lng_settings_cloud_password_manage_password_change" = "Change Password"; + "lng_clear_payment_info_title" = "Clear payment info"; "lng_clear_payment_info_sure" = "Are you sure you want to clear your payment and shipping info?"; "lng_clear_payment_info_shipping" = "Shipping info"; diff --git a/Telegram/SourceFiles/settings/cloud_password/settings_cloud_password_common.cpp b/Telegram/SourceFiles/settings/cloud_password/settings_cloud_password_common.cpp new file mode 100644 index 000000000..12d7300cc --- /dev/null +++ b/Telegram/SourceFiles/settings/cloud_password/settings_cloud_password_common.cpp @@ -0,0 +1,182 @@ +/* +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 +*/ +#include "settings/cloud_password/settings_cloud_password_common.h" + +#include "lang/lang_keys.h" +#include "lottie/lottie_icon.h" +#include "settings/settings_common.h" +#include "ui/widgets/buttons.h" +#include "ui/widgets/input_fields.h" +#include "ui/widgets/labels.h" +#include "ui/wrap/vertical_layout.h" +#include "styles/style_boxes.h" +#include "styles/style_layers.h" +#include "styles/style_settings.h" + +namespace Settings::CloudPassword { + +void SetupHeader( + not_null content, + const QString &lottie, + rpl::producer<> &&showFinished, + rpl::producer &&subtitle, + rpl::producer &&about) { + if (!lottie.isEmpty()) { + const auto &size = st::settingsCloudPasswordIconSize; + auto icon = CreateLottieIcon( + content, + { .name = lottie, .sizeOverride = { size, size } }, + st::settingLocalPasscodeIconPadding); + content->add(std::move(icon.widget)); + std::move( + showFinished + ) | rpl::start_with_next([animate = std::move(icon.animate)] { + animate(anim::repeat::once); + }, content->lifetime()); + + AddSkip(content); + } + + content->add( + object_ptr>( + content, + object_ptr( + content, + std::move(subtitle), + st::changePhoneTitle)), + st::changePhoneTitlePadding); + + { + const auto &st = st::settingLocalPasscodeDescription; + content->add( + object_ptr>( + content, + object_ptr(content, std::move(about), st)), + st::changePhoneDescriptionPadding); + } +} + +not_null AddPasswordField( + not_null content, + rpl::producer &&placeholder, + const QString &text) { + const auto &st = st::settingLocalPasscodeInputField; + auto container = object_ptr(content); + container->resize(container->width(), st.heightMin); + const auto field = Ui::CreateChild( + container.data(), + st, + std::move(placeholder), + text); + + container->geometryValue( + ) | rpl::start_with_next([=](const QRect &r) { + field->moveToLeft((r.width() - field->width()) / 2, 0); + }, container->lifetime()); + + content->add(std::move(container)); + return field; +} + +not_null AddError( + not_null content, + Ui::PasswordInput *input) { + const auto error = content->add( + object_ptr>( + content, + object_ptr( + content, + // Set any text to resize. + tr::lng_language_name(tr::now), + st::settingLocalPasscodeError)), + st::changePhoneDescriptionPadding)->entity(); + error->hide(); + if (input) { + QObject::connect(input, &Ui::MaskedInputField::changed, [=] { + error->hide(); + }); + } + return error; +}; + +not_null AddDoneButton( + not_null content, + rpl::producer &&text) { + const auto button = content->add( + object_ptr>( + content, + object_ptr( + content, + std::move(text), + st::changePhoneButton)), + st::settingLocalPasscodeButtonPadding)->entity(); + button->setTextTransform(Ui::RoundButton::TextTransform::NoTransform); + return button; +} + +void AddSkipInsteadOfField(not_null content) { + AddSkip(content, st::settingLocalPasscodeInputField.heightMin); +} + +void AddSkipInsteadOfError(not_null content) { + auto dummy = base::make_unique_q( + content, + tr::lng_language_name(tr::now), + st::settingLocalPasscodeError); + AddSkip(content, dummy->height()); + dummy = nullptr; +} + +AbstractStep::AbstractStep( + QWidget *parent, + not_null controller) +: AbstractSection(parent) +, _controller(controller) { +} + +not_null AbstractStep::controller() const { + return _controller; +} + +void AbstractStep::showBack() { + _showBack.fire({}); +} + +void AbstractStep::showOther(Type type) { + _showOther.fire_copy(type); +} + +void AbstractStep::setFocusCallback(Fn callback) { + _setInnerFocusCallback = callback; +} + +rpl::producer<> AbstractStep::showFinishes() const { + return _showFinished.events(); +} + +void AbstractStep::showFinished() { + _showFinished.fire({}); +} + +void AbstractStep::setInnerFocus() { + if (_setInnerFocusCallback) { + _setInnerFocusCallback(); + } +} + +rpl::producer AbstractStep::sectionShowOther() { + return _showOther.events(); +} + +rpl::producer<> AbstractStep::sectionShowBack() { + return _showBack.events(); +} + +AbstractStep::~AbstractStep() = default; + +} // namespace Settings::CloudPassword diff --git a/Telegram/SourceFiles/settings/cloud_password/settings_cloud_password_common.h b/Telegram/SourceFiles/settings/cloud_password/settings_cloud_password_common.h new file mode 100644 index 000000000..29912658c --- /dev/null +++ b/Telegram/SourceFiles/settings/cloud_password/settings_cloud_password_common.h @@ -0,0 +1,97 @@ +/* +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 + +#include "settings/settings_common.h" + +namespace Ui { +class FlatLabel; +class PasswordInput; +class RoundButton; +class VerticalLayout; +} // namespace Ui + +namespace Settings::CloudPassword { + +void SetupHeader( + not_null content, + const QString &lottie, + rpl::producer<> &&showFinished, + rpl::producer &&subtitle, + rpl::producer &&about); + +[[nodiscard]] not_null AddPasswordField( + not_null content, + rpl::producer &&placeholder, + const QString &text); + +[[nodiscard]] not_null AddError( + not_null content, + Ui::PasswordInput *input); + +[[nodiscard]] not_null AddDoneButton( + not_null content, + rpl::producer &&text); + +void AddSkipInsteadOfField(not_null content); +void AddSkipInsteadOfError(not_null content); + +class AbstractStep : public AbstractSection { +public: + AbstractStep( + QWidget *parent, + not_null controller); + ~AbstractStep(); + + void showFinished() override; + void setInnerFocus() override; + [[nodiscard]] rpl::producer sectionShowOther() override; + [[nodiscard]] rpl::producer<> sectionShowBack() override; + +protected: + [[nodiscard]] not_null controller() const; + + void showBack(); + void showOther(Type type); + + void setFocusCallback(Fn callback); + + [[nodiscard]] rpl::producer<> showFinishes() const; + +private: + const not_null _controller; + + Fn _setInnerFocusCallback; + + rpl::event_stream<> _showFinished; + rpl::event_stream _showOther; + rpl::event_stream<> _showBack; + +}; + +template +class TypedAbstractStep : public AbstractStep { +public: + TypedAbstractStep( + QWidget *parent, + not_null controller) + : AbstractStep(parent, controller) { + static_cast(this)->setupContent(); + } + + [[nodiscard]] static Type Id() { + return &SectionMetaImplementation::Meta; + } + [[nodiscard]] Type id() const final override { + return Id(); + } + +}; + +} // namespace Settings::CloudPassword + diff --git a/Telegram/SourceFiles/settings/settings.style b/Telegram/SourceFiles/settings/settings.style index 5f95d04f2..e507c9191 100644 --- a/Telegram/SourceFiles/settings/settings.style +++ b/Telegram/SourceFiles/settings/settings.style @@ -141,6 +141,7 @@ settingsCloudPasswordLabel: FlatLabel(defaultFlatLabel) { maxHeight: 20px; } settingsCloudPasswordLabelPadding: margins(22px, 8px, 10px, 8px); +settingsCloudPasswordIconSize: 100px; settingLocalPasscodeInputField: InputField(defaultInputField) { width: 256px;