From e9ab8df73720009b06ed28646ca35017b936a280 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 9 Aug 2019 11:06:27 +0100 Subject: [PATCH] Use QLocale::uiLanguages for system language. --- Telegram/SourceFiles/intro/introphone.cpp | 4 ++-- Telegram/SourceFiles/intro/introwidget.cpp | 10 ++-------- Telegram/SourceFiles/platform/linux/info_linux.cpp | 10 ++++++---- Telegram/SourceFiles/ui/countryinput.cpp | 4 +++- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Telegram/SourceFiles/intro/introphone.cpp b/Telegram/SourceFiles/intro/introphone.cpp index 74612fbc3..3962b5b58 100644 --- a/Telegram/SourceFiles/intro/introphone.cpp +++ b/Telegram/SourceFiles/intro/introphone.cpp @@ -202,8 +202,8 @@ QString PhoneWidget::fullNumber() const { return _code->getLastText() + _phone->getLastText(); } -void PhoneWidget::selectCountry(const QString &c) { - _country->onChooseCountry(c); +void PhoneWidget::selectCountry(const QString &country) { + _country->onChooseCountry(country); } void PhoneWidget::setInnerFocus() { diff --git a/Telegram/SourceFiles/intro/introwidget.cpp b/Telegram/SourceFiles/intro/introwidget.cpp index d6aa6b77c..0f071070d 100644 --- a/Telegram/SourceFiles/intro/introwidget.cpp +++ b/Telegram/SourceFiles/intro/introwidget.cpp @@ -43,8 +43,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Intro { namespace { -constexpr str_const kDefaultCountry = "US"; - void PrepareSupportMode() { using Data::AutoDownload::Full; @@ -70,11 +68,7 @@ Widget::Widget(QWidget *parent, not_null account) tr::lng_menu_settings(), st::defaultBoxButton)) , _next(this, nullptr, st::introNextButton) { - auto country = Platform::SystemCountry(); - if (country.isEmpty()) { - country = str_const_toString(kDefaultCountry); - } - getData()->country = country; + getData()->country = Platform::SystemCountry(); _back->entity()->setClickedCallback([this] { historyMove(Direction::Back); }); _back->hide(anim::type::instant); @@ -439,7 +433,7 @@ void Widget::getNearestDC() { ).arg(nearest.vnearest_dc().v ).arg(nearest.vthis_dc().v)); _account->suggestMainDcId(nearest.vnearest_dc().v); - auto nearestCountry = qs(nearest.vcountry()); + const auto nearestCountry = qs(nearest.vcountry()); if (getData()->country != nearestCountry) { getData()->country = nearestCountry; getData()->updated.notify(); diff --git a/Telegram/SourceFiles/platform/linux/info_linux.cpp b/Telegram/SourceFiles/platform/linux/info_linux.cpp index 35e3b9c9e..255fd79d9 100644 --- a/Telegram/SourceFiles/platform/linux/info_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/info_linux.cpp @@ -27,13 +27,15 @@ QString SystemVersionPretty() { } QString SystemCountry() { - QLocale locale; - return locale.name().split('_').last(); + return QLocale::system().name().split('_').last(); } QString SystemLanguage() { - QLocale locale; - return locale.name().split('_').first(); + const auto system = QLocale::system(); + const auto languages = system.uiLanguages(); + return languages.isEmpty() + ? system.name().split('_').first() + : languages.front(); } QDate WhenSystemBecomesOutdated() { diff --git a/Telegram/SourceFiles/ui/countryinput.cpp b/Telegram/SourceFiles/ui/countryinput.cpp index 96c5ce85f..a95a70d21 100644 --- a/Telegram/SourceFiles/ui/countryinput.cpp +++ b/Telegram/SourceFiles/ui/countryinput.cpp @@ -152,7 +152,9 @@ CountrySelectBox::CountrySelectBox(QWidget*) CountrySelectBox::CountrySelectBox(QWidget*, const QString &iso, Type type) : _type(type) , _select(this, st::contactsMultiSelect, tr::lng_country_ph()) { - LastValidISO = iso; + if (Data::CountriesByISO2().contains(iso)) { + LastValidISO = iso; + } } void CountrySelectBox::prepare() {