Allow adding Settings::Section-s without changing Type.

This commit is contained in:
John Preston 2022-04-01 15:53:23 +04:00
parent 6716c08306
commit aa7143a831
56 changed files with 318 additions and 179 deletions

View File

@ -1071,6 +1071,7 @@ PRIVATE
settings/settings_privacy_controllers.h
settings/settings_privacy_security.cpp
settings/settings_privacy_security.h
settings/settings_type.h
storage/details/storage_file_utilities.cpp
storage/details/storage_file_utilities.h
storage/details/storage_settings_scheme.cpp
@ -1286,6 +1287,8 @@ PRIVATE
qrc/emoji_6.qrc
qrc/emoji_7.qrc
qrc/emoji_preview.qrc
qrc/telegram/animations.qrc
qrc/telegram/export.qrc
qrc/telegram/telegram.qrc
qrc/telegram/sounds.qrc
winrc/Telegram.rc

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 746 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 567 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 868 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/animations">
<file alias="change_number.tgs">../../animations/change_number.tgs</file>
</qresource>
</RCC>

View File

@ -0,0 +1,44 @@
<RCC>
<qresource prefix="/export">
<file alias="css/style.css">../../export_html/css/style.css</file>
<file alias="images/back.png">../../export_html/images/back.png</file>
<file alias="images/back@2x.png">../../export_html/images/back@2x.png</file>
<file alias="images/media_call.png">../../export_html/images/media_call.png</file>
<file alias="images/media_call@2x.png">../../export_html/images/media_call@2x.png</file>
<file alias="images/media_contact.png">../../export_html/images/media_contact.png</file>
<file alias="images/media_contact@2x.png">../../export_html/images/media_contact@2x.png</file>
<file alias="images/media_file.png">../../export_html/images/media_file.png</file>
<file alias="images/media_file@2x.png">../../export_html/images/media_file@2x.png</file>
<file alias="images/media_game.png">../../export_html/images/media_game.png</file>
<file alias="images/media_game@2x.png">../../export_html/images/media_game@2x.png</file>
<file alias="images/media_location.png">../../export_html/images/media_location.png</file>
<file alias="images/media_location@2x.png">../../export_html/images/media_location@2x.png</file>
<file alias="images/media_music.png">../../export_html/images/media_music.png</file>
<file alias="images/media_music@2x.png">../../export_html/images/media_music@2x.png</file>
<file alias="images/media_photo.png">../../export_html/images/media_photo.png</file>
<file alias="images/media_photo@2x.png">../../export_html/images/media_photo@2x.png</file>
<file alias="images/media_shop.png">../../export_html/images/media_shop.png</file>
<file alias="images/media_shop@2x.png">../../export_html/images/media_shop@2x.png</file>
<file alias="images/media_video.png">../../export_html/images/media_video.png</file>
<file alias="images/media_video@2x.png">../../export_html/images/media_video@2x.png</file>
<file alias="images/media_voice.png">../../export_html/images/media_voice.png</file>
<file alias="images/media_voice@2x.png">../../export_html/images/media_voice@2x.png</file>
<file alias="images/section_calls.png">../../export_html/images/section_calls.png</file>
<file alias="images/section_calls@2x.png">../../export_html/images/section_calls@2x.png</file>
<file alias="images/section_chats.png">../../export_html/images/section_chats.png</file>
<file alias="images/section_chats@2x.png">../../export_html/images/section_chats@2x.png</file>
<file alias="images/section_contacts.png">../../export_html/images/section_contacts.png</file>
<file alias="images/section_contacts@2x.png">../../export_html/images/section_contacts@2x.png</file>
<file alias="images/section_frequent.png">../../export_html/images/section_frequent.png</file>
<file alias="images/section_frequent@2x.png">../../export_html/images/section_frequent@2x.png</file>
<file alias="images/section_other.png">../../export_html/images/section_other.png</file>
<file alias="images/section_other@2x.png">../../export_html/images/section_other@2x.png</file>
<file alias="images/section_photos.png">../../export_html/images/section_photos.png</file>
<file alias="images/section_photos@2x.png">../../export_html/images/section_photos@2x.png</file>
<file alias="images/section_sessions.png">../../export_html/images/section_sessions.png</file>
<file alias="images/section_sessions@2x.png">../../export_html/images/section_sessions@2x.png</file>
<file alias="images/section_web.png">../../export_html/images/section_web.png</file>
<file alias="images/section_web@2x.png">../../export_html/images/section_web@2x.png</file>
<file alias="js/script.js">../../export_html/js/script.js</file>
</qresource>
</RCC>

View File

