mirror of https://github.com/procxx/kepka.git
Improve non-authed language switch.
This commit is contained in:
parent
a7c8feaecb
commit
52e40cbc6e
|
@ -55,6 +55,7 @@ public:
|
||||||
|
|
||||||
void activateSelected();
|
void activateSelected();
|
||||||
rpl::producer<Language> activations() const;
|
rpl::producer<Language> activations() const;
|
||||||
|
void changeChosen(const QString &chosen);
|
||||||
|
|
||||||
Ui::ScrollToRequest rowScrollRequest(int index) const;
|
Ui::ScrollToRequest rowScrollRequest(int index) const;
|
||||||
|
|
||||||
|
@ -170,6 +171,7 @@ public:
|
||||||
Ui::ScrollToRequest jump(int rows);
|
Ui::ScrollToRequest jump(int rows);
|
||||||
void filter(const QString &query);
|
void filter(const QString &query);
|
||||||
rpl::producer<Language> activations() const;
|
rpl::producer<Language> activations() const;
|
||||||
|
void changeChosen(const QString &chosen);
|
||||||
void activateBySubmit();
|
void activateBySubmit();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -180,6 +182,7 @@ private:
|
||||||
Fn<Ui::ScrollToRequest(int rows)> _jump;
|
Fn<Ui::ScrollToRequest(int rows)> _jump;
|
||||||
Fn<void(const QString &query)> _filter;
|
Fn<void(const QString &query)> _filter;
|
||||||
Fn<rpl::producer<Language>()> _activations;
|
Fn<rpl::producer<Language>()> _activations;
|
||||||
|
Fn<void(const QString &chosen)> _changeChosen;
|
||||||
Fn<void()> _activateBySubmit;
|
Fn<void()> _activateBySubmit;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -613,6 +616,12 @@ rpl::producer<Language> Rows::activations() const {
|
||||||
return _activations.events();
|
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) {
|
void Rows::setSelected(int selected) {
|
||||||
_mouseSelection = false;
|
_mouseSelection = false;
|
||||||
const auto limit = count();
|
const auto limit = count();
|
||||||
|
@ -1003,6 +1012,14 @@ void Content::setupContent(
|
||||||
other->activations()
|
other->activations()
|
||||||
) | rpl::type_erased();
|
) | rpl::type_erased();
|
||||||
};
|
};
|
||||||
|
_changeChosen = [=](const QString &chosen) {
|
||||||
|
if (main) {
|
||||||
|
main->changeChosen(chosen);
|
||||||
|
}
|
||||||
|
if (other) {
|
||||||
|
other->changeChosen(chosen);
|
||||||
|
}
|
||||||
|
};
|
||||||
_activateBySubmit = [=] {
|
_activateBySubmit = [=] {
|
||||||
if (selectedIndex() < 0) {
|
if (selectedIndex() < 0) {
|
||||||
_jump(1);
|
_jump(1);
|
||||||
|
@ -1024,6 +1041,10 @@ rpl::producer<Language> Content::activations() const {
|
||||||
return _activations();
|
return _activations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Content::changeChosen(const QString &chosen) {
|
||||||
|
_changeChosen(chosen);
|
||||||
|
}
|
||||||
|
|
||||||
void Content::activateBySubmit() {
|
void Content::activateBySubmit() {
|
||||||
_activateBySubmit();
|
_activateBySubmit();
|
||||||
}
|
}
|
||||||
|
@ -1076,6 +1097,9 @@ void LanguageBox::prepare() {
|
||||||
// So we check that the language really has changed.
|
// So we check that the language really has changed.
|
||||||
if (language.id != Lang::Current().id()) {
|
if (language.id != Lang::Current().id()) {
|
||||||
Lang::CurrentCloudManager().switchToLanguage(language);
|
Lang::CurrentCloudManager().switchToLanguage(language);
|
||||||
|
if (inner) {
|
||||||
|
inner->changeChosen(Lang::Current().id());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, inner->lifetime());
|
}, inner->lifetime());
|
||||||
|
|
||||||
|
|
|
@ -94,7 +94,7 @@ bool PasscodeBox::onlyCheckCurrent() const {
|
||||||
void PasscodeBox::prepare() {
|
void PasscodeBox::prepare() {
|
||||||
addButton(
|
addButton(
|
||||||
(_cloudFields.customSubmitButton
|
(_cloudFields.customSubmitButton
|
||||||
? rpl::single(*_cloudFields.customSubmitButton)
|
? std::move(_cloudFields.customSubmitButton)
|
||||||
: _turningOff
|
: _turningOff
|
||||||
? tr::lng_passcode_remove_button()
|
? tr::lng_passcode_remove_button()
|
||||||
: tr::lng_settings_save()),
|
: tr::lng_settings_save()),
|
||||||
|
@ -111,7 +111,7 @@ void PasscodeBox::prepare() {
|
||||||
if (onlyCheck) {
|
if (onlyCheck) {
|
||||||
_oldPasscode->show();
|
_oldPasscode->show();
|
||||||
setTitle(_cloudFields.customTitle
|
setTitle(_cloudFields.customTitle
|
||||||
? rpl::single(*_cloudFields.customTitle)
|
? std::move(_cloudFields.customTitle)
|
||||||
: _cloudPwd
|
: _cloudPwd
|
||||||
? tr::lng_cloud_password_remove()
|
? tr::lng_cloud_password_remove()
|
||||||
: tr::lng_passcode_remove());
|
: tr::lng_passcode_remove());
|
||||||
|
|
|
@ -38,9 +38,9 @@ public:
|
||||||
|
|
||||||
// Check cloud password for some action.
|
// Check cloud password for some action.
|
||||||
Fn<void(const Core::CloudPasswordResult &)> customCheckCallback;
|
Fn<void(const Core::CloudPasswordResult &)> customCheckCallback;
|
||||||
std::optional<QString> customTitle;
|
rpl::producer<QString> customTitle;
|
||||||
std::optional<QString> customDescription;
|
std::optional<QString> customDescription;
|
||||||
std::optional<QString> customSubmitButton;
|
rpl::producer<QString> customSubmitButton;
|
||||||
};
|
};
|
||||||
PasscodeBox(QWidget*, const CloudFields &fields);
|
PasscodeBox(QWidget*, const CloudFields &fields);
|
||||||
|
|
||||||
|
|
|
@ -490,10 +490,10 @@ void EditAdminBox::requestTransferPassword(not_null<ChannelData*> channel) {
|
||||||
) | rpl::start_with_next([=](const Core::CloudPasswordState &state) {
|
) | rpl::start_with_next([=](const Core::CloudPasswordState &state) {
|
||||||
const auto box = std::make_shared<QPointer<PasscodeBox>>();
|
const auto box = std::make_shared<QPointer<PasscodeBox>>();
|
||||||
auto fields = PasscodeBox::CloudFields::From(state);
|
auto fields = PasscodeBox::CloudFields::From(state);
|
||||||
fields.customTitle = lang(lng_rights_transfer_password_title);
|
fields.customTitle = tr::lng_rights_transfer_password_title();
|
||||||
fields.customDescription
|
fields.customDescription
|
||||||
= lang(lng_rights_transfer_password_description);
|
= lang(lng_rights_transfer_password_description);
|
||||||
fields.customSubmitButton = lang(lng_passcode_submit);
|
fields.customSubmitButton = tr::lng_passcode_submit();
|
||||||
fields.customCheckCallback = crl::guard(this, [=](
|
fields.customCheckCallback = crl::guard(this, [=](
|
||||||
const Core::CloudPasswordResult &result) {
|
const Core::CloudPasswordResult &result) {
|
||||||
sendTransferRequestFrom(*box, channel, result);
|
sendTransferRequestFrom(*box, channel, result);
|
||||||
|
|
|
@ -422,7 +422,11 @@ void CloudManager::requestLanguageAndSwitch(
|
||||||
_switchingToLanguageRequest = 0;
|
_switchingToLanguageRequest = 0;
|
||||||
const auto language = Lang::ParseLanguage(result);
|
const auto language = Lang::ParseLanguage(result);
|
||||||
const auto finalize = [=] {
|
const auto finalize = [=] {
|
||||||
performSwitchAndRestart(language);
|
if (canApplyWithoutRestart(language.id)) {
|
||||||
|
performSwitchAndAddToRecent(language);
|
||||||
|
} else {
|
||||||
|
performSwitchAndRestart(language);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
if (!warning) {
|
if (!warning) {
|
||||||
finalize();
|
finalize();
|
||||||
|
@ -452,7 +456,7 @@ void CloudManager::switchToLanguage(const Language &data) {
|
||||||
if (data.id == qstr("#custom")) {
|
if (data.id == qstr("#custom")) {
|
||||||
performSwitchToCustom();
|
performSwitchToCustom();
|
||||||
} else if (canApplyWithoutRestart(data.id)) {
|
} else if (canApplyWithoutRestart(data.id)) {
|
||||||
performSwitch(data);
|
performSwitchAndAddToRecent(data);
|
||||||
} else {
|
} else {
|
||||||
QVector<MTPstring> keys;
|
QVector<MTPstring> keys;
|
||||||
keys.reserve(3);
|
keys.reserve(3);
|
||||||
|
@ -545,9 +549,13 @@ void CloudManager::performSwitch(const Language &data) {
|
||||||
requestLangPackDifference(Pack::Base);
|
requestLangPackDifference(Pack::Base);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CloudManager::performSwitchAndRestart(const Language &data) {
|
void CloudManager::performSwitchAndAddToRecent(const Language &data) {
|
||||||
Local::pushRecentLanguage(data);
|
Local::pushRecentLanguage(data);
|
||||||
performSwitch(data);
|
performSwitch(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CloudManager::performSwitchAndRestart(const Language &data) {
|
||||||
|
performSwitchAndAddToRecent(data);
|
||||||
restartAfterSwitch();
|
restartAfterSwitch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,7 @@ private:
|
||||||
bool canApplyWithoutRestart(const QString &id) const;
|
bool canApplyWithoutRestart(const QString &id) const;
|
||||||
void performSwitchToCustom();
|
void performSwitchToCustom();
|
||||||
void performSwitch(const Language &data);
|
void performSwitch(const Language &data);
|
||||||
|
void performSwitchAndAddToRecent(const Language &data);
|
||||||
void performSwitchAndRestart(const Language &data);
|
void performSwitchAndRestart(const Language &data);
|
||||||
void restartAfterSwitch();
|
void restartAfterSwitch();
|
||||||
void offerSwitchLangPack();
|
void offerSwitchLangPack();
|
||||||
|
|
|
@ -301,6 +301,8 @@ void Instance::reset(const Language &data) {
|
||||||
_values[i] = GetOriginalValue(LangKey(i));
|
_values[i] = GetOriginalValue(LangKey(i));
|
||||||
}
|
}
|
||||||
ranges::fill(_nonDefaultSet, 0);
|
ranges::fill(_nonDefaultSet, 0);
|
||||||
|
|
||||||
|
_idChanges.fire_copy(_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Instance::systemLangCode() const {
|
QString Instance::systemLangCode() const {
|
||||||
|
@ -329,6 +331,10 @@ QString Instance::id() const {
|
||||||
return id(Pack::Current);
|
return id(Pack::Current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpl::producer<QString> Instance::idChanges() const {
|
||||||
|
return _idChanges.events();
|
||||||
|
}
|
||||||
|
|
||||||
QString Instance::baseId() const {
|
QString Instance::baseId() const {
|
||||||
return id(Pack::Base);
|
return id(Pack::Base);
|
||||||
}
|
}
|
||||||
|
@ -538,6 +544,8 @@ void Instance::fillFromSerialized(
|
||||||
applyValue(nonDefaultStrings[i], nonDefaultStrings[i + 1]);
|
applyValue(nonDefaultStrings[i], nonDefaultStrings[i + 1]);
|
||||||
}
|
}
|
||||||
updatePluralRules();
|
updatePluralRules();
|
||||||
|
|
||||||
|
_idChanges.fire_copy(_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::loadFromContent(const QByteArray &content) {
|
void Instance::loadFromContent(const QByteArray &content) {
|
||||||
|
@ -560,6 +568,8 @@ void Instance::fillFromCustomContent(
|
||||||
_pluralId = PluralCodeForCustom(absolutePath, relativePath);
|
_pluralId = PluralCodeForCustom(absolutePath, relativePath);
|
||||||
_name = _nativeName = QString();
|
_name = _nativeName = QString();
|
||||||
loadFromCustomContent(absolutePath, relativePath, content);
|
loadFromCustomContent(absolutePath, relativePath, content);
|
||||||
|
|
||||||
|
_idChanges.fire_copy(_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::loadFromCustomContent(
|
void Instance::loadFromCustomContent(
|
||||||
|
@ -624,6 +634,8 @@ void Instance::fillFromLegacy(int legacyId, const QString &legacyPath) {
|
||||||
_name = _nativeName = QString();
|
_name = _nativeName = QString();
|
||||||
_base = nullptr;
|
_base = nullptr;
|
||||||
updatePluralRules();
|
updatePluralRules();
|
||||||
|
|
||||||
|
_idChanges.fire_copy(_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCallback takes two QByteArrays: key, value.
|
// SetCallback takes two QByteArrays: key, value.
|
||||||
|
|
|
@ -81,6 +81,7 @@ public:
|
||||||
QString langPackName() const;
|
QString langPackName() const;
|
||||||
QString cloudLangCode(Pack pack) const;
|
QString cloudLangCode(Pack pack) const;
|
||||||
QString id() const;
|
QString id() const;
|
||||||
|
rpl::producer<QString> idChanges() const;
|
||||||
QString baseId() const;
|
QString baseId() const;
|
||||||
QString name() const;
|
QString name() const;
|
||||||
QString nativeName() const;
|
QString nativeName() const;
|
||||||
|
@ -141,6 +142,7 @@ private:
|
||||||
Instance *_derived = nullptr;
|
Instance *_derived = nullptr;
|
||||||
|
|
||||||
QString _id, _pluralId;
|
QString _id, _pluralId;
|
||||||
|
rpl::event_stream<QString> _idChanges;
|
||||||
QString _name, _nativeName;
|
QString _name, _nativeName;
|
||||||
int _legacyId = kLegacyLanguageNone;
|
int _legacyId = kLegacyLanguageNone;
|
||||||
QString _customFilePathAbsolute;
|
QString _customFilePathAbsolute;
|
||||||
|
|
|
@ -35,7 +35,11 @@ void SetupLanguageButton(
|
||||||
const auto button = AddButtonWithLabel(
|
const auto button = AddButtonWithLabel(
|
||||||
container,
|
container,
|
||||||
tr::lng_settings_language(),
|
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::settingsSectionButton : st::settingsButton,
|
||||||
icon ? &st::settingsIconLanguage : nullptr);
|
icon ? &st::settingsIconLanguage : nullptr);
|
||||||
const auto guard = Ui::CreateChild<base::binary_guard>(button.get());
|
const auto guard = Ui::CreateChild<base::binary_guard>(button.get());
|
||||||
|
|
Loading…
Reference in New Issue