mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Use shared_ptr<Factory> as settings section id.
This commit is contained in:
parent
6ba922d7b0
commit
5ef48cac9c
8 changed files with 37 additions and 48 deletions
|
@ -45,7 +45,7 @@ Widget::Widget(
|
||||||
, _self(controller->key().settingsSelf())
|
, _self(controller->key().settingsSelf())
|
||||||
, _type(controller->section().settingsType())
|
, _type(controller->section().settingsType())
|
||||||
, _inner([&] {
|
, _inner([&] {
|
||||||
auto inner = _type()->create(this, controller->parentController());
|
auto inner = _type->create(this, controller->parentController());
|
||||||
if (inner->hasFlexibleTopBar()) {
|
if (inner->hasFlexibleTopBar()) {
|
||||||
auto filler = setInnerWidget(object_ptr<Ui::RpWidget>(this));
|
auto filler = setInnerWidget(object_ptr<Ui::RpWidget>(this));
|
||||||
filler->resize(1, 1);
|
filler->resize(1, 1);
|
||||||
|
|
|
@ -162,7 +162,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] static Type Id() {
|
[[nodiscard]] static Type Id() {
|
||||||
return &SectionMetaImplementation<SectionType>::Meta;
|
return SectionFactory<SectionType>::Instance();
|
||||||
}
|
}
|
||||||
[[nodiscard]] Type id() const final override {
|
[[nodiscard]] Type id() const final override {
|
||||||
return Id();
|
return Id();
|
||||||
|
|
|
@ -52,14 +52,16 @@ using Button = Ui::SettingsButton;
|
||||||
|
|
||||||
class AbstractSection;
|
class AbstractSection;
|
||||||
|
|
||||||
struct SectionMeta {
|
struct AbstractSectionFactory {
|
||||||
[[nodiscard]] virtual object_ptr<AbstractSection> create(
|
[[nodiscard]] virtual object_ptr<AbstractSection> create(
|
||||||
not_null<QWidget*> parent,
|
not_null<QWidget*> parent,
|
||||||
not_null<Window::SessionController*> controller) const = 0;
|
not_null<Window::SessionController*> controller) const = 0;
|
||||||
|
|
||||||
|
virtual ~AbstractSectionFactory() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename SectionType>
|
template <typename SectionType>
|
||||||
struct SectionMetaImplementation : SectionMeta {
|
struct SectionFactory : AbstractSectionFactory {
|
||||||
object_ptr<AbstractSection> create(
|
object_ptr<AbstractSection> create(
|
||||||
not_null<QWidget*> parent,
|
not_null<QWidget*> parent,
|
||||||
not_null<Window::SessionController*> controller
|
not_null<Window::SessionController*> controller
|
||||||
|
@ -67,9 +69,9 @@ struct SectionMetaImplementation : SectionMeta {
|
||||||
return object_ptr<SectionType>(parent, controller);
|
return object_ptr<SectionType>(parent, controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] static not_null<SectionMeta*> Meta() {
|
[[nodiscard]] static const std::shared_ptr<SectionFactory> &Instance() {
|
||||||
static SectionMetaImplementation result;
|
static const auto result = std::make_shared<SectionFactory>();
|
||||||
return &result;
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -120,7 +122,7 @@ public:
|
||||||
using AbstractSection::AbstractSection;
|
using AbstractSection::AbstractSection;
|
||||||
|
|
||||||
[[nodiscard]] static Type Id() {
|
[[nodiscard]] static Type Id() {
|
||||||
return &SectionMetaImplementation<SectionType>::Meta;
|
return SectionFactory<SectionType>::Instance();
|
||||||
}
|
}
|
||||||
[[nodiscard]] Type id() const final override {
|
[[nodiscard]] Type id() const final override {
|
||||||
return Id();
|
return Id();
|
||||||
|
|
|
@ -330,7 +330,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] static Type Id() {
|
[[nodiscard]] static Type Id() {
|
||||||
return &SectionMetaImplementation<SectionType>::Meta;
|
return SectionFactory<SectionType>::Instance();
|
||||||
}
|
}
|
||||||
[[nodiscard]] Type id() const final override {
|
[[nodiscard]] Type id() const final override {
|
||||||
return Id();
|
return Id();
|
||||||
|
|
|
@ -171,7 +171,7 @@ void AddTypeButton(
|
||||||
st::settingsNotificationType,
|
st::settingsNotificationType,
|
||||||
{ icon });
|
{ icon });
|
||||||
button->setClickedCallback([=] {
|
button->setClickedCallback([=] {
|
||||||
showOther(NotificationsTypeId(type));
|
showOther(NotificationsType::Id(type));
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto session = &controller->session();
|
const auto session = &controller->session();
|
||||||
|
@ -290,7 +290,7 @@ void AddTypeButton(
|
||||||
tr::lng_notification_exceptions_view(),
|
tr::lng_notification_exceptions_view(),
|
||||||
[=] {
|
[=] {
|
||||||
box->closeBox();
|
box->closeBox();
|
||||||
showOther(NotificationsTypeId(type));
|
showOther(NotificationsType::Id(type));
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,20 @@ namespace {
|
||||||
|
|
||||||
using Notify = Data::DefaultNotify;
|
using Notify = Data::DefaultNotify;
|
||||||
|
|
||||||
|
struct Factory : AbstractSectionFactory {
|
||||||
|
explicit Factory(Notify type) : type(type) {
|
||||||
|
}
|
||||||
|
|
||||||
|
object_ptr<AbstractSection> create(
|
||||||
|
not_null<QWidget*> parent,
|
||||||
|
not_null<Window::SessionController*> controller
|
||||||
|
) const final override {
|
||||||
|
return object_ptr<NotificationsType>(parent, controller, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
const Notify type = {};
|
||||||
|
};
|
||||||
|
|
||||||
class AddExceptionBoxController final
|
class AddExceptionBoxController final
|
||||||
: public ChatsListBoxController
|
: public ChatsListBoxController
|
||||||
, public base::has_weak_ptr {
|
, public base::has_weak_ptr {
|
||||||
|
@ -351,11 +365,6 @@ void ExceptionsController::sort() {
|
||||||
delegate()->peerListSortRows(predicate);
|
delegate()->peerListSortRows(predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <Notify kType>
|
|
||||||
[[nodiscard]] Type Id() {
|
|
||||||
return &NotificationsTypeMetaImplementation<kType>::Meta;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<QString> Title(Notify type) {
|
[[nodiscard]] rpl::producer<QString> Title(Notify type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Notify::User: return tr::lng_notification_title_private_chats();
|
case Notify::User: return tr::lng_notification_title_private_chats();
|
||||||
|
@ -562,15 +571,6 @@ void SetupExceptions(
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Type NotificationsTypeId(Notify type) {
|
|
||||||
switch (type) {
|
|
||||||
case Notify::User: return Id<Notify::User>();
|
|
||||||
case Notify::Group: return Id<Notify::Group>();
|
|
||||||
case Notify::Broadcast: return Id<Notify::Broadcast>();
|
|
||||||
}
|
|
||||||
Unexpected("Type in NotificationTypeId.");
|
|
||||||
}
|
|
||||||
|
|
||||||
NotificationsType::NotificationsType(
|
NotificationsType::NotificationsType(
|
||||||
QWidget *parent,
|
QWidget *parent,
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
|
@ -589,8 +589,8 @@ rpl::producer<QString> NotificationsType::title() {
|
||||||
Unexpected("Type in NotificationsType.");
|
Unexpected("Type in NotificationsType.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Type NotificationsType::id() const {
|
Type NotificationsType::Id(Notify type) {
|
||||||
return NotificationsTypeId(_type);
|
return std::make_shared<Factory>(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationsType::setupContent(
|
void NotificationsType::setupContent(
|
||||||
|
|
|
@ -25,32 +25,19 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<QString> title() override;
|
[[nodiscard]] rpl::producer<QString> title() override;
|
||||||
|
|
||||||
[[nodiscard]] Type id() const final override;
|
[[nodiscard]] static Type Id(Data::DefaultNotify type);
|
||||||
|
|
||||||
|
[[nodiscard]] Type id() const final override {
|
||||||
|
return Id(_type);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupContent(not_null<Window::SessionController*> controller);
|
void setupContent(not_null<Window::SessionController*> controller);
|
||||||
|
|
||||||
Data::DefaultNotify _type;
|
const Data::DefaultNotify _type;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <Data::DefaultNotify kType>
|
|
||||||
struct NotificationsTypeMetaImplementation : SectionMeta {
|
|
||||||
object_ptr<AbstractSection> create(
|
|
||||||
not_null<QWidget*> parent,
|
|
||||||
not_null<Window::SessionController*> controller
|
|
||||||
) const final override {
|
|
||||||
return object_ptr<NotificationsType>(parent, controller, kType);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] static not_null<SectionMeta*> Meta() {
|
|
||||||
static NotificationsTypeMetaImplementation result;
|
|
||||||
return &result;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
[[nodiscard]] Type NotificationsTypeId(Data::DefaultNotify type);
|
|
||||||
|
|
||||||
[[nodiscard]] bool NotificationsEnabledForType(
|
[[nodiscard]] bool NotificationsEnabledForType(
|
||||||
not_null<Main::Session*> session,
|
not_null<Main::Session*> session,
|
||||||
Data::DefaultNotify type);
|
Data::DefaultNotify type);
|
||||||
|
|
|
@ -9,7 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
namespace Settings {
|
namespace Settings {
|
||||||
|
|
||||||
struct SectionMeta;
|
struct AbstractSectionFactory;
|
||||||
using Type = not_null<SectionMeta*>(*)();
|
using Type = std::shared_ptr<AbstractSectionFactory>;
|
||||||
|
|
||||||
} // namespace Settings
|
} // namespace Settings
|
||||||
|
|
Loading…
Add table
Reference in a new issue