diff --git a/Telegram/SourceFiles/boxes/language_box.cpp b/Telegram/SourceFiles/boxes/language_box.cpp index c67916058..6450d41fa 100644 --- a/Telegram/SourceFiles/boxes/language_box.cpp +++ b/Telegram/SourceFiles/boxes/language_box.cpp @@ -55,6 +55,7 @@ public: void activateSelected(); rpl::producer activations() const; + void changeChosen(const QString &chosen); Ui::ScrollToRequest rowScrollRequest(int index) const; @@ -170,6 +171,7 @@ public: Ui::ScrollToRequest jump(int rows); void filter(const QString &query); rpl::producer activations() const; + void changeChosen(const QString &chosen); void activateBySubmit(); private: @@ -180,6 +182,7 @@ private: Fn _jump; Fn _filter; Fn()> _activations; + Fn _changeChosen; Fn _activateBySubmit; }; @@ -613,6 +616,12 @@ rpl::producer Rows::activations() const { return _activations.events(); } +void Rows::changeChosen(const QString &chosen) { + for (const auto &row : _rows) { + row.check->setChecked(row.data.id == chosen, anim::type::normal); + } +} + void Rows::setSelected(int selected) { _mouseSelection = false; const auto limit = count(); @@ -1003,6 +1012,14 @@ void Content::setupContent( other->activations() ) | rpl::type_erased(); }; + _changeChosen = [=](const QString &chosen) { + if (main) { + main->changeChosen(chosen); + } + if (other) { + other->changeChosen(chosen); + } + }; _activateBySubmit = [=] { if (selectedIndex() < 0) { _jump(1); @@ -1024,6 +1041,10 @@ rpl::producer Content::activations() const { return _activations(); } +void Content::changeChosen(const QString &chosen) { + _changeChosen(chosen); +} + void Content::activateBySubmit() { _activateBySubmit(); } @@ -1076,6 +1097,9 @@ void LanguageBox::prepare() { // So we check that the language really has changed. if (language.id != Lang::Current().id()) { Lang::CurrentCloudManager().switchToLanguage(language); + if (inner) { + inner->changeChosen(Lang::Current().id()); + } } }, inner->lifetime()); diff --git a/Telegram/SourceFiles/boxes/passcode_box.cpp b/Telegram/SourceFiles/boxes/passcode_box.cpp index c04aeebe3..613f61f67 100644 --- a/Telegram/SourceFiles/boxes/passcode_box.cpp +++ b/Telegram/SourceFiles/boxes/passcode_box.cpp @@ -94,7 +94,7 @@ bool PasscodeBox::onlyCheckCurrent() const { void PasscodeBox::prepare() { addButton( (_cloudFields.customSubmitButton - ? rpl::single(*_cloudFields.customSubmitButton) + ? std::move(_cloudFields.customSubmitButton) : _turningOff ? tr::lng_passcode_remove_button() : tr::lng_settings_save()), @@ -111,7 +111,7 @@ void PasscodeBox::prepare() { if (onlyCheck) { _oldPasscode->show(); setTitle(_cloudFields.customTitle - ? rpl::single(*_cloudFields.customTitle) + ? std::move(_cloudFields.customTitle) : _cloudPwd ? tr::lng_cloud_password_remove() : tr::lng_passcode_remove()); diff --git a/Telegram/SourceFiles/boxes/passcode_box.h b/Telegram/SourceFiles/boxes/passcode_box.h index 9414069d4..8b9dbdf05 100644 --- a/Telegram/SourceFiles/boxes/passcode_box.h +++ b/Telegram/SourceFiles/boxes/passcode_box.h @@ -38,9 +38,9 @@ public: // Check cloud password for some action. Fn customCheckCallback; - std::optional customTitle; + rpl::producer customTitle; std::optional customDescription; - std::optional customSubmitButton; + rpl::producer customSubmitButton; }; PasscodeBox(QWidget*, const CloudFields &fields); diff --git a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp index 90b9003ad..c667758fc 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp @@ -490,10 +490,10 @@ void EditAdminBox::requestTransferPassword(not_null channel) { ) | rpl::start_with_next([=](const Core::CloudPasswordState &state) { const auto box = std::make_shared>(); auto fields = PasscodeBox::CloudFields::From(state); - fields.customTitle = lang(lng_rights_transfer_password_title); + fields.customTitle = tr::lng_rights_transfer_password_title(); fields.customDescription = lang(lng_rights_transfer_password_description); - fields.customSubmitButton = lang(lng_passcode_submit); + fields.customSubmitButton = tr::lng_passcode_submit(); fields.customCheckCallback = crl::guard(this, [=]( const Core::CloudPasswordResult &result) { sendTransferRequestFrom(*box, channel, result); diff --git a/Telegram/SourceFiles/lang/lang_cloud_manager.cpp b/Telegram/SourceFiles/lang/lang_cloud_manager.cpp index 97fdfdbc9..b23e497d0 100644 --- a/Telegram/SourceFiles/lang/lang_cloud_manager.cpp +++ b/Telegram/SourceFiles/lang/lang_cloud_manager.cpp @@ -422,7 +422,11 @@ void CloudManager::requestLanguageAndSwitch( _switchingToLanguageRequest = 0; const auto language = Lang::ParseLanguage(result); const auto finalize = [=] { - performSwitchAndRestart(language); + if (canApplyWithoutRestart(language.id)) { + performSwitchAndAddToRecent(language); + } else { + performSwitchAndRestart(language); + } }; if (!warning) { finalize(); @@ -452,7 +456,7 @@ void CloudManager::switchToLanguage(const Language &data) { if (data.id == qstr("#custom")) { performSwitchToCustom(); } else if (canApplyWithoutRestart(data.id)) { - performSwitch(data); + performSwitchAndAddToRecent(data); } else { QVector keys; keys.reserve(3); @@ -545,9 +549,13 @@ void CloudManager::performSwitch(const Language &data) { requestLangPackDifference(Pack::Base); } -void CloudManager::performSwitchAndRestart(const Language &data) { +void CloudManager::performSwitchAndAddToRecent(const Language &data) { Local::pushRecentLanguage(data); performSwitch(data); +} + +void CloudManager::performSwitchAndRestart(const Language &data) { + performSwitchAndAddToRecent(data); restartAfterSwitch(); } diff --git a/Telegram/SourceFiles/lang/lang_cloud_manager.h b/Telegram/SourceFiles/lang/lang_cloud_manager.h index adde6043e..f95b4854a 100644 --- a/Telegram/SourceFiles/lang/lang_cloud_manager.h +++ b/Telegram/SourceFiles/lang/lang_cloud_manager.h @@ -60,6 +60,7 @@ private: bool canApplyWithoutRestart(const QString &id) const; void performSwitchToCustom(); void performSwitch(const Language &data); + void performSwitchAndAddToRecent(const Language &data); void performSwitchAndRestart(const Language &data); void restartAfterSwitch(); void offerSwitchLangPack(); diff --git a/Telegram/SourceFiles/lang/lang_instance.cpp b/Telegram/SourceFiles/lang/lang_instance.cpp index db4741bf2..36245aaa7 100644 --- a/Telegram/SourceFiles/lang/lang_instance.cpp +++ b/Telegram/SourceFiles/lang/lang_instance.cpp @@ -301,6 +301,8 @@ void Instance::reset(const Language &data) { _values[i] = GetOriginalValue(LangKey(i)); } ranges::fill(_nonDefaultSet, 0); + + _idChanges.fire_copy(_id); } QString Instance::systemLangCode() const { @@ -329,6 +331,10 @@ QString Instance::id() const { return id(Pack::Current); } +rpl::producer Instance::idChanges() const { + return _idChanges.events(); +} + QString Instance::baseId() const { return id(Pack::Base); } @@ -538,6 +544,8 @@ void Instance::fillFromSerialized( applyValue(nonDefaultStrings[i], nonDefaultStrings[i + 1]); } updatePluralRules(); + + _idChanges.fire_copy(_id); } void Instance::loadFromContent(const QByteArray &content) { @@ -560,6 +568,8 @@ void Instance::fillFromCustomContent( _pluralId = PluralCodeForCustom(absolutePath, relativePath); _name = _nativeName = QString(); loadFromCustomContent(absolutePath, relativePath, content); + + _idChanges.fire_copy(_id); } void Instance::loadFromCustomContent( @@ -624,6 +634,8 @@ void Instance::fillFromLegacy(int legacyId, const QString &legacyPath) { _name = _nativeName = QString(); _base = nullptr; updatePluralRules(); + + _idChanges.fire_copy(_id); } // SetCallback takes two QByteArrays: key, value. diff --git a/Telegram/SourceFiles/lang/lang_instance.h b/Telegram/SourceFiles/lang/lang_instance.h index 69c93ca55..a3ca475c8 100644 --- a/Telegram/SourceFiles/lang/lang_instance.h +++ b/Telegram/SourceFiles/lang/lang_instance.h @@ -81,6 +81,7 @@ public: QString langPackName() const; QString cloudLangCode(Pack pack) const; QString id() const; + rpl::producer idChanges() const; QString baseId() const; QString name() const; QString nativeName() const; @@ -141,6 +142,7 @@ private: Instance *_derived = nullptr; QString _id, _pluralId; + rpl::event_stream _idChanges; QString _name, _nativeName; int _legacyId = kLegacyLanguageNone; QString _customFilePathAbsolute; diff --git a/Telegram/SourceFiles/settings/settings_main.cpp b/Telegram/SourceFiles/settings/settings_main.cpp index 38305d77d..ab28e723e 100644 --- a/Telegram/SourceFiles/settings/settings_main.cpp +++ b/Telegram/SourceFiles/settings/settings_main.cpp @@ -35,7 +35,11 @@ void SetupLanguageButton( const auto button = AddButtonWithLabel( container, tr::lng_settings_language(), - rpl::single(Lang::Current().nativeName()), + rpl::single( + Lang::Current().id() + ) | rpl::then( + Lang::Current().idChanges() + ) | rpl::map([] { return Lang::Current().nativeName(); }), icon ? st::settingsSectionButton : st::settingsButton, icon ? &st::settingsIconLanguage : nullptr); const auto guard = Ui::CreateChild(button.get());