Moved out template classes for local passcode from header.
This commit is contained in:
parent
c47140c62d
commit
77d50d9177
|
@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "lottie/lottie_icon.h"
|
#include "lottie/lottie_icon.h"
|
||||||
#include "main/main_domain.h"
|
#include "main/main_domain.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
#include "settings/settings_common.h"
|
||||||
#include "storage/storage_domain.h"
|
#include "storage/storage_domain.h"
|
||||||
#include "ui/boxes/confirm_box.h"
|
#include "ui/boxes/confirm_box.h"
|
||||||
#include "ui/widgets/buttons.h"
|
#include "ui/widgets/buttons.h"
|
||||||
|
@ -91,6 +92,42 @@ void Divider::paintEvent(QPaintEvent *e) {
|
||||||
|
|
||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
|
class LocalPasscodeEnter : public AbstractSection {
|
||||||
|
public:
|
||||||
|
enum class EnterType {
|
||||||
|
Create,
|
||||||
|
Check,
|
||||||
|
Change,
|
||||||
|
};
|
||||||
|
|
||||||
|
LocalPasscodeEnter(
|
||||||
|
QWidget *parent,
|
||||||
|
not_null<Window::SessionController*> controller);
|
||||||
|
~LocalPasscodeEnter();
|
||||||
|
|
||||||
|
void showFinished() override;
|
||||||
|
void setInnerFocus() override;
|
||||||
|
[[nodiscard]] rpl::producer<Type> sectionShowOther() override;
|
||||||
|
[[nodiscard]] rpl::producer<> sectionShowBack() override;
|
||||||
|
|
||||||
|
[[nodiscard]] rpl::producer<QString> title() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void setupContent();
|
||||||
|
|
||||||
|
[[nodiscard]] virtual EnterType enterType() const = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
const not_null<Window::SessionController*> _controller;
|
||||||
|
|
||||||
|
rpl::event_stream<> _showFinished;
|
||||||
|
rpl::event_stream<> _setInnerFocus;
|
||||||
|
rpl::event_stream<Type> _showOther;
|
||||||
|
rpl::event_stream<> _showBack;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
LocalPasscodeEnter::LocalPasscodeEnter(
|
LocalPasscodeEnter::LocalPasscodeEnter(
|
||||||
QWidget *parent,
|
QWidget *parent,
|
||||||
not_null<Window::SessionController*> controller)
|
not_null<Window::SessionController*> controller)
|
||||||
|
@ -246,7 +283,7 @@ void LocalPasscodeEnter::setupContent() {
|
||||||
}
|
}
|
||||||
SetPasscode(_controller, newText);
|
SetPasscode(_controller, newText);
|
||||||
if (isCreate) {
|
if (isCreate) {
|
||||||
_showOther.fire(LocalPasscodeManage::Id());
|
_showOther.fire(LocalPasscodeManageId());
|
||||||
} else if (isChange) {
|
} else if (isChange) {
|
||||||
_showBack.fire({});
|
_showBack.fire({});
|
||||||
}
|
}
|
||||||
|
@ -262,7 +299,7 @@ void LocalPasscodeEnter::setupContent() {
|
||||||
const auto &domain = _controller->session().domain();
|
const auto &domain = _controller->session().domain();
|
||||||
if (domain.local().checkPasscode(newText.toUtf8())) {
|
if (domain.local().checkPasscode(newText.toUtf8())) {
|
||||||
cSetPasscodeBadTries(0);
|
cSetPasscodeBadTries(0);
|
||||||
_showOther.fire(LocalPasscodeManage::Id());
|
_showOther.fire(LocalPasscodeManageId());
|
||||||
} else {
|
} else {
|
||||||
cSetPasscodeBadTries(cPasscodeBadTries() + 1);
|
cSetPasscodeBadTries(cPasscodeBadTries() + 1);
|
||||||
cSetPasscodeLastTry(crl::now());
|
cSetPasscodeLastTry(crl::now());
|
||||||
|
@ -322,6 +359,95 @@ LocalPasscodeEnter::~LocalPasscodeEnter() = default;
|
||||||
|
|
||||||
} // namespace details
|
} // namespace details
|
||||||
|
|
||||||
|
class LocalPasscodeCreate;
|
||||||
|
class LocalPasscodeCheck;
|
||||||
|
class LocalPasscodeChange;
|
||||||
|
|
||||||
|
template <typename SectionType>
|
||||||
|
class TypedLocalPasscodeEnter : public details::LocalPasscodeEnter {
|
||||||
|
public:
|
||||||
|
TypedLocalPasscodeEnter(
|
||||||
|
QWidget *parent,
|
||||||
|
not_null<Window::SessionController*> controller)
|
||||||
|
: details::LocalPasscodeEnter(parent, controller) {
|
||||||
|
setupContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] static Type Id() {
|
||||||
|
return &SectionMetaImplementation<SectionType>::Meta;
|
||||||
|
}
|
||||||
|
[[nodiscard]] Type id() const final override {
|
||||||
|
return Id();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
[[nodiscard]] EnterType enterType() const final override {
|
||||||
|
if constexpr (std::is_same_v<SectionType, LocalPasscodeCreate>) {
|
||||||
|
return EnterType::Create;
|
||||||
|
}
|
||||||
|
if constexpr (std::is_same_v<SectionType, LocalPasscodeCheck>) {
|
||||||
|
return EnterType::Check;
|
||||||
|
}
|
||||||
|
if constexpr (std::is_same_v<SectionType, LocalPasscodeChange>) {
|
||||||
|
return EnterType::Change;
|
||||||
|
}
|
||||||
|
return EnterType::Create;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class LocalPasscodeCreate final
|
||||||
|
: public TypedLocalPasscodeEnter<LocalPasscodeCreate> {
|
||||||
|
public:
|
||||||
|
using TypedLocalPasscodeEnter::TypedLocalPasscodeEnter;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class LocalPasscodeCheck final
|
||||||
|
: public TypedLocalPasscodeEnter<LocalPasscodeCheck> {
|
||||||
|
public:
|
||||||
|
using TypedLocalPasscodeEnter::TypedLocalPasscodeEnter;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class LocalPasscodeChange final
|
||||||
|
: public TypedLocalPasscodeEnter<LocalPasscodeChange> {
|
||||||
|
public:
|
||||||
|
using TypedLocalPasscodeEnter::TypedLocalPasscodeEnter;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class LocalPasscodeManage : public Section<LocalPasscodeManage> {
|
||||||
|
public:
|
||||||
|
LocalPasscodeManage(
|
||||||
|
QWidget *parent,
|
||||||
|
not_null<Window::SessionController*> controller);
|
||||||
|
~LocalPasscodeManage();
|
||||||
|
|
||||||
|
[[nodiscard]] rpl::producer<QString> title() override;
|
||||||
|
|
||||||
|
void showFinished() override;
|
||||||
|
[[nodiscard]] rpl::producer<Type> sectionShowOther() override;
|
||||||
|
[[nodiscard]] rpl::producer<> sectionShowBack() override;
|
||||||
|
|
||||||
|
[[nodiscard]] rpl::producer<std::vector<Type>> removeFromStack() override;
|
||||||
|
|
||||||
|
[[nodiscard]] QPointer<Ui::RpWidget> createPinnedToBottom(
|
||||||
|
not_null<Ui::RpWidget*> parent) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setupContent();
|
||||||
|
|
||||||
|
const not_null<Window::SessionController*> _controller;
|
||||||
|
|
||||||
|
rpl::variable<bool> _isBottomFillerShown;
|
||||||
|
|
||||||
|
rpl::event_stream<> _showFinished;
|
||||||
|
rpl::event_stream<Type> _showOther;
|
||||||
|
rpl::event_stream<> _showBack;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
LocalPasscodeManage::LocalPasscodeManage(
|
LocalPasscodeManage::LocalPasscodeManage(
|
||||||
QWidget *parent,
|
QWidget *parent,
|
||||||
not_null<Window::SessionController*> controller)
|
not_null<Window::SessionController*> controller)
|
||||||
|
@ -491,4 +617,16 @@ rpl::producer<> LocalPasscodeManage::sectionShowBack() {
|
||||||
|
|
||||||
LocalPasscodeManage::~LocalPasscodeManage() = default;
|
LocalPasscodeManage::~LocalPasscodeManage() = default;
|
||||||
|
|
||||||
|
Type LocalPasscodeCreateId() {
|
||||||
|
return LocalPasscodeCreate::Id();
|
||||||
|
}
|
||||||
|
|
||||||
|
Type LocalPasscodeCheckId() {
|
||||||
|
return LocalPasscodeCheck::Id();
|
||||||
|
}
|
||||||
|
|
||||||
|
Type LocalPasscodeManageId() {
|
||||||
|
return LocalPasscodeManage::Id();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Settings
|
} // namespace Settings
|
||||||
|
|
|
@ -7,137 +7,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "settings/settings_common.h"
|
#include "settings/settings_type.h"
|
||||||
|
|
||||||
namespace Settings {
|
namespace Settings {
|
||||||
namespace details {
|
|
||||||
|
|
||||||
class LocalPasscodeEnter : public AbstractSection {
|
Type LocalPasscodeCreateId();
|
||||||
public:
|
Type LocalPasscodeCheckId();
|
||||||
enum class EnterType {
|
Type LocalPasscodeManageId();
|
||||||
Create,
|
|
||||||
Check,
|
|
||||||
Change,
|
|
||||||
};
|
|
||||||
|
|
||||||
LocalPasscodeEnter(
|
|
||||||
QWidget *parent,
|
|
||||||
not_null<Window::SessionController*> controller);
|
|
||||||
~LocalPasscodeEnter();
|
|
||||||
|
|
||||||
void showFinished() override;
|
|
||||||
void setInnerFocus() override;
|
|
||||||
[[nodiscard]] rpl::producer<Type> sectionShowOther() override;
|
|
||||||
[[nodiscard]] rpl::producer<> sectionShowBack() override;
|
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<QString> title() override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void setupContent();
|
|
||||||
|
|
||||||
[[nodiscard]] virtual EnterType enterType() const = 0;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
const not_null<Window::SessionController*> _controller;
|
|
||||||
|
|
||||||
rpl::event_stream<> _showFinished;
|
|
||||||
rpl::event_stream<> _setInnerFocus;
|
|
||||||
rpl::event_stream<Type> _showOther;
|
|
||||||
rpl::event_stream<> _showBack;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace details
|
|
||||||
|
|
||||||
class LocalPasscodeCreate;
|
|
||||||
class LocalPasscodeCheck;
|
|
||||||
class LocalPasscodeChange;
|
|
||||||
|
|
||||||
template <typename SectionType>
|
|
||||||
class TypedLocalPasscodeEnter : public details::LocalPasscodeEnter {
|
|
||||||
public:
|
|
||||||
TypedLocalPasscodeEnter(
|
|
||||||
QWidget *parent,
|
|
||||||
not_null<Window::SessionController*> controller)
|
|
||||||
: details::LocalPasscodeEnter(parent, controller) {
|
|
||||||
setupContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] static Type Id() {
|
|
||||||
return &SectionMetaImplementation<SectionType>::Meta;
|
|
||||||
}
|
|
||||||
[[nodiscard]] Type id() const final override {
|
|
||||||
return Id();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
[[nodiscard]] EnterType enterType() const final override {
|
|
||||||
if constexpr (std::is_same_v<SectionType, LocalPasscodeCreate>) {
|
|
||||||
return EnterType::Create;
|
|
||||||
}
|
|
||||||
if constexpr (std::is_same_v<SectionType, LocalPasscodeCheck>) {
|
|
||||||
return EnterType::Check;
|
|
||||||
}
|
|
||||||
if constexpr (std::is_same_v<SectionType, LocalPasscodeChange>) {
|
|
||||||
return EnterType::Change;
|
|
||||||
}
|
|
||||||
return EnterType::Create;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class LocalPasscodeCreate final
|
|
||||||
: public TypedLocalPasscodeEnter<LocalPasscodeCreate> {
|
|
||||||
public:
|
|
||||||
using TypedLocalPasscodeEnter::TypedLocalPasscodeEnter;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class LocalPasscodeCheck final
|
|
||||||
: public TypedLocalPasscodeEnter<LocalPasscodeCheck> {
|
|
||||||
public:
|
|
||||||
using TypedLocalPasscodeEnter::TypedLocalPasscodeEnter;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class LocalPasscodeChange final
|
|
||||||
: public TypedLocalPasscodeEnter<LocalPasscodeChange> {
|
|
||||||
public:
|
|
||||||
using TypedLocalPasscodeEnter::TypedLocalPasscodeEnter;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class LocalPasscodeManage : public Section<LocalPasscodeManage> {
|
|
||||||
public:
|
|
||||||
LocalPasscodeManage(
|
|
||||||
QWidget *parent,
|
|
||||||
not_null<Window::SessionController*> controller);
|
|
||||||
~LocalPasscodeManage();
|
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<QString> title() override;
|
|
||||||
|
|
||||||
void showFinished() override;
|
|
||||||
[[nodiscard]] rpl::producer<Type> sectionShowOther() override;
|
|
||||||
[[nodiscard]] rpl::producer<> sectionShowBack() override;
|
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<std::vector<Type>> removeFromStack() override;
|
|
||||||
|
|
||||||
[[nodiscard]] QPointer<Ui::RpWidget> createPinnedToBottom(
|
|
||||||
not_null<Ui::RpWidget*> parent) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void setupContent();
|
|
||||||
|
|
||||||
const not_null<Window::SessionController*> _controller;
|
|
||||||
|
|
||||||
rpl::variable<bool> _isBottomFillerShown;
|
|
||||||
|
|
||||||
rpl::event_stream<> _showFinished;
|
|
||||||
rpl::event_stream<Type> _showOther;
|
|
||||||
rpl::event_stream<> _showBack;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Settings
|
} // namespace Settings
|
||||||
|
|
||||||
|
|
|
@ -250,9 +250,9 @@ void SetupLocalPasscode(
|
||||||
{ &st::settingsIconLock, kIconGreen }
|
{ &st::settingsIconLock, kIconGreen }
|
||||||
)->addClickHandler([=] {
|
)->addClickHandler([=] {
|
||||||
if (controller->session().domain().local().hasLocalPasscode()) {
|
if (controller->session().domain().local().hasLocalPasscode()) {
|
||||||
showOther(LocalPasscodeCheck::Id());
|
showOther(LocalPasscodeCheckId());
|
||||||
} else {
|
} else {
|
||||||
showOther(LocalPasscodeCreate::Id());
|
showOther(LocalPasscodeCreateId());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue