mirror of
https://github.com/Qz3rK/tdesktop.git
synced 2026-07-03 14:15:08 +02:00
Move Settings::Main class to anonymous namespace
- Move Main class definition from header to .cpp file - Export only Type MainId() from header - Update all external references from Main::Id() to MainId() - Remove Builder::MainSection export from namespace - Add missing includes for settings_common_session.h where needed Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1114,7 +1114,7 @@ void BuildExportSection(SectionBuilder &builder) {
|
||||
|
||||
const auto kMeta = BuildHelper({
|
||||
.id = Advanced::Id(),
|
||||
.parentId = Main::Id(),
|
||||
.parentId = MainId(),
|
||||
.title = &tr::lng_settings_advanced,
|
||||
.icon = &st::menuIconManage,
|
||||
}, [](SectionBuilder &builder) {
|
||||
|
||||
@@ -951,7 +951,7 @@ base::weak_qptr<Ui::RpWidget> Business::createPinnedToBottom(
|
||||
|
||||
const auto kMeta = BuildHelper({
|
||||
.id = Business::Id(),
|
||||
.parentId = Main::Id(),
|
||||
.parentId = MainId(),
|
||||
.title = &tr::lng_business_title,
|
||||
.icon = &st::menuIconShop,
|
||||
}, [](SectionBuilder &builder) {
|
||||
|
||||
@@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "platform/platform_specific.h"
|
||||
#include "settings/sections/settings_main.h"
|
||||
#include "settings/settings_builder.h"
|
||||
#include "settings/settings_common_session.h"
|
||||
#include "tgcalls/VideoCaptureInterface.h"
|
||||
#include "ui/boxes/confirm_box.h"
|
||||
#include "ui/boxes/single_choice_box.h"
|
||||
@@ -725,7 +726,7 @@ void Calls::requestPermissionAndStartTestingMicrophone() {
|
||||
|
||||
const auto kMeta = BuildHelper({
|
||||
.id = Calls::Id(),
|
||||
.parentId = Main::Id(),
|
||||
.parentId = MainId(),
|
||||
.title = &tr::lng_settings_section_devices,
|
||||
.icon = &st::menuIconUnmute,
|
||||
}, [](SectionBuilder &builder) {
|
||||
|
||||
@@ -1274,7 +1274,7 @@ void BuildChatSectionContent(SectionBuilder &builder) {
|
||||
|
||||
const auto kMeta = BuildHelper({
|
||||
.id = Chat::Id(),
|
||||
.parentId = Main::Id(),
|
||||
.parentId = MainId(),
|
||||
.title = &tr::lng_settings_section_chat_settings,
|
||||
.icon = &st::menuIconChatBubble,
|
||||
}, [](SectionBuilder &builder) {
|
||||
|
||||
@@ -1033,7 +1033,7 @@ void BuildCreditsSectionContent(
|
||||
|
||||
const auto kCreditsBuilderMeta = BuildHelper({
|
||||
.id = Credits::Id(),
|
||||
.parentId = Main::Id(),
|
||||
.parentId = MainId(),
|
||||
.title = &tr::lng_credits_summary_title,
|
||||
.icon = &st::menuIconPremium,
|
||||
}, [](SectionBuilder &builder) {
|
||||
|
||||
@@ -1238,7 +1238,7 @@ void Folders::showFinished() {
|
||||
|
||||
const auto kMeta = BuildHelper({
|
||||
.id = Folders::Id(),
|
||||
.parentId = Main::Id(),
|
||||
.parentId = MainId(),
|
||||
.title = &tr::lng_filters_title,
|
||||
.icon = &st::menuIconShowInFolder,
|
||||
}, [](SectionBuilder &builder) {
|
||||
|
||||
@@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
|
||||
#include "settings/sections/settings_main.h"
|
||||
#include "settings/settings_builder.h"
|
||||
#include "settings/settings_common_session.h"
|
||||
#include "ui/wrap/vertical_layout.h"
|
||||
#include "ui/wrap/vertical_layout_reorder.h"
|
||||
#include "ui/wrap/padding_wrap.h"
|
||||
@@ -1294,7 +1295,7 @@ void Information::setupContent() {
|
||||
|
||||
const auto kMeta = BuildHelper({
|
||||
.id = Information::Id(),
|
||||
.parentId = Main::Id(),
|
||||
.parentId = MainId(),
|
||||
.title = &tr::lng_settings_section_info,
|
||||
.icon = &st::menuIconProfile,
|
||||
}, [](SectionBuilder &builder) {
|
||||
|
||||
@@ -595,6 +595,135 @@ void BuildValidationSuggestions(SectionBuilder &builder) {
|
||||
});
|
||||
}
|
||||
|
||||
class Main final : public Section<Main> {
|
||||
public:
|
||||
Main(QWidget *parent, not_null<Window::SessionController*> controller);
|
||||
|
||||
[[nodiscard]] rpl::producer<QString> title() override;
|
||||
|
||||
void fillTopBarMenu(const Ui::Menu::MenuCallback &addAction) override;
|
||||
void showFinished() override;
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
|
||||
private:
|
||||
void setupContent();
|
||||
|
||||
QPointer<Ui::UserpicButton> _userpic;
|
||||
|
||||
};
|
||||
|
||||
Main::Main(
|
||||
QWidget *parent,
|
||||
not_null<Window::SessionController*> controller)
|
||||
: Section(parent, controller) {
|
||||
setupContent();
|
||||
}
|
||||
|
||||
rpl::producer<QString> Main::title() {
|
||||
return tr::lng_menu_settings();
|
||||
}
|
||||
|
||||
void Main::fillTopBarMenu(const Ui::Menu::MenuCallback &addAction) {
|
||||
const auto &list = Core::App().domain().accounts();
|
||||
if (list.size() < Core::App().domain().maxAccounts()) {
|
||||
addAction(tr::lng_menu_add_account(tr::now), [=] {
|
||||
Core::App().domain().addActivated(MTP::Environment{});
|
||||
}, &st::menuIconAddAccount);
|
||||
}
|
||||
if (!controller()->session().supportMode()) {
|
||||
addAction(
|
||||
tr::lng_settings_information(tr::now),
|
||||
[=] { showOther(InformationId()); },
|
||||
&st::menuIconEdit);
|
||||
}
|
||||
const auto window = &controller()->window();
|
||||
const auto logout = addAction({
|
||||
.text = tr::lng_settings_logout(tr::now),
|
||||
.handler = [=] { window->showLogoutConfirmation(); },
|
||||
.icon = &st::menuIconLeaveAttention,
|
||||
.isAttention = true,
|
||||
});
|
||||
logout->setProperty("highlight-control-id", u"settings/log-out"_q);
|
||||
}
|
||||
|
||||
void Main::keyPressEvent(QKeyEvent *e) {
|
||||
crl::on_main(this, [=, text = e->text()]{
|
||||
CodesFeedString(controller(), text);
|
||||
});
|
||||
return Section::keyPressEvent(e);
|
||||
}
|
||||
|
||||
void Main::setupContent() {
|
||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||
|
||||
const auto window = controller();
|
||||
const auto session = &window->session();
|
||||
const auto cover = content->add(object_ptr<Cover>(
|
||||
content,
|
||||
window,
|
||||
session->user()));
|
||||
_userpic = cover->userpic();
|
||||
|
||||
const SectionBuildMethod buildMethod = [](
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
not_null<Window::SessionController*> controller,
|
||||
Fn<void(Type)> showOther,
|
||||
rpl::producer<> showFinished) {
|
||||
const auto isPaused = Window::PausedIn(
|
||||
controller,
|
||||
Window::GifPauseReason::Layer);
|
||||
auto builder = SectionBuilder(WidgetContext{
|
||||
.container = container,
|
||||
.controller = controller,
|
||||
.showOther = std::move(showOther),
|
||||
.isPaused = isPaused,
|
||||
});
|
||||
builder.addDivider();
|
||||
builder.addSkip();
|
||||
BuildValidationSuggestions(builder);
|
||||
BuildSectionButtons(builder);
|
||||
builder.addSkip();
|
||||
BuildInterfaceScale(builder);
|
||||
BuildPremiumSection(builder);
|
||||
BuildHelpSection(builder);
|
||||
};
|
||||
build(content, buildMethod);
|
||||
|
||||
Ui::ResizeFitChild(this, content);
|
||||
|
||||
session->api().cloudPassword().reload();
|
||||
session->api().reloadContactSignupSilent();
|
||||
session->api().sensitiveContent().reload();
|
||||
session->api().globalPrivacy().reload();
|
||||
session->api().premium().reload();
|
||||
session->data().cloudThemes().refresh();
|
||||
}
|
||||
|
||||
void Main::showFinished() {
|
||||
controller()->checkHighlightControl(u"profile-photo"_q, _userpic.data(), {
|
||||
.margin = st::settingsPhotoHighlightMargin,
|
||||
.shape = HighlightShape::Ellipse,
|
||||
});
|
||||
const auto emojiId = u"profile-photo/use-emoji"_q;
|
||||
if (controller()->takeHighlightControlId(emojiId)) {
|
||||
if (const auto popupMenu = _userpic->showChangePhotoMenu()) {
|
||||
const auto menu = popupMenu->menu();
|
||||
for (const auto action : menu->actions()) {
|
||||
const auto controlId = "highlight-control-id";
|
||||
if (action->property(controlId).toString() == emojiId) {
|
||||
if (const auto item = menu->itemForAction(action)) {
|
||||
HighlightWidget(item);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Section<Main>::showFinished();
|
||||
}
|
||||
|
||||
const auto kMeta = BuildHelper({
|
||||
.id = Main::Id(),
|
||||
.parentId = nullptr,
|
||||
@@ -985,91 +1114,8 @@ void SetupInterfaceScale(
|
||||
}
|
||||
}
|
||||
|
||||
Main::Main(
|
||||
QWidget *parent,
|
||||
not_null<Window::SessionController*> controller)
|
||||
: Section(parent, controller) {
|
||||
setupContent();
|
||||
}
|
||||
|
||||
rpl::producer<QString> Main::title() {
|
||||
return tr::lng_menu_settings();
|
||||
}
|
||||
|
||||
void Main::fillTopBarMenu(const Ui::Menu::MenuCallback &addAction) {
|
||||
const auto &list = Core::App().domain().accounts();
|
||||
if (list.size() < Core::App().domain().maxAccounts()) {
|
||||
addAction(tr::lng_menu_add_account(tr::now), [=] {
|
||||
Core::App().domain().addActivated(MTP::Environment{});
|
||||
}, &st::menuIconAddAccount);
|
||||
}
|
||||
if (!controller()->session().supportMode()) {
|
||||
addAction(
|
||||
tr::lng_settings_information(tr::now),
|
||||
[=] { showOther(InformationId()); },
|
||||
&st::menuIconEdit);
|
||||
}
|
||||
const auto window = &controller()->window();
|
||||
const auto logout = addAction({
|
||||
.text = tr::lng_settings_logout(tr::now),
|
||||
.handler = [=] { window->showLogoutConfirmation(); },
|
||||
.icon = &st::menuIconLeaveAttention,
|
||||
.isAttention = true,
|
||||
});
|
||||
logout->setProperty("highlight-control-id", u"settings/log-out"_q);
|
||||
}
|
||||
|
||||
void Main::keyPressEvent(QKeyEvent *e) {
|
||||
crl::on_main(this, [=, text = e->text()]{
|
||||
CodesFeedString(controller(), text);
|
||||
});
|
||||
return Section::keyPressEvent(e);
|
||||
}
|
||||
|
||||
void Main::setupContent() {
|
||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||
|
||||
const auto window = controller();
|
||||
const auto session = &window->session();
|
||||
const auto cover = content->add(object_ptr<Cover>(
|
||||
content,
|
||||
window,
|
||||
session->user()));
|
||||
_userpic = cover->userpic();
|
||||
|
||||
build(content, Builder::MainSection);
|
||||
|
||||
Ui::ResizeFitChild(this, content);
|
||||
|
||||
session->api().cloudPassword().reload();
|
||||
session->api().reloadContactSignupSilent();
|
||||
session->api().sensitiveContent().reload();
|
||||
session->api().globalPrivacy().reload();
|
||||
session->api().premium().reload();
|
||||
session->data().cloudThemes().refresh();
|
||||
}
|
||||
|
||||
void Main::showFinished() {
|
||||
controller()->checkHighlightControl(u"profile-photo"_q, _userpic.data(), {
|
||||
.margin = st::settingsPhotoHighlightMargin,
|
||||
.shape = HighlightShape::Ellipse,
|
||||
});
|
||||
const auto emojiId = u"profile-photo/use-emoji"_q;
|
||||
if (controller()->takeHighlightControlId(emojiId)) {
|
||||
if (const auto popupMenu = _userpic->showChangePhotoMenu()) {
|
||||
const auto menu = popupMenu->menu();
|
||||
for (const auto action : menu->actions()) {
|
||||
const auto controlId = "highlight-control-id";
|
||||
if (action->property(controlId).toString() == emojiId) {
|
||||
if (const auto item = menu->itemForAction(action)) {
|
||||
HighlightWidget(item);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Section<Main>::showFinished();
|
||||
Type MainId() {
|
||||
return Main::Id();
|
||||
}
|
||||
|
||||
void OpenFaq(base::weak_ptr<Window::SessionController> weak) {
|
||||
@@ -1115,9 +1161,4 @@ void OpenAskQuestionConfirm(not_null<Window::SessionController*> window) {
|
||||
}));
|
||||
}
|
||||
|
||||
namespace Builder {
|
||||
|
||||
SectionBuildMethod MainSection = kMeta.build;
|
||||
|
||||
} // namespace Builder
|
||||
} // namespace Settings
|
||||
|
||||
@@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "settings/settings_common_session.h"
|
||||
#include "settings/settings_type.h"
|
||||
|
||||
namespace Window {
|
||||
@@ -16,13 +15,13 @@ class SessionController;
|
||||
} // namespace Window
|
||||
|
||||
namespace Ui {
|
||||
class SettingsButton;
|
||||
class UserpicButton;
|
||||
class VerticalLayout;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Settings {
|
||||
|
||||
[[nodiscard]] Type MainId();
|
||||
|
||||
void SetupLanguageButton(
|
||||
not_null<Window::Controller*> window,
|
||||
not_null<Ui::VerticalLayout*> container);
|
||||
@@ -44,30 +43,4 @@ void SetupValidatePasswordSuggestion(
|
||||
void OpenFaq(base::weak_ptr<Window::SessionController> weak);
|
||||
void OpenAskQuestionConfirm(not_null<Window::SessionController*> window);
|
||||
|
||||
class Main : public Section<Main> {
|
||||
public:
|
||||
Main(QWidget *parent, not_null<Window::SessionController*> controller);
|
||||
|
||||
[[nodiscard]] rpl::producer<QString> title() override;
|
||||
|
||||
void fillTopBarMenu(
|
||||
const Ui::Menu::MenuCallback &addAction) override;
|
||||
|
||||
void showFinished() override;
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
|
||||
private:
|
||||
void setupContent();
|
||||
|
||||
QPointer<Ui::UserpicButton> _userpic;
|
||||
|
||||
};
|
||||
|
||||
namespace Builder {
|
||||
|
||||
extern SectionBuildMethod MainSection;
|
||||
|
||||
} // namespace Builder
|
||||
} // namespace Settings
|
||||
|
||||
@@ -1488,7 +1488,7 @@ void BuildNotificationsSectionContent(SectionBuilder &builder) {
|
||||
|
||||
const auto kMeta = BuildHelper({
|
||||
.id = Notifications::Id(),
|
||||
.parentId = Main::Id(),
|
||||
.parentId = MainId(),
|
||||
.title = &tr::lng_settings_section_notify,
|
||||
.icon = &st::menuIconNotifications,
|
||||
}, [](SectionBuilder &builder) {
|
||||
|
||||
@@ -1578,7 +1578,7 @@ base::weak_qptr<Ui::RpWidget> Premium::createPinnedToBottom(
|
||||
|
||||
const auto kMeta = BuildHelper({
|
||||
.id = Premium::Id(),
|
||||
.parentId = Main::Id(),
|
||||
.parentId = MainId(),
|
||||
.title = &tr::lng_premium_summary_title,
|
||||
.icon = &st::menuIconPremium,
|
||||
}, [](SectionBuilder &builder) {
|
||||
|
||||
@@ -1793,7 +1793,7 @@ void BuildPrivacySecuritySectionContent(SectionBuilder &builder) {
|
||||
|
||||
const auto kMeta = BuildHelper({
|
||||
.id = PrivacySecurity::Id(),
|
||||
.parentId = Main::Id(),
|
||||
.parentId = MainId(),
|
||||
.title = &tr::lng_settings_section_privacy,
|
||||
.icon = &st::menuIconLock,
|
||||
}, [](SectionBuilder &builder) {
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Settings {
|
||||
|
||||
bool HasMenu(Type type) {
|
||||
return (type == ::Settings::CloudPasswordEmailConfirmId())
|
||||
|| (type == Main::Id())
|
||||
|| (type == MainId())
|
||||
|| (type == Chat::Id());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user