@ -1,46 +1,4 @@
<RCC>
<qresource prefix="/export">
<file alias="css/style.css">../../export_html/css/style.css</file>
<file alias="images/back.png">../../export_html/images/back.png</file>
<file alias="images/back@2x.png">../../export_html/images/back@2x.png</file>
<file alias="images/media_call.png">../../export_html/images/media_call.png</file>
<file alias="images/media_call@2x.png">../../export_html/images/media_call@2x.png</file>
<file alias="images/media_contact.png">../../export_html/images/media_contact.png</file>
<file alias="images/media_contact@2x.png">../../export_html/images/media_contact@2x.png</file>
<file alias="images/media_file.png">../../export_html/images/media_file.png</file>
<file alias="images/media_file@2x.png">../../export_html/images/media_file@2x.png</file>
<file alias="images/media_game.png">../../export_html/images/media_game.png</file>
<file alias="images/media_game@2x.png">../../export_html/images/media_game@2x.png</file>
<file alias="images/media_location.png">../../export_html/images/media_location.png</file>
<file alias="images/media_location@2x.png">../../export_html/images/media_location@2x.png</file>
<file alias="images/media_music.png">../../export_html/images/media_music.png</file>
<file alias="images/media_music@2x.png">../../export_html/images/media_music@2x.png</file>
<file alias="images/media_photo.png">../../export_html/images/media_photo.png</file>
<file alias="images/media_photo@2x.png">../../export_html/images/media_photo@2x.png</file>
<file alias="images/media_shop.png">../../export_html/images/media_shop.png</file>
<file alias="images/media_shop@2x.png">../../export_html/images/media_shop@2x.png</file>
<file alias="images/media_video.png">../../export_html/images/media_video.png</file>
<file alias="images/media_video@2x.png">../../export_html/images/media_video@2x.png</file>
<file alias="images/media_voice.png">../../export_html/images/media_voice.png</file>
<file alias="images/media_voice@2x.png">../../export_html/images/media_voice@2x.png</file>
<file alias="images/section_calls.png">../../export_html/images/section_calls.png</file>
<file alias="images/section_calls@2x.png">../../export_html/images/section_calls@2x.png</file>
<file alias="images/section_chats.png">../../export_html/images/section_chats.png</file>
<file alias="images/section_chats@2x.png">../../export_html/images/section_chats@2x.png</file>
<file alias="images/section_contacts.png">../../export_html/images/section_contacts.png</file>
<file alias="images/section_contacts@2x.png">../../export_html/images/section_contacts@2x.png</file>
<file alias="images/section_frequent.png">../../export_html/images/section_frequent.png</file>
<file alias="images/section_frequent@2x.png">../../export_html/images/section_frequent@2x.png</file>
<file alias="images/section_other.png">../../export_html/images/section_other.png</file>
<file alias="images/section_other@2x.png">../../export_html/images/section_other@2x.png</file>
<file alias="images/section_photos.png">../../export_html/images/section_photos.png</file>
<file alias="images/section_photos@2x.png">../../export_html/images/section_photos@2x.png</file>
<file alias="images/section_sessions.png">../../export_html/images/section_sessions.png</file>
<file alias="images/section_sessions@2x.png">../../export_html/images/section_sessions@2x.png</file>
<file alias="images/section_web.png">../../export_html/images/section_web.png</file>
<file alias="images/section_web@2x.png">../../export_html/images/section_web@2x.png</file>
<file alias="js/script.js">../../export_html/js/script.js</file>
</qresource>
<qresource prefix="/gui">
<file alias="art/background.tgv">../../art/background.tgv</file>
<file alias="art/bg_thumbnail.png">../../art/bg_thumbnail.png</file>

View File

