From 3f543347b87b1ae3af9f6c5018594d03bf8da507 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 6 Sep 2018 00:01:50 +0300 Subject: [PATCH] Add language and scale settings. --- Telegram/Resources/langs/lang.strings | 3 + Telegram/SourceFiles/boxes/language_box.cpp | 25 +++ Telegram/SourceFiles/boxes/language_box.h | 3 + .../old_settings/settings_general_widget.cpp | 13 +- .../old_settings/settings_general_widget.h | 3 +- Telegram/SourceFiles/settings/settings.style | 5 + .../SourceFiles/settings/settings_main.cpp | 170 +++++++++++++++++- Telegram/SourceFiles/settings/settings_main.h | 5 + Telegram/SourceFiles/ui/rp_widget.h | 14 +- Telegram/SourceFiles/ui/widgets/checkbox.cpp | 5 + 10 files changed, 226 insertions(+), 20 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index b696ee4d7b..8b742b7ee9 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -328,6 +328,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_bg_tile" = "Tile background"; "lng_settings_adaptive_wide" = "Adaptive layout for wide screens"; +"lng_settings_language" = "Language"; +"lng_settings_default_scale" = "Default interface scale"; + "lng_backgrounds_header" = "Choose your new chat background"; "lng_theme_sure_keep" = "Keep this theme?"; "lng_theme_reverting#one" = "Reverting to the old theme in {count} second."; diff --git a/Telegram/SourceFiles/boxes/language_box.cpp b/Telegram/SourceFiles/boxes/language_box.cpp index c8fc3751b0..73742d8761 100644 --- a/Telegram/SourceFiles/boxes/language_box.cpp +++ b/Telegram/SourceFiles/boxes/language_box.cpp @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/confirm_box.h" #include "mainwidget.h" #include "mainwindow.h" +#include "messenger.h" #include "lang/lang_instance.h" #include "lang/lang_cloud_manager.h" #include "styles/style_boxes.h" @@ -150,3 +151,27 @@ void LanguageBox::refreshLanguages() { } _inner->setSelected(currentIndex); } + +base::binary_guard LanguageBox::Show() { + auto result = base::binary_guard(); + + const auto manager = Messenger::Instance().langCloudManager(); + if (manager->languageList().isEmpty()) { + auto guard = std::make_shared(); + std::tie(result, *guard) = base::make_binary_guard(); + auto alive = std::make_shared>( + std::make_unique()); + **alive = manager->languageListChanged().add_subscription([=] { + const auto show = guard->alive(); + *alive = nullptr; + if (show) { + Ui::show(Box()); + } + }); + } else { + Ui::show(Box()); + } + manager->requestLanguageList(); + + return result; +} diff --git a/Telegram/SourceFiles/boxes/language_box.h b/Telegram/SourceFiles/boxes/language_box.h index 19392d3e97..23b10cfb19 100644 --- a/Telegram/SourceFiles/boxes/language_box.h +++ b/Telegram/SourceFiles/boxes/language_box.h @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_cloud_manager.h" #include "boxes/abstract_box.h" #include "mtproto/sender.h" +#include "base/binary_guard.h" namespace Ui { class RadiobuttonGroup; @@ -21,6 +22,8 @@ public: LanguageBox(QWidget*) { } + static base::binary_guard Show(); + protected: void prepare() override; diff --git a/Telegram/SourceFiles/old_settings/settings_general_widget.cpp b/Telegram/SourceFiles/old_settings/settings_general_widget.cpp index 5a6c9266a4..98b3822dd0 100644 --- a/Telegram/SourceFiles/old_settings/settings_general_widget.cpp +++ b/Telegram/SourceFiles/old_settings/settings_general_widget.cpp @@ -220,17 +220,8 @@ void GeneralWidget::onChangeLanguage() { Lang::CurrentCloudManager().switchToLanguage(qsl("custom")); return; } - auto manager = Messenger::Instance().langCloudManager(); - if (manager->languageList().isEmpty()) { - _languagesLoadedSubscription = subscribe(manager->languageListChanged(), [this] { - unsubscribe(base::take(_languagesLoadedSubscription)); - Ui::show(Box()); - }); - } else { - unsubscribe(base::take(_languagesLoadedSubscription)); - Ui::show(Box()); - } - manager->requestLanguageList(); + + _languagesLoadWaiter = LanguageBox::Show(); } void GeneralWidget::onRestart() { diff --git a/Telegram/SourceFiles/old_settings/settings_general_widget.h b/Telegram/SourceFiles/old_settings/settings_general_widget.h index 082c8e2bd8..c50930ffb8 100644 --- a/Telegram/SourceFiles/old_settings/settings_general_widget.h +++ b/Telegram/SourceFiles/old_settings/settings_general_widget.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "old_settings/settings_block_widget.h" +#include "base/binary_guard.h" #include "ui/rp_widget.h" namespace OldSettings { @@ -98,7 +99,7 @@ private: Ui::SlideWrap *_startMinimized = nullptr; Ui::Checkbox *_addInSendTo = nullptr; - int _languagesLoadedSubscription = 0; + base::binary_guard _languagesLoadWaiter; }; diff --git a/Telegram/SourceFiles/settings/settings.style b/Telegram/SourceFiles/settings/settings.style index 1ad80c9cf3..ac05d7ad5b 100644 --- a/Telegram/SourceFiles/settings/settings.style +++ b/Telegram/SourceFiles/settings/settings.style @@ -10,3 +10,8 @@ using "ui/widgets/widgets.style"; using "info/info.style"; settingsSectionButton: infoProfileButton; +settingsSectionSkip: infoProfileSkip; +settingsButtonRightPosition: point(28px, 10px); +settingsButtonRight: FlatLabel(defaultFlatLabel) { + textFg: windowActiveTextFg; +} diff --git a/Telegram/SourceFiles/settings/settings_main.cpp b/Telegram/SourceFiles/settings/settings_main.cpp index 4c6effa9f6..9ca787f69f 100644 --- a/Telegram/SourceFiles/settings/settings_main.cpp +++ b/Telegram/SourceFiles/settings/settings_main.cpp @@ -9,13 +9,165 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "settings/settings_common.h" #include "boxes/abstract_box.h" +#include "boxes/language_box.h" +#include "boxes/confirm_box.h" #include "ui/wrap/vertical_layout.h" +#include "ui/wrap/padding_wrap.h" +#include "ui/widgets/labels.h" +#include "ui/widgets/discrete_sliders.h" #include "info/profile/info_profile_button.h" #include "info/profile/info_profile_cover.h" #include "lang/lang_keys.h" +#include "storage/localstorage.h" #include "styles/style_settings.h" namespace Settings { +namespace { + +void AddSkip(not_null container) { + container->add(object_ptr( + container, + st::settingsSectionSkip)); +} + +void AddDivider(not_null container) { + container->add(object_ptr(container)); +} + +void SetupLanguageButton(not_null container) { + const auto button = container->add(object_ptr