From 13d20e47870deac5ecd0f06d8b4a78b82f655654 Mon Sep 17 00:00:00 2001 From: Maurice Kalinowski Date: Wed, 7 Sep 2016 13:47:26 +0200 Subject: winrt: Report system languages for QLocale::uiLanguages dc3e7e45ebe447c139868cc161b484eac478194d introduced locales from a packaging perspective, providing the information available from the package manifest. However, developers are rather interested in the available and preferred system languages to update user interfaces. Task-number: QTBUG-55672 Change-Id: I740d4f9c9ca21a8cbd437d3b232470897c569d34 Reviewed-by: Jens Bache-Wiig Reviewed-by: Oliver Wolff --- src/corelib/tools/qlocale_win.cpp | 44 +++++++-------------------------------- 1 file changed, 8 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/corelib/tools/qlocale_win.cpp b/src/corelib/tools/qlocale_win.cpp index 42ac888e47..b5f97b5fe8 100644 --- a/src/corelib/tools/qlocale_win.cpp +++ b/src/corelib/tools/qlocale_win.cpp @@ -57,7 +57,7 @@ #include #include #include -#include +#include #endif // Q_OS_WINRT QT_BEGIN_NAMESPACE @@ -70,6 +70,7 @@ static QString winIso3116CtryName(LCID id = LOCALE_USER_DEFAULT); using namespace Microsoft::WRL; using namespace Microsoft::WRL::Wrappers; using namespace ABI::Windows::Foundation; +using namespace ABI::Windows::System::UserProfile; static QByteArray getWinLocaleName(LPWSTR id = LOCALE_NAME_USER_DEFAULT); static const char *winLangCodeToIsoName(int code); @@ -624,16 +625,17 @@ QVariant QSystemLocalePrivate::uiLanguages() return result; #else // !Q_OS_WINRT QStringList result; - ComPtr appLanguagesStatics; - if (FAILED(GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Globalization_ApplicationLanguages).Get(), &appLanguagesStatics))) { + + ComPtr preferences; + HRESULT hr = GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_System_UserProfile_GlobalizationPreferences).Get(), &preferences); + if (FAILED(hr)) { qWarning("Could not obtain ApplicationLanguagesStatic"); return QStringList(); } ComPtr > languageList; - // Languages is a ranked list of "long names" (e.g. en-US) of preferred languages, which matches - // languages from the manifest with languages from the user's system. - HRESULT hr = appLanguagesStatics->get_Languages(&languageList); + // Languages is a ranked list of "long names" (e.g. en-US) of preferred languages + hr = preferences->get_Languages(&languageList); Q_ASSERT_SUCCEEDED(hr); unsigned int size; hr = languageList->get_Size(&size); @@ -648,36 +650,6 @@ QVariant QSystemLocalePrivate::uiLanguages() result << QString::fromWCharArray(rawString, length); } - // ManifestLanguages covers all languages given in the manifest and uses short names (like "en"). - hr = appLanguagesStatics->get_ManifestLanguages(&languageList); - Q_ASSERT_SUCCEEDED(hr); - hr = languageList->get_Size(&size); - Q_ASSERT_SUCCEEDED(hr); - for (unsigned int i = 0; i < size; ++i) { - HString language; - hr = languageList->GetAt(i, language.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); - UINT32 length; - PCWSTR rawString = language.GetRawBuffer(&length); - const QString qLanguage = QString::fromWCharArray(rawString, length); - bool found = false; - // Since ApplicationLanguages:::Languages uses long names, we compare the "pre-dash" part of - // the language and filter it out, if it is already covered by a more specialized form. - for (const QString &lang : qAsConst(result)) { - int dashIndex = lang.indexOf('-'); - // There will not be any long name after the first short name was found, so we can stop. - if (dashIndex == -1) - break; - - if (lang.leftRef(dashIndex) == qLanguage) { - found = true; - break; - } - } - if (!found) - result << qLanguage; - } - return result; #endif // Q_OS_WINRT } -- cgit v1.2.3