@ -576,17 +576,13 @@ colorValueInput: InputField(defaultInputField) {
colorResultInput: InputField(colorValueInput) {
}
changePhoneIcon: icon {
{ "phone_simcard_from", changePhoneSimcardFrom },
{ "phone_simcard_migrate", changePhoneSimcardTo, point(30px, 11px) },
{ "phone_simcard_to", changePhoneSimcardTo, point(78px, 0px) }
};
changePhoneDescription: FlatLabel(boxLabel) {
minWidth: 332px;
align: align(top);
}
changePhoneIconTop: 20px;
changePhoneDescriptionTop: 96px;
changePhoneIconTop: 16px;
changePhoneIconSize: 96px;
changePhoneDescriptionTop: 128px;
changePhoneLabel: FlatLabel(defaultFlatLabel) {
minWidth: 275px;
textFg: windowSubTextFg;

View File

@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_session.h"
#include "data/data_user.h"
#include "mtproto/sender.h"
#include "lottie/lottie_icon.h"
#include "apiwrap.h"
#include "window/window_session_controller.h"
#include "styles/style_layers.h"
@ -66,6 +67,26 @@ void CreateErrorLabel(
} // namespace
namespace Settings {
ChangePhone::ChangePhone(
QWidget *parent,
not_null<Window::SessionController*> controller)
: Section(parent) {
setupContent(controller);
}
rpl::producer<QString> ChangePhone::Title() {
return tr::lng_change_phone_button();
}
void ChangePhone::setupContent(
not_null<Window::SessionController*> controller) {
}
} // namespace Settings
class ChangePhoneBox::EnterPhone : public Ui::BoxContent {
public:
EnterPhone(QWidget*, not_null<Window::SessionController*> controller);
@ -434,7 +455,22 @@ void ChangePhoneBox::EnterCode::sendCodeFail(const MTP::Error &error) {
ChangePhoneBox::ChangePhoneBox(
QWidget*,
not_null<Window::SessionController*> controller)
: _controller(controller) {
: _controller(controller)
, _icon(Lottie::MakeIcon({
.name = u"change_number"_q,
.sizeOverride = {
st::changePhoneIconSize,
st::changePhoneIconSize,
},
})) {
}
void ChangePhoneBox::showFinished() {
animateIcon();
}
void ChangePhoneBox::animateIcon() {
_icon->animate([=] { update(); }, 0, _icon->framesCount());
}
void ChangePhoneBox::prepare() {
@ -473,9 +509,9 @@ void ChangePhoneBox::paintEvent(QPaintEvent *e) {
BoxContent::paintEvent(e);
Painter p(this);
st::changePhoneIcon.paint(
p,
(width() - st::changePhoneIcon.width()) / 2,
st::changePhoneIconTop,
width());
const auto left = (width() - st::changePhoneIconSize) / 2;
_icon->paint(p, left, st::changePhoneIconTop);
if (!_icon->animating() && _icon->frameIndex() > 0) {
animateIcon();
}
}

View File

@ -8,14 +8,40 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#pragma once
#include "boxes/abstract_box.h"
#include "settings/settings_common.h"
namespace Lottie {
class Icon;
} // namespace Lottie
namespace Window {
class SessionController;
} // namespace Window
namespace Settings {
class ChangePhone : public Section<ChangePhone> {
public:
ChangePhone(
QWidget *parent,
not_null<Window::SessionController*> controller);
[[nodiscard]] static rpl::producer<QString> Title();
private:
void setupContent(not_null<Window::SessionController*> controller);
};
} // namespace Settings
class ChangePhoneBox : public Ui::BoxContent {
public:
ChangePhoneBox(QWidget*, not_null<Window::SessionController*> controller);
ChangePhoneBox(
QWidget*,
not_null<Window::SessionController*> controller);
void showFinished() override;
protected:
void prepare() override;
@ -23,10 +49,13 @@ protected:
void paintEvent(QPaintEvent *e) override;
private:
void animateIcon();
class EnterPhone;
class EnterCode;
const not_null<Window::SessionController*> _controller;
const std::unique_ptr<Lottie::Icon> _icon;
};

View File

@ -53,7 +53,7 @@ void AddReactionIcon(
}, icon->lifetime());
const auto initLottie = [=] {
state->icon = std::make_unique<Lottie::Icon>(Lottie::IconDescriptor{
state->icon = Lottie::MakeIcon({
.path = state->media->owner()->filepath(true),
.json = state->media->bytes(),
.sizeOverride = QSize(size, size),

View File

@ -289,7 +289,7 @@ void RenameBox(not_null<Ui::GenericBox*> box) {
Unexpected("Type in LottieForType.");
}();
const auto size = st::sessionBigLottieSize;
return std::make_unique<Lottie::Icon>(Lottie::IconDescriptor{
return Lottie::MakeIcon({
.path = u":/icons/settings/devices/"_q + path + u".lottie"_q,
.sizeOverride = QSize(size, size),
});
@ -1163,6 +1163,10 @@ Sessions::Sessions(
setupContent(controller);
}
rpl::producer<QString> Sessions::Title() {
return tr::lng_settings_sessions_title();
}
void Sessions::setupContent(not_null<Window::SessionController*> controller) {
const auto container = Ui::CreateChild<Ui::VerticalLayout>(this);
AddSkip(container, st::settingsPrivacySkip);

View File

@ -16,12 +16,14 @@ class Session;
namespace Settings {
class Sessions : public Section {
class Sessions : public Section<Sessions> {
public:
Sessions(
QWidget *parent,
not_null<Window::SessionController*> controller);
[[nodiscard]] static rpl::producer<QString> Title();
private:
void setupContent(not_null<Window::SessionController*> controller);

View File

@ -38,6 +38,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/window_controller.h"
#include "window/themes/window_theme_editor_box.h" // GenerateSlug.
#include "settings/settings_common.h"
#include "settings/settings_folders.h"
#include "settings/settings_main.h"
#include "mainwidget.h"
#include "main/main_session.h"
#include "main/main_session_settings.h"
@ -435,10 +437,10 @@ bool ResolveSettings(
controller->session().api().authorizations().reload();
}
const auto type = (section == qstr("folders"))
? ::Settings::Type::Folders
? ::Settings::Folders::Id()
: (section == qstr("devices"))
? ::Settings::Type::Sessions
: ::Settings::Type::Main;
? ::Settings::Sessions::Id()
: ::Settings::Main::Id();
controller->showSettings(type);
return true;
}

View File

@ -25,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "info/info_memento.h"
#include "info/settings/info_settings_widget.h"
#include "window/window_session_controller.h"
#include "settings/settings_advanced.h"
#include "settings/settings_intro.h"
#include "ui/layers/box_content.h"
@ -1652,7 +1653,7 @@ void UpdateApplication() {
controller->showSection(
std::make_shared<Info::Memento>(
Info::Settings::Tag{ controller->session().user() },
Info::Section::SettingsType::Advanced),
::Settings::Advanced::Id()),
Window::SectionShow());
} else {
window->showSpecialLayer(

View File

@ -234,7 +234,7 @@ void Reactions::loadImage(
void Reactions::setLottie(ImageSet &set) {
const auto size = style::ConvertScale(kSizeForDownscale);
set.icon = std::make_unique<Lottie::Icon>(Lottie::IconDescriptor{
set.icon = Lottie::MakeIcon({
.path = set.media->owner()->filepath(true),
.json = set.media->bytes(),
.sizeOverride = QSize(size, size),

View File

@ -45,7 +45,7 @@ Animation::Animation(
if (!media || !media->loaded()) {
return false;
}
icon = std::make_unique<Lottie::Icon>(Lottie::IconDescriptor{
icon = Lottie::MakeIcon({
.path = document->filepath(true),
.json = media->bytes(),
.sizeOverride = QSize(size, size),

View File

@ -617,29 +617,7 @@ rpl::producer<QString> TitleValue(
return tr::lng_profile_participants_section();
case Section::Type::Settings:
switch (section.settingsType()) {
case Section::SettingsType::Main:
return tr::lng_menu_settings();
case Section::SettingsType::Information:
return tr::lng_settings_section_info();
case Section::SettingsType::Notifications:
return tr::lng_settings_section_notify();
case Section::SettingsType::PrivacySecurity:
return tr::lng_settings_section_privacy();
case Section::SettingsType::Sessions:
return tr::lng_settings_sessions_title();
case Section::SettingsType::Advanced:
return tr::lng_settings_advanced();
case Section::SettingsType::Chat:
return tr::lng_settings_section_chat_settings();
case Section::SettingsType::Folders:
return tr::lng_filters_title();
case Section::SettingsType::Calls:
return tr::lng_settings_section_call_settings();
case Section::SettingsType::Experimental:
return tr::lng_settings_experimental();
}
Unexpected("Bad settings type in Info::TitleValue()");
return section.settingsType()()->title();
case Section::Type::PollResults:
return key.poll()->quiz()

View File

@ -14,6 +14,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "info/info_controller.h"
#include "info/info_memento.h"
#include "info/info_top_bar.h"
#include "settings/settings_chat.h"
#include "settings/settings_main.h"
#include "ui/widgets/discrete_sliders.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/shadow.h"
@ -395,8 +397,8 @@ void WrapWidget::createTopBar() {
addTopBarMenuButton();
addProfileCallsButton();
} else if (section.type() == Section::Type::Settings
&& (section.settingsType() == Section::SettingsType::Main
|| section.settingsType() == Section::SettingsType::Chat)) {
&& (section.settingsType() == ::Settings::Main::Id()
|| section.settingsType() == ::Settings::Chat::Id())) {
addTopBarMenuButton();
} else if (section.type() == Section::Type::Downloads) {
auto &manager = Core::App().downloadManager();

View File

@ -10,6 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "info/info_memento.h"
#include "info/info_controller.h"
#include "settings/settings_common.h"
#include "settings/settings_main.h"
#include "settings/settings_information.h"
#include "ui/ui_utility.h"
namespace Info {
@ -43,11 +45,9 @@ Widget::Widget(
: ContentWidget(parent, controller)
, _self(controller->key().settingsSelf())
, _type(controller->section().settingsType())
, _inner(setInnerWidget(
::Settings::CreateSection(
_type,
this,
controller->parentController()))) {
, _inner(
setInnerWidget(
_type()->create(this, controller->parentController()))) {
_inner->sectionShowOther(
) | rpl::start_with_next([=](Type type) {
controller->showSettings(type);
@ -84,7 +84,8 @@ void Widget::saveChanges(FnMut<void()> done) {
}
rpl::producer<bool> Widget::desiredShadowVisibility() const {
return (_type == Type::Main || _type == Type::Information)
return (_type == ::Settings::Main::Id()
|| _type == ::Settings::Information::Id())
? ContentWidget::desiredShadowVisibility()
: rpl::single(true);
}

View File

@ -11,7 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "info/info_controller.h"
namespace Settings {
class Section;
class AbstractSection;
} // namespace Settings
namespace Info {
@ -76,7 +76,7 @@ private:
not_null<UserData*> _self;
Type _type = Type();
not_null<::Settings::Section*> _inner;
not_null<::Settings::AbstractSection*> _inner;
};

View File

@ -682,6 +682,12 @@ std::unique_ptr<Ui::DropdownMenu> MakeAttachBotsMenu(
const auto raw = result.get();
const auto refresh = [=] {
raw->clearActions();
raw->addAction(u"Photo or video"_q, [=] {
});
raw->addAction(u"Document"_q, [=] {
});
for (const auto &bot : bots->attachBots()) {
const auto callback = [=] {
const auto active = controller->activeChatCurrent();

View File

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "settings/settings_common.h"
#include "settings/settings_chat.h"
#include "settings/settings_experimental.h"
#include "ui/wrap/vertical_layout.h"
#include "ui/wrap/slide_wrap.h"
#include "ui/widgets/labels.h"
@ -133,7 +134,7 @@ void SetupUpdate(
experimental->toggleOn(install->toggledValue());
}
experimental->entity()->setClickedCallback([=] {
showOther(Type::Experimental);
showOther(Experimental::Id());
});
}
@ -740,6 +741,10 @@ Advanced::Advanced(
setupContent(controller);
}
rpl::producer<QString> Advanced::Title() {
return tr::lng_settings_advanced();
}
rpl::producer<Type> Advanced::sectionShowOther() {
return _showOther.events();
}

View File

@ -21,7 +21,7 @@ namespace Settings {
void SetupConnectionType(
not_null<Window::Controller*> controller,
not_null<Main::Account*> account,
not_null<::Main::Account*> account,
not_null<Ui::VerticalLayout*> container);
bool HasUpdate();
void SetupUpdate(
@ -32,12 +32,14 @@ void SetupSystemIntegrationContent(
not_null<Ui::VerticalLayout*> container);
void SetupAnimations(not_null<Ui::VerticalLayout*> container);
class Advanced : public Section {
class Advanced : public Section<Advanced> {
public:
Advanced(
QWidget *parent,
not_null<Window::SessionController*> controller);
[[nodiscard]] static rpl::producer<QString> Title();
rpl::producer<Type> sectionShowOther() override;
private:

View File

@ -56,6 +56,10 @@ Calls::Calls(
Calls::~Calls() = default;
rpl::producer<QString> Calls::Title() {
return tr::lng_settings_section_call_settings();
}
Webrtc::VideoTrack *Calls::AddCameraSubsection(
std::shared_ptr<Ui::Show> show,
not_null<Ui::VerticalLayout*> content,

View File

@ -33,11 +33,13 @@ class VideoTrack;
namespace Settings {
class Calls : public Section {
class Calls : public Section<Calls> {
public:
Calls(QWidget *parent, not_null<Window::SessionController*> controller);
~Calls();
[[nodiscard]] static rpl::producer<QString> Title();
void sectionSaveChanges(FnMut<void()> done) override;
static Webrtc::VideoTrack *AddCameraSubsection(

View File

@ -1513,6 +1513,10 @@ Chat::Chat(QWidget *parent, not_null<Window::SessionController*> controller)
setupContent(controller);
}
rpl::producer<QString> Chat::Title() {
return tr::lng_settings_section_chat_settings();
}
void Chat::setupContent(not_null<Window::SessionController*> controller) {
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);

View File

@ -31,10 +31,12 @@ void SetupExport(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container);
class Chat : public Section {
class Chat : public Section<Chat> {
public:
Chat(QWidget *parent, not_null<Window::SessionController*> controller);
[[nodiscard]] static rpl::producer<QString> Title();
private:
void setupContent(not_null<Window::SessionController*> controller);

View File

@ -29,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/window_session_controller.h"
#include "media/audio/media_audio_track.h"
#include "settings/settings_common.h"
#include "settings/settings_folders.h"
#include "api/api_updates.h"
#include "base/qt/qt_common_adapters.h"
#include "base/custom_app_icon.h"
@ -171,7 +172,7 @@ auto GenerateCodes() {
});
codes.emplace(qsl("folders"), [](SessionController *window) {
if (window) {
window->showSettings(Settings::Type::Folders);
window->showSettings(Settings::Folders::Id());
}
});
codes.emplace(qsl("registertg"), [](SessionController *window) {

View File

@ -106,35 +106,6 @@ QSize Icon::size() const {
return _icon->size();
}
object_ptr<Section> CreateSection(
Type type,
not_null<QWidget*> parent,
not_null<Window::SessionController*> controller) {
switch (type) {
case Type::Main:
return object_ptr<Main>(parent, controller);
case Type::Information:
return object_ptr<Information>(parent, controller);
case Type::Notifications:
return object_ptr<Notifications>(parent, controller);
case Type::PrivacySecurity:
return object_ptr<PrivacySecurity>(parent, controller);
case Type::Sessions:
return object_ptr<Sessions>(parent, controller);
case Type::Advanced:
return object_ptr<Advanced>(parent, controller);
case Type::Folders:
return object_ptr<Folders>(parent, controller);
case Type::Chat:
return object_ptr<Chat>(parent, controller);
case Type::Calls:
return object_ptr<Calls>(parent, controller);
case Type::Experimental:
return object_ptr<Experimental>(parent, controller);
}
Unexpected("Settings section type in Widget::createInnerWidget.");
}
void AddSkip(not_null<Ui::VerticalLayout*> container) {
AddSkip(container, st::settingsSectionSkip);
}
@ -278,7 +249,7 @@ void FillMenu(
Fn<void(Type)> showOther,
MenuCallback addAction) {
const auto window = &controller->window();
if (type == Type::Chat) {
if (type == Chat::Id()) {
addAction(
tr::lng_settings_bg_theme_create(tr::now),
[=] { window->show(Box(Window::Theme::CreateBox, window)); },
@ -293,7 +264,7 @@ void FillMenu(
if (!controller->session().supportMode()) {
addAction(
tr::lng_settings_information(tr::now),
[=] { showOther(Type::Information); },
[=] { showOther(Information::Id()); },
&st::menuIconInfo);
}
addAction(

View File

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/rp_widget.h"
#include "ui/round_rect.h"
#include "base/object_ptr.h"
#include "settings/settings_type.h"
namespace Main {
class Session;
@ -35,32 +36,59 @@ namespace Settings {
extern const char kOptionMonoSettingsIcons[];
enum class Type {
Main,
Information,
Notifications,
PrivacySecurity,
Sessions,
Advanced,
Chat,
Folders,
Calls,
Experimental,
};
using Button = Ui::SettingsButton;
class Section : public Ui::RpWidget {
class AbstractSection;
struct SectionMeta {
[[nodiscard]] virtual object_ptr<AbstractSection> create(
not_null<QWidget*> parent,
not_null<Window::SessionController*> controller) const = 0;
[[nodiscard]] virtual rpl::producer<QString> title() const = 0;
};
template <typename SectionType>
struct SectionMetaImplementation : SectionMeta {
object_ptr<AbstractSection> create(
not_null<QWidget*> parent,
not_null<Window::SessionController*> controller
) const final override {
return object_ptr<SectionType>(parent, controller);
}
rpl::producer<QString> title() const final override {
return SectionType::Title();
}
[[nodiscard]] static not_null<SectionMeta*> Meta() {
static SectionMetaImplementation result;
return &result;
}
};
class AbstractSection : public Ui::RpWidget {
public:
using RpWidget::RpWidget;
virtual rpl::producer<Type> sectionShowOther() {
[[nodiscard]] virtual Type id() const = 0;
[[nodiscard]] virtual rpl::producer<Type> sectionShowOther() {
return nullptr;
}
virtual void sectionSaveChanges(FnMut<void()> done) {
done();
}
};
template <typename SectionType>
class Section : public AbstractSection {
public:
using AbstractSection::AbstractSection;
[[nodiscard]] static Type Id() {
return &SectionMetaImplementation<SectionType>::Meta;
}
[[nodiscard]] Type id() const final override {
return Id();
}
};
inline constexpr auto kIconRed = 1;
@ -105,11 +133,6 @@ private:
};
object_ptr<Section> CreateSection(
Type type,
not_null<QWidget*> parent,
not_null<Window::SessionController*> controller);
void AddSkip(not_null<Ui::VerticalLayout*> container);
void AddSkip(not_null<Ui::VerticalLayout*> container, int skip);
void AddDivider(not_null<Ui::VerticalLayout*> container);

View File

@ -146,6 +146,10 @@ Experimental::Experimental(
setupContent(controller);
}
rpl::producer<QString> Experimental::Title() {
return tr::lng_settings_experimental();
}
void Experimental::setupContent(
not_null<Window::SessionController*> controller) {
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);

View File

@ -11,12 +11,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Settings {
class Experimental : public Section {
class Experimental : public Section<Experimental> {
public:
Experimental(
QWidget *parent,
not_null<Window::SessionController*> controller);
[[nodiscard]] static rpl::producer<QString> Title();
private:
void setupContent(not_null<Window::SessionController*> controller);

View File

@ -580,6 +580,10 @@ Folders::~Folders() {
}
}
rpl::producer<QString> Folders::Title() {
return tr::lng_filters_title();
}
void Folders::setupContent(not_null<Window::SessionController*> controller) {
controller->session().data().chatsFilters().requestSuggested();

View File

@ -11,13 +11,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Settings {
class Folders : public Section {
class Folders : public Section<Folders> {
public:
Folders(
QWidget *parent,
not_null<Window::SessionController*> controller);
~Folders();
[[nodiscard]] static rpl::producer<QString> Title();
private:
void setupContent(not_null<Window::SessionController*> controller);

View File

@ -793,6 +793,10 @@ Information::Information(
setupContent(controller);
}
rpl::producer<QString> Information::Title() {
return tr::lng_settings_section_info();
}
void Information::setupContent(
not_null<Window::SessionController*> controller) {
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);

View File

@ -15,12 +15,14 @@ struct UnreadBadgeStyle;
namespace Settings {
class Information : public Section {
class Information : public Section<Information> {
public:
Information(
QWidget *parent,
not_null<Window::SessionController*> controller);
[[nodiscard]] static rpl::producer<QString> Title();
private:
void setupContent(not_null<Window::SessionController*> controller);

View File

@ -10,6 +10,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "settings/settings_common.h"
#include "settings/settings_codes.h"
#include "settings/settings_chat.h"
#include "settings/settings_information.h"
#include "settings/settings_notifications.h"
#include "settings/settings_privacy_security.h"
#include "settings/settings_advanced.h"
#include "settings/settings_folders.h"
#include "settings/settings_calls.h"
#include "boxes/language_box.h"
#include "boxes/username_box.h"
#include "ui/boxes/confirm_box.h"
@ -251,20 +257,20 @@ void SetupSections(
} else {
addSection(
tr::lng_settings_information(),
Type::Information,
Information::Id(),
{ &st::settingsIconAccount, kIconLightOrange });
}
addSection(
tr::lng_settings_section_notify(),
Type::Notifications,
Notifications::Id(),
{ &st::settingsIconNotifications, kIconRed });
addSection(
tr::lng_settings_section_privacy(),
Type::PrivacySecurity,
PrivacySecurity::Id(),
{ &st::settingsIconLock, kIconGreen });
addSection(
tr::lng_settings_section_chat_settings(),
Type::Chat,
Chat::Id(),
{ &st::settingsIconChat, kIconLightBlue });
const auto preload = [=] {
@ -307,16 +313,16 @@ void SetupSections(
) | rpl::before_next(preloadIfEnabled));
}
slided->entity()->setClickedCallback([=] {
showOther(Type::Folders);
showOther(Folders::Id());
});
addSection(
tr::lng_settings_advanced(),
Type::Advanced,
Advanced::Id(),
{ &st::settingsIconGeneral, kIconPurple });
addSection(
tr::lng_settings_section_call_settings(),
Type::Calls,
Calls::Id(),
{ &st::settingsIconCalls, kIconGreen });
SetupLanguageButton(container);
@ -524,6 +530,10 @@ Main::Main(
setupContent(controller);
}
rpl::producer<QString> Main::Title() {
return tr::lng_menu_settings();
}
void Main::keyPressEvent(QKeyEvent *e) {
crl::on_main(this, [=, text = e->text()]{
CodesFeedString(_controller, text);

View File

@ -32,10 +32,12 @@ void SetupFaq(
not_null<Ui::VerticalLayout*> container,
bool icon = true);
class Main : public Section {
class Main : public Section<Main> {
public:
Main(QWidget *parent, not_null<Window::SessionController*> controller);
[[nodiscard]] static rpl::producer<QString> Title();
rpl::producer<Type> sectionShowOther() override;
protected:

View File

@ -1097,6 +1097,10 @@ Notifications::Notifications(
setupContent(controller);
}
rpl::producer<QString> Notifications::Title() {
return tr::lng_settings_section_notify();
}
void Notifications::setupContent(
not_null<Window::SessionController*> controller) {
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);

View File

@ -11,12 +11,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Settings {
class Notifications : public Section {
class Notifications : public Section<Notifications> {
public:
Notifications(
QWidget *parent,
not_null<Window::SessionController*> controller);
[[nodiscard]] static rpl::producer<QString> Title();
private:
void setupContent(not_null<Window::SessionController*> controller);

View File

@ -820,7 +820,7 @@ void SetupSessionsList(
st::settingsButton,
{ &st::settingsIconLaptop, kIconLightOrange }
)->addClickHandler([=] {
showOther(Type::Sessions);
showOther(Sessions::Id());
});
}
@ -971,6 +971,10 @@ PrivacySecurity::PrivacySecurity(
setupContent(controller);
}
rpl::producer<QString> PrivacySecurity::Title() {
return tr::lng_settings_section_privacy();
}
rpl::producer<Type> PrivacySecurity::sectionShowOther() {
return _showOther.events();
}

View File

@ -34,12 +34,14 @@ void AddPrivacyButton(
Api::UserPrivacy::Key key,
Fn<std::unique_ptr<EditPrivacyController>()> controllerFactory);
class PrivacySecurity : public Section {
class PrivacySecurity : public Section<PrivacySecurity> {
public:
PrivacySecurity(
QWidget *parent,
not_null<Window::SessionController*> controller);
[[nodiscard]] static rpl::producer<QString> Title();
rpl::producer<Type> sectionShowOther() override;
private:

View File

@ -0,0 +1,15 @@
/*
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
namespace Settings {
struct SectionMeta;
using Type = not_null<SectionMeta*>(*)();
} // namespace Settings

View File

@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/boxes/confirm_box.h"
#include "boxes/filters/edit_filter_box.h"
#include "settings/settings_common.h"
#include "settings/settings_folders.h"
#include "api/api_chat_filters.h"
#include "apiwrap.h"
#include "styles/style_widgets.h"
@ -275,13 +276,13 @@ base::unique_qptr<Ui::SideBarButton> FiltersMenu::prepareButton(
} else {
const auto filters = &_session->session().data().chatsFilters();
if (filters->suggestedLoaded()) {
_session->showSettings(Settings::Type::Folders);
_session->showSettings(Settings::Folders::Id());
} else if (!_waitingSuggested) {
_waitingSuggested = true;
filters->requestSuggested();
filters->suggestedUpdated(
) | rpl::take(1) | rpl::start_with_next([=] {
_session->showSettings(Settings::Type::Folders);
_session->showSettings(Settings::Folders::Id());
}, _outer.lifetime());
}
}

View File

@ -31,6 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "storage/storage_account.h"
#include "support/support_templates.h"
#include "settings/settings_common.h"
#include "settings/settings_calls.h"
#include "settings/settings_information.h"
#include "base/qt_signal_producer.h"
#include "boxes/about_box.h"
@ -85,7 +86,7 @@ void ShowCallsBox(not_null<Window::SessionController*> window) {
st::popupMenuWithIcons);
const auto showSettings = [=] {
window->showSettings(
Settings::Type::Calls,
Settings::Calls::Id(),
Window::SectionShow(anim::type::instant));
};
const auto clearAll = crl::guard(box, [=] {

View File

@ -76,6 +76,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "storage/file_upload.h"
#include "facades.h"
#include "window/themes/window_theme.h"
#include "settings/settings_main.h"
#include "settings/settings_privacy_security.h"
#include "styles/style_window.h"
#include "styles/style_dialogs.h"
#include "styles/style_layers.h" // st::boxLabel
@ -567,7 +569,7 @@ void SessionNavigation::showSettings(
}
void SessionNavigation::showSettings(const SectionShow &params) {
showSettings(Settings::Type::Main, params);
showSettings(Settings::Main::Id(), params);
}
void SessionNavigation::showPollResults(
@ -667,7 +669,7 @@ void SessionController::suggestArchiveAndMute() {
tr::lng_suggest_hide_new_about(Ui::Text::RichLangValue),
st::boxLabel));
box->addButton(tr::lng_suggest_hide_new_to_settings(), [=] {
showSettings(Settings::Type::PrivacySecurity);
showSettings(Settings::PrivacySecurity::Id());
});
box->setCloseByOutsideClick(false);
box->boxClosing(

View File

@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "dialogs/dialogs_key.h"
#include "ui/layers/layer_widget.h"
#include "ui/layers/show.h"
#include "settings/settings_type.h"
#include "window/window_adaptive.h"
#include "mtproto/sender.h"
@ -40,10 +41,6 @@ namespace InlineBots {
class AttachWebView;
} // namespace InlineBots
namespace Settings {
enum class Type;
} // namespace Settings
namespace Calls {
struct StartGroupCallArgs;
} // namespace Calls

@ -1 +1 @@
Subproject commit e052821270b913798b65f3a1a292b7ab74107ff6
Subproject commit 2ae9d2928a406da58e510bdda54a99e44c4eff10