mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added common initial helpers for steps of cloud password settings.
This commit is contained in:
parent
540ee0bc44
commit
7e3c54f8d0
5 changed files with 303 additions and 0 deletions
|
@ -1072,6 +1072,8 @@ PRIVATE
|
||||||
profile/profile_block_widget.h
|
profile/profile_block_widget.h
|
||||||
profile/profile_cover_drop_area.cpp
|
profile/profile_cover_drop_area.cpp
|
||||||
profile/profile_cover_drop_area.h
|
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.cpp
|
||||||
settings/settings_advanced.h
|
settings/settings_advanced.h
|
||||||
settings/settings_blocked_peers.cpp
|
settings/settings_blocked_peers.cpp
|
||||||
|
|
|
@ -541,6 +541,27 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_settings_security_bots" = "Bots and websites";
|
"lng_settings_security_bots" = "Bots and websites";
|
||||||
"lng_settings_clear_payment_info" = "Clear Payment and Shipping Info";
|
"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_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_sure" = "Are you sure you want to clear your payment and shipping info?";
|
||||||
"lng_clear_payment_info_shipping" = "Shipping info";
|
"lng_clear_payment_info_shipping" = "Shipping info";
|
||||||
|
|
|
@ -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<Ui::VerticalLayout*> content,
|
||||||
|
const QString &lottie,
|
||||||
|
rpl::producer<> &&showFinished,
|
||||||
|
rpl::producer<QString> &&subtitle,
|
||||||
|
rpl::producer<QString> &&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<Ui::CenterWrap<>>(
|
||||||
|
content,
|
||||||
|
object_ptr<Ui::FlatLabel>(
|
||||||
|
content,
|
||||||
|
std::move(subtitle),
|
||||||
|
st::changePhoneTitle)),
|
||||||
|
st::changePhoneTitlePadding);
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto &st = st::settingLocalPasscodeDescription;
|
||||||
|
content->add(
|
||||||
|
object_ptr<Ui::CenterWrap<>>(
|
||||||
|
content,
|
||||||
|
object_ptr<Ui::FlatLabel>(content, std::move(about), st)),
|
||||||
|
st::changePhoneDescriptionPadding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
not_null<Ui::PasswordInput*> AddPasswordField(
|
||||||
|
not_null<Ui::VerticalLayout*> content,
|
||||||
|
rpl::producer<QString> &&placeholder,
|
||||||
|
const QString &text) {
|
||||||
|
const auto &st = st::settingLocalPasscodeInputField;
|
||||||
|
auto container = object_ptr<Ui::RpWidget>(content);
|
||||||
|
container->resize(container->width(), st.heightMin);
|
||||||
|
const auto field = Ui::CreateChild<Ui::PasswordInput>(
|
||||||
|
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<Ui::FlatLabel*> AddError(
|
||||||
|
not_null<Ui::VerticalLayout*> content,
|
||||||
|
Ui::PasswordInput *input) {
|
||||||
|
const auto error = content->add(
|
||||||
|
object_ptr<Ui::CenterWrap<Ui::FlatLabel>>(
|
||||||
|
content,
|
||||||
|
object_ptr<Ui::FlatLabel>(
|
||||||
|
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<Ui::RoundButton*> AddDoneButton(
|
||||||
|
not_null<Ui::VerticalLayout*> content,
|
||||||
|
rpl::producer<QString> &&text) {
|
||||||
|
const auto button = content->add(
|
||||||
|
object_ptr<Ui::CenterWrap<Ui::RoundButton>>(
|
||||||
|
content,
|
||||||
|
object_ptr<Ui::RoundButton>(
|
||||||
|
content,
|
||||||
|
std::move(text),
|
||||||
|
st::changePhoneButton)),
|
||||||
|
st::settingLocalPasscodeButtonPadding)->entity();
|
||||||
|
button->setTextTransform(Ui::RoundButton::TextTransform::NoTransform);
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddSkipInsteadOfField(not_null<Ui::VerticalLayout*> content) {
|
||||||
|
AddSkip(content, st::settingLocalPasscodeInputField.heightMin);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddSkipInsteadOfError(not_null<Ui::VerticalLayout*> content) {
|
||||||
|
auto dummy = base::make_unique_q<Ui::FlatLabel>(
|
||||||
|
content,
|
||||||
|
tr::lng_language_name(tr::now),
|
||||||
|
st::settingLocalPasscodeError);
|
||||||
|
AddSkip(content, dummy->height());
|
||||||
|
dummy = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
AbstractStep::AbstractStep(
|
||||||
|
QWidget *parent,
|
||||||
|
not_null<Window::SessionController*> controller)
|
||||||
|
: AbstractSection(parent)
|
||||||
|
, _controller(controller) {
|
||||||
|
}
|
||||||
|
|
||||||
|
not_null<Window::SessionController*> AbstractStep::controller() const {
|
||||||
|
return _controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractStep::showBack() {
|
||||||
|
_showBack.fire({});
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractStep::showOther(Type type) {
|
||||||
|
_showOther.fire_copy(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractStep::setFocusCallback(Fn<void()> callback) {
|
||||||
|
_setInnerFocusCallback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<> AbstractStep::showFinishes() const {
|
||||||
|
return _showFinished.events();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractStep::showFinished() {
|
||||||
|
_showFinished.fire({});
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractStep::setInnerFocus() {
|
||||||
|
if (_setInnerFocusCallback) {
|
||||||
|
_setInnerFocusCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<Type> AbstractStep::sectionShowOther() {
|
||||||
|
return _showOther.events();
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<> AbstractStep::sectionShowBack() {
|
||||||
|
return _showBack.events();
|
||||||
|
}
|
||||||
|
|
||||||
|
AbstractStep::~AbstractStep() = default;
|
||||||
|
|
||||||
|
} // namespace Settings::CloudPassword
|
|
@ -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<Ui::VerticalLayout*> content,
|
||||||
|
const QString &lottie,
|
||||||
|
rpl::producer<> &&showFinished,
|
||||||
|
rpl::producer<QString> &&subtitle,
|
||||||
|
rpl::producer<QString> &&about);
|
||||||
|
|
||||||
|
[[nodiscard]] not_null<Ui::PasswordInput*> AddPasswordField(
|
||||||
|
not_null<Ui::VerticalLayout*> content,
|
||||||
|
rpl::producer<QString> &&placeholder,
|
||||||
|
const QString &text);
|
||||||
|
|
||||||
|
[[nodiscard]] not_null<Ui::FlatLabel*> AddError(
|
||||||
|
not_null<Ui::VerticalLayout*> content,
|
||||||
|
Ui::PasswordInput *input);
|
||||||
|
|
||||||
|
[[nodiscard]] not_null<Ui::RoundButton*> AddDoneButton(
|
||||||
|
not_null<Ui::VerticalLayout*> content,
|
||||||
|
rpl::producer<QString> &&text);
|
||||||
|
|
||||||
|
void AddSkipInsteadOfField(not_null<Ui::VerticalLayout*> content);
|
||||||
|
void AddSkipInsteadOfError(not_null<Ui::VerticalLayout*> content);
|
||||||
|
|
||||||
|
class AbstractStep : public AbstractSection {
|
||||||
|
public:
|
||||||
|
AbstractStep(
|
||||||
|
QWidget *parent,
|
||||||
|
not_null<Window::SessionController*> controller);
|
||||||
|
~AbstractStep();
|
||||||
|
|
||||||
|
void showFinished() override;
|
||||||
|
void setInnerFocus() override;
|
||||||
|
[[nodiscard]] rpl::producer<Type> sectionShowOther() override;
|
||||||
|
[[nodiscard]] rpl::producer<> sectionShowBack() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
[[nodiscard]] not_null<Window::SessionController*> controller() const;
|
||||||
|
|
||||||
|
void showBack();
|
||||||
|
void showOther(Type type);
|
||||||
|
|
||||||
|
void setFocusCallback(Fn<void()> callback);
|
||||||
|
|
||||||
|
[[nodiscard]] rpl::producer<> showFinishes() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const not_null<Window::SessionController*> _controller;
|
||||||
|
|
||||||
|
Fn<void()> _setInnerFocusCallback;
|
||||||
|
|
||||||
|
rpl::event_stream<> _showFinished;
|
||||||
|
rpl::event_stream<Type> _showOther;
|
||||||
|
rpl::event_stream<> _showBack;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename SectionType>
|
||||||
|
class TypedAbstractStep : public AbstractStep {
|
||||||
|
public:
|
||||||
|
TypedAbstractStep(
|
||||||
|
QWidget *parent,
|
||||||
|
not_null<Window::SessionController*> controller)
|
||||||
|
: AbstractStep(parent, controller) {
|
||||||
|
static_cast<SectionType*>(this)->setupContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] static Type Id() {
|
||||||
|
return &SectionMetaImplementation<SectionType>::Meta;
|
||||||
|
}
|
||||||
|
[[nodiscard]] Type id() const final override {
|
||||||
|
return Id();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Settings::CloudPassword
|
||||||
|
|
|
@ -141,6 +141,7 @@ settingsCloudPasswordLabel: FlatLabel(defaultFlatLabel) {
|
||||||
maxHeight: 20px;
|
maxHeight: 20px;
|
||||||
}
|
}
|
||||||
settingsCloudPasswordLabelPadding: margins(22px, 8px, 10px, 8px);
|
settingsCloudPasswordLabelPadding: margins(22px, 8px, 10px, 8px);
|
||||||
|
settingsCloudPasswordIconSize: 100px;
|
||||||
|
|
||||||
settingLocalPasscodeInputField: InputField(defaultInputField) {
|
settingLocalPasscodeInputField: InputField(defaultInputField) {
|
||||||
width: 256px;
|
width: 256px;
|
||||||
|
|
Loading…
Add table
Reference in a new issue